@@ -1360,6 +1360,29 @@ will align the values like this:
13601360 :safe #'booleanp
13611361 :type 'boolean )
13621362
1363+ (defvar clojure--align-search-regexp-cache nil
1364+ " Cached regexp for `clojure--find-sexp-to-align' .
1365+ A cons of (KEY . REGEXP) where KEY captures the inputs used to build it." )
1366+
1367+ (defun clojure--align-search-regexp ()
1368+ " Return the cached regexp for alignment search.
1369+ Rebuilds the regexp only when the inputs change."
1370+ (let ((key (list clojure-align-reader-conditionals
1371+ clojure-align-binding-forms
1372+ clojure-align-cond-forms)))
1373+ (unless (equal key (car clojure--align-search-regexp-cache))
1374+ (setq clojure--align-search-regexp-cache
1375+ (cons key
1376+ (concat (when clojure-align-reader-conditionals
1377+ (concat clojure--beginning-of-reader-conditional-regexp
1378+ " \\ |" ))
1379+ " {\\ |("
1380+ (regexp-opt
1381+ (append clojure-align-binding-forms
1382+ clojure-align-cond-forms)
1383+ 'symbols )))))
1384+ (cdr clojure--align-search-regexp-cache)))
1385+
13631386(defcustom clojure-align-binding-forms
13641387 '(" let" " when-let" " when-some" " if-let" " if-some" " binding" " loop"
13651388 " doseq" " for" " with-open" " with-local-vars" " with-redefs" )
@@ -1440,14 +1463,7 @@ Place point as in `clojure--position-for-alignment'."
14401463 (let ((found))
14411464 (while (and (not found)
14421465 (search-forward-regexp
1443- (concat (when clojure-align-reader-conditionals
1444- (concat clojure--beginning-of-reader-conditional-regexp
1445- " \\ |" ))
1446- " {\\ |("
1447- (regexp-opt
1448- (append clojure-align-binding-forms
1449- clojure-align-cond-forms)
1450- 'symbols ))
1466+ (clojure--align-search-regexp)
14511467 end 'noerror ))
14521468
14531469 (let ((ppss (syntax-ppss )))
0 commit comments