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."
  (interactive)
  ;; 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.

Reference

If you have written a response to this, enter your response post's URL below.

Or, you can send a "comment" webmention (it's OK if you don't know what that means). When asked about your website on an IndieAuth login screen, simply type https://commentpara.de.

Markdown Support**bold**, _italics_, ~~strikethrough~~, [descr](link), `monospace`, ```LANG\nline1\nline2\n``` (Yep, multi-line code blocks too, with syntax highlighting!), auto-hyperlinking.

Webmentions #