Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Questions tagged [iteration]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
1 answer
23 views

Sample code for events management

I'd like to write a simple loop that catches and prints the incoming event while the script is running. I've tried this: (let ((key 0)) (while (= key 0) (setq event (read-...
user avatar
2 votes
1 answer
43 views

Simple recursive function freezes Emacs — how to correct the definition?

I was trying to familiarize myself with several languages by doing the advent of code exercises in these languages, and one that got me stuck is Emacs Lisp, in the very first exercise. The goal is to ...
user avatar
2 votes
1 answer
27 views

Cycling through a list back and forth

I need an interactive function that works like a generator, whenever it is called it should return "next" or "previous" value from a list. Whenever it reaches the end of the list, ...
user avatar
  • 1,073
0 votes
1 answer
45 views

Alternative way to disambiguate "dangling else" in a cl-loop

I need to achieve in a cl-loop the following conditional written in pseudocode. if (flag1) { if (flag2) {return ...} } else { return ... } Note that it is equivalent to if (flag1 && ...
user avatar
4 votes
2 answers
102 views

How do I splat the arguments to the `or` function?

I would like to evaluate a list of booleans like (nil nil t) into a single boolean, such that if any element is true, then the expression evaluates to true. I first looked at the (or) function in ...
user avatar
0 votes
2 answers
31 views

Query-replace stops after first item in while

Following this StackOverflow question, I coded this function to clean up text pasted from other sources, such as Google Docs: (defun sanitize-md () "Replace characters." (interactive &...
user avatar
  • 1,489
3 votes
1 answer
353 views

How to map or iterate over a list of files and set the result to `org-agenda-files`?

looking for a little help with my function. I'm trying to create a loop-while that'll return a list of files back to org-agenda-files. It's just not working though and i keep getting errors. Any ideas ...
user avatar
3 votes
0 answers
93 views

What kind of destructuring does cl-loop support?

1. Summary Is it possible to destructure an unordered plist in cl-loop's for-clauses? 2. Details From the documentation I would have expected destructuring to be universal, e.g. I would have ...
user avatar
  • 1,481
2 votes
1 answer
91 views

Infinite repetition (iteration) in Elisp code

There is an option to repeat a macro an infinite number of times until the function quits (for example, by reaching the end of the buffer) or if the user cancels the command in keyboard macros ...
user avatar
  • 635
7 votes
1 answer
3k views

How to break out of a dolist loop?

Is it possible to break out of a dolist loop? if not, are there alternatives to dolist that don't involve a while loop and indexing a list?
user avatar
  • 7,079
1 vote
1 answer
139 views

Iterate with both value and index

I want to iterate over a list with both the index and the value in the loop. Currently, the code looks like this: (let ((my-list '(a b c))) (cl-loop for index below (length my-list) for ...
user avatar
4 votes
3 answers
177 views

idiomatic way to lexically scope variables in a cl-loop body

Here is some asynchronous code in a cl-loop: ;;; foo.el --- -*- lexical-binding: t; -*- (let ((my-list '(a b c))) (cl-loop for index below (length my-list) ...
user avatar
0 votes
1 answer
83 views

Confusion about iter-defun

I'd like to make an iterator that yields pairs: (0 1) (1 1) (1 2) (2 2) (2 3) (3 3) etc. I've tried variants of the following: (iter-defun iter-rectangle-sizes () (let ((rect '(0 1))) (while ...
user avatar
1 vote
2 answers
1k views

Loop through top-level headings in Emacs Org-mode

I want to apply (org-id-get-create) to every top-level heading in the buffer. How can I loop through all top-level org-mode headings in the current buffer?
user avatar
  • 1,775
0 votes
3 answers
596 views

how to do a next in a elisp dotimes loop

By next I mean next as found in ruby/perl/python/etc #!/usr/bin/ruby for i in 0..5 if i < 2 then next end puts "Value of local variable is #{i}" end
user avatar
3 votes
4 answers
449 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")) ...
user avatar
  • 503
0 votes
1 answer
217 views

Emacs loops mysteriously

I am using emacs 25.3 and I observe that one indentation function that I wrote loop mysteriously. My function goes following: (defun aut-indent-func () (interactive) (defun loop (begin) (...
user avatar
  • 201
3 votes
2 answers
1k views

How to loop over every line in a buffer? [duplicate]

I am searching for some kind of reduce function, which loops through every line of a buffer, but I can not find it. Does anybody know the name of such a function? Something similar to Perl while (&...
user avatar
  • 1,164
1 vote
1 answer
182 views

Searching for multiple items with occur

I am new to Emacs and I am trying to search for all words entered one by one using 'occur'. I am trying following code: (defun occurlist (ss) (interactive "s\Enter list of search items: ") (...
user avatar
  • 113
6 votes
1 answer
144 views

How do I properly populate a function by iterating over an alist?

I've defined a function that is supposed to iterate over an alist, and use the CAR and CDR of each element in the list to populate the regexp in re-search-forward and the replacement string in replace-...
user avatar
  • 125
1 vote
2 answers
368 views

Standard emacs lisp function for "collect-if"

Is there a standard emacs-lisp function replacement for (defun collect-if (PREDICATE LIST) (loop for el in LIST if (funcall PREDICATE el) collect el)) Example toy application: Extract the odd ...
user avatar
  • 29.9k