From: Spencer Baugh via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Dmitry Gutov <dmitry@gutov.dev>,
monnier@iro.umontreal.ca, 73172@debbugs.gnu.org
Subject: bug#73172: [PATCH] Move to start of current header in diff-{file, hunk}-prev
Date: Fri, 20 Sep 2024 13:24:55 -0400 [thread overview]
Message-ID: <iera5g2grvc.fsf_-_@janestreet.com> (raw)
In-Reply-To: <86wmj67std.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 20 Sep 2024 09:17:02 +0300")
[-- Attachment #1: Type: text/plain, Size: 1838 bytes --]
Eli Zaretskii <eliz@gnu.org> writes:
>> Cc: Stefan Monnier <monnier@iro.umontreal.ca>, 73172@debbugs.gnu.org
>> Date: Thu, 19 Sep 2024 23:46:00 +0300
>> From: Dmitry Gutov <dmitry@gutov.dev>
>>
>> On 19/09/2024 21:41, Spencer Baugh wrote:
>>
>> >> and patch#2 seems good on balance.
>> >>
>> >> It does introduce some backward incompatibility in rare cases where I
>> >> have probably internalized the current behavior already -- for example
>> >> in the vc-print-root-log output pressing 'p' while on the first line
>> >> somewhere between the initial '*' and the end of the date dings with
>> >> "No previous log message", and how will move to bol.
>> >>
>> >> But it might be more consistent anyway, given that the there is no
>> >> ding already if you start out inside the summary text.
>> >
>> > Yes. It's definitely a change in behavior.
>> >
>> > But, if someone has internalized:
>> >
>> > diff-file-prev usually acts like "backward-sexp for files" (it moves
>> > point to the start of the current file), except that if point is in
>> > the header of the first file in the buffer then diff-file-prev does
>> > nothing instead.
>> >
>> > Then I think they'll be happy to be able to discard that knowledge
>> > in favor of:
>> >
>> > diff-file-prev always acts like "backward-sexp for files" (it moves
>> > point to the start of the current file).
>> >
>> > Especially because "does nothing in one weird corner case" is not useful
>> > or deliberate behavior (it's just a bug).
>>
>> Yeah, probably.
>>
>> It kind of indicated "no elements above" right away, which is a tad
>> meaningful, but indeed I struggle to produce a scenario where that would
>> make a big difference.
>
> Please be sure to document all behavior changes in NEWS, if you
> install such changes.
Updated patch to add to NEWS.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Move-to-start-of-current-header-in-diff-file-hunk-pr.patch --]
[-- Type: text/x-patch, Size: 2873 bytes --]
From d1481a60734c2ce7228cd356e7e0280e7e66cd34 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh@janestreet.com>
Date: Tue, 10 Sep 2024 14:18:39 -0400
Subject: [PATCH] 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.
---
etc/NEWS | 6 ++++++
lisp/emacs-lisp/easy-mmode.el | 11 +++++++++++
2 files changed, 17 insertions(+)
diff --git a/etc/NEWS b/etc/NEWS
index 8bd5c7c9515..637a0e63acb 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -304,6 +304,12 @@ according to diffs in the current buffer, but without applying the diffs
to the original text. If the selected range extends a hunk, the
command attempts to look up and copy the text in-between the hunks.
+---
+*** diff-file-prev and diff-hunk-prev reliably move to start of header.
+Previously, diff-file-prev and diff-hunk-prev would move when they were
+in the first header in the file, but not at the start of the header.
+Now they will reliably move to the start of the relevant header.
+
** php-ts-mode
---
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 @@ easy-mmode--prev
(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)))))
--
2.39.3
next prev parent reply other threads:[~2024-09-20 17:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-10 18:40 bug#73172: [PATCH] Move to start of current header in diff-{file, hunk}-prev Spencer Baugh via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-13 0:28 ` Dmitry Gutov
2024-09-19 18:41 ` Spencer Baugh via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-19 20:46 ` Dmitry Gutov
2024-09-20 6:17 ` Eli Zaretskii
2024-09-20 17:24 ` Spencer Baugh via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-09-27 1:32 ` Dmitry Gutov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=iera5g2grvc.fsf_-_@janestreet.com \
--to=bug-gnu-emacs@gnu.org \
--cc=73172@debbugs.gnu.org \
--cc=dmitry@gutov.dev \
--cc=eliz@gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=sbaugh@janestreet.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).