소스 검색

Added a less functional Org-mode copy of the cl reduce function.

* lisp/org.el (org-reduce): Added a less functional Org-mode copy of
  the cl reduce function.
Eric Schulte 14 년 전
부모
커밋
15417f67c4
1개의 변경된 파일12개의 추가작업 그리고 0개의 파일을 삭제
  1. 12 0
      lisp/org.el

+ 12 - 0
lisp/org.el

@@ -19660,6 +19660,18 @@ Taken from `count' in cl-seq.el with all keyword arguments removed."
       (if (funcall predicate e) (push e res)))
       (if (funcall predicate e) (push e res)))
     (nreverse res)))
     (nreverse res)))
 
 
+(defun org-reduce (cl-func cl-seq &rest cl-keys)
+  "Reduce two-argument FUNCTION across SEQ.
+Taken from `reduce' in cl-seq.el with all keyword arguments but
+\":initial-value\" removed."
+  (let ((cl-accum (cond ((memq :initial-value cl-keys)
+                         (cadr (memq :initial-value cl-keys)))
+                        (cl-seq (pop cl-seq))
+                        (t (funcall cl-func)))))
+    (while cl-seq
+      (setq cl-accum (funcall cl-func cl-accum (pop cl-seq))))
+    cl-accum))
+
 (defun org-back-over-empty-lines ()
 (defun org-back-over-empty-lines ()
   "Move backwards over whitespace, to the beginning of the first empty line.
   "Move backwards over whitespace, to the beginning of the first empty line.
 Returns the number of empty lines passed."
 Returns the number of empty lines passed."