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