aboutsummaryrefslogtreecommitdiffstats
path: root/lispref
diff options
context:
space:
mode:
authorRichard M. Stallman2003-08-13 17:28:31 +0000
committerRichard M. Stallman2003-08-13 17:28:31 +0000
commitd73eac4dc30db31e548abfbca0b4b439f60d1a7c (patch)
tree44915bcb6f922109b8f5e675e4348c63e214bdcb /lispref
parent55ccf8be3783bb59e3d54c770e2ce7a271474854 (diff)
downloademacs-d73eac4dc30db31e548abfbca0b4b439f60d1a7c.tar.gz
emacs-d73eac4dc30db31e548abfbca0b4b439f60d1a7c.zip
(Insertion): Add insert-buffer-substring-no-properties.
(Kill Functions): kill-region has new arg yank-handler. (Yanking): New node. (Yank Commands): Add yank-undo-function. (Low-Level Kill Ring): kill-new and kill-append have new arg yank-handler. (Changing Properties): Add remove-list-of-text-properties. (Atomic Changes): New node.
Diffstat (limited to 'lispref')
-rw-r--r--lispref/text.texi191
1 files changed, 187 insertions, 4 deletions
diff --git a/lispref/text.texi b/lispref/text.texi
index 3197a72c8d7..3c7e2a8c3e6 100644
--- a/lispref/text.texi
+++ b/lispref/text.texi
@@ -58,6 +58,7 @@ the character after point.
58 position stored in a register. 58 position stored in a register.
59* Base 64:: Conversion to or from base 64 encoding. 59* Base 64:: Conversion to or from base 64 encoding.
60* MD5 Checksum:: Compute the MD5 ``message digest''/``checksum''. 60* MD5 Checksum:: Compute the MD5 ``message digest''/``checksum''.
61* Atomic Changes:: Installing several buffer changs ``atomically''.
61* Change Hooks:: Supplying functions to be run when text is changed. 62* Change Hooks:: Supplying functions to be run when text is changed.
62@end menu 63@end menu
63 64
@@ -398,6 +399,11 @@ We hold these truth@point{}
398@end example 399@end example
399@end defun 400@end defun
400 401
402@defun insert-buffer-substring-no-properties from-buffer-or-name &optional start end
403This is like @code{insert-buffer-substring} except that it does not
404copy any text properties.
405@end defun
406
401 @xref{Sticky Properties}, for other insertion functions that inherit 407 @xref{Sticky Properties}, for other insertion functions that inherit
402text properties from the nearby text in addition to inserting it. 408text properties from the nearby text in addition to inserting it.
403Whitespace inserted by indentation functions also inherits text 409Whitespace inserted by indentation functions also inherits text
@@ -761,6 +767,7 @@ would be difficult to change the terminology now.
761@menu 767@menu
762* Kill Ring Concepts:: What text looks like in the kill ring. 768* Kill Ring Concepts:: What text looks like in the kill ring.
763* Kill Functions:: Functions that kill text. 769* Kill Functions:: Functions that kill text.
770* Yanking:: How yanking is done.
764* Yank Commands:: Commands that access the kill ring. 771* Yank Commands:: Commands that access the kill ring.
765* Low-Level Kill Ring:: Functions and variables for kill ring access. 772* Low-Level Kill Ring:: Functions and variables for kill ring access.
766* Internals of Kill Ring:: Variables that hold kill-ring data. 773* Internals of Kill Ring:: Variables that hold kill-ring data.
@@ -805,7 +812,7 @@ adds it to the most recent element. It determines automatically (using
805@code{last-command}) whether the previous command was a kill command, 812@code{last-command}) whether the previous command was a kill command,
806and if so appends the killed text to the most recent entry. 813and if so appends the killed text to the most recent entry.
807 814
808@deffn Command kill-region start end 815@deffn Command kill-region start end &optional yank-handler
809This function kills the text in the region defined by @var{start} and 816This function kills the text in the region defined by @var{start} and
810@var{end}. The text is deleted but saved in the kill ring, along with 817@var{end}. The text is deleted but saved in the kill ring, along with
811its text properties. The value is always @code{nil}. 818its text properties. The value is always @code{nil}.
@@ -818,6 +825,10 @@ If the buffer or text is read-only, @code{kill-region} modifies the kill
818ring just the same, then signals an error without modifying the buffer. 825ring just the same, then signals an error without modifying the buffer.
819This is convenient because it lets the user use a series of kill 826This is convenient because it lets the user use a series of kill
820commands to copy text from a read-only buffer into the kill ring. 827commands to copy text from a read-only buffer into the kill ring.
828
829If @var{yank-handler} is non-@code{nil}, this puts that value onto
830the string of killed text, as a @code{yank-handler} property.
831@xref{Yanking}.
821@end deffn 832@end deffn
822 833
823@defopt kill-read-only-ok 834@defopt kill-read-only-ok
@@ -842,6 +853,67 @@ support Emacs 18. For newer Emacs versions, it is better to use
842Ring}. 853Ring}.
843@end deffn 854@end deffn
844 855
856@node Yanking
857@subsection Yanking
858
859 Yanking means inserting text from the kill ring, but it does
860not insert the text blindly. Yank commands and some other commands
861use @code{insert-for-yank} to perform special processing on the
862text that they copy into the buffer.
863
864@defun insert-for-yank string
865This function normally works like @code{insert} except that it doesn't
866insert the text properties in the @code{yank-excluded-properties}
867list. However, if the first character of @var{string} has a
868non-@code{nil}@code{yank-handler} text property, that property
869can do various special processing on the text being inserted.
870@end defun
871
872@defun insert-buffer-substring-as-yank buf &optional start end
873This function resembles @code{insert-buffer-substring} except that it
874doesn't insert the text properties in the
875@code{yank-excluded-properties} list.
876@end defun
877
878 You can put a @code{yank-handler} text property on the text to
879control how it will be inserted if it is yanked. The
880@code{insert-for-yank} function looks for a @code{yank-handler}
881property on the first character in its @var{string} argument. The
882property value must be a list of one to four elements, with the
883following format (where elements after the first may be omitted):
884
885@example
886(@var{function} @var{param} @var{noexclude} @var{undo})
887@end example
888
889 Here is what the elements do:
890
891@table @var
892@item function
893When @var{function} is present and non-nil, it is called instead of
894@code{insert} to insert the string. @var{function} takes one
895argument---the string to insert.
896
897@item param
898If @var{param} is present and non-@code{nil}, it replaces @var{string}
899as the object passed to @var{function} (or @code{insert}); for
900example, if @var{function} is @code{yank-rectangle}, @var{param}
901should be a list of strings to insert as a rectangle.
902
903@item noexclude
904If @var{noexclude} is present and non-@code{nil}, the normal removal of the
905yank-excluded-properties is not performed; instead @var{function} is
906responsible for removing those properties. This may be necessary
907if @var{function} adjusts point before or after inserting the object.
908
909@item undo
910If @var{undo} is present and non-nil, it is a function that will be
911called by @code{yank-pop} to undo the insertion of the current object.
912It is called with two arguments, the start and end of the current
913region. @var{function} can set @code{yank-undo-function} to override
914the @var{undo} value.
915@end table
916
845@node Yank Commands 917@node Yank Commands
846@comment node-name, next, previous, up 918@comment node-name, next, previous, up
847@subsection Functions for Yanking 919@subsection Functions for Yanking
@@ -889,6 +961,17 @@ oldest.
889The return value is always @code{nil}. 961The return value is always @code{nil}.
890@end deffn 962@end deffn
891 963
964@defvar yank-undo-function
965If this variable is non-@code{nil}, the function @code{yank-pop} uses
966its value instead of @code{delete-region} to delete the text
967inserted by the previous @code{yank} or
968@code{yank-pop} command.
969
970The function @code{insert-for-yank} automatically sets this variable
971according to the @var{undo} element of the @code{yank-handler}
972text property, if there is one.
973@end defvar
974
892@node Low-Level Kill Ring 975@node Low-Level Kill Ring
893@subsection Low-Level Kill Ring 976@subsection Low-Level Kill Ring
894 977
@@ -912,19 +995,23 @@ If @var{n} is zero, indicating a request for the latest kill,
912the kill ring. 995the kill ring.
913@end defun 996@end defun
914 997
915@defun kill-new string 998@defun kill-new string &optional yank-handler
916This function puts the text @var{string} into the kill ring as a new 999This function puts the text @var{string} into the kill ring as a new
917entry at the front of the ring. It discards the oldest entry if 1000entry at the front of the ring. It discards the oldest entry if
918appropriate. It also invokes the value of 1001appropriate. It also invokes the value of
919@code{interprogram-cut-function} (see below). 1002@code{interprogram-cut-function} (see below).
1003
1004If @var{yank-handler} is non-@code{nil}, this puts that value onto
1005the string of killed text, as a @code{yank-handler} property.
1006@xref{Yanking}.
920@end defun 1007@end defun
921 1008
922@defun kill-append string before-p 1009@defun kill-append string before-p &optional yank-handler
923This function appends the text @var{string} to the first entry in the 1010This function appends the text @var{string} to the first entry in the
924kill ring. Normally @var{string} goes at the end of the entry, but if 1011kill ring. Normally @var{string} goes at the end of the entry, but if
925@var{before-p} is non-@code{nil}, it goes at the beginning. This 1012@var{before-p} is non-@code{nil}, it goes at the beginning. This
926function also invokes the value of @code{interprogram-cut-function} (see 1013function also invokes the value of @code{interprogram-cut-function} (see
927below). 1014below). This handles @var{yank-handler} just like @code{kill-new}.
928@end defun 1015@end defun
929 1016
930@defvar interprogram-paste-function 1017@defvar interprogram-paste-function
@@ -2435,6 +2522,12 @@ To remove all text properties from certain text, use
2435list. 2522list.
2436@end defun 2523@end defun
2437 2524
2525@defun remove-list-of-text-properties start end list-of-properties &optional object
2526Like @code{remove-list-properties} except that
2527@var{list-of-properties} is a list property names only, not an
2528alternating list of property values.
2529@end defun
2530
2438@defun set-text-properties start end props &optional object 2531@defun set-text-properties start end props &optional object
2439This function completely replaces the text property list for the text 2532This function completely replaces the text property list for the text
2440between @var{start} and @var{end} in the string or buffer @var{object}. 2533between @var{start} and @var{end} in the string or buffer @var{object}.
@@ -3697,6 +3790,96 @@ using the specified or chosen coding system. However, if
3697coding instead. 3790coding instead.
3698@end defun 3791@end defun
3699 3792
3793@node Atomic Changes
3794@section Atomic Change Groups
3795@cindex atomic changes
3796
3797 In data base terminology, an @dfn{atomic} change is an indivisible
3798change---it can succeed entirely or it can fail entirely, but it
3799cannot partly succeed. A Lisp program can make a series of changes to
3800one or several buffers as an @dfn{atomic change group}, meaning that
3801either the entire series of changes will be installed in their buffers
3802or, in case of an error, none of them will be.
3803
3804 To do this for one buffer, the one already current, simply write a
3805call to @code{atomic-change-group} around the code that makes the
3806changes, like this:
3807
3808@example
3809(atomic-change-group
3810 (insert foo)
3811 (delete-region x y))
3812@end example
3813
3814@noindent
3815If an error (or other nonlocal exit) occurs inside the body of
3816@code{atomic-change-group}, it unmakes all the changes in that buffer
3817that were during the execution of the body. This kind of change group
3818has no effect on any other buffers--any such changes remain.
3819
3820 If you need something more sophisticated, such as to make changes in
3821various buffers constitute one atomic group, you must directly call
3822lower-level functions that @code{atomic-change-group} uses.
3823
3824@defun prepare-change-group &optional buffer
3825This function sets up a change group for buffer @var{buffer}, which
3826defaults to the current buffer. It returns a ``handle'' that
3827represents the change group. You must use this handle to activate the
3828change group and subsequently to finish it.
3829@end defun
3830
3831 To use the change group, you must @dfn{activate} it. You must do
3832this before making any changes in the text of @var{buffer}.
3833
3834@defun activate-change-group handle
3835This function activates the change group that @var{handle} designates.
3836@end defun
3837
3838 After you activate the change group, any changes you make in that
3839buffer become part of it. Once you have made all the desired changes
3840in the buffer, you must @dfn{finish} the change group. There are two
3841ways to do this: you can either accept (and finalize) all the changes,
3842or cancel them all.
3843
3844@defun accept-change-group handle
3845This function accepts all the changes in the change group specified by
3846@var{handle}, making them final.
3847@end defun
3848
3849@defun cancel-change-group handle
3850This function cancels and undoes all the changes in the change group
3851specified by @var{handle}.
3852@end defun
3853
3854 Your code should use @code{unwind-protect} to make sure the group is
3855always finished. The call to @code{activate-change-group} should be
3856inside the @code{unwind-protect}, in case the user types @kbd{C-g}
3857just after it runs. (This is one reason why
3858@code{prepare-change-group} and @code{activate-change-group} are
3859separate functions, because normally you would call
3860@code{prepare-change-group} before the start of that
3861@code{unwind-protect}.) Once you finish the group, don't use the
3862handle again---in particular, don't try to finish the same group
3863twice.
3864
3865 To make a multibuffer change group, call @code{prepare-change-group}
3866once for each buffer you want to cover, then use @code{nconc} to
3867combine the returned values, like this:
3868
3869@example
3870(nconc (prepare-change-group buffer-1)
3871 (prepare-change-group buffer-2))
3872@end example
3873
3874You can then activate the multibuffer change group with a single call
3875to @code{activate-change-group}, and finish it with a single call to
3876@code{accept-change-group} or @code{cancel-change-group}.
3877
3878 Nested use of several change groups for the same buffer works as you
3879would expect. Non-nested use of change groups for the same buffer
3880will get Emacs confused, so don't let it happen; the first change
3881group you start for any given buffer should be the last one finished.
3882
3700@node Change Hooks 3883@node Change Hooks
3701@section Change Hooks 3884@section Change Hooks
3702@cindex change hooks 3885@cindex change hooks