Mercurial > emacs
annotate lisp/enriched.el @ 41301:f13ec83c07b9
Doc fix.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Mon, 19 Nov 2001 23:44:14 +0000 |
parents | 7f616838d931 |
children | d03985d6f325 |
rev | line source |
---|---|
13337 | 1 ;;; enriched.el --- read and save files in text/enriched format |
14169 | 2 |
16022
ac3fea1b270e
Add 1996 to copyright notice.
Richard M. Stallman <rms@gnu.org>
parents:
16021
diff
changeset
|
3 ;; Copyright (c) 1994, 1995, 1996 Free Software Foundation, Inc. |
9676 | 4 |
25278 | 5 ;; Author: Boris Goldowsky <boris@gnu.org> |
9676 | 6 ;; Keywords: wp, faces |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it 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. | |
14169 | 14 |
9676 | 15 ;; GNU Emacs is distributed in the hope that it will be useful, |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
14169 | 19 |
9676 | 20 ;; You should have received a copy of the GNU General Public License |
14169 | 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
9676 | 24 |
25 ;;; Commentary: | |
14169 | 26 |
9676 | 27 ;; This file implements reading, editing, and saving files with |
14169 | 28 ;; text-properties such as faces, levels of indentation, and true line |
29 ;; breaks distinguished from newlines just used to fit text into the window. | |
30 | |
9676 | 31 ;; The file format used is the MIME text/enriched format, which is a |
14169 | 32 ;; standard format defined in internet RFC 1563. All standard annotations |
33 ;; are supported except for <smaller> and <bigger>, which are currently not | |
9676 | 34 ;; possible to display. |
14169 | 35 |
9676 | 36 ;; A separate file, enriched.doc, contains further documentation and other |
14169 | 37 ;; important information about this code. It also serves as an example |
38 ;; file in text/enriched format. It should be in the etc directory of your | |
39 ;; emacs distribution. | |
40 | |
41 ;;; Code: | |
9676 | 42 |
43 (provide 'enriched) | |
44 | |
45 ;;; | |
46 ;;; Variables controlling the display | |
47 ;;; | |
48 | |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17207
diff
changeset
|
49 (defgroup enriched nil |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17207
diff
changeset
|
50 "Read and save files in text/enriched format" |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17207
diff
changeset
|
51 :group 'wp) |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17207
diff
changeset
|
52 |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17207
diff
changeset
|
53 (defcustom enriched-verbose t |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17207
diff
changeset
|
54 "*If non-nil, give status messages when reading and writing files." |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17207
diff
changeset
|
55 :type 'boolean |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17207
diff
changeset
|
56 :group 'enriched) |
9676 | 57 |
58 ;;; | |
59 ;;; Set up faces & display table | |
60 ;;; | |
61 | |
18898
fa6d68fd97b1
(fixed, excerpt): Define with defface. No longer
Richard M. Stallman <rms@gnu.org>
parents:
17426
diff
changeset
|
62 ;; Emacs doesn't have a "fixed" face by default, since all faces currently |
fa6d68fd97b1
(fixed, excerpt): Define with defface. No longer
Richard M. Stallman <rms@gnu.org>
parents:
17426
diff
changeset
|
63 ;; have to be fixed-width. So we just pick one that looks different from the |
fa6d68fd97b1
(fixed, excerpt): Define with defface. No longer
Richard M. Stallman <rms@gnu.org>
parents:
17426
diff
changeset
|
64 ;; default. |
fa6d68fd97b1
(fixed, excerpt): Define with defface. No longer
Richard M. Stallman <rms@gnu.org>
parents:
17426
diff
changeset
|
65 (defface fixed |
fa6d68fd97b1
(fixed, excerpt): Define with defface. No longer
Richard M. Stallman <rms@gnu.org>
parents:
17426
diff
changeset
|
66 '((t (:bold t))) |
fa6d68fd97b1
(fixed, excerpt): Define with defface. No longer
Richard M. Stallman <rms@gnu.org>
parents:
17426
diff
changeset
|
67 "Face used for text that must be shown in fixed width. |
fa6d68fd97b1
(fixed, excerpt): Define with defface. No longer
Richard M. Stallman <rms@gnu.org>
parents:
17426
diff
changeset
|
68 Currently, emacs can only display fixed-width fonts, but this may change. |
fa6d68fd97b1
(fixed, excerpt): Define with defface. No longer
Richard M. Stallman <rms@gnu.org>
parents:
17426
diff
changeset
|
69 This face is used for text specifically marked as fixed-width, for example |
fa6d68fd97b1
(fixed, excerpt): Define with defface. No longer
Richard M. Stallman <rms@gnu.org>
parents:
17426
diff
changeset
|
70 in text/enriched files." |
fa6d68fd97b1
(fixed, excerpt): Define with defface. No longer
Richard M. Stallman <rms@gnu.org>
parents:
17426
diff
changeset
|
71 :group 'enriched) |
fa6d68fd97b1
(fixed, excerpt): Define with defface. No longer
Richard M. Stallman <rms@gnu.org>
parents:
17426
diff
changeset
|
72 |
fa6d68fd97b1
(fixed, excerpt): Define with defface. No longer
Richard M. Stallman <rms@gnu.org>
parents:
17426
diff
changeset
|
73 (defface excerpt |
fa6d68fd97b1
(fixed, excerpt): Define with defface. No longer
Richard M. Stallman <rms@gnu.org>
parents:
17426
diff
changeset
|
74 '((t (:italic t))) |
fa6d68fd97b1
(fixed, excerpt): Define with defface. No longer
Richard M. Stallman <rms@gnu.org>
parents:
17426
diff
changeset
|
75 "Face used for text that is an excerpt from another document. |
fa6d68fd97b1
(fixed, excerpt): Define with defface. No longer
Richard M. Stallman <rms@gnu.org>
parents:
17426
diff
changeset
|
76 This is used in enriched-mode for text explicitly marked as an excerpt." |
fa6d68fd97b1
(fixed, excerpt): Define with defface. No longer
Richard M. Stallman <rms@gnu.org>
parents:
17426
diff
changeset
|
77 :group 'enriched) |
9676 | 78 |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
79 (defconst enriched-display-table (or (copy-sequence standard-display-table) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
80 (make-display-table))) |
9676 | 81 (aset enriched-display-table ?\f (make-vector (1- (frame-width)) ?-)) |
82 | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
83 (defconst enriched-par-props '(left-margin right-margin justification) |
9676 | 84 "Text-properties that usually apply to whole paragraphs. |
85 These are set front-sticky everywhere except at hard newlines.") | |
86 | |
87 ;;; | |
88 ;;; Variables controlling the file format | |
89 ;;; (bidirectional) | |
90 | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
91 (defconst enriched-initial-annotation |
9676 | 92 (lambda () |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
93 (format "Content-Type: text/enriched\nText-Width: %d\n\n" |
16021
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
94 fill-column)) |
9676 | 95 "What to insert at the start of a text/enriched file. |
96 If this is a string, it is inserted. If it is a list, it should be a lambda | |
97 expression, which is evaluated to get the string to insert.") | |
98 | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
99 (defconst enriched-annotation-format "<%s%s>" |
9676 | 100 "General format of enriched-text annotations.") |
101 | |
30925
a97dcc26018d
(enriched-annotation-regexp): Use `A-Z' instead
Gerd Moellmann <gerd@gnu.org>
parents:
30456
diff
changeset
|
102 (defconst enriched-annotation-regexp "<\\(/\\)?\\([-A-Za-z0-9]+\\)>" |
9676 | 103 "Regular expression matching enriched-text annotations.") |
104 | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
105 (defconst enriched-translations |
9676 | 106 '((face (bold-italic "bold" "italic") |
107 (bold "bold") | |
108 (italic "italic") | |
109 (underline "underline") | |
110 (fixed "fixed") | |
111 (excerpt "excerpt") | |
112 (default ) | |
113 (nil enriched-encode-other-face)) | |
114 (left-margin (4 "indent")) | |
115 (right-margin (4 "indentright")) | |
116 (justification (none "nofill") | |
117 (right "flushright") | |
118 (left "flushleft") | |
10519
66c7e651194d
(enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents:
9694
diff
changeset
|
119 (full "flushboth") |
9676 | 120 (center "center")) |
121 (PARAMETER (t "param")) ; Argument of preceding annotation | |
122 ;; The following are not part of the standard: | |
123 (FUNCTION (enriched-decode-foreground "x-color") | |
24989
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
124 (enriched-decode-background "x-bg-color") |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
125 (enriched-decode-display-prop "x-display")) |
9676 | 126 (read-only (t "x-read-only")) |
24989
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
127 (display (nil enriched-handle-display-prop)) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
128 (unknown (nil format-annotate-value)) |
9676 | 129 ; (font-size (2 "bigger") ; unimplemented |
130 ; (-2 "smaller")) | |
131 ) | |
132 "List of definitions of text/enriched annotations. | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
133 See `format-annotate-region' and `format-deannotate-region' for the definition |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
134 of this structure.") |
9676 | 135 |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
136 (defconst enriched-ignore |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
137 '(front-sticky rear-nonsticky hard) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
138 "Properties that are OK to ignore when saving text/enriched files. |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
139 Any property that is neither on this list nor dealt with by |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
140 `enriched-translations' will generate a warning.") |
9676 | 141 |
142 ;;; Internal variables | |
143 | |
144 (defvar enriched-mode nil | |
15239 | 145 "True if Enriched mode is in use.") |
9676 | 146 (make-variable-buffer-local 'enriched-mode) |
24466
7f92e74313e7
(enriched-mode): Make var permanent-local.
Karl Heuer <kwzh@gnu.org>
parents:
19685
diff
changeset
|
147 (put 'enriched-mode 'permanent-local t) |
9676 | 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 | |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17207
diff
changeset
|
154 (defcustom enriched-mode-hook nil |
15239 | 155 "Functions to run when entering Enriched mode. |
9676 | 156 If you set variables in this hook, you should arrange for them to be restored |
15239 | 157 to their old values if you leave Enriched mode. One way to do this is to add |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17207
diff
changeset
|
158 them and their old values to `enriched-old-bindings'." |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17207
diff
changeset
|
159 :type 'hook |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17207
diff
changeset
|
160 :group 'enriched) |
9676 | 161 |
162 (defvar enriched-old-bindings nil | |
163 "Store old variable values that we change when entering mode. | |
164 The value is a list of \(VAR VALUE VAR VALUE...).") | |
165 (make-variable-buffer-local 'enriched-old-bindings) | |
166 | |
167 ;;; | |
168 ;;; Define the mode | |
169 ;;; | |
170 | |
9694
f8aa9230c3fa
(enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents:
9677
diff
changeset
|
171 ;;;###autoload |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
172 (defun enriched-mode (&optional arg) |
9676 | 173 "Minor mode for editing text/enriched files. |
174 These are files with embedded formatting information in the MIME standard | |
175 text/enriched format. | |
15239 | 176 Turning the mode on runs `enriched-mode-hook'. |
9676 | 177 |
15239 | 178 More information about Enriched mode is available in the file |
9676 | 179 etc/enriched.doc in the Emacs distribution directory. |
180 | |
181 Commands: | |
182 | |
183 \\<enriched-mode-map>\\{enriched-mode-map}" | |
184 (interactive "P") | |
185 (let ((mod (buffer-modified-p))) | |
186 (cond ((or (<= (prefix-numeric-value arg) 0) | |
187 (and enriched-mode (null arg))) | |
188 ;; Turn mode off | |
189 (setq enriched-mode nil) | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
190 (setq buffer-file-format (delq 'text/enriched buffer-file-format)) |
9676 | 191 ;; restore old variable values |
192 (while enriched-old-bindings | |
193 (funcall 'set (car enriched-old-bindings) | |
194 (car (cdr enriched-old-bindings))) | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
195 (setq enriched-old-bindings (cdr (cdr enriched-old-bindings))))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
196 |
9676 | 197 (enriched-mode nil) ; Mode already on; do nothing. |
198 | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
199 (t (setq enriched-mode t) ; Turn mode on |
16021
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
200 (add-to-list 'buffer-file-format 'text/enriched) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
201 ;; Save old variable values before we change them. |
15239 | 202 ;; These will be restored if we exit Enriched mode. |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
203 (setq enriched-old-bindings |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
204 (list 'buffer-display-table buffer-display-table |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
205 'indent-line-function indent-line-function |
11129
2ce4b0aac50c
(enriched-mode): Use new plist-put and plist-get fns,
Boris Goldowsky <boris@gnu.org>
parents:
11055
diff
changeset
|
206 'default-text-properties default-text-properties)) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
207 (make-local-variable 'indent-line-function) |
11129
2ce4b0aac50c
(enriched-mode): Use new plist-put and plist-get fns,
Boris Goldowsky <boris@gnu.org>
parents:
11055
diff
changeset
|
208 (make-local-variable 'default-text-properties) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
209 (setq indent-line-function 'indent-to-left-margin |
16021
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
210 buffer-display-table enriched-display-table) |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
211 (use-hard-newlines 1 nil) |
11129
2ce4b0aac50c
(enriched-mode): Use new plist-put and plist-get fns,
Boris Goldowsky <boris@gnu.org>
parents:
11055
diff
changeset
|
212 (let ((sticky (plist-get default-text-properties 'front-sticky)) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
213 (p enriched-par-props)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
214 (while p |
16021
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
215 (add-to-list 'sticky (car p)) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
216 (setq p (cdr p))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
217 (if sticky |
11129
2ce4b0aac50c
(enriched-mode): Use new plist-put and plist-get fns,
Boris Goldowsky <boris@gnu.org>
parents:
11055
diff
changeset
|
218 (setq default-text-properties |
2ce4b0aac50c
(enriched-mode): Use new plist-put and plist-get fns,
Boris Goldowsky <boris@gnu.org>
parents:
11055
diff
changeset
|
219 (plist-put default-text-properties |
2ce4b0aac50c
(enriched-mode): Use new plist-put and plist-get fns,
Boris Goldowsky <boris@gnu.org>
parents:
11055
diff
changeset
|
220 'front-sticky sticky)))) |
15239 | 221 (run-hooks 'enriched-mode-hook))) |
9676 | 222 (set-buffer-modified-p mod) |
223 (force-mode-line-update))) | |
224 | |
225 ;;; | |
226 ;;; Keybindings | |
227 ;;; | |
228 | |
229 (defvar enriched-mode-map nil | |
15239 | 230 "Keymap for Enriched mode.") |
9676 | 231 |
232 (if (null enriched-mode-map) | |
233 (fset 'enriched-mode-map (setq enriched-mode-map (make-sparse-keymap)))) | |
234 | |
235 (if (not (assq 'enriched-mode minor-mode-map-alist)) | |
236 (setq minor-mode-map-alist | |
237 (cons (cons 'enriched-mode enriched-mode-map) | |
238 minor-mode-map-alist))) | |
239 | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
240 (define-key enriched-mode-map "\C-a" 'beginning-of-line-text) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
241 (define-key enriched-mode-map "\C-m" 'reindent-then-newline-and-indent) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
242 (define-key enriched-mode-map "\C-j" 'reindent-then-newline-and-indent) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
243 (define-key enriched-mode-map "\M-j" 'facemenu-justification-menu) |
10519
66c7e651194d
(enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents:
9694
diff
changeset
|
244 (define-key enriched-mode-map "\M-S" 'set-justification-center) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
245 (define-key enriched-mode-map "\C-x\t" 'increase-left-margin) |
10519
66c7e651194d
(enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents:
9694
diff
changeset
|
246 (define-key enriched-mode-map "\C-c\C-l" 'set-left-margin) |
66c7e651194d
(enriched-annotation-list): property `hard-newline'
Richard M. Stallman <rms@gnu.org>
parents:
9694
diff
changeset
|
247 (define-key enriched-mode-map "\C-c\C-r" 'set-right-margin) |
9676 | 248 |
249 ;;; | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
250 ;;; Some functions dealing with text-properties, especially indentation |
9676 | 251 ;;; |
252 | |
253 (defun enriched-map-property-regions (prop func &optional from to) | |
254 "Apply a function to regions of the buffer based on a text property. | |
255 For each contiguous region of the buffer for which the value of PROPERTY is | |
256 eq, the FUNCTION will be called. Optional arguments FROM and TO specify the | |
257 region over which to scan. | |
258 | |
259 The specified function receives three arguments: the VALUE of the property in | |
260 the region, and the START and END of each region." | |
261 (save-excursion | |
262 (save-restriction | |
263 (if to (narrow-to-region (point-min) to)) | |
264 (goto-char (or from (point-min))) | |
265 (let ((begin (point)) | |
266 end | |
267 (marker (make-marker)) | |
268 (val (get-text-property (point) prop))) | |
269 (while (setq end (text-property-not-all begin (point-max) prop val)) | |
270 (move-marker marker end) | |
271 (funcall func val begin (marker-position marker)) | |
272 (setq begin (marker-position marker) | |
273 val (get-text-property marker prop))) | |
274 (if (< begin (point-max)) | |
275 (funcall func val begin (point-max))))))) | |
276 | |
277 (put 'enriched-map-property-regions 'lisp-indent-hook 1) | |
278 | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
279 (defun enriched-insert-indentation (&optional from to) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
280 "Indent and justify each line in the region." |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
281 (save-excursion |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
282 (save-restriction |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
283 (if to (narrow-to-region (point-min) to)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
284 (goto-char (or from (point-min))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
285 (if (not (bolp)) (forward-line 1)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
286 (while (not (eobp)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
287 (if (eolp) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
288 nil ; skip blank lines |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
289 (indent-to (current-left-margin)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
290 (justify-current-line t nil t)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
291 (forward-line 1))))) |
9676 | 292 |
293 ;;; | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
294 ;;; Encoding Files |
9676 | 295 ;;; |
296 | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
297 ;;;###autoload |
16021
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
298 (defun enriched-encode (from to orig-buf) |
9676 | 299 (if enriched-verbose (message "Enriched: encoding document...")) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
300 (save-restriction |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
301 (narrow-to-region from to) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
302 (delete-to-left-margin) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
303 (unjustify-region) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
304 (goto-char from) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
305 (format-replace-strings '(("<" . "<<"))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
306 (format-insert-annotations |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
307 (format-annotate-region from (point-max) enriched-translations |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
308 'enriched-make-annotation enriched-ignore)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
309 (goto-char from) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
310 (insert (if (stringp enriched-initial-annotation) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
311 enriched-initial-annotation |
16021
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
312 (save-excursion |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
313 ;; Eval this in the buffer we are annotating. This |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
314 ;; fixes a bug which was saving incorrect File-Width |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
315 ;; information, since we were looking at local |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
316 ;; variables in the wrong buffer. |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
317 (if orig-buf (set-buffer orig-buf)) |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
318 (funcall enriched-initial-annotation)))) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
319 (enriched-map-property-regions 'hard |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
320 (lambda (v b e) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
321 (if (and v (= ?\n (char-after b))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
322 (progn (goto-char b) (insert "\n")))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
323 (point) nil) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
324 (if enriched-verbose (message nil)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
325 ;; Return new end. |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
326 (point-max))) |
9676 | 327 |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
328 (defun enriched-make-annotation (name positive) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
329 "Format an annotation called NAME. |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
330 If POSITIVE is non-nil, this is the opening annotation, if nil, this is the |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
331 matching close." |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
332 (cond ((stringp name) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
333 (format enriched-annotation-format (if positive "" "/") name)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
334 ;; Otherwise it is an annotation with parameters, represented as a list |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
335 (positive |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
336 (let ((item (car name)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
337 (params (cdr name))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
338 (concat (format enriched-annotation-format "" item) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
339 (mapconcat (lambda (i) (concat "<param>" i "</param>")) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
340 params "")))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
341 (t (format enriched-annotation-format "/" (car name))))) |
9676 | 342 |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
343 (defun enriched-encode-other-face (old new) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
344 "Generate annotations for random face change. |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
345 One annotation each for foreground color, background color, italic, etc." |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
346 (cons (and old (enriched-face-ans old)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
347 (and new (enriched-face-ans new)))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
348 |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
349 (defun enriched-face-ans (face) |
40516
7f616838d931
(enriched-face-ans): FIx previous change.
Richard M. Stallman <rms@gnu.org>
parents:
40442
diff
changeset
|
350 "Return annotations specifying FACE. |
7f616838d931
(enriched-face-ans): FIx previous change.
Richard M. Stallman <rms@gnu.org>
parents:
40442
diff
changeset
|
351 FACE may be a list of faces instead of a single face; |
7f616838d931
(enriched-face-ans): FIx previous change.
Richard M. Stallman <rms@gnu.org>
parents:
40442
diff
changeset
|
352 it can also be anything allowed as an element of a list |
7f616838d931
(enriched-face-ans): FIx previous change.
Richard M. Stallman <rms@gnu.org>
parents:
40442
diff
changeset
|
353 which can be the value of the `face' text property." |
27792
de64340fea42
(enriched-face-ans): Handle '(foreground-color
Gerd Moellmann <gerd@gnu.org>
parents:
25278
diff
changeset
|
354 (cond ((and (consp face) (eq (car face) 'foreground-color)) |
30456
597562b7a8c6
(enriched-face-ans): For a `foreground-color'
Gerd Moellmann <gerd@gnu.org>
parents:
29765
diff
changeset
|
355 (list (list "x-color" (cdr face)))) |
27792
de64340fea42
(enriched-face-ans): Handle '(foreground-color
Gerd Moellmann <gerd@gnu.org>
parents:
25278
diff
changeset
|
356 ((and (consp face) (eq (car face) 'background-color)) |
30456
597562b7a8c6
(enriched-face-ans): For a `foreground-color'
Gerd Moellmann <gerd@gnu.org>
parents:
29765
diff
changeset
|
357 (list (list "x-bg-color" (cdr face)))) |
40516
7f616838d931
(enriched-face-ans): FIx previous change.
Richard M. Stallman <rms@gnu.org>
parents:
40442
diff
changeset
|
358 ((listp face) |
7f616838d931
(enriched-face-ans): FIx previous change.
Richard M. Stallman <rms@gnu.org>
parents:
40442
diff
changeset
|
359 (apply 'append (mapcar 'enriched-face-ans face))) |
27792
de64340fea42
(enriched-face-ans): Handle '(foreground-color
Gerd Moellmann <gerd@gnu.org>
parents:
25278
diff
changeset
|
360 ((string-match "^fg:" (symbol-name face)) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
361 (list (list "x-color" (substring (symbol-name face) 3)))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
362 ((string-match "^bg:" (symbol-name face)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
363 (list (list "x-bg-color" (substring (symbol-name face) 3)))) |
34020
43839f6e2822
(enriched-face-ans): Use face-attribute instead
Gerd Moellmann <gerd@gnu.org>
parents:
30925
diff
changeset
|
364 ((let* ((fg (face-attribute face :foreground)) |
43839f6e2822
(enriched-face-ans): Use face-attribute instead
Gerd Moellmann <gerd@gnu.org>
parents:
30925
diff
changeset
|
365 (bg (face-attribute face :background)) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
366 (props (face-font face t)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
367 (ans (cdr (format-annotate-single-property-change |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
368 'face nil props enriched-translations)))) |
30456
597562b7a8c6
(enriched-face-ans): For a `foreground-color'
Gerd Moellmann <gerd@gnu.org>
parents:
29765
diff
changeset
|
369 (unless (eq fg 'unspecified) |
597562b7a8c6
(enriched-face-ans): For a `foreground-color'
Gerd Moellmann <gerd@gnu.org>
parents:
29765
diff
changeset
|
370 (setq ans (cons (list "x-color" fg) ans))) |
597562b7a8c6
(enriched-face-ans): For a `foreground-color'
Gerd Moellmann <gerd@gnu.org>
parents:
29765
diff
changeset
|
371 (unless (eq bg 'unspecified) |
597562b7a8c6
(enriched-face-ans): For a `foreground-color'
Gerd Moellmann <gerd@gnu.org>
parents:
29765
diff
changeset
|
372 (setq ans (cons (list "x-bg-color" bg) ans))) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
373 ans)))) |
9676 | 374 |
375 ;;; | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
376 ;;; Decoding files |
9676 | 377 ;;; |
378 | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
379 ;;;###autoload |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
380 (defun enriched-decode (from to) |
9676 | 381 (if enriched-verbose (message "Enriched: decoding document...")) |
16021
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
382 (use-hard-newlines 1 'never) |
9676 | 383 (save-excursion |
384 (save-restriction | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
385 (narrow-to-region from to) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
386 (goto-char from) |
16021
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
387 |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
388 ;; Deal with header |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
389 (let ((file-width (enriched-get-file-width))) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
390 (enriched-remove-header) |
9676 | 391 |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
392 ;; Deal with newlines |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
393 (while (search-forward-regexp "\n\n+" nil t) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
394 (if (current-justification) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
395 (delete-char -1)) |
16021
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
396 (set-hard-newline-properties (match-beginning 0) (point))) |
9676 | 397 |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
398 ;; Translate annotations |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
399 (format-deannotate-region from (point-max) enriched-translations |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
400 'enriched-next-annotation) |
9676 | 401 |
16021
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
402 ;; Indent or fill the buffer |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
403 (cond (file-width ; File was filled to this width |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
404 (setq fill-column file-width) |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
405 (if enriched-verbose (message "Indenting...")) |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
406 (enriched-insert-indentation)) |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
407 (t ; File was not filled. |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
408 (if enriched-verbose (message "Filling paragraphs...")) |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
409 (fill-region (point-min) (point-max)))) |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
410 (if enriched-verbose (message nil))) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
411 (point-max)))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
412 |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
413 (defun enriched-next-annotation () |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
414 "Find and return next text/enriched annotation. |
13488
71c747dc59ca
(enriched-next-annotation): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
13337
diff
changeset
|
415 Any \"<<\" strings encountered are converted to \"<\". |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
416 Return value is \(begin end name positive-p), or nil if none was found." |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
417 (while (and (search-forward "<" nil 1) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
418 (progn (goto-char (match-beginning 0)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
419 (not (looking-at enriched-annotation-regexp)))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
420 (forward-char 1) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
421 (if (= ?< (char-after (point))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
422 (delete-char 1) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
423 ;; A single < that does not start an annotation is an error, |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
424 ;; which we note and then ignore. |
14340
bf1d862f3673
(enriched-next-annotation): Delete format call inside message.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
425 (message "Warning: malformed annotation in file at %s" |
bf1d862f3673
(enriched-next-annotation): Delete format call inside message.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
426 (1- (point))))) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
427 (if (not (eobp)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
428 (let* ((beg (match-beginning 0)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
429 (end (match-end 0)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
430 (name (downcase (buffer-substring |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
431 (match-beginning 2) (match-end 2)))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
432 (pos (not (match-beginning 1)))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
433 (list beg end name pos)))) |
9676 | 434 |
435 (defun enriched-get-file-width () | |
436 "Look for file width information on this line." | |
437 (save-excursion | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
438 (if (search-forward "Text-Width: " (+ (point) 1000) t) |
9676 | 439 (read (current-buffer))))) |
440 | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
441 (defun enriched-remove-header () |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
442 "Remove file-format header at point." |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
443 (while (looking-at "^[-A-Za-z]+: .*\n") |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
444 (delete-region (point) (match-end 0))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
445 (if (looking-at "^\n") |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
446 (delete-char 1))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
447 |
17207
2d0b382efa26
(enriched-decode-foreground, enriched-decode-background):
Richard M. Stallman <rms@gnu.org>
parents:
16022
diff
changeset
|
448 (defun enriched-decode-foreground (from to &optional color) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
449 (let ((face (intern (concat "fg:" color)))) |
17207
2d0b382efa26
(enriched-decode-foreground, enriched-decode-background):
Richard M. Stallman <rms@gnu.org>
parents:
16022
diff
changeset
|
450 (cond ((null color) |
2d0b382efa26
(enriched-decode-foreground, enriched-decode-background):
Richard M. Stallman <rms@gnu.org>
parents:
16022
diff
changeset
|
451 (message "Warning: no color specified for <x-color>")) |
29765
2ec1f9510791
(enriched-decode-foreground, enriched-decode-background): Don't use
Dave Love <fx@gnu.org>
parents:
28110
diff
changeset
|
452 ((facep face)) |
28110
7f4fe6e367dc
(enriched-decode-foreground): Use display-color-p.
Dave Love <fx@gnu.org>
parents:
27792
diff
changeset
|
453 ((and (display-color-p) (facemenu-get-face face))) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
454 ((make-face face) |
17207
2d0b382efa26
(enriched-decode-foreground, enriched-decode-background):
Richard M. Stallman <rms@gnu.org>
parents:
16022
diff
changeset
|
455 (message "Warning: color `%s' can't be displayed" color))) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
456 (list from to 'face face))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
457 |
17207
2d0b382efa26
(enriched-decode-foreground, enriched-decode-background):
Richard M. Stallman <rms@gnu.org>
parents:
16022
diff
changeset
|
458 (defun enriched-decode-background (from to &optional color) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
459 (let ((face (intern (concat "bg:" color)))) |
17207
2d0b382efa26
(enriched-decode-foreground, enriched-decode-background):
Richard M. Stallman <rms@gnu.org>
parents:
16022
diff
changeset
|
460 (cond ((null color) |
2d0b382efa26
(enriched-decode-foreground, enriched-decode-background):
Richard M. Stallman <rms@gnu.org>
parents:
16022
diff
changeset
|
461 (message "Warning: no color specified for <x-bg-color>")) |
29765
2ec1f9510791
(enriched-decode-foreground, enriched-decode-background): Don't use
Dave Love <fx@gnu.org>
parents:
28110
diff
changeset
|
462 ((facep face)) |
28110
7f4fe6e367dc
(enriched-decode-foreground): Use display-color-p.
Dave Love <fx@gnu.org>
parents:
27792
diff
changeset
|
463 ((and (display-color-p) (facemenu-get-face face))) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
464 ((make-face face) |
17207
2d0b382efa26
(enriched-decode-foreground, enriched-decode-background):
Richard M. Stallman <rms@gnu.org>
parents:
16022
diff
changeset
|
465 (message "Warning: color `%s' can't be displayed" color))) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
466 (list from to 'face face))) |
9676 | 467 |
24989
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
468 |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
469 |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
470 ;;; Handling the `display' property. |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
471 |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
472 |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
473 (defun enriched-handle-display-prop (old new) |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
474 "Return a list of annotations for a change in the `display' property. |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
475 OLD is the old value of the property, NEW is the new value. Value |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
476 is a list `(CLOSE OPEN)', where CLOSE is a list of annotations to |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
477 close and OPEN a list of annotations to open. Each of these lists |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
478 has the form `(ANNOTATION PARAM ...)'." |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
479 (let ((annotation "x-display") |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
480 (param (prin1-to-string (or old new))) |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
481 close open) |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
482 (if (null old) |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
483 (list nil (list annotation param)) |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
484 (list (list annotation param))))) |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
485 |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
486 |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
487 (defun enriched-decode-display-prop (start end &optional param) |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
488 "Decode a `display' property for text between START and END. |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
489 PARAM is a `<param>' found for the property. |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
490 Value is a list `(START END SYMBOL VALUE)' with START and END denoting |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
491 the range of text to assign text property SYMBOL with value VALUE " |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
492 (let ((prop (when (stringp param) |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
493 (condition-case () |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
494 (car (read-from-string param)) |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
495 (error nil))))) |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
496 (unless prop |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
497 (message "Warning: invalid <x-display> parameter %s" param)) |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
498 (list start end 'display prop))) |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
499 |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
500 |
9676 | 501 ;;; enriched.el ends here |