57
57
58
58
; ;; Code:
59
59
60
-
61
60
(defvar calculate-lisp-indent-last-sexp )
62
61
(defvar delete-pair-blink-delay )
63
62
(defvar font-lock-beg )
@@ -717,7 +716,7 @@ If JUSTIFY is non-nil, justify as well as fill the paragraph."
717
716
(fill-prefix (clojure-adaptive-fill-function)))
718
717
(do-auto-fill )))))
719
718
720
-
719
+
721
720
; ;; #_ comments font-locking
722
721
; ; Code heavily borrowed from Slime.
723
722
; ; https://github.com/slime/slime/blob/master/contrib/slime-fontifying-fu.el#L186
@@ -780,7 +779,7 @@ and `(match-end 1)'."
780
779
(scan-error (setq result 'retry ))))
781
780
result))
782
781
783
-
782
+
784
783
; ;; General font-locking
785
784
(defun clojure-match-next-def ()
786
785
" Scans the buffer backwards for the next \" top-level\" definition.
@@ -1889,7 +1888,7 @@ work). To set it from Lisp code, use
1889
1888
(go-loop 1 )
1890
1889
(thread 0 ))
1891
1890
1892
-
1891
+
1893
1892
1894
1893
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1895
1894
; ;
@@ -1944,7 +1943,7 @@ nil."
1944
1943
(delete-region begin (point ))
1945
1944
result)))
1946
1945
1947
-
1946
+
1948
1947
1949
1948
(defcustom clojure-cache-project-dir t
1950
1949
" Whether to cache the results of `clojure-project-dir' ."
@@ -1988,7 +1987,7 @@ Return nil if not inside a project."
1988
1987
" Denormalize PATH by making it relative to the project root."
1989
1988
(file-relative-name path (clojure-project-dir)))
1990
1989
1991
-
1990
+
1992
1991
; ;; ns manipulation
1993
1992
(defun clojure-expected-ns (&optional path )
1994
1993
" Return the namespace matching PATH.
@@ -2125,7 +2124,7 @@ content) are considered part of the preceding sexp."
2125
2124
(make-obsolete-variable 'clojure-namespace-name-regex 'clojure-namespace-regexp " 5.12.0" )
2126
2125
2127
2126
(defconst clojure-namespace-regexp
2128
- (rx line-start (zero-or-more whitespace) " (" (? " clojure.core/" ) (or " in-ns" " ns" " ns+" ) symbol-end))
2127
+ (rx " (" (? " clojure.core/" ) (or " in-ns" " ns" " ns+" ) symbol-end))
2129
2128
2130
2129
(defcustom clojure-cache-ns nil
2131
2130
" Whether to cache the results of `clojure-find-ns' .
@@ -2148,12 +2147,13 @@ DIRECTION is `forward' or `backward'."
2148
2147
#'search-backward-regexp )))
2149
2148
(while (and (not candidate)
2150
2149
(funcall fn clojure-namespace-regexp nil t ))
2151
- (let ((end (match-end 0 )))
2150
+ (let ((start (match-beginning 0 ))
2151
+ (end (match-end 0 )))
2152
2152
(save-excursion
2153
- (save-match-data
2154
- (goto-char end)
2155
- (clojure-forward-logical-sexp )
2156
- ( unless ( or (clojure--in-string-p) (clojure--in-comment-p) (clojure-top-level-form-p " comment " ) )
2153
+ (when (clojure--is-top-level-form-p start)
2154
+ (save-match-data
2155
+ ( goto-char end )
2156
+ (clojure-forward-logical-sexp )
2157
2157
(setq candidate (string-remove-prefix " '" (thing-at-point 'symbol ))))))))
2158
2158
candidate))
2159
2159
@@ -2222,7 +2222,7 @@ Returns a list pair, e.g. (\"defn\" \"abc\") or (\"deftest\" \"some-test\")."
2222
2222
(list (match-string-no-properties 1 )
2223
2223
(match-string-no-properties 2 )))))
2224
2224
2225
-
2225
+
2226
2226
; ;; Sexp navigation
2227
2227
2228
2228
(defun clojure--looking-at-non-logical-sexp ()
@@ -2270,6 +2270,16 @@ This will skip over sexps that don't represent objects, so that ^hints and
2270
2270
(backward-sexp 1 ))
2271
2271
(setq n (1- n))))))
2272
2272
2273
+ (defun clojure--is-top-level-form-p (&optional point )
2274
+ " Return truthy if form at POINT is a top level form."
2275
+ (save-excursion
2276
+ (when point (goto-char point))
2277
+ (and (looking-at-p " (" )
2278
+ (= (point )
2279
+ (progn (forward-char )
2280
+ (beginning-of-defun-raw )
2281
+ (point ))))))
2282
+
2273
2283
(defun clojure-top-level-form-p (first-form )
2274
2284
" Return truthy if the first form matches FIRST-FORM."
2275
2285
(condition-case nil
@@ -3173,7 +3183,7 @@ Assumes cursor is at beginning of function."
3173
3183
(clojure--add-arity-reify-internal)))
3174
3184
(indent-region beg end-marker))))
3175
3185
3176
-
3186
+
3177
3187
; ;; Toggle Ignore forms
3178
3188
3179
3189
(defun clojure--toggle-ignore-next-sexp (&optional n )
0 commit comments