annotate lisp/modes/text-mode.el @ 193:f53b5ca2e663 r20-3b23

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