0

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)

5

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).

4

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)
  • 2
    pushnew is also useful in order to ensure that you don't get duplicate entries in the list. – Elias Mårtenson Oct 29 '15 at 6:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.