Mercurial > emacs
annotate lisp/indent.el @ 112451:98ad7c9e56a3
gnus-html.el (gnus-html-image-fetched): Don't kill the temporary buffer after being called. It's apparently being killed by url.el, and killing it made point move to end-of-buffer in a random buffer.
shr.el (shr-image-fetched): Ditto.
shr.el (shr-image-fetched): Avoid having point move in the article buffer.
gnus-html.el (gnus-html-image-fetched): Kill the buffer anyway, and fix the bug in url-http.el instead.
shr.el (shr-image-fetched): Ditto.
gravatar.el (gravatar-retrieve): Be silent when retrieving.
gnus-gravatar.el (gnus-gravatar-insert): Don't move point around in the article buffer.
(gnus-gravatar-insert): Use blank space from the current buffer to avoid breaking text properties. This makes X-Sent updating work again.
gnus-art.el (gnus-article-read-summary-keys): Don't call disabled commands.
author | Katsumi Yamaoka <yamaoka@jpl.org> |
---|---|
date | Mon, 24 Jan 2011 04:10:19 +0000 |
parents | ef719132ddfa |
children |
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 |
106913
eeda0c6e1f2f
(tab-always-indent): Fix custom-type.
Glenn Morris <rgm@gnu.org>
parents:
106815
diff
changeset
|
3 ;; Copyright (C) 1985, 1995, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
112218
376148b31b5e
Add 2011 to FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents:
107529
diff
changeset
|
4 ;; 2008, 2009, 2010, 2011 Free Software Foundation, Inc. |
845 | 5 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
6 ;; Maintainer: FSF |
110015
280c8ae2476d
Add "Package:" file headers to denote built-in packages.
Chong Yidong <cyd@stupidchicken.com>
parents:
108696
diff
changeset
|
7 ;; Package: emacs |
263 | 8 |
9 ;; This file is part of GNU Emacs. | |
10 | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
11 ;; GNU Emacs is free software: you can redistribute it and/or modify |
263 | 12 ;; it under the terms of the GNU General Public License as published by |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; the Free Software Foundation, either version 3 of the License, or |
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
14 ;; (at your option) any later version. |
263 | 15 |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
263 | 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 | 30 |
19420 | 31 (defgroup indent nil |
64012
70dbaa65c723
(indent): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
57676
diff
changeset
|
32 "Indentation commands." |
19420 | 33 :group 'editing) |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
34 |
19420 | 35 (defcustom standard-indent 4 |
100171 | 36 "Default number of columns for margin-changing functions to indent." |
19420 | 37 :group 'indent |
38 :type 'integer) | |
39 | |
41845
23120b6a0225
(indent-line-function): Default is indent-relative again.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41762
diff
changeset
|
40 (defvar indent-line-function 'indent-relative |
40482
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
41 "Function to indent the current line. |
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
42 This function will be called with no arguments. |
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
43 If it is called somewhere where auto-indentation cannot be done |
98147
0db3bd4aa48f
(indent-line-function): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
94678
diff
changeset
|
44 \(e.g. inside a string), the function should simply return `noindent'. |
40482
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
45 Setting this function is all you need to make TAB indent appropriately. |
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
46 Don't rebind TAB unless you really need to.") |
263 | 47 |
32242
6da78b4b7be2
(tab-always-indent): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31593
diff
changeset
|
48 (defcustom tab-always-indent t |
100171 | 49 "Controls the operation of the TAB key. |
32242
6da78b4b7be2
(tab-always-indent): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31593
diff
changeset
|
50 If t, hitting TAB always just indents the current line. |
6da78b4b7be2
(tab-always-indent): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31593
diff
changeset
|
51 If nil, hitting TAB indents the current line if point is at the left margin |
81327
f43a57ce897e
(tab-always-indent): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75347
diff
changeset
|
52 or in the line's indentation, otherwise it inserts a \"real\" TAB character. |
106482
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
103263
diff
changeset
|
53 If `complete', TAB first tries to indent the current line, and if the line |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
103263
diff
changeset
|
54 was already indented, then try to complete the thing at point. |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
103263
diff
changeset
|
55 |
81327
f43a57ce897e
(tab-always-indent): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75347
diff
changeset
|
56 Some programming language modes have their own variable to control this, |
74821
35c1ecc52a29
(tab-always-indent): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents:
74231
diff
changeset
|
57 e.g., `c-tab-always-indent', and do not respect this variable." |
32242
6da78b4b7be2
(tab-always-indent): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31593
diff
changeset
|
58 :group 'indent |
106913
eeda0c6e1f2f
(tab-always-indent): Fix custom-type.
Glenn Morris <rgm@gnu.org>
parents:
106815
diff
changeset
|
59 :type '(choice |
eeda0c6e1f2f
(tab-always-indent): Fix custom-type.
Glenn Morris <rgm@gnu.org>
parents:
106815
diff
changeset
|
60 (const :tag "Always indent" t) |
eeda0c6e1f2f
(tab-always-indent): Fix custom-type.
Glenn Morris <rgm@gnu.org>
parents:
106815
diff
changeset
|
61 (const :tag "Indent if inside indentation, else TAB" nil) |
eeda0c6e1f2f
(tab-always-indent): Fix custom-type.
Glenn Morris <rgm@gnu.org>
parents:
106815
diff
changeset
|
62 (const :tag "Indent, or if already indented complete" complete))) |
eeda0c6e1f2f
(tab-always-indent): Fix custom-type.
Glenn Morris <rgm@gnu.org>
parents:
106815
diff
changeset
|
63 |
32242
6da78b4b7be2
(tab-always-indent): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31593
diff
changeset
|
64 |
263 | 65 (defun indent-according-to-mode () |
48581
023f680b7cfe
(indent-according-to-mode, indent-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
45438
diff
changeset
|
66 "Indent line in proper way for current major mode. |
023f680b7cfe
(indent-according-to-mode, indent-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
45438
diff
changeset
|
67 The buffer-local variable `indent-line-function' determines how to do this, |
023f680b7cfe
(indent-according-to-mode, indent-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
45438
diff
changeset
|
68 but the functions `indent-relative' and `indent-relative-maybe' are |
023f680b7cfe
(indent-according-to-mode, indent-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
45438
diff
changeset
|
69 special; we don't actually use them here." |
263 | 70 (interactive) |
110417
8a3552ec7934
* lisp/indent.el (indent-according-to-mode): Apply syntax-propertize.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110015
diff
changeset
|
71 (syntax-propertize (line-end-position)) |
40482
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
72 (if (memq indent-line-function |
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
73 '(indent-relative indent-relative-maybe)) |
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
74 ;; These functions are used for tabbing, but can't be used for |
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
75 ;; indenting. Replace with something ad-hoc. |
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
76 (let ((column (save-excursion |
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
77 (beginning-of-line) |
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
78 (skip-chars-backward "\n \t") |
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
79 (beginning-of-line) |
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
80 (current-indentation)))) |
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
81 (if (<= (current-column) (current-indentation)) |
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
82 (indent-line-to column) |
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
83 (save-excursion (indent-line-to column)))) |
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
84 ;; The normal case. |
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
85 (funcall indent-line-function))) |
263 | 86 |
40482
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
87 (defun indent-for-tab-command (&optional arg) |
84773
d8b9b78eb16c
(indent-for-tab-command): Indent the region if
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82140
diff
changeset
|
88 "Indent line or region in proper way for current major mode or insert a tab. |
32242
6da78b4b7be2
(tab-always-indent): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31593
diff
changeset
|
89 Depending on `tab-always-indent', either insert a tab or indent. |
107529
d0d82a838677
* indent.el (indent-for-tab-command): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
106913
diff
changeset
|
90 |
d0d82a838677
* indent.el (indent-for-tab-command): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
106913
diff
changeset
|
91 In most major modes, if point was in the current line's indentation, |
d0d82a838677
* indent.el (indent-for-tab-command): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
106913
diff
changeset
|
92 it is moved to the first non-whitespace character after indenting; |
d0d82a838677
* indent.el (indent-for-tab-command): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
106913
diff
changeset
|
93 otherwise it stays at the same position in the text. |
87393
c5dbee67727b
Add prefix arg handling to indent-for-tab-command
Miles Bader <miles@gnu.org>
parents:
87336
diff
changeset
|
94 |
c5dbee67727b
Add prefix arg handling to indent-for-tab-command
Miles Bader <miles@gnu.org>
parents:
87336
diff
changeset
|
95 If a prefix argument is given, also rigidly indent the entire |
103263
f1b56c6c0ebc
* indent.el (indent-for-tab-command): Fix typo in docstring.
Chong Yidong <cyd@stupidchicken.com>
parents:
100908
diff
changeset
|
96 balanced expression which starts at the beginning of the current |
87393
c5dbee67727b
Add prefix arg handling to indent-for-tab-command
Miles Bader <miles@gnu.org>
parents:
87336
diff
changeset
|
97 line to reflect the current line's change in indentation. |
c5dbee67727b
Add prefix arg handling to indent-for-tab-command
Miles Bader <miles@gnu.org>
parents:
87336
diff
changeset
|
98 |
87336
9088a29785d1
(indent-for-tab-command): Fix doc-string typo.
Martin Rudalics <rudalics@gmx.at>
parents:
87180
diff
changeset
|
99 If `transient-mark-mode' is turned on and the region is active, |
87393
c5dbee67727b
Add prefix arg handling to indent-for-tab-command
Miles Bader <miles@gnu.org>
parents:
87336
diff
changeset
|
100 indent the region (in this case, any prefix argument is ignored). |
c5dbee67727b
Add prefix arg handling to indent-for-tab-command
Miles Bader <miles@gnu.org>
parents:
87336
diff
changeset
|
101 |
84773
d8b9b78eb16c
(indent-for-tab-command): Indent the region if
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82140
diff
changeset
|
102 The function actually called to indent the line is determined by the value of |
30690
e666b7ea99a9
(indent-for-tab-command): Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents:
26169
diff
changeset
|
103 `indent-line-function'." |
13035
b8453eab5114
(indent-for-tab-command): Get the prefix arg
Richard M. Stallman <rms@gnu.org>
parents:
12778
diff
changeset
|
104 (interactive "P") |
40482
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
105 (cond |
84840
f4b3c97a692f
* progmodes/cc-mode.el (c-mode-base-map): Use
Dan Nicolaescu <dann@ics.uci.edu>
parents:
84773
diff
changeset
|
106 ;; The region is active, indent it. |
99266
8d57082234b9
(indent-for-tab-command): Use use-region-p.
Chong Yidong <cyd@stupidchicken.com>
parents:
98147
diff
changeset
|
107 ((use-region-p) |
84840
f4b3c97a692f
* progmodes/cc-mode.el (c-mode-base-map): Use
Dan Nicolaescu <dann@ics.uci.edu>
parents:
84773
diff
changeset
|
108 (indent-region (region-beginning) (region-end))) |
40636
1b4d4e638a5b
(tab-always-indent, indent-for-tab-command):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40482
diff
changeset
|
109 ((or ;; indent-to-left-margin is only meant for indenting, |
40482
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
110 ;; so we force it to always insert a tab here. |
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
111 (eq indent-line-function 'indent-to-left-margin) |
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
112 (and (not tab-always-indent) |
50140
f94aa8667875
(indent-for-tab-command): If tab-always-indent is non-nil
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49597
diff
changeset
|
113 (or (> (current-column) (current-indentation)) |
f94aa8667875
(indent-for-tab-command): If tab-always-indent is non-nil
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49597
diff
changeset
|
114 (eq this-command last-command)))) |
40482
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
115 (insert-tab arg)) |
84773
d8b9b78eb16c
(indent-for-tab-command): Indent the region if
Dan Nicolaescu <dann@ics.uci.edu>
parents:
82140
diff
changeset
|
116 (t |
106482
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
103263
diff
changeset
|
117 (let ((old-tick (buffer-chars-modified-tick)) |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
103263
diff
changeset
|
118 (old-point (point)) |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
103263
diff
changeset
|
119 (old-indent (current-indentation))) |
87393
c5dbee67727b
Add prefix arg handling to indent-for-tab-command
Miles Bader <miles@gnu.org>
parents:
87336
diff
changeset
|
120 |
c5dbee67727b
Add prefix arg handling to indent-for-tab-command
Miles Bader <miles@gnu.org>
parents:
87336
diff
changeset
|
121 ;; Indent the line. |
c5dbee67727b
Add prefix arg handling to indent-for-tab-command
Miles Bader <miles@gnu.org>
parents:
87336
diff
changeset
|
122 (funcall indent-line-function) |
c5dbee67727b
Add prefix arg handling to indent-for-tab-command
Miles Bader <miles@gnu.org>
parents:
87336
diff
changeset
|
123 |
106482
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
103263
diff
changeset
|
124 (cond |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
103263
diff
changeset
|
125 ;; If the text was already indented right, try completion. |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
103263
diff
changeset
|
126 ((and (eq tab-always-indent 'complete) |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
103263
diff
changeset
|
127 (eq old-point (point)) |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
103263
diff
changeset
|
128 (eq old-tick (buffer-chars-modified-tick))) |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
103263
diff
changeset
|
129 (completion-at-point)) |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
103263
diff
changeset
|
130 |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
103263
diff
changeset
|
131 ;; If a prefix argument was given, rigidly indent the following |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
103263
diff
changeset
|
132 ;; sexp to match the change in the current line's indentation. |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
103263
diff
changeset
|
133 (arg |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
103263
diff
changeset
|
134 (let ((end-marker |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
103263
diff
changeset
|
135 (save-excursion |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
103263
diff
changeset
|
136 (forward-line 0) (forward-sexp) (point-marker))) |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
103263
diff
changeset
|
137 (indentation-change (- (current-indentation) old-indent))) |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
103263
diff
changeset
|
138 (save-excursion |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
103263
diff
changeset
|
139 (forward-line 1) |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
103263
diff
changeset
|
140 (when (and (not (zerop indentation-change)) |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
103263
diff
changeset
|
141 (< (point) end-marker)) |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
103263
diff
changeset
|
142 (indent-rigidly (point) end-marker indentation-change)))))))))) |
263 | 143 |
40482
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
144 (defun insert-tab (&optional arg) |
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
145 (let ((count (prefix-numeric-value arg))) |
19508
c86800208845
(indent-relative, insert-tab):
Richard M. Stallman <rms@gnu.org>
parents:
19420
diff
changeset
|
146 (if (and abbrev-mode |
c86800208845
(indent-relative, insert-tab):
Richard M. Stallman <rms@gnu.org>
parents:
19420
diff
changeset
|
147 (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
|
148 (expand-abbrev)) |
83b8438fa1a4
(indent-for-tab-command): Pass prefix arg to indent-tab.
Richard M. Stallman <rms@gnu.org>
parents:
14770
diff
changeset
|
149 (if indent-tabs-mode |
15113
8db176b73c9f
(insert-tab): fix previous change
Erik Naggum <erik@naggum.no>
parents:
15106
diff
changeset
|
150 (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
|
151 (indent-to (* tab-width (+ count (/ (current-column) tab-width))))))) |
263 | 152 |
153 (defun indent-rigidly (start end arg) | |
154 "Indent all lines starting in the region sideways by ARG columns. | |
45438
7a6c116b0d4a
(indent-rigidly): Mention how to remove all indentation.
Eli Zaretskii <eliz@gnu.org>
parents:
45367
diff
changeset
|
155 Called from a program, takes three arguments, START, END and ARG. |
7a6c116b0d4a
(indent-rigidly): Mention how to remove all indentation.
Eli Zaretskii <eliz@gnu.org>
parents:
45367
diff
changeset
|
156 You can remove all indentation from a region by giving a large negative ARG." |
263 | 157 (interactive "r\np") |
158 (save-excursion | |
159 (goto-char end) | |
160 (setq end (point-marker)) | |
161 (goto-char start) | |
162 (or (bolp) (forward-line 1)) | |
163 (while (< (point) end) | |
8642
ae3b75bae5d7
(indent-rigidly): Insert new indent, then delete old.
Richard M. Stallman <rms@gnu.org>
parents:
8208
diff
changeset
|
164 (let ((indent (current-indentation)) |
ae3b75bae5d7
(indent-rigidly): Insert new indent, then delete old.
Richard M. Stallman <rms@gnu.org>
parents:
8208
diff
changeset
|
165 eol-flag) |
ae3b75bae5d7
(indent-rigidly): Insert new indent, then delete old.
Richard M. Stallman <rms@gnu.org>
parents:
8208
diff
changeset
|
166 (save-excursion |
ae3b75bae5d7
(indent-rigidly): Insert new indent, then delete old.
Richard M. Stallman <rms@gnu.org>
parents:
8208
diff
changeset
|
167 (skip-chars-forward " \t") |
ae3b75bae5d7
(indent-rigidly): Insert new indent, then delete old.
Richard M. Stallman <rms@gnu.org>
parents:
8208
diff
changeset
|
168 (setq eol-flag (eolp))) |
ae3b75bae5d7
(indent-rigidly): Insert new indent, then delete old.
Richard M. Stallman <rms@gnu.org>
parents:
8208
diff
changeset
|
169 (or eol-flag |
ae3b75bae5d7
(indent-rigidly): Insert new indent, then delete old.
Richard M. Stallman <rms@gnu.org>
parents:
8208
diff
changeset
|
170 (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
|
171 (delete-region (point) (progn (skip-chars-forward " \t") (point)))) |
263 | 172 (forward-line 1)) |
173 (move-marker end nil))) | |
174 | |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
175 (defun indent-line-to (column) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
176 "Indent current line to COLUMN. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
177 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
|
178 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
|
179 (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
|
180 (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
|
181 (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
|
182 (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
|
183 (delete-region (point) |
1418ed733e9d
(indent-line-to): Delete spaces before inserting a tab.
Richard M. Stallman <rms@gnu.org>
parents:
13035
diff
changeset
|
184 (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
|
185 (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
|
186 ((> 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
|
187 (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
|
188 (progn (back-to-indentation) (point))))))) |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
189 |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
190 (defun current-left-margin () |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
191 "Return the left margin to use for this line. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
192 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
|
193 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
|
194 (save-excursion |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
195 (back-to-indentation) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
196 (max 0 |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
197 (+ left-margin (or (get-text-property |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
198 (if (and (eobp) (not (bobp))) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
199 (1- (point)) (point)) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
200 'left-margin) 0))))) |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
201 |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
202 (defun move-to-left-margin (&optional n force) |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
203 "Move to the left margin of the current line. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
204 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
|
205 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
|
206 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
|
207 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
|
208 (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
|
209 (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
|
210 (skip-chars-forward " \t") |
57164
11b507f888a6
(move-to-left-margin): Special case for minibuffer.
Richard M. Stallman <rms@gnu.org>
parents:
56831
diff
changeset
|
211 (if (minibufferp (current-buffer)) |
11b507f888a6
(move-to-left-margin): Special case for minibuffer.
Richard M. Stallman <rms@gnu.org>
parents:
56831
diff
changeset
|
212 (if (save-excursion (beginning-of-line) (bobp)) |
11b507f888a6
(move-to-left-margin): Special case for minibuffer.
Richard M. Stallman <rms@gnu.org>
parents:
56831
diff
changeset
|
213 (goto-char (minibuffer-prompt-end)) |
11b507f888a6
(move-to-left-margin): Special case for minibuffer.
Richard M. Stallman <rms@gnu.org>
parents:
56831
diff
changeset
|
214 (beginning-of-line)) |
11b507f888a6
(move-to-left-margin): Special case for minibuffer.
Richard M. Stallman <rms@gnu.org>
parents:
56831
diff
changeset
|
215 (let ((lm (current-left-margin)) |
11b507f888a6
(move-to-left-margin): Special case for minibuffer.
Richard M. Stallman <rms@gnu.org>
parents:
56831
diff
changeset
|
216 (cc (current-column))) |
11b507f888a6
(move-to-left-margin): Special case for minibuffer.
Richard M. Stallman <rms@gnu.org>
parents:
56831
diff
changeset
|
217 (cond ((> cc lm) |
11b507f888a6
(move-to-left-margin): Special case for minibuffer.
Richard M. Stallman <rms@gnu.org>
parents:
56831
diff
changeset
|
218 (if (> (move-to-column lm force) lm) |
11b507f888a6
(move-to-left-margin): Special case for minibuffer.
Richard M. Stallman <rms@gnu.org>
parents:
56831
diff
changeset
|
219 ;; If lm is in a tab and we are not forcing, move before tab |
11b507f888a6
(move-to-left-margin): Special case for minibuffer.
Richard M. Stallman <rms@gnu.org>
parents:
56831
diff
changeset
|
220 (backward-char 1))) |
11b507f888a6
(move-to-left-margin): Special case for minibuffer.
Richard M. Stallman <rms@gnu.org>
parents:
56831
diff
changeset
|
221 ((and force (< cc lm)) |
11b507f888a6
(move-to-left-margin): Special case for minibuffer.
Richard M. Stallman <rms@gnu.org>
parents:
56831
diff
changeset
|
222 (indent-to-left-margin)))))) |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
223 |
50140
f94aa8667875
(indent-for-tab-command): If tab-always-indent is non-nil
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49597
diff
changeset
|
224 ;; This used to be the default indent-line-function, |
263 | 225 ;; used in Fundamental Mode, Text Mode, etc. |
226 (defun indent-to-left-margin () | |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
227 "Indent current line to the column given by `current-left-margin'." |
79191
24b435ba9bce
(indent-to-left-margin): If point's in the indentation,
Richard M. Stallman <rms@gnu.org>
parents:
78236
diff
changeset
|
228 (save-excursion (indent-line-to (current-left-margin))) |
24b435ba9bce
(indent-to-left-margin): If point's in the indentation,
Richard M. Stallman <rms@gnu.org>
parents:
78236
diff
changeset
|
229 ;; If we are within the indentation, move past it. |
24b435ba9bce
(indent-to-left-margin): If point's in the indentation,
Richard M. Stallman <rms@gnu.org>
parents:
78236
diff
changeset
|
230 (when (save-excursion |
24b435ba9bce
(indent-to-left-margin): If point's in the indentation,
Richard M. Stallman <rms@gnu.org>
parents:
78236
diff
changeset
|
231 (skip-chars-backward " \t") |
24b435ba9bce
(indent-to-left-margin): If point's in the indentation,
Richard M. Stallman <rms@gnu.org>
parents:
78236
diff
changeset
|
232 (bolp)) |
24b435ba9bce
(indent-to-left-margin): If point's in the indentation,
Richard M. Stallman <rms@gnu.org>
parents:
78236
diff
changeset
|
233 (skip-chars-forward " \t"))) |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
234 |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
235 (defun delete-to-left-margin (&optional from to) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
236 "Remove left margin indentation from a region. |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
237 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
|
238 In no case will it delete non-whitespace. |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
239 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
|
240 (save-excursion |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
241 (goto-char (or to (point-max))) |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
242 (setq to (point-marker)) |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
243 (goto-char (or from (point-min))) |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
244 (or (bolp) (forward-line 1)) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
245 (while (< (point) to) |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
246 (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
|
247 (forward-line 1)) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
248 (move-marker to nil))) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
249 |
57297
42311c6c4bdb
(set-left-margin, set-right-margin): Rename `lm' arg to `width' for
Luc Teirlinck <teirllm@auburn.edu>
parents:
57164
diff
changeset
|
250 (defun set-left-margin (from to width) |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
251 "Set the left margin of the region to WIDTH. |
57297
42311c6c4bdb
(set-left-margin, set-right-margin): Rename `lm' arg to `width' for
Luc Teirlinck <teirllm@auburn.edu>
parents:
57164
diff
changeset
|
252 If `auto-fill-mode' is active, re-fill the region to fit the new margin. |
42311c6c4bdb
(set-left-margin, set-right-margin): Rename `lm' arg to `width' for
Luc Teirlinck <teirllm@auburn.edu>
parents:
57164
diff
changeset
|
253 |
42311c6c4bdb
(set-left-margin, set-right-margin): Rename `lm' arg to `width' for
Luc Teirlinck <teirllm@auburn.edu>
parents:
57164
diff
changeset
|
254 Interactively, WIDTH is the prefix argument, if specified. |
42311c6c4bdb
(set-left-margin, set-right-margin): Rename `lm' arg to `width' for
Luc Teirlinck <teirllm@auburn.edu>
parents:
57164
diff
changeset
|
255 Without prefix argument, the command prompts for WIDTH." |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
256 (interactive "r\nNSet left margin to column: ") |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
257 (save-excursion |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
258 ;; If inside indentation, start from BOL. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
259 (goto-char from) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
260 (skip-chars-backward " \t") |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
261 (if (bolp) (setq from (point))) |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
262 ;; Place end after whitespace |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
263 (goto-char to) |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
264 (skip-chars-forward " \t") |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
265 (setq to (point-marker))) |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
266 ;; Delete margin indentation first, but keep paragraph indentation. |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
267 (delete-to-left-margin from to) |
57297
42311c6c4bdb
(set-left-margin, set-right-margin): Rename `lm' arg to `width' for
Luc Teirlinck <teirllm@auburn.edu>
parents:
57164
diff
changeset
|
268 (put-text-property from to 'left-margin width) |
42311c6c4bdb
(set-left-margin, set-right-margin): Rename `lm' arg to `width' for
Luc Teirlinck <teirllm@auburn.edu>
parents:
57164
diff
changeset
|
269 (indent-rigidly from to width) |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
270 (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
|
271 (move-marker to nil)) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
272 |
57297
42311c6c4bdb
(set-left-margin, set-right-margin): Rename `lm' arg to `width' for
Luc Teirlinck <teirllm@auburn.edu>
parents:
57164
diff
changeset
|
273 (defun set-right-margin (from to width) |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
274 "Set the right margin of the region to WIDTH. |
57297
42311c6c4bdb
(set-left-margin, set-right-margin): Rename `lm' arg to `width' for
Luc Teirlinck <teirllm@auburn.edu>
parents:
57164
diff
changeset
|
275 If `auto-fill-mode' is active, re-fill the region to fit the new margin. |
42311c6c4bdb
(set-left-margin, set-right-margin): Rename `lm' arg to `width' for
Luc Teirlinck <teirllm@auburn.edu>
parents:
57164
diff
changeset
|
276 |
42311c6c4bdb
(set-left-margin, set-right-margin): Rename `lm' arg to `width' for
Luc Teirlinck <teirllm@auburn.edu>
parents:
57164
diff
changeset
|
277 Interactively, WIDTH is the prefix argument, if specified. |
42311c6c4bdb
(set-left-margin, set-right-margin): Rename `lm' arg to `width' for
Luc Teirlinck <teirllm@auburn.edu>
parents:
57164
diff
changeset
|
278 Without prefix argument, the command prompts for WIDTH." |
11281
10f9cf00c770
(set-right-margin): Fix prompt.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
279 (interactive "r\nNSet right margin to width: ") |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
280 (save-excursion |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
281 (goto-char from) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
282 (skip-chars-backward " \t") |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
283 (if (bolp) (setq from (point)))) |
57297
42311c6c4bdb
(set-left-margin, set-right-margin): Rename `lm' arg to `width' for
Luc Teirlinck <teirllm@auburn.edu>
parents:
57164
diff
changeset
|
284 (put-text-property from to 'right-margin width) |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
285 (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
|
286 |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
287 (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
|
288 "Programmatically change value of a text-property. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
289 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
|
290 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
|
291 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
|
292 (let ((begin from) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
293 end val) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
294 (while (setq val (get-text-property begin prop object) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
295 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
|
296 (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
|
297 (setq begin end)) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
298 (if (< begin to) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
299 (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
|
300 |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
301 (defun increase-left-margin (from to inc) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
302 "Increase or decrease the left-margin of the region. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
303 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
|
304 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
|
305 to change the margin by, in characters. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
306 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
|
307 (interactive "*r\nP") |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
308 (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
|
309 (save-excursion |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
310 (goto-char from) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
311 (skip-chars-backward " \t") |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
312 (if (bolp) (setq from (point))) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
313 (goto-char to) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
314 (setq to (point-marker))) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
315 (alter-text-property from to 'left-margin |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
316 (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
|
317 (indent-rigidly from to inc) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
318 (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
|
319 (move-marker to nil)) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
320 |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
321 (defun decrease-left-margin (from to inc) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
322 "Make the left margin of the region smaller. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
323 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
|
324 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
|
325 to change the margin by, in characters. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
326 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
|
327 (interactive "*r\nP") |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
328 (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
|
329 (increase-left-margin from to (- inc))) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
330 |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
331 (defun increase-right-margin (from to inc) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
332 "Increase the right-margin of the region. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
333 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
|
334 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
|
335 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
|
336 the right margin width. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
337 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
|
338 (interactive "r\nP") |
57676
94dfa49e7a83
(set-left-margin, set-right-margin): Delete redundant code.
Luc Teirlinck <teirllm@auburn.edu>
parents:
57297
diff
changeset
|
339 (setq inc (if inc (prefix-numeric-value inc) standard-indent)) |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
340 (save-excursion |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
341 (alter-text-property from to 'right-margin |
57676
94dfa49e7a83
(set-left-margin, set-right-margin): Delete redundant code.
Luc Teirlinck <teirllm@auburn.edu>
parents:
57297
diff
changeset
|
342 (lambda (v) (+ inc (or v 0)))) |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
343 (if auto-fill-function |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
344 (fill-region from to nil t t)))) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
345 |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
346 (defun decrease-right-margin (from to inc) |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
347 "Make the right margin of the region smaller. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
348 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
|
349 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
|
350 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
|
351 the right margin width. |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
352 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
|
353 (interactive "*r\nP") |
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
354 (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
|
355 (increase-right-margin from to (- inc))) |
263 | 356 |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
357 (defun beginning-of-line-text (&optional n) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
358 "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
|
359 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
|
360 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
|
361 fill-prefix, and any indentation used for centering or right-justifying the |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48581
diff
changeset
|
362 line, but does not move past any whitespace that was explicitly inserted |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
363 \(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
|
364 (interactive "p") |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
365 (beginning-of-line n) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
366 (skip-chars-forward " \t") |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
367 ;; Skip over fill-prefix. |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48581
diff
changeset
|
368 (if (and fill-prefix |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
369 (not (string-equal fill-prefix ""))) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
370 (if (equal fill-prefix |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48581
diff
changeset
|
371 (buffer-substring |
10812
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
372 (point) (min (point-max) (+ (length fill-prefix) (point))))) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
373 (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
|
374 (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
|
375 (looking-at adaptive-fill-regexp)) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
376 (goto-char (match-end 0)))) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
377 ;; Skip centering or flushright indentation |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
378 (if (memq (current-justification) '(center right)) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
379 (skip-chars-forward " \t"))) |
cd0a341fd620
(current-left-margin): careful of EOB.
Boris Goldowsky <boris@gnu.org>
parents:
10470
diff
changeset
|
380 |
263 | 381 (defvar indent-region-function nil |
12683
0e9d2009e609
(indent-region-function): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11281
diff
changeset
|
382 "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
|
383 A value of nil means really run `indent-according-to-mode' on each line.") |
263 | 384 |
45367
2a9743cfbeab
(indent-region): Make COLUMN arg optional.
Richard M. Stallman <rms@gnu.org>
parents:
43053
diff
changeset
|
385 (defun indent-region (start end &optional column) |
263 | 386 "Indent each nonblank line in the region. |
48581
023f680b7cfe
(indent-according-to-mode, indent-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
45438
diff
changeset
|
387 A numeric prefix argument specifies a column: indent each line to that column. |
023f680b7cfe
(indent-according-to-mode, indent-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
45438
diff
changeset
|
388 |
023f680b7cfe
(indent-according-to-mode, indent-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
45438
diff
changeset
|
389 With no prefix argument, the command chooses one of these methods and |
023f680b7cfe
(indent-according-to-mode, indent-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
45438
diff
changeset
|
390 indents all the lines with it: |
26169 | 391 |
48581
023f680b7cfe
(indent-according-to-mode, indent-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
45438
diff
changeset
|
392 1) If `fill-prefix' is non-nil, insert `fill-prefix' at the |
023f680b7cfe
(indent-according-to-mode, indent-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
45438
diff
changeset
|
393 beginning of each line in the region that does not already begin |
023f680b7cfe
(indent-according-to-mode, indent-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
45438
diff
changeset
|
394 with it. |
023f680b7cfe
(indent-according-to-mode, indent-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
45438
diff
changeset
|
395 2) If `indent-region-function' is non-nil, call that function |
023f680b7cfe
(indent-according-to-mode, indent-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
45438
diff
changeset
|
396 to indent the region. |
023f680b7cfe
(indent-according-to-mode, indent-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
45438
diff
changeset
|
397 3) Indent each line as specified by the variable `indent-line-function'. |
023f680b7cfe
(indent-according-to-mode, indent-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
45438
diff
changeset
|
398 |
023f680b7cfe
(indent-according-to-mode, indent-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
45438
diff
changeset
|
399 Called from a program, START and END specify the region to indent. |
023f680b7cfe
(indent-according-to-mode, indent-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
45438
diff
changeset
|
400 If the third argument COLUMN is an integer, it specifies the |
023f680b7cfe
(indent-according-to-mode, indent-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
45438
diff
changeset
|
401 column to indent to; if it is nil, use one of the three methods above." |
263 | 402 (interactive "r\nP") |
4465
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
403 (if (null column) |
263 | 404 (if fill-prefix |
405 (save-excursion | |
406 (goto-char end) | |
407 (setq end (point-marker)) | |
408 (goto-char start) | |
409 (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
|
410 (while (< (point) end) |
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
411 (or (looking-at regexp) |
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
412 (and (bolp) (eolp)) |
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
413 (insert fill-prefix)) |
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
414 (forward-line 1)))) |
263 | 415 (if indent-region-function |
416 (funcall indent-region-function start end) | |
417 (save-excursion | |
40482
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
418 (setq end (copy-marker end)) |
4465
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
419 (goto-char start) |
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
420 (while (< (point) end) |
4473
600d0d832d99
(indent-region): Fix paren error in last change.
Richard M. Stallman <rms@gnu.org>
parents:
4465
diff
changeset
|
421 (or (and (bolp) (eolp)) |
110417
8a3552ec7934
* lisp/indent.el (indent-according-to-mode): Apply syntax-propertize.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110015
diff
changeset
|
422 (indent-according-to-mode)) |
4465
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
423 (forward-line 1)) |
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
424 (move-marker end nil)))) |
794498c64928
(indent-region): Rename arg ARG to COLUMN.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
425 (setq column (prefix-numeric-value column)) |
263 | 426 (save-excursion |
427 (goto-char end) | |
428 (setq end (point-marker)) | |
429 (goto-char start) | |
430 (or (bolp) (forward-line 1)) | |
431 (while (< (point) end) | |
432 (delete-region (point) (progn (skip-chars-forward " \t") (point))) | |
433 (or (eolp) | |
10467
b8053ce05ab5
(standard-indent): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
8642
diff
changeset
|
434 (indent-to column 0)) |
263 | 435 (forward-line 1)) |
108696
144e6ea330f0
* indent.el (indent-region): Deactivate region (bug#6200).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107529
diff
changeset
|
436 (move-marker end nil))) |
144e6ea330f0
* indent.el (indent-region): Deactivate region (bug#6200).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107529
diff
changeset
|
437 ;; In most cases, reindenting modifies the buffer, but it may also |
144e6ea330f0
* indent.el (indent-region): Deactivate region (bug#6200).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107529
diff
changeset
|
438 ;; leave it unmodified, in which case we have to deactivate the mark |
144e6ea330f0
* indent.el (indent-region): Deactivate region (bug#6200).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107529
diff
changeset
|
439 ;; by hand. |
144e6ea330f0
* indent.el (indent-region): Deactivate region (bug#6200).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107529
diff
changeset
|
440 (deactivate-mark)) |
263 | 441 |
442 (defun indent-relative-maybe () | |
38151
9fb3fc20b9b0
(indent-relative-maybe, indent-relative): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents:
37367
diff
changeset
|
443 "Indent a new line like previous nonblank line. |
9fb3fc20b9b0
(indent-relative-maybe, indent-relative): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents:
37367
diff
changeset
|
444 If the previous nonblank line has no indent points beyond the |
9fb3fc20b9b0
(indent-relative-maybe, indent-relative): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents:
37367
diff
changeset
|
445 column point starts at, this command does nothing. |
9fb3fc20b9b0
(indent-relative-maybe, indent-relative): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents:
37367
diff
changeset
|
446 |
9fb3fc20b9b0
(indent-relative-maybe, indent-relative): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents:
37367
diff
changeset
|
447 See also `indent-relative'." |
263 | 448 (interactive) |
449 (indent-relative t)) | |
450 | |
451 (defun indent-relative (&optional unindented-ok) | |
452 "Space out to under next indent point in previous nonblank line. | |
453 An indent point is a non-whitespace character following whitespace. | |
25498
611af07c47c2
(indent-relative): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19895
diff
changeset
|
454 The following line shows the indentation points in this line. |
611af07c47c2
(indent-relative): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19895
diff
changeset
|
455 ^ ^ ^ ^ ^ ^ ^ ^ ^ |
263 | 456 If the previous nonblank line has no indent points beyond the |
38151
9fb3fc20b9b0
(indent-relative-maybe, indent-relative): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents:
37367
diff
changeset
|
457 column point starts at, `tab-to-tab-stop' is done instead, unless |
9fb3fc20b9b0
(indent-relative-maybe, indent-relative): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents:
37367
diff
changeset
|
458 this command is invoked with a numeric argument, in which case it |
9fb3fc20b9b0
(indent-relative-maybe, indent-relative): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents:
37367
diff
changeset
|
459 does nothing. |
9fb3fc20b9b0
(indent-relative-maybe, indent-relative): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents:
37367
diff
changeset
|
460 |
9fb3fc20b9b0
(indent-relative-maybe, indent-relative): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents:
37367
diff
changeset
|
461 See also `indent-relative-maybe'." |
263 | 462 (interactive "P") |
19508
c86800208845
(indent-relative, insert-tab):
Richard M. Stallman <rms@gnu.org>
parents:
19420
diff
changeset
|
463 (if (and abbrev-mode |
c86800208845
(indent-relative, insert-tab):
Richard M. Stallman <rms@gnu.org>
parents:
19420
diff
changeset
|
464 (eq (char-syntax (preceding-char)) ?w)) |
c86800208845
(indent-relative, insert-tab):
Richard M. Stallman <rms@gnu.org>
parents:
19420
diff
changeset
|
465 (expand-abbrev)) |
263 | 466 (let ((start-column (current-column)) |
467 indent) | |
468 (save-excursion | |
469 (beginning-of-line) | |
470 (if (re-search-backward "^[^\n]" nil t) | |
471 (let ((end (save-excursion (forward-line 1) (point)))) | |
472 (move-to-column start-column) | |
473 ;; Is start-column inside a tab on this line? | |
474 (if (> (current-column) start-column) | |
475 (backward-char 1)) | |
476 (or (looking-at "[ \t]") | |
477 unindented-ok | |
478 (skip-chars-forward "^ \t" end)) | |
479 (skip-chars-forward " \t" end) | |
480 (or (= (point) end) (setq indent (current-column)))))) | |
481 (if indent | |
482 (let ((opoint (point-marker))) | |
483 (indent-to indent 0) | |
484 (if (> opoint (point)) | |
485 (goto-char opoint)) | |
486 (move-marker opoint nil)) | |
487 (tab-to-tab-stop)))) | |
488 | |
19420 | 489 (defcustom tab-stop-list |
263 | 490 '(8 16 24 32 40 48 56 64 72 80 88 96 104 112 120) |
100171 | 491 "List of tab stop positions used by `tab-to-tab-stop'. |
19420 | 492 This should be a list of integers, ordered from smallest to largest." |
493 :group 'indent | |
494 :type '(repeat integer)) | |
87180
c50e8341c802
(tab-stop-list): Mark as safe-local-variable.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85688
diff
changeset
|
495 (put 'tab-stop-list 'safe-local-variable 'listp) |
263 | 496 |
40482
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
497 (defvar edit-tab-stops-map |
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
498 (let ((map (make-sparse-keymap))) |
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
499 (define-key map "\C-x\C-s" 'edit-tab-stops-note-changes) |
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
500 (define-key map "\C-c\C-c" 'edit-tab-stops-note-changes) |
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
501 map) |
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
502 "Keymap used in `edit-tab-stops'.") |
263 | 503 |
504 (defvar edit-tab-stops-buffer nil | |
56831
a6ed4f895b79
(edit-tab-stops-buffer): Doc fix.
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
505 "Buffer whose tab stops are being edited. |
a6ed4f895b79
(edit-tab-stops-buffer): Doc fix.
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
506 This matters if the variable `tab-stop-list' is local in that buffer.") |
263 | 507 |
508 (defun edit-tab-stops () | |
509 "Edit the tab stops used by `tab-to-tab-stop'. | |
510 Creates a buffer *Tab Stops* containing text describing the tab stops. | |
511 A colon indicates a column where there is a tab stop. | |
512 You can add or remove colons and then do \\<edit-tab-stops-map>\\[edit-tab-stops-note-changes] to make changes take effect." | |
513 (interactive) | |
514 (setq edit-tab-stops-buffer (current-buffer)) | |
515 (switch-to-buffer (get-buffer-create "*Tab Stops*")) | |
516 (use-local-map edit-tab-stops-map) | |
517 (make-local-variable 'indent-tabs-mode) | |
518 (setq indent-tabs-mode nil) | |
519 (overwrite-mode 1) | |
520 (setq truncate-lines t) | |
521 (erase-buffer) | |
522 (let ((tabs tab-stop-list)) | |
523 (while tabs | |
524 (indent-to (car tabs) 0) | |
525 (insert ?:) | |
526 (setq tabs (cdr tabs)))) | |
527 (let ((count 0)) | |
528 (insert ?\n) | |
529 (while (< count 8) | |
530 (insert (+ count ?0)) | |
531 (insert " ") | |
532 (setq count (1+ count))) | |
533 (insert ?\n) | |
534 (while (> count 0) | |
535 (insert "0123456789") | |
536 (setq count (1- count)))) | |
537 (insert "\nTo install changes, type C-c C-c") | |
538 (goto-char (point-min))) | |
539 | |
540 (defun edit-tab-stops-note-changes () | |
541 "Put edited tab stops into effect." | |
542 (interactive) | |
543 (let (tabs) | |
544 (save-excursion | |
545 (goto-char 1) | |
546 (end-of-line) | |
547 (while (search-backward ":" nil t) | |
548 (setq tabs (cons (current-column) tabs)))) | |
549 (bury-buffer (prog1 (current-buffer) | |
550 (switch-to-buffer edit-tab-stops-buffer))) | |
551 (setq tab-stop-list tabs)) | |
552 (message "Tab stops installed")) | |
553 | |
554 (defun tab-to-tab-stop () | |
555 "Insert spaces or tabs to next defined tab-stop column. | |
556 The variable `tab-stop-list' is a list of columns at which there are tab stops. | |
557 Use \\[edit-tab-stops] to edit them interactively." | |
558 (interactive) | |
12778
657be7aaa043
(tab-to-tab-stop): Expand abbrevs only after a word-char.
Richard M. Stallman <rms@gnu.org>
parents:
12683
diff
changeset
|
559 (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
|
560 (expand-abbrev)) |
263 | 561 (let ((tabs tab-stop-list)) |
562 (while (and tabs (>= (current-column) (car tabs))) | |
563 (setq tabs (cdr tabs))) | |
564 (if tabs | |
7973
b7ea350590a7
(tab-to-tab-stop): Combine new indentation with previous.
Richard M. Stallman <rms@gnu.org>
parents:
7813
diff
changeset
|
565 (let ((opoint (point))) |
41758
581ab0e31090
(tab-to-tab-stop): Use delete-horizontal-space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40636
diff
changeset
|
566 (delete-horizontal-space t) |
7973
b7ea350590a7
(tab-to-tab-stop): Combine new indentation with previous.
Richard M. Stallman <rms@gnu.org>
parents:
7813
diff
changeset
|
567 (indent-to (car tabs))) |
74231
0b8c05c54956
(tab-to-tab-stop, move-to-tab-stop): "?\ " -> "?\s".
Juanma Barranquero <lekktu@gmail.com>
parents:
68651
diff
changeset
|
568 (insert ?\s)))) |
263 | 569 |
570 (defun move-to-tab-stop () | |
571 "Move point to next defined tab-stop column. | |
572 The variable `tab-stop-list' is a list of columns at which there are tab stops. | |
573 Use \\[edit-tab-stops] to edit them interactively." | |
574 (interactive) | |
575 (let ((tabs tab-stop-list)) | |
576 (while (and tabs (>= (current-column) (car tabs))) | |
577 (setq tabs (cdr tabs))) | |
578 (if tabs | |
8037
fd5fb80a940d
(move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents:
7984
diff
changeset
|
579 (let ((before (point))) |
fd5fb80a940d
(move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents:
7984
diff
changeset
|
580 (move-to-column (car tabs) t) |
fd5fb80a940d
(move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents:
7984
diff
changeset
|
581 (save-excursion |
fd5fb80a940d
(move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents:
7984
diff
changeset
|
582 (goto-char before) |
fd5fb80a940d
(move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents:
7984
diff
changeset
|
583 ;; 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
|
584 ;; delete any superfluous spaces before the old point. |
74231
0b8c05c54956
(tab-to-tab-stop, move-to-tab-stop): "?\ " -> "?\s".
Juanma Barranquero <lekktu@gmail.com>
parents:
68651
diff
changeset
|
585 (if (and (eq (preceding-char) ?\s) |
8037
fd5fb80a940d
(move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents:
7984
diff
changeset
|
586 (eq (following-char) ?\t)) |
fd5fb80a940d
(move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents:
7984
diff
changeset
|
587 (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
|
588 (while (and (> (current-column) tabend) |
74231
0b8c05c54956
(tab-to-tab-stop, move-to-tab-stop): "?\ " -> "?\s".
Juanma Barranquero <lekktu@gmail.com>
parents:
68651
diff
changeset
|
589 (eq (preceding-char) ?\s)) |
8037
fd5fb80a940d
(move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents:
7984
diff
changeset
|
590 (forward-char -1)) |
fd5fb80a940d
(move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents:
7984
diff
changeset
|
591 (delete-region (point) before)))))))) |
fd5fb80a940d
(move-to-tab-stop): Delete unnecessary spaces
Richard M. Stallman <rms@gnu.org>
parents:
7984
diff
changeset
|
592 |
263 | 593 (define-key global-map "\t" 'indent-for-tab-command) |
40482
ec3016b59706
(indent-line-function): Change default to indent-relative.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38151
diff
changeset
|
594 (define-key esc-map "\C-\\" 'indent-region) |
263 | 595 (define-key ctl-x-map "\t" 'indent-rigidly) |
596 (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
|
597 |
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
269
diff
changeset
|
598 ;;; indent.el ends here |