Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [association-lists]

or alist for short, maps keys to values. It is a list of key-value pairs, where each pair is a cons whose car is the key and whose cdr is the value.

1
vote
1answer
135 views

how to implement a simple lookup table in lisp

I want to write an elisp function, when a country name is given, it returns the short code for the country. I've been reading about hash tables, but still not sure how to hashify my data set and make ...
7
votes
2answers
94 views

Is there a function like `assoc` that returns all matching values?

The assoc KEY LIST function returns the first element of an alist whose car is equal to KEY. Is there a built-in Emacs Lisp function which returns all elements of the alist whose cars are equal to ...
3
votes
1answer
109 views

“Dissasociate” auto-mode for specific files (in ESS)

I'd like to keep ess as automatic major mode for R files and everything else, except for Julia, for which I want to use julia-mode alone. However, I cannot find out how to "unbind" the file ...
0
votes
1answer
24 views

How not to propagate dired-actual-switches as a directory variable to the sub directories

I want to set dired-actual-switches for the directory /path/to/data, but not for data's subdirectories. So I generated the following .dir-locals.el file in /path/to/data: ;;; Directory Local ...
1
vote
1answer
424 views

How do you get data by key from a json list?

I loaded some json data into a string and have elisp parsing it using the json-read-from-string function. Now I want to do is access data from the JSON by key. When I print out the data via message, ...
3
votes
2answers
299 views

Replace element of alist using `equal` even if key does not exist

I have an alist whose keys are strings, and I need to set the value for one of its keys. If the key is not present, I need to add it. So for example, (alist-set "a" "bb" '(("a" . "b") ("c" . "d"))) =&...
2
votes
1answer
72 views

Is there any Emacs built-in to list the keys of an associton list?

I could not find any function to list the keys of an associton list in Emacs documentation. So I wrote a simple one. (defun my/keys (alist) "Return the keys of the given ALIST." (let ((value ...
0
votes
2answers
256 views

Why does `assoc` return nil for a plist?

I've got the following issue: (setq testvar '(link (:type "http" :path "//pygments.org/docs" :format bracket :raw-link "http://pygments.org/docs" :application nil))) (setq testvar (nth 1 testvar)) (...
0
votes
1answer
45 views

Custom sort order based on certain elements of a list

Q:  Each sub-list within the main list contains one of five possible categories. How can I customize the sort in the following order: CUSTOM SORT ORDER: 1. TASKS 2. EVENTS 3. UNDATED 4. ...
0
votes
0answers
32 views

elisp - construct a quasi-alist from variable [duplicate]

To construct a quasi-alist, case 1 is using hardcode string; case 2 is using a variable filename to replace the hadcode string. but case 2 doesn't work as expected (should the same as case 1). #+...
0
votes
2answers
65 views

How do I filter an alist to just the properties I care about?

To effectively use a service's API, I'm leveraging json-read to turn the JSON response into an understandable data structure: (let ((json-object-type 'alist) (json-array-type 'list) (...
2
votes
1answer
144 views

Read file lines into plist

I've been reading various tutorials on alist/plist access but can't figure this out. Let's say i have this file, test.txt: oranges 1 apples 2 grapes 3 I want to iterate this file line by line, and ...
0
votes
1answer
43 views

car on cons gets nil

I define an alist like this: (setq major-mode-list '(((emacs-lisp-mode inferior-emacs-lisp-mode) . ("Elisp" "Emacs")) ((haskell-mode) . ("Haskell" "Haskell")) )) And match current major-...
2
votes
1answer
399 views

Saving persistent undo to a single directory, alist format

It looks like this can be achieved by modifying the variable undo-tree-history-directory-alist, but I can't figure out how. I tried a number of lines, the last of which is (setq undo-tree-history-...
15
votes
1answer
2k views

Is '(a . b) really a list?

I'm really confused with the . notation. Is '(a . b) a list? (listp '(a . b)) returns t but when I want to know its length (length '(a . b)) gives an error Wrong type argument: listp, b. The same is ...
0
votes
2answers
104 views

How do I create and update an alist?

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 (...
3
votes
1answer
529 views

Why does emacs use both propertly lists and association lists?

http://www.gnu.org/software/emacs/manual/html_node/elisp/Plists-and-Alists.html gives some supposed differences between plists and alists. Basically it comes down to: Alists can be used as stacks, ...
7
votes
2answers
148 views

construct an association list from two vectors

I have two vectors, [apple orange] and [5 10]. How do I construct an association list ((apple 5) (orange 10)) from them?
6
votes
3answers
1k views

Looking for a simple way to update an alist without introducing degeneracies

In my .emacs file I have code like this: (setq default-frame-alist (assq-delete-all 'width default-frame-alist)) (add-to-list 'default-frame-alist (cons 'width new-width)) The ...
1
vote
2answers
66 views

Enable mode association with backup files as well

I want to enable mode association with backup files as well. E.g., if I backup my my-markdown.md file as my-markdown.md.orig or my-markdown.md.lastweek etc, I want them still be associated with the ...
34
votes
5answers
4k views

How to replace an element of an alist?

I have this by default in my auto-mode-alist: ("\\.js\\'" . javascript-mode) (even with emacs -Q). I'd like to substitute js2-mode for javascript-mode. Of course, I could use assq-delete-all and ...
10
votes
3answers
2k views

Best way to retrieve values in nested assoc-lists?

Suppose I've got an assoc-list like this: (setq x '((foo . ((bar . "llama") (baz . "monkey"))))) And I want the value at bar. I can do this: (assoc-default 'bar (assoc-default '...