aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorStefan Monnier2015-04-24 16:11:35 -0400
committerStefan Monnier2015-04-24 16:11:35 -0400
commite224c9465dfe7033b11c0aeb830298c101c9bdcc (patch)
tree72847f19bb9220eedc8d729c3c813c4bea36c13b /lisp
parent18a78f8215cc0052bf41d23b8d594cde50d776dd (diff)
downloademacs-e224c9465dfe7033b11c0aeb830298c101c9bdcc.tar.gz
emacs-e224c9465dfe7033b11c0aeb830298c101c9bdcc.zip
* lisp/emacs-lisp/seq.el (seq-doseq): Tighten the code
(seq-doseq): Fix out-of-scope binding. Don't call `seq-length at every iteration. Reduce `if's from 3 to 2 per iteration. (emacs-lisp-mode-hook): Don't tweak in Emacs≥25.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/emacs-lisp/seq.el34
1 files changed, 17 insertions, 17 deletions
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
index 320ee201487..b8647ec93ec 100644
--- a/lisp/emacs-lisp/seq.el
+++ b/lisp/emacs-lisp/seq.el
@@ -44,31 +44,28 @@
44 44
45(defmacro seq-doseq (spec &rest body) 45(defmacro seq-doseq (spec &rest body)
46 "Loop over a sequence. 46 "Loop over a sequence.
47Similar to `dolist' but can be applied lists, strings and vectors. 47Similar to `dolist' but can be applied to lists, strings, and vectors.
48 48
49Evaluate BODY with VAR bound to each element of SEQ, in turn. 49Evaluate BODY with VAR bound to each element of SEQ, in turn.
50Then evaluate RESULT to get return value, default nil.
51 50
52\(fn (VAR SEQ [RESULT]) BODY...)" 51\(fn (VAR SEQ) BODY...)"
53 (declare (indent 1) (debug ((symbolp form &optional form) body))) 52 (declare (indent 1) (debug ((symbolp form &optional form) body)))
54 (let ((is-list (make-symbol "is-list")) 53 (let ((is-list (make-symbol "is-list"))
55 (seq (make-symbol "seq")) 54 (seq (make-symbol "seq"))
56 (index (make-symbol "index"))) 55 (index (make-symbol "index")))
57 `(let* ((,seq ,(cadr spec)) 56 `(let* ((,seq ,(cadr spec))
58 (,is-list (listp ,seq)) 57 (,length (if (listp ,seq) nil (seq-length ,seq)))
59 (,index (if ,is-list ,seq 0))) 58 (,index (if ,is-list ,seq 0)))
60 (while (if ,is-list 59 (while (if ,length
61 (consp ,index) 60 (< ,index ,length)
62 (< ,index (seq-length ,seq))) 61 (consp ,index))
63 (let ((,(car spec) (if ,is-list 62 (let ((,(car spec) (if ,length
64 (car ,index) 63 (prog1 (seq-elt ,seq ,index)
65 (seq-elt ,seq ,index)))) 64 (setq ,index (+ ,index 1)))
66 ,@body 65 (pop ,index))))
67 (setq ,index (if ,is-list 66 ,@body))
68 (cdr ,index) 67 ;; FIXME: Do we really want to support this?
69 (+ ,index 1))))) 68 ,@(cddr spec))))
70 ,@(if (cddr spec)
71 `((setq ,(car spec) nil) ,@(cddr spec))))))
72 69
73(defun seq-drop (seq n) 70(defun seq-drop (seq n)
74 "Return a subsequence of SEQ without its first N elements. 71 "Return a subsequence of SEQ without its first N elements.
@@ -350,7 +347,10 @@ This is an optimization for lists in `seq-take-while'."
350(defalias 'seq-each #'seq-do) 347(defalias 'seq-each #'seq-do)
351(defalias 'seq-map #'mapcar) 348(defalias 'seq-map #'mapcar)
352 349
353(add-to-list 'emacs-lisp-mode-hook #'seq--activate-font-lock-keywords) 350(unless (fboundp 'elisp--font-lock-flush-elisp-buffers)
351 ;; In Emacs≥25, (via elisp--font-lock-flush-elisp-buffers and a few others)
352 ;; we automatically highlight macros.
353 (add-to-list 'emacs-lisp-mode-hook #'seq--activate-font-lock-keywords))
354 354
355(provide 'seq) 355(provide 'seq)
356;;; seq.el ends here 356;;; seq.el ends here