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.

Filter by
Sorted by
Tagged with
1
vote
1answer
32 views

Association in Elisp not found

I have a simple alist in elisp like this: (defvar *oneliners* '((js . "//") (python . "#") )) I am a bit surprised that searching for the python key gives me nil. I am calling it from ...
1
vote
1answer
162 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
102 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
132 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
25 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
545 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
345 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
121 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
261 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
48 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
33 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
69 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
165 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
46 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
450 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
111 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
571 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
151 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 ...
36
votes
5answers
5k 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 '...