annotate lisp/modes/enriched.el @ 39:06f275776fba

Added tag r19-15b102 for changeset 1a767b41a199
author cvs
date Mon, 13 Aug 2007 08:54:02 +0200
parents ac2d302a0011
children 34a5b81f86ba
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; enriched.el --- read and save files in text/enriched format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Copyright (c) 1994, 1995 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; XEmacs version: Mike Sperber <sperber@informatik.uni-tuebingen.de>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Original author: Boris Goldowsky <boris@gnu.ai.mit.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: wp, faces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
8 ;; This file is part of XEmacs.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
11 ;; under the terms of the GNU General Public License as published by
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
14
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
18 ;; General Public License for more details.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
19
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
23 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
25 ;;; Synched up with: FSF 19.34.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; This file implements reading, editing, and saving files with
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
30 ;; text-properties such as faces, levels of indentation, and true line
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
31 ;; breaks distinguished from newlines just used to fit text into the
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
32 ;; window.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; The file format used is the MIME text/enriched format, which is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; standard format defined in internet RFC 1563. All standard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; annotations are supported.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
38 ;; A separate file, enriched.doc, contains further documentation and
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
39 ;; other important information about this code. It also serves as an
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
40 ;; example file in text/enriched format. It should be in the etc
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
41 ;; directory of your emacs distribution.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;; TODO for the XEmacs port:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;; Currently XEmacs does not support default-text-properties. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; original enriched.el uses this to set the left-margin,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; right-margin, and justification properties to 'front-sticky.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;; If you know the Right Way to fix this, contact
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; Mike Sperber <sperber@informatik.uni-tuebingen.de>.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (provide 'enriched)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
52 (if window-system (require 'facemenu))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;;; Variables controlling the display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (defvar enriched-verbose t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 "*If non-nil, give status messages when reading and writing files.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (defvar enriched-default-right-margin 10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 "*Default amount of space to leave on the right edge of the screen.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 This can be increased inside text by changing the 'right-margin text property.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 Measured in character widths. If the screen is narrower than this, it is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 assumed to be 0.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (defvar enriched-fill-after-visiting t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 "If t, fills paragraphs when reading in enriched documents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 If nil, only fills when you explicitly request it. If the value is 'ask, then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 it will query you whether to fill.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 Filling is never done if the current text-width is the same as the value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 stored in the file.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;;; Set up faces & display table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
78 ;; XEmacs change (Can't cheat, we have variable width fonts)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (if (not (find-face 'fixed))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (copy-face 'default 'fixed))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (if (not (find-face 'excerpt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (copy-face 'italic 'excerpt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (defconst enriched-display-table (make-display-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (aset enriched-display-table ?\f (make-string (1- (frame-width)) ?-))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
88 (defconst enriched-par-props '(left-margin right-margin justification)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
89 "Text-properties that usually apply to whole paragraphs.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
90 These are set front-sticky everywhere except at hard newlines.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
91
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;;; Variables controlling the file format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;;; (bidirectional)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (defconst enriched-initial-annotation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (format "Content-Type: text/enriched\nText-Width: %d\n\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (enriched-text-width)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 "What to insert at the start of a text/enriched file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 If this is a string, it is inserted. If it is a list, it should be a lambda
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 expression, which is evaluated to get the string to insert.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (defconst enriched-annotation-format "<%s%s>"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 "General format of enriched-text annotations.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (defconst enriched-annotation-regexp "<\\(/\\)?\\([-A-za-z0-9]+\\)>"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 "Regular expression matching enriched-text annotations.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (defconst enriched-translations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 '((face (bold-italic "bold" "italic")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (bold "bold")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (italic "italic")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (underline "underline")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (fixed "fixed")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (excerpt "excerpt")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (default )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (nil enriched-encode-other-face))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
119 (left-margin (4 "indent"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
120 (right-margin (4 "indentright"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (justification (none "nofill")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (right "flushright")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (left "flushleft")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (full "flushboth")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (center "center"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (PARAMETER (t "param")) ; Argument of preceding annotation
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
127 ;; The following are not part of the standard:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (FUNCTION (enriched-decode-foreground "x-color")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (enriched-decode-background "x-bg-color")
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
130 ;; XEmacs addition
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (facemenu-make-larger "bigger")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (facemenu-make-smaller "smaller"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (read-only (t "x-read-only"))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
134 (unknown (nil format-annotate-value))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
135 ; (font-size (2 "bigger") ; unimplemented
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
136 ; (-2 "smaller"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
137 )
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 "List of definitions of text/enriched annotations.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 See `format-annotate-region' and `format-deannotate-region' for the definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 of this structure.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
142 (defconst enriched-ignore
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
143 '(front-sticky rear-nonsticky hard)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 "Properties that are OK to ignore when saving text/enriched files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 Any property that is neither on this list nor dealt with by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 `enriched-translations' will generate a warning.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ;;; Internal variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (defvar enriched-mode nil
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
151 "True if Enriched mode is in use.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (make-variable-buffer-local 'enriched-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (if (not (assq 'enriched-mode minor-mode-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (setq minor-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (cons '(enriched-mode " Enriched")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 minor-mode-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
159 (defvar enriched-mode-hook nil
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
160 "Functions to run when entering Enriched mode.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 If you set variables in this hook, you should arrange for them to be restored
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
162 to their old values if you leave Enriched mode. One way to do this is to add
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 them and their old values to `enriched-old-bindings'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (defvar enriched-old-bindings nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 "Store old variable values that we change when entering mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 The value is a list of \(VAR VALUE VAR VALUE...).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (make-variable-buffer-local 'enriched-old-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (defvar enriched-text-width nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (make-variable-buffer-local 'enriched-text-width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ;;; Define the mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (defun enriched-mode (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 "Minor mode for editing text/enriched files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 These are files with embedded formatting information in the MIME standard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 text/enriched format.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
182 Turning the mode on runs `enriched-mode-hook'.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
184 More information about Enriched mode is available in the file
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 etc/enriched.doc in the Emacs distribution directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 Commands:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 \\<enriched-mode-map>\\{enriched-mode-map}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (let ((mod (buffer-modified-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (cond ((or (<= (prefix-numeric-value arg) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (and enriched-mode (null arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ;; Turn mode off
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (setq enriched-mode nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (setq buffer-file-format (delq 'text/enriched buffer-file-format))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 ;; restore old variable values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (while enriched-old-bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (funcall 'set (car enriched-old-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (car (cdr enriched-old-bindings)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (setq enriched-old-bindings (cdr (cdr enriched-old-bindings)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (enriched-mode nil) ; Mode already on; do nothing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (t (setq enriched-mode t) ; Turn mode on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (if (not (memq 'text/enriched buffer-file-format))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (setq buffer-file-format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (cons 'text/enriched buffer-file-format)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 ;; Save old variable values before we change them.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
210 ;; These will be restored if we exit Enriched mode.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (setq enriched-old-bindings
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
212 ;; XEmacs change
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
213 (list ; 'buffer-display-table buffer-display-table
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
214 'indent-line-function indent-line-function
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
215 'use-hard-newlines use-hard-newlines
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
216 'default-text-properties default-text-properties))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (make-local-variable 'indent-line-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (make-local-variable 'use-hard-newlines)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
219 (make-local-variable 'default-text-properties)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (setq indent-line-function 'indent-to-left-margin
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
221 ;; XEmacs change
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
222 ;; buffer-display-table enriched-display-table
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
223 use-hard-newlines t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
224 (let ((sticky (plist-get default-text-properties 'front-sticky))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
225 (p enriched-par-props))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
226 (while p
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
227 (if (not (memq (car p) sticky))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
228 (setq sticky (cons (car p) sticky)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
229 (setq p (cdr p)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
230 (if sticky
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
231 (setq default-text-properties
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
232 (plist-put default-text-properties
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
233 'front-sticky sticky))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
234 (run-hooks 'enriched-mode-hook)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (set-buffer-modified-p mod)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
236 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (redraw-modeline)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 ;;; Keybindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (defvar enriched-mode-map nil
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
244 "Keymap for Enriched mode.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (if (null enriched-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (fset 'enriched-mode-map (setq enriched-mode-map (make-sparse-keymap))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (if (not (assq 'enriched-mode minor-mode-map-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (setq minor-mode-map-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (cons (cons 'enriched-mode enriched-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 minor-mode-map-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (define-key enriched-mode-map "\C-a" 'beginning-of-line-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (define-key enriched-mode-map "\C-m" 'reindent-then-newline-and-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (define-key enriched-mode-map "\C-j" 'reindent-then-newline-and-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (define-key enriched-mode-map "\M-j" 'facemenu-justification-menu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (define-key enriched-mode-map "\M-S" 'set-justification-center)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (define-key enriched-mode-map "\C-x\t" 'increase-left-margin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (define-key enriched-mode-map "\C-c\C-l" 'set-left-margin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (define-key enriched-mode-map "\C-c\C-r" 'set-right-margin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 ;;; Some functions dealing with text-properties, especially indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (defun enriched-map-property-regions (prop func &optional from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 "Apply a function to regions of the buffer based on a text property.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 For each contiguous region of the buffer for which the value of PROPERTY is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 eq, the FUNCTION will be called. Optional arguments FROM and TO specify the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 region over which to scan.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 The specified function receives three arguments: the VALUE of the property in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 the region, and the START and END of each region."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (if to (narrow-to-region (point-min) to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (goto-char (or from (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (let ((begin (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (marker (make-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (val (get-text-property (point) prop)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (while (setq end (text-property-not-all begin (point-max) prop val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (move-marker marker end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (funcall func val begin (marker-position marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (setq begin (marker-position marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 val (get-text-property marker prop)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (if (< begin (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (funcall func val begin (point-max)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (put 'enriched-map-property-regions 'lisp-indent-hook 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (defun enriched-insert-indentation (&optional from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 "Indent and justify each line in the region."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (if to (narrow-to-region (point-min) to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (goto-char (or from (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (if (not (bolp)) (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (while (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (if (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 nil ; skip blank lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (indent-to (current-left-margin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (justify-current-line t nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (forward-line 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (defun enriched-text-width ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 "The width of unindented text in this window, in characters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 This is the width of the window minus `enriched-default-right-margin'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (or enriched-text-width
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (let ((ww (window-width)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (setq enriched-text-width
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (if (> ww enriched-default-right-margin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (- ww enriched-default-right-margin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 ww)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 ;;; Encoding Files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (defun enriched-encode (from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (if enriched-verbose (message "Enriched: encoding document..."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (narrow-to-region from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (delete-to-left-margin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (unjustify-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (goto-char from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (format-replace-strings '(("<" . "<<")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (format-insert-annotations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (format-annotate-region from (point-max) enriched-translations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 'enriched-make-annotation enriched-ignore))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (goto-char from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (insert (if (stringp enriched-initial-annotation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 enriched-initial-annotation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (funcall enriched-initial-annotation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (enriched-map-property-regions 'hard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (lambda (v b e)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (if (and v (= ?\n (char-after b)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (progn (goto-char b) (insert "\n"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (point) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (if enriched-verbose (message nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 ;; Return new end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (defun enriched-make-annotation (name positive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 "Format an annotation called NAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 If POSITIVE is non-nil, this is the opening annotation, if nil, this is the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 matching close."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (cond ((stringp name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (format enriched-annotation-format (if positive "" "/") name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 ;; Otherwise it is an annotation with parameters, represented as a list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (positive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (let ((item (car name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (params (cdr name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (concat (format enriched-annotation-format "" item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (mapconcat (lambda (i) (concat "<param>" i "</param>"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 params ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (t (format enriched-annotation-format "/" (car name)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
361 ;; XEmacs addition
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (defun enriched-face-strip-size (face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 "Create a symbol from the name of FACE devoid of size information,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 i.e. remove all larger- and smaller- prefixes."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (let* ((face-symbol (face-name face))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (face-name (symbol-name face-symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (old-name face-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 new-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (not (string-equal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 old-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (setq new-name (replace-in-string old-name "^larger-" ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (setq old-name new-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (not (string-equal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 old-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (setq new-name (replace-in-string old-name "^smaller-" ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (setq old-name new-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (if (string-equal new-name face-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 face-symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (intern new-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (defun enriched-encode-other-face (old new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 "Generate annotations for random face change.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 One annotation each for foreground color, background color, italic, etc."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (cons (and old (enriched-face-ans old))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (and new (enriched-face-ans new))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (defun enriched-face-ans (face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 "Return annotations specifying FACE."
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
393 ;; XEmacs change (entire body of this function)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (let ((face-name (symbol-name face)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (cond ((string-match "^fg:" face-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (list (list "x-color" (substring face-name 3))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 ((string-match "^bg:" face-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (list (list "x-bg-color" (substring face-name 3))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 ((or (string-match "^larger-" face-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (string-match "^smaller-" face-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (cdr (format-annotate-single-property-change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 'face nil (enriched-face-strip-size face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 enriched-translations)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (let* ((fg (and (not (eq (face-foreground face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (face-foreground 'default)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (color-instance-name (face-foreground face))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (bg (and (not (eq (face-background face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (face-background 'default)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (color-instance-name (face-background face))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (ans '()))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (if fg (setq ans (cons (list "x-color" fg) ans)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (if bg (setq ans (cons (list "x-bg-color" bg) ans)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 ans)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
416 ;; XEmacs addition
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (defun enriched-size-annotation (n annotation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 "Generate ANNOTATION N times."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (let ((l '()))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (while (not (zerop n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (setq l (cons annotation l))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (setq n (1- n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 l))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
425 ;; XEmacs addition
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (defun enriched-encode-size (old new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 "Return annotations specifying SIZE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (let* ((old (or old 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (new (or new 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (closing-annotation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (enriched-size-annotation (abs old)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (if (> old 0) "bigger" "smaller")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (opening-annotation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (enriched-size-annotation (abs new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (if (> new 0) "bigger" "smaller"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (cons closing-annotation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 opening-annotation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 ;;; Decoding files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (defun enriched-decode (from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (if enriched-verbose (message "Enriched: decoding document..."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (narrow-to-region from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (goto-char from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (let ((file-width (enriched-get-file-width))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (use-hard-newlines t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (enriched-remove-header)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 ;; Deal with newlines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (goto-char from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (while (search-forward-regexp "\n\n+" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (if (current-justification)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (delete-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (put-text-property (match-beginning 0) (point) 'hard t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (put-text-property (match-beginning 0) (point) 'front-sticky nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 ;; Translate annotations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (format-deannotate-region from (point-max) enriched-translations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 'enriched-next-annotation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 ;; Fill paragraphs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (if (or (and file-width ; possible reasons not to fill:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (= file-width (enriched-text-width))) ; correct wd.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (null enriched-fill-after-visiting) ; never fill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (and (eq 'ask enriched-fill-after-visiting) ; asked & declined
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (not (y-or-n-p "Re-fill for current display width? "))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 ;; Minimally, we have to insert indentation and justification.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (enriched-insert-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (if enriched-verbose (message "Filling paragraphs..."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (fill-region (point-min) (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (if enriched-verbose (message nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (defun enriched-next-annotation ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 "Find and return next text/enriched annotation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 Any \"<<\" strings encountered are converted to \"<\".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 Return value is \(begin end name positive-p), or nil if none was found."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (while (and (search-forward "<" nil 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (progn (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (not (looking-at enriched-annotation-regexp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (if (= ?< (char-after (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 ;; A single < that does not start an annotation is an error,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 ;; which we note and then ignore.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
491 (message "Warning: malformed annotation in file at %s"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
492 (1- (point)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (if (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (let* ((beg (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (end (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (name (downcase (buffer-substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (match-beginning 2) (match-end 2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (pos (not (match-beginning 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (list beg end name pos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (defun enriched-get-file-width ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 "Look for file width information on this line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (if (search-forward "Text-Width: " (+ (point) 1000) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (read (current-buffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (defun enriched-remove-header ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 "Remove file-format header at point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (while (looking-at "^[-A-Za-z]+: .*\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (delete-region (point) (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (if (looking-at "^\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (delete-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (defun enriched-decode-foreground (from to color)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
515 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (let ((face (facemenu-get-face (intern (concat "fg:" color)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (if (not face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (make-face face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (message "Warning: Color \"%s\" can't be displayed." color)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (list from to 'face face)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (defun enriched-decode-background (from to color)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
524 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (let ((face (facemenu-get-face (intern (concat "bg:" color)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (if (not face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (make-face face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (message "Warning: Color \"%s\" can't be displayed." color)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (list from to 'face face)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 ;;; enriched.el ends here