Mercurial > emacs
annotate lisp/textmodes/text-mode.el @ 107596:866e76f8ad75
Retrospective commit from 2009-10-08.
Finish up working on paragraph's base direction.
Start working on display of right-to-left glyph rows.
Rewrite set_cursor_from_row to support bidi.
xdisp.c (string_buffer_position_lim): New function.
(string_buffer_position): Most of code moved to
string_buffer_position_lim. Last argument and return value are
now EMACS_INT; all callers changed.
(set_cursor_from_row): Rewritten to support bidirectional text and
reversed glyph rows.
dispextern.h <string_buffer_position>: Update prototype.
bidi.c (bidi_paragraph_init): Fix initialization of POS.
dispextern.h (struct glyph_row): New member reversed_p.
buffer.c (syms_of_buffer): Remove DEFVAR_LISP_NOPRO for
default-direction-reversed, default-bidi-display-reordering, and
default-paragraph-direction.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Fri, 01 Jan 2010 06:27:51 -0500 |
parents | a9dc0e7c3f2b |
children | 1d1d5d9bd884 |
rev | line source |
---|---|
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
28108
diff
changeset
|
1 ;;; text-mode.el --- text mode, and its idiosyncratic commands |
657
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
283
diff
changeset
|
2 |
74509 | 3 ;; Copyright (C) 1985, 1992, 1994, 2001, 2002, 2003, 2004, |
100908 | 4 ;; 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. |
841 | 5 |
775
1ca26ccad38e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
727
diff
changeset
|
6 ;; Maintainer: FSF |
38697
a19197c6442f
Keyword added and FSF specified as Maintainer.
Pavel Janík <Pavel@Janik.cz>
parents:
38412
diff
changeset
|
7 ;; Keywords: wp |
36 | 8 |
9 ;; This file is part of GNU Emacs. | |
10 | |
94670
f4a69fedbd46
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 |
36 | 12 ;; it under the terms of the GNU General Public License as published by |
94670
f4a69fedbd46
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 |
f4a69fedbd46
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
14 ;; (at your option) any later version. |
36 | 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 | |
94670
f4a69fedbd46
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/>. |
2315
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1576
diff
changeset
|
23 |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1576
diff
changeset
|
24 ;;; Commentary: |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1576
diff
changeset
|
25 |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1576
diff
changeset
|
26 ;; This package provides the fundamental text mode documented in the |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1576
diff
changeset
|
27 ;; Emacs user's manual. |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1576
diff
changeset
|
28 |
775
1ca26ccad38e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
727
diff
changeset
|
29 ;;; Code: |
36 | 30 |
26598 | 31 (defcustom text-mode-hook nil |
32 "Normal hook run when entering Text mode and many related modes." | |
33 :type 'hook | |
71100
83b8d9f95633
* textmodes/flyspell.el (turn-on-flyspell, turn-off-flyspell): New
Reiner Steib <Reiner.Steib@gmx.de>
parents:
68648
diff
changeset
|
34 :options '(turn-on-auto-fill turn-on-flyspell) |
26598 | 35 :group 'data) |
19589
8c19d570a391
(text-mode-hook): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18256
diff
changeset
|
36 |
19590
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
37 (defvar text-mode-variant nil |
40484
2e6c799155b3
(text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40481
diff
changeset
|
38 "Non-nil if this buffer's major mode is a variant of Text mode. |
2e6c799155b3
(text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40481
diff
changeset
|
39 Use (derived-mode-p 'text-mode) instead.") |
36 | 40 |
40484
2e6c799155b3
(text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40481
diff
changeset
|
41 (defvar text-mode-syntax-table |
2e6c799155b3
(text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40481
diff
changeset
|
42 (let ((st (make-syntax-table))) |
2e6c799155b3
(text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40481
diff
changeset
|
43 (modify-syntax-entry ?\" ". " st) |
2e6c799155b3
(text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40481
diff
changeset
|
44 (modify-syntax-entry ?\\ ". " st) |
47966
85dbcc2c6739
(text-mode-syntax-table): Make ' a prefix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47213
diff
changeset
|
45 ;; We add `p' so that M-c on 'hello' leads to 'Hello' rather than 'hello'. |
85dbcc2c6739
(text-mode-syntax-table): Make ' a prefix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47213
diff
changeset
|
46 (modify-syntax-entry ?' "w p" st) |
40484
2e6c799155b3
(text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40481
diff
changeset
|
47 st) |
2e6c799155b3
(text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40481
diff
changeset
|
48 "Syntax table used while in `text-mode'.") |
36 | 49 |
40484
2e6c799155b3
(text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40481
diff
changeset
|
50 (defvar text-mode-map |
2e6c799155b3
(text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40481
diff
changeset
|
51 (let ((map (make-sparse-keymap))) |
2e6c799155b3
(text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40481
diff
changeset
|
52 (define-key map "\e\t" 'ispell-complete-word) |
2e6c799155b3
(text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40481
diff
changeset
|
53 map) |
2e6c799155b3
(text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40481
diff
changeset
|
54 "Keymap for `text-mode'. |
2e6c799155b3
(text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40481
diff
changeset
|
55 Many other modes, such as `mail-mode', `outline-mode' and `indented-text-mode', |
36 | 56 inherit all the commands defined in this map.") |
57 | |
58 | |
40360
04be247dd745
(text-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38697
diff
changeset
|
59 (define-derived-mode text-mode nil "Text" |
18132
95f6ac42b352
(spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
60 "Major mode for editing text written for humans to read. |
18256
27f2dfb2c1de
(text-mode): Let all-white lines separate paragraphs.
Richard M. Stallman <rms@gnu.org>
parents:
18222
diff
changeset
|
61 In this mode, paragraphs are delimited only by blank or white lines. |
18132
95f6ac42b352
(spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
62 You can thus get the full benefit of adaptive filling |
95f6ac42b352
(spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
63 (see the variable `adaptive-fill-mode'). |
6323 | 64 \\{text-mode-map} |
18132
95f6ac42b352
(spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
65 Turning on Text mode runs the normal hook `text-mode-hook'." |
43122
2630388260f5
(text-mode-hook-identify): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents:
40484
diff
changeset
|
66 (make-local-variable 'text-mode-variant) |
2630388260f5
(text-mode-hook-identify): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents:
40484
diff
changeset
|
67 (setq text-mode-variant t) |
59255
bf01ac46d369
(text-mode): Use mode-require-final-newline.
Richard M. Stallman <rms@gnu.org>
parents:
52640
diff
changeset
|
68 (set (make-local-variable 'require-final-newline) |
bf01ac46d369
(text-mode): Use mode-require-final-newline.
Richard M. Stallman <rms@gnu.org>
parents:
52640
diff
changeset
|
69 mode-require-final-newline) |
40484
2e6c799155b3
(text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40481
diff
changeset
|
70 (set (make-local-variable 'indent-line-function) 'indent-relative)) |
18132
95f6ac42b352
(spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
71 |
40481
7b44c3509111
(paragraph-indent-minor-mode): Don't set paragraph-separate.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40360
diff
changeset
|
72 (define-derived-mode paragraph-indent-text-mode text-mode "Parindent" |
18132
95f6ac42b352
(spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
73 "Major mode for editing text, with leading spaces starting a paragraph. |
95f6ac42b352
(spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
74 In this mode, you do not need blank lines between paragraphs |
95f6ac42b352
(spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
75 when the first line of the following paragraph starts with whitespace. |
27202
6047ac0aaa7c
(text-mode): Remove page-delimiter's `^' from paragraph-start.
Dave Love <fx@gnu.org>
parents:
26598
diff
changeset
|
76 `paragraph-indent-minor-mode' provides a similar facility as a minor mode. |
18132
95f6ac42b352
(spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
77 Special commands: |
95f6ac42b352
(spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
78 \\{text-mode-map} |
18222
b7ad635feeb8
(paragraph-indent-text-mode): Renamed from spaced-text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
18132
diff
changeset
|
79 Turning on Paragraph-Indent Text mode runs the normal hooks |
b7ad635feeb8
(paragraph-indent-text-mode): Renamed from spaced-text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
18132
diff
changeset
|
80 `text-mode-hook' and `paragraph-indent-text-mode-hook'." |
47966
85dbcc2c6739
(text-mode-syntax-table): Make ' a prefix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47213
diff
changeset
|
81 :abbrev-table nil :syntax-table nil |
40484
2e6c799155b3
(text-mode-map): Remove the \t binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40481
diff
changeset
|
82 (paragraph-indent-minor-mode)) |
27202
6047ac0aaa7c
(text-mode): Remove page-delimiter's `^' from paragraph-start.
Dave Love <fx@gnu.org>
parents:
26598
diff
changeset
|
83 |
6047ac0aaa7c
(text-mode): Remove page-delimiter's `^' from paragraph-start.
Dave Love <fx@gnu.org>
parents:
26598
diff
changeset
|
84 (defun paragraph-indent-minor-mode () |
6047ac0aaa7c
(text-mode): Remove page-delimiter's `^' from paragraph-start.
Dave Love <fx@gnu.org>
parents:
26598
diff
changeset
|
85 "Minor mode for editing text, with leading spaces starting a paragraph. |
6047ac0aaa7c
(text-mode): Remove page-delimiter's `^' from paragraph-start.
Dave Love <fx@gnu.org>
parents:
26598
diff
changeset
|
86 In this mode, you do not need blank lines between paragraphs when the |
6047ac0aaa7c
(text-mode): Remove page-delimiter's `^' from paragraph-start.
Dave Love <fx@gnu.org>
parents:
26598
diff
changeset
|
87 first line of the following paragraph starts with whitespace, as with |
52640
2e9f5698c9db
(paragraph-indent-minor-mode): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
88 `paragraph-indent-text-mode'. |
27202
6047ac0aaa7c
(text-mode): Remove page-delimiter's `^' from paragraph-start.
Dave Love <fx@gnu.org>
parents:
26598
diff
changeset
|
89 Turning on Paragraph-Indent minor mode runs the normal hook |
6047ac0aaa7c
(text-mode): Remove page-delimiter's `^' from paragraph-start.
Dave Love <fx@gnu.org>
parents:
26598
diff
changeset
|
90 `paragraph-indent-text-mode-hook'." |
6047ac0aaa7c
(text-mode): Remove page-delimiter's `^' from paragraph-start.
Dave Love <fx@gnu.org>
parents:
26598
diff
changeset
|
91 (interactive) |
6047ac0aaa7c
(text-mode): Remove page-delimiter's `^' from paragraph-start.
Dave Love <fx@gnu.org>
parents:
26598
diff
changeset
|
92 (set (make-local-variable 'paragraph-start) |
40481
7b44c3509111
(paragraph-indent-minor-mode): Don't set paragraph-separate.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40360
diff
changeset
|
93 (concat "[ \t\n\f]\\|" paragraph-start)) |
7b44c3509111
(paragraph-indent-minor-mode): Don't set paragraph-separate.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40360
diff
changeset
|
94 (set (make-local-variable 'indent-line-function) 'indent-to-left-margin) |
27202
6047ac0aaa7c
(text-mode): Remove page-delimiter's `^' from paragraph-start.
Dave Love <fx@gnu.org>
parents:
26598
diff
changeset
|
95 (run-hooks 'paragraph-indent-text-mode-hook)) |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47966
diff
changeset
|
96 |
18222
b7ad635feeb8
(paragraph-indent-text-mode): Renamed from spaced-text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
18132
diff
changeset
|
97 (defalias 'indented-text-mode 'text-mode) |
36 | 98 |
43287
431e14e1690f
(text-mode-hook-identify): Restore previous definition.
Richard M. Stallman <rms@gnu.org>
parents:
43190
diff
changeset
|
99 ;; This can be made a no-op once all modes that use text-mode-hook |
431e14e1690f
(text-mode-hook-identify): Restore previous definition.
Richard M. Stallman <rms@gnu.org>
parents:
43190
diff
changeset
|
100 ;; are "derived" from text-mode. |
431e14e1690f
(text-mode-hook-identify): Restore previous definition.
Richard M. Stallman <rms@gnu.org>
parents:
43190
diff
changeset
|
101 (defun text-mode-hook-identify () |
431e14e1690f
(text-mode-hook-identify): Restore previous definition.
Richard M. Stallman <rms@gnu.org>
parents:
43190
diff
changeset
|
102 "Mark that this mode has run `text-mode-hook'. |
431e14e1690f
(text-mode-hook-identify): Restore previous definition.
Richard M. Stallman <rms@gnu.org>
parents:
43190
diff
changeset
|
103 This is how `toggle-text-mode-auto-fill' knows which buffers to operate on." |
431e14e1690f
(text-mode-hook-identify): Restore previous definition.
Richard M. Stallman <rms@gnu.org>
parents:
43190
diff
changeset
|
104 (set (make-local-variable 'text-mode-variant) t)) |
431e14e1690f
(text-mode-hook-identify): Restore previous definition.
Richard M. Stallman <rms@gnu.org>
parents:
43190
diff
changeset
|
105 |
431e14e1690f
(text-mode-hook-identify): Restore previous definition.
Richard M. Stallman <rms@gnu.org>
parents:
43190
diff
changeset
|
106 (add-hook 'text-mode-hook 'text-mode-hook-identify) |
43190
dde60cf0dc4a
(text-mode-hook-identify): Define as no-op.
Richard M. Stallman <rms@gnu.org>
parents:
43122
diff
changeset
|
107 |
19590
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
108 (defun toggle-text-mode-auto-fill () |
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
109 "Toggle whether to use Auto Fill in Text mode and related modes. |
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
110 This command affects all buffers that use modes related to Text mode, |
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
111 both existing buffers and buffers that you subsequently create." |
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
112 (interactive) |
40360
04be247dd745
(text-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38697
diff
changeset
|
113 (let ((enable-mode (not (memq 'turn-on-auto-fill text-mode-hook)))) |
19590
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
114 (if enable-mode |
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
115 (add-hook 'text-mode-hook 'turn-on-auto-fill) |
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
116 (remove-hook 'text-mode-hook 'turn-on-auto-fill)) |
40360
04be247dd745
(text-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38697
diff
changeset
|
117 (dolist (buffer (buffer-list)) |
04be247dd745
(text-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38697
diff
changeset
|
118 (with-current-buffer buffer |
04be247dd745
(text-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38697
diff
changeset
|
119 (if (or (derived-mode-p 'text-mode) text-mode-variant) |
04be247dd745
(text-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38697
diff
changeset
|
120 (auto-fill-mode (if enable-mode 1 0))))) |
19590
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
121 (message "Auto Fill %s in Text modes" |
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
122 (if enable-mode "enabled" "disabled")))) |
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
123 |
97703
81b9b3976a29
(text-mode-map): Unbind "\es" from `center-line' and "\eS" from `center-paragraph'.
Juri Linkov <juri@jurta.org>
parents:
94670
diff
changeset
|
124 |
81b9b3976a29
(text-mode-map): Unbind "\es" from `center-line' and "\eS" from `center-paragraph'.
Juri Linkov <juri@jurta.org>
parents:
94670
diff
changeset
|
125 (define-key facemenu-keymap "\eS" 'center-paragraph) |
81b9b3976a29
(text-mode-map): Unbind "\es" from `center-line' and "\eS" from `center-paragraph'.
Juri Linkov <juri@jurta.org>
parents:
94670
diff
changeset
|
126 |
36 | 127 (defun center-paragraph () |
128 "Center each nonblank line in the paragraph at or after point. | |
1576 | 129 See `center-line' for more info." |
36 | 130 (interactive) |
131 (save-excursion | |
132 (forward-paragraph) | |
133 (or (bolp) (newline 1)) | |
134 (let ((end (point))) | |
135 (backward-paragraph) | |
136 (center-region (point) end)))) | |
137 | |
138 (defun center-region (from to) | |
139 "Center each nonblank line starting in the region. | |
1576 | 140 See `center-line' for more info." |
36 | 141 (interactive "r") |
142 (if (> from to) | |
143 (let ((tem to)) | |
144 (setq to from from tem))) | |
145 (save-excursion | |
146 (save-restriction | |
147 (narrow-to-region from to) | |
148 (goto-char from) | |
149 (while (not (eobp)) | |
150 (or (save-excursion (skip-chars-forward " \t") (eolp)) | |
151 (center-line)) | |
152 (forward-line 1))))) | |
153 | |
97703
81b9b3976a29
(text-mode-map): Unbind "\es" from `center-line' and "\eS" from `center-paragraph'.
Juri Linkov <juri@jurta.org>
parents:
94670
diff
changeset
|
154 (define-key facemenu-keymap "\es" 'center-line) |
81b9b3976a29
(text-mode-map): Unbind "\es" from `center-line' and "\eS" from `center-paragraph'.
Juri Linkov <juri@jurta.org>
parents:
94670
diff
changeset
|
155 |
13023
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
156 (defun center-line (&optional nlines) |
36 | 157 "Center the line point is on, within the width specified by `fill-column'. |
158 This means adjusting the indentation so that it equals | |
13023
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
159 the distance between the end of the text and `fill-column'. |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
160 The argument NLINES says how many lines to center." |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
161 (interactive "P") |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
162 (if nlines (setq nlines (prefix-numeric-value nlines))) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
163 (while (not (eq nlines 0)) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
164 (save-excursion |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
165 (let ((lm (current-left-margin)) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
166 line-length) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
167 (beginning-of-line) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
168 (delete-horizontal-space) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
169 (end-of-line) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
170 (delete-horizontal-space) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
171 (setq line-length (current-column)) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
172 (if (> (- fill-column lm line-length) 0) |
28108
0d9cac36402a
(text-mode-hook): Add flyspell-mode to
Dave Love <fx@gnu.org>
parents:
27202
diff
changeset
|
173 (indent-line-to |
13023
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
174 (+ lm (/ (- fill-column lm line-length) 2)))))) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
175 (cond ((null nlines) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
176 (setq nlines 0)) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
177 ((> nlines 0) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
178 (setq nlines (1- nlines)) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
179 (forward-line 1)) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
180 ((< nlines 0) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
181 (setq nlines (1+ nlines)) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
182 (forward-line -1))))) |
657
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
283
diff
changeset
|
183 |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79719
diff
changeset
|
184 ;; arch-tag: a07ccaad-da13-4d7b-9c61-cd04f5926aab |
657
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
283
diff
changeset
|
185 ;;; text-mode.el ends here |