diff options
author | Miha Rihtaršič <miha@kamnitnik.top> | 2021-11-17 09:12:21 +0100 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2021-11-18 08:11:26 +0100 |
commit | f596f0db82c0b1ff3fe8e8f1d8b07d2fe7504ab6 (patch) | |
tree | 53531e053459279635bc7f64ef13909dcffd14ce | |
parent | b48cbaf5c7e47c002fd274aea21554245075bfe8 (diff) | |
download | emacs-f596f0db82c0b1ff3fe8e8f1d8b07d2fe7504ab6.tar.gz emacs-f596f0db82c0b1ff3fe8e8f1d8b07d2fe7504ab6.tar.bz2 emacs-f596f0db82c0b1ff3fe8e8f1d8b07d2fe7504ab6.zip |
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 (bug#51892).
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)".
-rw-r--r-- | lisp/indent.el | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/lisp/indent.el b/lisp/indent.el index aa6b8d17c4a..ec01733d123 100644 --- a/lisp/indent.el +++ b/lisp/indent.el @@ -88,16 +88,20 @@ This variable has no effect unless `tab-always-indent' is `complete'." 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 inhibit-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 INHIBIT-WIDEN is +non-nil." (interactive) (save-restriction - (widen) + (unless inhibit-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 @@ column to indent to; if it is nil, use one of the three methods above." (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 @@ column to indent to; if it is nil, use one of the three methods above." (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)) |