aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThien-Thi Nguyen2007-05-10 08:43:56 +0000
committerThien-Thi Nguyen2007-05-10 08:43:56 +0000
commited9bc8a2e6603eff98f0894b782c3d98d1e877aa (patch)
tree47d50cfd66d5f38dc461378255f83d7bd49f9dad
parent00affaf137861756b1d4e6e9a8a65c990261367c (diff)
downloademacs-ed9bc8a2e6603eff98f0894b782c3d98d1e877aa.tar.gz
emacs-ed9bc8a2e6603eff98f0894b782c3d98d1e877aa.zip
* elisp.texi (Top): Remove "Saving Properties" from detailed menu.
* files.texi (Format Conversion): Expand intro; add menu. (Format Conversion Overview, Format Conversion Round-Trip) (Format Conversion Piecemeal): New nodes/subsections. * hooks.texi: Xref "Format Conversion" , not "Saving Properties". * text.texi (Text Properties): Remove "Saving Properties" from menu. (Saving Properties): Delete node/subsection.
-rw-r--r--lispref/ChangeLog12
-rw-r--r--lispref/elisp.texi2
-rw-r--r--lispref/files.texi162
-rw-r--r--lispref/hooks.texi4
-rw-r--r--lispref/text.texi71
5 files changed, 159 insertions, 92 deletions
diff --git a/lispref/ChangeLog b/lispref/ChangeLog
index 9b5427cdc75..5d340be7818 100644
--- a/lispref/ChangeLog
+++ b/lispref/ChangeLog
@@ -1,3 +1,13 @@
12007-05-10 Thien-Thi Nguyen <ttn@gnuvola.org>
2
3 * elisp.texi (Top): Remove "Saving Properties" from detailed menu.
4 * files.texi (Format Conversion): Expand intro; add menu.
5 (Format Conversion Overview, Format Conversion Round-Trip)
6 (Format Conversion Piecemeal): New nodes/subsections.
7 * hooks.texi: Xref "Format Conversion" , not "Saving Properties".
8 * text.texi (Text Properties): Remove "Saving Properties" from menu.
9 (Saving Properties): Delete node/subsection.
10
12007-05-07 Karl Berry <karl@gnu.org> 112007-05-07 Karl Berry <karl@gnu.org>
2 12
3 * elisp.texi (EMACSVER): back to 22. 13 * elisp.texi (EMACSVER): back to 22.
@@ -385,7 +395,7 @@
385 395
386 * loading.texi (How Programs Do Loading): Fix anchor position at 396 * loading.texi (How Programs Do Loading): Fix anchor position at
387 load-read-function definition doc. (tiny change) 397 load-read-function definition doc. (tiny change)
388 398
3892007-02-21 Kim F. Storm <storm@cua.dk> 3992007-02-21 Kim F. Storm <storm@cua.dk>
390 400
391 * strings.texi (Text Comparison): Mention that assoc-string 401 * strings.texi (Text Comparison): Mention that assoc-string
diff --git a/lispref/elisp.texi b/lispref/elisp.texi
index 5d73a38e3fc..dca788bf54d 100644
--- a/lispref/elisp.texi
+++ b/lispref/elisp.texi
@@ -1066,8 +1066,6 @@ Text Properties
1066* Format Properties:: Properties for representing formatting of text. 1066* Format Properties:: Properties for representing formatting of text.
1067* Sticky Properties:: How inserted text gets properties from 1067* Sticky Properties:: How inserted text gets properties from
1068 neighboring text. 1068 neighboring text.
1069* Saving Properties:: Saving text properties in files, and reading
1070 them back.
1071* Lazy Properties:: Computing text properties in a lazy fashion 1069* Lazy Properties:: Computing text properties in a lazy fashion
1072 only when text is examined. 1070 only when text is examined.
1073* Clickable Text:: Using text properties to make regions of text 1071* Clickable Text:: Using text properties to make regions of text
diff --git a/lispref/files.texi b/lispref/files.texi
index 656dbf346dc..1df6aead199 100644
--- a/lispref/files.texi
+++ b/lispref/files.texi
@@ -374,8 +374,7 @@ buffer name instead.
374@end deffn 374@end deffn
375 375
376 Saving a buffer runs several hooks. It also performs format 376 Saving a buffer runs several hooks. It also performs format
377conversion (@pxref{Format Conversion}), and may save text properties in 377conversion (@pxref{Format Conversion}).
378``annotations'' (@pxref{Saving Properties}).
379 378
380@defvar write-file-functions 379@defvar write-file-functions
381The value of this variable is a list of functions to be called before 380The value of this variable is a list of functions to be called before
@@ -496,9 +495,9 @@ and the length of the data inserted. An error is signaled if
496 495
497The function @code{insert-file-contents} checks the file contents 496The function @code{insert-file-contents} checks the file contents
498against the defined file formats, and converts the file contents if 497against the defined file formats, and converts the file contents if
499appropriate. @xref{Format Conversion}. It also calls the functions in 498appropriate and also calls the functions in
500the list @code{after-insert-file-functions}; see @ref{Saving 499the list @code{after-insert-file-functions}. @xref{Format Conversion}.
501Properties}. Normally, one of the functions in the 500Normally, one of the functions in the
502@code{after-insert-file-functions} list determines the coding system 501@code{after-insert-file-functions} list determines the coding system
503(@pxref{Coding Systems}) used for decoding the file's contents, 502(@pxref{Coding Systems}) used for decoding the file's contents,
504including end-of-line conversion. 503including end-of-line conversion.
@@ -620,9 +619,10 @@ file name to use for purposes of locking and unlocking, overriding
620@var{filename} and @var{visit} for that purpose. 619@var{filename} and @var{visit} for that purpose.
621 620
622The function @code{write-region} converts the data which it writes to 621The function @code{write-region} converts the data which it writes to
623the appropriate file formats specified by @code{buffer-file-format}. 622the appropriate file formats specified by @code{buffer-file-format}
624@xref{Format Conversion}. It also calls the functions in the list 623and also calls the functions in the list
625@code{write-region-annotate-functions}; see @ref{Saving Properties}. 624@code{write-region-annotate-functions}.
625@xref{Format Conversion}.
626 626
627Normally, @code{write-region} displays the message @samp{Wrote 627Normally, @code{write-region} displays the message @samp{Wrote
628@var{filename}} in the echo area. If @var{visit} is neither @code{t} 628@var{filename}} in the echo area. If @var{visit} is neither @code{t}
@@ -2802,23 +2802,70 @@ is a good way to come up with one.
2802@cindex file format conversion 2802@cindex file format conversion
2803@cindex encoding file formats 2803@cindex encoding file formats
2804@cindex decoding file formats 2804@cindex decoding file formats
2805 The variable @code{format-alist} defines a list of @dfn{file formats}, 2805@cindex text properties in files
2806which describe textual representations used in files for the data (text, 2806@cindex saving text properties
2807text-properties, and possibly other information) in an Emacs buffer. 2807 Emacs performs several steps to convert the data in a buffer (text,
2808Emacs performs format conversion if appropriate when reading and writing 2808text properties, and possibly other information) to and from a
2809files. 2809representation suitable for storing into a file. This section describes
2810the fundamental functions that perform this @dfn{format conversion},
2811namely @code{insert-file-contents} for reading a file into a buffer,
2812and @code{write-region} for writing a buffer into a file.
2813
2814@menu
2815* Overview: Format Conversion Overview. @code{insert-file-contents} and @code{write-region}
2816* Round-Trip: Format Conversion Round-Trip. Using @code{format-alist}.
2817* Piecemeal: Format Conversion Piecemeal. Specifying non-paired conversion.
2818@end menu
2819
2820@node Format Conversion Overview
2821@subsection Overview
2822@noindent
2823The function @code{insert-file-contents}:
2824
2825@itemize
2826@item initially, inserts bytes from the file into the buffer;
2827@item decodes bytes to characters as appropriate;
2828@item processes formats as defined by entries in @code{format-alist}; and
2829@item calls functions in @code{after-insert-file-functions}.
2830@end itemize
2831
2832@noindent
2833The function @code{write-region}:
2834
2835@itemize
2836@item initially, calls functions in @code{write-region-annotate-functions};
2837@item processes formats as defined by entries in @code{format-alist};
2838@item encodes characters to bytes as appropriate; and
2839@item modifies the file with the bytes.
2840@end itemize
2841
2842 This shows the symmetry of the lowest-level operations; reading and
2843writing handle things in opposite order. The rest of this section
2844describes the two facilities surrounding the three variables named
2845above, as well as some related functions. @ref{Coding Systems}, for
2846details on character encoding and decoding.
2847
2848@node Format Conversion Round-Trip
2849@subsection Round-Trip Specification
2850
2851 The most general of the two facilities is controlled by the variable
2852@code{format-alist}, a list of @dfn{file format} specifications, which
2853describe textual representations used in files for the data in an Emacs
2854buffer. The descriptions for reading and writing are paired, which is
2855why we call this ``round-trip'' specification
2856(@pxref{Format Conversion Piecemeal}, for non-paired specification).
2810 2857
2811@defvar format-alist 2858@defvar format-alist
2812This list contains one format definition for each defined file format. 2859This list contains one format definition for each defined file format.
2813@end defvar
2814
2815@cindex format definition
2816Each format definition is a list of this form: 2860Each format definition is a list of this form:
2817 2861
2818@example 2862@example
2819(@var{name} @var{doc-string} @var{regexp} @var{from-fn} @var{to-fn} @var{modify} @var{mode-fn}) 2863(@var{name} @var{doc-string} @var{regexp} @var{from-fn} @var{to-fn} @var{modify} @var{mode-fn})
2820@end example 2864@end example
2865@end defvar
2821 2866
2867@cindex format definition
2868@noindent
2822Here is what the elements in a format definition mean: 2869Here is what the elements in a format definition mean:
2823 2870
2824@table @var 2871@table @var
@@ -2956,6 +3003,89 @@ regular save in the same buffer. This variable is always buffer-local
2956in all buffers. 3003in all buffers.
2957@end defvar 3004@end defvar
2958 3005
3006@node Format Conversion Piecemeal
3007@subsection Piecemeal Specification
3008
3009 In contrast to the round-trip specification described in the previous
3010subsection (@pxref{Format Conversion Round-Trip}), you can use the variables
3011@code{after-insert-file-functions} and @code{write-region-annotate-functions}
3012to separately control the respective reading and writing conversions.
3013
3014 Conversion starts with one representation and produces another
3015representation. When there is only one conversion to do, there is no
3016conflict about what to start with. However, when there are multiple
3017conversions involved, conflict may arise when two conversions need to
3018start with the same data.
3019
3020 This situation is best understood in the context of converting text
3021properties during @code{write-region}. For example, the character at
3022position 42 in a buffer is @samp{X} with a text property @code{foo}. If
3023the conversion for @code{foo} is done by inserting into the buffer, say,
3024@samp{FOO:}, then that changes the character at position 42 from
3025@samp{X} to @samp{F}. The next conversion will start with the wrong
3026data straight away.
3027
3028 To avoid conflict, cooperative conversions do not modify the buffer,
3029but instead specify @dfn{annotations}, a list of elements of the form
3030@code{(@var{position} . @var{string})}, sorted in order of increasing
3031@var{position}.
3032
3033 If there is more than one conversion, @code{write-region} merges their
3034annotations destructively into one sorted list. Later, when the text
3035from the buffer is actually written to the file, it intermixes the
3036specified annotations at the corresponding positions. All this takes
3037place without modifying the buffer.
3038
3039@c ??? What about ``overriding'' conversions like those allowed
3040@c ??? for `write-region-annotate-functions', below? --ttn
3041
3042 In contrast, when reading, the annotations intermixed with the text
3043are handled immediately. @code{insert-file-contents} sets point to the
3044beginning of some text to be converted, then calls the conversion
3045functions with the length of that text. These functions should always
3046return with point at the beginning of the inserted text. This approach
3047makes sense for reading because annotations removed by the first
3048converter can't be mistakenly processed by a later converter.
3049
3050 Each conversion function should scan for the annotations it
3051recognizes, remove the annotation, modify the buffer text (to set a text
3052property, for example), and return the updated length of the text, as it
3053stands after those changes. The value returned by one function becomes
3054the argument to the next function.
3055
3056@defvar write-region-annotate-functions
3057A list of functions for @code{write-region} to call. Each function in
3058the list is called with two arguments: the start and end of the region
3059to be written. These functions should not alter the contents of the
3060buffer. Instead, they should return annotations.
3061
3062@c ??? Following adapted from comment in `build_annotations' (fileio.c).
3063@c ??? Perhaps this is intended for internal use only?
3064@c ??? Someone who understands this, please reword it. --ttn
3065As a special case, if a function returns with a different buffer
3066current, Emacs takes it to mean the current buffer contains altered text
3067to be output, and discards all previous annotations because they should
3068have been dealt with by this function.
3069@end defvar
3070
3071@defvar after-insert-file-functions
3072Each function in this list is called by @code{insert-file-contents}
3073with one argument, the number of characters inserted, and should
3074return the new character count, leaving point the same.
3075@c ??? The docstring mentions a handler from `file-name-handler-alist'
3076@c "intercepting" `insert-file-contents'. Hmmm. --ttn
3077@end defvar
3078
3079 We invite users to write Lisp programs to store and retrieve text
3080properties in files, using these hooks, and thus to experiment with
3081various data formats and find good ones. Eventually we hope users
3082will produce good, general extensions we can install in Emacs.
3083
3084 We suggest not trying to handle arbitrary Lisp objects as text property
3085names or values---because a program that general is probably difficult
3086to write, and slow. Instead, choose a set of possible data types that
3087are reasonably flexible, and not too hard to encode.
3088
2959@ignore 3089@ignore
2960 arch-tag: 141f74ce-6ae3-40dc-a6c4-ef83fc4ec35c 3090 arch-tag: 141f74ce-6ae3-40dc-a6c4-ef83fc4ec35c
2961@end ignore 3091@end ignore
diff --git a/lispref/hooks.texi b/lispref/hooks.texi
index 019777f5eed..572d3b79d93 100644
--- a/lispref/hooks.texi
+++ b/lispref/hooks.texi
@@ -48,7 +48,7 @@ or their values are used). The variables whose names end in
48@xref{Init File}. 48@xref{Init File}.
49 49
50@item after-insert-file-functions 50@item after-insert-file-functions
51@xref{Saving Properties}. 51@xref{Format Conversion}.
52 52
53@item after-make-frame-functions 53@item after-make-frame-functions
54@xref{Creating Frames}. 54@xref{Creating Frames}.
@@ -330,7 +330,7 @@ Manual}.
330@xref{Saving Buffers}. 330@xref{Saving Buffers}.
331 331
332@item write-region-annotate-functions 332@item write-region-annotate-functions
333@xref{Saving Properties}. 333@xref{Format Conversion}.
334@end table 334@end table
335 335
336@ignore 336@ignore
diff --git a/lispref/text.texi b/lispref/text.texi
index b8c344e0e7a..e5a7e73a528 100644
--- a/lispref/text.texi
+++ b/lispref/text.texi
@@ -2577,8 +2577,6 @@ along with the characters; this includes such diverse functions as
2577* Format Properties:: Properties for representing formatting of text. 2577* Format Properties:: Properties for representing formatting of text.
2578* Sticky Properties:: How inserted text gets properties from 2578* Sticky Properties:: How inserted text gets properties from
2579 neighboring text. 2579 neighboring text.
2580* Saving Properties:: Saving text properties in files, and reading
2581 them back.
2582* Lazy Properties:: Computing text properties in a lazy fashion 2580* Lazy Properties:: Computing text properties in a lazy fashion
2583 only when text is examined. 2581 only when text is examined.
2584* Clickable Text:: Using text properties to make regions of text 2582* Clickable Text:: Using text properties to make regions of text
@@ -3399,75 +3397,6 @@ adjoining text.
3399 @xref{Insertion}, for the ordinary insertion functions which do not 3397 @xref{Insertion}, for the ordinary insertion functions which do not
3400inherit. 3398inherit.
3401 3399
3402@node Saving Properties
3403@subsection Saving Text Properties in Files
3404@cindex text properties in files
3405@cindex saving text properties
3406
3407 You can save text properties in files (along with the text itself),
3408and restore the same text properties when visiting or inserting the
3409files, using these two hooks:
3410
3411@defvar write-region-annotate-functions
3412This variable's value is a list of functions for @code{write-region} to
3413run to encode text properties in some fashion as annotations to the text
3414being written in the file. @xref{Writing to Files}.
3415
3416Each function in the list is called with two arguments: the start and
3417end of the region to be written. These functions should not alter the
3418contents of the buffer. Instead, they should return lists indicating
3419annotations to write in the file in addition to the text in the
3420buffer.
3421
3422Each function should return a list of elements of the form
3423@code{(@var{position} . @var{string})}, where @var{position} is an
3424integer specifying the relative position within the text to be written,
3425and @var{string} is the annotation to add there.
3426
3427Each list returned by one of these functions must be already sorted in
3428increasing order by @var{position}. If there is more than one function,
3429@code{write-region} merges the lists destructively into one sorted list.
3430
3431When @code{write-region} actually writes the text from the buffer to the
3432file, it intermixes the specified annotations at the corresponding
3433positions. All this takes place without modifying the buffer.
3434@end defvar
3435
3436@defvar after-insert-file-functions
3437This variable holds a list of functions for @code{insert-file-contents}
3438to call after inserting a file's contents. These functions should scan
3439the inserted text for annotations, and convert them to the text
3440properties they stand for.
3441
3442Each function receives one argument, the length of the inserted text;
3443point indicates the start of that text. The function should scan that
3444text for annotations, delete them, and create the text properties that
3445the annotations specify. The function should return the updated length
3446of the inserted text, as it stands after those changes. The value
3447returned by one function becomes the argument to the next function.
3448
3449These functions should always return with point at the beginning of
3450the inserted text.
3451
3452The intended use of @code{after-insert-file-functions} is for converting
3453some sort of textual annotations into actual text properties. But other
3454uses may be possible.
3455@end defvar
3456
3457We invite users to write Lisp programs to store and retrieve text
3458properties in files, using these hooks, and thus to experiment with
3459various data formats and find good ones. Eventually we hope users
3460will produce good, general extensions we can install in Emacs.
3461
3462We suggest not trying to handle arbitrary Lisp objects as text property
3463names or values---because a program that general is probably difficult
3464to write, and slow. Instead, choose a set of possible data types that
3465are reasonably flexible, and not too hard to encode.
3466
3467@xref{Format Conversion}, for a related feature.
3468
3469@c ??? In next edition, merge this info Format Conversion.
3470
3471@node Lazy Properties 3400@node Lazy Properties
3472@subsection Lazy Computation of Text Properties 3401@subsection Lazy Computation of Text Properties
3473 3402