Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more

Questions tagged [iteration]

The tag has no usage guidance.

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

Looping a vector of 5*n entries by steps of 5 while assigning chunks of 5 to local variables

A server sends a vector of integers like [6 4 8 7 16 ...] and the protocol says it will be always 5n values. Is there a nice way to loop over the vector assigning chunks of 5 values to 5 local ...
Harald's user avatar
  • 328
1 vote
2 answers
90 views

Ignore condition in initial run of while loop

In C# you can write a while-loop like this do { stuff(); } while (condition) which means it will first do stuff() once, and only then start checking the condition for additional runs. Is there an ...
meedstrom's user avatar
  • 153
1 vote
1 answer
167 views

How to terminate a while loop

I'm not very skilled in elisp, I have only a minimal knowledge of it. I have to modify an existing function, as I'm trying to fix a problem in an obsolete emacs package that could fulfill my needs.? (...
Carlo Dormeletti's user avatar
0 votes
1 answer
232 views

How to iterate over a sequence of elements?

I want to set the foreground colours for outlines using a list stored in pigment-darkbg. How can I do this in a neat and short way ? (defun outline-tyface () (interactive) (let ( (pigment-darkbg ...
Dilna's user avatar
  • 1
1 vote
1 answer
65 views

How do you install DoReMi?

I found that DoReMi is a better way of resizing windows in emacs, but DoReMi is not in the Melpa package repository. I looked at the Emacs Wiki and doremi.el was there but I'm not too sure how to use ...
FFFluoride's user avatar
2 votes
0 answers
88 views

why does the Iterator Yield A Different Value?

I tested two similar generators, and the result confused me. This iterator yields values as I expected: ELISP> (iter-defun f (x) (setq x (iter-yield (1+ x))) (setq x (iter-yield ...
shynur's user avatar
  • 5,318
-1 votes
2 answers
44 views

interactively prompt for a list (or regex) rather than just a single item

I have a function to kill buffers matching a given regex: ;; Like kill-matching-buffers, but doesn't prompt every time. ;; TODO: get this to use vertico (defun kill-matching-buffers-just-do-it () &...
firstname gklsodascb's user avatar
0 votes
2 answers
84 views

Iterate over vector (or sequence) and use index and value in conditional

I want to go through the values (0 or 1) of an array, then if entry has value 1, a function is called. But I also want to keep track on which element I am processing. (defvar selectr [0 1 1 0 0]) ...
Dilna's user avatar
  • 1
2 votes
1 answer
60 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-...
Quasar999's user avatar
3 votes
2 answers
155 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 ...
jthulhu's user avatar
  • 225
2 votes
1 answer
125 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, ...
iLemming's user avatar
  • 1,263
0 votes
1 answer
58 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 && ...
Firmin Martin's user avatar
3 votes
1 answer
91 views

How to distinguish input from the return value of body in while-no-input?

(while-no-input &rest BODY) Execute BODY only as long as there's no pending input. If input arrives, that ends the execution of BODY, and while-no-input returns t. Quitting makes it return nil. ...
tejasvi88's user avatar
  • 151
2 votes
4 answers
1k views

Equivalent of `continue' in `cl-loop'?

Does the cl-loop macro implement an equivalent to the continue keyword of other languages? The behavior of break can be achieved by using until or while clauses by placing them in the middle of cl-...
kdb's user avatar
  • 1,561
4 votes
2 answers
205 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 ...
Linus Arver's user avatar
0 votes
2 answers
42 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 &...
emonigma's user avatar
  • 1,907
3 votes
1 answer
1k 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 ...
Nick Martin's user avatar
3 votes
0 answers
250 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 ...
kdb's user avatar
  • 1,561
2 votes
1 answer
175 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 ...
Sati's user avatar
  • 815
13 votes
2 answers
5k 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?
ideasman42's user avatar
  • 8,826
3 votes
1 answer
744 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 ...
Damien Cassou's user avatar
4 votes
3 answers
240 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) ...
Damien Cassou's user avatar
1 vote
1 answer
119 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 ...
little-dude's user avatar
3 votes
2 answers
2k 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?
Adam's user avatar
  • 1,897
0 votes
3 answers
847 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
american-ninja-warrior's user avatar
3 votes
4 answers
582 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")) ...
Oly's user avatar
  • 593
0 votes
1 answer
282 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) (...
Jason Hu's user avatar
  • 201
4 votes
2 answers
2k 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 (&...
ceving's user avatar
  • 1,368
1 vote
1 answer
249 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: ") (...
rnso's user avatar
  • 113
6 votes
1 answer
217 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-...
rjww's user avatar
  • 125
1 vote
2 answers
506 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 ...
Tobias's user avatar
  • 33.2k