Emacs, scripting and anything text oriented.

How to save a function name in a variable in elisp?

Kaushal Modi

I have a couple of theme packages installed on my emacs but I would like to assign a default theme.

I set the zenburn theme via a function zenburn. I set the leuven theme via another function leuven. But in my emacs startup I didn’t want to hard-code either of these function and thus arose the need to set a variable to one of these functions.

You assign the function to a variable using defvar and you call that function linked to that variable using funcall.

(defvar default-theme 'zenburn)

;; zenburn
(defun zenburn ()
  "Activate zenburn theme."
  ;; disable other themes before setting this theme
  (disable-theme 'leuven)
  (load-theme 'zenburn t))

(funcall default-theme) ;; Set the default theme

You can check out my full emacs config for visual settings on my git.