-;; Copyright (c) 1994, 1995, 1997, 1999 Free Software Foundation
+;; Copyright (C) 1994, 1995, 1997, 1999, 2001, 2002, 2003, 2004,
+;; 2005, 2006 Free Software Foundation, Inc.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;; change this variable, or use `format-write-file'.
;;
;; Auto-save files are normally created in the same format as the visited
;; change this variable, or use `format-write-file'.
;;
;; Auto-save files are normally created in the same format as the visited
;; particularly fast or otherwise preferred format to be used for
;; auto-saving (or nil to do no encoding on auto-save files, but then you
;; risk losing any text-properties in the buffer).
;; particularly fast or otherwise preferred format to be used for
;; auto-saving (or nil to do no encoding on auto-save files, but then you
;; risk losing any text-properties in the buffer).
REGEXP is a regular expression to match against the beginning of the file;
it should match only files in that format. Use nil to avoid
REGEXP is a regular expression to match against the beginning of the file;
it should match only files in that format. Use nil to avoid
and END, and can make any modifications it likes, returning the new
end. It must make sure that the beginning of the file no longer
matches REGEXP, or else it will get called again.
Alternatively, FROM-FN can be a string, which specifies a shell command
(including options) to be used as a filter to perform the conversion.
and END, and can make any modifications it likes, returning the new
end. It must make sure that the beginning of the file no longer
matches REGEXP, or else it will get called again.
Alternatively, FROM-FN can be a string, which specifies a shell command
(including options) to be used as a filter to perform the conversion.
arguments: BEGIN, END, and BUFFER. BUFFER is the original buffer that
the data being written came from, which the function could use, for
example, to find the values of local variables. TO-FN should either
arguments: BEGIN, END, and BUFFER. BUFFER is the original buffer that
the data being written came from, which the function could use, for
example, to find the values of local variables. TO-FN should either
MODE-FN, if specified, is called when visiting a file with that format.
It is called with a single positive argument, on the assumption
MODE-FN, if specified, is called when visiting a file with that format.
It is called with a single positive argument, on the assumption
PRESERVE, if non-nil, means that `format-write-file' should not remove
this format from `buffer-file-formats'.")
PRESERVE, if non-nil, means that `format-write-file' should not remove
this format from `buffer-file-formats'.")
;;; Basic Functions (called from Lisp)
(defun format-encode-run-method (method from to &optional buffer)
;;; Basic Functions (called from Lisp)
(defun format-encode-run-method (method from to &optional buffer)
- "Translate using function or shell script METHOD the text from FROM to TO.
-If METHOD is a string, it is a shell command;
+ "Translate using METHOD the text from FROM to TO.
+If METHOD is a string, it is a shell command (including options);
otherwise, it should be a Lisp function.
BUFFER should be the buffer that the output originally came from."
(if (stringp method)
otherwise, it should be a Lisp function.
BUFFER should be the buffer that the output originally came from."
(if (stringp method)
- "Decode using function or shell script METHOD the text from FROM to TO.
-If METHOD is a string, it is a shell command; otherwise, it should be
-a Lisp function. Decoding is done for the given BUFFER."
+ "Decode using METHOD the text from FROM to TO.
+If METHOD is a string, it is a shell command (including options); otherwise,
+it should be a Lisp function. Decoding is done for the given BUFFER."
(defun format-annotate-function (format from to orig-buf format-count)
"Return annotations for writing region as FORMAT.
(defun format-annotate-function (format from to orig-buf format-count)
"Return annotations for writing region as FORMAT.
-FORMAT is a symbol naming one of the formats defined in `format-alist',
-it must be a single symbol, not a list like `buffer-file-format'.
+FORMAT is a symbol naming one of the formats defined in `format-alist'.
+It must be a single symbol, not a list like `buffer-file-format'.
FROM and TO delimit the region to be operated on in the current buffer.
ORIG-BUF is the original buffer that the data came from.
FORMAT-COUNT is an integer specifying how many times this function has
been called in the process of decoding ORIG-BUF.
FROM and TO delimit the region to be operated on in the current buffer.
ORIG-BUF is the original buffer that the data came from.
FORMAT-COUNT is an integer specifying how many times this function has
been called in the process of decoding ORIG-BUF.
it either returns a list of annotations, or returns with a different buffer
current, which contains the modified text to write. In the latter case,
this function's value is nil.
it either returns a list of annotations, or returns with a different buffer
current, which contains the modified text to write. In the latter case,
this function's value is nil.
For most purposes, consider using `format-decode-region' instead."
(let ((mod (buffer-modified-p))
For most purposes, consider using `format-decode-region' instead."
(let ((mod (buffer-modified-p))
-If the format is not specified, this function attempts to guess.
-`buffer-file-format' is set to the format used, and any mode-functions
-for the format are called."
+If the format is not specified, attempt a regexp-based guess.
+Set `buffer-file-format' to the format used, and call any
+format-specific mode functions."
for identifying regular expressions at the beginning of the region."
(interactive
(list (region-beginning) (region-end)
for identifying regular expressions at the beginning of the region."
(interactive
(list (region-beginning) (region-end)
one of the formats defined in `format-alist', or a list of such symbols."
(interactive
(list (region-beginning) (region-end)
one of the formats defined in `format-alist', or a list of such symbols."
(interactive
(list (region-beginning) (region-end)
-name as FILENAME, to write a file of the same old name in that directory."
+name as FILENAME, to write a file of the same old name in that directory.
+
+If optional third arg CONFIRM is non-nil, ask for confirmation before
+overwriting an existing file. Interactively, confirmation is required
+unless you supply a prefix argument."
(interactive
;; Same interactive spec as write-file, plus format question.
(let* ((file (if buffer-file-name
(interactive
;; Same interactive spec as write-file, plus format question.
(let* ((file (if buffer-file-name
(dolist (fmt preserve-formats)
(unless (memq fmt buffer-file-format)
(setq buffer-file-format (append buffer-file-format (list fmt))))))
(dolist (fmt preserve-formats)
(unless (memq fmt buffer-file-format)
(setq buffer-file-format (append buffer-file-format (list fmt))))))
"Insert the contents of file FILENAME using data format FORMAT.
If FORMAT is nil then do not do any format conversion.
The optional third and fourth arguments BEG and END specify
"Insert the contents of file FILENAME using data format FORMAT.
If FORMAT is nil then do not do any format conversion.
The optional third and fourth arguments BEG and END specify
(interactive
;; Same interactive spec as write-file, plus format question.
(let* ((file (read-file-name "Find file: "))
(interactive
;; Same interactive spec as write-file, plus format question.
(let* ((file (read-file-name "Find file: "))
(defun format-replace-strings (alist &optional reverse beg end)
"Do multiple replacements on the buffer.
ALIST is a list of (FROM . TO) pairs, which should be proper arguments to
(defun format-replace-strings (alist &optional reverse beg end)
"Do multiple replacements on the buffer.
ALIST is a list of (FROM . TO) pairs, which should be proper arguments to
-`search-forward' and `replace-match' respectively.
-Optional 2nd arg REVERSE, if non-nil, means the pairs are (TO . FROM), so that
-you can use the same list in both directions if it contains only literal
-strings.
+`search-forward' and `replace-match', respectively.
+Optional second arg REVERSE, if non-nil, means the pairs are (TO . FROM),
+so that you can use the same list in both directions if it contains only
+literal strings.
(defun format-make-relatively-unique (a b)
"Delete common elements of lists A and B, return as pair.
(defun format-make-relatively-unique (a b)
"Delete common elements of lists A and B, return as pair.
(defun format-common-tail (a b)
"Given two lists that have a common tail, return it.
(defun format-common-tail (a b)
"Given two lists that have a common tail, return it.
- "Arrange ITEMS to following partial ORDER.
-Elements of ITEMS equal to elements of ORDER will be rearranged to follow the
-ORDER. Unmatched items will go last."
+ "Arrange ITEMS to follow partial ORDER.
+Elements of ITEMS equal to elements of ORDER will be rearranged
+to follow the ORDER. Unmatched items will go last."
A region is a dotted pair (FROM . TO). Both parameters are lists of
regions. Each list must contain nonoverlapping, noncontiguous
regions, in descending order. The result is also nonoverlapping,
noncontiguous, and in descending order. The first element of MINUEND
can have a cdr of nil, indicating that the end of that region is not
A region is a dotted pair (FROM . TO). Both parameters are lists of
regions. Each list must contain nonoverlapping, noncontiguous
regions, in descending order. The result is also nonoverlapping,
noncontiguous, and in descending order. The first element of MINUEND
can have a cdr of nil, indicating that the end of that region is not
;; next-single-property-change instead of text-property-not-all, but then
;; we have to see if we passed TO.
(defun format-property-increment-region (from to prop delta default)
;; next-single-property-change instead of text-property-not-all, but then
;; we have to see if we passed TO.
(defun format-property-increment-region (from to prop delta default)
DELTA may be negative. If property PROP is nil anywhere
in the region, it is treated as though it were DEFAULT."
(let ((cur from) val newval next)
DELTA may be negative. If property PROP is nil anywhere
in the region, it is treated as though it were DEFAULT."
(let ((cur from) val newval next)
(defun format-insert-annotations (list &optional offset)
"Apply list of annotations to buffer as `write-region' would.
(defun format-insert-annotations (list &optional offset)
"Apply list of annotations to buffer as `write-region' would.
appropriate place. Use second arg OFFSET if the annotations' locations are
not relative to the beginning of the buffer: annotations will be inserted
appropriate place. Use second arg OFFSET if the annotations' locations are
not relative to the beginning of the buffer: annotations will be inserted
-at their location-OFFSET+1 \(ie, the offset is treated as the character number
-of the first character in the buffer)."
+at their location-OFFSET+1 \(ie, the offset is treated as the position of
+the first character in the buffer)."
(defun format-annotate-region (from to translations format-fn ignore)
"Generate annotations for text properties in the region.
(defun format-annotate-region (from to translations format-fn ignore)
"Generate annotations for text properties in the region.
annotations as defined by alist TRANSLATIONS and FORMAT-FN. IGNORE lists text
properties not to consider; any text properties that are neither ignored nor
listed in TRANSLATIONS are warned about.
annotations as defined by alist TRANSLATIONS and FORMAT-FN. IGNORE lists text
properties not to consider; any text properties that are neither ignored nor
listed in TRANSLATIONS are warned about.
(defun format-annotate-location (loc all ignore translations)
"Return annotation(s) needed at location LOC.
(defun format-annotate-location (loc all ignore translations)
"Return annotation(s) needed at location LOC.
If ALL is true, don't look at previous location, but generate annotations for
all non-nil properties.
Third argument IGNORE is a list of text-properties not to consider.
If ALL is true, don't look at previous location, but generate annotations for
all non-nil properties.
Third argument IGNORE is a list of text-properties not to consider.
"Return annotations for property PROP changing from OLD to NEW.
These are searched for in the translations alist TRANSLATIONS
(see `format-annotate-region' for the format).
"Return annotations for property PROP changing from OLD to NEW.
These are searched for in the translations alist TRANSLATIONS
(see `format-annotate-region' for the format).
-If NEW does not appear in the list, but there is a default function, then that
-function is called.
-Returns a cons of the form (CLOSE . OPEN)
+If NEW does not appear in the list, but there is a default function,
+then call that function.
+Return a cons of the form (CLOSE . OPEN)
(format-annotate-atomic-property-change prop-alist old new)))))
(defun format-annotate-atomic-property-change (prop-alist old new)
(format-annotate-atomic-property-change prop-alist old new)))))
(defun format-annotate-atomic-property-change (prop-alist old new)