Mercurial > hg > xemacs-beta
annotate lisp/text-mode.el @ 5613:a944c124b2d3
Be more careful about what we shadow, #'byte-compile-eval.
2011-12-13 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el (byte-compile-eval):
When evaluating code at compile time, don't put those macros in
the macro environment that only make sense when creating
byte-compiled output.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Tue, 13 Dec 2011 20:42:30 +0000 |
parents | 308d34e9f07d |
children | 182d01410b8d |
rev | line source |
---|---|
428 | 1 ;;; text-mode.el --- text mode, and its idiosyncratic commands. |
2 | |
3 ;; Copyright (C) 1985, 1992, 1994, 1997 Free Software Foundation, Inc. | |
4 | |
5 ;; Maintainer: FSF | |
6 ;; Keywords: wp, dumped | |
7 | |
8 ;; This file is part of XEmacs. | |
9 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
428
diff
changeset
|
10 ;; XEmacs is free software: you can redistribute it and/or modify it |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
428
diff
changeset
|
11 ;; under the terms of the GNU General Public License as published by the |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
428
diff
changeset
|
12 ;; Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
428
diff
changeset
|
13 ;; option) any later version. |
428 | 14 |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
428
diff
changeset
|
15 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
428
diff
changeset
|
16 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
428
diff
changeset
|
17 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
428
diff
changeset
|
18 ;; for more details. |
428 | 19 |
20 ;; You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
428
diff
changeset
|
21 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
428 | 22 |
23 ;;; Synched up with: FSF 20.2. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;; This file is dumped with XEmacs. | |
28 | |
29 ;; This package provides the fundamental text mode documented in the | |
30 ;; Emacs user's manual. | |
31 | |
32 ;;; Code: | |
33 | |
34 (defvar text-mode-hook nil | |
35 "Normal hook run when entering Text mode and many related modes.") | |
36 | |
37 (defvar text-mode-variant nil | |
38 "Non-nil if this buffer's major mode is a variant of Text mode.") | |
39 | |
40 (defvar text-mode-syntax-table nil | |
41 "Syntax table used while in text mode.") | |
42 | |
43 (defvar text-mode-abbrev-table nil | |
44 "Abbrev table used while in text mode.") | |
45 (define-abbrev-table 'text-mode-abbrev-table ()) | |
46 | |
47 (if text-mode-syntax-table | |
48 () | |
49 (setq text-mode-syntax-table (make-syntax-table)) | |
50 (modify-syntax-entry ?\" ". " text-mode-syntax-table) | |
51 (modify-syntax-entry ?\\ ". " text-mode-syntax-table) | |
52 (modify-syntax-entry ?' "w " text-mode-syntax-table)) | |
53 | |
54 (defvar text-mode-map nil | |
55 "Keymap for Text mode. | |
56 Many other modes, such as Mail mode, Outline mode and Indented Text mode, | |
57 inherit all the commands defined in this map.") | |
58 | |
59 (if text-mode-map | |
60 () | |
61 (setq text-mode-map (make-sparse-keymap)) | |
62 ;; XEmacs change | |
63 (set-keymap-name text-mode-map 'text-mode-map) | |
64 (define-key text-mode-map "\e\t" 'ispell-complete-word) | |
65 (define-key text-mode-map "\t" 'indent-relative) | |
66 (define-key text-mode-map "\es" 'center-line) | |
67 (define-key text-mode-map "\eS" 'center-paragraph)) | |
68 | |
69 | |
70 (defun text-mode () | |
71 "Major mode for editing text written for humans to read. | |
72 In this mode, paragraphs are delimited only by blank or white lines. | |
73 You can thus get the full benefit of adaptive filling | |
74 (see the variable `adaptive-fill-mode'). | |
75 \\{text-mode-map} | |
76 Turning on Text mode runs the normal hook `text-mode-hook'." | |
77 (interactive) | |
78 (kill-all-local-variables) | |
79 (use-local-map text-mode-map) | |
80 (setq local-abbrev-table text-mode-abbrev-table) | |
81 (set-syntax-table text-mode-syntax-table) | |
82 (make-local-variable 'paragraph-start) | |
83 (setq paragraph-start (concat page-delimiter "\\|[ \t]*$")) | |
84 (make-local-variable 'paragraph-separate) | |
85 (setq paragraph-separate paragraph-start) | |
86 (setq mode-name "Text") | |
87 (setq major-mode 'text-mode) | |
88 (run-hooks 'text-mode-hook)) | |
89 | |
90 (defun paragraph-indent-text-mode () | |
91 "Major mode for editing text, with leading spaces starting a paragraph. | |
92 In this mode, you do not need blank lines between paragraphs | |
93 when the first line of the following paragraph starts with whitespace. | |
94 Special commands: | |
95 \\{text-mode-map} | |
96 Turning on Paragraph-Indent Text mode runs the normal hooks | |
97 `text-mode-hook' and `paragraph-indent-text-mode-hook'." | |
98 (interactive) | |
99 (kill-all-local-variables) | |
100 (use-local-map text-mode-map) | |
101 (setq mode-name "Parindent") | |
102 (setq major-mode 'paragraph-indent-text-mode) | |
103 (setq local-abbrev-table text-mode-abbrev-table) | |
104 (set-syntax-table text-mode-syntax-table) | |
105 (run-hooks 'text-mode-hook 'paragraph-indent-text-mode-hook)) | |
106 | |
107 (defalias 'indented-text-mode 'text-mode) | |
108 | |
109 (defun text-mode-hook-identify () | |
110 "Mark that this mode has run `text-mode-hook'. | |
111 This is how `toggle-text-mode-auto-fill' knows which buffers to operate on." | |
112 (make-local-variable 'text-mode-variant) | |
113 (setq text-mode-variant t)) | |
114 | |
115 (add-hook 'text-mode-hook 'text-mode-hook-identify) | |
116 | |
117 (defun toggle-text-mode-auto-fill () | |
118 "Toggle whether to use Auto Fill in Text mode and related modes. | |
119 This command affects all buffers that use modes related to Text mode, | |
120 both existing buffers and buffers that you subsequently create." | |
121 (interactive) | |
122 (let ((enable-mode (not (memq 'turn-on-auto-fill text-mode-hook))) | |
123 (buffers (buffer-list))) | |
124 (if enable-mode | |
125 (add-hook 'text-mode-hook 'turn-on-auto-fill) | |
126 (remove-hook 'text-mode-hook 'turn-on-auto-fill)) | |
127 (while buffers | |
128 (with-current-buffer (car buffers) | |
129 (if text-mode-variant | |
130 (auto-fill-mode (if enable-mode 1 0)))) | |
131 (setq buffers (cdr buffers))) | |
132 (message "Auto Fill %s in Text modes" | |
133 (if enable-mode "enabled" "disabled")))) | |
134 | |
135 (defun center-paragraph () | |
136 "Center each nonblank line in the paragraph at or after point. | |
137 See `center-line' for more info." | |
138 (interactive) | |
139 (save-excursion | |
140 (forward-paragraph) | |
141 (or (bolp) (newline 1)) | |
142 (let ((end (point))) | |
143 (backward-paragraph) | |
144 (center-region (point) end)))) | |
145 | |
146 (defun center-region (from to) | |
147 "Center each nonblank line starting in the region. | |
148 See `center-line' for more info." | |
149 (interactive "r") | |
150 (if (> from to) | |
151 (let ((tem to)) | |
152 (setq to from from tem))) | |
153 (save-excursion | |
154 (save-restriction | |
155 (narrow-to-region from to) | |
156 (goto-char from) | |
157 (while (not (eobp)) | |
158 (or (save-excursion (skip-chars-forward " \t") (eolp)) | |
159 (center-line)) | |
160 (forward-line 1))))) | |
161 | |
162 (defun center-line (&optional nlines) | |
163 "Center the line point is on, within the width specified by `fill-column'. | |
164 This means adjusting the indentation so that it equals | |
165 the distance between the end of the text and `fill-column'. | |
166 The argument NLINES says how many lines to center." | |
167 (interactive "P") | |
168 (if nlines (setq nlines (prefix-numeric-value nlines))) | |
169 (while (not (eq nlines 0)) | |
170 (save-excursion | |
171 (let ((lm (current-left-margin)) | |
172 line-length) | |
173 (beginning-of-line) | |
174 (delete-horizontal-space) | |
175 (end-of-line) | |
176 (delete-horizontal-space) | |
177 (setq line-length (current-column)) | |
178 (if (> (- fill-column lm line-length) 0) | |
179 (indent-line-to | |
180 (+ lm (/ (- fill-column lm line-length) 2)))))) | |
181 (cond ((null nlines) | |
182 (setq nlines 0)) | |
183 ((> nlines 0) | |
184 (setq nlines (1- nlines)) | |
185 (forward-line 1)) | |
186 ((< nlines 0) | |
187 (setq nlines (1+ nlines)) | |
188 (forward-line -1))))) | |
189 | |
190 ;;; text-mode.el ends here |