diff options
| author | Yuan Fu <casouri@gmail.com> | 2025-09-18 22:09:13 -0700 |
|---|---|---|
| committer | Yuan Fu <casouri@gmail.com> | 2025-09-18 22:09:13 -0700 |
| commit | 53fd5a4812b77e49d3ab45fc16bb2998abaf1d86 (patch) | |
| tree | 8fc72fc802c52a88d5c2a42b3da2b9be5a333ffa | |
| parent | af897a63fb14f98c0e897e1ce09f052bc494ec87 (diff) | |
Fix expreg point restore (issue#8)externals/expreg
Now when we try to restore point, we also check if point is
within the expanded range. If not, don't restore point.
* expreg.el (expreg--initial-point): Replaced by the new variable.
(expreg--initial-point-and-last-range): New variable.
(expreg--keyboard-quit-advice): Use expreg--initial-point-and-last-range
(expreg-expand):
(expreg-contract): Set expreg--initial-point-and-last-range
| -rw-r--r-- | expreg.el | 25 |
1 files changed, 19 insertions, 6 deletions
@@ -221,19 +221,26 @@ This should be a list of (BEG . END).") "The regions we’ve expanded past. This should be a list of (BEG . END).") -(defvar-local expreg--initial-point nil +(defvar-local expreg--initial-point-and-last-range nil "The point at where the first ‘expreg-expand’ is called. + +And the max range we’ve reached when expanding. +The shape is (POS . (BEG . END)). This is used to restore point when canceling the expansion when ‘expreg-restore-point-on-quit’ is enabled.") (defun expreg--keyboard-quit-advice () "Restores point when ‘keyboard-quit’ is called." (interactive) - (when (and expreg-restore-point-on-quit expreg--initial-point + (when (and expreg-restore-point-on-quit expreg--initial-point-and-last-range (region-active-p) - (eq (marker-buffer expreg--initial-point) (current-buffer))) - (goto-char expreg--initial-point)) - (setq expreg--initial-point nil)) + (eq (marker-buffer (car expreg--initial-point-and-last-range)) + (current-buffer)) + (<= (cadr expreg--initial-point-and-last-range) + (point) + (cddr expreg--initial-point-and-last-range))) + (goto-char (car expreg--initial-point-and-last-range))) + (setq expreg--initial-point-and-last-range nil)) ;;;###autoload (defun expreg-expand () @@ -247,7 +254,7 @@ This is used to restore point when canceling the expansion when (cddr (car expreg--prev-regions))))) (setq-local expreg--next-regions nil) (setq-local expreg--prev-regions nil) - (setq-local expreg--initial-point (point-marker)) + (setq-local expreg--initial-point-and-last-range (cons (point-marker) nil)) (when expreg-restore-point-on-quit ;; We have to add the advice using :before. :after doesn’t work ;; (advice doesn’t get called). ‘set-transient-map’ doesn’t work @@ -287,6 +294,9 @@ This is used to restore point when canceling the expansion when (unless transient-mark-mode (activate-mark)))) + (setcdr expreg--initial-point-and-last-range + (cons (region-beginning) (region-end))) + (when expreg--verbose (message "blame: %s\nnext: %S\nprev: %S" (caar expreg--prev-regions) @@ -303,6 +313,9 @@ This is used to restore point when canceling the expansion when (set-mark (cddr (car expreg--prev-regions))) (goto-char (cadr (car expreg--prev-regions)))) + (setcdr expreg--initial-point-and-last-range + (cons (region-beginning) (region-end))) + (when expreg--verbose (message "next: %S\nprev: %S" expreg--next-regions expreg--prev-regions))) |
