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
2 answers
74 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 ...
2 votes
1 answer
44 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 ...
1 vote
1 answer
35 views

Return a list of functions with a given property or creating a group of functions

I am a copy editor and I make an intensive use of custom "predicates" when I perform replacements in LaTeX code. I use, among others, this technique: ;; predicate (defun omit-comments (beg ...
1 vote
1 answer
93 views

Strange behavior pushing an element into the car of a list using a function

The following is a very simple function called my-function which begins by setting the global variable L to be the list containing nil. The next step is to modify (car L), a.k.a. nil, by pushing ...
0 votes
0 answers
34 views

Dom traversal return nil even though the test condition seems to be true

The purpose of the traversal this time is to be able to visit each node, if there is a specific attribute inside that node, it should return true, add that node to the list and proceed on the next ...
-1 votes
2 answers
143 views

Web scraping traversal using dom.el, pcase error: Unknown pattern

I would like to traverse the dom tree, extract the text and build a list after visiting each node. Implementing the recursion with the help of text-tag function returned an unknown pattern error. The ...
0 votes
1 answer
55 views

Text extraction after dom traversal returns empty

I would like to extract the text from each visited node but while traversing and build a list. I only get an empty result. Here is the following attempt using dom.el (defun extract-text-from-dom (dom-...
4 votes
2 answers
395 views

Filter a list of strings to create a separate list of those that match a given prefix

If I have a list, (“apple” “pear” “grape” “apricot”) how do I create a new list with elements starting with the letter “a”? The new list will be: (“apple” “apricot”).
0 votes
2 answers
54 views

How to step into (apply ..) function when using Edebug?

When using edebug, stepping into a function call works. But if I change the function call from (foo args) to (apply '#foo args) edebug says apply is built-in function and won't let me step into. I ...
1 vote
3 answers
313 views

Does Emacs has a built-in function for unpacking lists with an arbitrary depth that keeps nil values?

What I'm looking for I want to have a function that given the following inputs, returns the following outputs. Input (1 nil) (1 (2) (nil)) (1 (2 (3)) (nil (nil))) (1 (2 (3 (4))) (nil (nil (nil)))) (1 (...
0 votes
1 answer
42 views

How can I return a list from this function given :str nil and 1 argument

I could not figure out how to get a list out of this (my/tf :str nil "foo" ). This function returns a concatenated string of directories or a list. Function Must: Return a string when one ...
-1 votes
1 answer
42 views

Print complete list [duplicate]

I am trying to print a list but I get a partial list when calling (message "%S" mylist) ("richad" "richda" "ricahd" "ricadh" "ricdha" "...
2 votes
2 answers
151 views

How do I get a return of multiple strings from a list?

I want this ("start" "--color=always" "--exclude=*pdf" "end") but I am getting this ("start" ("--color=always" "--exclude=*pdf") &...
0 votes
1 answer
63 views

How to unpack lists regardless of the depth? [duplicate]

I want to have a function that does the following Input '(1 (2) (3)) '(1 (2) ((3 4))) '(1 (2) ((3 4) (5 6))) '(1 (2) ((3 4) (5 6 (7 8)))) '(1 (2) ((3 4) (5 6 (7 8 (9 10))))) Output '(1 2 3) '(1 2 3 4)...
2 votes
1 answer
66 views

add-to-list or push? Is there any disadvantage in using one over the other?

I've added a line in my early-init.el file that sets a background color to prevent the glare during startup. ;; Customize background color to prevent startup glare (add-to-list 'default-frame-alist ...
2 votes
3 answers
1k 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 ...
0 votes
1 answer
57 views

Combining commands for two major modes

I want to extend the execution of the body of emacs-lisp-mode also to lisp-interaction-mode. How can I combine two conditions together? (cond ((eq major-mode 'emacs-lisp-mode) (let ( (...
-1 votes
1 answer
70 views

Print an alist in a named buffer

I want to print an alist in a specific named buffer, which I have to create if it does not exist. either by tabulated-list-format or using table-contents. How can I adapt these two functions to print ...
10 votes
3 answers
5k 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
1 answer
47 views

Elisp construct

What is this construct in elisp ? '( ("approx" "approximately") ("appt" "appointment") ("apt" "apartment") ("dept" &...
0 votes
2 answers
27 views

How do you filter buffer list in a script? [duplicate]

Let's say there are three buffers: "buffer1.py" "buffer2.rb" "buffer3.ipynb" How do you filter/glob that list to select a specific buffer aka (switch-to-buffer "*....
0 votes
2 answers
34 views

kill-buffer ERROR: wrong-type-argument - can't programatically kill buffers

I'm trying to kill buffers after selecting them from buffer-list: (kill-buffer (cl-remove-if-not (lambda (b) (and (string-match-p "ein" (buffer-...
2 votes
2 answers
177 views

Marking as safe all possible lists of strings

Following this answer, I put the following lines in a .dir-locals.el file: ((latex-mode (TeX-engine . default) (mode . latex ) (TeX-master . "main") (ispell-buffer-session-localwords ...
7 votes
4 answers
3k 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 ...
1 vote
1 answer
36 views

Edit org-agenda Files

Is there a way to edit the files which are included in org-agenda? I have a pretty long list and want to just tidy up a bit. I know I have the variable stored in init.el, but it's just one long line ...
7 votes
1 answer
133 views

“(equal a b)⇒t” whereas “(equal b a)⇒error”

GNU Emacs Lisp Reference Manual, 2.8 Equality Predicates: Comparing circular lists may therefore cause deep recursion that leads to an error, and this may result in counterintuitive behavior such as (...
4 votes
1 answer
590 views

Is it faster to add an element at the beginning of a list with add-to-list than at the end?

I've noticed that some people use a t at the end of this code: (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) that t makes it append at the end of ...
0 votes
2 answers
58 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: (...
3 votes
1 answer
726 views

How to write a list literal that contains items conditionally? [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 10 11 ...
1 vote
1 answer
70 views

Add a blank line between headings in the Global TODO list

My Global TODO list shows headings one after another, without any spacing between headings. To me this looks a little crowded, and it would be easier to see the end of one heading and the start of the ...
-2 votes
2 answers
55 views

seq-mapn with array in lambda function

I am using the following function to make a list of lists. (defun pmchart selectr nc) "TODO." (seq-mapn (lambda (p q) (message "p: %S" p) (list q (append ...
-3 votes
1 answer
100 views

Adapting list according to array

I want to construct a list of lists using the function pmchart (pmchart '("Peter" "John") [3 2] 5) to produce '(("Peter" "xxxxx" "xxxxx" "xxxxx&...
0 votes
1 answer
21 views

Updating values in a list

I have the following variable composed of two numbers. (defvar recorder '(0 0)) Inside some function I want to update the first value in recorder. And in another function, I want to update the ...
0 votes
1 answer
253 views

Printing each element in list on separate line

I am using \n so that when printing the list, each element in the list gets a new line when calling message. I am trying to have a go at printing a list where each element does not have a \n at the ...
9 votes
6 answers
1k views

When is the first element in the argument list regarded as a function symbol and when not?

I'm learning elisp, and I just learned that the first element of a list is interpreted as a function symbol. I then learned how to define a function with defun. Here's the example from An Introduction ...
1 vote
2 answers
1k views

Dolist not modifying the list

I'm trying to prepend each substring of split-string with numbering (1.,2.,3.,..) then return all the substrings concatenated with a newline (defun japanese-get-definition (dictentry) "Get a ...
2 votes
2 answers
299 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 (...
4 votes
2 answers
679 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 - ...
1 vote
2 answers
99 views

Why changing the value of this variable via add-to-list is not working?

Usually, I do the following to change a variable's value: 1 - I execute the command set-variable 2 - I pick cider-shadow-cljs-command 3 - I tweak the value changing it to be "shadow-cljs" It ...
0 votes
1 answer
41 views

Working with a list of alists

I have a number of "alists". (defconst assoc-table-1 '( ("frantic" . "fN") ("authentic" . "atN") )) (defconst assoc-table-2 '( ("graphology&...
0 votes
1 answer
22 views

Reading the list produced by (mac-frame-geometry)

I just learned about the function (mac-frame-geometry). It produces a list in the form of: '((outer-position 0 . 25) (outer-size 1920 . 1055) (external-border-size 0 . 0) (title-bar-size 1920 . ...
-3 votes
1 answer
62 views

Adding replacement strings to a list

I want to add replacements to matching words to a list called nscrip. I already have a large number of lists that I use for dabbrev, written in the following form. Perhaps I can use these lists, or ...
0 votes
1 answer
38 views

Clear list when number of elements exceeds N

I have a list, and want to clear it with (setq slist '()). But I only want to do this when the number of elements exceeds the value N.
1 vote
0 answers
32 views

Clearing a made list [closed]

I am adding to a list as I execute a number of functions. How can I clear the elements in the list by calling a function for such task.
0 votes
1 answer
25 views

Adding to a list when there is a match only

The following function replaces filenames and places the result in a list. Although the list gets filled, I do not want to add the filename when there is no match. How can I avoid sending non-...
1 vote
1 answer
286 views

How can I use `add-to-list` to add multiple elements to a list value of a variable?

Is this the way to use add-to-list with multiple entries? (add-to-list 'auto-mode-alist '(("\\.f\\'" . fortran-mode) ("\\.F\\'" . fortran-mode) ...
0 votes
3 answers
185 views

Using `let` with `list`

I have read that by default, a function returns the value of the last expression evaluated as the return value. Does it mean that when using special form let, the value of the last expression in the ...
2 votes
1 answer
70 views

Why do stream-cons and cons behave differently?

I am trying to create a lazy sequence of the lines in the current buffer using the stream.el library. These two recursive functions both read the lines of the current buffer from point to the end of ...
1 vote
2 answers
124 views

How to randomize the order of elements in an alist?

I'm using ielm inside Emacs to randomize an associative list. I'm getting duplicate entries a lot of the time, not sure what I'm doing wrong? (defun q () "Q." (let ((alist)) (setf ...
0 votes
1 answer
38 views

Unclear wrong argument

The following expression: (car input-method-function) Give the following message: Wrong type argument: listp, list Why? input-method-function is list.