diff options
| author | Spencer Baugh | 2024-09-10 14:18:39 -0400 |
|---|---|---|
| committer | Dmitry Gutov | 2024-09-27 04:27:55 +0300 |
| commit | e776903b31cf2b2d21d91cbc7d6b7dbc1e9d442f (patch) | |
| tree | c0752ebde2259d01c64ad3f04c5de191335c4e50 | |
| parent | da1416fc6998718d1e36e32961b4415045949632 (diff) | |
| download | emacs-e776903b31cf2b2d21d91cbc7d6b7dbc1e9d442f.tar.gz emacs-e776903b31cf2b2d21d91cbc7d6b7dbc1e9d442f.zip | |
Move to start of current header in diff-{file,hunk}-prev
If point was after a file or hunk header, the diff-file-prev and
diff-hunk-prev commands would move to the start of that header.
But if point was *within* the header, they would not move, and
would report "No previous file" or "No previous hunk". This
differs from the behavior of most other movement commands,
e.g. backward-sexp or backward-sentence.
This commit fixes diff-file-prev and diff-hunk-prev, as well as
other easy-mmode-define-navigation BASE-prev commands. Now
these commands move to the start of the containing "thing" just
like other movement commands.
* lisp/emacs-lisp/easy-mmode.el (easy-mmode--prev):
Move to start of current match first. (bug#73172)
* etc/NEWS: Document the behavior change.
| -rw-r--r-- | etc/NEWS | 6 | ||||
| -rw-r--r-- | lisp/emacs-lisp/easy-mmode.el | 11 |
2 files changed, 17 insertions, 0 deletions
| @@ -370,6 +370,12 @@ hunk), and then removes the hunk from the diffs. | |||
| 370 | This is useful to undo or revert changes, committed and uncommitted, when | 370 | This is useful to undo or revert changes, committed and uncommitted, when |
| 371 | you are in buffers generated by 'C-x v =' and 'C-x v D'. | 371 | you are in buffers generated by 'C-x v =' and 'C-x v D'. |
| 372 | 372 | ||
| 373 | --- | ||
| 374 | *** diff-file-prev and diff-hunk-prev reliably move to start of header. | ||
| 375 | Previously, diff-file-prev and diff-hunk-prev would move when point is | ||
| 376 | after the corresponding file or hunk header, but not when inside it. | ||
| 377 | Now they will reliably move to the start of the current header. | ||
| 378 | |||
| 373 | ** php-ts-mode | 379 | ** php-ts-mode |
| 374 | 380 | ||
| 375 | --- | 381 | --- |
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el index d3dcab899d6..7a94d832273 100644 --- a/lisp/emacs-lisp/easy-mmode.el +++ b/lisp/emacs-lisp/easy-mmode.el | |||
| @@ -772,6 +772,17 @@ ENDFUN and NARROWFUN are treated like in `easy-mmode-define-navigation'." | |||
| 772 | (unless count (setq count 1)) | 772 | (unless count (setq count 1)) |
| 773 | (if (< count 0) (easy-mmode--next re name (- count) endfun narrowfun) | 773 | (if (< count 0) (easy-mmode--next re name (- count) endfun narrowfun) |
| 774 | (let ((re-narrow (and narrowfun (prog1 (buffer-narrowed-p) (widen))))) | 774 | (let ((re-narrow (and narrowfun (prog1 (buffer-narrowed-p) (widen))))) |
| 775 | ;; If point is inside a match for RE, move to its beginning like | ||
| 776 | ;; `backward-sexp' and other movement commands. | ||
| 777 | (when (and (not (zerop count)) | ||
| 778 | (save-excursion | ||
| 779 | ;; Make sure we're out of the current match if any. | ||
| 780 | (goto-char (if (re-search-backward re nil t 1) | ||
| 781 | (match-end 0) (point-min))) | ||
| 782 | (re-search-forward re nil t 1)) | ||
| 783 | (< (match-beginning 0) (point) (match-end 0))) | ||
| 784 | (goto-char (match-beginning 0)) | ||
| 785 | (setq count (1- count))) | ||
| 775 | (unless (re-search-backward re nil t count) | 786 | (unless (re-search-backward re nil t count) |
| 776 | (user-error "No previous %s" name)) | 787 | (user-error "No previous %s" name)) |
| 777 | (when re-narrow (funcall narrowfun))))) | 788 | (when re-narrow (funcall narrowfun))))) |