Mercurial > hg > xemacs-beta
annotate lisp/indent.el @ 5940:c608d4b0b75e cygwin64 tip
rescue lost branch from 64bit.backup
author | Henry Thompson <ht@markup.co.uk> |
---|---|
date | Thu, 16 Dec 2021 18:48:58 +0000 |
parents | b7ae5f44b950 |
children |
rev | line source |
---|---|
428 | 1 ;;; indent.el --- indentation commands for XEmacs |
2 | |
3 ;; Copyright (C) 1985, 1992, 1993, 1995, 1997 Free Software Foundation, Inc. | |
814 | 4 ;; Copyright (C) 2002 Ben Wing. |
428 | 5 |
6 ;; Maintainer: FSF | |
7 ;; Keywords: lisp, languages, tools, dumped | |
8 | |
9 ;; This file is part of XEmacs. | |
10 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4812
diff
changeset
|
11 ;; XEmacs is free software: you can redistribute it and/or modify it |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4812
diff
changeset
|
12 ;; under the terms of the GNU General Public License as published by the |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4812
diff
changeset
|
13 ;; Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4812
diff
changeset
|
14 ;; option) any later version. |
428 | 15 |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4812
diff
changeset
|
16 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4812
diff
changeset
|
17 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4812
diff
changeset
|
18 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4812
diff
changeset
|
19 ;; for more details. |
428 | 20 |
21 ;; You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
4812
diff
changeset
|
22 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
428 | 23 |
24 ;;; Synched up with: FSF 19.30. | |
25 | |
26 ;;; Commentary: | |
27 | |
28 ;; This file is dumped with XEmacs. | |
29 | |
30 ;; Commands for making and changing indentation in text. These are | |
31 ;; described in the XEmacs Reference Manual. | |
32 | |
33 ;; 06/11/1997 - Convert (preceding|following)-char to char-(before|after) -slb | |
34 | |
35 ;;; Code: | |
36 | |
37 (defvar standard-indent 4 "\ | |
38 Default number of columns for margin-changing functions to indent.") | |
39 | |
40 (defvar indent-line-function 'indent-to-left-margin | |
41 "Function to indent current line.") | |
42 | |
43 (defun indent-according-to-mode () | |
44 "Indent line in proper way for current major mode." | |
45 (interactive) | |
46 (funcall indent-line-function)) | |
47 | |
48 (defun indent-for-tab-command (&optional prefix-arg) | |
49 "Indent line in proper way for current major mode." | |
50 (interactive "P") | |
5655
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
51 (labels |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
52 ((insert-tab (&optional prefix-arg) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
53 (let ((count (prefix-numeric-value prefix-arg))) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
54 (if abbrev-mode |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
55 (expand-abbrev)) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
56 (if indent-tabs-mode |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
57 (insert-char ?\t count) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
58 ;; XEmacs: (Need the `1+') |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
59 (indent-to (* tab-width (1+ (/ (current-column) tab-width)))))))) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
60 (if (eq indent-line-function 'indent-to-left-margin) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
61 (insert-tab prefix-arg) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
62 (if prefix-arg |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
63 (funcall indent-line-function prefix-arg) |
b7ae5f44b950
Remove some redundant functions, change others to labels, lisp/
Aidan Kehoe <kehoea@parhasard.net>
parents:
5402
diff
changeset
|
64 (funcall indent-line-function))))) |
428 | 65 |
444 | 66 (defun indent-rigidly (start end count) |
67 "Indent all lines starting in the region sideways by COUNT columns. | |
68 Called from a program, takes three arguments, START, END and COUNT." | |
428 | 69 (interactive "r\np") |
70 (save-excursion | |
71 (goto-char end) | |
72 (setq end (point-marker)) | |
73 (goto-char start) | |
74 (or (bolp) (forward-line 1)) | |
75 (while (< (point) end) | |
76 (let ((indent (current-indentation)) | |
77 eol-flag) | |
78 (save-excursion | |
79 (skip-chars-forward " \t") | |
80 (setq eol-flag (eolp))) | |
81 (or eol-flag | |
444 | 82 (indent-to (max 0 (+ indent count)) 0)) |
428 | 83 (delete-region (point) (progn (skip-chars-forward " \t") (point)))) |
84 (forward-line 1)) | |
85 (move-marker end nil) | |
86 (setq zmacs-region-stays nil))) ; XEmacs | |
87 | |
88 (defun indent-line-to (column) | |
89 "Indent current line to COLUMN. | |
90 This function removes or adds spaces and tabs at beginning of line | |
91 only if necessary. It leaves point at end of indentation." | |
92 (back-to-indentation) | |
93 (let ((cur-col (current-column))) | |
94 (cond ((< cur-col column) | |
95 (if (>= (- column (* (/ cur-col tab-width) tab-width)) tab-width) | |
96 (delete-region (point) | |
97 (progn (skip-chars-backward " ") (point)))) | |
98 (indent-to column)) | |
99 ((> cur-col column) ; too far right (after tab?) | |
100 (delete-region (progn (move-to-column column t) (point)) | |
101 (progn (back-to-indentation) (point))))))) | |
102 | |
103 (defun current-left-margin () | |
104 "Return the left margin to use for this line. | |
105 This is the value of the buffer-local variable `left-margin' plus the value | |
106 of the `left-margin' text-property at the start of the line." | |
107 (save-excursion | |
108 (back-to-indentation) | |
109 (max 0 | |
110 (+ left-margin (or (get-text-property | |
111 (if (and (eobp) (not (bobp))) | |
112 (1- (point)) (point)) | |
113 'left-margin) 0))))) | |
114 | |
115 (defun move-to-left-margin (&optional n force) | |
116 "Move to the left margin of the current line. | |
117 With optional argument, move forward N-1 lines first. | |
118 The column moved to is the one given by the `current-left-margin' function. | |
119 If the line's indentation appears to be wrong, and this command is called | |
120 interactively or with optional argument FORCE, it will be fixed." | |
121 (interactive (list (prefix-numeric-value current-prefix-arg) t)) | |
122 (beginning-of-line n) | |
123 (skip-chars-forward " \t") | |
124 (let ((lm (current-left-margin)) | |
125 (cc (current-column))) | |
126 (cond ((> cc lm) | |
127 (if (> (move-to-column lm force) lm) | |
128 ;; If lm is in a tab and we are not forcing, move before tab | |
129 (backward-char 1))) | |
130 ((and force (< cc lm)) | |
131 (indent-to-left-margin))))) | |
132 | |
133 ;; This is the default indent-line-function, | |
134 ;; used in Fundamental Mode, Text Mode, etc. | |
135 (defun indent-to-left-margin () | |
136 "Indent current line to the column given by `current-left-margin'." | |
137 (indent-line-to (current-left-margin))) | |
138 | |
139 (defun delete-to-left-margin (&optional from to) | |
140 "Remove left margin indentation from a region. | |
444 | 141 The amount of indentation to delete is determined by calling the |
142 function `current-left-margin'. | |
428 | 143 In no case will it delete non-whitespace. |
144 Args FROM and TO are optional; default is the whole buffer." | |
145 (save-excursion | |
146 (goto-char (or to (point-max))) | |
147 (setq to (point-marker)) | |
148 (goto-char (or from (point-min))) | |
149 (or (bolp) (forward-line 1)) | |
150 (while (< (point) to) | |
151 (delete-region (point) (progn (move-to-left-margin nil t) (point))) | |
152 (forward-line 1)) | |
153 (move-marker to nil))) | |
154 | |
155 (defun set-left-margin (from to lm) | |
156 "Set the left margin of the region to WIDTH. | |
157 If `auto-fill-mode' is active, re-fill the region to fit the new margin." | |
158 (interactive "r\nNSet left margin to column: ") | |
159 (if (interactive-p) (setq lm (prefix-numeric-value lm))) | |
160 (save-excursion | |
161 ;; If inside indentation, start from BOL. | |
162 (goto-char from) | |
163 (skip-chars-backward " \t") | |
164 (if (bolp) (setq from (point))) | |
165 ;; Place end after whitespace | |
166 (goto-char to) | |
167 (skip-chars-forward " \t") | |
168 (setq to (point-marker))) | |
169 ;; Delete margin indentation first, but keep paragraph indentation. | |
170 (delete-to-left-margin from to) | |
171 (put-text-property from to 'left-margin lm) | |
172 (indent-rigidly from to lm) | |
173 (if auto-fill-function (save-excursion (fill-region from to nil t t))) | |
174 (move-marker to nil)) | |
175 | |
176 (defun set-right-margin (from to lm) | |
177 "Set the right margin of the region to WIDTH. | |
178 If `auto-fill-mode' is active, re-fill the region to fit the new margin." | |
179 (interactive "r\nNSet right margin to width: ") | |
180 (if (interactive-p) (setq lm (prefix-numeric-value lm))) | |
181 (save-excursion | |
182 (goto-char from) | |
183 (skip-chars-backward " \t") | |
184 (if (bolp) (setq from (point)))) | |
185 (put-text-property from to 'right-margin lm) | |
186 (if auto-fill-function (save-excursion (fill-region from to nil t t)))) | |
187 | |
188 (defun alter-text-property (from to prop func &optional object) | |
189 "Programmatically change value of a text-property. | |
190 For each region between FROM and TO that has a single value for PROPERTY, | |
191 apply FUNCTION to that value and sets the property to the function's result. | |
192 Optional fifth argument OBJECT specifies the string or buffer to operate on." | |
193 (let ((begin from) | |
194 end val) | |
195 (while (setq val (get-text-property begin prop object) | |
196 end (text-property-not-all begin to prop val object)) | |
197 (put-text-property begin end prop (funcall func val) object) | |
198 (setq begin end)) | |
199 (if (< begin to) | |
200 (put-text-property begin to prop (funcall func val) object)))) | |
201 | |
202 (defun increase-left-margin (from to inc) | |
203 "Increase or decrease the left-margin of the region. | |
204 With no prefix argument, this adds `standard-indent' of indentation. | |
205 A prefix arg (optional third arg INC noninteractively) specifies the amount | |
206 to change the margin by, in characters. | |
207 If `auto-fill-mode' is active, re-fill the region to fit the new margin." | |
208 (interactive "*r\nP") | |
209 (setq inc (if inc (prefix-numeric-value inc) standard-indent)) | |
210 (save-excursion | |
211 (goto-char from) | |
212 (skip-chars-backward " \t") | |
213 (if (bolp) (setq from (point))) | |
214 (goto-char to) | |
215 (setq to (point-marker))) | |
216 (alter-text-property from (marker-position to) 'left-margin ; XEmacs | |
217 (lambda (v) (max (- left-margin) (+ inc (or v 0))))) | |
218 (indent-rigidly from (marker-position to) inc) ; XEmacs | |
219 (if auto-fill-function | |
220 (save-excursion | |
221 (fill-region from (marker-position to) nil t t))) ; XEmacs | |
222 (move-marker to nil)) | |
223 | |
224 (defun decrease-left-margin (from to inc) | |
225 "Make the left margin of the region smaller. | |
226 With no prefix argument, decrease the indentation by `standard-indent'. | |
227 A prefix arg (optional third arg INC noninteractively) specifies the amount | |
228 to change the margin by, in characters. | |
229 If `auto-fill-mode' is active, re-fill the region to fit the new margin." | |
230 (interactive "*r\nP") | |
231 (setq inc (if inc (prefix-numeric-value inc) standard-indent)) | |
232 (increase-left-margin from to (- inc))) | |
233 | |
234 (defun increase-right-margin (from to inc) | |
235 "Increase the right-margin of the region. | |
236 With no prefix argument, increase the right margin by `standard-indent'. | |
237 A prefix arg (optional third arg INC noninteractively) specifies the amount | |
238 to change the margin by, in characters. A negative argument decreases | |
239 the right margin width. | |
240 If `auto-fill-mode' is active, re-fill the region to fit the new margin." | |
241 (interactive "r\nP") | |
242 (if (interactive-p) | |
243 (setq inc (if inc (prefix-numeric-value current-prefix-arg) | |
244 standard-indent))) | |
245 (save-excursion | |
246 (alter-text-property from to 'right-margin | |
247 (lambda (v) (+ inc (or v 0)))) | |
248 (if auto-fill-function | |
249 (fill-region from to nil t t)))) | |
250 | |
251 (defun decrease-right-margin (from to inc) | |
252 "Make the right margin of the region smaller. | |
253 With no prefix argument, decrease the right margin by `standard-indent'. | |
254 A prefix arg (optional third arg INC noninteractively) specifies the amount | |
255 of width to remove, in characters. A negative argument increases | |
256 the right margin width. | |
257 If `auto-fill-mode' is active, re-fills region to fit in new margin." | |
258 (interactive "*r\nP") | |
259 (setq inc (if inc (prefix-numeric-value inc) standard-indent)) | |
260 (increase-right-margin from to (- inc))) | |
261 | |
262 (defun beginning-of-line-text (&optional n) | |
263 "Move to the beginning of the text on this line. | |
264 With optional argument, move forward N-1 lines first. | |
265 From the beginning of the line, moves past the left-margin indentation, the | |
266 fill-prefix, and any indentation used for centering or right-justifying the | |
444 | 267 line, but does not move past any whitespace that was explicitly inserted |
428 | 268 \(such as a tab used to indent the first line of a paragraph)." |
269 (interactive "p") | |
270 (beginning-of-line n) | |
271 (skip-chars-forward " \t") | |
272 ;; Skip over fill-prefix. | |
444 | 273 (if (and fill-prefix |
428 | 274 (not (string-equal fill-prefix ""))) |
275 (if (equal fill-prefix | |
444 | 276 (buffer-substring |
428 | 277 (point) (min (point-max) (+ (length fill-prefix) (point))))) |
278 (forward-char (length fill-prefix))) | |
279 (if (and adaptive-fill-mode adaptive-fill-regexp | |
280 (looking-at adaptive-fill-regexp)) | |
281 (goto-char (match-end 0)))) | |
282 ;; Skip centering or flushright indentation | |
283 (if (memq (current-justification) '(center right)) | |
284 (skip-chars-forward " \t"))) | |
285 | |
286 (defvar indent-region-function nil | |
287 "Short cut function to indent region using `indent-according-to-mode'. | |
288 A value of nil means really run `indent-according-to-mode' on each line.") | |
289 | |
4812
5b560b7374ff
Make COLUMN optional in #'indent-region, as in GNU.
Aidan Kehoe <kehoea@parhasard.net>
parents:
814
diff
changeset
|
290 (defun indent-region (start end &optional column) |
428 | 291 "Indent each nonblank line in the region. |
292 With no argument, indent each line using `indent-according-to-mode', | |
293 or use `indent-region-function' to do the whole region if that's non-nil. | |
294 If there is a fill prefix, make each line start with the fill prefix. | |
295 With argument COLUMN, indent each line to that column. | |
296 Called from a program, takes three args: START, END and COLUMN." | |
297 (interactive "r\nP") | |
298 (if (null column) | |
299 (if fill-prefix | |
300 (save-excursion | |
301 (goto-char end) | |
302 (setq end (point-marker)) | |
303 (goto-char start) | |
304 (let ((regexp (regexp-quote fill-prefix))) | |
305 (while (< (point) end) | |
306 (or (looking-at regexp) | |
307 (and (bolp) (eolp)) | |
308 (insert fill-prefix)) | |
309 (forward-line 1)))) | |
310 (if indent-region-function | |
311 (funcall indent-region-function start end) | |
312 (save-excursion | |
313 (goto-char end) | |
314 (setq end (point-marker)) | |
315 (goto-char start) | |
316 (or (bolp) (forward-line 1)) | |
317 (while (< (point) end) | |
318 (or (and (bolp) (eolp)) | |
319 (funcall indent-line-function)) | |
320 (forward-line 1)) | |
321 (move-marker end nil)))) | |
322 (setq column (prefix-numeric-value column)) | |
323 (save-excursion | |
324 (goto-char end) | |
325 (setq end (point-marker)) | |
326 (goto-char start) | |
327 (or (bolp) (forward-line 1)) | |
328 (while (< (point) end) | |
329 (delete-region (point) (progn (skip-chars-forward " \t") (point))) | |
330 (or (eolp) | |
331 (indent-to column 0)) | |
332 (forward-line 1)) | |
333 (move-marker end nil)))) | |
334 | |
814 | 335 (defvar indent-balanced-expression-function nil |
336 "Short cut function to indent balanced expression. | |
337 A value of nil means really run `indent-according-to-mode' on each line of | |
338 balanced expression as computed with `forward-sexp'.") | |
339 | |
340 (defun indent-balanced-expression () | |
341 "Indent each nonblank line in the balanced expression at point. | |
342 Use `indent-balanced-expression-function' if that's non-nil, or find | |
343 expression with `forward-sexp' and use `indent-region' on result." | |
344 (interactive "") | |
345 (let ((fun (or indent-balanced-expression-function | |
346 (cond ((memq major-mode '(c-mode c++-mode java-mode objc-mode | |
347 idl-mode pike-mode | |
348 c++-c-mode elec-c-mode)) | |
349 'c-indent-exp) | |
350 ((memq major-mode | |
351 '(lisp-mode | |
352 emacs-lisp-mode lisp-interaction-mode | |
353 scheme-mode inferior-scheme-mode | |
354 scheme-interaction-mode)) | |
355 'indent-sexp))))) | |
356 (if fun (funcall fun) | |
357 (let ((end (save-excursion (forward-sexp) (point)))) | |
358 (indent-region (point) end nil))))) | |
359 | |
360 (defun indent-region-or-balanced-expression () | |
361 "Indent region if active, or balanced expression at point. | |
362 See `indent-region' and `indent-balanced-expression'." | |
363 (interactive "") | |
364 (if (region-active-p) | |
365 (indent-region (region-beginning) (region-end) nil) | |
366 (indent-balanced-expression))) | |
367 | |
428 | 368 (defun indent-relative-maybe () |
369 "Indent a new line like previous nonblank line." | |
370 (interactive) | |
371 (indent-relative t)) | |
372 | |
373 (defun indent-relative (&optional unindented-ok) | |
374 "Space out to under next indent point in previous nonblank line. | |
375 An indent point is a non-whitespace character following whitespace. | |
376 If the previous nonblank line has no indent points beyond the | |
377 column point starts at, `tab-to-tab-stop' is done instead." | |
378 (interactive "P") | |
379 (if abbrev-mode (expand-abbrev)) | |
380 (let ((start-column (current-column)) | |
381 indent) | |
382 (save-excursion | |
383 (beginning-of-line) | |
384 (if (re-search-backward "^[^\n]" nil t) | |
385 (let ((end (save-excursion (forward-line 1) (point)))) | |
386 (move-to-column start-column) | |
387 ;; Is start-column inside a tab on this line? | |
388 (if (> (current-column) start-column) | |
389 (backward-char 1)) | |
390 (or (looking-at "[ \t]") | |
391 unindented-ok | |
392 (skip-chars-forward "^ \t" end)) | |
393 (skip-chars-forward " \t" end) | |
394 (or (= (point) end) (setq indent (current-column)))))) | |
395 (if indent | |
396 (let ((opoint (point-marker))) | |
397 (delete-region (point) (progn (skip-chars-backward " \t") (point))) | |
398 (indent-to indent 0) | |
399 (if (> opoint (point)) | |
400 (goto-char opoint)) | |
401 (move-marker opoint nil)) | |
402 (tab-to-tab-stop)))) | |
403 | |
404 (defvar tab-stop-list | |
405 '(8 16 24 32 40 48 56 64 72 80 88 96 104 112 120) | |
406 "*List of tab stop positions used by `tab-to-tab-stops'. | |
407 This should be a list of integers, ordered from smallest to largest.") | |
408 | |
409 (defvar edit-tab-stops-map nil "Keymap used in `edit-tab-stops'.") | |
410 (if edit-tab-stops-map | |
411 nil | |
412 (setq edit-tab-stops-map (make-sparse-keymap)) | |
413 (define-key edit-tab-stops-map "\C-x\C-s" 'edit-tab-stops-note-changes) | |
414 (define-key edit-tab-stops-map "\C-c\C-c" 'edit-tab-stops-note-changes)) | |
415 | |
416 (defvar edit-tab-stops-buffer nil | |
417 "Buffer whose tab stops are being edited--in case | |
418 the variable `tab-stop-list' is local in that buffer.") | |
419 | |
420 (defun edit-tab-stops () | |
421 "Edit the tab stops used by `tab-to-tab-stop'. | |
422 Creates a buffer *Tab Stops* containing text describing the tab stops. | |
423 A colon indicates a column where there is a tab stop. | |
424 You can add or remove colons and then do \\<edit-tab-stops-map>\\[edit-tab-stops-note-changes] to make changes take effect." | |
425 (interactive) | |
426 (setq edit-tab-stops-buffer (current-buffer)) | |
427 (switch-to-buffer (get-buffer-create "*Tab Stops*")) | |
428 ;; #### I18N3 should mark buffer as output-translating | |
429 (use-local-map edit-tab-stops-map) | |
430 (make-local-variable 'indent-tabs-mode) | |
431 (setq indent-tabs-mode nil) | |
432 (overwrite-mode 1) | |
433 (setq truncate-lines t) | |
434 (erase-buffer) | |
435 (let ((tabs tab-stop-list)) | |
436 (while tabs | |
437 (indent-to (car tabs) 0) | |
438 (insert ?:) | |
439 (setq tabs (cdr tabs)))) | |
440 (let ((count 0)) | |
441 (insert ?\n) | |
442 (while (< count 8) | |
443 (insert (+ count ?0)) | |
444 (insert " ") | |
445 (setq count (1+ count))) | |
446 (insert ?\n) | |
447 (while (> count 0) | |
448 (insert "0123456789") | |
449 (setq count (1- count)))) | |
450 ;; XEmacs | |
451 (insert (substitute-command-keys "\nTo install changes, type \\<edit-tab-stops-map>\\[edit-tab-stops-note-changes]")) | |
452 (goto-char (point-min))) | |
453 | |
454 (defun edit-tab-stops-note-changes () | |
455 "Put edited tab stops into effect." | |
456 (interactive) | |
457 (let (tabs) | |
458 (save-excursion | |
459 (goto-char 1) | |
460 (end-of-line) | |
461 (while (search-backward ":" nil t) | |
462 (setq tabs (cons (current-column) tabs)))) | |
463 (bury-buffer (prog1 (current-buffer) | |
464 (switch-to-buffer edit-tab-stops-buffer))) | |
465 (setq tab-stop-list tabs)) | |
466 (message "Tab stops installed")) | |
467 | |
468 (defun tab-to-tab-stop () | |
469 "Insert spaces or tabs to next defined tab-stop column. | |
470 The variable `tab-stop-list' is a list of columns at which there are tab stops. | |
471 Use \\[edit-tab-stops] to edit them interactively." | |
472 (interactive) | |
473 (and abbrev-mode (eq (char-syntax (char-before (point))) ?w) | |
474 (expand-abbrev)) | |
475 (let ((tabs tab-stop-list)) | |
476 (while (and tabs (>= (current-column) (car tabs))) | |
477 (setq tabs (cdr tabs))) | |
478 (if tabs | |
479 (let ((opoint (point))) | |
480 (skip-chars-backward " \t") | |
481 (delete-region (point) opoint) | |
482 (indent-to (car tabs))) | |
483 (insert ?\ )))) | |
484 | |
485 (defun move-to-tab-stop () | |
486 "Move point to next defined tab-stop column. | |
487 The variable `tab-stop-list' is a list of columns at which there are tab stops. | |
488 Use \\[edit-tab-stops] to edit them interactively." | |
489 (interactive) | |
490 (let ((tabs tab-stop-list)) | |
491 (while (and tabs (>= (current-column) (car tabs))) | |
492 (setq tabs (cdr tabs))) | |
493 (if tabs | |
494 (let ((before (point))) | |
495 (move-to-column (car tabs) t) | |
496 (save-excursion | |
497 (goto-char before) | |
498 ;; If we just added a tab, or moved over one, | |
499 ;; delete any superfluous spaces before the old point. | |
500 (if (and (eq (char-before (point)) ?\ ) | |
501 (eq (char-after (point)) ?\t)) | |
502 (let ((tabend (* (/ (current-column) tab-width) tab-width))) | |
503 (while (and (> (current-column) tabend) | |
504 (eq (char-before (point)) ?\ )) | |
446 | 505 (backward-char 1)) |
428 | 506 (delete-region (point) before)))))))) |
507 | |
508 ;(define-key global-map "\t" 'indent-for-tab-command) | |
509 ;(define-key esc-map "\034" 'indent-region) | |
510 ;(define-key ctl-x-map "\t" 'indent-rigidly) | |
511 ;(define-key esc-map "i" 'tab-to-tab-stop) | |
512 | |
513 ;;; indent.el ends here |