Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass a function as a parameter in Emacs Lisp?

I'm trying to add a function I created to a hook, but the obvious (to my Schemer mind) way doesn't seem to work. The function is used in 2 places and I want to keep my code DRY so no anonymous function. Though I could wrap my function in a lambda, there must be a better way.

Doesn't work:

(defun my-function ()
   ;; do my stuff)

(add-hook 'some-hook-list my-function)

I get the error message:

Symbol's value as variable is void: my-function

like image 623
Cristian Avatar asked Sep 03 '25 04:09

Cristian


1 Answers

I figured it out. It's pretty simple. Just quote the function:

Fixed code: (defun my-function () ;; do my stuff)

(add-hook 'some-hook-list 'my-function) ;;; There's a quote before my-function
like image 190
Cristian Avatar answered Sep 05 '25 00:09

Cristian