diff options
Diffstat (limited to 'lisp/indent.el')
-rw-r--r-- | lisp/indent.el | 63 |
1 files changed, 36 insertions, 27 deletions
diff --git a/lisp/indent.el b/lisp/indent.el index 071f46fd42a..d6dee94016d 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 @@ -236,21 +240,23 @@ Blank lines are ignored." (current-indentation)))) indent)))) -(defvar indent-rigidly-map - (let ((map (make-sparse-keymap))) - (define-key map [left] 'indent-rigidly-left) - (define-key map [right] 'indent-rigidly-right) - (define-key map [S-left] 'indent-rigidly-left-to-tab-stop) - (define-key map [S-right] 'indent-rigidly-right-to-tab-stop) - map) - "Transient keymap for adjusting indentation interactively. -It is activated by calling `indent-rigidly' interactively.") +(defvar-keymap indent-rigidly-map + :doc "Transient keymap for adjusting indentation interactively. +It is activated by calling `indent-rigidly' interactively." + "TAB" #'indent-rigidly-right + "<left>" #'indent-rigidly-left + "<right>" #'indent-rigidly-right + "S-<left>" #'indent-rigidly-left-to-tab-stop + "S-<right>" #'indent-rigidly-right-to-tab-stop) +(put 'indent-rigidly-right :advertised-binding (kbd "<right>")) (defun indent-rigidly (start end arg &optional interactive) "Indent all lines starting in the region. If called interactively with no prefix argument, activate a transient mode in which the indentation can be adjusted interactively by typing \\<indent-rigidly-map>\\[indent-rigidly-left], \\[indent-rigidly-right], \\[indent-rigidly-left-to-tab-stop], or \\[indent-rigidly-right-to-tab-stop]. +In addition, \\`TAB' is also bound (and calls `indent-rigidly-right'). + Typing any other key exits this mode, and this key is then acted upon as normally. If `transient-mark-mode' is enabled, exiting also deactivates the mark. @@ -602,7 +608,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 +625,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)) |