From 2d7ec18119a1cc39db30ab8efab45aa7f494a444 Mon Sep 17 00:00:00 2001 From: Jai Flack Date: Wed, 1 Jun 2022 16:16:25 +1000 Subject: [PATCH] Only use the mark for preserving original position when correcting The main motivation for this is to replace gusbrs's contribution for inclusion in GNU ELPA. Functional differences: - It no longer touches the user's mark-ring unless they 'stop so the mark is present where corrections began. - Less twidling with marks to get the right result, it is now only used to return to the start when necessary. --- flyspell-correct.el | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/flyspell-correct.el b/flyspell-correct.el index c661340..b68d8d9 100644 --- a/flyspell-correct.el +++ b/flyspell-correct.el @@ -353,14 +353,14 @@ until all errors in buffer have been addressed." ;; idiomatically done using the opoint arg of ;; `flyspell-correct-word-before-point'. (interactive "d") - ;; push mark when starting - (when (or (not (mark t)) - (/= (mark t) (point))) - (push-mark (point) t)) (let ((original-pos (point)) (target-pos (point)) (hard-move-point) - (mark-opos)) + (original-mark-ring mark-ring) + (preserve-mark)) + (when (or (not (mark t)) + (/= (mark t) (point))) + (push-mark (point) t)) (unwind-protect (save-excursion (let ((incorrect-word-pos)) @@ -406,9 +406,9 @@ until all errors in buffer have been addressed." (when res ;; stop at misspelled word (when (eq (car-safe res) 'stop) - (setq target-pos incorrect-word-pos - hard-move-point t - mark-opos t)) + (setq target-pos incorrect-word-pos) + (setq hard-move-point t) + (setq preserve-mark t)) ;; break from rapid mode (when (or @@ -419,23 +419,15 @@ until all errors in buffer have been addressed." ;; explicit rapid mode disablers (eq (car-safe res) 'break) (eq (car-safe res) 'stop)) - (setq overlay nil)) - - (when (and - ;; don't push mark if there is no change - (not (memq (car-safe res) '(stop break skip))) - (/= (mark t) (point))) - ;; `flyspell-correct-at-point' may move point, use - ;; original `incorrect-word-pos' instead - (push-mark incorrect-word-pos t))))))))) - - (when hard-move-point - (when mark-opos - (push-mark (point) t)) - (goto-char target-pos)) + (setq overlay nil))))))))) + + (if hard-move-point + (goto-char target-pos) + (goto-char (mark t))) ;; We pushed the mark when starting, but if the operation is canceled ;; without any change that mark is redundant and needs to be cleaned-up. - (when (= (mark t) (point)) (pop-mark))))) + (unless preserve-mark + (setq mark-ring original-mark-ring))))) ;;; Overlays