comparison lisp/text-mode.el @ 251:677f6a0ee643 r20-5b24

Import from CVS: tag r20-5b24
author cvs
date Mon, 13 Aug 2007 10:19:59 +0200
parents 41ff10fd062f
children 70ad99077275
comparison
equal deleted inserted replaced
250:f385a461c9aa 251:677f6a0ee643
20 ;; You should have received a copy of the GNU General Public License 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 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 22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 ;; 02111-1307, USA. 23 ;; 02111-1307, USA.
24 24
25 ;;; Synched up with: FSF 19.34. 25 ;;; Synched up with: FSF 20.2.
26 26
27 ;;; Commentary: 27 ;;; Commentary:
28 28
29 ;; This file is dumped with XEmacs. 29 ;; This file is dumped with XEmacs.
30 30
31 ;; This package provides the fundamental text mode documented in the 31 ;; This package provides the fundamental text mode documented in the
32 ;; Emacs user's manual. 32 ;; Emacs user's manual.
33 33
34 ;;; Code: 34 ;;; Code:
35
36 (defvar text-mode-hook nil
37 "Normal hook run when entering Text mode and many related modes.")
38
39 (defvar text-mode-variant nil
40 "Non-nil if this buffer's major mode is a variant of Text mode.")
35 41
36 (defvar text-mode-syntax-table nil 42 (defvar text-mode-syntax-table nil
37 "Syntax table used while in text mode.") 43 "Syntax table used while in text mode.")
38 44
39 (defvar text-mode-abbrev-table nil 45 (defvar text-mode-abbrev-table nil
56 () 62 ()
57 (setq text-mode-map (make-sparse-keymap)) 63 (setq text-mode-map (make-sparse-keymap))
58 ;; XEmacs change 64 ;; XEmacs change
59 (set-keymap-name text-mode-map 'text-mode-map) 65 (set-keymap-name text-mode-map 'text-mode-map)
60 (define-key text-mode-map "\e\t" 'ispell-complete-word) 66 (define-key text-mode-map "\e\t" 'ispell-complete-word)
61 (define-key text-mode-map "\t" 'tab-to-tab-stop) 67 (define-key text-mode-map "\t" 'indent-relative)
62 (define-key text-mode-map "\es" 'center-line) 68 (define-key text-mode-map "\es" 'center-line)
63 (define-key text-mode-map "\eS" 'center-paragraph)) 69 (define-key text-mode-map "\eS" 'center-paragraph))
64 70
65 71
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 () 72 (defun text-mode ()
73 "Major mode for editing text intended for humans to read. 73 "Major mode for editing text written for humans to read.
74 Special commands: 74 In this mode, paragraphs are delimited only by blank or white lines.
75 You can thus get the full benefit of adaptive filling
76 (see the variable `adaptive-fill-mode').
75 \\{text-mode-map} 77 \\{text-mode-map}
76 Turning on Text mode calls the value of the variable `text-mode-hook', 78 Turning on Text mode runs the normal hook `text-mode-hook'."
77 if that value is non-nil."
78 (interactive) 79 (interactive)
79 (kill-all-local-variables) 80 (kill-all-local-variables)
80 (use-local-map text-mode-map) 81 (use-local-map text-mode-map)
82 (setq local-abbrev-table text-mode-abbrev-table)
83 (set-syntax-table text-mode-syntax-table)
84 (make-local-variable 'paragraph-start)
85 (setq paragraph-start (concat "[ \t]*$\\|" page-delimiter))
86 (make-local-variable 'paragraph-separate)
87 (setq paragraph-separate paragraph-start)
81 (setq mode-name "Text") 88 (setq mode-name "Text")
82 (setq major-mode 'text-mode) 89 (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)) 90 (run-hooks 'text-mode-hook))
86 91
87 (defvar indented-text-mode-map () 92 (defun paragraph-indent-text-mode ()
88 "Keymap for Indented Text mode. 93 "Major mode for editing text, with leading spaces starting a paragraph.
89 All the commands defined in Text mode are inherited unless overridden.") 94 In this mode, you do not need blank lines between paragraphs
90 95 when the first line of the following paragraph starts with whitespace.
91 (if indented-text-mode-map 96 Special commands:
92 () 97 \\{text-mode-map}
93 ;; Make different definition for TAB before the one in text-mode-map, but 98 Turning on Paragraph-Indent Text mode runs the normal hooks
94 ;; share the rest. 99 `text-mode-hook' and `paragraph-indent-text-mode-hook'."
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) 100 (interactive)
110 (kill-all-local-variables) 101 (kill-all-local-variables)
111 (use-local-map text-mode-map) 102 (use-local-map text-mode-map)
112 (define-abbrev-table 'text-mode-abbrev-table ()) 103 (setq mode-name "Parindent")
104 (setq major-mode 'paragraph-indent-text-mode)
113 (setq local-abbrev-table text-mode-abbrev-table) 105 (setq local-abbrev-table text-mode-abbrev-table)
114 (set-syntax-table text-mode-syntax-table) 106 (set-syntax-table text-mode-syntax-table)
115 (make-local-variable 'indent-line-function) 107 (run-hooks 'text-mode-hook 'paragraph-indent-text-mode-hook))
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 108
109 (defalias 'indented-text-mode 'text-mode)
110
111 (defun text-mode-hook-identify ()
112 "Mark that this mode has run `text-mode-hook'.
113 This is how `toggle-text-mode-auto-fill' knows which buffers to operate on."
114 (make-local-variable 'text-mode-variant)
115 (setq text-mode-variant t))
116
117 (add-hook 'text-mode-hook 'text-mode-hook-identify)
118
119 (defun toggle-text-mode-auto-fill ()
120 "Toggle whether to use Auto Fill in Text mode and related modes.
121 This command affects all buffers that use modes related to Text mode,
122 both existing buffers and buffers that you subsequently create."
123 (interactive)
124 (let ((enable-mode (not (memq 'turn-on-auto-fill text-mode-hook)))
125 (buffers (buffer-list)))
126 (if enable-mode
127 (add-hook 'text-mode-hook 'turn-on-auto-fill)
128 (remove-hook 'text-mode-hook 'turn-on-auto-fill))
129 (while buffers
130 (with-current-buffer (car buffers)
131 (if text-mode-variant
132 (auto-fill-mode (if enable-mode 1 0))))
133 (setq buffers (cdr buffers)))
134 (message "Auto Fill %s in Text modes"
135 (if enable-mode "enabled" "disabled"))))
136
126 (defun center-paragraph () 137 (defun center-paragraph ()
127 "Center each nonblank line in the paragraph at or after point. 138 "Center each nonblank line in the paragraph at or after point.
128 See `center-line' for more info." 139 See `center-line' for more info."
129 (interactive) 140 (interactive)
130 (save-excursion 141 (save-excursion