@@ -638,6 +638,14 @@ point) to check."
638
638
(replace-match (clojure-docstring-fill-prefix))))
639
639
(lisp-indent-line )))
640
640
641
+ (defun clojure--symbol-get (function-name property )
642
+ " Return the symbol PROPERTY for the symbol named FUNCTION-NAME.
643
+ FUNCTION-NAME is a string. If it contains a `/' , also try only the part after the `/' ."
644
+ (or (get (intern-soft function-name) property)
645
+ (and (string-match " /\\ ([^/]+\\ )\\ '" function-name)
646
+ (get (intern-soft (match-string 1 function-name))
647
+ property))))
648
+
641
649
(defun clojure-indent-function (indent-point state )
642
650
" When indenting a line within a function call, indent properly.
643
651
@@ -670,7 +678,12 @@ This function also returns nil meaning don't specify the indentation."
670
678
(if (not (> (save-excursion (forward-line 1 ) (point ))
671
679
calculate-lisp-indent-last-sexp))
672
680
(progn (goto-char calculate-lisp-indent-last-sexp)
673
- (beginning-of-line )
681
+ (skip-chars-backward " [:blank:]" )
682
+ ; ; We're done if we find the start of line,
683
+ (while (and (not (looking-at-p " ^" ))
684
+ ; ; or start of sexp.
685
+ (ignore-errors (forward-sexp -1 ) t ))
686
+ (skip-chars-backward " [:blank:]" ))
674
687
(parse-partial-sexp (point )
675
688
calculate-lisp-indent-last-sexp 0 t )))
676
689
; ; Indent under the list or under the first sexp on the same
@@ -682,13 +695,13 @@ This function also returns nil meaning don't specify the indentation."
682
695
(let* ((function (buffer-substring (point )
683
696
(progn (forward-sexp 1 ) (point ))))
684
697
(open-paren (elt state 1 ))
685
- (method nil )
686
- (function-tail ( car
687
- ( reverse
688
- ( split-string ( substring-no-properties function) " / " ))) ))
689
- ( setq method ( or ( get ( intern-soft function) 'clojure-indent-function )
690
- ( get ( intern-soft function-tail) 'clojure-indent-function )) )
691
- ( cond (( member (char-after open-paren) '( ?\[ ?\{ ))
698
+ (forward-sexp-function # 'clojure-forward-logical-sexp )
699
+ (method (clojure--symbol-get function 'clojure-indent-function )))
700
+ ; ; Maps, sets, vectors and reader conditionals.
701
+ ( cond (( or ( member ( char-after open-paren) '( ?\[ ?\{ ))
702
+ ( ignore-errors
703
+ ( and ( eq ( char-before open-paren) ?\? )
704
+ ( eq (char-before ( 1- open-paren)) ?\# )) ))
692
705
(goto-char open-paren)
693
706
(1+ (current-column )))
694
707
((or (eq method 'defun )
@@ -724,15 +737,15 @@ move upwards in an sexp to check for contextual indenting."
724
737
(when (looking-at " \\ sw\\ |\\ s_" )
725
738
(let* ((start (point ))
726
739
(fn (buffer-substring start (progn (forward-sexp 1 ) (point ))))
727
- (meth (get ( intern-soft fn) 'clojure-backtracking-indent )))
740
+ (meth (clojure--symbol- get fn 'clojure-backtracking-indent )))
728
741
(let ((n 0 ))
729
742
(when (< (point ) indent-point)
730
743
(condition-case ()
731
744
(progn
732
745
(forward-sexp 1 )
733
746
(while (< (point ) indent-point)
734
747
(parse-partial-sexp (point ) indent-point 1 t )
735
- (incf n)
748
+ (cl- incf n)
736
749
(forward-sexp 1 )))
737
750
(error nil )))
738
751
(push n path))
@@ -752,7 +765,7 @@ move upwards in an sexp to check for contextual indenting."
752
765
(condition-case ()
753
766
(progn
754
767
(backward-up-list 1 )
755
- (incf depth))
768
+ (cl- incf depth))
756
769
(error (setq depth clojure-max-backtracking)))))
757
770
indent))
758
771
@@ -1071,22 +1084,27 @@ Returns a list pair, e.g. (\"defn\" \"abc\") or (\"deftest\" \"some-test\")."
1071
1084
1072
1085
1073
1086
; ;; Sexp navigation
1087
+ (defun clojure--looking-at-logical-sexp ()
1088
+ " Return non-nil if sexp after point represents code.
1089
+ Sexps that don't represent code are ^metadata or #reader.macros."
1090
+ (forward-sexp 1 )
1091
+ (forward-sexp -1 )
1092
+ (not (looking-at-p " \\ ^\\ |#[[:alpha:]]" )))
1093
+
1074
1094
(defun clojure-forward-logical-sexp (&optional n )
1075
1095
" Move forward N logical sexps.
1076
1096
This will skip over sexps that don't represent objects, so that ^hints and
1077
1097
#reader.macros are considered part of the following sexp."
1078
1098
(interactive " p" )
1079
- (if (< n 0 )
1080
- (clojure-backward-logical-sexp (- n))
1081
- (while (> n 0 )
1082
- ; ; Non-logical sexps.
1083
- (while (progn (forward-sexp 1 )
1084
- (forward-sexp -1 )
1085
- (looking-at-p " \\ ^\\ |#[[:alpha:]]" ))
1086
- (forward-sexp 1 ))
1087
- ; ; The actual sexp
1088
- (forward-sexp 1 )
1089
- (setq n (1- n)))))
1099
+ (let ((forward-sexp-function nil ))
1100
+ (if (< n 0 )
1101
+ (clojure-backward-logical-sexp (- n))
1102
+ (while (> n 0 )
1103
+ (while (not (clojure--looking-at-logical-sexp))
1104
+ (forward-sexp 1 ))
1105
+ ; ; The actual sexp
1106
+ (forward-sexp 1 )
1107
+ (setq n (1- n))))))
1090
1108
1091
1109
(defun clojure-backward-logical-sexp (&optional n )
1092
1110
" Move backward N logical sexps.
0 commit comments