So I'm trying to add something into some elisp mode hooks — specifically, I'd like to define a hook's prettify-symbols-alist and then specifically activate it by calling prettify-symbols-mode.
In any case, I'm getting org-babel to export the values into a pair of lists from a table, using pairlis to tie them together as an alist, and add-hook it into the desired mode using a anonymous function.
So, the thing is, right now if I use a global variable, like the following, it works:
(let ((token (quote ("not" "*" "/" "->" "map" "/=" "<=" ">=" "lambda")))
(code (quote (172 215 247 8594 8614 8800 8804 8805 955)))) ; Generated automatically using org-babel
(require 'cl)
(setq *globalvar (pairlis token code))
(add-hook 'emacs-lisp-mode-hook
(lambda ()
(setq prettify-symbols-alist *globalvar)
(prettify-symbols-mode 1))))
But if I try to not use a global variable, by doing it this way, it doesn't work:
(let ((token (quote ("not" "*" "/" "->" "map" "/=" "<=" ">=" "lambda")))
(code (quote (172 215 247 8594 8614 8800 8804 8805 955)))) ; Generated automatically using org-babel
(let (localv)
(require 'cl)
(setq localv (pairlis token code))
(add-hook 'emacs-lisp-mode-hook
(lambda ()
(setq prettify-symbols-alist localv)
(prettify-symbols-mode 1))))
I kind of know why: if I C-h v emacs-lisp-mode-hook, I'll see that it refers to whatever variable I used in the let form, which works when the variable exists, as in *globalvar, but not when I use localvar, which no longer exists outside of its let form. But I'm not sure how to force evaluation of the local variable itself, as I'm still struggling with a lot of concepts in elisp that aren't immediately clear to me.
What am I missing? Where am I going wrong here?
lexical-bindingto non-nil, orlocalvwill be a free variable in your hook function. Preferably, setlexical-bindingas a file-local variable.let-boundlocalvvariable is bound (to no avail) while yourlambdaform is being defined, but is no longer bound when that function executes at some point later on. You're expecting a lexical closure, which you'll only get if you enable lexical binding for the library.'(lambda ...)like that. See emacs.stackexchange.com/q/3595/454lexical-bindingto a non-nilvalue, but I'm trying to figure out how to do that withorg-babel, since this is basically an org file that gets tangled into an emacs lisp file. Unfortunately, this page is saying that it should be set as the first line (presumably;; -*- lexical-binding: t -*-?), but… I can't seem to find out how to ensure that happens.'(lambda ...), I was initially planning to use(defun ...)and define a function that would take both the hook and the alist to use, but I never could get it to work properly. I ended up using'(lambda ...)because it worked at the time, but I'm beginning to suspect that I might need to relook at the(defun ...)again.