Simplify alist lookups in align-region

* lisp/align.el (align-region): Simplify alist lookup caching.
This commit is contained in:
Stefan Kangas 2023-09-26 18:42:57 +02:00
parent 9cf1fc49e8
commit cf4778a136

View file

@ -1337,12 +1337,18 @@ aligner would have dealt with are."
(thissep (if rulesep (cdr rulesep) separate))
same (eol 0)
search-start
groups ;; group-c
spacing spacing-c
tab-stop tab-stop-c
repeat repeat-c
valid valid-c
first
(groups (ensure-list (or (cdr (assq 'group rule)) 1)))
(spacing (cdr (assq 'spacing rule)))
(tab-stop (let ((rule-ts (assq 'tab-stop rule)))
(cond (rule-ts
(cdr rule-ts))
((symbolp align-to-tab-stop)
(symbol-value align-to-tab-stop))
(t
align-to-tab-stop))))
(repeat (cdr (assq 'repeat rule)))
(valid (assq 'valid rule))
(first (car groups))
regions index
last-point
save-match-data
@ -1459,44 +1465,12 @@ aligner would have dealt with are."
(if (and (bolp) (> (point) search-start))
(forward-char -1))
;; lookup the `group' attribute the first time
;; that we need it
(unless nil ;; group-c
(setq groups (or (cdr (assq 'group rule)) 1))
(setq groups (ensure-list groups))
(setq first (car groups)))
(unless spacing-c
(setq spacing (cdr (assq 'spacing rule))
spacing-c t))
(unless tab-stop-c
(setq tab-stop
(let ((rule-ts (assq 'tab-stop rule)))
(cond (rule-ts
(cdr rule-ts))
((symbolp align-to-tab-stop)
(symbol-value align-to-tab-stop))
(t
align-to-tab-stop)))
tab-stop-c t))
;; test whether we have found a match on the same
;; line as a previous match
(when (> (point) eol)
(setq same nil)
(align--set-marker eol (line-end-position)))
;; lookup the `repeat' attribute the first time
(or repeat-c
(setq repeat (cdr (assq 'repeat rule))
repeat-c t))
;; lookup the `valid' attribute the first time
(or valid-c
(setq valid (assq 'valid rule)
valid-c t))
;; remember the beginning position of this rule
;; match, and save the match-data, since either
;; the `valid' form, or the code that searches for