There are various ways to do it. Kaushal's way can be made a good bit more efficient, with:
(while (not (eobp))
(let ((line (buffer-substring (point)
(progn (forward-line 1) (point)))))
But in Emacs it is much more customary to work on the buffer rather than on strings. So rather than ...
Use cl-map, instead:
(cl-map 'vector #'1+ [1 2 3 4])
A little extra background: cl-map is the Common Lisp map function that generalizes to sequence types:
(cl-map 'vector #'1+ '[1 2 3 4]) ;; ==> [2 3 4 5]
(cl-map 'list #'1+ '(1 2 3 4)) ;; ==> (2 3 4 5)
(cl-map 'string #'upcase "abc") ;; ==> "ABC"
It can also convert between sequence types (eg,...
This would probably depend on a situation. In general, if I need to tie a number of values with a number of names, I'd use a hash-table, but if I have to use a property list, I'd use cl-loop. Below are some examples:
(cl-loop for (key value) on '(:prop1 a :prop2 b :prop3 c) by 'cddr
;;; (a b c)
And if you have a data-structure you ...
If you're happy using dash.el you can use -each and destructuring -let:
(-let [(author . name) it]
(git-clone author name)))
Alternatively, you can use -lambda from dash.el to create an anonymous function with destructuring:
(-lambda ((author . name)) (git-clone author name))
You can create an anonymous lambda function to take each element of your list and apply your function to it.
(defvar packages '(("auto-complete" . "auto-complete")
("defunkt" . "markdown-mode")))
(defun toy-fnx (author name)
(message "Package %s by author %s" name author)
(mapcar (lambda (...
It's really a function, which means add 1. you can try below example:
ELISP> (1+ 3)
4 (#o4, #x4, ?\C-d)
The implementation is at data.c:
DEFUN ("1+", Fadd1, Sadd1, 1, 1, 0,
doc: /* Return NUMBER plus one. NUMBER may be a number or a marker.
Markers are converted to integers. */)
(register Lisp_Object number)
You will likely get various loop and iteration answers. AFAIK, there is no idiomatic way to do this. I don't even think it's very common to want to accumulate only the property values (not associating them with the properties).
Here is one simple way to do it:
(defun prop-values (plist)
(let ((pl (cdr plist))
I don't know of any idiomatic way but I came up with this:
(defun my/walk-line-by-line ()
"Process each line in the buffer one by one."
(while (not (eobp))
(let* ((lb (line-beginning-position))
(ln (buffer-substring-no-properties lb ...
With Emacs from the current Git HEAD which will become Emacs 25, you can do the
following, i.e., turn the plist into an alist easily with the new
seq-partition function, and then process the alist entries using standard
(let* ((my-plist (list :a 1 :b 2 :c 3 :more (list 4 5 6)))
(my-alist (seq-partition my-plist 2))
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 ...
I think the following is as idiomatic as it can get:
(dolist (line (split-string (buffer-string) "\n"))
... process line here ...
EDIT: Here is another solution with loop in place of dolist, and which also classifies the lines according to whether or not they match your regular expression:
(loop for line in (split-string (buffer-string) &...
Taken literally, your sample line would translate to the following:
(define-key evil-normal-state-map (kbd "<tab>") (kbd ">>"))
Although I don't personally recommend this. It's much cleaner to reference the function you want to run by name instead of using a keyboard macro. This clears up the need for a distinction between nmap and nnoremap, ...
I think you've overcomplicated the problem.
You're obtaining a list comprising hours, minutes, seconds, and microseconds, so I think your code would be simpler and more readable if you expressed that explicitly:
(defvar time-stamp "00:00:52,010")
(cl-destructuring-bind (hours minutes seconds microseconds)
(mapcar #'string-to-number (...
It's mainly just a warning - really a suggestion.
It's pointing out that if you don't care to produce a new list from the original one, where the returned list's elements are the results of applying the function argument to the original list's elements, then you might as well just use dolist or mapc instead of mapcar.
In this case, your mapcar is, yes, ...
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'
Library Dired+ offers a bunch of commands that let you act on the marked files and the files marked in marked subdirectories, defined recursively. These commands have names like diredp-*-recursive.
It is also the case that you can insert any subdirs (and subsubdirs etc.) into the same Dired buffer, and then act on marked files there.
One of the Dired+ ...
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)
The not so elegant inplace-variant for the case that the original vector is no longer needed afterwards and memory allocation is time-critical (e.g. the vector is big).
(setq x [1 2 3 4])
(cl-loop for var across-ref x do
(setf var (1+ var)))
The result is stored in x. If you need the form to return x in the end you can add finally return x as ...
If you haven't already try undo-tree.el. It gives Emacs a conventional undo, otherwise you need to undo the undos in order to redo--there is no redo function... With it you can add:
(global-set-key (kbd "C-s-/") 'undo-tree-redo)
to your emacs init file, or where ever you keep custom keybindings, and walk back and forward through any change.
Following up Basils comment on the problems with recursive solutions I give here an iterative solution.
It exploits a breadth first search and therefore needs a queue. My first attempt with a depths-first search caused me some trouble with creating the structure and setting the values of the return tree.
The queue impl comes with the answer but you can ...
Or... you can just loop for yourself:
(let ((long '("1" "2" "3" "4"))
(short '("a" "b" "c"))
(while (or long short)
(setq ret (cons (concat
long (cdr long)
short (cdr short)))
One way to improve speed is to parse the contents of your agenda files once in a temporary buffer collecting the effort of all the entries matching goal+PRIORITY="B" (see Test 1). With ~10K lines, I get "Elapsed time: 0.052280s" compared to "Elapsed time: 1.340006s" using org-map-entries (Test 2) which I think is what you were trying to do. For better ...