Skip to content

Commit

Permalink
Simplify alist lookups in align-region
Browse files Browse the repository at this point in the history
* lisp/align.el (align-region): Simplify alist lookup caching.
  • Loading branch information
skangas committed Sep 28, 2023
1 parent 9cf1fc4 commit cf4778a
Showing 1 changed file with 12 additions and 38 deletions.
50 changes: 12 additions & 38 deletions lisp/align.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cf4778a

Please sign in to comment.