From: Spencer Baugh Date: Tue, 10 Sep 2024 18:18:39 +0000 (-0400) Subject: Move to start of current header in diff-{file,hunk}-prev X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=900ebbc423e17b1fa5e069a3d581820f9070fd22;p=emacs.git 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. (cherry picked from commit e776903b31cf2b2d21d91cbc7d6b7dbc1e9d442f) --- diff --git a/etc/NEWS b/etc/NEWS index 65b7475272a..3273c0a24cf 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -335,6 +335,12 @@ hunk), and then removes the hunk from the diffs. 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 --- diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el index 54c20d20e0d..c05e1f70b9a 100644 --- a/lisp/emacs-lisp/easy-mmode.el +++ b/lisp/emacs-lisp/easy-mmode.el @@ -770,6 +770,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)))))