New answers tagged

0

You can use the builtin macro let-alist to access value from nested alist, e.g., (let-alist '((foo . ((bar . ((chocolate . "edible") (gold . "inedible"))) (jar . "glass")))) .foo.bar.chocolate) ;; => "edible" And your x is not an alist, alist is a list of key-value pairs, i.e., ((key1 . val1) (...


3

I have the following nested alist: The example does not show a real alist, because its first element, foo, is not a cons cell. I'd personally call it a tree. Functions like assoc-string may handle this, others may ignore such elements, but in general alist functions expect every element to be a cons with a car and a cdr. See (info "(elisp) Lists"...


1

tramp-methods is an association list. Which means that you don't have to replace an existing value at all. When a value is looked up in an alist, only the first match for the key is returned. Therefore merely pushing a new (KEY . VALUE) onto the front of the list has the desired effect, regardless of whether or not there are other uses of that same KEY in ...


2

You can use alist-get with setf (elisp) Generalized Variables, e.g., ;; Add (let ((al (list (cons 'a 1) (cons 'b 2)))) (setf (alist-get 'c al) 3) al) ;; => ((c . 3) (a . 1) (b . 2)) ;; Replace/update (let ((al (list (cons 'a 1) (cons 'b 2)))) (setf (alist-get 'b al) "2") al) ;; => ((a . 1) (b . "2")) (add-to-list 'tramp-...


1

I ended with function like: (defun my-assoc-push (key value alist-name) (when (not (symbolp alist-name)) (error "alist-name is not a symbol.")) (set alist-name (cons (cons key value) (cl-remove key (symbol-value alist-name) :key #'car :test #'equal)))) (my-assoc-push "gssh" '((tramp-login-program "compute ...


Top 50 recent answers are included