Skip to content

Commit

Permalink
Fix occasional :require / :require-macros confusion in cljr-slash
Browse files Browse the repository at this point in the history
Fixes #512
  • Loading branch information
vemv committed Mar 5, 2022
1 parent 5422252 commit 424d554
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- [#512](https://github.com/clojure-emacs/clj-refactor.el/issues/512): Fix occasional :require` / `:require-macros` confusion in `cljr-slash`.

## 3.3.3

- Adapt `cljr--inject-jack-in-dependencies` to upstream changes in CIDER.
Expand Down
22 changes: 16 additions & 6 deletions clj-refactor.el
Original file line number Diff line number Diff line change
Expand Up @@ -552,15 +552,18 @@ If optional `with-whitespace' is T sexp elements are not trimmed."
(goto-char (point-at-bol))
(looking-at "\\s-*;+")))

(defun cljr--search-forward-within-sexp (s &optional save-excursion)
(defun cljr--search-forward-within-sexp (s &optional save-excursion regexp)
"Searches forward for S in the current sexp.
if SAVE-EXCURSION is T POINT does not move."
(let ((bound (save-excursion (forward-list 1) (point))))
(let ((bound (save-excursion (forward-list 1) (point)))
(f (if regexp
're-search-forward
'search-forward)))
(if save-excursion
(save-excursion
(search-forward s bound t))
(search-forward s bound t))))
(funcall f s bound t))
(funcall f s bound t))))

(defun cljr--goto-toplevel ()
(paredit-backward-up (cljr--depth-at-point))
Expand Down Expand Up @@ -1022,13 +1025,20 @@ no namespace form above point, return the first one in the buffer."
(defun cljr--insert-in-ns (type &optional cljs?)
"Insert another clause into the TYPE clause of the ns statement.
TYPE is :require, :use etc
TYPE is :require, :use etc, as a regexp.
If CLJS? is T we insert in the cljs part of the ns declaration."
(cljr--goto-ns)
(when cljs?
(cljr--goto-cljs-branch))
(if (cljr--search-forward-within-sexp (concat "(" type))
(if (cljr--search-forward-within-sexp (concat "("
type
;; match e.g. `require' but not `require-macros',
;; or vice versa.
;; See https://github.com/clojure-emacs/clj-refactor.el/issues/512
"\\(?:$\\|[^-a-zA-Z]\\)")
nil
t)
(if (looking-at " *)")
(progn
(search-backward "(")
Expand Down

0 comments on commit 424d554

Please sign in to comment.