diff options
| author | Eli Zaretskii | 2015-12-07 18:20:43 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2015-12-07 18:20:43 +0200 |
| commit | 86130adf1ef6ca8e8feabcc0fe966f84bf5d42dc (patch) | |
| tree | 810bb3c9399a49a66c7be910fbec3660f54f85bc | |
| parent | eb85d55cea4c5a715c4381ab6aeee630183fa23e (diff) | |
| download | emacs-86130adf1ef6ca8e8feabcc0fe966f84bf5d42dc.tar.gz emacs-86130adf1ef6ca8e8feabcc0fe966f84bf5d42dc.zip | |
Improve documentation of kill commands
* lisp/simple.el (region-extract-function, delete-backward-char)
(delete-forward-char, kill-region, copy-region-as-kill)
(kill-ring-save): Better document the optional argument REGION in
the doc strings. Mention in the doc strings that text put in the
kill-ring can be filtered by 'filter-buffer-substring'.
* doc/lispref/text.texi (Kill Functions): Mention that functions
described in this subsection can filter text they put in the
kill-ring. Add a cross-reference to "Buffer Contents" and an
index entry. Document the optional argument 'region' and its
effect.
(Bug#21315)
| -rw-r--r-- | doc/lispref/text.texi | 42 | ||||
| -rw-r--r-- | lisp/simple.el | 55 |
2 files changed, 68 insertions, 29 deletions
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi index dfd85bf124e..4d26638a94c 100644 --- a/doc/lispref/text.texi +++ b/doc/lispref/text.texi | |||
| @@ -899,13 +899,25 @@ adds it to the most recent element. It determines automatically (using | |||
| 899 | @code{last-command}) whether the previous command was a kill command, | 899 | @code{last-command}) whether the previous command was a kill command, |
| 900 | and if so appends the killed text to the most recent entry. | 900 | and if so appends the killed text to the most recent entry. |
| 901 | 901 | ||
| 902 | @deffn Command kill-region start end | 902 | @cindex filtering killed text |
| 903 | This function kills the text in the region defined by @var{start} and | 903 | The commands described below can filter the killed text before they |
| 904 | @var{end}. The text is deleted but saved in the kill ring, along with | 904 | save it in the kill ring. They call @code{filter-buffer-substring} |
| 905 | its text properties. The value is always @code{nil}. | 905 | (@pxref{Buffer Contents}) to perform the filtering. By default, |
| 906 | there's no filtering, but major and minor modes and hook functions can | ||
| 907 | set up filtering, so that text saved in the kill ring is different | ||
| 908 | from what was in the buffer. | ||
| 909 | |||
| 910 | @deffn Command kill-region start end &optional region | ||
| 911 | This function kills the stretch of text between @var{start} and | ||
| 912 | @var{end}; but if the optional argument @var{region} is | ||
| 913 | non-@code{nil}, it ignores @var{start} and @var{end}, and kills the | ||
| 914 | text in the current region instead. The text is deleted but saved in | ||
| 915 | the kill ring, along with its text properties. The value is always | ||
| 916 | @code{nil}. | ||
| 906 | 917 | ||
| 907 | In an interactive call, @var{start} and @var{end} are point and | 918 | In an interactive call, @var{start} and @var{end} are point and |
| 908 | the mark. | 919 | the mark, and @var{region} is always non-@code{nil}, so the command |
| 920 | always kills the text in the current region. | ||
| 909 | 921 | ||
| 910 | If the buffer or text is read-only, @code{kill-region} modifies the kill | 922 | If the buffer or text is read-only, @code{kill-region} modifies the kill |
| 911 | ring just the same, then signals an error without modifying the buffer. | 923 | ring just the same, then signals an error without modifying the buffer. |
| @@ -919,18 +931,20 @@ error if the buffer or text is read-only. Instead, it simply returns, | |||
| 919 | updating the kill ring but not changing the buffer. | 931 | updating the kill ring but not changing the buffer. |
| 920 | @end defopt | 932 | @end defopt |
| 921 | 933 | ||
| 922 | @deffn Command copy-region-as-kill start end | 934 | @deffn Command copy-region-as-kill start end &optional region |
| 923 | This command saves the region defined by @var{start} and @var{end} on | 935 | This function saves the stretch of text between @var{start} and |
| 924 | the kill ring (including text properties), but does not delete the text | 936 | @var{end} on the kill ring (including text properties), but does not |
| 925 | from the buffer. It returns @code{nil}. | 937 | delete the text from the buffer. However, if the optional argument |
| 938 | @var{region} is non-@code{nil}, the function ignores @var{start} and | ||
| 939 | @var{end}, and saves the current region instead. It always returns | ||
| 940 | @code{nil}. | ||
| 941 | |||
| 942 | In an interactive call, @var{start} and @var{end} are point and | ||
| 943 | the mark, and @var{region} is always non-@code{nil}, so the command | ||
| 944 | always saves the text in the current region. | ||
| 926 | 945 | ||
| 927 | The command does not set @code{this-command} to @code{kill-region}, so a | 946 | The command does not set @code{this-command} to @code{kill-region}, so a |
| 928 | subsequent kill command does not append to the same kill ring entry. | 947 | subsequent kill command does not append to the same kill ring entry. |
| 929 | |||
| 930 | @c FIXME Why is it better? Why isn't copy-region-as-kill obsolete then? | ||
| 931 | @c Why is it used in many places in Emacs? | ||
| 932 | In Lisp programs, it is better to use @code{kill-new} or | ||
| 933 | @code{kill-append} instead of this command. @xref{Low-Level Kill Ring}. | ||
| 934 | @end deffn | 948 | @end deffn |
| 935 | 949 | ||
| 936 | @node Yanking | 950 | @node Yanking |
diff --git a/lisp/simple.el b/lisp/simple.el index 2ccb016aca5..17b9c918ead 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -974,7 +974,8 @@ If DELETE is `delete-only', then only delete the region and the return value | |||
| 974 | is undefined. If DELETE is nil, just return the content as a string. | 974 | is undefined. If DELETE is nil, just return the content as a string. |
| 975 | If DELETE is `bounds', then don't delete, but just return the | 975 | If DELETE is `bounds', then don't delete, but just return the |
| 976 | boundaries of the region as a list of (START . END) positions. | 976 | boundaries of the region as a list of (START . END) positions. |
| 977 | If anything else, delete the region and return its content as a string.") | 977 | If anything else, delete the region and return its content as a string, |
| 978 | after filtering it with `filter-buffer-substring'.") | ||
| 978 | 979 | ||
| 979 | (defvar region-insert-function | 980 | (defvar region-insert-function |
| 980 | (lambda (lines) | 981 | (lambda (lines) |
| @@ -999,6 +1000,10 @@ Optional second arg KILLFLAG, if non-nil, means to kill (save in | |||
| 999 | kill ring) instead of delete. Interactively, N is the prefix | 1000 | kill ring) instead of delete. Interactively, N is the prefix |
| 1000 | arg, and KILLFLAG is set if N is explicitly specified. | 1001 | arg, and KILLFLAG is set if N is explicitly specified. |
| 1001 | 1002 | ||
| 1003 | When killing, the killed text is filtered by | ||
| 1004 | `filter-buffer-substring' before it is saved in the kill ring, so | ||
| 1005 | the actual saved text might be different from what was killed. | ||
| 1006 | |||
| 1002 | In Overwrite mode, single character backward deletion may replace | 1007 | In Overwrite mode, single character backward deletion may replace |
| 1003 | tabs with spaces so as to back over columns, unless point is at | 1008 | tabs with spaces so as to back over columns, unless point is at |
| 1004 | the end of the line." | 1009 | the end of the line." |
| @@ -1034,7 +1039,11 @@ To disable this, set variable `delete-active-region' to nil. | |||
| 1034 | 1039 | ||
| 1035 | Optional second arg KILLFLAG non-nil means to kill (save in kill | 1040 | Optional second arg KILLFLAG non-nil means to kill (save in kill |
| 1036 | ring) instead of delete. Interactively, N is the prefix arg, and | 1041 | ring) instead of delete. Interactively, N is the prefix arg, and |
| 1037 | KILLFLAG is set if N was explicitly specified." | 1042 | KILLFLAG is set if N was explicitly specified. |
| 1043 | |||
| 1044 | When killing, the killed text is filtered by | ||
| 1045 | `filter-buffer-substring' before it is saved in the kill ring, so | ||
| 1046 | the actual saved text might be different from what was killed." | ||
| 1038 | (declare (interactive-only delete-char)) | 1047 | (declare (interactive-only delete-char)) |
| 1039 | (interactive "p\nP") | 1048 | (interactive "p\nP") |
| 1040 | (unless (integerp n) | 1049 | (unless (integerp n) |
| @@ -4249,21 +4258,25 @@ The command \\[yank] can retrieve it from there. | |||
| 4249 | If you want to append the killed region to the last killed text, | 4258 | If you want to append the killed region to the last killed text, |
| 4250 | use \\[append-next-kill] before \\[kill-region]. | 4259 | use \\[append-next-kill] before \\[kill-region]. |
| 4251 | 4260 | ||
| 4261 | Any command that calls this function is a \"kill command\". | ||
| 4262 | If the previous command was also a kill command, | ||
| 4263 | the text killed this time appends to the text killed last time | ||
| 4264 | to make one entry in the kill ring. | ||
| 4265 | |||
| 4266 | The killed text is filtered by `filter-buffer-substring' before it is | ||
| 4267 | saved in the kill ring, so the actual saved text might be different | ||
| 4268 | from what was killed. | ||
| 4269 | |||
| 4252 | If the buffer is read-only, Emacs will beep and refrain from deleting | 4270 | If the buffer is read-only, Emacs will beep and refrain from deleting |
| 4253 | the text, but put the text in the kill ring anyway. This means that | 4271 | the text, but put the text in the kill ring anyway. This means that |
| 4254 | you can use the killing commands to copy text from a read-only buffer. | 4272 | you can use the killing commands to copy text from a read-only buffer. |
| 4255 | 4273 | ||
| 4256 | Lisp programs should use this function for killing text. | 4274 | Lisp programs should use this function for killing text. |
| 4257 | (To delete text, use `delete-region'.) | 4275 | (To delete text, use `delete-region'.) |
| 4258 | Supply two arguments, character positions indicating the stretch of text | 4276 | Supply two arguments, character positions BEG and END indicating the |
| 4259 | to be killed. | 4277 | stretch of text to be killed. If the optional argument REGION is |
| 4260 | Any command that calls this function is a \"kill command\". | 4278 | non-nil, the function ignores BEG and END, and kills the current |
| 4261 | If the previous command was also a kill command, | 4279 | region instead." |
| 4262 | the text killed this time appends to the text killed last time | ||
| 4263 | to make one entry in the kill ring. | ||
| 4264 | |||
| 4265 | The optional argument REGION if non-nil, indicates that we're not just killing | ||
| 4266 | some text between BEG and END, but we're killing the region." | ||
| 4267 | ;; Pass mark first, then point, because the order matters when | 4280 | ;; Pass mark first, then point, because the order matters when |
| 4268 | ;; calling `kill-append'. | 4281 | ;; calling `kill-append'. |
| 4269 | (interactive (list (mark) (point) 'region)) | 4282 | (interactive (list (mark) (point) 'region)) |
| @@ -4308,8 +4321,14 @@ In Transient Mark mode, deactivate the mark. | |||
| 4308 | If `interprogram-cut-function' is non-nil, also save the text for a window | 4321 | If `interprogram-cut-function' is non-nil, also save the text for a window |
| 4309 | system cut and paste. | 4322 | system cut and paste. |
| 4310 | 4323 | ||
| 4311 | The optional argument REGION if non-nil, indicates that we're not just copying | 4324 | The copied text is filtered by `filter-buffer-substring' before it is |
| 4312 | some text between BEG and END, but we're copying the region. | 4325 | saved in the kill ring, so the actual saved text might be different |
| 4326 | from what was in the buffer. | ||
| 4327 | |||
| 4328 | When called from Lisp, save in the kill ring the stretch of text | ||
| 4329 | between BEG and END, unless the optional argument REGION is | ||
| 4330 | non-nil, in which case ignore BEG and END, and save the current | ||
| 4331 | region instead. | ||
| 4313 | 4332 | ||
| 4314 | This command's old key binding has been given to `kill-ring-save'." | 4333 | This command's old key binding has been given to `kill-ring-save'." |
| 4315 | ;; Pass mark first, then point, because the order matters when | 4334 | ;; Pass mark first, then point, because the order matters when |
| @@ -4334,8 +4353,14 @@ system cut and paste. | |||
| 4334 | If you want to append the killed line to the last killed text, | 4353 | If you want to append the killed line to the last killed text, |
| 4335 | use \\[append-next-kill] before \\[kill-ring-save]. | 4354 | use \\[append-next-kill] before \\[kill-ring-save]. |
| 4336 | 4355 | ||
| 4337 | The optional argument REGION if non-nil, indicates that we're not just copying | 4356 | The copied text is filtered by `filter-buffer-substring' before it is |
| 4338 | some text between BEG and END, but we're copying the region. | 4357 | saved in the kill ring, so the actual saved text might be different |
| 4358 | from what was in the buffer. | ||
| 4359 | |||
| 4360 | When called from Lisp, save in the kill ring the stretch of text | ||
| 4361 | between BEG and END, unless the optional argument REGION is | ||
| 4362 | non-nil, in which case ignore BEG and END, and save the current | ||
| 4363 | region instead. | ||
| 4339 | 4364 | ||
| 4340 | This command is similar to `copy-region-as-kill', except that it gives | 4365 | This command is similar to `copy-region-as-kill', except that it gives |
| 4341 | visual feedback indicating the extent of the region being copied." | 4366 | visual feedback indicating the extent of the region being copied." |