Overriding a function in Emacs Lisp
- by scrapdog
I would like to temporarily override the kill-new function. I have a way I want to reimplement kill-new that works in only in certain contexts, but I don't want to reimplement a special version of kill-region on top of that. (kill-new is called from kill-region)
Since Emacs Lisp uses dynamic scoping, this should be possible, right? (On the other hand, it seems that this would be an unsafe thing to support, and it might make me a bit nervous knowing that it is possible...)
I have experimented with using let and fset, but so far have found no way to get it to work as expected. So, hopefully someone can fill in the blank in the following pseudocode:
(defun my-kill-new (string &optional replace yank-handler)
(message "in my-kill-new!"))
(defun foo ()
(some-form-that-binds-a-function (kill-new my-kill-new)
(kill-region (point) (mark))))
What should some-form-that-binds-a-function be? Or am I barking up the wrong tree?