* doc/lispref/text.texi (Yanking): Mention it.
(Yanking): Document it.
* lisp/simple.el (yank-transform-functions): New user option.
(yank): Mention it.
* lisp/subr.el (insert-for-yank): Use it.
property, as well as the variables @code{yank-handled-properties} and
@code{yank-excluded-properties} (see below), before inserting the
result into the current buffer.
+
+@var{string} will be run through @code{yank-transform-functions} (see
+below) before inserting.
@end defun
@defun insert-buffer-substring-as-yank buf &optional start end
@code{yank-handled-properties}.
@end defopt
+@defopt yank-transform-functions
+This variable is a list of functions. Each function is called (in
+order) with the string to be yanked as the parameter, and should
+return a (possibly transformed) string. This variable can be set
+globally, but can also be used to create new commands that are
+variations on @code{yank}. For instance, to create a command that
+works like @code{yank}, but cleans up whitespace before inserting, you
+could say something like:
+
+@lisp
+(defun yank-with-clean-whitespace ()
+ (interactive)
+ (let ((yank-transform-functions
+ '(string-clean-whitespace)))
+ (call-interactively #'yank)))
+@end lisp
+@end defopt
@node Yank Commands
@subsection Functions for Yanking
This command lets you examine all data in the current selection and
the clipboard, and insert it into the buffer.
+** New user option 'yank-transform-functions'.
+This function allows the user to alter the string to be inserted.
+
---
** New function 'minibuffer-lazy-highlight-setup'.
This function allows setting up the minibuffer so that lazy
:group 'killing
:version "24.3")
+(defcustom yank-transform-functions nil
+ "List of functions to run on strings to be yanked.
+Each function in this list will be called (in order) with the
+string to be yanked as the sole argument, and should return the (possibly)
+ transformed string."
+ :type '(repeat function)
+ :version "29.1"
+ :group 'killing)
+
(defvar yank-window-start nil)
(defvar yank-undo-function nil
"If non-nil, function used by `yank-pop' to delete last stretch of yanked text.
Properties listed in `yank-handled-properties' are processed,
then those listed in `yank-excluded-properties' are discarded.
+STRING will be run through `yank-transform-functions'.
+
If STRING has a non-nil `yank-handler' property anywhere, the
normal insert behavior is altered, and instead, for each contiguous
segment of STRING that has a given value of the `yank-handler'
This function is like `insert', except it honors the variables
`yank-handled-properties' and `yank-excluded-properties', and the
-`yank-handler' text property, in the way that `yank' does."
+`yank-handler' text property, in the way that `yank' does.
+
+It also runs the string through `yank-transform-functions'."
+ ;; Allow altering the yank string.
+ (dolist (func yank-transform-functions)
+ (setq string (funcall func string)))
(let (to)
(while (setq to (next-single-property-change 0 'yank-handler string))
(insert-for-yank-1 (substring string 0 to))