Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding a function in Emacs Lisp

Tags:

emacs

elisp

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?

like image 801
kes Avatar asked Mar 09 '10 05:03

kes


1 Answers

Your some-form-that-binds-a-function is called flet, so you were close.

like image 106
Ivan Andrus Avatar answered Oct 13 '22 09:10

Ivan Andrus