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
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 ...
Gabriele Nicolardi's user avatar
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 ...
Ruy's user avatar
  • 839
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 ...
alexander's user avatar
  • 133
-1 votes
2 answers
142 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 ...
alexander's user avatar
  • 133
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-...
alexander's user avatar
  • 133
4 votes
2 answers
394 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”).
zeynel's user avatar
  • 371
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 ...
eugene's user avatar
  • 489
1 vote
3 answers
312 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 (...
rdrg109's user avatar
  • 408
-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" "...
Dilna's user avatar
  • 1
0 votes
1 answer
62 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)...
rdrg109's user avatar
  • 408
2 votes
1 answer
65 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 ...
Zoli's user avatar
  • 421
0 votes
1 answer
56 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 ( (...
Dilna's user avatar
  • 1
-1 votes
1 answer
68 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 ...
Dilna's user avatar
  • 1
0 votes
1 answer
47 views

Elisp construct

What is this construct in elisp ? '( ("approx" "approximately") ("appt" "appointment") ("apt" "apartment") ("dept" &...
Dilna's user avatar
  • 1
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-...
Daniel Krajnik's user avatar
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 "*....
Daniel Krajnik's user avatar
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 ...
tigerjack's user avatar
  • 163
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 ...
Jason Hunter's user avatar
4 votes
1 answer
586 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 ...
Zoli's user avatar
  • 421
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 ...
Rick's user avatar
  • 25
2 votes
2 answers
150 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") &...
ritchie's user avatar
  • 149
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 (...
shynur's user avatar
  • 5,164
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 ...
ironfish's user avatar
  • 248
-2 votes
2 answers
54 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 ...
Dilna's user avatar
  • 1
-3 votes
1 answer
99 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&...
Dilna's user avatar
  • 1
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 ...
Dilna's user avatar
  • 1
0 votes
1 answer
249 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 ...
Dilna's user avatar
  • 1
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 ...
norio's user avatar
  • 203
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 ...
Pedro Delfino's user avatar
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&...
Dilna's user avatar
  • 1
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 . ...
ocodo's user avatar
  • 1,222
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.
Dilna's user avatar
  • 1
-3 votes
1 answer
60 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 ...
Dilna's user avatar
  • 1
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.
Dilna's user avatar
  • 1
0 votes
1 answer
24 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-...
Dilna's user avatar
  • 1
1 vote
1 answer
284 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) ...
Dilna's user avatar
  • 1
0 votes
3 answers
181 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 ...
Dilna's user avatar
  • 1
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 ...
Johan Myréen's user avatar
1 vote
2 answers
123 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 ...
gdonald's user avatar
  • 167
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.
Quasar999's user avatar
1 vote
2 answers
125 views

Incorporate a list of floats, into another list of floats, in numerical order, with remainders

In this example, there is a list of miscellaneous orphan floats '(9.9 10.1 10.3 10.5 10.7 10.9 11.1) that needs to be incorporated in numerical order into a second main / master list (10.0 10.2 10.4 ...
lawlist's user avatar
  • 19.1k
1 vote
2 answers
57 views

Next greater or lesser number than ARG in a list of integers

In this example, there is a list of integers '(2527 1771 2107 2317). The variable arg is an integer, which may or may not be one of the integers in the list. Q: How can an Emacs user ...
lawlist's user avatar
  • 19.1k
0 votes
0 answers
85 views

Why not build lists in-order? (instead of pushing to the front & reversing)

In emacs-lisp a common pattern is to build a list by adding to the font, then reversing it. As it's possible to build the list by storing the last cons cell, then appending to it - it seems like a ...
ideasman42's user avatar
  • 8,726
2 votes
2 answers
45 views

ring: convert a ring back to a list -- keeping rotation

In the following example, the element (c fig) is the current-item. The user has chosen to rotate the ring forwards, by calling ring-next. How can a user return the revised list in its rotated state; ...
lawlist's user avatar
  • 19.1k
1 vote
1 answer
65 views

Process of packages loading

It seems I totally do not understand the mechanism of package loading in Emacs. I have in my init.el something like this: (use-package elpy :ensure t :init (elpy-enable) :config (defalias '...
Alex's user avatar
  • 155
0 votes
1 answer
46 views

(copy-sequence (cons 'foo 'bar)) => wrong-type-argument listp

In this example, there is a cons-cell (foo . bar) which needs a two (2) step approach so that it can be copied using copy-sequence: First, there needs to be a test to identify this particular type of ...
lawlist's user avatar
  • 19.1k
0 votes
1 answer
79 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 ...
Arch Stanton's user avatar
  • 1,625
0 votes
1 answer
101 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 ...
crocefisso's user avatar
  • 1,244
1 vote
1 answer
298 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 ...
jds's user avatar
  • 177
0 votes
0 answers
27 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 ...
OsunSeyi's user avatar