annotate lisp/prim/format.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children b82b59fe008d
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 ;;; format.el --- read and save files in multiple formats
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Copyright (c) 1994, 1995 Free Software Foundation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Author: Boris Goldowsky <boris@gnu.ai.mit.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; along with GNU Emacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;;; Synched up with: FSF 19.30.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; This file defines a unified mechanism for saving & loading files stored in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; different formats. `format-alist' contains information that directs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; Emacs to call an encoding or decoding function when reading or writing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; files that match certain conditions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; When a file is visited, its format is determined by matching the beginning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; of the file against regular expressions stored in `format-alist'. If this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; fails, you can manually translate the buffer using `format-decode-buffer'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; In either case, the formats used are listed in the variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; `buffer-file-format', and become the default format for saving the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; To save a buffer in a different format, change this variable, or use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; `format-write-file'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; Auto-save files are normally created in the same format as the visited
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; file, but the variable `auto-save-file-format' can be set to a particularly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; fast or otherwise preferred format to be used for auto-saving (or nil to do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; no encoding on auto-save files, but then you risk losing any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;; text-properties in the buffer).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; You can manually translate a buffer into or out of a particular format with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;; the functions `format-encode-buffer' and `format-decode-buffer'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; To translate just the region use the functions `format-encode-region' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; `format-decode-region'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; You can define a new format by writing the encoding and decoding functions,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;; and adding an entry to `format-alist'. See enriched.el for an example of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;; how to implement a file format. There are various functions defined
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; in this file that may be useful for writing the encoding and decoding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; functions:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;; * `format-annotate-region' and `format-deannotate-region' allow a single
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;; alist of information to be used for encoding and decoding. The alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;; defines a correspondence between strings in the file ("annotations")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; and text-properties in the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; * `format-replace-strings' is similarly useful for doing simple
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; string->string translations in a reversible manner.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (put 'buffer-file-format 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (defconst format-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 '((text/enriched "Extended MIME text/enriched format."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 "Content-[Tt]ype:[ \t]*text/enriched"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 enriched-decode enriched-encode t enriched-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (plain "Standard ASCII format, no text properties."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;; Plain only exists so that there is an obvious neutral choice in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;; the completion list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 nil nil nil nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 "List of information about understood file formats.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 Elements are of the form \(NAME DOC-STR REGEXP FROM-FN TO-FN MODIFY MODE-FN).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 NAME is a symbol, which is stored in `buffer-file-format'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 DOC-STR should be a single line providing more information about the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 format. It is currently unused, but in the future will be shown to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 the user if they ask for more information.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 REGEXP is a regular expression to match against the beginning of the file;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 it should match only files in that format.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 FROM-FN is called to decode files in that format; it gets two args, BEGIN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 and END, and can make any modifications it likes, returning the new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 end. It must make sure that the beginning of the file no longer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 matches REGEXP, or else it will get called again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 TO-FN is called to encode a region into that format; it is also passed BEGIN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 and END, and either returns a list of annotations like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 `write-region-annotate-functions', or modifies the region and returns
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 the new end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 MODIFY, if non-nil, means the TO-FN modifies the region. If nil, TO-FN may
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 not make any changes and should return a list of annotations.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 MODE-FN, if specified, is called when visiting a file with that format.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;;; Basic Functions (called from Lisp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (defun format-annotate-function (format from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 "Returns annotations for writing region as FORMAT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 FORMAT is a symbol naming one of the formats defined in `format-alist',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 it must be a single symbol, not a list like `buffer-file-format'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 This function works like a function on `write-region-annotate-functions':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 it either returns a list of annotations, or returns with a different buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 current, which contains the modified text to write.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 For most purposes, consider using `format-encode-region' instead."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;; This function is called by write-region (actually build-annotations)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;; for each element of buffer-file-format.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (let* ((info (assq format format-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (to-fn (nth 4 info))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (modify (nth 5 info)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (if to-fn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (if modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ;; To-function wants to modify region. Copy to safe place.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (let ((copy-buf (get-buffer-create " *Format Temp*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (copy-to-buffer copy-buf from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (set-buffer copy-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (format-insert-annotations write-region-annotations-so-far from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (funcall to-fn (point-min) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;; Otherwise just call function, it will return annotations.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (funcall to-fn from to)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (defun format-decode (format length &optional visit-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 ;; This function is called by insert-file-contents whenever a file is read.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 "Decode text from any known FORMAT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 FORMAT is a symbol appearing in `format-alist' or a list of such symbols,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 or nil, in which case this function tries to guess the format of the data by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 matching against the regular expressions in `format-alist'. After a match is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 found and the region decoded, the alist is searched again from the beginning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 for another match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 Second arg LENGTH is the number of characters following point to operate on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 If optional third arg VISIT-FLAG is true, set `buffer-file-format'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 to the list of formats used, and call any mode functions defined for those
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 formats.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 Returns the new length of the decoded region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 For most purposes, consider using `format-decode-region' instead."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (let ((mod (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (begin (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (end (+ (point) length)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (if (null format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 ;; Figure out which format it is in, remember list in `format'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (let ((try format-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (while try
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (let* ((f (car try))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (regexp (nth 2 f))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (p (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (if (and regexp (looking-at regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (< (match-end 0) (+ begin length)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (setq format (cons (car f) format))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ;; Decode it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (if (nth 3 f) (setq end (funcall (nth 3 f) begin end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 ;; Call visit function if required
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (if (and visit-flag (nth 6 f)) (funcall (nth 6 f) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;; Safeguard against either of the functions changing pt.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (goto-char p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 ;; Rewind list to look for another format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (setq try format-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (setq try (cdr try))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ;; Deal with given format(s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (or (listp format) (setq format (list format)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (let ((do format) f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (while do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (or (setq f (assq (car do) format-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (error "Unknown format" (car do)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 ;; Decode:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (if (nth 3 f) (setq end (funcall (nth 3 f) begin end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 ;; Call visit function if required
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (if (and visit-flag (nth 6 f)) (funcall (nth 6 f) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (setq do (cdr do)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (if visit-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (setq buffer-file-format format))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (set-buffer-modified-p mod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 ;; Return new length of region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (- end begin)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 ;;; Interactive functions & entry points
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (defun format-decode-buffer (&optional format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 "Translate the buffer from some FORMAT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 If the format is not specified, this function attempts to guess.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 `buffer-file-format' is set to the format used, and any mode-functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 for the format are called."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (list (format-read "Translate buffer from format (default: guess): ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (format-decode format (buffer-size) t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (defun format-decode-region (from to &optional format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 "Decode the region from some format.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 Arg FORMAT is optional; if omitted the format will be determined by looking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 for identifying regular expressions at the beginning of the region."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (list (region-beginning) (region-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (format-read "Translate region from format (default: guess): ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (goto-char from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (format-decode format (- to from) nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (defun format-encode-buffer (&optional format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 "Translate the buffer into FORMAT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 FORMAT defaults to `buffer-file-format'. It is a symbol naming one of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 formats defined in `format-alist', or a list of such symbols."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (list (format-read (format "Translate buffer to format (default %s): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 buffer-file-format))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (format-encode-region (point-min) (point-max) format))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (defun format-encode-region (beg end &optional format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 "Translate the region into some FORMAT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 FORMAT defaults to `buffer-file-format', it is a symbol naming
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 one of the formats defined in `format-alist', or a list of such symbols."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (list (region-beginning) (region-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (format-read (format "Translate region to format (default %s): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 buffer-file-format))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (if (null format) (setq format buffer-file-format))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (if (symbolp format) (setq format (list format)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (let ((cur-buf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (end (point-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (while format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (let* ((info (assq (car format) format-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (to-fn (nth 4 info))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (modify (nth 5 info))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (if to-fn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (if modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (setq end (funcall to-fn beg end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (format-insert-annotations (funcall to-fn beg end))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (setq format (cdr format)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (defun format-write-file (filename format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 "Write current buffer into a FILE using some FORMAT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 Makes buffer visit that file and sets the format as the default for future
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 saves. If the buffer is already visiting a file, you can specify a directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 name as FILE, to write a file of the same old name in that directory."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 ;; Same interactive spec as write-file, plus format question.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (let* ((file (if buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (read-file-name "Write file: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 nil nil nil nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (read-file-name "Write file: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (cdr (assq 'default-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (buffer-local-variables)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 nil nil (buffer-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (fmt (format-read (format "Write file `%s' in format: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (file-name-nondirectory file)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (list file fmt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (setq buffer-file-format format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (write-file filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (defun format-find-file (filename format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 "Find the file FILE using data format FORMAT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 If FORMAT is nil then do not do any format conversion."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 ;; Same interactive spec as write-file, plus format question.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (let* ((file (read-file-name "Find file: "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (fmt (format-read (format "Read file `%s' in format: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (file-name-nondirectory file)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (list file fmt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (let ((format-alist nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (find-file filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (if format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (format-decode-buffer format)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (defun format-insert-file (filename format &optional beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 "Insert the contents of file FILE using data format FORMAT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 If FORMAT is nil then do not do any format conversion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 The optional third and fourth arguments BEG and END specify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 the part of the file to read.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 The return value is like the value of `insert-file-contents':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 a list (ABSOLUTE-FILE-NAME . SIZE)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 ;; Same interactive spec as write-file, plus format question.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (let* ((file (read-file-name "Find file: "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (fmt (format-read (format "Read file `%s' in format: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (file-name-nondirectory file)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (list file fmt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (let (value size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (let ((format-alist nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (setq value (insert-file-contents filename nil beg end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (setq size (nth 1 value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (if format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (setq size (format-decode size format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 value (cons (car value) size)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (defun format-read (&optional prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 "Read and return the name of a format.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 Return value is a list, like `buffer-file-format'; it may be nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 Formats are defined in `format-alist'. Optional arg is the PROMPT to use."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (let* ((table (mapcar (lambda (x) (list (symbol-name (car x))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 format-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (ans (completing-read (or prompt "Format: ") table nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (if (not (equal "" ans)) (list (intern ans)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301
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 ;;; Below are some functions that may be useful in writing encoding and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 ;;; decoding functions for use in format-alist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (defun format-replace-strings (alist &optional reverse beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 "Do multiple replacements on the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 ALIST is a list of (from . to) pairs, which should be proper arguments to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 `search-forward' and `replace-match' respectively.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 Optional 2nd arg REVERSE, if non-nil, means the pairs are (to . from), so that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 you can use the same list in both directions if it contains only literal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 Optional args BEGIN and END specify a region of the buffer to operate on."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (or beg (setq beg (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (if end (narrow-to-region (point-min) end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (while alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (let ((from (if reverse (cdr (car alist)) (car (car alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (to (if reverse (car (cdr alist)) (cdr (car alist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (while (search-forward from nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (insert to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (set-text-properties (- (point) (length to)) (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (text-properties-at (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (delete-region (point) (+ (point) (- (match-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (match-beginning 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (setq alist (cdr alist)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 ;;; Some list-manipulation functions that we need.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (defun format-delq-cons (cons list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 "Remove the given CONS from LIST by side effect,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 and return the new LIST. Since CONS could be the first element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 of LIST, write `\(setq foo \(format-delq-cons element foo))' to be sure of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 changing the value of `foo'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (if (eq cons list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (cdr list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (let ((p list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (while (not (eq (cdr p) cons))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (if (null p) (error "format-delq-cons: not an element."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (setq p (cdr p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 ;; Now (cdr p) is the cons to delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (setcdr p (cdr cons))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (defun format-make-relatively-unique (a b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 "Delete common elements of lists A and B, return as pair.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 Compares using `equal'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (let* ((acopy (copy-sequence a))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (bcopy (copy-sequence b))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (tail acopy))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (while tail
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (let ((dup (member (car tail) bcopy))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (next (cdr tail)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (if dup (setq acopy (format-delq-cons tail acopy)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 bcopy (format-delq-cons dup bcopy)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (setq tail next)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (cons acopy bcopy)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (defun format-common-tail (a b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 "Given two lists that have a common tail, return it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 Compares with `equal', and returns the part of A that is equal to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 equivalent part of B. If even the last items of the two are not equal,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 returns nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (let ((la (length a))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (lb (length b)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 ;; Make sure they are the same length
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (if (> la lb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (setq a (nthcdr (- la lb) a))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (setq b (nthcdr (- lb la) b))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (while (not (equal a b))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (setq a (cdr a)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 b (cdr b)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 a)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (defun format-reorder (items order)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 "Arrange ITEMS to following partial ORDER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 Elements of ITEMS equal to elements of ORDER will be rearranged to follow the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 ORDER. Unmatched items will go last."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (if order
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (let ((item (member (car order) items)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (if item
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (cons (car item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (format-reorder (format-delq-cons item items)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (cdr order)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (format-reorder items (cdr order))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 items))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (put 'face 'format-list-valued t) ; These text-properties take values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (put 'unknown 'format-list-valued t) ; that are lists, the elements of which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 ; should be considered separately.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 ; See format-deannotate-region and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 ; format-annotate-region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 ;;; Decoding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (defun format-deannotate-region (from to translations next-fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 "Translate annotations in the region into text properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 This sets text properties between FROM to TO as directed by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 TRANSLATIONS and NEXT-FN arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 NEXT-FN is a function that searches forward from point for an annotation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 It should return a list of 4 elements: \(BEGIN END NAME POSITIVE). BEGIN and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 END are buffer positions bounding the annotation, NAME is the name searched
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 for in TRANSLATIONS, and POSITIVE should be non-nil if this annotation marks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 the beginning of a region with some property, or nil if it ends the region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 NEXT-FN should return nil if there are no annotations after point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 The basic format of the TRANSLATIONS argument is described in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 documentation for the `format-annotate-region' function. There are some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 additional things to keep in mind for decoding, though:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 When an annotation is found, the TRANSLATIONS list is searched for a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 text-property name and value that corresponds to that annotation. If the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 text-property has several annotations associated with it, it will be used only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 if the other annotations are also in effect at that point. The first match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 found whose annotations are all present is used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 The text property thus determined is set to the value over the region between
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 the opening and closing annotations. However, if the text-property name has a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 non-nil `format-list-valued' property, then the value will be consed onto the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 surrounding value of the property, rather than replacing that value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 There are some special symbols that can be used in the \"property\" slot of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 the TRANSLATIONS list: PARAMETER and FUNCTION \(spelled in uppercase).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 Annotations listed under the pseudo-property PARAMETER are considered to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 arguments of the immediately surrounding annotation; the text between the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 opening and closing parameter annotations is deleted from the buffer but saved
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 as a string. The surrounding annotation should be listed under the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 pseudo-property FUNCTION. Instead of inserting a text-property for this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 annotation, the function listed in the VALUE slot is called to make whatever
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 changes are appropriate. The function's first two arguments are the START and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 END locations, and the rest of the arguments are any PARAMETERs found in that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 Any annotations that are found by NEXT-FN but not defined by TRANSLATIONS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 are saved as values of the `unknown' text-property \(which is list-valued).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 The TRANSLATIONS list should usually contain an entry of the form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 \(unknown \(nil format-annotate-value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 to write these unknown annotations back into the file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (narrow-to-region (point-min) to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (goto-char from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (let (next open-ans todo loc unknown-ans)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (while (setq next (funcall next-fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (let* ((loc (nth 0 next))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (end (nth 1 next))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (name (nth 2 next))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (positive (nth 3 next))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (found nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 ;; Delete the annotation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (delete-region loc end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (if positive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 ;; Positive annotations are stacked, remembering location
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (setq open-ans (cons (list name loc) open-ans))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 ;; It is a negative annotation:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 ;; Close the top annotation & add its text property.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 ;; If the file's nesting is messed up, the close might not match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 ;; the top thing on the open-annotations stack.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 ;; If no matching annotation is open, just ignore the close.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (if (not (assoc name open-ans))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (message "Extra closing annotation (%s) in file" name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 ;; If one is open, but not on the top of the stack, close
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 ;; the things in between as well. Set `found' when the real
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 ;; oneis closed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (while (not found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (let* ((top (car open-ans)) ; first on stack: should match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (top-name (car top))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (start (car (cdr top))) ; location of start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (params (cdr (cdr top))) ; parameters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (aalist translations)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (matched nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (if (equal name top-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (setq found t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (message "Improper nesting in file."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 ;; Look through property names in TRANSLATIONS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (while aalist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (let ((prop (car (car aalist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (alist (cdr (car aalist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 ;; And look through values for each property
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (while alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (let ((value (car (car alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (ans (cdr (car alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (if (member top-name ans)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 ;; This annotation is listed, but still have to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 ;; check if multiple annotations are satisfied
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (if (member 'nil (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (lambda (r)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (assoc r open-ans))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 ans))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 nil ; multiple ans not satisfied
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 ;; Yes, use the current property name &
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 ;; value. Set loop variables to nil so loop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 ;; will exit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (setq alist nil aalist nil matched t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 ;; pop annotation off stack.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 open-ans (cdr open-ans))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 ;; Check for pseudo-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 ((eq prop 'PARAMETER)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 ;; This is a parameter of the top open ann:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 ;; delete text and use as arg.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (if open-ans
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 ;; (If nothing open, discard).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (setq open-ans
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (cons (append (car open-ans)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (buffer-substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 start loc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (cdr open-ans))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (delete-region start loc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 ((eq prop 'FUNCTION)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 ;; Not a property, but a function to call.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (let ((rtn (apply value start loc params)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (if rtn (setq todo (cons rtn todo)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 ;; Normal property/value pair
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (setq todo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (cons (list start loc prop value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 todo)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (setq alist (cdr alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (setq aalist (cdr aalist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (if matched
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 ;; Didn't find any match for the annotation:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 ;; Store as value of text-property `unknown'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (setq open-ans (cdr open-ans))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (setq todo (cons (list start loc 'unknown top-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 todo))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (setq unknown-ans (cons name unknown-ans)))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 ;; Once entire file has been scanned, add the properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (while todo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (let* ((item (car todo))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (from (nth 0 item))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (to (nth 1 item))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (prop (nth 2 item))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (val (nth 3 item)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (put-text-property
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 from to prop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (cond ((numberp val) ; add to ambient value if numeric
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (+ val (or (get-text-property from prop) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 ((get prop 'format-list-valued) ; value gets consed onto
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 ; list-valued properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (let ((prev (get-text-property from prop)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (cons val (if (listp prev) prev (list prev)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (t val)))) ; normally, just set to val.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (setq todo (cdr todo)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (if unknown-ans
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (message "Unknown annotations: %s" unknown-ans))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 ;;; Encoding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (defun format-insert-annotations (list &optional offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 "Apply list of annotations to buffer as `write-region' would.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 Inserts each element of the given LIST of buffer annotations at its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 appropriate place. Use second arg OFFSET if the annotations' locations are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 not relative to the beginning of the buffer: annotations will be inserted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 at their location-OFFSET+1 \(ie, the offset is treated as the character number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 of the first character in the buffer)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (if (not offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (setq offset 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (setq offset (1- offset)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (let ((l (reverse list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (while l
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (goto-char (- (car (car l)) offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (insert (cdr (car l)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (setq l (cdr l)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (defun format-annotate-value (old new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 "Return OLD and NEW as a \(close . open) annotation pair.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 Useful as a default function for TRANSLATIONS alist when the value of the text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 property is the name of the annotation that you want to use, as it is for the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 `unknown' text property."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (cons (if old (list old))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (if new (list new))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (defun format-annotate-region (from to trans format-fn ignore)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 "Generate annotations for text properties in the region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 Searches for changes between FROM and TO, and describes them with a list of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 annotations as defined by alist TRANSLATIONS and FORMAT-FN. IGNORE lists text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 properties not to consider; any text properties that are neither ignored nor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 listed in TRANSLATIONS are warned about.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 If you actually want to modify the region, give the return value of this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 function to `format-insert-annotations'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 Format of the TRANSLATIONS argument:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 Each element is a list whose car is a PROPERTY, and the following
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 elements are VALUES of that property followed by the names of zero or more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 ANNOTATIONS. Whenever the property takes on that value, the annotations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 \(as formatted by FORMAT-FN) are inserted into the file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 When the property stops having that value, the matching negated annotation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 will be inserted \(it may actually be closed earlier and reopened, if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 necessary, to keep proper nesting).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 If the property's value is a list, then each element of the list is dealt with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 separately.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 If a VALUE is numeric, then it is assumed that there is a single annotation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 and each occurrence of it increments the value of the property by that number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 Thus, given the entry \(left-margin \(4 \"indent\")), if the left margin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 changes from 4 to 12, two <indent> annotations will be generated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 If the VALUE is nil, then instead of annotations, a function should be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 specified. This function is used as a default: it is called for all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 transitions not explicitly listed in the table. The function is called with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 two arguments, the OLD and NEW values of the property. It should return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 lists of annotations like `format-annotate-location' does.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 The same structure can be used in reverse for reading files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (let ((all-ans nil) ; All annotations - becomes return value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (open-ans nil) ; Annotations not yet closed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (loc nil) ; Current location
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (not-found nil)) ; Properties that couldn't be saved
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (while (or (null loc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (and (setq loc (next-property-change loc nil to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 (< loc to)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 (or loc (setq loc from))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (let* ((ans (format-annotate-location loc (= loc from) ignore trans))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (neg-ans (format-reorder (aref ans 0) open-ans))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (pos-ans (aref ans 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (ignored (aref ans 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (setq not-found (append ignored not-found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 ignore (append ignored ignore))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 ;; First do the negative (closing) annotations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (while neg-ans
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 ;; Check if it's missing. This can happen (eg, a numeric property
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 ;; going negative can generate closing annotations before there are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 ;; any open). Warn user & ignore.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (if (not (member (car neg-ans) open-ans))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (message "Can't close %s: not open." (car neg-ans))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (while (not (equal (car neg-ans) (car open-ans)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 ;; To close anno. N, need to first close ans 1 to N-1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 ;; remembering to re-open them later.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (setq pos-ans (cons (car open-ans) pos-ans))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (setq all-ans
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (cons (cons loc (funcall format-fn (car open-ans) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 all-ans))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (setq open-ans (cdr open-ans)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 ;; Now remove the one we're really interested in from open list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (setq open-ans (cdr open-ans))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 ;; And put the closing annotation here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (setq all-ans
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (cons (cons loc (funcall format-fn (car neg-ans) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 all-ans)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (setq neg-ans (cdr neg-ans)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 ;; Now deal with positive (opening) annotations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (let ((p pos-ans))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (while pos-ans
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (setq open-ans (cons (car pos-ans) open-ans))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (setq all-ans
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (cons (cons loc (funcall format-fn (car pos-ans) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 all-ans))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (setq pos-ans (cdr pos-ans))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 ;; Close any annotations still open
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (while open-ans
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (setq all-ans
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (cons (cons to (funcall format-fn (car open-ans) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 all-ans))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 (setq open-ans (cdr open-ans)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (if not-found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (message "These text properties could not be saved:\n %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 not-found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (nreverse all-ans)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 ;;; Internal functions for format-annotate-region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (defun format-annotate-location (loc all ignore trans)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 "Return annotation(s) needed at LOCATION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 This includes any properties that change between LOC-1 and LOC.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 If ALL is true, don't look at previous location, but generate annotations for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 all non-nil properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 Third argument IGNORE is a list of text-properties not to consider.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 Return value is a vector of 3 elements:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 1. List of names of the annotations to close
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 2. List of the names of annotations to open.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 3. List of properties that were ignored or couldn't be annotated."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (let* ((prev-loc (1- loc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 (before-plist (if all nil (text-properties-at prev-loc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (after-plist (text-properties-at loc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 p negatives positives prop props not-found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 ;; make list of all property names involved
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (setq p before-plist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 (while p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 (if (not (memq (car p) props))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 (setq props (cons (car p) props)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 (setq p (cdr (cdr p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (setq p after-plist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (while p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 (if (not (memq (car p) props))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 (setq props (cons (car p) props)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 (setq p (cdr (cdr p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (while props
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 (setq prop (car props)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 props (cdr props))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 (if (memq prop ignore)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 nil ; If it's been ignored before, ignore it now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (let ((before (if all nil (car (cdr (memq prop before-plist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 (after (car (cdr (memq prop after-plist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 (if (equal before after)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 nil ; no change; ignore
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (let ((result (format-annotate-single-property-change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 prop before after trans)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (if (not result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (setq not-found (cons prop not-found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (setq negatives (nconc negatives (car result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 positives (nconc positives (cdr result)))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (vector negatives positives not-found)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (defun format-annotate-single-property-change (prop old new trans)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 "Return annotations for PROPERTY changing from OLD to NEW.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 These are searched for in the TRANSLATIONS alist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 If NEW does not appear in the list, but there is a default function, then that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 function is called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 Annotations to open and to close are returned as a dotted pair."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 (let ((prop-alist (cdr (assoc prop trans)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 (if (not prop-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 ;; If property is numeric, nil means 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 (cond ((and (numberp old) (null new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (numberp (car (car prop-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 (setq new 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 ((and (numberp new) (null old)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (numberp (car (car prop-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (setq old 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 ;; If either old or new is a list, have to treat both that way.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 (if (or (consp old) (consp new))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (let* ((old (if (listp old) old (list old)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (new (if (listp new) new (list new)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (tail (format-common-tail old new))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 close open)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (while old
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (setq close
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 (append (car (format-annotate-atomic-property-change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 prop-alist (car old) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 close)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 old (cdr old)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (while new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (setq open
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (append (cdr (format-annotate-atomic-property-change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 prop-alist nil (car new)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 open)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 new (cdr new)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (format-make-relatively-unique close open))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 (format-annotate-atomic-property-change prop-alist old new)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 (defun format-annotate-atomic-property-change (prop-alist old new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 "Internal function annotate a single property change.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 PROP-ALIST is the relevant segement of a TRANSLATIONS list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 OLD and NEW are the values."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 ;; Numerical annotation - use difference
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 ((and (numberp old) (numberp new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (numberp (car (car prop-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 (let* ((entry (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (while (and (car (car prop-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (not (numberp (car (car prop-alist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (setq prop-alist (cdr prop-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (car prop-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (increment (car (car prop-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (n (ceiling (/ (float (- new old)) (float increment))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (anno (car (cdr (car prop-alist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 (if (> n 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (cons nil (make-list n anno))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (cons (make-list (- n) anno) nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 ;; Standard annotation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 (t (let ((close (and old (cdr (assoc old prop-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 (open (and new (cdr (assoc new prop-alist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 (if (or close open)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 (format-make-relatively-unique close open)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 ;; Call "Default" function, if any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 (let ((default (assq nil prop-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 (if default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 (funcall (car (cdr default)) old new))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 ;; format.el ends here