annotate lisp/indent.el @ 2354:dcc756fba34f

* xterm.h (x_focus_frame): Add extern keyword to declaration.
author Jim Blandy <jimb@redhat.com>
date Thu, 25 Mar 1993 02:12:14 +0000
parents 10e417efb12a
children 794498c64928
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
660
08eb386dd0f3 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 269
diff changeset
1 ;;; indent.el --- indentation commands for Emacs
08eb386dd0f3 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 269
diff changeset
2
845
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
3 ;; Copyright (C) 1985 Free Software Foundation, Inc.
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
4
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 732
diff changeset
5 ;; Maintainer: FSF
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
6
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
8
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 732
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
12 ;; any later version.
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
13
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
17 ;; GNU General Public License for more details.
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
18
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
22
2307
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2201
diff changeset
23 ;;; Commentary:
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2201
diff changeset
24
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2201
diff changeset
25 ;; Commands for making and changing indentation in text. These are
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2201
diff changeset
26 ;; described in the Emacs manual.
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2201
diff changeset
27
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 732
diff changeset
28 ;;; Code:
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
29
269
2ca8cdb96a9f *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 263
diff changeset
30 (defvar indent-line-function 'indent-to-left-margin "\
2192
96adb71c61ec * indent.el (indent-line-function): Doc fix.
Jim Blandy <jimb@redhat.com>
parents: 845
diff changeset
31 Function to indent current line.")
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
32
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
33 (defun indent-according-to-mode ()
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
34 "Indent line in proper way for current major mode."
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
35 (interactive)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
36 (funcall indent-line-function))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
37
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
38 (defun indent-for-tab-command ()
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
39 "Indent line in proper way for current major mode."
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
40 (interactive)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
41 (if (eq indent-line-function 'indent-to-left-margin)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
42 (insert-tab)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
43 (funcall indent-line-function)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
44
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
45 (defun insert-tab ()
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
46 (if abbrev-mode
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
47 (expand-abbrev))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
48 (if indent-tabs-mode
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
49 (insert ?\t)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
50 (indent-to (* tab-width (1+ (/ (current-column) tab-width))))))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
51
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
52 (defun indent-rigidly (start end arg)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
53 "Indent all lines starting in the region sideways by ARG columns.
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
54 Called from a program, takes three arguments, START, END and ARG."
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
55 (interactive "r\np")
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
56 (save-excursion
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
57 (goto-char end)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
58 (setq end (point-marker))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
59 (goto-char start)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
60 (or (bolp) (forward-line 1))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
61 (while (< (point) end)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
62 (let ((indent (current-indentation)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
63 (delete-region (point) (progn (skip-chars-forward " \t") (point)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
64 (or (eolp)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
65 (indent-to (max 0 (+ indent arg)) 0)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
66 (forward-line 1))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
67 (move-marker end nil)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
68
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
69 ;; This is the default indent-line-function,
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
70 ;; used in Fundamental Mode, Text Mode, etc.
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
71 (defun indent-to-left-margin ()
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
72 (or (= (current-indentation) left-margin)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
73 (let (epos)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
74 (save-excursion
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
75 (beginning-of-line)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
76 (delete-region (point)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
77 (progn (skip-chars-forward " \t")
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
78 (point)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
79 (indent-to left-margin)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
80 (setq epos (point)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
81 (if (< (point) epos)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
82 (goto-char epos)))))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
83
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
84 (defvar indent-region-function nil
2201
bfe994df6c27 * indent.el (indent-region, indent-region-function): Doc fix.
Jim Blandy <jimb@redhat.com>
parents: 2192
diff changeset
85 "Function which is short cut to indent region using indent-according-to-mode.
bfe994df6c27 * indent.el (indent-region, indent-region-function): Doc fix.
Jim Blandy <jimb@redhat.com>
parents: 2192
diff changeset
86 A value of nil means really run indent-according-to-mode on each line.")
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
87
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
88 (defun indent-region (start end arg)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
89 "Indent each nonblank line in the region.
2201
bfe994df6c27 * indent.el (indent-region, indent-region-function): Doc fix.
Jim Blandy <jimb@redhat.com>
parents: 2192
diff changeset
90 With no argument, indent each line using indent-according-to-mode.
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
91 \(If there is a fill prefix, make each line start with the fill prefix.)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
92 With argument COLUMN, indent each line to that column.
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
93 Called from a program, takes three args: START, END and COLUMN."
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
94 (interactive "r\nP")
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
95 (if (null arg)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
96 (if fill-prefix
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
97 (save-excursion
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
98 (goto-char end)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
99 (setq end (point-marker))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
100 (goto-char start)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
101 (let ((regexp (regexp-quote fill-prefix)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
102 (while (< (point) end)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
103 (or (looking-at regexp)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
104 (insert fill-prefix))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
105 (forward-line 1))))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
106 (if indent-region-function
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
107 (funcall indent-region-function start end)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
108 (save-excursion
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
109 (goto-char end)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
110 (setq end (point-marker))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
111 (goto-char start)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
112 (or (bolp) (forward-line 1))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
113 (while (< (point) end)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
114 (funcall indent-line-function)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
115 (forward-line 1))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
116 (move-marker end nil))))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
117 (setq arg (prefix-numeric-value arg))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
118 (save-excursion
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
119 (goto-char end)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
120 (setq end (point-marker))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
121 (goto-char start)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
122 (or (bolp) (forward-line 1))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
123 (while (< (point) end)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
124 (delete-region (point) (progn (skip-chars-forward " \t") (point)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
125 (or (eolp)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
126 (indent-to arg 0))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
127 (forward-line 1))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
128 (move-marker end nil))))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
129
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
130 (defun indent-relative-maybe ()
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
131 "Indent a new line like previous nonblank line."
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
132 (interactive)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
133 (indent-relative t))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
134
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
135 (defun indent-relative (&optional unindented-ok)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
136 "Space out to under next indent point in previous nonblank line.
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
137 An indent point is a non-whitespace character following whitespace.
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
138 If the previous nonblank line has no indent points beyond the
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
139 column point starts at, `tab-to-tab-stop' is done instead."
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
140 (interactive "P")
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
141 (if abbrev-mode (expand-abbrev))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
142 (let ((start-column (current-column))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
143 indent)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
144 (save-excursion
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
145 (beginning-of-line)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
146 (if (re-search-backward "^[^\n]" nil t)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
147 (let ((end (save-excursion (forward-line 1) (point))))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
148 (move-to-column start-column)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
149 ;; Is start-column inside a tab on this line?
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
150 (if (> (current-column) start-column)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
151 (backward-char 1))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
152 (or (looking-at "[ \t]")
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
153 unindented-ok
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
154 (skip-chars-forward "^ \t" end))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
155 (skip-chars-forward " \t" end)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
156 (or (= (point) end) (setq indent (current-column))))))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
157 (if indent
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
158 (let ((opoint (point-marker)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
159 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
160 (indent-to indent 0)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
161 (if (> opoint (point))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
162 (goto-char opoint))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
163 (move-marker opoint nil))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
164 (tab-to-tab-stop))))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
165
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
166 (defvar tab-stop-list
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
167 '(8 16 24 32 40 48 56 64 72 80 88 96 104 112 120)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
168 "*List of tab stop positions used by `tab-to-tab-stops'.")
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
169
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
170 (defvar edit-tab-stops-map nil "Keymap used in `edit-tab-stops'.")
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
171 (if edit-tab-stops-map
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
172 nil
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
173 (setq edit-tab-stops-map (make-sparse-keymap))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
174 (define-key edit-tab-stops-map "\C-x\C-s" 'edit-tab-stops-note-changes)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
175 (define-key edit-tab-stops-map "\C-c\C-c" 'edit-tab-stops-note-changes))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
176
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
177 (defvar edit-tab-stops-buffer nil
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
178 "Buffer whose tab stops are being edited--in case
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
179 the variable `tab-stop-list' is local in that buffer.")
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
180
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
181 (defun edit-tab-stops ()
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
182 "Edit the tab stops used by `tab-to-tab-stop'.
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
183 Creates a buffer *Tab Stops* containing text describing the tab stops.
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
184 A colon indicates a column where there is a tab stop.
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
185 You can add or remove colons and then do \\<edit-tab-stops-map>\\[edit-tab-stops-note-changes] to make changes take effect."
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
186 (interactive)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
187 (setq edit-tab-stops-buffer (current-buffer))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
188 (switch-to-buffer (get-buffer-create "*Tab Stops*"))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
189 (use-local-map edit-tab-stops-map)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
190 (make-local-variable 'indent-tabs-mode)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
191 (setq indent-tabs-mode nil)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
192 (overwrite-mode 1)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
193 (setq truncate-lines t)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
194 (erase-buffer)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
195 (let ((tabs tab-stop-list))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
196 (while tabs
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
197 (indent-to (car tabs) 0)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
198 (insert ?:)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
199 (setq tabs (cdr tabs))))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
200 (let ((count 0))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
201 (insert ?\n)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
202 (while (< count 8)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
203 (insert (+ count ?0))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
204 (insert " ")
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
205 (setq count (1+ count)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
206 (insert ?\n)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
207 (while (> count 0)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
208 (insert "0123456789")
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
209 (setq count (1- count))))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
210 (insert "\nTo install changes, type C-c C-c")
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
211 (goto-char (point-min)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
212
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
213 (defun edit-tab-stops-note-changes ()
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
214 "Put edited tab stops into effect."
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
215 (interactive)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
216 (let (tabs)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
217 (save-excursion
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
218 (goto-char 1)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
219 (end-of-line)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
220 (while (search-backward ":" nil t)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
221 (setq tabs (cons (current-column) tabs))))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
222 (bury-buffer (prog1 (current-buffer)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
223 (switch-to-buffer edit-tab-stops-buffer)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
224 (setq tab-stop-list tabs))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
225 (message "Tab stops installed"))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
226
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
227 (defun tab-to-tab-stop ()
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
228 "Insert spaces or tabs to next defined tab-stop column.
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
229 The variable `tab-stop-list' is a list of columns at which there are tab stops.
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
230 Use \\[edit-tab-stops] to edit them interactively."
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
231 (interactive)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
232 (if abbrev-mode (expand-abbrev))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
233 (let ((tabs tab-stop-list))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
234 (while (and tabs (>= (current-column) (car tabs)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
235 (setq tabs (cdr tabs)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
236 (if tabs
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
237 (indent-to (car tabs))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
238 (insert ?\ ))))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
239
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
240 (defun move-to-tab-stop ()
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
241 "Move point to next defined tab-stop column.
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
242 The variable `tab-stop-list' is a list of columns at which there are tab stops.
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
243 Use \\[edit-tab-stops] to edit them interactively."
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
244 (interactive)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
245 (let ((tabs tab-stop-list))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
246 (while (and tabs (>= (current-column) (car tabs)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
247 (setq tabs (cdr tabs)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
248 (if tabs
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
249 (move-to-column (car tabs) t))))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
250
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
251 (define-key global-map "\t" 'indent-for-tab-command)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
252 (define-key esc-map "\034" 'indent-region)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
253 (define-key ctl-x-map "\t" 'indent-rigidly)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
254 (define-key esc-map "i" 'tab-to-tab-stop)
660
08eb386dd0f3 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 269
diff changeset
255
08eb386dd0f3 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 269
diff changeset
256 ;;; indent.el ends here