GNU bug report logs - #51892
29.0.50; [PATCH] Don't ignore restriction in indent-region-line-by-line

Previous Next

Package: emacs;

Reported by: miha <at> kamnitnik.top

Date: Tue, 16 Nov 2021 12:54:01 UTC

Severity: normal

Tags: patch

Found in version 29.0.50

Fixed in version 29.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 51892 in the body.
You can then email your comments to 51892 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#51892; Package emacs. (Tue, 16 Nov 2021 12:54:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to miha <at> kamnitnik.top:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 16 Nov 2021 12:54:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: miha <at> kamnitnik.top
To: bug-gnu-emacs <at> gnu.org
Subject: 29.0.50; [PATCH] Don't ignore restriction in
 indent-region-line-by-line
Date: Tue, 16 Nov 2021 13:57:59 +0100
[Message part 1 (text/plain, inline)]
Emacs convention is that low-level functions should respect restriction
so that their callers can set restriction according to their needs. For
example, 'c-indent-region' is a lower-level function which respects the
current restriction and 'indent-region' is a higher-level user command
which sets the restriction for lower-level functions, it calls
"(widen)".

'indent-region-line-by-line' is a low-level function on a similar level
as 'c-indent-region'. This patch makes it respect the current
restriction instead of having it call "(widen)".

[0001-Don-t-ignore-restriction-in-indent-region-line-by-li.patch (text/x-patch, inline)]
From bb388580fa7fa15be8aeabb9b80526fefbfac3aa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miha=20Rihtar=C5=A1i=C4=8D?= <miha <at> kamnitnik.top>
Date: Mon, 15 Nov 2021 17:57:36 +0100
Subject: [PATCH 1/6] Don't ignore restriction in indent-region-line-by-line

* lisp/indent.el (indent-according-to-mode): Don't widen if the new
optional argument is non-nil.
(indent-region): Explicitly widen before calling
indent-region-line-by-line.
(indent-region-line-by-line): Don't widen.
---
 lisp/indent.el | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/lisp/indent.el b/lisp/indent.el
index aa6b8d17c4..0a906fb526 100644
--- a/lisp/indent.el
+++ b/lisp/indent.el
@@ -88,16 +88,20 @@ indent-line-ignored-functions
                                         indent-relative-first-indent-point)
   "Values that are ignored by `indent-according-to-mode'.")
 
-(defun indent-according-to-mode ()
+(defun indent-according-to-mode (&optional dont-widen)
   "Indent line in proper way for current major mode.
 Normally, this is done by calling the function specified by the
 variable `indent-line-function'.  However, if the value of that
 variable is present in the `indent-line-ignored-functions' variable,
 handle it specially (since those functions are used for tabbing);
-in that case, indent by aligning to the previous non-blank line."
+in that case, indent by aligning to the previous non-blank line.
+
+Ignore restriction, unless the optional argument DONT-WIDEN is
+non-nil."
   (interactive)
   (save-restriction
-    (widen)
+    (unless dont-widen
+      (widen))
   (syntax-propertize (line-end-position))
   (if (memq indent-line-function indent-line-ignored-functions)
       ;; These functions are used for tabbing, but can't be used for
@@ -601,7 +605,10 @@ indent-region
       (funcall indent-region-function start end)))
    ;; Else, use a default implementation that calls indent-line-function on
    ;; each line.
-   (t (indent-region-line-by-line start end)))
+   (t
+    (save-restriction
+      (widen)
+      (indent-region-line-by-line start end))))
   ;; In most cases, reindenting modifies the buffer, but it may also
   ;; leave it unmodified, in which case we have to deactivate the mark
   ;; by hand.
@@ -615,7 +622,7 @@ indent-region-line-by-line
                 (make-progress-reporter "Indenting region..." (point) end))))
       (while (< (point) end)
         (or (and (bolp) (eolp))
-            (indent-according-to-mode))
+            (indent-according-to-mode t))
         (forward-line 1)
         (and pr (progress-reporter-update pr (point))))
       (and pr (progress-reporter-done pr))
-- 
2.33.1

[signature.asc (application/pgp-signature, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51892; Package emacs. (Wed, 17 Nov 2021 08:14:01 GMT) Full text and rfc822 format available.

Message #8 received at 51892 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: miha <at> kamnitnik.top
Cc: 51892 <at> debbugs.gnu.org
Subject: Re: bug#51892: 29.0.50; [PATCH] Don't ignore restriction in
 indent-region-line-by-line
Date: Wed, 17 Nov 2021 09:13:23 +0100
miha <at> kamnitnik.top writes:

> Emacs convention is that low-level functions should respect restriction
> so that their callers can set restriction according to their needs. For
> example, 'c-indent-region' is a lower-level function which respects the
> current restriction and 'indent-region' is a higher-level user command
> which sets the restriction for lower-level functions, it calls
> "(widen)".

I think that makes sense, so I've pushed this to Emacs 29.  (But I
renamed dont-widen to inhibit-widen, since I think that's what we're
calling arguments like this these days.)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug marked as fixed in version 29.1, send any further explanations to 51892 <at> debbugs.gnu.org and miha <at> kamnitnik.top Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Wed, 17 Nov 2021 08:14:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51892; Package emacs. (Wed, 17 Nov 2021 18:15:01 GMT) Full text and rfc822 format available.

Message #13 received at 51892 <at> debbugs.gnu.org (full text, mbox):

From: <miha <at> kamnitnik.top>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 51892 <at> debbugs.gnu.org
Subject: Re: bug#51892: 29.0.50; [PATCH] Don't ignore restriction in
 indent-region-line-by-line
Date: Wed, 17 Nov 2021 19:19:10 +0100
[Message part 1 (text/plain, inline)]
Lars Ingebrigtsen <larsi <at> gnus.org> writes:

> miha <at> kamnitnik.top writes:
>
>> Emacs convention is that low-level functions should respect restriction
>> so that their callers can set restriction according to their needs. For
>> example, 'c-indent-region' is a lower-level function which respects the
>> current restriction and 'indent-region' is a higher-level user command
>> which sets the restriction for lower-level functions, it calls
>> "(widen)".
>
> I think that makes sense, so I've pushed this to Emacs 29.  (But I
> renamed dont-widen to inhibit-widen, since I think that's what we're
> calling arguments like this these days.)

Thanks, but maybe you forgot to actually push to origin/master? I
fetched it just now and the last commit touching indent.el was about two
months ago.
[signature.asc (application/pgp-signature, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51892; Package emacs. (Thu, 18 Nov 2021 09:04:02 GMT) Full text and rfc822 format available.

Message #16 received at 51892 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: <miha <at> kamnitnik.top>
Cc: 51892 <at> debbugs.gnu.org
Subject: Re: bug#51892: 29.0.50; [PATCH] Don't ignore restriction in
 indent-region-line-by-line
Date: Thu, 18 Nov 2021 10:03:03 +0100
<miha <at> kamnitnik.top> writes:

> Thanks, but maybe you forgot to actually push to origin/master? 

Yup; forgot again.  Pushed now.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 16 Dec 2021 12:24:12 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 103 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.