summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2022-05-20 00:15:28 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2022-05-20 00:15:38 +0200
commitc9a8a47ba4b8cda05c48fff4259ce8f0bd079c87 (patch)
tree9508f0edef78e59fcb94d637a98cf09a679fa5bc /lisp
parentfb752561eab92343683552a5780dd80406936d09 (diff)
downloademacs-c9a8a47ba4b8cda05c48fff4259ce8f0bd079c87.tar.gz
emacs-c9a8a47ba4b8cda05c48fff4259ce8f0bd079c87.tar.bz2
emacs-c9a8a47ba4b8cda05c48fff4259ce8f0bd079c87.zip
Add new user option 'yank-transform-functions'
* 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.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/simple.el11
-rw-r--r--lisp/subr.el7
2 files changed, 17 insertions, 1 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index cd7a82b7aca..bed72457c3a 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -5928,6 +5928,15 @@ See also `yank-handled-properties'."
: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.
@@ -5999,6 +6008,8 @@ property, as described below.
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'
diff --git a/lisp/subr.el b/lisp/subr.el
index d7f06bdcde8..945587db53c 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -4070,7 +4070,12 @@ remove properties specified by `yank-excluded-properties'."
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))