Questions tagged [list]

is for the list object in Lisp programming. A list represents a sequence of zero or more elements. Emacs Lisp relies extensively on the list data structure; it is a fundamental building block. Emacs provides many facilities for building, modifying, extending, and efficiently handling list data structures.

Filter by
Sorted by
Tagged with
15
votes
2answers
10k views

How to concatenate two lists?

Sorry, but elisp is not my best. I need to combine two lists of strings in this way: ("a" "b" "c") + ("d" "e" "f") -> ("a" "b" "c" "d" "e" "f") Well, the order is not important, so I wrote this ...
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 ...
12
votes
1answer
480 views

Why does a constant in `let` change with repeated calls? [duplicate]

Say we have such a foo function: (defun foo (e) (let ((lst '(a b c))) (delq e lst))) Then we use it in following way (sequentially evaluating one by one): (foo 'c) ; => (a b) (foo 'b) ; =&...
12
votes
1answer
1k views

Meaning of period in (. 123)

I learnt . /path/to/file in bash is used to execute a file. Just out of curiosity, I eval something like the following in Emacs (. 123) ⇒ 123 (read "(. 123)") ⇒ 123 It looks like Emacs ...
9
votes
7answers
7k views

How to remove / delete nth element of a list

Q:  How to remove / delete nth element of a list. CAVEAT:  Do not remove all occurrences / members matching nth element -- e.g., eq or equal. EXAMPLE:  Remove the 17th element of: '(a b c d e f g h ...
9
votes
0answers
510 views

When to use quote for lists? Modifying quoted lists in Elisp

The Common Lisp Hyper Spec says: The consequences are undefined if literal objects (including quoted objects) are destructively modified. This is further motivated at the Constant Modification ...
8
votes
2answers
138 views

Proper reinitialization of a list? What is happening under the hood?

I'm teaching myself some more elisp and have encountered the following problem: If I want to reset a list variable it won't get updated after the first evaluation. Here is some example code: (defun ...
7
votes
5answers
683 views

Report duplicates in a list?

Q: how do I get only the duplicate elements in a list? delete-dups (and cl-delete-duplicates) deletes all duplicate elements from a list: (delete-dups '(a b c c d d)) ; => '(a b c d) ...
7
votes
3answers
298 views

Removing the last element of a list

Is there a simpler way to remove the last element of a list than this? (setq list (reverse (cdr (reverse list))))
7
votes
1answer
327 views

Convert 2-item list to a dotted pair?

Q: how can I convert a 2-item list to a dotted pair cons cell? I can convert a 2-item list to a dotted pair with: (let ((list '(1 2))) (cons (car list) (cadr list))) ; => (1 . 2) I'm ...
6
votes
2answers
2k views

add-to-list vs add-hook?

What is the difference between add-to-list vs add-hook? For example I see in progmodes/make-mode.el: (add-hook 'completion-at-point-functions #'makefile-completions-at-point nil t) ...
6
votes
1answer
171 views

Shortening trees list with (setcdr (nthcdr 2 trees) nil)

I am starting to learn elisp and working through this tutorial https://www.gnu.org/software/emacs/manual/html_node/eintr/kill_002dnew-function.html and I do not understand this basic example: (setq ...
5
votes
3answers
1k views

How to check if a given string is a substring of an element of a list

According to documentation, member checks if a a given element is an element of a list. For example if the list, say my_list consists of apple and orange, (member "apple" my_list) returns true. Is ...
5
votes
1answer
717 views

Are the graphical depictions in docs drawed in manual labour?

There are tons of pretty graphical depictions in the emacs(or elisp) docs such as x1: -------------- -------------- -------------- | car | cdr | | car | cdr | | car | ...
5
votes
2answers
981 views

How to iterate over JSON list and select one element

Say I have a list of names with ids, in JSON: (let ((json-object-type 'plist)) (setq mylist (json-read-from-string "[{\"name\": \"Adam\", \"id\": \"1\"}, {\"...
5
votes
1answer
495 views

Add to a list that defcustom has not yet defined

We can avoid adding duplicate elements to a list variable by using add-to-list. When setting a customizable variable (i.e. one that is or will be defined by defcustom) from our init file, we're ...
5
votes
1answer
450 views

Converting nested lists to org-mode lists

I need to convert all nested lists present in buffer to org-mode headers using elisp. How can I do this? 1.2.7.2 Some Header Name -> **** Some Header Name
5
votes
0answers
161 views

Structure-preserving copying of sequences

The form (cl-copy-tree TREE t) returns a deep-copy of a sequence TREE. The the Common Lisp Hyper Spec explains that copy-tree does not preserve circularities and sharing of substructures. I.e., even ...
4
votes
4answers
483 views

Map function onto nested list?

Q: how can I map a function onto elements of nested lists? For flat lists, we can use mapcar to apply a function to each element of the list: (setq flat '("kittens" "puppies" "otters" "bunnies")) (...
4
votes
2answers
350 views

How to delete all list elements matching a regexp?

Given a list: (setq mylist '("a1" "a2" "b1" "b2")) How to delete all elements that match ^a? What I want is "a1" and "a2" deleted, only left "b1" and "b2" in the list.
4
votes
2answers
402 views

How can I paste paragraph not to interrupt numbers in list org mode?

In list environment, after I copy several paragraphs, the next item number will change into number 1, How can I deal with that? For example, 1. aaa 2. aaa 3. aaa bbb <---this is what I copied ...
4
votes
1answer
196 views

Circular list use of “#”

Looking at this, I see (setq x '#1=(a #1#)) but this evaluates to (a #0). As I understand, this should be (a #1=(a #1#)). But then what syntax makes #0 mean #1=(a #1#)? In general what is # doing in ...
4
votes
1answer
220 views

Check box add date in org mode

I have a book list contained which will be read or had done. Like this * English books [0/2] - [ ] bible - [ ] When I use C-c C-c to check, is it possible to add date behind or add low level ...
3
votes
4answers
335 views

How to mapcar uneven lists?

I am aware I can use mapcar to join 2 lists into pairs, however all the map functions seem to quit at the shortest list. This for example (cl-mapcar #'concat '("1" "2" "3" "4") '("a" "b" "c")) ...
3
votes
1answer
233 views

What's difference between + and - in the list in org mode

I find I can create bullets with the - and + both. How can I decide when to use + and -
3
votes
3answers
319 views

Move point inwards while counting number of nested parentheses without throwing an error

I would like to write a function that counts the number of nested parentheses while moving the cursor to the innermost bracket without throwing an error. (defun count-and-move () (interactive) ...
3
votes
2answers
179 views

How to check if two lists share any elements?

Besides looping over list items and comparing, what is a good way in elisp to check if there are any shared items between two lists? For example, in Python this can be done with sets or list ...
3
votes
2answers
168 views

Apply different function to each element in list?

I have a time-stamp of a video formatted as "00:00:00,000" such that "%H:%M:%s,%3N". I am want to eventually use this timestamp as part of an in-interval-p function where I take two timestamps and a ...
3
votes
1answer
732 views

Melpa - 'Failed to download melpa'

I am on a fresh install of emacs 26.3, and I have the following in my init.el: (require 'package) (add-to-list 'package-archives '("melpa", "http://melpa.org/packages/") t) (package-...
3
votes
2answers
912 views

Adding many items to a list

What is the proper way to add many items to a list? I assume just using many add-to-lists is not the normal way?
3
votes
2answers
53 views

How to define a bundle of variable-and-function pairs?

I want to define a bundle of variable-and-function pairs, e.g.: vl/path-doc points to my often used path, and vl/open-path-doc is used for open it in dired-mode. I tried this piece of code: (setq ...
3
votes
1answer
405 views

Org Mode. Set separation length between elements of a list

I have noticed there is a big gap between the elements of a list when exporting to PDF. Is there a way to modify it?
3
votes
2answers
402 views

Sort list by checked/unchecked state

I was wondering if org-mode offers a function to sort a list by the item states? So that checked items appear on top and unchecked items at the bottom? For example with this list - [ ] Not yet done - ...
3
votes
1answer
105 views

How does a list end in nil?

I believe Emacs lists have nil at their end. That said, I was trying to test examples. Can anyone tell the difference between a and b? (setq a '(foo)) (setq b '(foo nil)) ;; Returns nil and (nil)...
3
votes
1answer
53 views

How to map or iterate over a list of files and set the result to `org-agenda-files`?

looking for a little help with my function. I'm trying to create a loop-while that'll return a list of files back to org-agenda-files. It's just not working though and i keep getting errors. Any ideas ...
3
votes
3answers
136 views

List manipulation — appending duplicate equal lists

START WITH: (let ((my-list '((12 1 2016) (12 2 2016) (12 3 2016) (12 1 2016) (12 4 2016) (12 5 2016) ...
3
votes
1answer
86 views

Does `mapc` place a symbol on the active element of the sequence?

I understand that (eq '(3 . d) '(3 . d)) returns nil, and (eq 3 3) returns t. But I do not understand why delq is deleting one (3 . d) in the second example each loop when y is (3 . d). Is mapc ...
3
votes
1answer
134 views

Why is this function not pure

I just spent a significant amount of time debugging an issue that boils down to the following: (defun my-new-alist () `((x . nil))) (setq a (my-new-alist)) (setq b (my-new-alist)) (push 1 (alist-...
3
votes
1answer
192 views

What has replaced elib?

Looking for some data structures for elisp, I came across this. But then this warns me off -- without specifying exactly what replaces elib. So where do I get packages to do doubly linked lists?
3
votes
0answers
328 views

Automatically create checkbox in new line

When creating a list in org-mode, one can press M-RET to create a new line which already has a list item of the same indentation as the line above it in it. How can one achieve the same thing but ...
2
votes
4answers
330 views

Why does the member function return a list's tail rather than t?

Why does Elisp (member '3 '(1 2 3 4 5 6)) return (3 4 5 6) instead of t (true) or 3, or (3)? I see the utility of a function to return the remainder/tail of an ordered list starting from, and ...
2
votes
2answers
544 views

Append lists smartly?

How do I append two lists together, and delete duplicates? For example: (setq list1 ("a" "b" "c")) (setq list2 ("b" "c" "d")) (setq list3 (a b c)) (setq list4 (c d e)) ;; use case (append-list-to-...
2
votes
2answers
108 views

Does `car` on an non-lazy function generated list evals the whole list?

I want to get in a huge directory the first file which satisfies some condition, something like (require 'seq) (require 'f) (defun lazy-filter-file (pred path) (car (seq-filter pred (f--files path ...
2
votes
2answers
356 views

Sort list by decreasing length of the strings

I have this list: (setq MYLIST '("J. Phys." "New. J. Phys." "J. Phys. Soc. Jap." "Phys. Plasmas")) How can I get a new list ordered by the decreasing ...
2
votes
2answers
206 views

Why is the . needed for adding suffixes to the 'auto-mode-alist?

In https://www.emacswiki.org/emacs/AutoModeAlist one needs to use this command in order to add .py for python-mode (add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode)) Why do we need the . ...
2
votes
1answer
60 views

trying to make a self-modifying function [duplicate]

I'm trying to make a function that returns a list of perfect numbers: A perfect number is a positive integer that is equal to the sum of its proper positive divisors For instance, 28 is perfect ...
2
votes
1answer
288 views

Org Mode - Is there a way to reverse org-list-make-subtree?

By using org-list-make-subtree (C-c C-*) you turn an Org List into a sub tree: - Item 1 - Item 2 - Item 3 would turn into * Item 1 ** Item 2 *** Item 3 But is there a built in function (like ...
2
votes
1answer
2k views

Indenting lists in org-mode

I copied and paste text in an org file and formatted it as a list: - Funded pensions :: As explained more fully in Chapter 3, funded pensions are paid on behalf of its members. How can I have the ...
2
votes
1answer
36 views

Make forward-list search for specific symbol only

Is there a way to make forward-list and backward-listsearch for specific symbols (such as 「」『』) only? I have code that make use of these functions to iterate through 「」『』 pairs in plain text. But ...
2
votes
2answers
170 views

Evaluating symbol in function arguments affected by destructive operations?

While evaluating a function call, the arguments is from left to right. For example, (let ((x '(1 2 3))) (list (nreverse x) x)) ;; => ((3 2 1) (1)) The first argument (nreverse x) evaluates to (...