Mercurial > emacs
annotate lisp/indent.el @ 13278:9493a12ca8a5
(internal-ange-ftp-mode):
Set comint-password-prompt-regexp locally to not match anything.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 23 Oct 1995 16:57:42 +0000 |
parents | b8453eab5114 |
children | 1418ed733e9d |
rev | line source |
---|---|
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
269
diff
changeset
|
1 ;;; indent.el --- indentation commands for Emacs |
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
269
diff
changeset
|
2 |
11235 | 3 ;; Copyright (C) 1985, 1995 Free Software Foundation, Inc. |
845 | 4 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
5 ;; Maintainer: FSF |
263 | 6 |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
11 ;; the Free Software Foundation; either version 2, or (at your option) |
263 | 12 ;; any later version. |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
22 | |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2201
diff
changeset
|
23 ;;; Commentary: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2201
diff
changeset
|
24 |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2201
diff
changeset
|
25 ;; Commands for making and changing indentation in text. These are |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2201
diff
changeset
|
26 ;; described in the Emacs manual. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2201
diff
changeset
|
27 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
28 ;;; Code: |
263 | 29 |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
30 (defvar standard-indent 4 "\ |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
31 Default number of columns for margin-changing functions to indent.") |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
32 |
269 | 33 (defvar indent-line-function 'indent-to-left-margin "\ |
2192
96adb71c61ec
* indent.el (indent-line-function): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
845
diff
changeset
|
34 Function to indent current line.") |
263 | 35 |
36 (defun indent-according-to-mode () | |
37 "Indent line in proper way for current major mode." | |
38 (interactive) | |
39 (funcall indent-line-function)) | |
40 | |
13035
b8453eab5114
(indent-for-tab-command): Get the prefix arg
Richard M. Stallman <rms@gnu.org>
parents:
12778
diff
changeset
|
41 (defun indent-for-tab-command (&optional prefix-arg) |
263 | 42 "Indent line in proper way for current major mode." |
13035
b8453eab5114
(indent-for-tab-command): Get the prefix arg
Richard M. Stallman <rms@gnu.org>
parents:
12778
diff
changeset
|
43 (interactive "P") |
263 | 44 (if (eq indent-line-function 'indent-to-left-margin) |
45 (insert-tab) | |
13035
b8453eab5114
(indent-for-tab-command): Get the prefix arg
Richard M. Stallman <rms@gnu.org>
parents:
12778
diff
changeset
|
46 (if prefix-arg |
b8453eab5114
(indent-for-tab-command): Get the prefix arg
Richard M. Stallman <rms@gnu.org>
parents:
12778
diff
changeset
|
47 (funcall indent-line-function prefix-arg) |
b8453eab5114
(indent-for-tab-command): Get the prefix arg
Richard M. Stallman <rms@gnu.org>
parents:
12778
diff
changeset
|
48 (funcall indent-line-function)))) |
263 | 49 |
50 (defun insert-tab () | |
51 (if abbrev-mode | |
52 (expand-abbrev)) | |
53 (if indent-tabs-mode | |
54 (insert ?\t) | |
55 (indent-to (* tab-width (1+ (/ (current-column) tab-width)))))) | |
56 | |
57 (defun indent-rigidly (start end arg) | |
58 "Indent all lines starting in the region sideways by ARG columns. | |
59 Called from a program, takes three arguments, START, END and ARG." | |
60 (interactive "r\np") | |
61 (save-excursion | |
62 (goto-char end) | |
63 (setq end (point-marker)) | |
64 (goto-char start) | |
65 (or (bolp) (forward-line 1)) | |
66 (while (< (point) end) | |
8642
ae3b75bae5d7
(indent-rigidly): Insert new indent, then delete old.
Richard M. Stallman <rms@gnu.org>
parents:
8208
diff
changeset
|
67 (let ((indent (current-indentation)) |
ae3b75bae5d7
(indent-rigidly): Insert new indent, then delete old.
Richard M. Stallman <rms@gnu.org>
parents:
8208
diff
changeset
|
68 eol-flag) |
ae3b75bae5d7
(indent-rigidly): Insert new indent, then delete old.
Richard M. Stallman <rms@gnu.org>
parents:
8208
diff
changeset
|
69 (save-excursion |
ae3b75bae5d7
(indent-rigidly): Insert new indent, then delete old.
Richard M. Stallman <rms@gnu.org>
parents:
8208
diff
changeset
|
70 (skip-chars-forward " \t") |
ae3b75bae5d7
(indent-rigidly): Insert new indent, then delete old.
Richard M. Stallman <rms@gnu.org>
parents:
8208
diff
changeset
|
71 (setq eol-flag (eolp))) |
ae3b75bae5d7
(indent-rigidly): Insert new indent, then delete old.
Richard M. Stallman <rms@gnu.org>
parents:
8208
diff
changeset
|
72 (or eol-flag |
ae3b75bae5d7
(indent-rigidly): Insert new indent, then delete old.
Richard M. Stallman <rms@gnu.org>
parents:
8208
diff
changeset
|
73 (indent-to (max 0 (+ indent arg)) 0)) |
ae3b75bae5d7
(indent-rigidly): Insert new indent, then delete old.
Richard M. Stallman <rms@gnu.org>
parents:
8208
diff
changeset
|
74 (delete-region (point) (progn (skip-chars-forward " \t") (point)))) |
263 | 75 (forward-line 1)) |
76 (move-marker end nil))) | |
77 | |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
78 (defun indent-line-to (column) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
79 "Indent current line to COLUMN. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
80 This function removes or adds spaces and tabs at beginning of line |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
81 only if necessary. It leaves point at end of indentation." |
11043
4c0a98538670
(indent-line-to): move to end of indentation, even if it didn't change.
Boris Goldowsky <boris@gnu.org>
parents:
10812
diff
changeset
|
82 (back-to-indentation) |
4c0a98538670
(indent-line-to): move to end of indentation, even if it didn't change.
Boris Goldowsky <boris@gnu.org>
parents:
10812
diff
changeset
|
83 (let ((cur-col (current-column))) |
4c0a98538670
(indent-line-to): move to end of indentation, even if it didn't change.
Boris Goldowsky <boris@gnu.org>
parents:
10812
diff
changeset
|
84 (cond ((< cur-col column) |
4c0a98538670
(indent-line-to): move to end of indentation, even if it didn't change.
Boris Goldowsky <boris@gnu.org>
parents:
10812
diff
changeset
|
85 (indent-to column)) |
4c0a98538670
(indent-line-to): move to end of indentation, even if it didn't change.
Boris Goldowsky <boris@gnu.org>
parents:
10812
diff
changeset
|
86 ((> cur-col column) ; too far right (after tab?) |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
87 (delete-region (progn (move-to-column column t) (point)) |
11043
4c0a98538670
(indent-line-to): move to end of indentation, even if it didn't change.
Boris Goldowsky <boris@gnu.org>
parents:
10812
diff
changeset
|
88 (progn (back-to-indentation) (point))))))) |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
89 |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
90 (defun current-left-margin () |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
91 "Return the left margin to use for this line. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
92 This is the value of the buffer-local variable `left-margin' plus the value |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
93 of the `left-margin' text-property at the start of the line." |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
94 (save-excursion |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
95 (back-to-indentation) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
96 (max 0 |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
97 (+ left-margin (or (get-text-property |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
98 (if (and (eobp) (not (bobp))) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
99 (1- (point)) (point)) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
100 'left-margin) 0))))) |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
101 |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
102 (defun move-to-left-margin (&optional n force) |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
103 "Move to the left margin of the current line. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
104 With optional argument, move forward N-1 lines first. |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
105 The column moved to is the one given by the `current-left-margin' function. |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
106 If the line's indentation appears to be wrong, and this command is called |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
107 interactively or with optional argument FORCE, it will be fixed." |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
108 (interactive (list (prefix-numeric-value current-prefix-arg) t)) |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
109 (beginning-of-line n) |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
110 (let ((lm (current-left-margin))) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
111 (if (memq (current-justification) '(right center)) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
112 (move-to-column lm) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
113 (skip-chars-forward " \t")) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
114 (let ((cc (current-column))) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
115 (cond ((> cc lm) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
116 (if (> (move-to-column lm force) lm) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
117 ;; If lm is in a tab and we are not forcing, move before tab |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
118 (backward-char 1))) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
119 ((and force (< cc lm)) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
120 (indent-to-left-margin)))))) |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
121 |
263 | 122 ;; This is the default indent-line-function, |
123 ;; used in Fundamental Mode, Text Mode, etc. | |
124 (defun indent-to-left-margin () | |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
125 "Indent current line to the column given by `current-left-margin'." |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
126 (indent-line-to (current-left-margin))) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
127 |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
128 (defun delete-to-left-margin (&optional from to) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
129 "Remove left margin indentation from a region. |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
130 This deletes to the column given by `current-left-margin'. |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
131 In no case will it delete non-whitespace. |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
132 Args FROM and TO are optional; default is the whole buffer." |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
133 (save-excursion |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
134 (goto-char (or to (point-max))) |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
135 (setq to (point-marker)) |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
136 (goto-char (or from (point-min))) |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
137 (or (bolp) (forward-line 1)) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
138 (while (< (point) to) |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
139 (delete-region (point) (progn (move-to-left-margin nil t) (point))) |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
140 (forward-line 1)) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
141 (move-marker to nil))) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
142 |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
143 (defun set-left-margin (from to lm) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
144 "Set the left margin of the region to WIDTH. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
145 If `auto-fill-mode' is active, re-fill the region to fit the new margin." |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
146 (interactive "r\nNSet left margin to column: ") |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
147 (if (interactive-p) (setq lm (prefix-numeric-value lm))) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
148 (save-excursion |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
149 ;; If inside indentation, start from BOL. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
150 (goto-char from) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
151 (skip-chars-backward " \t") |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
152 (if (bolp) (setq from (point))) |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
153 ;; Place end after whitespace |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
154 (goto-char to) |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
155 (skip-chars-forward " \t") |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
156 (setq to (point-marker))) |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
157 ;; Delete margin indentation first, but keep paragraph indentation. |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
158 (delete-to-left-margin from to) |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
159 (put-text-property from to 'left-margin lm) |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
160 (indent-rigidly from to lm) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
161 (if auto-fill-function (save-excursion (fill-region from to nil t t))) |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
162 (move-marker to nil)) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
163 |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
164 (defun set-right-margin (from to lm) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
165 "Set the right margin of the region to WIDTH. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
166 If `auto-fill-mode' is active, re-fill the region to fit the new margin." |
11281
10f9cf00c770
(set-right-margin): Fix prompt.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
167 (interactive "r\nNSet right margin to width: ") |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
168 (if (interactive-p) (setq lm (prefix-numeric-value lm))) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
169 (save-excursion |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
170 (goto-char from) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
171 (skip-chars-backward " \t") |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
172 (if (bolp) (setq from (point)))) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
173 (put-text-property from to 'right-margin lm) |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
174 (if auto-fill-function (save-excursion (fill-region from to nil t t)))) |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
175 |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
176 (defun alter-text-property (from to prop func &optional object) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
177 "Programmatically change value of a text-property. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
178 For each region between FROM and TO that has a single value for PROPERTY, |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
179 apply FUNCTION to that value and sets the property to the function's result. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
180 Optional fifth argument OBJECT specifies the string or buffer to operate on." |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
181 (let ((begin from) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
182 end val) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
183 (while (setq val (get-text-property begin prop object) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
184 end (text-property-not-all begin to prop val object)) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
185 (put-text-property begin end prop (funcall func val) object) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
186 (setq begin end)) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
187 (if (< begin to) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
188 (put-text-property begin to prop (funcall func val) object)))) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
189 |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
190 (defun increase-left-margin (from to inc) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
191 "Increase or decrease the left-margin of the region. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
192 With no prefix argument, this adds `standard-indent' of indentation. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
193 A prefix arg (optional third arg INC noninteractively) specifies the amount |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
194 to change the margin by, in characters. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
195 If `auto-fill-mode' is active, re-fill the region to fit the new margin." |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
196 (interactive "*r\nP") |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
197 (setq inc (if inc (prefix-numeric-value inc) standard-indent)) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
198 (save-excursion |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
199 (goto-char from) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
200 (skip-chars-backward " \t") |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
201 (if (bolp) (setq from (point))) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
202 (goto-char to) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
203 (setq to (point-marker))) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
204 (alter-text-property from to 'left-margin |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
205 (lambda (v) (max (- left-margin) (+ inc (or v 0))))) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
206 (indent-rigidly from to inc) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
207 (if auto-fill-function (save-excursion (fill-region from to nil t t))) |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
208 (move-marker to nil)) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
209 |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
210 (defun decrease-left-margin (from to inc) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
211 "Make the left margin of the region smaller. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
212 With no prefix argument, decrease the indentation by `standard-indent'. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
213 A prefix arg (optional third arg INC noninteractively) specifies the amount |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
214 to change the margin by, in characters. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
215 If `auto-fill-mode' is active, re-fill the region to fit the new margin." |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
216 (interactive "*r\nP") |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
217 (setq inc (if inc (prefix-numeric-value inc) standard-indent)) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
218 (increase-left-margin from to (- inc))) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
219 |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
220 (defun increase-right-margin (from to inc) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
221 "Increase the right-margin of the region. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
222 With no prefix argument, increase the right margin by `standard-indent'. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
223 A prefix arg (optional third arg INC noninteractively) specifies the amount |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
224 to change the margin by, in characters. A negative argument decreases |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
225 the right margin width. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
226 If `auto-fill-mode' is active, re-fill the region to fit the new margin." |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
227 (interactive "r\nP") |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
228 (if (interactive-p) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
229 (setq inc (if inc (prefix-numeric-value current-prefix-arg) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
230 standard-indent))) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
231 (save-excursion |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
232 (alter-text-property from to 'right-margin |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
233 (lambda (v) (+ inc (or v 0)))) |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
234 (if auto-fill-function |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
235 (fill-region from to nil t t)))) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
236 |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
237 (defun decrease-right-margin (from to inc) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
238 "Make the right margin of the region smaller. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
239 With no prefix argument, decrease the right margin by `standard-indent'. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
240 A prefix arg (optional third arg INC noninteractively) specifies the amount |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
241 of width to remove, in characters. A negative argument increases |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
242 the right margin width. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
243 If `auto-fill-mode' is active, re-fills region to fit in new margin." |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
244 (interactive "*r\nP") |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
245 (setq inc (if inc (prefix-numeric-value inc) standard-indent)) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
246 (increase-right-margin from to (- inc))) |
263 | 247 |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
248 (defun beginning-of-line-text (&optional n) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
249 "Move to the beginning of the text on this line. |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
250 With optional argument, move forward N-1 lines first. |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
251 From the beginning of the line, moves past the left-margin indentation, the |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
252 fill-prefix, and any indentation used for centering or right-justifying the |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
253 line, but does not move past any whitespace that was explicitly inserted |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
254 \(such as a tab used to indent the first line of a paragraph)." |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
255 (interactive "p") |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
256 (beginning-of-line n) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
257 (skip-chars-forward " \t") |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
258 ;; Skip over fill-prefix. |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
259 (if (and fill-prefix |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
260 (not (string-equal fill-prefix ""))) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
261 (if (equal fill-prefix |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
262 (buffer-substring |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
263 (point) (min (point-max) (+ (length fill-prefix) (point))))) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
264 (forward-char (length fill-prefix))) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
265 (if (and adaptive-fill-mode |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
266 (looking-at adaptive-fill-regexp)) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
267 (goto-char (match-end 0)))) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
268 ;; Skip centering or flushright indentation |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
269 (if (memq (current-justification) '(center right)) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
270 (skip-chars-forward " \t"))) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
271 |
263 | 272 (defvar indent-region-function nil |
12683
0e9d2009e609
(indent-region-function): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11281
diff
changeset
|
273 "Short cut function to indent region using `indent-according-to-mode'. |
0e9d2009e609
(indent-region-function): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11281
diff
changeset
|
274 A value of nil means really run `indent-according-to-mode' on each line.") |
263 | 275 |
4465
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
276 (defun indent-region (start end column) |
263 | 277 "Indent each nonblank line in the region. |
4465
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
278 With no argument, indent each line using `indent-according-to-mode', |
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
279 or use `indent-region-function' to do the whole region if that's non-nil. |
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
280 If there is a fill prefix, make each line start with the fill prefix. |
263 | 281 With argument COLUMN, indent each line to that column. |
282 Called from a program, takes three args: START, END and COLUMN." | |
283 (interactive "r\nP") | |
4465
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
284 (if (null column) |
263 | 285 (if fill-prefix |
286 (save-excursion | |
287 (goto-char end) | |
288 (setq end (point-marker)) | |
289 (goto-char start) | |
290 (let ((regexp (regexp-quote fill-prefix))) | |
4465
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
291 (while (< (point) end) |
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
292 (or (looking-at regexp) |
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
293 (and (bolp) (eolp)) |
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
294 (insert fill-prefix)) |
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
295 (forward-line 1)))) |
263 | 296 (if indent-region-function |
297 (funcall indent-region-function start end) | |
298 (save-excursion | |
4465
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
299 (goto-char end) |
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
300 (setq end (point-marker)) |
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
301 (goto-char start) |
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
302 (or (bolp) (forward-line 1)) |
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
303 (while (< (point) end) |
4473
600d0d832d99
(indent-region): Fix paren error in last change.
Richard M. Stallman <rms@gnu.org>
parents:
4465
diff
changeset
|
304 (or (and (bolp) (eolp)) |
4465
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
305 (funcall indent-line-function)) |
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
306 (forward-line 1)) |
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
307 (move-marker end nil)))) |
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
308 (setq column (prefix-numeric-value column)) |
263 | 309 (save-excursion |
310 (goto-char end) | |
311 (setq end (point-marker)) | |
312 (goto-char start) | |
313 (or (bolp) (forward-line 1)) | |
314 (while (< (point) end) | |
315 (delete-region (point) (progn (skip-chars-forward " \t") (point))) | |
316 (or (eolp) | |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
317 (indent-to column 0)) |
263 | 318 (forward-line 1)) |
319 (move-marker end nil)))) | |
320 | |
321 (defun indent-relative-maybe () | |
322 "Indent a new line like previous nonblank line." | |
323 (interactive) | |
324 (indent-relative t)) | |
325 | |
326 (defun indent-relative (&optional unindented-ok) | |
327 "Space out to under next indent point in previous nonblank line. | |
328 An indent point is a non-whitespace character following whitespace. | |
329 If the previous nonblank line has no indent points beyond the | |
330 column point starts at, `tab-to-tab-stop' is done instead." | |
331 (interactive "P") | |
332 (if abbrev-mode (expand-abbrev)) | |
333 (let ((start-column (current-column)) | |
334 indent) | |
335 (save-excursion | |
336 (beginning-of-line) | |
337 (if (re-search-backward "^[^\n]" nil t) | |
338 (let ((end (save-excursion (forward-line 1) (point)))) | |
339 (move-to-column start-column) | |
340 ;; Is start-column inside a tab on this line? | |
341 (if (> (current-column) start-column) | |
342 (backward-char 1)) | |
343 (or (looking-at "[ \t]") | |
344 unindented-ok | |
345 (skip-chars-forward "^ \t" end)) | |
346 (skip-chars-forward " \t" end) | |
347 (or (= (point) end) (setq indent (current-column)))))) | |
348 (if indent | |
349 (let ((opoint (point-marker))) | |
350 (delete-region (point) (progn (skip-chars-backward " \t") (point))) | |
351 (indent-to indent 0) | |
352 (if (> opoint (point)) | |
353 (goto-char opoint)) | |
354 (move-marker opoint nil)) | |
355 (tab-to-tab-stop)))) | |
356 | |
357 (defvar tab-stop-list | |
358 '(8 16 24 32 40 48 56 64 72 80 88 96 104 112 120) | |
7813
1fa576a274b5
(tab-stop-list): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
4473
diff
changeset
|
359 "*List of tab stop positions used by `tab-to-tab-stops'. |
1fa576a274b5
(tab-stop-list): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
4473
diff
changeset
|
360 This should be a list of integers, ordered from smallest to largest.") |
263 | 361 |
362 (defvar edit-tab-stops-map nil "Keymap used in `edit-tab-stops'.") | |
363 (if edit-tab-stops-map | |
364 nil | |
365 (setq edit-tab-stops-map (make-sparse-keymap)) | |
366 (define-key edit-tab-stops-map "\C-x\C-s" 'edit-tab-stops-note-changes) | |
367 (define-key edit-tab-stops-map "\C-c\C-c" 'edit-tab-stops-note-changes)) | |
368 | |
369 (defvar edit-tab-stops-buffer nil | |
370 "Buffer whose tab stops are being edited--in case | |
371 the variable `tab-stop-list' is local in that buffer.") | |
372 | |
373 (defun edit-tab-stops () | |
374 "Edit the tab stops used by `tab-to-tab-stop'. | |
375 Creates a buffer *Tab Stops* containing text describing the tab stops. | |
376 A colon indicates a column where there is a tab stop. | |
377 You can add or remove colons and then do \\<edit-tab-stops-map>\\[edit-tab-stops-note-changes] to make changes take effect." | |
378 (interactive) | |
379 (setq edit-tab-stops-buffer (current-buffer)) | |
380 (switch-to-buffer (get-buffer-create "*Tab Stops*")) | |
381 (use-local-map edit-tab-stops-map) | |
382 (make-local-variable 'indent-tabs-mode) | |
383 (setq indent-tabs-mode nil) | |
384 (overwrite-mode 1) | |
385 (setq truncate-lines t) | |
386 (erase-buffer) | |
387 (let ((tabs tab-stop-list)) | |
388 (while tabs | |
389 (indent-to (car tabs) 0) | |
390 (insert ?:) | |
391 (setq tabs (cdr tabs)))) | |
392 (let ((count 0)) | |
393 (insert ?\n) | |
394 (while (< count 8) | |
395 (insert (+ count ?0)) | |
396 (insert " ") | |
397 (setq count (1+ count))) | |
398 (insert ?\n) | |
399 (while (> count 0) | |
400 (insert "0123456789") | |
401 (setq count (1- count)))) | |
402 (insert "\nTo install changes, type C-c C-c") | |
403 (goto-char (point-min))) | |
404 | |
405 (defun edit-tab-stops-note-changes () | |
406 "Put edited tab stops into effect." | |
407 (interactive) | |
408 (let (tabs) | |
409 (save-excursion | |
410 (goto-char 1) | |
411 (end-of-line) | |
412 (while (search-backward ":" nil t) | |
413 (setq tabs (cons (current-column) tabs)))) | |
414 (bury-buffer (prog1 (current-buffer) | |
415 (switch-to-buffer edit-tab-stops-buffer))) | |
416 (setq tab-stop-list tabs)) | |
417 (message "Tab stops installed")) | |
418 | |
419 (defun tab-to-tab-stop () | |
420 "Insert spaces or tabs to next defined tab-stop column. | |
421 The variable `tab-stop-list' is a list of columns at which there are tab stops. | |
422 Use \\[edit-tab-stops] to edit them interactively." | |
423 (interactive) | |
12778
657be7aaa043
(tab-to-tab-stop): Expand abbrevs only after a word-char.
Richard M. Stallman <rms@gnu.org>
parents:
12683
diff
changeset
|
424 (and abbrev-mode (= (char-syntax (preceding-char)) ?w) |
657be7aaa043
(tab-to-tab-stop): Expand abbrevs only after a word-char.
Richard M. Stallman <rms@gnu.org>
parents:
12683
diff
changeset
|
425 (expand-abbrev)) |
263 | 426 (let ((tabs tab-stop-list)) |
427 (while (and tabs (>= (current-column) (car tabs))) | |
428 (setq tabs (cdr tabs))) | |
429 (if tabs | |
7973
b7ea350590a7
(tab-to-tab-stop): Combine new indentation with previous.
Richard M. Stallman <rms@gnu.org>
parents:
7813
diff
changeset
|
430 (let ((opoint (point))) |
b7ea350590a7
(tab-to-tab-stop): Combine new indentation with previous.
Richard M. Stallman <rms@gnu.org>
parents:
7813
diff
changeset
|
431 (skip-chars-backward " \t") |
b7ea350590a7
(tab-to-tab-stop): Combine new indentation with previous.
Richard M. Stallman <rms@gnu.org>
parents:
7813
diff
changeset
|
432 (delete-region (point) opoint) |
b7ea350590a7
(tab-to-tab-stop): Combine new indentation with previous.
Richard M. Stallman <rms@gnu.org>
parents:
7813
diff
changeset
|
433 (indent-to (car tabs))) |
263 | 434 (insert ?\ )))) |
435 | |
436 (defun move-to-tab-stop () | |
437 "Move point to next defined tab-stop column. | |
438 The variable `tab-stop-list' is a list of columns at which there are tab stops. | |
439 Use \\[edit-tab-stops] to edit them interactively." | |
440 (interactive) | |
441 (let ((tabs tab-stop-list)) | |
442 (while (and tabs (>= (current-column) (car tabs))) | |
443 (setq tabs (cdr tabs))) | |
444 (if tabs | |
8037
fd5fb80a940d
(move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents:
7984
diff
changeset
|
445 (let ((before (point))) |
fd5fb80a940d
(move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents:
7984
diff
changeset
|
446 (move-to-column (car tabs) t) |
fd5fb80a940d
(move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents:
7984
diff
changeset
|
447 (save-excursion |
fd5fb80a940d
(move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents:
7984
diff
changeset
|
448 (goto-char before) |
fd5fb80a940d
(move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents:
7984
diff
changeset
|
449 ;; If we just added a tab, or moved over one, |
fd5fb80a940d
(move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents:
7984
diff
changeset
|
450 ;; delete any superfluous spaces before the old point. |
fd5fb80a940d
(move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents:
7984
diff
changeset
|
451 (if (and (eq (preceding-char) ?\ ) |
fd5fb80a940d
(move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents:
7984
diff
changeset
|
452 (eq (following-char) ?\t)) |
fd5fb80a940d
(move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents:
7984
diff
changeset
|
453 (let ((tabend (* (/ (current-column) tab-width) tab-width))) |
fd5fb80a940d
(move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents:
7984
diff
changeset
|
454 (while (and (> (current-column) tabend) |
fd5fb80a940d
(move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents:
7984
diff
changeset
|
455 (eq (preceding-char) ?\ )) |
fd5fb80a940d
(move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents:
7984
diff
changeset
|
456 (forward-char -1)) |
fd5fb80a940d
(move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents:
7984
diff
changeset
|
457 (delete-region (point) before)))))))) |
fd5fb80a940d
(move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents:
7984
diff
changeset
|
458 |
263 | 459 (define-key global-map "\t" 'indent-for-tab-command) |
460 (define-key esc-map "\034" 'indent-region) | |
461 (define-key ctl-x-map "\t" 'indent-rigidly) | |
462 (define-key esc-map "i" 'tab-to-tab-stop) | |
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
269
diff
changeset
|
463 |
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
269
diff
changeset
|
464 ;;; indent.el ends here |