Overriding a function in Emacs Lisp

Posted by scrapdog on Stack Overflow See other posts from Stack Overflow or by scrapdog
Published on 2010-03-09T05:12:17Z Indexed on 2010/03/09 6:06 UTC
Read the original article Hit count: 415

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about emacs

Related posts about emacs-lisp