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
0
votes
1answer
17 views

Flatten parallel nested window trees

Sometimes when moving windows around in emacs, it will get to a state where there is a horizontal or vertical stack of windows which appears to be a single list, but is actually made up of multiple ...
0
votes
1answer
35 views

What does setcdr do to a list which is the return value of a function?

If I have something like this, (setq first (list 'a 'b 'c)) (setq second (list 'x 'y 'z)) ;; I know the let binding makes little sense but ;; I need it in the full version of the function. (defun ...
0
votes
1answer
24 views

How to extract tables names from an org file?

I have an org file with headlines and subheadlines containing tables. Each table has a name (i.e. each table starts with a #+name: tablename header). I'd like to generate a list containing all tables ...
1
vote
1answer
29 views

How can I apply function `max` to a list of numbers?

I want to find the max element in a list of numbers. (setq l (list 1 2 3 4 5)) What is an easy way to call the max function on l? So far I have this but this seems convoluted: (eval `(max ,@l)) It ...
0
votes
0answers
26 views

Bullets in Lists (Org-Mode) [duplicate]

like asked here: custom bullet style Isn't there any way to use • in Org-mode lists? It would look much nicer than *... I made a shortkey to insert • bullets, but they won't be recognized by Emacs as ...
36
votes
3answers
14k views

What's the difference between push and add-to-list?

I've found that different packages in their installation instructions use either push or add-to-list (For example adding a directory to load-path) and I was wondering what the difference is and what ...
0
votes
1answer
23 views

Why does a stray period cause an error I associate with mismatched parens?

A typo that changed (foo) to (foo . ) in my .init file caused an Invalid read syntax: ) error. I get why it's a syntax error. But why this error? I thought this error message reliably reflected ...
0
votes
2answers
36 views

How to remove an item from a list of unique items, returning true on success?

Sometimes a list is known to contain a list of unique items, where it is useful to check if the item exists in the list, removing it if it does. This is an inefficient way to accomplish this: (...
0
votes
1answer
35 views

Any existing function to fix comma-separated list in parens-pair?

I am looking a way to programatically fix invalidly formatted code for programming languages that use relatively simple list expression of elements separated by commas (ie, not in C++). For example I'...
2
votes
1answer
35 views

How to merge overlapping ranges given a list of (min . max) cons cells?

Given a list of cons cells, what is an efficient way to merge overlapping ranges? When any values minimum or maximum are within the bounds (inclusive) of any of the other cons cells in the list, these ...
4
votes
2answers
564 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 ...
0
votes
1answer
39 views

nconc does not seem to update first parameter when its value is nil

I’m trying to add several values at once to a given list, which may be nil or already contain some other values. After some research, I found the two following versions are working well: (let ((x '(a))...
6
votes
3answers
2k 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?
0
votes
1answer
30 views

capture the content of buffer as a list

I want to pass a buffer's content into a list. I figured out how to read the content of the buffer I want to use but cannot figure out how to correctly capture the content and then use it as a list. ...
4
votes
1answer
245 views

How can I convert a string form of a list to an actual list?

I would like to convert these two strings "(a b c)" "(9 . 3)" to these (a b c) (9 . 3) I'd had some luck with the first one evaluating this, (mapcar 'intern (split-string (string-...
1
vote
2answers
52 views

How to add suffix to all list member?

When I evaluate (setq sample-list (list 'abc 'def)) (message "%s_suffix" sample-list) Output is: (abc def)_suffix But I need to get: abc_suffix def_suffix How can I get the output?
4
votes
4answers
353 views

Combine two lists elementwise

I need to combine two lists elementwise. Given two lists that look something like, (setq qux '("foo" "bar" "baz")) (setq quux '("xyzzy" "thud" "...
3
votes
3answers
289 views

When is it better to use the backquote, `(…), and when to use (list …)?

The docstring for quote says, Quoting should be reserved for constants that will never be modified by side-effects, unless you like self-modifying code. Are there cases in which it is the best ...
3
votes
1answer
96 views

What is the difference between these two lists?

I'm reading An Introduction to Programming in Emacs Lisp by Robert J. Chassell. When the book is introducing setcar, it points out that when we use this function to a list, the list should be ...
3
votes
2answers
239 views

What difference does it make changing the order of arguments to 'append'

I want to understand the implications of append's property that "All arguments except the last one are copied, so none of the arguments is altered." (from the Elisp manual) Say I have a list ...
9
votes
1answer
1k 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 ...
1
vote
2answers
69 views

How to add a string at nth position of an ordered list of strings

The built-in function add-to-ordered-list is for symbols, not strings. I have a list of strings and need to add another string to the list at a specific nth position. How can I accomplish this? TASK:...
0
votes
1answer
23 views

Access strange list data

I'm trying to parse the output of ledger-context-at-point for the account name. The output looks something like: (acct-transaction account ((indent " " 238117) (status nil nil)...
2
votes
5answers
968 views

Remove multiple elements from a list

Given '(a b c d), how would I remove b and c to end up with '(a d)? Is there a "right" way to remove multiple, distinct elements from a list? Obviously, one could do (delete 'c (delete 'b '(a b c d))...
3
votes
3answers
58 views

Retrieve alist from list of alists by value of specific key inside of it

I'm probably missing something simple here but... I've got a list of alists parsed from JSON using json-parse-string. The list of alists is like the following (details omitted for brevity): ( ((id . 1)...
2
votes
2answers
231 views

Assoc in a nested alist

I have the following nested alist: (setq x '(foo . ((bar . ((chocolate . "edible") (gold . "inedible"))) (jar . "glass")))) How can get entry (chocolate ...
1
vote
3answers
266 views

Replace element in a list / add in case of absence, with custom test/key functions

add-to-list doesn't refresh item, it only checks for existence of item by equal or custom comparison function: (add-to-list 'tramp-methods '("gssh" (tramp-login-program "gcloud ...
1
vote
1answer
45 views

Function like `setcar` that doesn't change the value of the input function?

Early beginner here. I'm looking for a function that takes a list and changes only its first element, using some function or other. I realize setcar sort of does that, but it also changes the initial ...
3
votes
3answers
435 views

How to replace an element of a list?

Is there a way to replace an item in a list? (replace-element-in-list (elem-src elem-dst ls &optional times comparison-fn)) ;; ... ) Example use: (replace-element-in-list 1 100 '(3 2 1)) => ...
3
votes
1answer
42 views

How to add a value after a given value in parts of a list, returning a new list?

I have the following structure: '((a (1 2 3 4)) (b (1 2)) (c (1 3 4 5)) I want to return a new list that's similar, but that has a 7 inserted after each 2: '((a (1 2 7 3 4)) (b (1 2 7)) (c (1 ...
3
votes
1answer
275 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 ...
1
vote
2answers
237 views

Filter list by regexps

How can I get all elements of a list which don't match multiple patterns? The patterns are given as a list. For instance, I want all files without '("no" "nix") in them. (setq se-...
1
vote
2answers
385 views

Is there a way to spread a list like in Typescript or Golang?

I have a variable with some common values between dap-mode debug templates and I want to use that variable along with other cons elements for :environment-variable in languages like Golang or ...
2
votes
1answer
384 views

How to write a list literal with conditional items? [duplicate]

Given a list literal '(1 2 3) is it possible to conditionally include parts of the list? eg: '(1 2 3 (when thing-is-true '(10 11 12))) 4 5 6) Which would result in '(1 2 3 4 5 6) or '(1 2 3 ...
6
votes
1answer
7k 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-...
0
votes
3answers
207 views

How to replace a list within a list?

What would be the an efficient/concise way to replace a sub-list with another list? Example function call: (replace-list-list-with-list '("A" "B" "C" "D") '("B" "C") '("NEW" "TEXT")) Would result ...
8
votes
3answers
1k 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))))
3
votes
1answer
69 views

Why does Flycheck complain "mapcar called for effect" when my function returns the result of mapcar by design?

Since installing Flycheck I've been bombarded with complaints about the elisp functions I've used reliably for years. This is the first one I can't understand. Here my function is designed to return ...
3
votes
1answer
155 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)...
9
votes
7answers
9k 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 ...
0
votes
1answer
44 views

Print matching strings line by line

I was trying to use this code shared by @JordonBiondo over here to collect regex matches in a list. (defun matches-in-buffer (regexp &optional buffer) "return a list of matches of REGEXP in ...
1
vote
0answers
48 views

Emacs freezes when using split-string in recursive function

I'm trying to figure out why my emacs keeps freezing when running this set of functions to split a string into a list of pairs. Is there some significant overhead happening when using string-split? Is ...
1
vote
2answers
512 views

Get first n elements of a list

How can I get the first N elements of a list? I know I can use subseq: (subseq '("one" "two" "three" "four" "five") 0 2) Yet when I use subseq, it produces one of the following results: on the ...
1
vote
1answer
44 views

Would (cycle-list <ls>) be a bad idea?

Would you consider something like this a bad practice? (defun cycle-list (ls &optional backward?) "Given any list, returns the next element each time it is called." (let* ((last-pos (- (...
4
votes
1answer
265 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 ...
2
votes
1answer
39 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 ...
1
vote
2answers
229 views

How to subtract 1 from the nth element of a list of numbers?

How do I subtract 1 from the second element of the list (3 6)? (setq x '(3 6)) (- (nth 1 x) 1) The above quote does the math but does not return a modified list.
-1
votes
2answers
58 views

Add a number to every item in list

How do I add a number, say 2, to every item in a list? (setq x '(1 2)) (+ 2 x) (mapcar '2+ x) (loop for i in x do (+ 2 i)) (dolist (i x) (+ 2 i)) None of the above work.
3
votes
3answers
336 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
201 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 ...