1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -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

@ -772,6 +772,17 @@ ENDFUN and NARROWFUN are treated like in `easy-mmode-define-navigation'."
(unless count (setq count 1))
(if (< count 0) (easy-mmode--next re name (- count) endfun narrowfun)
(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)
(user-error "No previous %s" name))
(when re-narrow (funcall narrowfun)))))