Mercurial > emacs
comparison lisp/textmodes/enriched.el @ 57147:049bdfb5d92f
(enriched-rerun-flag): New variable.
(enriched-before-change-major-mode): New function.
Add it to `change-major-mode-hook'.
(enriched-after-change-major-mode): New function.
Add it to `after-change-major-mode-hook'.
(enriched-mode): Make it work correctly if called from
`after-change-major-mode-hook'.
No longer set `indent-line-function'.
author | Luc Teirlinck <teirllm@auburn.edu> |
---|---|
date | Sun, 19 Sep 2004 00:12:43 +0000 |
parents | a712704c769c |
children | 6cbbae74d7ca 0796fc36c2bd |
comparison
equal
deleted
inserted
replaced
57146:942b8e28d21a | 57147:049bdfb5d92f |
---|---|
1 ;;; enriched.el --- read and save files in text/enriched format | 1 ;;; enriched.el --- read and save files in text/enriched format |
2 | 2 |
3 ;; Copyright (c) 1994, 1995, 1996, 2002 Free Software Foundation, Inc. | 3 ;; Copyright (c) 1994, 1995, 1996, 2002, 2004 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: Boris Goldowsky <boris@gnu.org> | 5 ;; Author: Boris Goldowsky <boris@gnu.org> |
6 ;; Keywords: wp, faces | 6 ;; Keywords: wp, faces |
7 | 7 |
8 ;; This file is part of GNU Emacs. | 8 ;; This file is part of GNU Emacs. |
139 Any property that is neither on this list nor dealt with by | 139 Any property that is neither on this list nor dealt with by |
140 `enriched-translations' will generate a warning.") | 140 `enriched-translations' will generate a warning.") |
141 | 141 |
142 ;;; Internal variables | 142 ;;; Internal variables |
143 | 143 |
144 | |
145 (defcustom enriched-mode-hook nil | 144 (defcustom enriched-mode-hook nil |
146 "Hook run after entering/leaving Enriched mode. | 145 "Hook run after entering/leaving Enriched mode. |
147 If you set variables in this hook, you should arrange for them to be restored | 146 If you set variables in this hook, you should arrange for them to be restored |
148 to their old values if you leave Enriched mode. One way to do this is to add | 147 to their old values if you leave Enriched mode. One way to do this is to add |
149 them and their old values to `enriched-old-bindings'." | 148 them and their old values to `enriched-old-bindings'." |
152 | 151 |
153 (defvar enriched-old-bindings nil | 152 (defvar enriched-old-bindings nil |
154 "Store old variable values that we change when entering mode. | 153 "Store old variable values that we change when entering mode. |
155 The value is a list of \(VAR VALUE VAR VALUE...).") | 154 The value is a list of \(VAR VALUE VAR VALUE...).") |
156 (make-variable-buffer-local 'enriched-old-bindings) | 155 (make-variable-buffer-local 'enriched-old-bindings) |
156 | |
157 ;; Technical internal variable. Bound to t if `enriched-mode' is | |
158 ;; being rerun by a major mode to allow it to restore buffer-local | |
159 ;; variables and to correctly update `enriched-old-bindings'. | |
160 (defvar enriched-rerun-flag nil) | |
157 | 161 |
158 ;;; | 162 ;;; |
159 ;;; Define the mode | 163 ;;; Define the mode |
160 ;;; | 164 ;;; |
161 | 165 |
179 (setq buffer-file-format (delq 'text/enriched buffer-file-format)) | 183 (setq buffer-file-format (delq 'text/enriched buffer-file-format)) |
180 ;; restore old variable values | 184 ;; restore old variable values |
181 (while enriched-old-bindings | 185 (while enriched-old-bindings |
182 (set (pop enriched-old-bindings) (pop enriched-old-bindings)))) | 186 (set (pop enriched-old-bindings) (pop enriched-old-bindings)))) |
183 | 187 |
184 ((memq 'text/enriched buffer-file-format) | 188 ((and (memq 'text/enriched buffer-file-format) |
189 (not enriched-rerun-flag)) | |
185 ;; Mode already on; do nothing. | 190 ;; Mode already on; do nothing. |
186 nil) | 191 nil) |
187 | 192 |
188 (t ; Turn mode on | 193 (t ; Turn mode on |
189 (push 'text/enriched buffer-file-format) | 194 (add-to-list 'buffer-file-format 'text/enriched) |
190 ;; Save old variable values before we change them. | 195 ;; Save old variable values before we change them. |
191 ;; These will be restored if we exit Enriched mode. | 196 ;; These will be restored if we exit Enriched mode. |
192 (setq enriched-old-bindings | 197 (setq enriched-old-bindings |
193 (list 'buffer-display-table buffer-display-table | 198 (list 'buffer-display-table buffer-display-table |
194 'indent-line-function indent-line-function | |
195 'default-text-properties default-text-properties)) | 199 'default-text-properties default-text-properties)) |
196 (make-local-variable 'indent-line-function) | |
197 (make-local-variable 'default-text-properties) | 200 (make-local-variable 'default-text-properties) |
198 (setq indent-line-function 'indent-to-left-margin ;WHY?? -sm | 201 (setq buffer-display-table enriched-display-table) |
199 buffer-display-table enriched-display-table) | 202 (use-hard-newlines 1 (if enriched-rerun-flag 'never nil)) |
200 (use-hard-newlines 1 nil) | |
201 (let ((sticky (plist-get default-text-properties 'front-sticky)) | 203 (let ((sticky (plist-get default-text-properties 'front-sticky)) |
202 (p enriched-par-props)) | 204 (p enriched-par-props)) |
203 (dolist (x p) | 205 (dolist (x p) |
204 (add-to-list 'sticky x)) | 206 (add-to-list 'sticky x)) |
205 (if sticky | 207 (if sticky |
206 (setq default-text-properties | 208 (setq default-text-properties |
207 (plist-put default-text-properties | 209 (plist-put default-text-properties |
208 'front-sticky sticky))))))) | 210 'front-sticky sticky))))))) |
211 | |
212 (defun enriched-before-change-major-mode () | |
213 (when enriched-mode | |
214 (while enriched-old-bindings | |
215 (set (pop enriched-old-bindings) (pop enriched-old-bindings))))) | |
216 | |
217 (add-hook 'change-major-mode-hook 'enriched-before-change-major-mode) | |
218 | |
219 (defun enriched-after-change-major-mode () | |
220 (when enriched-mode | |
221 (let ((enriched-rerun-flag t)) | |
222 (enriched-mode 1)))) | |
223 | |
224 (add-hook 'after-change-major-mode-hook 'enriched-after-change-major-mode) | |
209 | 225 |
210 ;;; | 226 ;;; |
211 ;;; Keybindings | 227 ;;; Keybindings |
212 ;;; | 228 ;;; |
213 | 229 |