annotate lisp/modes/enriched.el @ 215:1f0dabaa0855 r20-4b6

Import from CVS: tag r20-4b6
author cvs
date Mon, 13 Aug 2007 10:07:35 +0200
parents e45d5e7c476e
children
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
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
2
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
3 ;; Copyright (c) 1994, 1995, 1996 Free Software Foundation, Inc.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; XEmacs version: Mike Sperber <sperber@informatik.uni-tuebingen.de>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Original author: Boris Goldowsky <boris@gnu.ai.mit.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Keywords: wp, faces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
9 ;; This file is part of XEmacs.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
12 ;; under the terms of the GNU General Public License as published by
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; any later version.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
15
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
19 ;; General Public License for more details.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
20
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; 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
22 ;; 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
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
24 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
26 ;;; Synched up with: FSF 20.2.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; Commentary:
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
29
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; This file implements reading, editing, and saving files with
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
31 ;; text-properties such as faces, levels of indentation, and true line
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
32 ;; breaks distinguished from newlines just used to fit text into the window.
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
33
0
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
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
35 ;; standard format defined in internet RFC 1563. All standard annotations
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
36 ;; are supported except for <smaller> and <bigger>, which are currently not
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
37 ;; possible to display.
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
38
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
39 ;; A separate file, enriched.doc, contains further documentation and other
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
40 ;; important information about this code. It also serves as an example
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
41 ;; file in text/enriched format. It should be in the etc directory of your
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
42 ;; emacs distribution.
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
43
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;; TODO for the XEmacs port:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; Currently XEmacs does not support default-text-properties. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; original enriched.el uses this to set the left-margin,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;; right-margin, and justification properties to 'front-sticky.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; If you know the Right Way to fix this, contact
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;; Mike Sperber <sperber@informatik.uni-tuebingen.de>.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
52 ;;; Code:
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
53
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (provide 'enriched)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;;; Variables controlling the display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 2
diff changeset
60 (defgroup enriched nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 2
diff changeset
61 "Read and save files in text/enriched format"
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 2
diff changeset
62 :group 'wp)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 2
diff changeset
63
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 2
diff changeset
64 (defcustom enriched-verbose t
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 2
diff changeset
65 "*If non-nil, give status messages when reading and writing files."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 2
diff changeset
66 :type 'boolean
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 2
diff changeset
67 :group 'enriched)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 2
diff changeset
68
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;;; Set up faces & display table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
73 ;; Emacs doesn't have a "fixed" face by default, since all faces currently
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
74 ;; have to be fixed-width. So we just pick one that looks different from the
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
75 ;; default.
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
76 (defface fixed
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
77 '((t (:bold t)))
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
78 "Face used for text that must be shown in fixed width.
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
79 Currently, emacs can only display fixed-width fonts, but this may change.
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
80 This face is used for text specifically marked as fixed-width, for example
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
81 in text/enriched files."
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
82 :group 'enriched)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
84 (defface excerpt
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
85 '((t (:italic t)))
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
86 "Face used for text that is an excerpt from another document.
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
87 This is used in enriched-mode for text explicitly marked as an excerpt."
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
88 :group 'enriched)
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
89
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
90 (defconst enriched-display-table
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
91 ;; XEmacs change
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
92 ;; (or (copy-sequence standard-display-table)
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
93 ;; (make-display-table)))
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
94 (make-display-table))
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
95 (aset enriched-display-table ?\f (make-vector (1- (frame-width)) ?-))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
97 (defconst enriched-par-props '(left-margin right-margin justification)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
98 "Text-properties that usually apply to whole paragraphs.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
99 These are set front-sticky everywhere except at hard newlines.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
100
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;;; Variables controlling the file format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;;; (bidirectional)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (defconst enriched-initial-annotation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (format "Content-Type: text/enriched\nText-Width: %d\n\n"
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
108 fill-column))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 "What to insert at the start of a text/enriched file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 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
111 expression, which is evaluated to get the string to insert.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (defconst enriched-annotation-format "<%s%s>"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 "General format of enriched-text annotations.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (defconst enriched-annotation-regexp "<\\(/\\)?\\([-A-za-z0-9]+\\)>"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 "Regular expression matching enriched-text annotations.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (defconst enriched-translations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 '((face (bold-italic "bold" "italic")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (bold "bold")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (italic "italic")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (underline "underline")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (fixed "fixed")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (excerpt "excerpt")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (default )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (nil enriched-encode-other-face))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
128 (left-margin (4 "indent"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
129 (right-margin (4 "indentright"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (justification (none "nofill")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (right "flushright")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (left "flushleft")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (full "flushboth")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (center "center"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (PARAMETER (t "param")) ; Argument of preceding annotation
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
136 ;; The following are not part of the standard:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (FUNCTION (enriched-decode-foreground "x-color")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (enriched-decode-background "x-bg-color")
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
139 ;; XEmacs addition
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (facemenu-make-larger "bigger")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (facemenu-make-smaller "smaller"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (read-only (t "x-read-only"))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
143 (unknown (nil format-annotate-value))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
144 ; (font-size (2 "bigger") ; unimplemented
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
145 ; (-2 "smaller"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
146 )
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 "List of definitions of text/enriched annotations.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 See `format-annotate-region' and `format-deannotate-region' for the definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 of this structure.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
151 (defconst enriched-ignore
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
152 '(front-sticky rear-nonsticky hard)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 "Properties that are OK to ignore when saving text/enriched files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 Any property that is neither on this list nor dealt with by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 `enriched-translations' will generate a warning.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 ;;; Internal variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (defvar enriched-mode nil
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
160 "True if Enriched mode is in use.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (make-variable-buffer-local 'enriched-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (if (not (assq 'enriched-mode minor-mode-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (setq minor-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (cons '(enriched-mode " Enriched")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 minor-mode-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 2
diff changeset
168 (defcustom enriched-mode-hook nil
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
169 "Functions to run when entering Enriched mode.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 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
171 to their old values if you leave Enriched mode. One way to do this is to add
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 2
diff changeset
172 them and their old values to `enriched-old-bindings'."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 2
diff changeset
173 :type 'hook
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 2
diff changeset
174 :group 'enriched)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (defvar enriched-old-bindings nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 "Store old variable values that we change when entering mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 The value is a list of \(VAR VALUE VAR VALUE...).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (make-variable-buffer-local 'enriched-old-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 ;;; Define the mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (defun enriched-mode (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 "Minor mode for editing text/enriched files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 These are files with embedded formatting information in the MIME standard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 text/enriched format.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
190 Turning the mode on runs `enriched-mode-hook'.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
192 More information about Enriched mode is available in the file
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 etc/enriched.doc in the Emacs distribution directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 Commands:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 \\<enriched-mode-map>\\{enriched-mode-map}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (let ((mod (buffer-modified-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (cond ((or (<= (prefix-numeric-value arg) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (and enriched-mode (null arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 ;; Turn mode off
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (setq enriched-mode nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (setq buffer-file-format (delq 'text/enriched buffer-file-format))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 ;; restore old variable values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (while enriched-old-bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (funcall 'set (car enriched-old-bindings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (car (cdr enriched-old-bindings)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (setq enriched-old-bindings (cdr (cdr enriched-old-bindings)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (enriched-mode nil) ; Mode already on; do nothing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (t (setq enriched-mode t) ; Turn mode on
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
214 (add-to-list 'buffer-file-format 'text/enriched)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 ;; Save old variable values before we change them.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
216 ;; These will be restored if we exit Enriched mode.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (setq enriched-old-bindings
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
218 ;; XEmacs change
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
219 (list ; 'buffer-display-table buffer-display-table
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
220 'indent-line-function indent-line-function
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
221 'default-text-properties default-text-properties))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (make-local-variable 'indent-line-function)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
223 (make-local-variable 'default-text-properties)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (setq indent-line-function 'indent-to-left-margin
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
225 ;; XEmacs change
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
226 ;; buffer-display-table enriched-display-table
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
227 )
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
228 (use-hard-newlines 1 nil)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
229 (let ((sticky (plist-get default-text-properties 'front-sticky))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
230 (p enriched-par-props))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
231 (while p
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
232 (add-to-list 'sticky (car p))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
233 (setq p (cdr p)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
234 (if sticky
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
235 (setq default-text-properties
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
236 (plist-put default-text-properties
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
237 'front-sticky sticky))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
238 (run-hooks 'enriched-mode-hook)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (set-buffer-modified-p mod)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
240 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (redraw-modeline)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 ;;; Keybindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (defvar enriched-mode-map nil
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
248 "Keymap for Enriched mode.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (if (null enriched-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (fset 'enriched-mode-map (setq enriched-mode-map (make-sparse-keymap))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (if (not (assq 'enriched-mode minor-mode-map-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (setq minor-mode-map-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (cons (cons 'enriched-mode enriched-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 minor-mode-map-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (define-key enriched-mode-map "\C-a" 'beginning-of-line-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (define-key enriched-mode-map "\C-m" 'reindent-then-newline-and-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (define-key enriched-mode-map "\C-j" 'reindent-then-newline-and-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (define-key enriched-mode-map "\M-j" 'facemenu-justification-menu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (define-key enriched-mode-map "\M-S" 'set-justification-center)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (define-key enriched-mode-map "\C-x\t" 'increase-left-margin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (define-key enriched-mode-map "\C-c\C-l" 'set-left-margin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (define-key enriched-mode-map "\C-c\C-r" 'set-right-margin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 ;;; Some functions dealing with text-properties, especially indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (defun enriched-map-property-regions (prop func &optional from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 "Apply a function to regions of the buffer based on a text property.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 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
274 eq, the FUNCTION will be called. Optional arguments FROM and TO specify the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 region over which to scan.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 The specified function receives three arguments: the VALUE of the property in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 the region, and the START and END of each region."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (if to (narrow-to-region (point-min) to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (goto-char (or from (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (let ((begin (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (marker (make-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (val (get-text-property (point) prop)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (while (setq end (text-property-not-all begin (point-max) prop val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (move-marker marker end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (funcall func val begin (marker-position marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (setq begin (marker-position marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 val (get-text-property marker prop)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (if (< begin (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (funcall func val begin (point-max)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (put 'enriched-map-property-regions 'lisp-indent-hook 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (defun enriched-insert-indentation (&optional from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 "Indent and justify each line in the region."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (if to (narrow-to-region (point-min) to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (goto-char (or from (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (if (not (bolp)) (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (while (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (if (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 nil ; skip blank lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (indent-to (current-left-margin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (justify-current-line t nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (forward-line 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 ;;; Encoding Files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 ;;;###autoload
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
316 (defun enriched-encode (from to &optional orig-buf)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (if enriched-verbose (message "Enriched: encoding document..."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (narrow-to-region from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (delete-to-left-margin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (unjustify-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (goto-char from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (format-replace-strings '(("<" . "<<")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (format-insert-annotations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (format-annotate-region from (point-max) enriched-translations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 'enriched-make-annotation enriched-ignore))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (goto-char from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (insert (if (stringp enriched-initial-annotation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 enriched-initial-annotation
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
330 (save-excursion
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
331 ;; Eval this in the buffer we are annotating. This
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
332 ;; fixes a bug which was saving incorrect File-Width
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
333 ;; information, since we were looking at local
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
334 ;; variables in the wrong buffer.
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
335 (if orig-buf (set-buffer orig-buf))
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
336 (funcall enriched-initial-annotation))))
0
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)))
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 134
diff changeset
407 (color-name (face-foreground face))))
0
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)))
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 134
diff changeset
410 (color-name (face-background face))))
0
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..."))
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
446 (use-hard-newlines 1 'never)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (narrow-to-region from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (goto-char from)
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
451
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
452 ;; Deal with header
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
453 (let ((file-width (enriched-get-file-width)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (enriched-remove-header)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 ;; Deal with newlines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (while (search-forward-regexp "\n\n+" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (if (current-justification)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (delete-char -1))
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
460 (set-hard-newline-properties (match-beginning 0) (point)))
0
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
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
466 ;; Indent or fill the buffer
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
467 (cond (file-width ; File was filled to this width
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
468 (setq fill-column file-width)
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
469 (if enriched-verbose (message "Indenting..."))
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
470 (enriched-insert-indentation))
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
471 (t ; File was not filled.
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
472 (if enriched-verbose (message "Filling paragraphs..."))
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
473 (fill-region (point-min) (point-max))))
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
474 (if enriched-verbose (message nil)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (defun enriched-next-annotation ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 "Find and return next text/enriched annotation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 Any \"<<\" strings encountered are converted to \"<\".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 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
481 (while (and (search-forward "<" nil 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (progn (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (not (looking-at enriched-annotation-regexp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (if (= ?< (char-after (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 ;; A single < that does not start an annotation is an error,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 ;; which we note and then ignore.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
489 (message "Warning: malformed annotation in file at %s"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
490 (1- (point)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (if (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (let* ((beg (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (end (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (name (downcase (buffer-substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (match-beginning 2) (match-end 2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (pos (not (match-beginning 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (list beg end name pos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (defun enriched-get-file-width ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 "Look for file width information on this line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (if (search-forward "Text-Width: " (+ (point) 1000) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (read (current-buffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (defun enriched-remove-header ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 "Remove file-format header at point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (while (looking-at "^[-A-Za-z]+: .*\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (delete-region (point) (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (if (looking-at "^\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (delete-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
512 (defun enriched-decode-foreground (from to &optional color)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
513 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (let ((face (facemenu-get-face (intern (concat "fg:" color)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (if (not face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (make-face face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (message "Warning: Color \"%s\" can't be displayed." color)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (list from to 'face face)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 207
diff changeset
521 (defun enriched-decode-background (from to &optional color)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
522 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (let ((face (facemenu-get-face (intern (concat "bg:" color)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (if (not face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (make-face face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (message "Warning: Color \"%s\" can't be displayed." color)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (list from to 'face face)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 ;;; enriched.el ends here