annotate lisp/modes/enriched.el @ 183:e121b013d1f0 r20-3b18

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