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