diff options
| author | Richard M. Stallman | 1996-09-01 03:25:54 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1996-09-01 03:25:54 +0000 |
| commit | d1abb42fc8051d53da10f2decfe436ddf599b378 (patch) | |
| tree | 3699bb4c3ec882c785d4273269c606553acd3a2b /lisp | |
| parent | 965eb84afdfe12fb2d037b5019d0308b06df1653 (diff) | |
| download | emacs-d1abb42fc8051d53da10f2decfe436ddf599b378.tar.gz emacs-d1abb42fc8051d53da10f2decfe436ddf599b378.zip | |
(format-alist): Doc fix.
(format-annotate-function): New argument ORIG-BUF, passed on to TO-FN.
(format-encode-region): Let TO-FN know that our current buffer is
its ORIG-BUF.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/format.el | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/lisp/format.el b/lisp/format.el index 929be66cdef..0c7774d26ed 100644 --- a/lisp/format.el +++ b/lisp/format.el | |||
| @@ -83,20 +83,25 @@ FROM-FN is called to decode files in that format; it gets two args, BEGIN | |||
| 83 | and END, and can make any modifications it likes, returning the new | 83 | and END, and can make any modifications it likes, returning the new |
| 84 | end. It must make sure that the beginning of the file no longer | 84 | end. It must make sure that the beginning of the file no longer |
| 85 | matches REGEXP, or else it will get called again. | 85 | matches REGEXP, or else it will get called again. |
| 86 | TO-FN is called to encode a region into that format; it is also passed BEGIN | 86 | TO-FN is called to encode a region into that format; it is passed three |
| 87 | and END, and either returns a list of annotations like | 87 | arguments: BEGIN, END, and BUFFER. BUFFER is the original buffer that |
| 88 | `write-region-annotate-functions', or modifies the region and returns | 88 | the data being written came from, which the function could use, for |
| 89 | the new end. | 89 | example, to find the values of local variables. TO-FN should either |
| 90 | MODIFY, if non-nil, means the TO-FN modifies the region. If nil, TO-FN may | 90 | return a list of annotations like `write-region-annotate-functions', |
| 91 | not make any changes and should return a list of annotations. | 91 | or modify the region and return the new end. |
| 92 | MODIFY, if non-nil, means the TO-FN wants to modify the region. If nil, | ||
| 93 | TO-FN will not make any changes but will instead return a list of | ||
| 94 | annotations. | ||
| 92 | MODE-FN, if specified, is called when visiting a file with that format.") | 95 | MODE-FN, if specified, is called when visiting a file with that format.") |
| 93 | 96 | ||
| 94 | ;;; Basic Functions (called from Lisp) | 97 | ;;; Basic Functions (called from Lisp) |
| 95 | 98 | ||
| 96 | (defun format-annotate-function (format from to) | 99 | (defun format-annotate-function (format from to orig-buf) |
| 97 | "Returns annotations for writing region as FORMAT. | 100 | "Returns annotations for writing region as FORMAT. |
| 98 | FORMAT is a symbol naming one of the formats defined in `format-alist', | 101 | FORMAT is a symbol naming one of the formats defined in `format-alist', |
| 99 | it must be a single symbol, not a list like `buffer-file-format'. | 102 | it must be a single symbol, not a list like `buffer-file-format'. |
| 103 | FROM and TO delimit the region to be operated on in the current buffer. | ||
| 104 | ORIG-BUF is the original buffer that the data came from. | ||
| 100 | This function works like a function on `write-region-annotate-functions': | 105 | This function works like a function on `write-region-annotate-functions': |
| 101 | it either returns a list of annotations, or returns with a different buffer | 106 | it either returns a list of annotations, or returns with a different buffer |
| 102 | current, which contains the modified text to write. | 107 | current, which contains the modified text to write. |
| @@ -114,10 +119,10 @@ For most purposes, consider using `format-encode-region' instead." | |||
| 114 | (copy-to-buffer copy-buf from to) | 119 | (copy-to-buffer copy-buf from to) |
| 115 | (set-buffer copy-buf) | 120 | (set-buffer copy-buf) |
| 116 | (format-insert-annotations write-region-annotations-so-far from) | 121 | (format-insert-annotations write-region-annotations-so-far from) |
| 117 | (funcall to-fn (point-min) (point-max)) | 122 | (funcall to-fn (point-min) (point-max) orig-buf) |
| 118 | nil) | 123 | nil) |
| 119 | ;; Otherwise just call function, it will return annotations. | 124 | ;; Otherwise just call function, it will return annotations. |
| 120 | (funcall to-fn from to))))) | 125 | (funcall to-fn from to orig-buf))))) |
| 121 | 126 | ||
| 122 | (defun format-decode (format length &optional visit-flag) | 127 | (defun format-decode (format length &optional visit-flag) |
| 123 | ;; This function is called by insert-file-contents whenever a file is read. | 128 | ;; This function is called by insert-file-contents whenever a file is read. |
| @@ -232,8 +237,9 @@ one of the formats defined in `format-alist', or a list of such symbols." | |||
| 232 | result) | 237 | result) |
| 233 | (if to-fn | 238 | (if to-fn |
| 234 | (if modify | 239 | (if modify |
| 235 | (setq end (funcall to-fn beg end)) | 240 | (setq end (funcall to-fn beg end (current-buffer))) |
| 236 | (format-insert-annotations (funcall to-fn beg end)))) | 241 | (format-insert-annotations |
| 242 | (funcall to-fn beg end (current-buffer))))) | ||
| 237 | (setq format (cdr format))))))) | 243 | (setq format (cdr format))))))) |
| 238 | 244 | ||
| 239 | (defun format-write-file (filename format) | 245 | (defun format-write-file (filename format) |