Skip to content

Commit 0758795

Browse files
committed
Avoid duplicate thing-at-point call in alignment position check
1 parent f13aa84 commit 0758795

1 file changed

Lines changed: 25 additions & 23 deletions

File tree

clojure-mode.el

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,29 +1423,31 @@ construct."
14231423
;; Are we in a reader conditional?
14241424
(and clojure-align-reader-conditionals
14251425
(looking-back clojure--beginning-of-reader-conditional-regexp (- (point) 4)))
1426-
;; Are we in a cond form?
1427-
(let* ((fun (car (member (thing-at-point 'symbol) clojure-align-cond-forms)))
1428-
(method (and fun (clojure--get-indent-method fun)))
1429-
;; The number of special arguments in the cond form is
1430-
;; the number of sexps we skip before aligning.
1431-
(skip (cond ((numberp method) method)
1432-
((null method) 0)
1433-
((sequencep method) (elt method 0)))))
1434-
(when (and fun (numberp skip))
1435-
(clojure-forward-logical-sexp skip)
1436-
(comment-forward (point-max))
1437-
fun)) ; Return non-nil (the var name).
1438-
;; Are we in a let-like form?
1439-
(when (member (thing-at-point 'symbol)
1440-
clojure-align-binding-forms)
1441-
;; Position inside the binding vector.
1442-
(clojure-forward-logical-sexp)
1443-
(backward-sexp)
1444-
(when (eq (char-after) ?\[)
1445-
(forward-char 1)
1446-
(comment-forward (point-max))
1447-
;; Return non-nil.
1448-
t)))))
1426+
;; Check cond forms and let-like forms, computing the symbol once.
1427+
(let ((sym (thing-at-point 'symbol)))
1428+
(or
1429+
;; Are we in a cond form?
1430+
(let* ((fun (car (member sym clojure-align-cond-forms)))
1431+
(method (and fun (clojure--get-indent-method fun)))
1432+
;; The number of special arguments in the cond form is
1433+
;; the number of sexps we skip before aligning.
1434+
(skip (cond ((numberp method) method)
1435+
((null method) 0)
1436+
((sequencep method) (elt method 0)))))
1437+
(when (and fun (numberp skip))
1438+
(clojure-forward-logical-sexp skip)
1439+
(comment-forward (point-max))
1440+
fun)) ; Return non-nil (the var name).
1441+
;; Are we in a let-like form?
1442+
(when (member sym clojure-align-binding-forms)
1443+
;; Position inside the binding vector.
1444+
(clojure-forward-logical-sexp)
1445+
(backward-sexp)
1446+
(when (eq (char-after) ?\[)
1447+
(forward-char 1)
1448+
(comment-forward (point-max))
1449+
;; Return non-nil.
1450+
t)))))))
14491451

14501452
(defvar clojure--align-search-regexp-cache nil
14511453
"Cached regexp for `clojure--find-sexp-to-align'.

0 commit comments

Comments
 (0)