aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2001-12-01 00:17:08 +0000
committerStefan Monnier2001-12-01 00:17:08 +0000
commit6c0bc4a0b901db9be13c6dfdb8370b160dc144ca (patch)
tree16742f92ea0e7ac99eeae2b669d670cd8cd96eaf
parentf7d5479b3d89a3a3af03adf2ed66d3c6be56b40c (diff)
downloademacs-6c0bc4a0b901db9be13c6dfdb8370b160dc144ca.tar.gz
emacs-6c0bc4a0b901db9be13c6dfdb8370b160dc144ca.zip
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
-rw-r--r--lisp/enriched.el91
1 files changed, 38 insertions, 53 deletions
diff --git a/lisp/enriched.el b/lisp/enriched.el
index bd474058b7c..43da676c4c4 100644
--- a/lisp/enriched.el
+++ b/lisp/enriched.el
@@ -73,7 +73,7 @@ in text/enriched files."
73(defface excerpt 73(defface excerpt
74 '((t (:italic t))) 74 '((t (:italic t)))
75 "Face used for text that is an excerpt from another document. 75 "Face used for text that is an excerpt from another document.
76This is used in enriched-mode for text explicitly marked as an excerpt." 76This is used in `enriched-mode' for text explicitly marked as an excerpt."
77 :group 'enriched) 77 :group 'enriched)
78 78
79(defconst enriched-display-table (or (copy-sequence standard-display-table) 79(defconst enriched-display-table (or (copy-sequence standard-display-table)
@@ -141,18 +141,9 @@ Any property that is neither on this list nor dealt with by
141 141
142;;; Internal variables 142;;; Internal variables
143 143
144(defvar enriched-mode nil
145 "True if Enriched mode is in use.")
146(make-variable-buffer-local 'enriched-mode)
147(put 'enriched-mode 'permanent-local t)
148
149(if (not (assq 'enriched-mode minor-mode-alist))
150 (setq minor-mode-alist
151 (cons '(enriched-mode " Enriched")
152 minor-mode-alist)))
153 144
154(defcustom enriched-mode-hook nil 145(defcustom enriched-mode-hook nil
155 "Functions to run when entering Enriched mode. 146 "Hook run after entering/leaving Enriched mode.
156If you set variables in this hook, you should arrange for them to be restored 147If you set variables in this hook, you should arrange for them to be restored
157to their old values if you leave Enriched mode. One way to do this is to add 148to their old values if you leave Enriched mode. One way to do this is to add
158them and their old values to `enriched-old-bindings'." 149them and their old values to `enriched-old-bindings'."
@@ -168,59 +159,53 @@ The value is a list of \(VAR VALUE VAR VALUE...).")
168;;; Define the mode 159;;; Define the mode
169;;; 160;;;
170 161
162(put 'enriched-mode 'permanent-local t)
171;;;###autoload 163;;;###autoload
172(defun enriched-mode (&optional arg) 164(define-minor-mode enriched-mode
173 "Minor mode for editing text/enriched files. 165 "Minor mode for editing text/enriched files.
174These are files with embedded formatting information in the MIME standard 166These are files with embedded formatting information in the MIME standard
175text/enriched format. 167text/enriched format.
176Turning the mode on runs `enriched-mode-hook'. 168Turning the mode on runs `enriched-mode-hook'.
177 169
178More information about Enriched mode is available in the file 170More information about Enriched mode is available in the file
179etc/enriched.doc in the Emacs distribution directory. 171etc/enriched.doc in the Emacs distribution directory.
180 172
181Commands: 173Commands:
182 174
183\\<enriched-mode-map>\\{enriched-mode-map}" 175\\<enriched-mode-map>\\{enriched-mode-map}"
184 (interactive "P") 176 nil " Enriched" nil
185 (let ((mod (buffer-modified-p))) 177 (cond ((null enriched-mode)
186 (cond ((or (<= (prefix-numeric-value arg) 0) 178 ;; Turn mode off
187 (and enriched-mode (null arg))) 179 (setq buffer-file-format (delq 'text/enriched buffer-file-format))
188 ;; Turn mode off 180 ;; restore old variable values
189 (setq enriched-mode nil) 181 (while enriched-old-bindings
190 (setq buffer-file-format (delq 'text/enriched buffer-file-format)) 182 (set (pop enriched-old-bindings) (pop enriched-old-bindings))))
191 ;; restore old variable values 183
192 (while enriched-old-bindings 184 ((memq 'text/enriched buffer-file-format)
193 (funcall 'set (car enriched-old-bindings) 185 ;; Mode already on; do nothing.
194 (car (cdr enriched-old-bindings))) 186 nil)
195 (setq enriched-old-bindings (cdr (cdr enriched-old-bindings))))) 187
196 188 (t ; Turn mode on
197 (enriched-mode nil) ; Mode already on; do nothing. 189 (push 'text/enriched buffer-file-format)
198 190 ;; Save old variable values before we change them.
199 (t (setq enriched-mode t) ; Turn mode on 191 ;; These will be restored if we exit Enriched mode.
200 (add-to-list 'buffer-file-format 'text/enriched) 192 (setq enriched-old-bindings
201 ;; Save old variable values before we change them. 193 (list 'buffer-display-table buffer-display-table
202 ;; These will be restored if we exit Enriched mode. 194 'indent-line-function indent-line-function
203 (setq enriched-old-bindings 195 'default-text-properties default-text-properties))
204 (list 'buffer-display-table buffer-display-table 196 (make-local-variable 'indent-line-function)
205 'indent-line-function indent-line-function 197 (make-local-variable 'default-text-properties)
206 'default-text-properties default-text-properties)) 198 (setq indent-line-function 'indent-to-left-margin ;WHY?? -sm
207 (make-local-variable 'indent-line-function) 199 buffer-display-table enriched-display-table)
208 (make-local-variable 'default-text-properties) 200 (use-hard-newlines 1 nil)
209 (setq indent-line-function 'indent-to-left-margin 201 (let ((sticky (plist-get default-text-properties 'front-sticky))
210 buffer-display-table enriched-display-table) 202 (p enriched-par-props))
211 (use-hard-newlines 1 nil) 203 (dolist (x p)
212 (let ((sticky (plist-get default-text-properties 'front-sticky)) 204 (add-to-list 'sticky x))
213 (p enriched-par-props)) 205 (if sticky
214 (while p 206 (setq default-text-properties
215 (add-to-list 'sticky (car p)) 207 (plist-put default-text-properties
216 (setq p (cdr p))) 208 'front-sticky sticky)))))))
217 (if sticky
218 (setq default-text-properties
219 (plist-put default-text-properties
220 'front-sticky sticky))))
221 (run-hooks 'enriched-mode-hook)))
222 (set-buffer-modified-p mod)
223 (force-mode-line-update)))
224 209
225;;; 210;;;
226;;; Keybindings 211;;; Keybindings