From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Spencer Baugh via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#73172: [PATCH] Move to start of current header in diff-{file, hunk}-prev Date: Fri, 20 Sep 2024 13:24:55 -0400 Message-ID: References: <4dbaac34-a1cc-4d4c-839c-bda74001e4b5@gutov.dev> <86wmj67std.fsf@gnu.org> Reply-To: Spencer Baugh Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36770"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Dmitry Gutov , monnier@iro.umontreal.ca, 73172@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Sep 20 19:26:19 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1srhOd-0009Oe-8A for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 20 Sep 2024 19:26:19 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1srhO5-00010A-Rr; Fri, 20 Sep 2024 13:25:45 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1srhO3-0000zp-Lq for bug-gnu-emacs@gnu.org; Fri, 20 Sep 2024 13:25:43 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1srhO3-0006YA-Ch for bug-gnu-emacs@gnu.org; Fri, 20 Sep 2024 13:25:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=wAVXh8KOdZ4X+oyZZV85KgpgTk+6erxC4n43yhHvIOg=; b=SKIgR922d8kVURCtratKPaGqfqBkI/J+zF/Nk/yMA+oo4hqmedVbAskE+F+z+xMoosnJ/gBDgDhpGdiTOCDJJP+2W9ba5FerkBp2JBo8hQtZ1gjTf997ciUYfO5FvMhjUjICctiNOQesws/6EeOZ+fAQxjCGxrRgnsiyXo8XsNh4sxYzYxjL+9+/3lVlC/rjdWoaN+kAQ0IaXVSNTg0P/ZSDvMFysqQfVI1Wk5/2uATt6xsFKQMNDtFexvSCKw4AryFIGU6hoxLXak6/mp4SDniaXSUhjEc7zO229Fr7CqGCCPpDw/56XMsODoKHOQnY0ivmIz3uBT5E7Bwzsei1XQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1srhOM-0000gE-Dg for bug-gnu-emacs@gnu.org; Fri, 20 Sep 2024 13:26:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 20 Sep 2024 17:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 73172 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 73172-submit@debbugs.gnu.org id=B73172.17268531242201 (code B ref 73172); Fri, 20 Sep 2024 17:26:02 +0000 Original-Received: (at 73172) by debbugs.gnu.org; 20 Sep 2024 17:25:24 +0000 Original-Received: from localhost ([127.0.0.1]:36290 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1srhNj-0000ZF-E6 for submit@debbugs.gnu.org; Fri, 20 Sep 2024 13:25:24 -0400 Original-Received: from mxout1.mail.janestreet.com ([38.105.200.78]:35909) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1srhNg-0000X2-Hk for 73172@debbugs.gnu.org; Fri, 20 Sep 2024 13:25:21 -0400 In-Reply-To: <86wmj67std.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 20 Sep 2024 09:17:02 +0300") DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1726853096; bh=wAVXh8KOdZ4X+oyZZV85KgpgTk+6erxC4n43yhHvIOg=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=3uJiP3U/+sHqz1HdSP/Q48/8NCsUTXtFFZo5PcuoJrdWQ+Aco3uHX4PXgNejD4Fgs pqpwQYEpmPa59t5+a6lxEf4XQjDP7iCJuRdEWIslf3NbNgp2vZgvkgx7N51GDHEH1x gkBvHDvtowZPCOP2lV3wXAKr/KrAz/jUieW3UEMkvQt+oor/DQs+fhCyr49Pyb33k1 6uZ70L/hs8pOSw87z3fl9W47FDNWz8ZrgIaBNh4jqUSqaIsDxUqxko7HhWTVjiNqnP aIWebQ8uIpyJSsH8G+vVIzbKd9qK7x9OLUC2eDh2fMW+vU35+eMVWda4bh7Y+Hh341 Q0SHziG0INW2A== X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:292132 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> Cc: Stefan Monnier , 73172@debbugs.gnu.org >> Date: Thu, 19 Sep 2024 23:46:00 +0300 >> From: Dmitry Gutov >> >> 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. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Move-to-start-of-current-header-in-diff-file-hunk-pr.patch >From d1481a60734c2ce7228cd356e7e0280e7e66cd34 Mon Sep 17 00:00:00 2001 From: Spencer Baugh 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 --=-=-=--