Skip to content

Commit 8db56ec

Browse files
committed
[Fix #278] Understand namespace aliases in backtracking indent
1 parent e8c71e1 commit 8db56ec

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

clojure-mode.el

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,14 @@ point) to check."
638638
(replace-match (clojure-docstring-fill-prefix))))
639639
(lisp-indent-line)))
640640

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+
641649
(defun clojure-indent-function (indent-point state)
642650
"When indenting a line within a function call, indent properly.
643651
@@ -687,13 +695,8 @@ This function also returns nil meaning don't specify the indentation."
687695
(let* ((function (buffer-substring (point)
688696
(progn (forward-sexp 1) (point))))
689697
(open-paren (elt state 1))
690-
(method nil)
691698
(forward-sexp-function #'clojure-forward-logical-sexp)
692-
(function-tail (car
693-
(reverse
694-
(split-string (substring-no-properties function) "/")))))
695-
(setq method (or (get (intern-soft function) 'clojure-indent-function)
696-
(get (intern-soft function-tail) 'clojure-indent-function)))
699+
(method (clojure--symbol-get function 'clojure-indent-function)))
697700
;; Maps, sets, vectors and reader conditionals.
698701
(cond ((or (member (char-after open-paren) '(?\[ ?\{))
699702
(ignore-errors
@@ -734,15 +737,15 @@ move upwards in an sexp to check for contextual indenting."
734737
(when (looking-at "\\sw\\|\\s_")
735738
(let* ((start (point))
736739
(fn (buffer-substring start (progn (forward-sexp 1) (point))))
737-
(meth (get (intern-soft fn) 'clojure-backtracking-indent)))
740+
(meth (clojure--symbol-get fn 'clojure-backtracking-indent)))
738741
(let ((n 0))
739742
(when (< (point) indent-point)
740743
(condition-case ()
741744
(progn
742745
(forward-sexp 1)
743746
(while (< (point) indent-point)
744747
(parse-partial-sexp (point) indent-point 1 t)
745-
(incf n)
748+
(cl-incf n)
746749
(forward-sexp 1)))
747750
(error nil)))
748751
(push n path))
@@ -762,7 +765,7 @@ move upwards in an sexp to check for contextual indenting."
762765
(condition-case ()
763766
(progn
764767
(backward-up-list 1)
765-
(incf depth))
768+
(cl-incf depth))
766769
(error (setq depth clojure-max-backtracking)))))
767770
indent))
768771

test/clojure-mode-indentation-test.el

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ values of customisable variables."
179179
#?(:clj :foo
180180
|:cljs :bar)")
181181

182+
(check-indentation backtracking-with-aliases
183+
"
184+
(clojure.core/letfn [(twice [x]
185+
|(* x 2))]
186+
:a)"
187+
"
188+
(clojure.core/letfn [(twice [x]
189+
|(* x 2))]
190+
:a)")
182191

183192
(provide 'clojure-mode-indentation-test)
184193

0 commit comments

Comments
 (0)