This naive attempt did not work:
;; function_key = dict()
(setq function-key '())
;; function_key["evil-next-line"] = 108
(add-to-list function-key '(evil-next-line . 108))
It just exploded with a (setting-constant nil)
add-to-list
accept a symbol
as the first argument:
(add-to-list 'function-key '(evil-next-line . 108))
If your variable is lexical, you will want to use push
instead:
(let ((foo ...))
(push ... foo))
NB. You might want to consider Hash Tables instead of alists for lookup (they correspond to dict
in Python).
In addition to sds's suggestion of add-to-list
, you can also use push
, which doesn't require you to quote the variable:
(push '(evil-next-line . 108) function-key)
pushnew
is also useful in order to ensure that you don't get duplicate entries in the list.
Commented
Oct 29, 2015 at 6:42