* bug#51892: 29.0.50; [PATCH] Don't ignore restriction in indent-region-line-by-line
@ 2021-11-16 12:57 miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-17 8:13 ` Lars Ingebrigtsen
0 siblings, 1 reply; 4+ messages in thread
From: miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-16 12:57 UTC (permalink / raw)
To: 51892
[-- Attachment #1.1: Type: text/plain, Size: 546 bytes --]
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)".
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-Don-t-ignore-restriction-in-indent-region-line-by-li.patch --]
[-- Type: text/x-patch, Size: 2728 bytes --]
From bb388580fa7fa15be8aeabb9b80526fefbfac3aa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miha=20Rihtar=C5=A1i=C4=8D?= <miha@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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]
^ permalink raw reply related [flat|nested] 4+ messages in thread
* bug#51892: 29.0.50; [PATCH] Don't ignore restriction in indent-region-line-by-line
2021-11-16 12:57 bug#51892: 29.0.50; [PATCH] Don't ignore restriction in indent-region-line-by-line miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2021-11-17 8:13 ` Lars Ingebrigtsen
2021-11-17 18:19 ` miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 4+ messages in thread
From: Lars Ingebrigtsen @ 2021-11-17 8:13 UTC (permalink / raw)
To: miha; +Cc: 51892
miha@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
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#51892: 29.0.50; [PATCH] Don't ignore restriction in indent-region-line-by-line
2021-11-17 8:13 ` Lars Ingebrigtsen
@ 2021-11-17 18:19 ` miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-18 9:03 ` Lars Ingebrigtsen
0 siblings, 1 reply; 4+ messages in thread
From: miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-17 18:19 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: 51892
[-- Attachment #1: Type: text/plain, Size: 791 bytes --]
Lars Ingebrigtsen <larsi@gnus.org> writes:
> miha@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.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#51892: 29.0.50; [PATCH] Don't ignore restriction in indent-region-line-by-line
2021-11-17 18:19 ` miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2021-11-18 9:03 ` Lars Ingebrigtsen
0 siblings, 0 replies; 4+ messages in thread
From: Lars Ingebrigtsen @ 2021-11-18 9:03 UTC (permalink / raw)
To: miha; +Cc: 51892
<miha@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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-11-18 9:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-16 12:57 bug#51892: 29.0.50; [PATCH] Don't ignore restriction in indent-region-line-by-line miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-17 8:13 ` Lars Ingebrigtsen
2021-11-17 18:19 ` miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-18 9:03 ` Lars Ingebrigtsen
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.