Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

2
votes
1answer
49 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 ...
6
votes
1answer
112 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))))
6
votes
1answer
125 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 ...
1
vote
1answer
32 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 ...
2
votes
1answer
46 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 ...
2
votes
1answer
41 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
42 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
44 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?
3
votes
4answers
244 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")) (...
3
votes
0answers
99 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 ...
2
votes
2answers
79 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
100 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 ...
3
votes
2answers
95 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
38 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
26 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 --...
1
vote
0answers
76 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 ...
0
votes
1answer
69 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 ...
1
vote
1answer
101 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 ...
2
votes
4answers
235 views

How to mapcar uneven lists?

I am aware I can use mapcar to join 2 lists into pairs, however all the map functions seem to quit at the shortest list. This for example (cl-mapcar #'concat '("1" "2" "3" "4") '("a" "b" "c")) ...
2
votes
2answers
233 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 ...
2
votes
2answers
303 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
34 views

cons a symbol with a variable and return as a symbol

How can I make fun2 return as the same as fun1? (defun fun1 () '((hello . "test"))) ; <= returns ((hello . "test")) (defun fun2 (str) '((hello . str))) ; <= this is wrong! should return ((...
3
votes
2answers
52 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 ...
0
votes
2answers
233 views

How do I rotate list elements?

Q: how do I rotate the elements of a list such that last becomes first? Given a list of arbitrary length, how do I rotate the list non-destructively such that the last element becomes the first ...
1
vote
1answer
158 views

How to pop an arbitrary element from a list?

Q: how do I pop an arbitrary element from a list? Given the list '(a b c d e), pop returns a and destructively modifies the list to '(b c d e). How can I generalize this function so I could pop an ...
1
vote
1answer
53 views

Doubly-linked list package

Are there any good packages for Emacs that implement doubly-linked lists? I know I could make them myself, but I'd rather not re-invent the wheel.
1
vote
3answers
75 views

How can I convert a list of integers to a string?

Let's say I have a list of integers, representing year, month, day for a date: (2017 8 21) and I want to format the list in one function call, as in (format "%04d-%02d-%02d" 2017 8 21) Is there an ...
2
votes
1answer
273 views

How to sort an association list (alist)?

Is there a way to sort an association list? In my case I would like to sort the alist elements by the values in each list element (represented by the integers in the example below). Example: (setq ...
1
vote
1answer
47 views

How to create and traverse a multidimensional list

I have code like this: (let* ((l1 '(1 2 3)) (l2 '(4 5 6)) (l3 '(7 8 9)) (ml '(l1 l2 l3))) (dolist (l ml) (message "%s" l) (dolist (e l) (message "%s" e)))) But ...
1
vote
1answer
97 views

How to get the value of :ID: property of a org-contacts-entry in an org-capture-template?

Problem I want to get the value of a property of a org-contacts-db entry: \* Example Contact :MYTAG: :PROPERTIES: :ID: foobar :END: With the function call (org-contacts-filter "Example ...
2
votes
2answers
170 views

Why is the . needed for adding suffixes to the 'auto-mode-alist?

In https://www.emacswiki.org/emacs/AutoModeAlist one needs to use this command in order to add .py for python-mode (add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode)) Why do we need the . ...
1
vote
1answer
221 views

how to specify an infinite 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, ...
2
votes
1answer
1k views

How to enable type-check rules with flycheck-tslint

I want flycheck to use the tslint's --type-check flag to compile my typescript files. In order to see unused imports on the fly inside emacs. By tslint docs --type-check Enables the type ...
13
votes
2answers
6k views

How to concatenate two lists?

Sorry, but elisp is not my best. I need to combine two lists of strings in this way: ("a" "b" "c") + ("d" "e" "f") -> ("a" "b" "c" "d" "e" "f") Well, the order is not important, so I wrote this ...
0
votes
1answer
67 views

Custom function to map through nested lists sorting by time-stamp

In the following example, please assume that we are using time-to-seconds to convert each times-stamp into a decimal representation. I have already converted the time-stamps to seconds in this ...
4
votes
0answers
117 views

Structure-preserving copying of sequences

The form (cl-copy-tree TREE t) returns a deep-copy of a sequence TREE. The the Common Lisp Hyper Spec explains that copy-tree does not preserve circularities and sharing of substructures. I.e., even ...
5
votes
1answer
254 views

Add to a list that defcustom has not yet defined

We can avoid adding duplicate elements to a list variable by using add-to-list. When setting a customizable variable (i.e. one that is or will be defined by defcustom) from our init file, we're ...
6
votes
3answers
377 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) ...
2
votes
1answer
84 views

Compare all elements of 2 lists, not necessarily in same order

Q: How to test whether all elements of two lists are the same even though the order may be different? EXAMPLE: (test-fn '(answered cached unread) '(unread answered cached)) => t
1
vote
1answer
126 views

Building a list of strings with a regexp while loop

I'd like to perform a regexp search, capture part of a matched string, and save that part to a list. (Eventually the plan is to save this list to a file in a particular format, but for now a simple ...
2
votes
2answers
223 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 - ...
3
votes
0answers
213 views

Automatically create checkbox in new line

When creating a list in org-mode, one can press M-RET to create a new line which already has a list item of the same indentation as the line above it in it. How can one achieve the same thing but ...
6
votes
2answers
927 views

add-to-list vs add-hook?

What is the difference between add-to-list vs add-hook? For example I see in progmodes/make-mode.el: (add-hook 'completion-at-point-functions #'makefile-completions-at-point nil t) ...
8
votes
6answers
4k 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 ...
3
votes
1answer
60 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 ...
3
votes
3answers
132 views

List manipulation — appending duplicate equal lists

START WITH: (let ((my-list '((12 1 2016) (12 2 2016) (12 3 2016) (12 1 2016) (12 4 2016) (12 5 2016) ...
0
votes
1answer
20 views

Mapping a function over `frame-list` to get a list of the `top` frame-parameter values

I'd like to make a list of parameters of each frame such as the top coordinate, left coordinate, and name to achieve what I asked in my previous question. I'm trying to follow the advice I got there ...
0
votes
1answer
93 views

Problems with setting the default font

I'm trying to set the default font for my Emacs based on a variable (so I can use a different font on a different machine): (setq fontspec (concat ck-font-name "-" (number-to-string ck-font-size))) (...
2
votes
4answers
300 views

Why does the member function return a list's tail rather than t?

Why does Elisp (member '3 '(1 2 3 4 5 6)) return (3 4 5 6) instead of t (true) or 3, or (3)? I see the utility of a function to return the remainder/tail of an ordered list starting from, and ...
1
vote
1answer
70 views

How to use text-properties in a lambda function

I wish to map the text properties onto a list and them insert them on a new buffer. For some reason the following snippet doesn't work. I've used the -map utility from dash.el package for the map. ...