Mercurial > emacs
annotate lisp/textmodes/text-mode.el @ 21426:4b4a4e32ffef
(mouse-save-then-kill): Get point-before-scroll
from the right buffer.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 08 Apr 1998 07:22:05 +0000 |
parents | 7fccc0f34e57 |
children | 3f3121176533 |
rev | line source |
---|---|
657
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
283
diff
changeset
|
1 ;;; text-mode.el --- text mode, and its idiosyncratic commands. |
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
283
diff
changeset
|
2 |
7300 | 3 ;; Copyright (C) 1985, 1992, 1994 Free Software Foundation, Inc. |
841 | 4 |
775
1ca26ccad38e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
727
diff
changeset
|
5 ;; Maintainer: FSF |
36 | 6 |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
727 | 11 ;; the Free Software Foundation; either version 2, or (at your option) |
36 | 12 ;; any later version. |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
14169 | 20 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 ;; Boston, MA 02111-1307, USA. | |
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 |
19589
8c19d570a391
(text-mode-hook): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18256
diff
changeset
|
31 (defvar text-mode-hook nil |
8c19d570a391
(text-mode-hook): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18256
diff
changeset
|
32 "Normal hook run when entering Text mode and many related modes.") |
8c19d570a391
(text-mode-hook): New defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18256
diff
changeset
|
33 |
19590
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
34 (defvar text-mode-variant nil |
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
35 "Non-nil if this buffer's major mode is a variant of Text mode.") |
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
36 |
36 | 37 (defvar text-mode-syntax-table nil |
38 "Syntax table used while in text mode.") | |
39 | |
40 (defvar text-mode-abbrev-table nil | |
41 "Abbrev table used while in text mode.") | |
42 (define-abbrev-table 'text-mode-abbrev-table ()) | |
43 | |
44 (if text-mode-syntax-table | |
45 () | |
46 (setq text-mode-syntax-table (make-syntax-table)) | |
47 (modify-syntax-entry ?\" ". " text-mode-syntax-table) | |
48 (modify-syntax-entry ?\\ ". " text-mode-syntax-table) | |
49 (modify-syntax-entry ?' "w " text-mode-syntax-table)) | |
50 | |
51 (defvar text-mode-map nil | |
52 "Keymap for Text mode. | |
53 Many other modes, such as Mail mode, Outline mode and Indented Text mode, | |
54 inherit all the commands defined in this map.") | |
55 | |
56 (if text-mode-map | |
57 () | |
58 (setq text-mode-map (make-sparse-keymap)) | |
4896
bc777b8e4b45
(text-mode-map): Bind ispell-complete-word to M-TAB.
Richard M. Stallman <rms@gnu.org>
parents:
4744
diff
changeset
|
59 (define-key text-mode-map "\e\t" 'ispell-complete-word) |
18222
b7ad635feeb8
(paragraph-indent-text-mode): Renamed from spaced-text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
18132
diff
changeset
|
60 (define-key text-mode-map "\t" 'indent-relative) |
36 | 61 (define-key text-mode-map "\es" 'center-line) |
62 (define-key text-mode-map "\eS" 'center-paragraph)) | |
63 | |
64 | |
65 (defun text-mode () | |
18132
95f6ac42b352
(spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
66 "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
|
67 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
|
68 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
|
69 (see the variable `adaptive-fill-mode'). |
6323 | 70 \\{text-mode-map} |
18132
95f6ac42b352
(spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
71 Turning on Text mode runs the normal hook `text-mode-hook'." |
36 | 72 (interactive) |
73 (kill-all-local-variables) | |
74 (use-local-map text-mode-map) | |
18132
95f6ac42b352
(spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
75 (setq local-abbrev-table text-mode-abbrev-table) |
95f6ac42b352
(spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
76 (set-syntax-table text-mode-syntax-table) |
95f6ac42b352
(spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
77 (make-local-variable 'paragraph-start) |
18256
27f2dfb2c1de
(text-mode): Let all-white lines separate paragraphs.
Richard M. Stallman <rms@gnu.org>
parents:
18222
diff
changeset
|
78 (setq paragraph-start (concat "[ \t]*$\\|" page-delimiter)) |
18132
95f6ac42b352
(spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
79 (make-local-variable 'paragraph-separate) |
95f6ac42b352
(spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
80 (setq paragraph-separate paragraph-start) |
36 | 81 (setq mode-name "Text") |
82 (setq major-mode 'text-mode) | |
18132
95f6ac42b352
(spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
83 (run-hooks 'text-mode-hook)) |
95f6ac42b352
(spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
84 |
18222
b7ad635feeb8
(paragraph-indent-text-mode): Renamed from spaced-text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
18132
diff
changeset
|
85 (defun paragraph-indent-text-mode () |
18132
95f6ac42b352
(spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
86 "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
|
87 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
|
88 when the first line of the following paragraph starts with whitespace. |
95f6ac42b352
(spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
89 Special commands: |
95f6ac42b352
(spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
90 \\{text-mode-map} |
18222
b7ad635feeb8
(paragraph-indent-text-mode): Renamed from spaced-text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
18132
diff
changeset
|
91 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
|
92 `text-mode-hook' and `paragraph-indent-text-mode-hook'." |
18132
95f6ac42b352
(spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
93 (interactive) |
95f6ac42b352
(spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
94 (kill-all-local-variables) |
95f6ac42b352
(spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
95 (use-local-map text-mode-map) |
18222
b7ad635feeb8
(paragraph-indent-text-mode): Renamed from spaced-text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
18132
diff
changeset
|
96 (setq mode-name "Parindent") |
b7ad635feeb8
(paragraph-indent-text-mode): Renamed from spaced-text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
18132
diff
changeset
|
97 (setq major-mode 'paragraph-indent-text-mode) |
36 | 98 (setq local-abbrev-table text-mode-abbrev-table) |
99 (set-syntax-table text-mode-syntax-table) | |
18222
b7ad635feeb8
(paragraph-indent-text-mode): Renamed from spaced-text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
18132
diff
changeset
|
100 (run-hooks 'text-mode-hook 'paragraph-indent-text-mode-hook)) |
18132
95f6ac42b352
(spaced-text-mode): Renamed from text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
101 |
18222
b7ad635feeb8
(paragraph-indent-text-mode): Renamed from spaced-text-mode.
Richard M. Stallman <rms@gnu.org>
parents:
18132
diff
changeset
|
102 (defalias 'indented-text-mode 'text-mode) |
36 | 103 |
19620
7fccc0f34e57
(text-mode-hook-identify): New function,
Richard M. Stallman <rms@gnu.org>
parents:
19590
diff
changeset
|
104 (defun text-mode-hook-identify () |
7fccc0f34e57
(text-mode-hook-identify): New function,
Richard M. Stallman <rms@gnu.org>
parents:
19590
diff
changeset
|
105 "Mark that this mode has run `text-mode-hook'. |
7fccc0f34e57
(text-mode-hook-identify): New function,
Richard M. Stallman <rms@gnu.org>
parents:
19590
diff
changeset
|
106 This is how `toggle-text-mode-auto-fill' knows which buffers to operate on." |
7fccc0f34e57
(text-mode-hook-identify): New function,
Richard M. Stallman <rms@gnu.org>
parents:
19590
diff
changeset
|
107 (make-local-variable 'text-mode-variant) |
7fccc0f34e57
(text-mode-hook-identify): New function,
Richard M. Stallman <rms@gnu.org>
parents:
19590
diff
changeset
|
108 (setq text-mode-variant t)) |
7fccc0f34e57
(text-mode-hook-identify): New function,
Richard M. Stallman <rms@gnu.org>
parents:
19590
diff
changeset
|
109 |
7fccc0f34e57
(text-mode-hook-identify): New function,
Richard M. Stallman <rms@gnu.org>
parents:
19590
diff
changeset
|
110 (add-hook 'text-mode-hook 'text-mode-hook-identify) |
7fccc0f34e57
(text-mode-hook-identify): New function,
Richard M. Stallman <rms@gnu.org>
parents:
19590
diff
changeset
|
111 |
19590
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
112 (defun toggle-text-mode-auto-fill () |
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
113 "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
|
114 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
|
115 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
|
116 (interactive) |
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
117 (let ((enable-mode (not (memq 'turn-on-auto-fill text-mode-hook))) |
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
118 (buffers (buffer-list))) |
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
119 (if enable-mode |
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
120 (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
|
121 (remove-hook 'text-mode-hook 'turn-on-auto-fill)) |
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
122 (while buffers |
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
123 (with-current-buffer (car buffers) |
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
124 (if text-mode-variant |
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
125 (auto-fill-mode (if enable-mode 1 0)))) |
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
126 (setq buffers (cdr buffers))) |
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
127 (message "Auto Fill %s in Text modes" |
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
128 (if enable-mode "enabled" "disabled")))) |
167f4700890a
(text-mode-variant): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
19589
diff
changeset
|
129 |
36 | 130 (defun center-paragraph () |
131 "Center each nonblank line in the paragraph at or after point. | |
1576 | 132 See `center-line' for more info." |
36 | 133 (interactive) |
134 (save-excursion | |
135 (forward-paragraph) | |
136 (or (bolp) (newline 1)) | |
137 (let ((end (point))) | |
138 (backward-paragraph) | |
139 (center-region (point) end)))) | |
140 | |
141 (defun center-region (from to) | |
142 "Center each nonblank line starting in the region. | |
1576 | 143 See `center-line' for more info." |
36 | 144 (interactive "r") |
145 (if (> from to) | |
146 (let ((tem to)) | |
147 (setq to from from tem))) | |
148 (save-excursion | |
149 (save-restriction | |
150 (narrow-to-region from to) | |
151 (goto-char from) | |
152 (while (not (eobp)) | |
153 (or (save-excursion (skip-chars-forward " \t") (eolp)) | |
154 (center-line)) | |
155 (forward-line 1))))) | |
156 | |
13023
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
157 (defun center-line (&optional nlines) |
36 | 158 "Center the line point is on, within the width specified by `fill-column'. |
159 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
|
160 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
|
161 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
|
162 (interactive "P") |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
163 (if nlines (setq nlines (prefix-numeric-value nlines))) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
164 (while (not (eq nlines 0)) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
165 (save-excursion |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
166 (let ((lm (current-left-margin)) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
167 line-length) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
168 (beginning-of-line) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
169 (delete-horizontal-space) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
170 (end-of-line) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
171 (delete-horizontal-space) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
172 (setq line-length (current-column)) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
173 (if (> (- fill-column lm line-length) 0) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
174 (indent-line-to |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
175 (+ lm (/ (- fill-column lm line-length) 2)))))) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
176 (cond ((null nlines) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
177 (setq nlines 0)) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
178 ((> nlines 0) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
179 (setq nlines (1- nlines)) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
180 (forward-line 1)) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
181 ((< nlines 0) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
182 (setq nlines (1+ nlines)) |
78f30dd2c8fd
(center-line): New arg NLINES.
Richard M. Stallman <rms@gnu.org>
parents:
10899
diff
changeset
|
183 (forward-line -1))))) |
657
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
283
diff
changeset
|
184 |
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
283
diff
changeset
|
185 ;;; text-mode.el ends here |