1 |
;;; enriched.el --- read and save files in text/enriched format |
;;; enriched.el --- read and save files in text/enriched format |
2 |
|
|
3 |
;; Copyright (c) 1994, 1995, 1996, 2002 Free Software Foundation, Inc. |
;; Copyright (c) 1994, 1995, 1996, 2002, 2004 Free Software Foundation, Inc. |
4 |
|
|
5 |
;; Author: Boris Goldowsky <boris@gnu.org> |
;; Author: Boris Goldowsky <boris@gnu.org> |
6 |
;; Keywords: wp, faces |
;; Keywords: wp, faces |
141 |
|
|
142 |
;;; Internal variables |
;;; Internal variables |
143 |
|
|
|
|
|
144 |
(defcustom enriched-mode-hook nil |
(defcustom enriched-mode-hook nil |
145 |
"Hook run after entering/leaving Enriched mode. |
"Hook run after entering/leaving Enriched mode. |
146 |
If you set variables in this hook, you should arrange for them to be restored |
If you set variables in this hook, you should arrange for them to be restored |
154 |
The value is a list of \(VAR VALUE VAR VALUE...).") |
The value is a list of \(VAR VALUE VAR VALUE...).") |
155 |
(make-variable-buffer-local 'enriched-old-bindings) |
(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) |
161 |
|
|
162 |
;;; |
;;; |
163 |
;;; Define the mode |
;;; Define the mode |
164 |
;;; |
;;; |
185 |
(while enriched-old-bindings |
(while enriched-old-bindings |
186 |
(set (pop enriched-old-bindings) (pop enriched-old-bindings)))) |
(set (pop enriched-old-bindings) (pop enriched-old-bindings)))) |
187 |
|
|
188 |
((memq 'text/enriched buffer-file-format) |
((and (memq 'text/enriched buffer-file-format) |
189 |
|
(not enriched-rerun-flag)) |
190 |
;; Mode already on; do nothing. |
;; Mode already on; do nothing. |
191 |
nil) |
nil) |
192 |
|
|
193 |
(t ; Turn mode on |
(t ; Turn mode on |
194 |
(push 'text/enriched buffer-file-format) |
(add-to-list 'buffer-file-format 'text/enriched) |
195 |
;; Save old variable values before we change them. |
;; Save old variable values before we change them. |
196 |
;; These will be restored if we exit Enriched mode. |
;; These will be restored if we exit Enriched mode. |
197 |
(setq enriched-old-bindings |
(setq enriched-old-bindings |
198 |
(list 'buffer-display-table buffer-display-table |
(list 'buffer-display-table buffer-display-table |
|
'indent-line-function indent-line-function |
|
199 |
'default-text-properties default-text-properties)) |
'default-text-properties default-text-properties)) |
|
(make-local-variable 'indent-line-function) |
|
200 |
(make-local-variable 'default-text-properties) |
(make-local-variable 'default-text-properties) |
201 |
(setq indent-line-function 'indent-to-left-margin ;WHY?? -sm |
(setq buffer-display-table enriched-display-table) |
202 |
buffer-display-table enriched-display-table) |
(use-hard-newlines 1 (if enriched-rerun-flag 'never nil)) |
|
(use-hard-newlines 1 nil) |
|
203 |
(let ((sticky (plist-get default-text-properties 'front-sticky)) |
(let ((sticky (plist-get default-text-properties 'front-sticky)) |
204 |
(p enriched-par-props)) |
(p enriched-par-props)) |
205 |
(dolist (x p) |
(dolist (x p) |
209 |
(plist-put default-text-properties |
(plist-put default-text-properties |
210 |
'front-sticky sticky))))))) |
'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) |
225 |
|
|
226 |
;;; |
;;; |
227 |
;;; Keybindings |
;;; Keybindings |
228 |
;;; |
;;; |