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.
(cherry picked from commit
e776903b31cf2b2d21d91cbc7d6b7dbc1e9d442f)
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'.
+---
+*** 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
---
(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)))))