diff options
| author | Stefan Monnier | 2001-10-30 05:37:08 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2001-10-30 05:37:08 +0000 |
| commit | a17b712b4d812d28086ae9af02f9043b36cf3e19 (patch) | |
| tree | 24bfa8ca5180c0253a7e93268c524f9a2fa0f13d | |
| parent | 0fb36e365e635a1d957c5ee200d16a200a399210 (diff) | |
| download | emacs-a17b712b4d812d28086ae9af02f9043b36cf3e19.tar.gz emacs-a17b712b4d812d28086ae9af02f9043b36cf3e19.zip | |
(indent-line-function): Change default to indent-relative.
(tab-always-indent): Add an `always' setting.
(indent-according-to-mode): Handle `indent-relative' and
`indent-relative-maybe' specially.
(indent-for-tab-command): Rename `prefix-arg' to `arg'.
Handle the `always; case for `tab-always-indent'.
Don't call indent-according-to-mode for indent-relative' and
`indent-relative-maybe'.
(insert-tab): Rename `prefix-arg' to `arg'.
(indent-region): Indent the first line as well.
(indent-relative): Don't mark the buffer modified if the indentation
is unchanged.
| -rw-r--r-- | lisp/indent.el | 75 |
1 files changed, 51 insertions, 24 deletions
diff --git a/lisp/indent.el b/lisp/indent.el index d097a02c833..e772b69de52 100644 --- a/lisp/indent.el +++ b/lisp/indent.el | |||
| @@ -37,23 +37,42 @@ | |||
| 37 | :group 'indent | 37 | :group 'indent |
| 38 | :type 'integer) | 38 | :type 'integer) |
| 39 | 39 | ||
| 40 | (defvar indent-line-function 'indent-to-left-margin | 40 | (defvar indent-line-function 'indent-relative |
| 41 | "Function to indent current line.") | 41 | "Function to indent the current line. |
| 42 | This function will be called with no arguments. | ||
| 43 | If it is called somewhere where auto-indentation cannot be done | ||
| 44 | \(f.ex. inside a string), the function should simply return `noindent'. | ||
| 45 | Setting this function is all you need to make TAB indent appropriately. | ||
| 46 | Don't rebind TAB unless you really need to.") | ||
| 42 | 47 | ||
| 43 | (defcustom tab-always-indent t | 48 | (defcustom tab-always-indent t |
| 44 | "*Controls the operation of the TAB key. | 49 | "*Controls the operation of the TAB key. |
| 45 | If t, hitting TAB always just indents the current line. | 50 | If t, hitting TAB always just indents the current line. |
| 51 | If `never', hitting TAB just inserts a tab. | ||
| 46 | If nil, hitting TAB indents the current line if point is at the left margin | 52 | If nil, hitting TAB indents the current line if point is at the left margin |
| 47 | or in the line's indentation, otherwise it insert a `real' tab character." | 53 | or in the line's indentation, otherwise it insert a `real' tab character." |
| 48 | :group 'indent | 54 | :group 'indent |
| 49 | :type 'boolean) | 55 | :type '(choice (const nil) (const t) (const never) (const always))) |
| 50 | 56 | ||
| 51 | (defun indent-according-to-mode () | 57 | (defun indent-according-to-mode () |
| 52 | "Indent line in proper way for current major mode." | 58 | "Indent line in proper way for current major mode." |
| 53 | (interactive) | 59 | (interactive) |
| 54 | (funcall indent-line-function)) | 60 | (if (memq indent-line-function |
| 61 | '(indent-relative indent-relative-maybe)) | ||
| 62 | ;; These functions are used for tabbing, but can't be used for | ||
| 63 | ;; indenting. Replace with something ad-hoc. | ||
| 64 | (let ((column (save-excursion | ||
| 65 | (beginning-of-line) | ||
| 66 | (skip-chars-backward "\n \t") | ||
| 67 | (beginning-of-line) | ||
| 68 | (current-indentation)))) | ||
| 69 | (if (<= (current-column) (current-indentation)) | ||
| 70 | (indent-line-to column) | ||
| 71 | (save-excursion (indent-line-to column)))) | ||
| 72 | ;; The normal case. | ||
| 73 | (funcall indent-line-function))) | ||
| 55 | 74 | ||
| 56 | (defun indent-for-tab-command (&optional prefix-arg) | 75 | (defun indent-for-tab-command (&optional arg) |
| 57 | "Indent line in proper way for current major mode or insert a tab. | 76 | "Indent line in proper way for current major mode or insert a tab. |
| 58 | Depending on `tab-always-indent', either insert a tab or indent. | 77 | Depending on `tab-always-indent', either insert a tab or indent. |
| 59 | If initial point was within line's indentation, position after | 78 | If initial point was within line's indentation, position after |
| @@ -61,14 +80,25 @@ the indentation. Else stay at same point in text. | |||
| 61 | The function actually called to indent is determined by the value of | 80 | The function actually called to indent is determined by the value of |
| 62 | `indent-line-function'." | 81 | `indent-line-function'." |
| 63 | (interactive "P") | 82 | (interactive "P") |
| 64 | (if (or (eq indent-line-function 'indent-to-left-margin) | 83 | (cond |
| 65 | (and (not tab-always-indent) | 84 | ((or (eq tab-always-indent 'never) |
| 66 | (> (current-column) (current-indentation)))) | 85 | ;; indent-to-left-margin is only meant for indenting, |
| 67 | (insert-tab prefix-arg) | 86 | ;; so we force it to always insert a tab here. |
| 68 | (funcall indent-line-function))) | 87 | (eq indent-line-function 'indent-to-left-margin) |
| 69 | 88 | (and (not tab-always-indent) | |
| 70 | (defun insert-tab (&optional prefix-arg) | 89 | (> (current-column) (current-indentation))) |
| 71 | (let ((count (prefix-numeric-value prefix-arg))) | 90 | (and (not (eq tab-always-indent 'always)) |
| 91 | (eq this-command last-command))) | ||
| 92 | (insert-tab arg)) | ||
| 93 | ;; Those functions are meant specifically for tabbing and not for | ||
| 94 | ;; indenting, so we can't pass them to indent-according-to-mode. | ||
| 95 | ((memq indent-line-function '(indent-relative indent-relative-maybe)) | ||
| 96 | (funcall indent-line-function)) | ||
| 97 | (t ;; The normal case. | ||
| 98 | (indent-according-to-mode)))) | ||
| 99 | |||
| 100 | (defun insert-tab (&optional arg) | ||
| 101 | (let ((count (prefix-numeric-value arg))) | ||
| 72 | (if (and abbrev-mode | 102 | (if (and abbrev-mode |
| 73 | (eq (char-syntax (preceding-char)) ?w)) | 103 | (eq (char-syntax (preceding-char)) ?w)) |
| 74 | (expand-abbrev)) | 104 | (expand-abbrev)) |
| @@ -322,10 +352,8 @@ If COLUMN is nil, then indent each line according to the mode." | |||
| 322 | (if indent-region-function | 352 | (if indent-region-function |
| 323 | (funcall indent-region-function start end) | 353 | (funcall indent-region-function start end) |
| 324 | (save-excursion | 354 | (save-excursion |
| 325 | (goto-char end) | 355 | (setq end (copy-marker end)) |
| 326 | (setq end (point-marker)) | ||
| 327 | (goto-char start) | 356 | (goto-char start) |
| 328 | (or (bolp) (forward-line 1)) | ||
| 329 | (while (< (point) end) | 357 | (while (< (point) end) |
| 330 | (or (and (bolp) (eolp)) | 358 | (or (and (bolp) (eolp)) |
| 331 | (funcall indent-line-function)) | 359 | (funcall indent-line-function)) |
| @@ -385,7 +413,6 @@ See also `indent-relative-maybe'." | |||
| 385 | (or (= (point) end) (setq indent (current-column)))))) | 413 | (or (= (point) end) (setq indent (current-column)))))) |
| 386 | (if indent | 414 | (if indent |
| 387 | (let ((opoint (point-marker))) | 415 | (let ((opoint (point-marker))) |
| 388 | (delete-region (point) (progn (skip-chars-backward " \t") (point))) | ||
| 389 | (indent-to indent 0) | 416 | (indent-to indent 0) |
| 390 | (if (> opoint (point)) | 417 | (if (> opoint (point)) |
| 391 | (goto-char opoint)) | 418 | (goto-char opoint)) |
| @@ -399,12 +426,12 @@ This should be a list of integers, ordered from smallest to largest." | |||
| 399 | :group 'indent | 426 | :group 'indent |
| 400 | :type '(repeat integer)) | 427 | :type '(repeat integer)) |
| 401 | 428 | ||
| 402 | (defvar edit-tab-stops-map nil "Keymap used in `edit-tab-stops'.") | 429 | (defvar edit-tab-stops-map |
| 403 | (if edit-tab-stops-map | 430 | (let ((map (make-sparse-keymap))) |
| 404 | nil | 431 | (define-key map "\C-x\C-s" 'edit-tab-stops-note-changes) |
| 405 | (setq edit-tab-stops-map (make-sparse-keymap)) | 432 | (define-key map "\C-c\C-c" 'edit-tab-stops-note-changes) |
| 406 | (define-key edit-tab-stops-map "\C-x\C-s" 'edit-tab-stops-note-changes) | 433 | map) |
| 407 | (define-key edit-tab-stops-map "\C-c\C-c" 'edit-tab-stops-note-changes)) | 434 | "Keymap used in `edit-tab-stops'.") |
| 408 | 435 | ||
| 409 | (defvar edit-tab-stops-buffer nil | 436 | (defvar edit-tab-stops-buffer nil |
| 410 | "Buffer whose tab stops are being edited--in case | 437 | "Buffer whose tab stops are being edited--in case |
| @@ -497,7 +524,7 @@ Use \\[edit-tab-stops] to edit them interactively." | |||
| 497 | (delete-region (point) before)))))))) | 524 | (delete-region (point) before)))))))) |
| 498 | 525 | ||
| 499 | (define-key global-map "\t" 'indent-for-tab-command) | 526 | (define-key global-map "\t" 'indent-for-tab-command) |
| 500 | (define-key esc-map "\034" 'indent-region) | 527 | (define-key esc-map "\C-\\" 'indent-region) |
| 501 | (define-key ctl-x-map "\t" 'indent-rigidly) | 528 | (define-key ctl-x-map "\t" 'indent-rigidly) |
| 502 | (define-key esc-map "i" 'tab-to-tab-stop) | 529 | (define-key esc-map "i" 'tab-to-tab-stop) |
| 503 | 530 | ||