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
3
votes
1answer
58 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 ...
0
votes
2answers
39 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
310 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
212 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 ...
3
votes
1answer
806 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
146 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 ...
7
votes
3answers
309 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))))
1
vote
1answer
24 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
106 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
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 ...
0
votes
1answer
37 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
41 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
81 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
43 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 (- (...
9
votes
0answers
512 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 ...
4
votes
1answer
197 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
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 ...
1
vote
2answers
186 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
50 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
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) ...
1
vote
4answers
318 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
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 ...
1
vote
2answers
37 views

How to check if a list ends with another list?

Currently I'm using a fairly inefficient way to check if one list uses another list at it's end. Is there a more efficient way to do this? (defun is-in-list (ls-haystack ls-ends-with) (catch 'found ...
3
votes
2answers
180 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 ...
1
vote
1answer
47 views

Is function `list` equivalent to using `cons` with a final cdr of `nil`?

I'm trying to explain Elisp to 5th and 6th graders and I tell them that (+ 1 2) evaluates to 3 and not (3). So if I do want something that evaluates to (3) would I just evaluate ((+ 1 2))? No! This ...
0
votes
2answers
47 views

Representing leading zeroes in a list

I would like to have this table #+NAME: addition-table | | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | |---+----+----+----+----+----+----+----+----+----+----| | 0 | 00 | 01 | 02 | 03 | 04 | ...
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 | ...
7
votes
5answers
685 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) ...
6
votes
1answer
172 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 ...
0
votes
1answer
397 views

how to specify an Cyclic list in lisp?

How to specify a list, which's last element is referring to the first element? By specify I mean, for example, how to write a setq statement with this list. I have seen this in the documentation, ...
1
vote
1answer
58 views

Map each element of a list over every element of another list

Let's assume I've got two lists: ("A" "B" "C" "D") and ("+" "-"). I want to concatenate each element of the first list with every element of the second to get ("A+" "A-" "B+" "B-" ... ). Is there a ...
0
votes
1answer
34 views

Inline elements of variable list value in rx() macro call [duplicate]

Is there a more compact way to make use of the rx macro in cases where we want to inline a list of strings from a variable? Such as (defconst c++20-new-keywords-list (list "char8_t" "import" ...
1
vote
1answer
130 views

Elisp: How to accumulate function return into a list

I have this small snippet of Elisp code that decodes kernel traces: (defvar projbase "/my/proj/base") (setq my_shell_output (substring (shell-command-to-string (concat "/home/demetra/scripts/...
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 ...
1
vote
2answers
120 views

Orgmode automatically increment an unordered list

I use org-mode for planning projects and tasks, etc. Say I am reading a book and I want to track my progress chapter by chapter. I want to create a list of repetitive elements with an incremented ...
2
votes
1answer
61 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 ...
1
vote
2answers
599 views

How to continue giving list number after insert a block of code

GNU Emacs 24.5.1 (i686-pc-mingw32) Org-mode version 8.2.10 (release_8.2.10 @ e:/emacs/share/emacs/24.5/lisp/org/) In my org file, 1. one thing #+begin_src sh ls -la #+end_src 2. second ...
1
vote
1answer
52 views

midnight-mode add-to-list Format specifier doesn't match argument type

I've been trying to get midnight-mode to add to the following list. I have a feeling it has to do with an elisp error in my config I'm not seeing. It works fine with setq, but with add-to-list I get a ...
3
votes
1answer
408 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?
0
votes
1answer
59 views

List variable that is set to one list or another depending on condition

I am trying to create a list variable that can be set to one list or another depending on a condition. What I have so far is as follows. (let ((l (if local list1 list2))) ; Append items to the list ...
0
votes
1answer
48 views

How can i add same value to every item in list, turning it into alist?

I tried to use this code, but it returns (k k k k k) (mapcar (lambda (x) 'cons x '(k)) '(a b c d e)) What am i doing wrong here? Why doesn't cons work?
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")) (...
2
votes
2answers
171 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 (...
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 ...
4
votes
2answers
357 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.
2
votes
2answers
66 views

Arbitrary length lists as argument for interactive function

Say I have a defun with a dolist inside that I want to be able to pass a string that is then converted to a list with a length equal to the number of words in said string via the minibuffer, so ...
0
votes
1answer
31 views

Comparing `system-configuration-options` to a user-specified list

In this example, the system-configuration-options is a string: "--prefix=/Users/HOME/.0.data/.0.emacs/.0.x11 --with-x --with-ns=no --enable-checking=yes,glyphs --enable-check-lisp-object-type --...
0
votes
1answer
114 views

Updating `dired-directory` after renaming a file

Q:   I have a list of strings: '("apple" "pear" "peach" "nectarine" "watermelon"). How can I replace "peach" with "plum" and maintain the same order of fruits?  [CAVEAT: The list may be very long ...
2
votes
0answers
120 views

Directed Acyclic Graphs in Emacs Lisp

Emacs Lisp has support for lists (naturally), association lists, and property lists, vectors, and hash tables. Does it have support for directed acyclic graphs (DAGs)? I have not found a DAG API in ...
1
vote
1answer
166 views

Replacing autoref command format specification in auctex's font-latex-match-reference-keywords-local

With some help I have redefined the autoref command to take an optional argument, see https://tex.stackexchange.com/questions/428229/autoref-with-optional-argument-text-in-generated-link Now I am ...