diff options
author | Miles Bader <miles@gnu.org> | 2007-12-25 21:07:12 +0000 |
---|---|---|
committer | Miles Bader <miles@gnu.org> | 2007-12-25 21:07:12 +0000 |
commit | 1225a933f039fa2a00680658573cc334892e4a8a (patch) | |
tree | 346086bb80aeffab10ad1321af775b0d3facf646 /lisp/indent.el | |
parent | 4496b02bedf7bf5c98249ae486ca80bd049fa9f0 (diff) | |
download | emacs-1225a933f039fa2a00680658573cc334892e4a8a.tar.gz |
Add prefix arg handling to indent-for-tab-command
(indent-for-tab-command): Rigidly indent the following sexp along
with the current line when a prefix arg is given in the
non-active-region case. Specify raw prefix in interactive spec.
Simplify main indentation logic to get rid of the conditional call
to `indent-according-to-mode' (it just ended up calling
`indent-line-function' in all cases anyway, which can be done more
simply here). Remove unnecessary test of ARG in active region case.
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-964
Diffstat (limited to 'lisp/indent.el')
-rw-r--r-- | lisp/indent.el | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/lisp/indent.el b/lisp/indent.el index 96f65dcf778..17ebe3b5567 100644 --- a/lisp/indent.el +++ b/lisp/indent.el @@ -82,14 +82,20 @@ special; we don't actually use them here." Depending on `tab-always-indent', either insert a tab or indent. If initial point was within line's indentation, position after the indentation. Else stay at same point in text. + +If a prefix argument is given, also rigidly indent the entire +balanced expression which starts at the beginning the current +line to reflect the current line's change in indentation. + If `transient-mark-mode' is turned on and the region is active, -indent the region. +indent the region (in this case, any prefix argument is ignored). + The function actually called to indent the line is determined by the value of `indent-line-function'." - (interactive "p") + (interactive "P") (cond ;; The region is active, indent it. - ((and arg transient-mark-mode mark-active + ((and transient-mark-mode mark-active (not (eq (region-beginning) (region-end)))) (indent-region (region-beginning) (region-end))) ((or ;; indent-to-left-margin is only meant for indenting, @@ -99,13 +105,27 @@ The function actually called to indent the line is determined by the value of (or (> (current-column) (current-indentation)) (eq this-command last-command)))) (insert-tab arg)) - ;; Those functions are meant specifically for tabbing and not for - ;; indenting, so we can't pass them to indent-according-to-mode. - ((memq indent-line-function '(indent-relative indent-relative-maybe)) - (funcall indent-line-function)) - ;; Indent the line. (t - (indent-according-to-mode)))) + (let ((end-marker + (and arg + (save-excursion + (forward-line 0) (forward-sexp) (point-marker)))) + (old-indent + (current-indentation))) + + ;; Indent the line. + (funcall indent-line-function) + + ;; If a prefix argument was given, rigidly indent the following + ;; sexp to match the change in the current line's indentation. + ;; + (when arg + (let ((indentation-change (- (current-indentation) old-indent))) + (unless (zerop indentation-change) + (save-excursion + (forward-line 1) + (when (< (point) end-marker) + (indent-rigidly (point) end-marker indentation-change)))))))))) (defun insert-tab (&optional arg) (let ((count (prefix-numeric-value arg))) |