7

One option is to use catch / throw: https://www.gnu.org/software/emacs/manual/html_node/elisp/Catch-and-Throw.html (catch 'foo (dolist (x '("a" "b" "c" "d" "e" "f" "g")) (when (equal x "d") (throw 'foo x)))) The catch statement evaluates to the value thrown (x in this case), or the value of the last body form if the throw function never ...


6

The two built-in "zip-with" functions: seq-mapn from seq.el (Emacs ≥ 25.1) cl-mapcar from cl-lib.el (Emacs ≥ 24.3; was mapcar* in cl.el before that) and the most prominent third-party one: -zip-with from dash.el (Dash ≥ 1.1.0) all share the limitation you describe: all the map functions seem to quit at the shortest list The philosophical ...


6

A slightly more idiomatic example: (goto-char (point-min)) (while (not (eobp)) ... (forward-line 1))


5

You can make a while loop using the function forward-line as your test. If forward-line reaches the end of the buffer, it returns the number of lines it wanted to move but couldn't. That leads to the following loop: (save-excursion ;; save our starting position (goto-char (point-min)) ;; go to the beginning of the buffer (while (< (forward-line) ...


5

You want (cadr search-pair), not (cdr search-pair). Either that or use an alist whose entries are dotted pairs, with the cdrs being your replacement strings. The error message tells you that a string was expected and instead the list ("replacement-str") was passed.


5

You can use org-map-entries to apply a function to all the entries in a org-mode buffer matching a search. In this case the search "LEVEL=1" will match all top level headlines. The function you specify will be called without arguments with the point on the headline. So (org-map-entries 'org-id-get-create "LEVEL=1") will apply the org-id-get-create ...


4

This is actually not really different from your "home-made" version, but uses a loop clause to handle the incrementing: (let ((my-list '(a b c))) (cl-loop for index from 0 for item in my-list do (insert (format "index=%s, item=%s\n" index item))))


4

Without looking up any of the Org variables or functions you refer to, here's a guess at what you're trying to do. They both do the same thing: iterate over a list of file names, expanding them in directory org-gtd-folder, and setting the value of variable org-agenda-files to the resulting list of absolute file names. ;; Use `mapcar' (setq org-agenda-files ...


3

If you wanted this for a function you would use apply, but as or is a special form you can't do that. In particular, or only evaluates as many arguments as it needs to. You could write a macro: (defmacro or-list (list) `(or ,@(eval list))) (setq mylist '(a b c)) (or-list mylist) then expands to (or a b c)


3

Your problem is that the timer runs the function when the loop has finished. The lexically bound variables index and value have for all calls the values after the last iteration. One solution is to evaluate the variables at iteration time and pass just the values as arguments to the function. (let ((my-list '(a b c))) (cl-loop for index below (length my-...


3

There is no such facility for loops. Considering next in Ruby is the idiom to avoid a nested if, you can easily work around this by using this advice the other way around. (dotimes (i 6) (unless (< i 2) (message "Value of local variable is %d" i))) An even uglier workaround is using the throw/catch facility (which is designed for control flow, not ...


3

As pointed out in the comments, the infinite loop is due to an identification of the call to (loop ...) as referring to the loop/cl-loop macro from Emacs' Common Lisp emulation library and its subsequent macroexpansion to an Elisp (while t ...) loop. I believe you can make your code simpler, more idiomatic and a good deal faster whilst avoiding the other ...


2

How about this? (defun or-list (list) (cl-some #'identity list)) Here cl-some takes two arguments: a predicate and a list and returns non-nil if the predicate applied to some member of the list is non-nil. In our case, the identity function is a good predicate since we only want to test whether our list members are themselves non-nil.


2

Emacs 25 will include the seq.el library, which will provide default functions to manipulate sequences. Right now you can download it from GNU ELPA for Emacs 24. The functions you are looking for are: (seq-filter (lambda (x) (/= 0 (% x 2))) '(1 2 3 4 5)) ; => (1 3 5) (seq-remove (lambda (x) (/= 0 (% x 2))) '(1 2 3 4 5)) ; => (2 4)


2

Okay remove-if-not makes a copy of the list it operates on. So this is the equivalent to collect-if above. From my perspective remove-if-not is a really tricky name for something like collect-if or sub-list (not with the meaning of cl-sublis but with the meaning of sub-list). There should be an alias saying more directly what that function does.


2

Or... you can just loop for yourself: (let ((long '("1" "2" "3" "4")) (short '("a" "b" "c")) ret) (while (or long short) (setq ret (cons (concat (car-safe long) (car-safe short)) ret) long (cdr long) short (cdr short))) (nreverse ret))


2

Append the needed number of empty strings to short: (let* ((long '("1" "2" "3" "4")) (short '("a" "b" "c")) (_short (append short (make-list (- (list-length long) (list-length short)) "")))) (mapcar* 'concat long _short))


2

Another option is to use backquoting to substitute the values for each loop iteration directly into the lambda form: ;;; foo.el --- -*- lexical-binding: t; -*- (let ((my-list '(a b c))) (cl-loop for index below (length my-list) for value = (seq-elt my-list index) do (run-at-time 0 nil ...


1

If you try to match the form (while COND BODY) to what you have above, you will see that COND matches (let* ((pair (pop replacement-list)) (to-find (car pair)) (to-replace (cdr pair))) (message "%s %s" to-find to-replace) (query-replace to-find to-replace nil (point-min) (point-max)) ) and BODY is just replacement-list. ...


1

You are using while, not dolist, while stops when the TEST condition returns nil, not sure about the value of query-replace, but it definitely does not do what you want.


1

You really ask two questions: How to iterate forever? (while t ...) See the Elisp manual, node Iteration. The first argument of while is a sexp. It is evaluated to see if the body needs to be evaluated again. The sexp t always evaluates to itself, a non-nil value, so the body is always reevaluated. How to get the outermost list? (defun outer-paren ()...


1

One way is to create a macro: (defmacro lexical-save (vars &rest body) `(lexical-let ,(mapcar (lambda (var) (list var var)) vars) ,@body)) You can use it is follows: (let ((my-list '(a b c))) (cl-loop for index below (length my-list) for value = (seq-elt my-list index) do (run-at-time 0 nil ...


1

There is no error, the (error "unknown iterator operation %S" op) is part of the closure. Simply type (iter-next rectangles) repeatedly, you will see the expected result. cl-loop also provides a syntax sugar for generators: (cl-loop repeat 5 for r iter-by (iter-rectangle-sizes) collect r) ;; => ((1 1) (1 2) (2 2) (2 3) (3 3))


1

Emacs 26 or newer version of seq.el provides seq-map-indexed (seq-map-indexed (lambda (element index) (concat element (seq-elt '("a" "b" "c") index))) '("1" "2" "3" "4")) ;; => ("1a" "2b" "3c" "4") This works because concat can work with nil (concat "4" nil) ;; => "4" You can also iter the lists by yourself (let (result) (let ((index 0)) ...


1

Your let is malformed, for one thing. It should be (let ((lst (split-string ss)))...). What you wrote instead binds variable lst to nil and variable split-string to ss. Your second problem is that subsequent invocations of occur still search the original buffer, not the output Occur buffer. So all you see is the result of the last search of the original ...


Only top voted, non community-wiki answers of a minimum length are eligible