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
4 votes
2 answers
352 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
  • 181
0 votes
2 answers
31 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
301 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
  • 398
-1 votes
1 answer
32 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,183
0 votes
1 answer
55 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
  • 398
2 votes
1 answer
50 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
  • 391
0 votes
1 answer
49 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,183
-1 votes
1 answer
54 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,183
0 votes
1 answer
44 views

Elisp construct

What is this construct in elisp ? '( ("approx" "approximately") ("appt" "appointment") ("apt" "apartment") ("dept" &...
Dilna's user avatar
  • 1,183
0 votes
2 answers
21 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
18 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
161 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
24 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
508 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
  • 391
0 votes
1 answer
38 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
132 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
  • 151
7 votes
1 answer
132 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
  • 4,272
0 votes
0 answers
31 views

Why setf to add a new element failed in function body?

(setq orig '((a . 1) (b . 2))) (setq added '((b . 0) (c . 3) (d . 4))) ;; method 1 (mapc (lambda (x) (setf (alist-get (car x) orig) (cdr x))) added) orig ;; =&...
yinz Liu's user avatar
1 vote
1 answer
65 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
  • 148
-2 votes
2 answers
53 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,183
-3 votes
1 answer
86 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,183
0 votes
1 answer
20 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,183
0 votes
1 answer
162 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,183
9 votes
6 answers
996 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
  • 191
1 vote
2 answers
87 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
36 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,183
0 votes
1 answer
19 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,202
0 votes
1 answer
37 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,183
-3 votes
1 answer
58 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,183
1 vote
0 answers
31 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,183
0 votes
1 answer
23 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,183
1 vote
1 answer
184 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,183
0 votes
3 answers
88 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,183
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
100 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
36 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
122 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
  • 18.9k
1 vote
2 answers
54 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
  • 18.9k
0 votes
0 answers
74 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,406
2 votes
2 answers
43 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
  • 18.9k
1 vote
1 answer
61 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 '...
Alexey Gorelov's user avatar
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
  • 18.9k
0 votes
1 answer
72 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,555
0 votes
1 answer
81 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,185
1 vote
1 answer
218 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
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 ...
OsunSeyi's user avatar
0 votes
1 answer
26 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 ...
Leah Velleman's user avatar
0 votes
1 answer
111 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'...
PRouleau's user avatar
  • 754
2 votes
1 answer
42 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 ...
ideasman42's user avatar
  • 8,406
0 votes
2 answers
56 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: (...
ideasman42's user avatar
  • 8,406