annotate lisp/prim/indent.el @ 142:1856695b1fa9 r20-2b5

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