66
66
67
67
(require 'cl-lib )
68
68
(require 'imenu )
69
+ (require 'newcomment )
69
70
70
71
(declare-function lisp-fill-paragraph " lisp-mode" (&optional justify))
71
72
@@ -682,9 +683,11 @@ Implementation function for `clojure--find-indent-spec'."
682
683
(let* ((function (thing-at-point 'symbol ))
683
684
(method (or (when function ; ; Is there a spec here?
684
685
(clojure--get-indent-method function))
685
- (progn (up-list ) ; ; Otherwise look higher up.
686
- (clojure-backward-logical-sexp 1 )
687
- (clojure--find-indent-spec-backtracking)))))
686
+ ; ; `up-list' errors on unbalanced sexps.
687
+ (ignore-errors
688
+ (up-list ) ; ; Otherwise look higher up.
689
+ (clojure-backward-logical-sexp 1 )
690
+ (clojure--find-indent-spec-backtracking)))))
688
691
(when (numberp method)
689
692
(setq method (list method)))
690
693
(pcase method
@@ -733,6 +736,18 @@ LAST-SEXP is the start of the previous sexp."
733
736
(skip-chars-forward " [:blank:]" )
734
737
(current-column )))
735
738
739
+ (defun clojure--not-function-form-p ()
740
+ " Non-nil if form at point doesn't represent a function call."
741
+ (or (member (char-after ) '(?\[ ?\{ ))
742
+ (save-excursion ; ; Catch #?@ (:cljs ...)
743
+ (skip-chars-backward " \r\n [:blank:]" )
744
+ (when (eq (char-before ) ?@ )
745
+ (forward-char -1 ))
746
+ (and (eq (char-before ) ?\? )
747
+ (eq (char-before (1- (point ))) ?\# )))
748
+ ; ; Car of form is not a symbol.
749
+ (not (looking-at " .\\ (?:\\ sw\\ |\\ s_\\ )" ))))
750
+
736
751
(defun clojure-indent-function (indent-point state )
737
752
" When indenting a line within a function call, indent properly.
738
753
@@ -760,12 +775,7 @@ This function also returns nil meaning don't specify the indentation."
760
775
; ; Goto to the open-paren.
761
776
(goto-char (elt state 1 ))
762
777
; ; Maps, sets, vectors and reader conditionals.
763
- (if (or (member (char-after ) '(?\[ ?\{ ))
764
- (and (eq (char-before ) ?\? )
765
- (eq (char-before (1- (point ))) ?\# ))
766
- ; ; Car of form is not a symbol.
767
- (and (elt state 2 )
768
- (not (looking-at " .\\ sw\\ |.\\ s_" ))))
778
+ (if (clojure--not-function-form-p)
769
779
(1+ (current-column ))
770
780
; ; Function or macro call.
771
781
(forward-char 1 )
@@ -1103,23 +1113,23 @@ Returns a list pair, e.g. (\"defn\" \"abc\") or (\"deftest\" \"some-test\")."
1103
1113
1104
1114
1105
1115
; ;; Sexp navigation
1106
- (defun clojure--looking-at-logical-sexp ()
1116
+ (defun clojure--looking-at-non- logical-sexp ()
1107
1117
" Return non-nil if sexp after point represents code.
1108
1118
Sexps that don't represent code are ^metadata or #reader.macros."
1109
- (forward-sexp 1 )
1110
- (forward-sexp -1 )
1111
- (not ( looking-at-p " \\ ^\\ |#[?[:alpha:]]" ) ))
1119
+ (comment-normalize-vars )
1120
+ (comment-forward ( point-max ) )
1121
+ (looking-at-p " \\ ^\\ |#[?[:alpha:]]" ))
1112
1122
1113
1123
(defun clojure-forward-logical-sexp (&optional n )
1114
1124
" Move forward N logical sexps.
1115
1125
This will skip over sexps that don't represent objects, so that ^hints and
1116
1126
#reader.macros are considered part of the following sexp."
1117
1127
(interactive " p" )
1118
- (let ((forward-sexp-function nil ) )
1119
- ( if ( < n 0 )
1120
- (clojure-backward-logical- sexp ( - n ))
1128
+ (if ( < n 0 )
1129
+ (clojure-backward-logical-sexp ( - n) )
1130
+ ( let ((forward- sexp-function nil ))
1121
1131
(while (> n 0 )
1122
- (while (not ( clojure--looking-at-logical-sexp) )
1132
+ (while (clojure--looking-at-non- logical-sexp)
1123
1133
(forward-sexp 1 ))
1124
1134
; ; The actual sexp
1125
1135
(forward-sexp 1 )
@@ -1132,17 +1142,18 @@ This will skip over sexps that don't represent objects, so that ^hints and
1132
1142
(interactive " p" )
1133
1143
(if (< n 0 )
1134
1144
(clojure-forward-logical-sexp (- n))
1135
- (while (> n 0 )
1136
- ; ; The actual sexp
1137
- (backward-sexp 1 )
1138
- ; ; Non-logical sexps.
1139
- (while (and (not (bobp ))
1140
- (ignore-errors
1141
- (save-excursion
1142
- (backward-sexp 1 )
1143
- (not (clojure--looking-at-logical-sexp)))))
1144
- (backward-sexp 1 ))
1145
- (setq n (1- n)))))
1145
+ (let ((forward-sexp-function nil ))
1146
+ (while (> n 0 )
1147
+ ; ; The actual sexp
1148
+ (backward-sexp 1 )
1149
+ ; ; Non-logical sexps.
1150
+ (while (and (not (bobp ))
1151
+ (ignore-errors
1152
+ (save-excursion
1153
+ (backward-sexp 1 )
1154
+ (clojure--looking-at-non-logical-sexp))))
1155
+ (backward-sexp 1 ))
1156
+ (setq n (1- n))))))
1146
1157
1147
1158
(defconst clojurescript-font-lock-keywords
1148
1159
(eval-when-compile
0 commit comments