annotate lisp/modes/text-mode.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; Synched up with: FSF 19.30.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; This package provides the fundamental text mode documented in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; Emacs user's manual.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 (defvar text-mode-syntax-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 "Syntax table used while in text mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (defvar text-mode-abbrev-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 "Abbrev table used while in text mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (define-abbrev-table 'text-mode-abbrev-table ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (if text-mode-syntax-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (setq text-mode-syntax-table (make-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (modify-syntax-entry ?\" ". " text-mode-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 ?' "w " text-mode-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (defvar text-mode-map nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 "Keymap for Text mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 Many other modes, such as Mail mode, Outline mode and Indented Text mode,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 inherit all the commands defined in this map.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (if text-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (setq text-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (set-keymap-name text-mode-map 'text-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (define-key text-mode-map "\t" 'tab-to-tab-stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (define-key text-mode-map "\es" 'center-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (define-key text-mode-map "\eS" 'center-paragraph))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;(defun non-saved-text-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ; "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
62 ; (text-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ; (make-local-variable 'delete-auto-save-files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ; (setq delete-auto-save-files t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (defun text-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 "Major mode for editing text intended for humans to read.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 Special commands:\\{text-mode-map}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 Turning on Text mode calls the value of the variable `text-mode-hook',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 if that value is non-nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (use-local-map text-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (setq mode-name "Text")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (setq major-mode 'text-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (setq local-abbrev-table text-mode-abbrev-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (set-syntax-table text-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (run-hooks 'text-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (defvar indented-text-mode-map ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 "Keymap for Indented Text mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 All the commands defined in Text mode are inherited unless overridden.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (if indented-text-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;; Make different definition for TAB before the one in text-mode-map, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;; share the rest.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (setq indented-text-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (set-keymap-name indented-text-mode-map 'indented-text-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (set-keymap-parents indented-text-mode-map (list text-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (define-key indented-text-mode-map "\t" 'indent-relative))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (defun indented-text-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 "Major mode for editing text with indented paragraphs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 In this mode, paragraphs are delimited only by blank lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 You can thus get the benefit of adaptive filling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (see the variable `adaptive-fill-mode').
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 \\{indented-text-mode-map}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 Turning on `indented-text-mode' calls the value of the variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 `text-mode-hook', if that value is non-nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (use-local-map text-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (define-abbrev-table 'text-mode-abbrev-table ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (setq local-abbrev-table text-mode-abbrev-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (set-syntax-table text-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (make-local-variable 'indent-line-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (setq indent-line-function 'indent-relative-maybe)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (make-local-variable 'paragraph-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (setq paragraph-start (concat "$\\|" page-delimiter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (make-local-variable 'paragraph-separate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (setq paragraph-separate paragraph-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (use-local-map indented-text-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (setq mode-name "Indented Text")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (setq major-mode 'indented-text-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (run-hooks 'text-mode-hook 'indented-text-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (defun center-paragraph ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 "Center each nonblank line in the paragraph at or after point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 See `center-line' for more info."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (forward-paragraph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (or (bolp) (newline 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (let ((end (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (backward-paragraph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (center-region (point) end))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (defun center-region (from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 "Center each nonblank line starting in the region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 See `center-line' for more info."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (if (> from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (let ((tem to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (setq to from from tem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (narrow-to-region from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (goto-char from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (while (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (or (save-excursion (skip-chars-forward " \t") (eolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (center-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (forward-line 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (defun center-line (&optional nlines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 "Center the line point is on, within the width specified by `fill-column'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 This means adjusting the indentation so that it equals
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 the distance between the end of the text and `fill-column'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 The argument NLINES says how many lines to center."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (if nlines (setq nlines (prefix-numeric-value nlines)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (while (not (eq nlines 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (let ((lm (current-left-margin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 line-length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (delete-horizontal-space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (delete-horizontal-space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (setq line-length (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (if (> (- fill-column lm line-length) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (indent-line-to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (+ lm (/ (- fill-column lm line-length) 2))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (cond ((null nlines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (setq nlines 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 ((> nlines 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (setq nlines (1- nlines))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 ((< nlines 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (setq nlines (1+ nlines))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (forward-line -1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 ;;; text-mode.el ends here