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