1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-06 03:40:56 -08:00

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.
This commit is contained in:
Spencer Baugh 2024-09-10 14:18:39 -04:00 committed by Dmitry Gutov
parent da1416fc69
commit e776903b31
2 changed files with 17 additions and 0 deletions

View file

@ -370,6 +370,12 @@ hunk), and then removes the hunk from the diffs.
This is useful to undo or revert changes, committed and uncommitted, when This is useful to undo or revert changes, committed and uncommitted, when
you are in buffers generated by 'C-x v =' and 'C-x v D'. you are in buffers generated by 'C-x v =' and 'C-x v D'.
---
*** diff-file-prev and diff-hunk-prev reliably move to start of header.
Previously, diff-file-prev and diff-hunk-prev would move when point is
after the corresponding file or hunk header, but not when inside it.
Now they will reliably move to the start of the current header.
** php-ts-mode ** php-ts-mode
--- ---

View file

@ -772,6 +772,17 @@ ENDFUN and NARROWFUN are treated like in `easy-mmode-define-navigation'."
(unless count (setq count 1)) (unless count (setq count 1))
(if (< count 0) (easy-mmode--next re name (- count) endfun narrowfun) (if (< count 0) (easy-mmode--next re name (- count) endfun narrowfun)
(let ((re-narrow (and narrowfun (prog1 (buffer-narrowed-p) (widen))))) (let ((re-narrow (and narrowfun (prog1 (buffer-narrowed-p) (widen)))))
;; If point is inside a match for RE, move to its beginning like
;; `backward-sexp' and other movement commands.
(when (and (not (zerop count))
(save-excursion
;; Make sure we're out of the current match if any.
(goto-char (if (re-search-backward re nil t 1)
(match-end 0) (point-min)))
(re-search-forward re nil t 1))
(< (match-beginning 0) (point) (match-end 0)))
(goto-char (match-beginning 0))
(setq count (1- count)))
(unless (re-search-backward re nil t count) (unless (re-search-backward re nil t count)
(user-error "No previous %s" name)) (user-error "No previous %s" name))
(when re-narrow (funcall narrowfun))))) (when re-narrow (funcall narrowfun)))))