annotate lisp/text-mode.el @ 247:e70b3a057e12 r20-5b22

Import from CVS: tag r20-5b22
author cvs
date Mon, 13 Aug 2007 10:18:21 +0200
parents 41ff10fd062f
children 677f6a0ee643
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1 ;;; text-mode.el --- text mode, and its idiosyncratic commands.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 1992, 1994, 1997 Free Software Foundation, Inc.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
5 ;; Maintainer: FSF
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
6 ;; Keywords: wp, dumped
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
7
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
9
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
13 ;; any later version.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
14
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
18 ;; General Public License for more details.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
19
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
23 ;; 02111-1307, USA.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
24
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
25 ;;; Synched up with: FSF 19.34.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
26
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
27 ;;; Commentary:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
28
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
29 ;; This file is dumped with XEmacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
30
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
31 ;; This package provides the fundamental text mode documented in the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
32 ;; Emacs user's manual.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
33
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
34 ;;; Code:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
35
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
36 (defvar text-mode-syntax-table nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
37 "Syntax table used while in text mode.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
38
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
39 (defvar text-mode-abbrev-table nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
40 "Abbrev table used while in text mode.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
41 (define-abbrev-table 'text-mode-abbrev-table ())
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
42
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
43 (if text-mode-syntax-table
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
44 ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
45 (setq text-mode-syntax-table (make-syntax-table))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
46 (modify-syntax-entry ?\" ". " text-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
47 (modify-syntax-entry ?\\ ". " text-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
48 (modify-syntax-entry ?' "w " text-mode-syntax-table))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
49
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
50 (defvar text-mode-map nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
51 "Keymap for Text mode.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
52 Many other modes, such as Mail mode, Outline mode and Indented Text mode,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
53 inherit all the commands defined in this map.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
54
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
55 (if text-mode-map
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
56 ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
57 (setq text-mode-map (make-sparse-keymap))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
58 ;; XEmacs change
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
59 (set-keymap-name text-mode-map 'text-mode-map)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
60 (define-key text-mode-map "\e\t" 'ispell-complete-word)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
61 (define-key text-mode-map "\t" 'tab-to-tab-stop)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
62 (define-key text-mode-map "\es" 'center-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
63 (define-key text-mode-map "\eS" 'center-paragraph))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
64
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
65
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
66 ;(defun non-saved-text-mode ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
67 ; "Like text-mode, but delete auto save file when file is saved for real."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
68 ; (text-mode)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
69 ; (make-local-variable 'delete-auto-save-files)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
70 ; (setq delete-auto-save-files t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
71
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
72 (defun text-mode ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
73 "Major mode for editing text intended for humans to read.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
74 Special commands:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
75 \\{text-mode-map}
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
76 Turning on Text mode calls the value of the variable `text-mode-hook',
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
77 if that value is non-nil."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
78 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
79 (kill-all-local-variables)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
80 (use-local-map text-mode-map)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
81 (setq mode-name "Text")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
82 (setq major-mode 'text-mode)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
83 (setq local-abbrev-table text-mode-abbrev-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
84 (set-syntax-table text-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
85 (run-hooks 'text-mode-hook))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
86
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
87 (defvar indented-text-mode-map ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
88 "Keymap for Indented Text mode.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
89 All the commands defined in Text mode are inherited unless overridden.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
90
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
91 (if indented-text-mode-map
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
92 ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
93 ;; Make different definition for TAB before the one in text-mode-map, but
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
94 ;; share the rest.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
95 ;; XEmacs change
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
96 (setq indented-text-mode-map (make-sparse-keymap))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
97 (set-keymap-name indented-text-mode-map 'indented-text-mode-map)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
98 (set-keymap-parents indented-text-mode-map (list text-mode-map))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
99 (define-key indented-text-mode-map "\t" 'indent-relative))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
100
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
101 (defun indented-text-mode ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
102 "Major mode for editing text with indented paragraphs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
103 In this mode, paragraphs are delimited only by blank lines.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
104 You can thus get the benefit of adaptive filling
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
105 (see the variable `adaptive-fill-mode').
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
106 \\{indented-text-mode-map}
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
107 Turning on `indented-text-mode' calls the value of the variable
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
108 `text-mode-hook', if that value is non-nil."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
109 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
110 (kill-all-local-variables)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
111 (use-local-map text-mode-map)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
112 (define-abbrev-table 'text-mode-abbrev-table ())
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
113 (setq local-abbrev-table text-mode-abbrev-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
114 (set-syntax-table text-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
115 (make-local-variable 'indent-line-function)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
116 (setq indent-line-function 'indent-relative-maybe)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
117 (make-local-variable 'paragraph-start)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
118 (setq paragraph-start (concat "$\\|" page-delimiter))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
119 (make-local-variable 'paragraph-separate)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
120 (setq paragraph-separate paragraph-start)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
121 (use-local-map indented-text-mode-map)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
122 (setq mode-name "Indented Text")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
123 (setq major-mode 'indented-text-mode)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
124 (run-hooks 'text-mode-hook 'indented-text-mode-hook))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
125
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
126 (defun center-paragraph ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
127 "Center each nonblank line in the paragraph at or after point.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
128 See `center-line' for more info."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
129 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
130 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
131 (forward-paragraph)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
132 (or (bolp) (newline 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
133 (let ((end (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
134 (backward-paragraph)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
135 (center-region (point) end))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
136
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
137 (defun center-region (from to)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
138 "Center each nonblank line starting in the region.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
139 See `center-line' for more info."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
140 (interactive "r")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
141 (if (> from to)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
142 (let ((tem to))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
143 (setq to from from tem)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
144 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
145 (save-restriction
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
146 (narrow-to-region from to)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
147 (goto-char from)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
148 (while (not (eobp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
149 (or (save-excursion (skip-chars-forward " \t") (eolp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
150 (center-line))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
151 (forward-line 1)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
152
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
153 (defun center-line (&optional nlines)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
154 "Center the line point is on, within the width specified by `fill-column'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
155 This means adjusting the indentation so that it equals
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
156 the distance between the end of the text and `fill-column'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
157 The argument NLINES says how many lines to center."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
158 (interactive "P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
159 (if nlines (setq nlines (prefix-numeric-value nlines)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
160 (while (not (eq nlines 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
161 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
162 (let ((lm (current-left-margin))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
163 line-length)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
164 (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
165 (delete-horizontal-space)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
166 (end-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
167 (delete-horizontal-space)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
168 (setq line-length (current-column))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
169 (if (> (- fill-column lm line-length) 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
170 (indent-line-to
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
171 (+ lm (/ (- fill-column lm line-length) 2))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
172 (cond ((null nlines)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
173 (setq nlines 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
174 ((> nlines 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
175 (setq nlines (1- nlines))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
176 (forward-line 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
177 ((< nlines 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
178 (setq nlines (1+ nlines))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
179 (forward-line -1)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
180
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
181 ;;; text-mode.el ends here