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
6
votes
2answers
2k 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) ...
3
votes
4answers
335 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
356 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 ...
3
votes
2answers
912 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
42 views

cons a symbol with a variable and return as a symbol [duplicate]

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
53 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
473 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
227 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
63 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.
2
votes
1answer
584 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
3answers
101 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 ...
1
vote
1answer
49 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
145 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
206 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 . ...
2
votes
1answer
2k 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 ...
15
votes
2answers
10k 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
79 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 ...
5
votes
0answers
161 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
495 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 ...
2
votes
1answer
145 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
2
votes
1answer
147 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 ...
3
votes
2answers
402 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
328 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 ...
3
votes
3answers
136 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
134 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))) (...
0
votes
1answer
23 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 ...
1
vote
1answer
79 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. ...
2
votes
4answers
330 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 ...
5
votes
3answers
1k 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 ...
12
votes
1answer
1k views

Meaning of period in (. 123)

I learnt . /path/to/file in bash is used to execute a file. Just out of curiosity, I eval something like the following in Emacs (. 123) ⇒ 123 (read "(. 123)") ⇒ 123 It looks like Emacs ...
1
vote
1answer
84 views

How to merge two buffers containing questions and answers

In my line of work, I often have one document containing questions and another document containing answers. How can I merge these documents in the form of Question/Answer. BUFFER #1: Q1: Do you ...
0
votes
1answer
773 views

how to access/print a list of a list?

Given; (setq whole '(group1 group2(element1 element2(suba subb subc) element3) group3)) I would to print some list of that list, like element2 sublist. How can i do it?
7
votes
1answer
327 views

Convert 2-item list to a dotted pair?

Q: how can I convert a 2-item list to a dotted pair cons cell? I can convert a 2-item list to a dotted pair with: (let ((list '(1 2))) (cons (car list) (cadr list))) ; => (1 . 2) I'm ...
1
vote
2answers
70 views

Test whether all elements/symbols of a list are the same (eq)

Project: (1) Push every new this-command onto a list containing any previously pushed this-command. (2) Limit the list to a variable length (e.g., 3 or 5), and chop off the oldest. (3) Compare ...
2
votes
1answer
288 views

Org Mode - Is there a way to reverse org-list-make-subtree?

By using org-list-make-subtree (C-c C-*) you turn an Org List into a sub tree: - Item 1 - Item 2 - Item 3 would turn into * Item 1 ** Item 2 *** Item 3 But is there a built in function (like ...
1
vote
2answers
1k views

How to remove MELPA repository from package-archives?

I added MELPA stable and MELPA repositories with (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/")) (add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa....
12
votes
1answer
480 views

Why does a constant in `let` change with repeated calls? [duplicate]

Say we have such a foo function: (defun foo (e) (let ((lst '(a b c))) (delq e lst))) Then we use it in following way (sequentially evaluating one by one): (foo 'c) ; => (a b) (foo 'b) ; =&...
5
votes
1answer
450 views

Converting nested lists to org-mode lists

I need to convert all nested lists present in buffer to org-mode headers using elisp. How can I do this? 1.2.7.2 Some Header Name -> **** Some Header Name
3
votes
1answer
192 views

What has replaced elib?

Looking for some data structures for elisp, I came across this. But then this warns me off -- without specifying exactly what replaces elib. So where do I get packages to do doubly linked lists?
3
votes
1answer
134 views

Why is this function not pure

I just spent a significant amount of time debugging an issue that boils down to the following: (defun my-new-alist () `((x . nil))) (setq a (my-new-alist)) (setq b (my-new-alist)) (push 1 (alist-...
8
votes
2answers
138 views

Proper reinitialization of a list? What is happening under the hood?

I'm teaching myself some more elisp and have encountered the following problem: If I want to reset a list variable it won't get updated after the first evaluation. Here is some example code: (defun ...
15
votes
1answer
2k views

Is '(a . b) really a list?

I'm really confused with the . notation. Is '(a . b) a list? (listp '(a . b)) returns t but when I want to know its length (length '(a . b)) gives an error Wrong type argument: listp, b. The same is ...
2
votes
1answer
229 views

Change level into list in org mode

I have following text which are expressed in level 5 ***** It's better to be first than it is to be better. ***** The basic issue in marketing is creating a category you can be first in. It’s the law ...
4
votes
1answer
220 views

Check box add date in org mode

I have a book list contained which will be read or had done. Like this * English books [0/2] - [ ] bible - [ ] When I use C-c C-c to check, is it possible to add date behind or add low level ...
2
votes
1answer
133 views

turn a list into a set of arguments for a function [duplicate]

I have a defun get-quotes with one mandatory and 2 optional arguments. I would like to do something like this: (let ((articles '("/home/matt/art/mice.pdf" '("/home/matt/art/cats.pdf" "Smith, ...
0
votes
1answer
60 views

list data structure split across files?

If I were trying to use a list as a data structure -- and it was getting really big -- is there a precedent of breaking it up and having it span files? One particular list of mine is looking very tree-...
2
votes
1answer
61 views

How to add-to-list to read-in file contents

When I do this (setq v (f-read-text "s.el")) where s.el is of this form ((thing1 . thing2) (thing3 . thing4)) I get v back as one long string. And (setq v (append (f-read-text "s.el"))) doesn't seem ...
2
votes
2answers
544 views

Append lists smartly?

How do I append two lists together, and delete duplicates? For example: (setq list1 ("a" "b" "c")) (setq list2 ("b" "c" "d")) (setq list3 (a b c)) (setq list4 (c d e)) ;; use case (append-list-to-...
2
votes
1answer
2k views

Indenting lists in org-mode

I copied and paste text in an org file and formatted it as a list: - Funded pensions :: As explained more fully in Chapter 3, funded pensions are paid on behalf of its members. How can I have the ...
4
votes
2answers
402 views

How can I paste paragraph not to interrupt numbers in list org mode?

In list environment, after I copy several paragraphs, the next item number will change into number 1, How can I deal with that? For example, 1. aaa 2. aaa 3. aaa bbb <---this is what I copied ...