Mercurial > emacs
annotate lisp/enriched.el @ 49576:873d790b25eb
*** empty log message ***
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Mon, 03 Feb 2003 16:31:35 +0000 |
parents | c9f374d3e6f3 |
children |
rev | line source |
---|---|
13337 | 1 ;;; enriched.el --- read and save files in text/enriched format |
14169 | 2 |
44146 | 3 ;; Copyright (c) 1994, 1995, 1996, 2002 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 |
42455
7662f312caf2
(various face definitions): Use :weight and :slant.
Richard M. Stallman <rms@gnu.org>
parents:
41759
diff
changeset
|
66 '((t (:weight bold))) |
18898
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 |
42455
7662f312caf2
(various face definitions): Use :weight and :slant.
Richard M. Stallman <rms@gnu.org>
parents:
41759
diff
changeset
|
74 '((t (:slant italic))) |
18898
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. |
41759 | 76 This is used in Enriched mode for text explicitly marked as an excerpt." |
18898
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") |
42458
7be0bbebc00f
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
42455
diff
changeset
|
120 (center "center")) |
9676 | 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 | |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17207
diff
changeset
|
145 (defcustom enriched-mode-hook nil |
41714
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
146 "Hook run after entering/leaving Enriched mode. |
9676 | 147 If you set variables in this hook, you should arrange for them to be restored |
15239 | 148 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
|
149 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
|
150 :type 'hook |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17207
diff
changeset
|
151 :group 'enriched) |
9676 | 152 |
153 (defvar enriched-old-bindings nil | |
154 "Store old variable values that we change when entering mode. | |
155 The value is a list of \(VAR VALUE VAR VALUE...).") | |
156 (make-variable-buffer-local 'enriched-old-bindings) | |
157 | |
158 ;;; | |
159 ;;; Define the mode | |
160 ;;; | |
161 | |
41714
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
162 (put 'enriched-mode 'permanent-local t) |
9694
f8aa9230c3fa
(enriched-mode): Add autoload cookie.
Boris Goldowsky <boris@gnu.org>
parents:
9677
diff
changeset
|
163 ;;;###autoload |
41714
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
164 (define-minor-mode enriched-mode |
9676 | 165 "Minor mode for editing text/enriched files. |
166 These are files with embedded formatting information in the MIME standard | |
167 text/enriched format. | |
15239 | 168 Turning the mode on runs `enriched-mode-hook'. |
9676 | 169 |
42458
7be0bbebc00f
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
42455
diff
changeset
|
170 More information about Enriched mode is available in the file |
41714
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
171 etc/enriched.doc in the Emacs distribution directory. |
9676 | 172 |
173 Commands: | |
174 | |
42479
d9873c0f6418
(enriched-handle-display-prop): Remove unused variables.
Pavel Janík <Pavel@Janik.cz>
parents:
42458
diff
changeset
|
175 \\{enriched-mode-map}" |
41714
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
176 nil " Enriched" nil |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
177 (cond ((null enriched-mode) |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
178 ;; Turn mode off |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
179 (setq buffer-file-format (delq 'text/enriched buffer-file-format)) |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
180 ;; restore old variable values |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
181 (while enriched-old-bindings |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
182 (set (pop enriched-old-bindings) (pop enriched-old-bindings)))) |
42458
7be0bbebc00f
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
42455
diff
changeset
|
183 |
41714
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
184 ((memq 'text/enriched buffer-file-format) |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
185 ;; Mode already on; do nothing. |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
186 nil) |
9676 | 187 |
41714
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
188 (t ; Turn mode on |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
189 (push 'text/enriched buffer-file-format) |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
190 ;; Save old variable values before we change them. |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
191 ;; These will be restored if we exit Enriched mode. |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
192 (setq enriched-old-bindings |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
193 (list 'buffer-display-table buffer-display-table |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
194 'indent-line-function indent-line-function |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
195 'default-text-properties default-text-properties)) |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
196 (make-local-variable 'indent-line-function) |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
197 (make-local-variable 'default-text-properties) |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
198 (setq indent-line-function 'indent-to-left-margin ;WHY?? -sm |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
199 buffer-display-table enriched-display-table) |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
200 (use-hard-newlines 1 nil) |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
201 (let ((sticky (plist-get default-text-properties 'front-sticky)) |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
202 (p enriched-par-props)) |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
203 (dolist (x p) |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
204 (add-to-list 'sticky x)) |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
205 (if sticky |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
206 (setq default-text-properties |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
207 (plist-put default-text-properties |
d03985d6f325
(enriched-mode): Use define-minor-mode. Use dolist and pop and push.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40516
diff
changeset
|
208 'front-sticky sticky))))))) |
9676 | 209 |
210 ;;; | |
211 ;;; Keybindings | |
212 ;;; | |
213 | |
214 (defvar enriched-mode-map nil | |
15239 | 215 "Keymap for Enriched mode.") |
9676 | 216 |
217 (if (null enriched-mode-map) | |
218 (fset 'enriched-mode-map (setq enriched-mode-map (make-sparse-keymap)))) | |
219 | |
220 (if (not (assq 'enriched-mode minor-mode-map-alist)) | |
221 (setq minor-mode-map-alist | |
222 (cons (cons 'enriched-mode enriched-mode-map) | |
223 minor-mode-map-alist))) | |
224 | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
225 (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
|
226 (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
|
227 (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
|
228 (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
|
229 (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
|
230 (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
|
231 (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
|
232 (define-key enriched-mode-map "\C-c\C-r" 'set-right-margin) |
9676 | 233 |
234 ;;; | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
235 ;;; Some functions dealing with text-properties, especially indentation |
9676 | 236 ;;; |
237 | |
238 (defun enriched-map-property-regions (prop func &optional from to) | |
239 "Apply a function to regions of the buffer based on a text property. | |
240 For each contiguous region of the buffer for which the value of PROPERTY is | |
241 eq, the FUNCTION will be called. Optional arguments FROM and TO specify the | |
242 region over which to scan. | |
243 | |
244 The specified function receives three arguments: the VALUE of the property in | |
245 the region, and the START and END of each region." | |
246 (save-excursion | |
247 (save-restriction | |
248 (if to (narrow-to-region (point-min) to)) | |
249 (goto-char (or from (point-min))) | |
250 (let ((begin (point)) | |
251 end | |
252 (marker (make-marker)) | |
253 (val (get-text-property (point) prop))) | |
254 (while (setq end (text-property-not-all begin (point-max) prop val)) | |
255 (move-marker marker end) | |
256 (funcall func val begin (marker-position marker)) | |
257 (setq begin (marker-position marker) | |
258 val (get-text-property marker prop))) | |
259 (if (< begin (point-max)) | |
260 (funcall func val begin (point-max))))))) | |
261 | |
262 (put 'enriched-map-property-regions 'lisp-indent-hook 1) | |
263 | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
264 (defun enriched-insert-indentation (&optional from to) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
265 "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
|
266 (save-excursion |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
267 (save-restriction |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
268 (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
|
269 (goto-char (or from (point-min))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
270 (if (not (bolp)) (forward-line 1)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
271 (while (not (eobp)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
272 (if (eolp) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
273 nil ; skip blank lines |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
274 (indent-to (current-left-margin)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
275 (justify-current-line t nil t)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
276 (forward-line 1))))) |
9676 | 277 |
278 ;;; | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
279 ;;; Encoding Files |
9676 | 280 ;;; |
281 | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
282 ;;;###autoload |
16021
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
283 (defun enriched-encode (from to orig-buf) |
9676 | 284 (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
|
285 (save-restriction |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
286 (narrow-to-region from to) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
287 (delete-to-left-margin) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
288 (unjustify-region) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
289 (goto-char from) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
290 (format-replace-strings '(("<" . "<<"))) |
42458
7be0bbebc00f
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
42455
diff
changeset
|
291 (format-insert-annotations |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
292 (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
|
293 'enriched-make-annotation enriched-ignore)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
294 (goto-char from) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
295 (insert (if (stringp enriched-initial-annotation) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
296 enriched-initial-annotation |
16021
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
297 (save-excursion |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
298 ;; 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
|
299 ;; 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
|
300 ;; 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
|
301 ;; variables in the wrong buffer. |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
302 (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
|
303 (funcall enriched-initial-annotation)))) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
304 (enriched-map-property-regions 'hard |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
305 (lambda (v b e) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
306 (if (and v (= ?\n (char-after b))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
307 (progn (goto-char b) (insert "\n")))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
308 (point) nil) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
309 (if enriched-verbose (message nil)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
310 ;; Return new end. |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
311 (point-max))) |
9676 | 312 |
42545
190c648a9f3e
(enriched-make-annotation): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
42479
diff
changeset
|
313 (defun enriched-make-annotation (internal-ann positive) |
190c648a9f3e
(enriched-make-annotation): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
42479
diff
changeset
|
314 "Format an annotation INTERNAL-ANN. |
190c648a9f3e
(enriched-make-annotation): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
42479
diff
changeset
|
315 INTERNAL-ANN may be a string, for a flag, or a list of the form (PARAM VALUE). |
190c648a9f3e
(enriched-make-annotation): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
42479
diff
changeset
|
316 If POSITIVE is non-nil, this is the opening annotation; |
190c648a9f3e
(enriched-make-annotation): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
42479
diff
changeset
|
317 if nil, the matching close." |
42567
b1eda5349a48
(enriched-make-annotation): Fix the change from 2002-01-05.
Pavel Janík <Pavel@Janik.cz>
parents:
42545
diff
changeset
|
318 (cond ((stringp internal-ann) |
b1eda5349a48
(enriched-make-annotation): Fix the change from 2002-01-05.
Pavel Janík <Pavel@Janik.cz>
parents:
42545
diff
changeset
|
319 (format enriched-annotation-format (if positive "" "/") internal-ann)) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
320 ;; 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
|
321 (positive |
42567
b1eda5349a48
(enriched-make-annotation): Fix the change from 2002-01-05.
Pavel Janík <Pavel@Janik.cz>
parents:
42545
diff
changeset
|
322 (let ((item (car internal-ann)) |
b1eda5349a48
(enriched-make-annotation): Fix the change from 2002-01-05.
Pavel Janík <Pavel@Janik.cz>
parents:
42545
diff
changeset
|
323 (params (cdr internal-ann))) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
324 (concat (format enriched-annotation-format "" item) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
325 (mapconcat (lambda (i) (concat "<param>" i "</param>")) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
326 params "")))) |
42567
b1eda5349a48
(enriched-make-annotation): Fix the change from 2002-01-05.
Pavel Janík <Pavel@Janik.cz>
parents:
42545
diff
changeset
|
327 (t (format enriched-annotation-format "/" (car internal-ann))))) |
9676 | 328 |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
329 (defun enriched-encode-other-face (old new) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
330 "Generate annotations for random face change. |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
331 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
|
332 (cons (and old (enriched-face-ans old)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
333 (and new (enriched-face-ans new)))) |
42458
7be0bbebc00f
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
42455
diff
changeset
|
334 |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
335 (defun enriched-face-ans (face) |
40516
7f616838d931
(enriched-face-ans): FIx previous change.
Richard M. Stallman <rms@gnu.org>
parents:
40442
diff
changeset
|
336 "Return annotations specifying FACE. |
7f616838d931
(enriched-face-ans): FIx previous change.
Richard M. Stallman <rms@gnu.org>
parents:
40442
diff
changeset
|
337 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
|
338 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
|
339 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
|
340 (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
|
341 (list (list "x-color" (cdr face)))) |
27792
de64340fea42
(enriched-face-ans): Handle '(foreground-color
Gerd Moellmann <gerd@gnu.org>
parents:
25278
diff
changeset
|
342 ((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
|
343 (list (list "x-bg-color" (cdr face)))) |
44126
00aef3a1182b
(enriched-face-ans): Support FACE of the form
Eli Zaretskii <eliz@gnu.org>
parents:
42567
diff
changeset
|
344 ((and (listp face) (eq (car face) :foreground)) |
00aef3a1182b
(enriched-face-ans): Support FACE of the form
Eli Zaretskii <eliz@gnu.org>
parents:
42567
diff
changeset
|
345 (list (list "x-color" (cadr face)))) |
00aef3a1182b
(enriched-face-ans): Support FACE of the form
Eli Zaretskii <eliz@gnu.org>
parents:
42567
diff
changeset
|
346 ((and (listp face) (eq (car face) :background)) |
00aef3a1182b
(enriched-face-ans): Support FACE of the form
Eli Zaretskii <eliz@gnu.org>
parents:
42567
diff
changeset
|
347 (list (list "x-bg-color" (cadr face)))) |
40516
7f616838d931
(enriched-face-ans): FIx previous change.
Richard M. Stallman <rms@gnu.org>
parents:
40442
diff
changeset
|
348 ((listp face) |
7f616838d931
(enriched-face-ans): FIx previous change.
Richard M. Stallman <rms@gnu.org>
parents:
40442
diff
changeset
|
349 (apply 'append (mapcar 'enriched-face-ans face))) |
34020
43839f6e2822
(enriched-face-ans): Use face-attribute instead
Gerd Moellmann <gerd@gnu.org>
parents:
30925
diff
changeset
|
350 ((let* ((fg (face-attribute face :foreground)) |
43839f6e2822
(enriched-face-ans): Use face-attribute instead
Gerd Moellmann <gerd@gnu.org>
parents:
30925
diff
changeset
|
351 (bg (face-attribute face :background)) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
352 (props (face-font face t)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
353 (ans (cdr (format-annotate-single-property-change |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
354 'face nil props enriched-translations)))) |
30456
597562b7a8c6
(enriched-face-ans): For a `foreground-color'
Gerd Moellmann <gerd@gnu.org>
parents:
29765
diff
changeset
|
355 (unless (eq fg 'unspecified) |
597562b7a8c6
(enriched-face-ans): For a `foreground-color'
Gerd Moellmann <gerd@gnu.org>
parents:
29765
diff
changeset
|
356 (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
|
357 (unless (eq bg 'unspecified) |
597562b7a8c6
(enriched-face-ans): For a `foreground-color'
Gerd Moellmann <gerd@gnu.org>
parents:
29765
diff
changeset
|
358 (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
|
359 ans)))) |
9676 | 360 |
361 ;;; | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
362 ;;; Decoding files |
9676 | 363 ;;; |
364 | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
365 ;;;###autoload |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
366 (defun enriched-decode (from to) |
9676 | 367 (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
|
368 (use-hard-newlines 1 'never) |
9676 | 369 (save-excursion |
370 (save-restriction | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
371 (narrow-to-region from to) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
372 (goto-char from) |
16021
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
373 |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
374 ;; Deal with header |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
375 (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
|
376 (enriched-remove-header) |
9676 | 377 |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
378 ;; Deal with newlines |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
379 (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
|
380 (if (current-justification) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
381 (delete-char -1)) |
16021
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
382 (set-hard-newline-properties (match-beginning 0) (point))) |
9676 | 383 |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
384 ;; Translate annotations |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
385 (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
|
386 'enriched-next-annotation) |
9676 | 387 |
16021
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
388 ;; Indent or fill the buffer |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
389 (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
|
390 (setq fill-column file-width) |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
391 (if enriched-verbose (message "Indenting...")) |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
392 (enriched-insert-indentation)) |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
393 (t ; File was not filled. |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
394 (if enriched-verbose (message "Filling paragraphs...")) |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
395 (fill-region (point-min) (point-max)))) |
d6a8a05960d5
Don't fill based on window width.
Richard M. Stallman <rms@gnu.org>
parents:
15239
diff
changeset
|
396 (if enriched-verbose (message nil))) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
397 (point-max)))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
398 |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
399 (defun enriched-next-annotation () |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
400 "Find and return next text/enriched annotation. |
13488
71c747dc59ca
(enriched-next-annotation): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
13337
diff
changeset
|
401 Any \"<<\" strings encountered are converted to \"<\". |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
402 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
|
403 (while (and (search-forward "<" nil 1) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
404 (progn (goto-char (match-beginning 0)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
405 (not (looking-at enriched-annotation-regexp)))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
406 (forward-char 1) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
407 (if (= ?< (char-after (point))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
408 (delete-char 1) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
409 ;; 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
|
410 ;; which we note and then ignore. |
42458
7be0bbebc00f
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
42455
diff
changeset
|
411 (message "Warning: malformed annotation in file at %s" |
14340
bf1d862f3673
(enriched-next-annotation): Delete format call inside message.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
412 (1- (point))))) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
413 (if (not (eobp)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
414 (let* ((beg (match-beginning 0)) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
415 (end (match-end 0)) |
42458
7be0bbebc00f
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
42455
diff
changeset
|
416 (name (downcase (buffer-substring |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
417 (match-beginning 2) (match-end 2)))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
418 (pos (not (match-beginning 1)))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
419 (list beg end name pos)))) |
9676 | 420 |
421 (defun enriched-get-file-width () | |
422 "Look for file width information on this line." | |
423 (save-excursion | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
424 (if (search-forward "Text-Width: " (+ (point) 1000) t) |
9676 | 425 (read (current-buffer))))) |
426 | |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
427 (defun enriched-remove-header () |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
428 "Remove file-format header at point." |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
429 (while (looking-at "^[-A-Za-z]+: .*\n") |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
430 (delete-region (point) (match-end 0))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
431 (if (looking-at "^\n") |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
432 (delete-char 1))) |
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
433 |
17207
2d0b382efa26
(enriched-decode-foreground, enriched-decode-background):
Richard M. Stallman <rms@gnu.org>
parents:
16022
diff
changeset
|
434 (defun enriched-decode-foreground (from to &optional color) |
44415
c9f374d3e6f3
(enriched-decode-foreground, enriched-decode-background):
Richard M. Stallman <rms@gnu.org>
parents:
44392
diff
changeset
|
435 (if color |
c9f374d3e6f3
(enriched-decode-foreground, enriched-decode-background):
Richard M. Stallman <rms@gnu.org>
parents:
44392
diff
changeset
|
436 (list from to 'face (list ':foreground color)) |
c9f374d3e6f3
(enriched-decode-foreground, enriched-decode-background):
Richard M. Stallman <rms@gnu.org>
parents:
44392
diff
changeset
|
437 (message "Warning: no color specified for <x-color>") |
44376
b5dd3758c750
(enriched-face-ans): Delete special treatment for fg:... and bg:... faces.
Richard M. Stallman <rms@gnu.org>
parents:
44146
diff
changeset
|
438 nil)) |
11055
c8790275a636
Rewrite, many things moved to format.el.
Boris Goldowsky <boris@gnu.org>
parents:
10519
diff
changeset
|
439 |
17207
2d0b382efa26
(enriched-decode-foreground, enriched-decode-background):
Richard M. Stallman <rms@gnu.org>
parents:
16022
diff
changeset
|
440 (defun enriched-decode-background (from to &optional color) |
44415
c9f374d3e6f3
(enriched-decode-foreground, enriched-decode-background):
Richard M. Stallman <rms@gnu.org>
parents:
44392
diff
changeset
|
441 (if color |
c9f374d3e6f3
(enriched-decode-foreground, enriched-decode-background):
Richard M. Stallman <rms@gnu.org>
parents:
44392
diff
changeset
|
442 (list from to 'face (list ':background color)) |
c9f374d3e6f3
(enriched-decode-foreground, enriched-decode-background):
Richard M. Stallman <rms@gnu.org>
parents:
44392
diff
changeset
|
443 (message "Warning: no color specified for <x-bg-color>") |
44376
b5dd3758c750
(enriched-face-ans): Delete special treatment for fg:... and bg:... faces.
Richard M. Stallman <rms@gnu.org>
parents:
44146
diff
changeset
|
444 nil)) |
24989
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
445 |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
446 ;;; Handling the `display' property. |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
447 |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
448 |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
449 (defun enriched-handle-display-prop (old new) |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
450 "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
|
451 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
|
452 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
|
453 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
|
454 has the form `(ANNOTATION PARAM ...)'." |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
455 (let ((annotation "x-display") |
42479
d9873c0f6418
(enriched-handle-display-prop): Remove unused variables.
Pavel Janík <Pavel@Janik.cz>
parents:
42458
diff
changeset
|
456 (param (prin1-to-string (or old new)))) |
24989
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
457 (if (null old) |
42567
b1eda5349a48
(enriched-make-annotation): Fix the change from 2002-01-05.
Pavel Janík <Pavel@Janik.cz>
parents:
42545
diff
changeset
|
458 (cons nil (list (list annotation param))) |
b1eda5349a48
(enriched-make-annotation): Fix the change from 2002-01-05.
Pavel Janík <Pavel@Janik.cz>
parents:
42545
diff
changeset
|
459 (cons (list (list annotation param)) nil)))) |
24989
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
460 |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
461 (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
|
462 "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
|
463 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
|
464 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
|
465 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
|
466 (let ((prop (when (stringp param) |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
467 (condition-case () |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
468 (car (read-from-string param)) |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
469 (error nil))))) |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
470 (unless prop |
5d58f00ad19c
(enriched-translations): Add `display' and "x-display".
Gerd Moellmann <gerd@gnu.org>
parents:
24466
diff
changeset
|
471 (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
|
472 (list start end 'display prop))) |
42458
7be0bbebc00f
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
42455
diff
changeset
|
473 |
9676 | 474 ;;; enriched.el ends here |