Is it possible to reference a local variable inside the definition of a function? Here's an example:
I have an alist text-alist
consisting of keys and text snippets. I want each text snippet bound to a key in the prefix map my-text-prefix-map
. The code below doesn't work, I guess because when the functions in my-text-prefix-map
are run, the value of text
is unknown. Is there any way to remedy this?
(mapc (lambda (text)
(define-key my-text-prefix-map (kbd (car text))
(lambda ()
(interactive)
(insert (cdr text)))))
text-alist)