-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce completable-for-cljr-slash?
#493
Closed
Closed
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2192625
Introduce `completable-for-cljr-slash?`
vemv f4db22e
Also support keywords, metadata
vemv 8f67d6f
Migrate assertions to Buttercup
vemv 9eed803
Disable linting for now
vemv 642dd4a
Prefer `thing-at-point` over `cider-symbol-at-point`
vemv 0d3fbcf
Expand `completable-for-cljr-slash?` test coverage
vemv 1a1c716
Extract and complete `cljr--namespace-of-thing-at-point`
vemv 833cf5e
`completable-for-cljr-slash?`: also complete @
vemv 5134e25
Add an additional `string-remove-prefix`
vemv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ | |
|
||
(development | ||
(depends-on "ecukes") | ||
(depends-on "espuds")) | ||
(depends-on "espuds") | ||
(depends-on "buttercup")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1983,37 +1983,43 @@ the alias in the project." | |
(backward-sexp 1) | ||
(looking-at-p "[-+0-9]"))) | ||
|
||
(defun completable-for-cljr-slash? (sym) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All definitions should have a docstring, especially the "public" ones. |
||
(when sym | ||
(not (null (string-match-p "^\\^?\\(::\\)?\\([a-zA-Z]+[a-zA-Z0-9\\-]*\\)+\\(\\.?[a-zA-Z]+[a-zA-Z0-9\\-]*\\)*$" sym))))) | ||
|
||
;;;###autoload | ||
(defun cljr-slash () | ||
"Inserts / as normal, but also checks for common namespace shorthands to require. | ||
If `cljr-magic-requires' is non-nil, executing this command after one of the aliases | ||
listed in `cljr-magic-require-namespaces', or any alias used elsewhere in the project, | ||
will add the corresponding require statement to the ns form." | ||
(interactive) | ||
(insert "/") | ||
(when-let (aliases (and cljr-magic-requires | ||
(not (cljr--in-map-destructuring?)) | ||
(not (cljr--in-ns-above-point-p)) | ||
(not (cljr--in-reader-literal-p)) | ||
(not (cider-in-comment-p)) | ||
(not (cider-in-string-p)) | ||
(not (cljr--in-keyword-sans-alias-p)) | ||
(not (cljr--in-number-p)) | ||
(clojure-find-ns) | ||
(cljr--magic-requires-lookup-alias))) | ||
(let ((short (cl-first aliases))) | ||
(when-let (long (cljr--prompt-user-for "Require " (cl-second aliases))) | ||
(when (and (not (cljr--in-namespace-declaration-p (concat ":as " short "\b"))) | ||
(or (not (eq :prompt cljr-magic-requires)) | ||
(not (> (length (cl-second aliases)) 1)) ; already prompted | ||
(yes-or-no-p (format "Add %s :as %s to requires?" long short)))) | ||
(save-excursion | ||
(cljr--insert-in-ns ":require") | ||
(let ((libspec (format "[%s :as %s]" long short))) | ||
(insert libspec) | ||
(ignore-errors (cljr--maybe-eval-ns-form)) | ||
(cljr--indent-defun) | ||
(cljr--post-command-message "Required %s" libspec)))))))) | ||
(let ((original-input (thing-at-point 'symbol))) | ||
(insert "/") | ||
vemv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(when-let (aliases (and cljr-magic-requires | ||
(completable-for-cljr-slash? original-input) | ||
(not (cljr--in-map-destructuring?)) | ||
(not (cljr--in-ns-above-point-p)) | ||
(not (cljr--in-reader-literal-p)) | ||
(not (cider-in-comment-p)) | ||
(not (cider-in-string-p)) | ||
(not (cljr--in-keyword-sans-alias-p)) | ||
(not (cljr--in-number-p)) | ||
(clojure-find-ns) | ||
(cljr--magic-requires-lookup-alias))) | ||
vemv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(let ((short (cl-first aliases))) | ||
(when-let (long (cljr--prompt-user-for "Require " (cl-second aliases))) | ||
(when (and (not (cljr--in-namespace-declaration-p (concat ":as " short "\b"))) | ||
(or (not (eq :prompt cljr-magic-requires)) | ||
(not (> (length (cl-second aliases)) 1)) ; already prompted | ||
(yes-or-no-p (format "Add %s :as %s to requires?" long short)))) | ||
(save-excursion | ||
(cljr--insert-in-ns ":require") | ||
(let ((libspec (format "[%s :as %s]" long short))) | ||
(insert libspec) | ||
(ignore-errors (cljr--maybe-eval-ns-form)) | ||
(cljr--indent-defun) | ||
(cljr--post-command-message "Required %s" libspec))))))))) | ||
|
||
(defun cljr--in-namespace-declaration-p (s) | ||
(save-excursion | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(provide 'feature) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
(require 'paredit) | ||
(require 'clj-refactor) | ||
|
||
(describe "completable-for-cljr-slash?" | ||
(it "Returns `t' for tokens that can represent alias-prefixed named things (symbols, keywords, metadata)" | ||
(expect (completable-for-cljr-slash? nil) :to-be nil) | ||
(dolist (prefix '("" "^" "^::")) | ||
(expect (completable-for-cljr-slash? (concat prefix "a")) :to-be t) | ||
(expect (completable-for-cljr-slash? (concat prefix "a-")) :to-be t) | ||
(expect (completable-for-cljr-slash? (concat prefix "a2")) :to-be t) | ||
(expect (completable-for-cljr-slash? (concat prefix "a-2")) :to-be t) | ||
(expect (completable-for-cljr-slash? (concat prefix "a2-")) :to-be t) | ||
(expect (completable-for-cljr-slash? (concat prefix "a2.a")) :to-be t) | ||
(expect (completable-for-cljr-slash? (concat prefix "a2.a-")) :to-be t) | ||
(expect (completable-for-cljr-slash? (concat prefix "a2.a2")) :to-be t) | ||
(expect (completable-for-cljr-slash? (concat prefix "a2.a-2")) :to-be t) | ||
(expect (completable-for-cljr-slash? (concat prefix "a2.a2-")) :to-be t) | ||
(expect (completable-for-cljr-slash? (concat prefix "a2.a.")) :to-be nil) | ||
(expect (completable-for-cljr-slash? (concat prefix "a2.2")) :to-be nil) | ||
(expect (completable-for-cljr-slash? (concat prefix "a2.2a")) :to-be nil) | ||
(expect (completable-for-cljr-slash? (concat prefix "a2.-")) :to-be nil) | ||
(expect (completable-for-cljr-slash? (concat prefix "a2.-a")) :to-be nil) | ||
(expect (completable-for-cljr-slash? (concat prefix "-")) :to-be nil) | ||
(expect (completable-for-cljr-slash? (concat prefix ".")) :to-be nil) | ||
(expect (completable-for-cljr-slash? (concat prefix "2")) :to-be nil) | ||
(expect (completable-for-cljr-slash? (concat prefix "+")) :to-be nil) | ||
(expect (completable-for-cljr-slash? (concat prefix "+")) :to-be nil) | ||
(expect (completable-for-cljr-slash? (concat prefix "a/")) :to-be nil) | ||
(expect (completable-for-cljr-slash? (concat prefix "a/a")) :to-be nil) | ||
(expect (completable-for-cljr-slash? (concat prefix "a/a/")) :to-be nil)))) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a target like
unit-tests
would be better here.make test
should probably run all tests and there should be a separatemake
target for the integration tests.