From unknown Sat Aug 16 16:12:50 2025 X-Loop: help-debbugs@gnu.org Subject: bug#73172: [PATCH] Move to start of current header in diff-{file,hunk}-prev Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 10 Sep 2024 18:41:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 73172 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 73172@debbugs.gnu.org Cc: Stefan Monnier , Dmitry Gutov X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.172599361814217 (code B ref -1); Tue, 10 Sep 2024 18:41:02 +0000 Received: (at submit) by debbugs.gnu.org; 10 Sep 2024 18:40:18 +0000 Received: from localhost ([127.0.0.1]:37013 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1so5mj-0003hE-AX for submit@debbugs.gnu.org; Tue, 10 Sep 2024 14:40:18 -0400 Received: from lists.gnu.org ([209.51.188.17]:42850) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1so5mh-0003eV-5K for submit@debbugs.gnu.org; Tue, 10 Sep 2024 14:40:16 -0400 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 1so5ma-00061O-Ry for bug-gnu-emacs@gnu.org; Tue, 10 Sep 2024 14:40:08 -0400 Received: from mxout1.mail.janestreet.com ([38.105.200.78]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1so5mX-0002iP-R7 for bug-gnu-emacs@gnu.org; Tue, 10 Sep 2024 14:40:08 -0400 From: Spencer Baugh Date: Tue, 10 Sep 2024 14:40:04 -0400 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1725993604; bh=HPmXmKrRarZ+CsVvH/qjurQ0MEuROL7BMI26dsEr0YU=; h=From:To:Cc:Subject:Date; b=uwhAT5AdkRX7Yi3d0Ia/eNjucQ7OPfbX8gWAXtpbe5Snm4zsSf68SHC0DqRTGG1Gl Wv+I4DVIrbM82nkIfdu0/MVJcZe2soFQ2iOxqOoopd408AJwSzF+E11MbnsOZ3hSgm mNvG9xW2pidOc+lWvzfrxljSWMY8/uVGKOwMKFXhAjpeJBwAwc+f4clfJo1gMIe8NW XOwJqaaMtt8TxQqkfvjceIMT6S9eGVOVuI8oeGtYJcey0HvKmgNUT/3njGztj0QG1Q +iChcTbCebRDQ5ZDXNylpkO0kyAX2MLIdwzdIjGKMfy3iAVswHV5DlZe/4ihMURmSL ba82ecqp9UOUQ== Received-SPF: pass client-ip=38.105.200.78; envelope-from=sbaugh@janestreet.com; helo=mxout1.mail.janestreet.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) --=-=-= Content-Type: text/plain Tags: patch (The following change is split across two patches; the first one, "move easy-mmode", fixes an unrelated FIXME, which makes the diff in the second patch simpler) 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. Also discussed here: https://lists.gnu.org/archive/html/help-gnu-emacs/2024-08/msg00367.html In GNU Emacs 29.2.50 (build 17, x86_64-pc-linux-gnu, X toolkit, cairo version 1.15.12, Xaw scroll bars) of 2024-09-06 built on igm-qws-u22796a Repository revision: e6d04c06a7eb6ce932b52a346368d02b7a811a00 Repository branch: emacs-29 Windowing system distributor 'The X.Org Foundation', version 11.0.12011000 System Description: Rocky Linux 8.10 (Green Obsidian) Configured using: 'configure --with-x-toolkit=lucid --without-gpm --without-gconf --without-selinux --without-imagemagick --with-modules --with-gif=no --with-cairo --with-rsvg --without-compress-install --with-native-compilation=aot --with-tree-sitter PKG_CONFIG_PATH=/usr/local/home/garnish/libtree-sitter/0.22.6-1/lib/pkgconfig/' --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Move-easy-mmode-define-navigation-logic-to-helper-fu.patch >From 93f50388bda9f986a5aa8e51378793031cfdce05 Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Tue, 10 Sep 2024 13:46:18 -0400 Subject: [PATCH] Move easy-mmode-define-navigation logic to helper functions The functions defined by easy-mmode-define-navigation are useful even if the easy-mmode-define-navigation macro is not used. Let's take a step towards exposing them by moving them out as helpers. This also makes the macro much easier to modify and work on. * lisp/emacs-lisp/easy-mmode.el (easy-mmode--prev) (easy-mmode--next): Add. (easy-mmode-define-navigation): Use easy-mmode--prev and easy-mmode--next. --- lisp/emacs-lisp/easy-mmode.el | 86 ++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el index a140027839e..d3dcab899d6 100644 --- a/lisp/emacs-lisp/easy-mmode.el +++ b/lisp/emacs-lisp/easy-mmode.el @@ -763,6 +763,48 @@ easy-mmode-defsyntax ;;; easy-mmode-define-navigation ;;; +(defun easy-mmode--prev (re name count &optional endfun narrowfun) + "Go to the previous COUNT'th occurence of RE. + +If none, error with NAME. + +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))))) + (unless (re-search-backward re nil t count) + (user-error "No previous %s" name)) + (when re-narrow (funcall narrowfun))))) + +(defun easy-mmode--next (re name count &optional endfun narrowfun) + "Go to the next COUNT'th occurence of RE. + +If none, error with NAME. + +ENDFUN and NARROWFUN are treated like in `easy-mmode-define-navigation'." + (unless count (setq count 1)) + (if (< count 0) (easy-mmode--prev re name (- count) endfun narrowfun) + (if (looking-at re) (setq count (1+ count))) + (let ((re-narrow (and narrowfun (prog1 (buffer-narrowed-p) (widen))))) + (if (not (re-search-forward re nil t count)) + (if (looking-at re) + (goto-char (or (if endfun (funcall endfun)) (point-max))) + (user-error "No next %s" name)) + (goto-char (match-beginning 0)) + (when (and (eq (current-buffer) (window-buffer)) + (called-interactively-p 'interactive)) + (let ((endpt (or (save-excursion + (if endfun (funcall endfun) + (re-search-forward re nil t 2))) + (point-max)))) + (unless (pos-visible-in-window-p endpt nil t) + (let ((ws (window-start))) + (recenter '(0)) + (if (< (window-start) ws) + ;; recenter scrolled in the wrong direction! + (set-window-start nil ws))))))) + (when re-narrow (funcall narrowfun))))) + (defmacro easy-mmode-define-navigation (base re &optional name endfun narrowfun &rest body) "Define BASE-next and BASE-prev to navigate in the buffer. @@ -780,53 +822,23 @@ easy-mmode-define-navigation (let* ((base-name (symbol-name base)) (prev-sym (intern (concat base-name "-prev"))) (next-sym (intern (concat base-name "-next"))) - (when-narrowed - (lambda (body) - (if (null narrowfun) body - `(let ((was-narrowed (prog1 (buffer-narrowed-p) (widen)))) - ,body - (when was-narrowed (funcall #',narrowfun))))))) + (endfun (when endfun `#',endfun)) + (narrowfun (when narrowfun `#',narrowfun))) (unless name (setq name base-name)) - ;; FIXME: Move most of those functions's bodies to helper functions! `(progn (defun ,next-sym (&optional count) ,(format "Go to the next COUNT'th %s. Interactively, COUNT is the prefix numeric argument, and defaults to 1." name) (interactive "p") - (unless count (setq count 1)) - (if (< count 0) (,prev-sym (- count)) - (if (looking-at ,re) (setq count (1+ count))) - ,(funcall when-narrowed - `(if (not (re-search-forward ,re nil t count)) - (if (looking-at ,re) - (goto-char (or ,(if endfun `(funcall #',endfun)) (point-max))) - (user-error "No next %s" ,name)) - (goto-char (match-beginning 0)) - (when (and (eq (current-buffer) (window-buffer)) - (called-interactively-p 'interactive)) - (let ((endpt (or (save-excursion - ,(if endfun `(funcall #',endfun) - `(re-search-forward ,re nil t 2))) - (point-max)))) - (unless (pos-visible-in-window-p endpt nil t) - (let ((ws (window-start))) - (recenter '(0)) - (if (< (window-start) ws) - ;; recenter scrolled in the wrong direction! - (set-window-start nil ws)))))))) - ,@body)) + (easy-mmode--next ,re ,name count ,endfun ,narrowfun) + ,@body) (put ',next-sym 'definition-name ',base) (defun ,prev-sym (&optional count) ,(format "Go to the previous COUNT'th %s. -Interactively, COUNT is the prefix numeric argument, and defaults to 1." - (or name base-name)) +Interactively, COUNT is the prefix numeric argument, and defaults to 1." name) (interactive "p") - (unless count (setq count 1)) - (if (< count 0) (,next-sym (- count)) - ,(funcall when-narrowed - `(unless (re-search-backward ,re nil t count) - (user-error "No previous %s" ,name))) - ,@body)) + (easy-mmode--prev ,re ,name count ,endfun ,narrowfun) + ,@body) (put ',prev-sym 'definition-name ',base)))) ;; When deleting these two, also delete them from loaddefs-gen.el. -- 2.39.3 --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Move-to-start-of-current-header-in-diff-file-hunk-pr.patch >From 3bf96598caae3746001fdd5d4f4a4d5a14bdf717 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. --- lisp/emacs-lisp/easy-mmode.el | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 --=-=-=-- From unknown Sat Aug 16 16:12:50 2025 X-Loop: help-debbugs@gnu.org Subject: bug#73172: [PATCH] Move to start of current header in diff-{file, hunk}-prev Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 13 Sep 2024 00:30:01 +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 To: Spencer Baugh , 73172@debbugs.gnu.org Cc: Stefan Monnier Received: via spool by 73172-submit@debbugs.gnu.org id=B73172.172618734416902 (code B ref 73172); Fri, 13 Sep 2024 00:30:01 +0000 Received: (at 73172) by debbugs.gnu.org; 13 Sep 2024 00:29:04 +0000 Received: from localhost ([127.0.0.1]:42112 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1souBM-0004OY-8z for submit@debbugs.gnu.org; Thu, 12 Sep 2024 20:29:04 -0400 Received: from fout2-smtp.messagingengine.com ([103.168.172.145]:48325) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1souBJ-0004O0-Ef for 73172@debbugs.gnu.org; Thu, 12 Sep 2024 20:29:02 -0400 Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.phl.internal (Postfix) with ESMTP id DC3FA1380488; Thu, 12 Sep 2024 20:28:46 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Thu, 12 Sep 2024 20:28:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1726187326; x=1726273726; bh=+UmMn2o6hAfyoro9AhjepfEeJ6TBOmOelrQDYFBbmFY=; b= AMrpuML+HG0pYQ09WtNryUxuxe3qFvgvt8sw9my0L3AI54/Mmfsk4/YTRR04eu4f FMEjQAWgnfXKzC6nGVDxAfXXxdXzFd1u4cUfThyhZt71BxuYXbT/Mi8gkLn1Dmat eevMRrff+5NjOIpDib2Q9nhA27SlduYlxrQBQw788LaxHAJ2mgXcVuz4Rz6atJdy 1tAoLDUshIt0uJDFJ4sYbhy64M5D1hYyi2LTEndoRuUQ8mcFdJ2kyw6ghvALsRmM OSAfaSeIhJKcosOQjey2xmCyDYvTQerctZpvT9Padod6BO0GaTXcQgYKktgwUwwE d1ioOkPoE1aIbDHn9XZOwA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1726187326; x= 1726273726; bh=+UmMn2o6hAfyoro9AhjepfEeJ6TBOmOelrQDYFBbmFY=; b=G QoyRuYg/nbZrI+A0la3sRBw1d5FDaPEnIOjBTFW9PE02EnBqq3/8M6HEZZbTQOgA /ZXK+QE54Ro/0vQt9Z4vFQPBS8QpoeLubXosRWeTnwEq+UE1KmoigqKnzy2YxmfS OxLriTBJZB6GOZFgVd3OkUaffv5nu3PnC0K7QFJp0KAIq9ANtqdp5gloGoAlqFMB Q4x6suTSkOgp1zgRs4bUMoJPeyYW6ixdjo/K2kVqjwpqvwq4cQ65OsaCq1GeuI6T I04bG/IiOTVtJHl9ijYVFldNmiVuBcuopJ2Ft20eLFLporlG//FZbYIcyYAQrsv6 2bEcGkG+qpnVxfNd+3yoA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudejgedgfeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtvdej necuhfhrohhmpeffmhhithhrhicuifhuthhovhcuoegumhhithhrhiesghhuthhovhdrug gvvheqnecuggftrfgrthhtvghrnhepffeifedvleeukedtgfelieegudfgveekfeejveej ffetffeuueeugefhveeiuddvnecuffhomhgrihhnpehgnhhurdhorhhgnecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepughmihhtrhihsehguhht ohhvrdguvghvpdhnsggprhgtphhtthhopeefpdhmohguvgepshhmthhpohhuthdprhgtph htthhopehssggruhhghhesjhgrnhgvshhtrhgvvghtrdgtohhmpdhrtghpthhtohepjeef udejvdesuggvsggsuhhgshdrghhnuhdrohhrghdprhgtphhtthhopehmohhnnhhivghrse hirhhordhumhhonhhtrhgvrghlrdgtrg X-ME-Proxy: Feedback-ID: i07de48aa:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Sep 2024 20:28:45 -0400 (EDT) Message-ID: <4dbaac34-a1cc-4d4c-839c-bda74001e4b5@gutov.dev> Date: Fri, 13 Sep 2024 03:28:43 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird References: Content-Language: en-US From: Dmitry Gutov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Hi Spencer and Stefan, On 10/09/2024 21:40, Spencer Baugh via Bug reports for GNU Emacs, the Swiss army knife of text editors wrote: > (The following change is split across two patches; the first one, "move > easy-mmode", fixes an unrelated FIXME, which makes the diff in the > second patch simpler) > > 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. > > Also discussed here: > https://lists.gnu.org/archive/html/help-gnu-emacs/2024-08/msg00367.html Patch#1 seems unequivocally a good thing (easier code iteration) 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. There aren't many in-tree callers of easy-mmode-define-navigation (diff-mode, log-view, smerge and, uh, cvs-status), and few 3rd party callers, so this seems low-impact. diff-hl-mode is not affected either because it only uses diff-hunk-next, not diff-hunk-prev. From unknown Sat Aug 16 16:12:50 2025 X-Loop: help-debbugs@gnu.org Subject: bug#73172: [PATCH] Move to start of current header in diff-{file,hunk}-prev Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 19 Sep 2024 18:42: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 To: Dmitry Gutov Cc: Stefan Monnier , 73172@debbugs.gnu.org Received: via spool by 73172-submit@debbugs.gnu.org id=B73172.172677131931212 (code B ref 73172); Thu, 19 Sep 2024 18:42:02 +0000 Received: (at 73172) by debbugs.gnu.org; 19 Sep 2024 18:41:59 +0000 Received: from localhost ([127.0.0.1]:33502 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1srM6J-00087L-57 for submit@debbugs.gnu.org; Thu, 19 Sep 2024 14:41:59 -0400 Received: from mxout6.mail.janestreet.com ([64.215.233.21]:48681) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1srM6E-000871-Mn for 73172@debbugs.gnu.org; Thu, 19 Sep 2024 14:41:57 -0400 From: Spencer Baugh In-Reply-To: <4dbaac34-a1cc-4d4c-839c-bda74001e4b5@gutov.dev> (Dmitry Gutov's message of "Fri, 13 Sep 2024 03:28:43 +0300") References: <4dbaac34-a1cc-4d4c-839c-bda74001e4b5@gutov.dev> Date: Thu, 19 Sep 2024 14:41:31 -0400 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1726771291; bh=B+wYPV0WHewu6MwQ5GMIOL67RdrlExXS2bb13gUtbG8=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=GLgz9GpBgVB38OrkVHVBgwtGFV/2il+r5LZ/cFtPQAGoe50zrFywNWMkSeIRaOelU Tdqtb0Thiw3ZyfnHroEW0VoysfsJFMlhecDgLs45CCfdI7ZOdn4ha5t9jVcJG0CIiK FyYo2C15dyJkTy8g2SeqkQXD7O/lMB/fDXA9v5zBXEPgI9WXrOVHFjwAb5DF62CRzG hHLn37ibkzj19ndmBFb+j9dUoM1zkBDzaopWUJmdpImNgJajwmdDDT7u7tY09SBsKJ gckfs55GsyqKewY5aPt7SOYFlKGWLpK7mfiXVGEvomYru6LcCXo84LGJhfIXWZjGoB du3hFlUUYceJg== X-Spam-Score: -0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Dmitry Gutov writes: > Hi Spencer and Stefan, > > On 10/09/2024 21:40, Spencer Baugh via Bug reports for GNU Emacs, the > Swiss army knife of text editors wrote: > >> (The following change is split across two patches; the first one, "move >> easy-mmode", fixes an unrelated FIXME, which makes the diff in the >> second patch simpler) >> 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. >> Also discussed here: >> https://lists.gnu.org/archive/html/help-gnu-emacs/2024-08/msg00367.html > > Patch#1 seems unequivocally a good thing (easier code iteration) BTW, if we want to go ahead and install that patch on its own, that would be fine with me. > 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). > There aren't many in-tree callers of easy-mmode-define-navigation > (diff-mode, log-view, smerge and, uh, cvs-status), and few 3rd party > callers, so this seems low-impact. diff-hl-mode is not affected either > because it only uses diff-hunk-next, not diff-hunk-prev. Yep. I think it will be a nice improvement for those few other commands as well. From unknown Sat Aug 16 16:12:50 2025 X-Loop: help-debbugs@gnu.org Subject: bug#73172: [PATCH] Move to start of current header in diff-{file,hunk}-prev Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 19 Sep 2024 20:47: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 To: Spencer Baugh Cc: Stefan Monnier , 73172@debbugs.gnu.org Received: via spool by 73172-submit@debbugs.gnu.org id=B73172.172677879224169 (code B ref 73172); Thu, 19 Sep 2024 20:47:02 +0000 Received: (at 73172) by debbugs.gnu.org; 19 Sep 2024 20:46:32 +0000 Received: from localhost ([127.0.0.1]:33586 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1srO2p-0006Hl-M4 for submit@debbugs.gnu.org; Thu, 19 Sep 2024 16:46:31 -0400 Received: from fout7-smtp.messagingengine.com ([103.168.172.150]:51637) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1srO2l-0006HR-R2 for 73172@debbugs.gnu.org; Thu, 19 Sep 2024 16:46:30 -0400 Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfout.phl.internal (Postfix) with ESMTP id 6ED2E138022F; Thu, 19 Sep 2024 16:46:04 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-09.internal (MEProxy); Thu, 19 Sep 2024 16:46:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1726778764; x=1726865164; bh=swouBHHbOUfqbDVmbAraasxm9Jq5glfdCIwQ2sDOrlU=; b= OVnKMcjzMyvoHZFr13JpGTBrikqU5RnxfTQANf3OfwPXs2P22rJ8qjDIZakgopxJ /uLELQ+BKGXVJyxHGJQWD32wMQrylV/fcBE3XLOPb1rr/KoqIAai0LS4zTXmaA0M S9vXEWn0+eCYXxL3DDauco11r85Ng1M4ISqTlsrW4P3s0sZMYnkfBESslkZ88gIX cVKMWhHNcb2ucC4cnrKHzBW0n/KM5fgtR3UC/32Izgmt19rYgRDKsZAtJve/fKfu CHeucCJGEVMX+p3hYTBSmVhhhrormCqhvn0C6xIFPxvJrRbKLa+IdB0d8LOmr+cV 1RDyNNC6wtxPGvy5FSk5vA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1726778764; x= 1726865164; bh=swouBHHbOUfqbDVmbAraasxm9Jq5glfdCIwQ2sDOrlU=; b=I gXuxq4mmdJ2MkcJKB3yOTcNodAXY84cwCyym9O4MLCEcL00tAvkTpqZkLO0lzv0R RqFTTCpkIgEFt5HI/vbPCFqTC5nfr7Gmk8plCl7v3DNKu8+0qOpT80vywbHnnBqr VgvFzbBKshSB2okApF2P+utJeUB37t5mJfS9reiqwq9e+iXbhhMa+FtjHLxBi2QT V040wyAkrm4l4GlDWpj3fphTg8+XtxzeKBSG1+HK1Qq/mK3Ax4DaiMhJJSv6ACnI 1OOD0PeN948c512bsRr78a5rVfmaQK3DnwItAWQE2xuy8Ra/2CXukEjG6pzANbkv iOV7TS8AxFBdLmd1fiJJA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudeluddgudehgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefkffggfgfuvfevfhfhjggtgfesthejredttddv jeenucfhrhhomhepffhmihhtrhihucfiuhhtohhvuceoughmihhtrhihsehguhhtohhvrd guvghvqeenucggtffrrghtthgvrhhnpeffieefvdelueektdfgleeigedugfevkeefjeev jeffteffueeuueeghfevieduvdenucffohhmrghinhepghhnuhdrohhrghenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegumhhithhrhiesghhu thhovhdruggvvhdpnhgspghrtghpthhtohepfedpmhhouggvpehsmhhtphhouhhtpdhrtg hpthhtohepshgsrghughhhsehjrghnvghsthhrvggvthdrtghomhdprhgtphhtthhopeej fedujedvseguvggssghughhsrdhgnhhurdhorhhgpdhrtghpthhtohepmhhonhhnihgvrh esihhrohdruhhmohhnthhrvggrlhdrtggr X-ME-Proxy: Feedback-ID: i07de48aa:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 19 Sep 2024 16:46:02 -0400 (EDT) Message-ID: Date: Thu, 19 Sep 2024 23:46:00 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird References: <4dbaac34-a1cc-4d4c-839c-bda74001e4b5@gutov.dev> Content-Language: en-US From: Dmitry Gutov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) On 19/09/2024 21:41, Spencer Baugh wrote: >>> Also discussed here: >>> https://lists.gnu.org/archive/html/help-gnu-emacs/2024-08/msg00367.html >> >> Patch#1 seems unequivocally a good thing (easier code iteration) > > BTW, if we want to go ahead and install that patch on its own, that > would be fine with me. I think we'll wait a week or so for somebody to protest, and install both if nobody does. >> 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. From unknown Sat Aug 16 16:12:50 2025 X-Loop: help-debbugs@gnu.org Subject: bug#73172: [PATCH] Move to start of current header in diff-{file, hunk}-prev Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 20 Sep 2024 06:18: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 To: Dmitry Gutov Cc: sbaugh@janestreet.com, monnier@iro.umontreal.ca, 73172@debbugs.gnu.org Received: via spool by 73172-submit@debbugs.gnu.org id=B73172.172681306014656 (code B ref 73172); Fri, 20 Sep 2024 06:18:02 +0000 Received: (at 73172) by debbugs.gnu.org; 20 Sep 2024 06:17:40 +0000 Received: from localhost ([127.0.0.1]:33893 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1srWxX-0003oJ-Hv for submit@debbugs.gnu.org; Fri, 20 Sep 2024 02:17:39 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44938) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1srWxV-0003o1-FO for 73172@debbugs.gnu.org; Fri, 20 Sep 2024 02:17:38 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1srWx6-0004nJ-Pt; Fri, 20 Sep 2024 02:17:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=uVHII5X2GP4wp0vqbuPofAjCXqIZl3IFGnX5CGljlPI=; b=gG9IOkbaBhMP SGlTWTjQcmO6/DHZKuXKE3Y9TYL/rA2Om3IbG93yTNx6rwgGqm9ltcU+wIBtMvWpqpTin8YrfFm// 3jvy23++o2OVO9ORCqHb+dMOwXGUjxCzReVMjW9bhCZmETrccBUzoUdTmUfQyR1dC/PaNg1bTAMsf xm8hoIdOL5X+Ppt2AIxt1jmjiWx0wpObTnyCEuv6cnQf6Fopzn6pC8035+7SnXJR2oQzRVRJehEtR h5oDF3NFCl1jXHoi52aPcookEKtrzKgxFlNcF5fQj0BkEiJpJ/vSxtv3zdPDVbRZAWFYr4bXq+tFw CrfT+k1jseU3hOkAqHvmbg==; Date: Fri, 20 Sep 2024 09:17:02 +0300 Message-Id: <86wmj67std.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: (message from Dmitry Gutov on Thu, 19 Sep 2024 23:46:00 +0300) References: <4dbaac34-a1cc-4d4c-839c-bda74001e4b5@gutov.dev> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > 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. From unknown Sat Aug 16 16:12:50 2025 X-Loop: help-debbugs@gnu.org Subject: bug#73172: [PATCH] Move to start of current header in diff-{file,hunk}-prev 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 To: Eli Zaretskii Cc: Dmitry Gutov , monnier@iro.umontreal.ca, 73172@debbugs.gnu.org Received: via spool by 73172-submit@debbugs.gnu.org id=B73172.17268531242201 (code B ref 73172); Fri, 20 Sep 2024 17:26:02 +0000 Received: (at 73172) by debbugs.gnu.org; 20 Sep 2024 17:25:24 +0000 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 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 From: Spencer Baugh In-Reply-To: <86wmj67std.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 20 Sep 2024 09:17:02 +0300") References: <4dbaac34-a1cc-4d4c-839c-bda74001e4b5@gutov.dev> <86wmj67std.fsf@gnu.org> Date: Fri, 20 Sep 2024 13:24:55 -0400 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" 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-Spam-Score: -0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --=-=-= 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 --=-=-=-- From unknown Sat Aug 16 16:12:50 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Spencer Baugh Subject: bug#73172: closed (Re: bug#73172: [PATCH] Move to start of current header in diff-{file,hunk}-prev) Message-ID: References: X-Gnu-PR-Message: they-closed 73172 X-Gnu-PR-Package: emacs X-Gnu-PR-Keywords: patch Reply-To: 73172@debbugs.gnu.org Date: Fri, 27 Sep 2024 01:33:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1727400782-22942-1" This is a multi-part message in MIME format... ------------=_1727400782-22942-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #73172: [PATCH] Move to start of current header in diff-{file,hunk}-prev which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 73172@debbugs.gnu.org. --=20 73172: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D73172 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1727400782-22942-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 73172-done) by debbugs.gnu.org; 27 Sep 2024 01:32:42 +0000 Received: from localhost ([127.0.0.1]:33613 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1stzqb-0005wy-Lb for submit@debbugs.gnu.org; Thu, 26 Sep 2024 21:32:41 -0400 Received: from fout-a1-smtp.messagingengine.com ([103.168.172.144]:38805) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1stzqZ-0005wY-Pj for 73172-done@debbugs.gnu.org; Thu, 26 Sep 2024 21:32:40 -0400 Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfout.phl.internal (Postfix) with ESMTP id 2EA16138014F; Thu, 26 Sep 2024 21:32:06 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-10.internal (MEProxy); Thu, 26 Sep 2024 21:32:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1727400726; x=1727487126; bh=7DoTEHqJETqZM3b8PmQTtkfStkVeQ5vNukhbgu8HGqM=; b= f16hvX7Ayb6XjkOe8yS/wE493ozaW2E3mTVv2419WTal4TghM9u0wMXI/iHeakDW Br3l4CHMVsmMpbydVnKRba3lUC3w2vv/JfNhX7V9vmzQFL21JTZXj21iO+rFWoR4 0B4KGdoj0HPhs6yf5182WGpcNxXZbGKYMChTeo4l0K+MmBWNt9iBRu472wxJRRkM bL7hmrDVhbCnZ+oJf+pgPuQ1s1f/e4GwZxfHyEy6HeaUXyiN7Aorz0GZd9oEaTIE ZFcc1WBfheYoT9lE5G4rc1ccvmWRtTkpfG+ienCUWJN14H862Cu/kjWRn0afYvUB RDdiB1xcGt9BW3Y0c4z+aQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1727400726; x= 1727487126; bh=7DoTEHqJETqZM3b8PmQTtkfStkVeQ5vNukhbgu8HGqM=; b=a 1Mu0QeATdrfUvWWstikXpDJUPR/KlUnHUtZqQS8L1il0vq17wPgS/VBhX6k3sHjb 2yw6Mq/MwzshrHoKWq6nwX+3aXYV8PWMPJ3RVA58KnO02lpToXGKEGyHpCU2xLjr AQW/g6ua0zDK4A1G0LowG4Xeg/JwP6PF6/dzQy/avl1JXvWWftpWtfSD3y2eHz/L in+ymikv6rnl32Al1Iytc0DKqj5TBKJTa/bSjq2M4OBh8a4Sohj3y6l3s5+dPn1D fMtmMa6aS8xo+6t/CqCQG/0uNAkoSZY0P007JAOVmJzdah9ugciUBjq4FPs9LCh+ V2Fc5tx3PWTxI9wyjzvmg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddtkedggeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtvdej necuhfhrohhmpeffmhhithhrhicuifhuthhovhcuoegumhhithhrhiesghhuthhovhdrug gvvheqnecuggftrfgrthhtvghrnhepteduleejgeehtefgheegjeekueehvdevieekueef tddvtdevfefhvdevgedujeehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepughmihhtrhihsehguhhtohhvrdguvghvpdhnsggprhgtphhtthho peegpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehssggruhhghhesjhgrnhgvsh htrhgvvghtrdgtohhmpdhrtghpthhtohepvghlihiisehgnhhurdhorhhgpdhrtghpthht ohepmhhonhhnihgvrhesihhrohdruhhmohhnthhrvggrlhdrtggrpdhrtghpthhtohepje efudejvddqughonhgvseguvggssghughhsrdhgnhhurdhorhhg X-ME-Proxy: Feedback-ID: i07de48aa:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Sep 2024 21:32:04 -0400 (EDT) Message-ID: Date: Fri, 27 Sep 2024 04:32:01 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: bug#73172: [PATCH] Move to start of current header in diff-{file,hunk}-prev To: Spencer Baugh , Eli Zaretskii References: <4dbaac34-a1cc-4d4c-839c-bda74001e4b5@gutov.dev> <86wmj67std.fsf@gnu.org> Content-Language: en-US From: Dmitry Gutov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 73172-done Cc: 73172-done@debbugs.gnu.org, monnier@iro.umontreal.ca X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) On 20/09/2024 20:24, Spencer Baugh wrote: > Updated patch to add to NEWS. Thanks! Now pushed to master, both changes. Let's see if anybody noticed the difference. I've taken the liberty to rewrite the NEWS entry a little so it makes more sense to me, but please feel free to update it more. ------------=_1727400782-22942-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 10 Sep 2024 18:40:18 +0000 Received: from localhost ([127.0.0.1]:37013 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1so5mj-0003hE-AX for submit@debbugs.gnu.org; Tue, 10 Sep 2024 14:40:18 -0400 Received: from lists.gnu.org ([209.51.188.17]:42850) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1so5mh-0003eV-5K for submit@debbugs.gnu.org; Tue, 10 Sep 2024 14:40:16 -0400 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 1so5ma-00061O-Ry for bug-gnu-emacs@gnu.org; Tue, 10 Sep 2024 14:40:08 -0400 Received: from mxout1.mail.janestreet.com ([38.105.200.78]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1so5mX-0002iP-R7 for bug-gnu-emacs@gnu.org; Tue, 10 Sep 2024 14:40:08 -0400 From: Spencer Baugh To: bug-gnu-emacs@gnu.org Subject: [PATCH] Move to start of current header in diff-{file,hunk}-prev Date: Tue, 10 Sep 2024 14:40:04 -0400 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1725993604; bh=HPmXmKrRarZ+CsVvH/qjurQ0MEuROL7BMI26dsEr0YU=; h=From:To:Cc:Subject:Date; b=uwhAT5AdkRX7Yi3d0Ia/eNjucQ7OPfbX8gWAXtpbe5Snm4zsSf68SHC0DqRTGG1Gl Wv+I4DVIrbM82nkIfdu0/MVJcZe2soFQ2iOxqOoopd408AJwSzF+E11MbnsOZ3hSgm mNvG9xW2pidOc+lWvzfrxljSWMY8/uVGKOwMKFXhAjpeJBwAwc+f4clfJo1gMIe8NW XOwJqaaMtt8TxQqkfvjceIMT6S9eGVOVuI8oeGtYJcey0HvKmgNUT/3njGztj0QG1Q +iChcTbCebRDQ5ZDXNylpkO0kyAX2MLIdwzdIjGKMfy3iAVswHV5DlZe/4ihMURmSL ba82ecqp9UOUQ== Received-SPF: pass client-ip=38.105.200.78; envelope-from=sbaugh@janestreet.com; helo=mxout1.mail.janestreet.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit Cc: Stefan Monnier , Dmitry Gutov X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) --=-=-= Content-Type: text/plain Tags: patch (The following change is split across two patches; the first one, "move easy-mmode", fixes an unrelated FIXME, which makes the diff in the second patch simpler) 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. Also discussed here: https://lists.gnu.org/archive/html/help-gnu-emacs/2024-08/msg00367.html In GNU Emacs 29.2.50 (build 17, x86_64-pc-linux-gnu, X toolkit, cairo version 1.15.12, Xaw scroll bars) of 2024-09-06 built on igm-qws-u22796a Repository revision: e6d04c06a7eb6ce932b52a346368d02b7a811a00 Repository branch: emacs-29 Windowing system distributor 'The X.Org Foundation', version 11.0.12011000 System Description: Rocky Linux 8.10 (Green Obsidian) Configured using: 'configure --with-x-toolkit=lucid --without-gpm --without-gconf --without-selinux --without-imagemagick --with-modules --with-gif=no --with-cairo --with-rsvg --without-compress-install --with-native-compilation=aot --with-tree-sitter PKG_CONFIG_PATH=/usr/local/home/garnish/libtree-sitter/0.22.6-1/lib/pkgconfig/' --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Move-easy-mmode-define-navigation-logic-to-helper-fu.patch >From 93f50388bda9f986a5aa8e51378793031cfdce05 Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Tue, 10 Sep 2024 13:46:18 -0400 Subject: [PATCH] Move easy-mmode-define-navigation logic to helper functions The functions defined by easy-mmode-define-navigation are useful even if the easy-mmode-define-navigation macro is not used. Let's take a step towards exposing them by moving them out as helpers. This also makes the macro much easier to modify and work on. * lisp/emacs-lisp/easy-mmode.el (easy-mmode--prev) (easy-mmode--next): Add. (easy-mmode-define-navigation): Use easy-mmode--prev and easy-mmode--next. --- lisp/emacs-lisp/easy-mmode.el | 86 ++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el index a140027839e..d3dcab899d6 100644 --- a/lisp/emacs-lisp/easy-mmode.el +++ b/lisp/emacs-lisp/easy-mmode.el @@ -763,6 +763,48 @@ easy-mmode-defsyntax ;;; easy-mmode-define-navigation ;;; +(defun easy-mmode--prev (re name count &optional endfun narrowfun) + "Go to the previous COUNT'th occurence of RE. + +If none, error with NAME. + +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))))) + (unless (re-search-backward re nil t count) + (user-error "No previous %s" name)) + (when re-narrow (funcall narrowfun))))) + +(defun easy-mmode--next (re name count &optional endfun narrowfun) + "Go to the next COUNT'th occurence of RE. + +If none, error with NAME. + +ENDFUN and NARROWFUN are treated like in `easy-mmode-define-navigation'." + (unless count (setq count 1)) + (if (< count 0) (easy-mmode--prev re name (- count) endfun narrowfun) + (if (looking-at re) (setq count (1+ count))) + (let ((re-narrow (and narrowfun (prog1 (buffer-narrowed-p) (widen))))) + (if (not (re-search-forward re nil t count)) + (if (looking-at re) + (goto-char (or (if endfun (funcall endfun)) (point-max))) + (user-error "No next %s" name)) + (goto-char (match-beginning 0)) + (when (and (eq (current-buffer) (window-buffer)) + (called-interactively-p 'interactive)) + (let ((endpt (or (save-excursion + (if endfun (funcall endfun) + (re-search-forward re nil t 2))) + (point-max)))) + (unless (pos-visible-in-window-p endpt nil t) + (let ((ws (window-start))) + (recenter '(0)) + (if (< (window-start) ws) + ;; recenter scrolled in the wrong direction! + (set-window-start nil ws))))))) + (when re-narrow (funcall narrowfun))))) + (defmacro easy-mmode-define-navigation (base re &optional name endfun narrowfun &rest body) "Define BASE-next and BASE-prev to navigate in the buffer. @@ -780,53 +822,23 @@ easy-mmode-define-navigation (let* ((base-name (symbol-name base)) (prev-sym (intern (concat base-name "-prev"))) (next-sym (intern (concat base-name "-next"))) - (when-narrowed - (lambda (body) - (if (null narrowfun) body - `(let ((was-narrowed (prog1 (buffer-narrowed-p) (widen)))) - ,body - (when was-narrowed (funcall #',narrowfun))))))) + (endfun (when endfun `#',endfun)) + (narrowfun (when narrowfun `#',narrowfun))) (unless name (setq name base-name)) - ;; FIXME: Move most of those functions's bodies to helper functions! `(progn (defun ,next-sym (&optional count) ,(format "Go to the next COUNT'th %s. Interactively, COUNT is the prefix numeric argument, and defaults to 1." name) (interactive "p") - (unless count (setq count 1)) - (if (< count 0) (,prev-sym (- count)) - (if (looking-at ,re) (setq count (1+ count))) - ,(funcall when-narrowed - `(if (not (re-search-forward ,re nil t count)) - (if (looking-at ,re) - (goto-char (or ,(if endfun `(funcall #',endfun)) (point-max))) - (user-error "No next %s" ,name)) - (goto-char (match-beginning 0)) - (when (and (eq (current-buffer) (window-buffer)) - (called-interactively-p 'interactive)) - (let ((endpt (or (save-excursion - ,(if endfun `(funcall #',endfun) - `(re-search-forward ,re nil t 2))) - (point-max)))) - (unless (pos-visible-in-window-p endpt nil t) - (let ((ws (window-start))) - (recenter '(0)) - (if (< (window-start) ws) - ;; recenter scrolled in the wrong direction! - (set-window-start nil ws)))))))) - ,@body)) + (easy-mmode--next ,re ,name count ,endfun ,narrowfun) + ,@body) (put ',next-sym 'definition-name ',base) (defun ,prev-sym (&optional count) ,(format "Go to the previous COUNT'th %s. -Interactively, COUNT is the prefix numeric argument, and defaults to 1." - (or name base-name)) +Interactively, COUNT is the prefix numeric argument, and defaults to 1." name) (interactive "p") - (unless count (setq count 1)) - (if (< count 0) (,next-sym (- count)) - ,(funcall when-narrowed - `(unless (re-search-backward ,re nil t count) - (user-error "No previous %s" ,name))) - ,@body)) + (easy-mmode--prev ,re ,name count ,endfun ,narrowfun) + ,@body) (put ',prev-sym 'definition-name ',base)))) ;; When deleting these two, also delete them from loaddefs-gen.el. -- 2.39.3 --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Move-to-start-of-current-header-in-diff-file-hunk-pr.patch >From 3bf96598caae3746001fdd5d4f4a4d5a14bdf717 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. --- lisp/emacs-lisp/easy-mmode.el | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 --=-=-=-- ------------=_1727400782-22942-1--