annotate lisp/modes/enriched.el @ 0:376386a54a3c r19-14

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