diff options
Diffstat (limited to 'lisp/indent.el')
-rw-r--r-- | lisp/indent.el | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/lisp/indent.el b/lisp/indent.el index 48e5b309e48..d20c8053c5f 100644 --- a/lisp/indent.el +++ b/lisp/indent.el @@ -89,16 +89,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 @@ -167,7 +171,7 @@ prefix argument is ignored." (let ((old-tick (buffer-chars-modified-tick)) (old-point (point)) (old-indent (current-indentation)) - (syn `(,(syntax-after (point))))) + (syn (syntax-after (point)))) ;; Indent the line. (or (not (eq (indent--funcall-widened indent-line-function) 'noindent)) @@ -179,21 +183,21 @@ prefix argument is ignored." (cond ;; If the text was already indented right, try completion. ((and (eq tab-always-indent 'complete) - (eq old-point (point)) - (eq old-tick (buffer-chars-modified-tick)) + (eql old-point (point)) + (eql old-tick (buffer-chars-modified-tick)) (or (null tab-first-completion) (eq last-command this-command) - (and (equal tab-first-completion 'eol) + (and (eq tab-first-completion 'eol) (eolp)) - (and (member tab-first-completion - '(word word-or-paren word-or-paren-or-punct)) - (not (member 2 syn))) - (and (member tab-first-completion - '(word-or-paren word-or-paren-or-punct)) - (not (or (member 4 syn) - (member 5 syn)))) - (and (equal tab-first-completion 'word-or-paren-or-punct) - (not (member 1 syn))))) + (and (memq tab-first-completion + '(word word-or-paren word-or-paren-or-punct)) + (not (eql 2 syn))) + (and (memq tab-first-completion + '(word-or-paren word-or-paren-or-punct)) + (not (or (eql 4 syn) + (eql 5 syn)))) + (and (eq tab-first-completion 'word-or-paren-or-punct) + (not (eql 1 syn))))) (completion-at-point)) ;; If a prefix argument was given, rigidly indent the following @@ -602,7 +606,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. @@ -616,7 +623,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)) |