annotate lisp/indent.el @ 24419:30e478cd167e

(shell-command-default-error-buffer): Renamed from shell-command-on-region-default-error-buffer. (shell-command-on-region): Mention in echo area when there is some error output. Mention success or failure, too. Accumulate multiple error outputs going forward, with formfeed in between. Display the error buffer when we have put something in it. (shell-command): Add the ERROR-BUFFER argument feature.
author Karl Heuer <kwzh@gnu.org>
date Mon, 01 Mar 1999 03:19:32 +0000
parents bff4ed62d00a
children 611af07c47c2
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
11235
e6bdaaa6ce1b Update copyright.
Karl Heuer <kwzh@gnu.org>
parents: 11043
diff changeset
3 ;; Copyright (C) 1985, 1995 Free Software Foundation, Inc.
845
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
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13577
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13577
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13577
diff changeset
22 ;; Boston, MA 02111-1307, USA.
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
23
2307
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2201
diff changeset
24 ;;; Commentary:
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2201
diff changeset
25
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2201
diff changeset
26 ;; 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
27 ;; described in the Emacs manual.
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2201
diff changeset
28
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 732
diff changeset
29 ;;; Code:
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
30
19420
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17155
diff changeset
31 (defgroup indent nil
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17155
diff changeset
32 "Indentation commands"
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17155
diff changeset
33 :group 'editing)
10467
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
34
19420
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17155
diff changeset
35 (defcustom standard-indent 4
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17155
diff changeset
36 "*Default number of columns for margin-changing functions to indent."
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17155
diff changeset
37 :group 'indent
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17155
diff changeset
38 :type 'integer)
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17155
diff changeset
39
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17155
diff changeset
40 (defvar indent-line-function 'indent-to-left-margin
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17155
diff changeset
41 "Function to indent current line.")
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
42
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
43 (defun indent-according-to-mode ()
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
44 "Indent line in proper way for current major mode."
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
45 (interactive)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
46 (funcall indent-line-function))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
47
13035
b8453eab5114 (indent-for-tab-command): Get the prefix arg
Richard M. Stallman <rms@gnu.org>
parents: 12778
diff changeset
48 (defun indent-for-tab-command (&optional prefix-arg)
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
49 "Indent line in proper way for current major mode."
13035
b8453eab5114 (indent-for-tab-command): Get the prefix arg
Richard M. Stallman <rms@gnu.org>
parents: 12778
diff changeset
50 (interactive "P")
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
51 (if (eq indent-line-function 'indent-to-left-margin)
15106
83b8438fa1a4 (indent-for-tab-command): Pass prefix arg to indent-tab.
Richard M. Stallman <rms@gnu.org>
parents: 14770
diff changeset
52 (insert-tab prefix-arg)
13035
b8453eab5114 (indent-for-tab-command): Get the prefix arg
Richard M. Stallman <rms@gnu.org>
parents: 12778
diff changeset
53 (if prefix-arg
b8453eab5114 (indent-for-tab-command): Get the prefix arg
Richard M. Stallman <rms@gnu.org>
parents: 12778
diff changeset
54 (funcall indent-line-function prefix-arg)
b8453eab5114 (indent-for-tab-command): Get the prefix arg
Richard M. Stallman <rms@gnu.org>
parents: 12778
diff changeset
55 (funcall indent-line-function))))
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
56
15106
83b8438fa1a4 (indent-for-tab-command): Pass prefix arg to indent-tab.
Richard M. Stallman <rms@gnu.org>
parents: 14770
diff changeset
57 (defun insert-tab (&optional prefix-arg)
83b8438fa1a4 (indent-for-tab-command): Pass prefix arg to indent-tab.
Richard M. Stallman <rms@gnu.org>
parents: 14770
diff changeset
58 (let ((count (prefix-numeric-value prefix-arg)))
19508
c86800208845 (indent-relative, insert-tab):
Richard M. Stallman <rms@gnu.org>
parents: 19420
diff changeset
59 (if (and abbrev-mode
c86800208845 (indent-relative, insert-tab):
Richard M. Stallman <rms@gnu.org>
parents: 19420
diff changeset
60 (eq (char-syntax (preceding-char)) ?w))
15106
83b8438fa1a4 (indent-for-tab-command): Pass prefix arg to indent-tab.
Richard M. Stallman <rms@gnu.org>
parents: 14770
diff changeset
61 (expand-abbrev))
83b8438fa1a4 (indent-for-tab-command): Pass prefix arg to indent-tab.
Richard M. Stallman <rms@gnu.org>
parents: 14770
diff changeset
62 (if indent-tabs-mode
15113
8db176b73c9f (insert-tab): fix previous change
Erik Naggum <erik@naggum.no>
parents: 15106
diff changeset
63 (insert-char ?\t count)
15106
83b8438fa1a4 (indent-for-tab-command): Pass prefix arg to indent-tab.
Richard M. Stallman <rms@gnu.org>
parents: 14770
diff changeset
64 (indent-to (* tab-width (+ count (/ (current-column) tab-width)))))))
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
65
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
66 (defun indent-rigidly (start end arg)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
67 "Indent all lines starting in the region sideways by ARG columns.
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
68 Called from a program, takes three arguments, START, END and ARG."
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
69 (interactive "r\np")
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
70 (save-excursion
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
71 (goto-char end)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
72 (setq end (point-marker))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
73 (goto-char start)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
74 (or (bolp) (forward-line 1))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
75 (while (< (point) end)
8642
ae3b75bae5d7 (indent-rigidly): Insert new indent, then delete old.
Richard M. Stallman <rms@gnu.org>
parents: 8208
diff changeset
76 (let ((indent (current-indentation))
ae3b75bae5d7 (indent-rigidly): Insert new indent, then delete old.
Richard M. Stallman <rms@gnu.org>
parents: 8208
diff changeset
77 eol-flag)
ae3b75bae5d7 (indent-rigidly): Insert new indent, then delete old.
Richard M. Stallman <rms@gnu.org>
parents: 8208
diff changeset
78 (save-excursion
ae3b75bae5d7 (indent-rigidly): Insert new indent, then delete old.
Richard M. Stallman <rms@gnu.org>
parents: 8208
diff changeset
79 (skip-chars-forward " \t")
ae3b75bae5d7 (indent-rigidly): Insert new indent, then delete old.
Richard M. Stallman <rms@gnu.org>
parents: 8208
diff changeset
80 (setq eol-flag (eolp)))
ae3b75bae5d7 (indent-rigidly): Insert new indent, then delete old.
Richard M. Stallman <rms@gnu.org>
parents: 8208
diff changeset
81 (or eol-flag
ae3b75bae5d7 (indent-rigidly): Insert new indent, then delete old.
Richard M. Stallman <rms@gnu.org>
parents: 8208
diff changeset
82 (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
83 (delete-region (point) (progn (skip-chars-forward " \t") (point))))
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
84 (forward-line 1))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
85 (move-marker end nil)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
86
10467
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
87 (defun indent-line-to (column)
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
88 "Indent current line to COLUMN.
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
89 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
90 only if necessary. It leaves point at end of indentation."
11043
4c0a98538670 (indent-line-to): move to end of indentation, even if it didn't change.
Boris Goldowsky <boris@gnu.org>
parents: 10812
diff changeset
91 (back-to-indentation)
4c0a98538670 (indent-line-to): move to end of indentation, even if it didn't change.
Boris Goldowsky <boris@gnu.org>
parents: 10812
diff changeset
92 (let ((cur-col (current-column)))
4c0a98538670 (indent-line-to): move to end of indentation, even if it didn't change.
Boris Goldowsky <boris@gnu.org>
parents: 10812
diff changeset
93 (cond ((< cur-col column)
17155
d8e2f7cfb2b7 (indent-line-to): Fix off-by-one bug when deciding
Karl Heuer <kwzh@gnu.org>
parents: 15113
diff changeset
94 (if (>= (- column (* (/ cur-col tab-width) tab-width)) tab-width)
13545
1418ed733e9d (indent-line-to): Delete spaces before inserting a tab.
Richard M. Stallman <rms@gnu.org>
parents: 13035
diff changeset
95 (delete-region (point)
1418ed733e9d (indent-line-to): Delete spaces before inserting a tab.
Richard M. Stallman <rms@gnu.org>
parents: 13035
diff changeset
96 (progn (skip-chars-backward " ") (point))))
11043
4c0a98538670 (indent-line-to): move to end of indentation, even if it didn't change.
Boris Goldowsky <boris@gnu.org>
parents: 10812
diff changeset
97 (indent-to column))
4c0a98538670 (indent-line-to): move to end of indentation, even if it didn't change.
Boris Goldowsky <boris@gnu.org>
parents: 10812
diff changeset
98 ((> cur-col column) ; too far right (after tab?)
10812
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
99 (delete-region (progn (move-to-column column t) (point))
11043
4c0a98538670 (indent-line-to): move to end of indentation, even if it didn't change.
Boris Goldowsky <boris@gnu.org>
parents: 10812
diff changeset
100 (progn (back-to-indentation) (point)))))))
10467
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
101
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
102 (defun current-left-margin ()
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
103 "Return the left margin to use for this line.
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
104 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
105 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
106 (save-excursion
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
107 (back-to-indentation)
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
108 (max 0
10812
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
109 (+ left-margin (or (get-text-property
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
110 (if (and (eobp) (not (bobp)))
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
111 (1- (point)) (point))
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
112 'left-margin) 0)))))
10467
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
113
10812
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
114 (defun move-to-left-margin (&optional n force)
10467
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
115 "Move to the left margin of the current line.
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
116 With optional argument, move forward N-1 lines first.
10812
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
117 The column moved to is the one given by the `current-left-margin' function.
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
118 If the line's indentation appears to be wrong, and this command is called
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
119 interactively or with optional argument FORCE, it will be fixed."
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
120 (interactive (list (prefix-numeric-value current-prefix-arg) t))
10467
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
121 (beginning-of-line n)
13577
d88cdc4a0cfe (move-to-left-margin): Removed left-over code that
Richard M. Stallman <rms@gnu.org>
parents: 13545
diff changeset
122 (skip-chars-forward " \t")
d88cdc4a0cfe (move-to-left-margin): Removed left-over code that
Richard M. Stallman <rms@gnu.org>
parents: 13545
diff changeset
123 (let ((lm (current-left-margin))
d88cdc4a0cfe (move-to-left-margin): Removed left-over code that
Richard M. Stallman <rms@gnu.org>
parents: 13545
diff changeset
124 (cc (current-column)))
d88cdc4a0cfe (move-to-left-margin): Removed left-over code that
Richard M. Stallman <rms@gnu.org>
parents: 13545
diff changeset
125 (cond ((> cc lm)
d88cdc4a0cfe (move-to-left-margin): Removed left-over code that
Richard M. Stallman <rms@gnu.org>
parents: 13545
diff changeset
126 (if (> (move-to-column lm force) lm)
d88cdc4a0cfe (move-to-left-margin): Removed left-over code that
Richard M. Stallman <rms@gnu.org>
parents: 13545
diff changeset
127 ;; If lm is in a tab and we are not forcing, move before tab
d88cdc4a0cfe (move-to-left-margin): Removed left-over code that
Richard M. Stallman <rms@gnu.org>
parents: 13545
diff changeset
128 (backward-char 1)))
d88cdc4a0cfe (move-to-left-margin): Removed left-over code that
Richard M. Stallman <rms@gnu.org>
parents: 13545
diff changeset
129 ((and force (< cc lm))
d88cdc4a0cfe (move-to-left-margin): Removed left-over code that
Richard M. Stallman <rms@gnu.org>
parents: 13545
diff changeset
130 (indent-to-left-margin)))))
10467
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
131
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
132 ;; This is the default indent-line-function,
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
133 ;; used in Fundamental Mode, Text Mode, etc.
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
134 (defun indent-to-left-margin ()
10812
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
135 "Indent current line to the column given by `current-left-margin'."
10467
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
136 (indent-line-to (current-left-margin)))
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
137
10812
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
138 (defun delete-to-left-margin (&optional from to)
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
139 "Remove left margin indentation from a region.
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
140 This deletes to the column given by `current-left-margin'.
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
141 In no case will it delete non-whitespace.
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
142 Args FROM and TO are optional; default is the whole buffer."
10467
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
143 (save-excursion
10812
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
144 (goto-char (or to (point-max)))
10467
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
145 (setq to (point-marker))
10812
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
146 (goto-char (or from (point-min)))
10467
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
147 (or (bolp) (forward-line 1))
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
148 (while (< (point) to)
10812
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
149 (delete-region (point) (progn (move-to-left-margin nil t) (point)))
10467
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
150 (forward-line 1))
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
151 (move-marker to nil)))
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
152
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
153 (defun set-left-margin (from to lm)
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
154 "Set the left margin of the region to WIDTH.
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
155 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
156 (interactive "r\nNSet left margin to column: ")
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
157 (if (interactive-p) (setq lm (prefix-numeric-value lm)))
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
158 (save-excursion
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
159 ;; If inside indentation, start from BOL.
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
160 (goto-char from)
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
161 (skip-chars-backward " \t")
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
162 (if (bolp) (setq from (point)))
10812
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
163 ;; Place end after whitespace
10467
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
164 (goto-char to)
10812
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
165 (skip-chars-forward " \t")
10467
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
166 (setq to (point-marker)))
10812
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
167 ;; Delete margin indentation first, but keep paragraph indentation.
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
168 (delete-to-left-margin from to)
10467
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
169 (put-text-property from to 'left-margin lm)
10812
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
170 (indent-rigidly from to lm)
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
171 (if auto-fill-function (save-excursion (fill-region from to nil t t)))
10467
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
172 (move-marker to nil))
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 set-right-margin (from to lm)
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
175 "Set the right margin of the region to WIDTH.
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
176 If `auto-fill-mode' is active, re-fill the region to fit the new margin."
11281
10f9cf00c770 (set-right-margin): Fix prompt.
Richard M. Stallman <rms@gnu.org>
parents: 11235
diff changeset
177 (interactive "r\nNSet right margin to width: ")
10467
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
178 (if (interactive-p) (setq lm (prefix-numeric-value lm)))
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
179 (save-excursion
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
180 (goto-char from)
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
181 (skip-chars-backward " \t")
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
182 (if (bolp) (setq from (point))))
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
183 (put-text-property from to 'right-margin lm)
10812
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
184 (if auto-fill-function (save-excursion (fill-region from to nil t t))))
10467
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
185
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
186 (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
187 "Programmatically change value of a text-property.
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
188 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
189 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
190 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
191 (let ((begin from)
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
192 end val)
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
193 (while (setq val (get-text-property begin prop object)
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
194 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
195 (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
196 (setq begin end))
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
197 (if (< begin to)
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
198 (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
199
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
200 (defun increase-left-margin (from to inc)
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
201 "Increase or decrease the left-margin of the region.
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
202 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
203 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
204 to change the margin by, in characters.
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
205 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
206 (interactive "*r\nP")
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
207 (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
208 (save-excursion
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
209 (goto-char from)
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
210 (skip-chars-backward " \t")
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
211 (if (bolp) (setq from (point)))
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
212 (goto-char to)
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
213 (setq to (point-marker)))
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
214 (alter-text-property from to 'left-margin
10812
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
215 (lambda (v) (max (- left-margin) (+ inc (or v 0)))))
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
216 (indent-rigidly from to inc)
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
217 (if auto-fill-function (save-excursion (fill-region from to nil t t)))
10467
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
218 (move-marker to nil))
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
219
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
220 (defun decrease-left-margin (from to inc)
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
221 "Make the left margin of the region smaller.
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
222 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
223 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
224 to change the margin by, in characters.
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
225 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
226 (interactive "*r\nP")
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
227 (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
228 (increase-left-margin from to (- inc)))
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
229
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
230 (defun increase-right-margin (from to inc)
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
231 "Increase the right-margin of the region.
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
232 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
233 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
234 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
235 the right margin width.
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
236 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
237 (interactive "r\nP")
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
238 (if (interactive-p)
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
239 (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
240 standard-indent)))
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
241 (save-excursion
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
242 (alter-text-property from to 'right-margin
10812
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
243 (lambda (v) (+ inc (or v 0))))
10467
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
244 (if auto-fill-function
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
245 (fill-region from to nil t t))))
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
246
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
247 (defun decrease-right-margin (from to inc)
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
248 "Make the right margin of the region smaller.
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
249 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
250 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
251 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
252 the right margin width.
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
253 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
254 (interactive "*r\nP")
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
255 (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
256 (increase-right-margin from to (- inc)))
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
257
10812
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
258 (defun beginning-of-line-text (&optional n)
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
259 "Move to the beginning of the text on this line.
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
260 With optional argument, move forward N-1 lines first.
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
261 From the beginning of the line, moves past the left-margin indentation, the
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
262 fill-prefix, and any indentation used for centering or right-justifying the
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
263 line, but does not move past any whitespace that was explicitly inserted
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
264 \(such as a tab used to indent the first line of a paragraph)."
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
265 (interactive "p")
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
266 (beginning-of-line n)
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
267 (skip-chars-forward " \t")
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
268 ;; Skip over fill-prefix.
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
269 (if (and fill-prefix
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
270 (not (string-equal fill-prefix "")))
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
271 (if (equal fill-prefix
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
272 (buffer-substring
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
273 (point) (min (point-max) (+ (length fill-prefix) (point)))))
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
274 (forward-char (length fill-prefix)))
14770
e3567339daa7 (beginning-of-line-text): Check adaptive-fill-regexp is non-nil.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
275 (if (and adaptive-fill-mode adaptive-fill-regexp
10812
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
276 (looking-at adaptive-fill-regexp))
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
277 (goto-char (match-end 0))))
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
278 ;; Skip centering or flushright indentation
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
279 (if (memq (current-justification) '(center right))
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
280 (skip-chars-forward " \t")))
cd0a341fd620 (current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents: 10470
diff changeset
281
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
282 (defvar indent-region-function nil
12683
0e9d2009e609 (indent-region-function): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 11281
diff changeset
283 "Short cut function to indent region using `indent-according-to-mode'.
0e9d2009e609 (indent-region-function): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 11281
diff changeset
284 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
285
4465
794498c64928 (indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
286 (defun indent-region (start end column)
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
287 "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
288 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
289 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
290 If there is a fill prefix, make each line start with the fill prefix.
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
291 With argument COLUMN, indent each line to that column.
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
292 Called from a program, takes three args: START, END and COLUMN."
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
293 (interactive "r\nP")
4465
794498c64928 (indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
294 (if (null column)
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
295 (if fill-prefix
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
296 (save-excursion
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
297 (goto-char end)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
298 (setq end (point-marker))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
299 (goto-char start)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
300 (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
301 (while (< (point) end)
794498c64928 (indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
302 (or (looking-at regexp)
794498c64928 (indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
303 (and (bolp) (eolp))
794498c64928 (indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
304 (insert fill-prefix))
794498c64928 (indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
305 (forward-line 1))))
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
306 (if indent-region-function
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
307 (funcall indent-region-function start end)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
308 (save-excursion
4465
794498c64928 (indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
309 (goto-char end)
794498c64928 (indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
310 (setq end (point-marker))
794498c64928 (indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
311 (goto-char start)
794498c64928 (indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
312 (or (bolp) (forward-line 1))
794498c64928 (indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
313 (while (< (point) end)
4473
600d0d832d99 (indent-region): Fix paren error in last change.
Richard M. Stallman <rms@gnu.org>
parents: 4465
diff changeset
314 (or (and (bolp) (eolp))
4465
794498c64928 (indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
315 (funcall indent-line-function))
794498c64928 (indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
316 (forward-line 1))
794498c64928 (indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
317 (move-marker end nil))))
794498c64928 (indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents: 2307
diff changeset
318 (setq column (prefix-numeric-value column))
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
319 (save-excursion
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
320 (goto-char end)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
321 (setq end (point-marker))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
322 (goto-char start)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
323 (or (bolp) (forward-line 1))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
324 (while (< (point) end)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
325 (delete-region (point) (progn (skip-chars-forward " \t") (point)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
326 (or (eolp)
10467
b8053ce05ab5 (standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 8642
diff changeset
327 (indent-to column 0))
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
328 (forward-line 1))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
329 (move-marker end nil))))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
330
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
331 (defun indent-relative-maybe ()
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
332 "Indent a new line like previous nonblank line."
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
333 (interactive)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
334 (indent-relative t))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
335
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
336 (defun indent-relative (&optional unindented-ok)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
337 "Space out to under next indent point in previous nonblank line.
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
338 An indent point is a non-whitespace character following whitespace.
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
339 If the previous nonblank line has no indent points beyond the
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
340 column point starts at, `tab-to-tab-stop' is done instead."
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
341 (interactive "P")
19508
c86800208845 (indent-relative, insert-tab):
Richard M. Stallman <rms@gnu.org>
parents: 19420
diff changeset
342 (if (and abbrev-mode
c86800208845 (indent-relative, insert-tab):
Richard M. Stallman <rms@gnu.org>
parents: 19420
diff changeset
343 (eq (char-syntax (preceding-char)) ?w))
c86800208845 (indent-relative, insert-tab):
Richard M. Stallman <rms@gnu.org>
parents: 19420
diff changeset
344 (expand-abbrev))
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
345 (let ((start-column (current-column))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
346 indent)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
347 (save-excursion
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
348 (beginning-of-line)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
349 (if (re-search-backward "^[^\n]" nil t)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
350 (let ((end (save-excursion (forward-line 1) (point))))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
351 (move-to-column start-column)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
352 ;; Is start-column inside a tab on this line?
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
353 (if (> (current-column) start-column)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
354 (backward-char 1))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
355 (or (looking-at "[ \t]")
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
356 unindented-ok
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
357 (skip-chars-forward "^ \t" end))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
358 (skip-chars-forward " \t" end)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
359 (or (= (point) end) (setq indent (current-column))))))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
360 (if indent
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
361 (let ((opoint (point-marker)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
362 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
363 (indent-to indent 0)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
364 (if (> opoint (point))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
365 (goto-char opoint))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
366 (move-marker opoint nil))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
367 (tab-to-tab-stop))))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
368
19420
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17155
diff changeset
369 (defcustom tab-stop-list
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
370 '(8 16 24 32 40 48 56 64 72 80 88 96 104 112 120)
19895
bff4ed62d00a (tab-stop-list): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 19508
diff changeset
371 "*List of tab stop positions used by `tab-to-tab-stop'.
19420
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17155
diff changeset
372 This should be a list of integers, ordered from smallest to largest."
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17155
diff changeset
373 :group 'indent
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 17155
diff changeset
374 :type '(repeat integer))
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
375
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
376 (defvar edit-tab-stops-map nil "Keymap used in `edit-tab-stops'.")
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
377 (if edit-tab-stops-map
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
378 nil
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
379 (setq edit-tab-stops-map (make-sparse-keymap))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
380 (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
381 (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
382
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
383 (defvar edit-tab-stops-buffer nil
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
384 "Buffer whose tab stops are being edited--in case
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
385 the variable `tab-stop-list' is local in that buffer.")
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
386
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
387 (defun edit-tab-stops ()
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
388 "Edit the tab stops used by `tab-to-tab-stop'.
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
389 Creates a buffer *Tab Stops* containing text describing the tab stops.
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
390 A colon indicates a column where there is a tab stop.
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
391 You can add or remove colons and then do \\<edit-tab-stops-map>\\[edit-tab-stops-note-changes] to make changes take effect."
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
392 (interactive)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
393 (setq edit-tab-stops-buffer (current-buffer))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
394 (switch-to-buffer (get-buffer-create "*Tab Stops*"))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
395 (use-local-map edit-tab-stops-map)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
396 (make-local-variable 'indent-tabs-mode)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
397 (setq indent-tabs-mode nil)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
398 (overwrite-mode 1)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
399 (setq truncate-lines t)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
400 (erase-buffer)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
401 (let ((tabs tab-stop-list))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
402 (while tabs
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
403 (indent-to (car tabs) 0)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
404 (insert ?:)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
405 (setq tabs (cdr tabs))))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
406 (let ((count 0))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
407 (insert ?\n)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
408 (while (< count 8)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
409 (insert (+ count ?0))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
410 (insert " ")
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
411 (setq count (1+ count)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
412 (insert ?\n)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
413 (while (> count 0)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
414 (insert "0123456789")
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
415 (setq count (1- count))))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
416 (insert "\nTo install changes, type C-c C-c")
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
417 (goto-char (point-min)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
418
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
419 (defun edit-tab-stops-note-changes ()
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
420 "Put edited tab stops into effect."
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
421 (interactive)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
422 (let (tabs)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
423 (save-excursion
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
424 (goto-char 1)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
425 (end-of-line)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
426 (while (search-backward ":" nil t)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
427 (setq tabs (cons (current-column) tabs))))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
428 (bury-buffer (prog1 (current-buffer)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
429 (switch-to-buffer edit-tab-stops-buffer)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
430 (setq tab-stop-list tabs))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
431 (message "Tab stops installed"))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
432
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
433 (defun tab-to-tab-stop ()
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
434 "Insert spaces or tabs to next defined tab-stop column.
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
435 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
436 Use \\[edit-tab-stops] to edit them interactively."
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
437 (interactive)
12778
657be7aaa043 (tab-to-tab-stop): Expand abbrevs only after a word-char.
Richard M. Stallman <rms@gnu.org>
parents: 12683
diff changeset
438 (and abbrev-mode (= (char-syntax (preceding-char)) ?w)
657be7aaa043 (tab-to-tab-stop): Expand abbrevs only after a word-char.
Richard M. Stallman <rms@gnu.org>
parents: 12683
diff changeset
439 (expand-abbrev))
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
440 (let ((tabs tab-stop-list))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
441 (while (and tabs (>= (current-column) (car tabs)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
442 (setq tabs (cdr tabs)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
443 (if tabs
7973
b7ea350590a7 (tab-to-tab-stop): Combine new indentation with previous.
Richard M. Stallman <rms@gnu.org>
parents: 7813
diff changeset
444 (let ((opoint (point)))
b7ea350590a7 (tab-to-tab-stop): Combine new indentation with previous.
Richard M. Stallman <rms@gnu.org>
parents: 7813
diff changeset
445 (skip-chars-backward " \t")
b7ea350590a7 (tab-to-tab-stop): Combine new indentation with previous.
Richard M. Stallman <rms@gnu.org>
parents: 7813
diff changeset
446 (delete-region (point) opoint)
b7ea350590a7 (tab-to-tab-stop): Combine new indentation with previous.
Richard M. Stallman <rms@gnu.org>
parents: 7813
diff changeset
447 (indent-to (car tabs)))
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
448 (insert ?\ ))))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
449
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
450 (defun move-to-tab-stop ()
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
451 "Move point to next defined tab-stop column.
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
452 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
453 Use \\[edit-tab-stops] to edit them interactively."
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
454 (interactive)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
455 (let ((tabs tab-stop-list))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
456 (while (and tabs (>= (current-column) (car tabs)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
457 (setq tabs (cdr tabs)))
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
458 (if tabs
8037
fd5fb80a940d (move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents: 7984
diff changeset
459 (let ((before (point)))
fd5fb80a940d (move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents: 7984
diff changeset
460 (move-to-column (car tabs) t)
fd5fb80a940d (move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents: 7984
diff changeset
461 (save-excursion
fd5fb80a940d (move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents: 7984
diff changeset
462 (goto-char before)
fd5fb80a940d (move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents: 7984
diff changeset
463 ;; 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
464 ;; 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
465 (if (and (eq (preceding-char) ?\ )
fd5fb80a940d (move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents: 7984
diff changeset
466 (eq (following-char) ?\t))
fd5fb80a940d (move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents: 7984
diff changeset
467 (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
468 (while (and (> (current-column) tabend)
fd5fb80a940d (move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents: 7984
diff changeset
469 (eq (preceding-char) ?\ ))
fd5fb80a940d (move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents: 7984
diff changeset
470 (forward-char -1))
fd5fb80a940d (move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents: 7984
diff changeset
471 (delete-region (point) before))))))))
fd5fb80a940d (move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents: 7984
diff changeset
472
263
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
473 (define-key global-map "\t" 'indent-for-tab-command)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
474 (define-key esc-map "\034" 'indent-region)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
475 (define-key ctl-x-map "\t" 'indent-rigidly)
57bcc096ab9c Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
476 (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
477
08eb386dd0f3 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 269
diff changeset
478 ;;; indent.el ends here