annotate lisp/indent.el @ 392:1f50e6fe4f3f r21-2-11

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