Skip to content

Commit 22c0846

Browse files
committed
Increase js/ namespace detection accuracy for .cljc files
Fixes clojure-emacs#523
1 parent 1fdc95a commit 22c0846

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
* [#523](https://github.com/clojure-emacs/clj-refactor.el/issues/523): Increase `js/` namespace detection accuracy for .cljc files.
6+
57
## 3.9.1
68

79
* [#430](https://github.com/clojure-emacs/clj-refactor.el/issues/430) `cljr-add-missing-libspec`: produce more friendly prompts.

clj-refactor.el

+13-7
Original file line numberDiff line numberDiff line change
@@ -1087,19 +1087,22 @@ If CLJS? is T we insert in the cljs part of the ns declaration."
10871087

10881088
(defun cljr--cljs-file-p (&optional buf)
10891089
"Is BUF, or the current buffer, visiting a cljs file?"
1090-
(string-equal (file-name-extension (buffer-file-name (or buf (current-buffer))))
1091-
"cljs"))
1090+
(when-let ((bfn (buffer-file-name (or buf (current-buffer)))))
1091+
(string-equal (file-name-extension bfn)
1092+
"cljs")))
10921093

10931094
(defun cljr--cljc-file-p (&optional buf)
10941095
"Is BUF, or the current buffer, visiting a cljc file?"
1095-
(string-equal (file-name-extension (buffer-file-name (or buf (current-buffer))))
1096-
"cljc"))
1096+
(when-let ((bfn (buffer-file-name (or buf (current-buffer)))))
1097+
(string-equal (file-name-extension bfn)
1098+
"cljc")))
10971099

10981100
(defun cljr--clj-file-p (&optional buf)
10991101
"Is BUF, or the current buffer, visiting a clj file?"
11001102
(or (eq major-mode 'clojure-mode)
1101-
(string-equal (file-name-extension (buffer-file-name (or buf (current-buffer))))
1102-
"clj")))
1103+
(when-let ((bfn (buffer-file-name (or buf (current-buffer)))))
1104+
(string-equal (file-name-extension bfn)
1105+
"clj"))))
11031106

11041107
(defun cljr--add-test-declarations ()
11051108
(save-excursion
@@ -2042,7 +2045,10 @@ is not set to `:prompt'."
20422045
(gethash :cljs aliases))))
20432046

20442047
(defun cljr--js-alias-p (alias)
2045-
(and (cljr--cljs-file-p)
2048+
(and (member "cljs" (condition-case nil
2049+
(cljr--language-context-at-point) ;; it shouldn't fail, but we can leave it like this until consideredfully time-proven.
2050+
(error (when (cljr--cljs-file-p)
2051+
'("cljs")))))
20462052
(string-equal "js" alias)))
20472053

20482054
(defun cljr--ns-alias-at-point ()

0 commit comments

Comments
 (0)