diff options
| author | Richard M. Stallman | 2003-08-13 17:28:31 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2003-08-13 17:28:31 +0000 |
| commit | d73eac4dc30db31e548abfbca0b4b439f60d1a7c (patch) | |
| tree | 44915bcb6f922109b8f5e675e4348c63e214bdcb /lispref | |
| parent | 55ccf8be3783bb59e3d54c770e2ce7a271474854 (diff) | |
| download | emacs-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.texi | 191 |
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 | ||
| 403 | This is like @code{insert-buffer-substring} except that it does not | ||
| 404 | copy 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 |
| 402 | text properties from the nearby text in addition to inserting it. | 408 | text properties from the nearby text in addition to inserting it. |
| 403 | Whitespace inserted by indentation functions also inherits text | 409 | Whitespace 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, |
| 806 | and if so appends the killed text to the most recent entry. | 813 | and 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 |
| 809 | This function kills the text in the region defined by @var{start} and | 816 | This 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 |
| 811 | its text properties. The value is always @code{nil}. | 818 | its 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 | |||
| 818 | ring just the same, then signals an error without modifying the buffer. | 825 | ring just the same, then signals an error without modifying the buffer. |
| 819 | This is convenient because it lets the user use a series of kill | 826 | This is convenient because it lets the user use a series of kill |
| 820 | commands to copy text from a read-only buffer into the kill ring. | 827 | commands to copy text from a read-only buffer into the kill ring. |
| 828 | |||
| 829 | If @var{yank-handler} is non-@code{nil}, this puts that value onto | ||
| 830 | the 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 | |||
| 842 | Ring}. | 853 | Ring}. |
| 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 | ||
| 860 | not insert the text blindly. Yank commands and some other commands | ||
| 861 | use @code{insert-for-yank} to perform special processing on the | ||
| 862 | text that they copy into the buffer. | ||
| 863 | |||
| 864 | @defun insert-for-yank string | ||
| 865 | This function normally works like @code{insert} except that it doesn't | ||
| 866 | insert the text properties in the @code{yank-excluded-properties} | ||
| 867 | list. However, if the first character of @var{string} has a | ||
| 868 | non-@code{nil}@code{yank-handler} text property, that property | ||
| 869 | can do various special processing on the text being inserted. | ||
| 870 | @end defun | ||
| 871 | |||
| 872 | @defun insert-buffer-substring-as-yank buf &optional start end | ||
| 873 | This function resembles @code{insert-buffer-substring} except that it | ||
| 874 | doesn'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 | ||
| 879 | control how it will be inserted if it is yanked. The | ||
| 880 | @code{insert-for-yank} function looks for a @code{yank-handler} | ||
| 881 | property on the first character in its @var{string} argument. The | ||
| 882 | property value must be a list of one to four elements, with the | ||
| 883 | following 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 | ||
| 893 | When @var{function} is present and non-nil, it is called instead of | ||
| 894 | @code{insert} to insert the string. @var{function} takes one | ||
| 895 | argument---the string to insert. | ||
| 896 | |||
| 897 | @item param | ||
| 898 | If @var{param} is present and non-@code{nil}, it replaces @var{string} | ||
| 899 | as the object passed to @var{function} (or @code{insert}); for | ||
| 900 | example, if @var{function} is @code{yank-rectangle}, @var{param} | ||
| 901 | should be a list of strings to insert as a rectangle. | ||
| 902 | |||
| 903 | @item noexclude | ||
| 904 | If @var{noexclude} is present and non-@code{nil}, the normal removal of the | ||
| 905 | yank-excluded-properties is not performed; instead @var{function} is | ||
| 906 | responsible for removing those properties. This may be necessary | ||
| 907 | if @var{function} adjusts point before or after inserting the object. | ||
| 908 | |||
| 909 | @item undo | ||
| 910 | If @var{undo} is present and non-nil, it is a function that will be | ||
| 911 | called by @code{yank-pop} to undo the insertion of the current object. | ||
| 912 | It is called with two arguments, the start and end of the current | ||
| 913 | region. @var{function} can set @code{yank-undo-function} to override | ||
| 914 | the @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. | |||
| 889 | The return value is always @code{nil}. | 961 | The return value is always @code{nil}. |
| 890 | @end deffn | 962 | @end deffn |
| 891 | 963 | ||
| 964 | @defvar yank-undo-function | ||
| 965 | If this variable is non-@code{nil}, the function @code{yank-pop} uses | ||
| 966 | its value instead of @code{delete-region} to delete the text | ||
| 967 | inserted by the previous @code{yank} or | ||
| 968 | @code{yank-pop} command. | ||
| 969 | |||
| 970 | The function @code{insert-for-yank} automatically sets this variable | ||
| 971 | according to the @var{undo} element of the @code{yank-handler} | ||
| 972 | text 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, | |||
| 912 | the kill ring. | 995 | the kill ring. |
| 913 | @end defun | 996 | @end defun |
| 914 | 997 | ||
| 915 | @defun kill-new string | 998 | @defun kill-new string &optional yank-handler |
| 916 | This function puts the text @var{string} into the kill ring as a new | 999 | This function puts the text @var{string} into the kill ring as a new |
| 917 | entry at the front of the ring. It discards the oldest entry if | 1000 | entry at the front of the ring. It discards the oldest entry if |
| 918 | appropriate. It also invokes the value of | 1001 | appropriate. It also invokes the value of |
| 919 | @code{interprogram-cut-function} (see below). | 1002 | @code{interprogram-cut-function} (see below). |
| 1003 | |||
| 1004 | If @var{yank-handler} is non-@code{nil}, this puts that value onto | ||
| 1005 | the 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 |
| 923 | This function appends the text @var{string} to the first entry in the | 1010 | This function appends the text @var{string} to the first entry in the |
| 924 | kill ring. Normally @var{string} goes at the end of the entry, but if | 1011 | kill 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 |
| 926 | function also invokes the value of @code{interprogram-cut-function} (see | 1013 | function also invokes the value of @code{interprogram-cut-function} (see |
| 927 | below). | 1014 | below). 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 | |||
| 2435 | list. | 2522 | list. |
| 2436 | @end defun | 2523 | @end defun |
| 2437 | 2524 | ||
| 2525 | @defun remove-list-of-text-properties start end list-of-properties &optional object | ||
| 2526 | Like @code{remove-list-properties} except that | ||
| 2527 | @var{list-of-properties} is a list property names only, not an | ||
| 2528 | alternating 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 |
| 2439 | This function completely replaces the text property list for the text | 2532 | This function completely replaces the text property list for the text |
| 2440 | between @var{start} and @var{end} in the string or buffer @var{object}. | 2533 | between @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 | |||
| 3697 | coding instead. | 3790 | coding 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 | ||
| 3798 | change---it can succeed entirely or it can fail entirely, but it | ||
| 3799 | cannot partly succeed. A Lisp program can make a series of changes to | ||
| 3800 | one or several buffers as an @dfn{atomic change group}, meaning that | ||
| 3801 | either the entire series of changes will be installed in their buffers | ||
| 3802 | or, 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 | ||
| 3805 | call to @code{atomic-change-group} around the code that makes the | ||
| 3806 | changes, like this: | ||
| 3807 | |||
| 3808 | @example | ||
| 3809 | (atomic-change-group | ||
| 3810 | (insert foo) | ||
| 3811 | (delete-region x y)) | ||
| 3812 | @end example | ||
| 3813 | |||
| 3814 | @noindent | ||
| 3815 | If an error (or other nonlocal exit) occurs inside the body of | ||
| 3816 | @code{atomic-change-group}, it unmakes all the changes in that buffer | ||
| 3817 | that were during the execution of the body. This kind of change group | ||
| 3818 | has no effect on any other buffers--any such changes remain. | ||
| 3819 | |||
| 3820 | If you need something more sophisticated, such as to make changes in | ||
| 3821 | various buffers constitute one atomic group, you must directly call | ||
| 3822 | lower-level functions that @code{atomic-change-group} uses. | ||
| 3823 | |||
| 3824 | @defun prepare-change-group &optional buffer | ||
| 3825 | This function sets up a change group for buffer @var{buffer}, which | ||
| 3826 | defaults to the current buffer. It returns a ``handle'' that | ||
| 3827 | represents the change group. You must use this handle to activate the | ||
| 3828 | change group and subsequently to finish it. | ||
| 3829 | @end defun | ||
| 3830 | |||
| 3831 | To use the change group, you must @dfn{activate} it. You must do | ||
| 3832 | this before making any changes in the text of @var{buffer}. | ||
| 3833 | |||
| 3834 | @defun activate-change-group handle | ||
| 3835 | This 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 | ||
| 3839 | buffer become part of it. Once you have made all the desired changes | ||
| 3840 | in the buffer, you must @dfn{finish} the change group. There are two | ||
| 3841 | ways to do this: you can either accept (and finalize) all the changes, | ||
| 3842 | or cancel them all. | ||
| 3843 | |||
| 3844 | @defun accept-change-group handle | ||
| 3845 | This 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 | ||
| 3850 | This function cancels and undoes all the changes in the change group | ||
| 3851 | specified by @var{handle}. | ||
| 3852 | @end defun | ||
| 3853 | |||
| 3854 | Your code should use @code{unwind-protect} to make sure the group is | ||
| 3855 | always finished. The call to @code{activate-change-group} should be | ||
| 3856 | inside the @code{unwind-protect}, in case the user types @kbd{C-g} | ||
| 3857 | just after it runs. (This is one reason why | ||
| 3858 | @code{prepare-change-group} and @code{activate-change-group} are | ||
| 3859 | separate 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 | ||
| 3862 | handle again---in particular, don't try to finish the same group | ||
| 3863 | twice. | ||
| 3864 | |||
| 3865 | To make a multibuffer change group, call @code{prepare-change-group} | ||
| 3866 | once for each buffer you want to cover, then use @code{nconc} to | ||
| 3867 | combine 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 | |||
| 3874 | You can then activate the multibuffer change group with a single call | ||
| 3875 | to @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 | ||
| 3879 | would expect. Non-nested use of change groups for the same buffer | ||
| 3880 | will get Emacs confused, so don't let it happen; the first change | ||
| 3881 | group 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 |