[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] scratch/org-edna f05cf5e 23/72: Created finders for compatibility
From: |
Ian Dunn |
Subject: |
[elpa] scratch/org-edna f05cf5e 23/72: Created finders for compatibility with org-depend |
Date: |
Sun, 21 May 2017 21:11:22 -0400 (EDT) |
branch: scratch/org-edna
commit f05cf5e080d23015cc5c6ffb891cec0da5ca6e27
Author: Ian D <address@hidden>
Commit: Ian D <address@hidden>
Created finders for compatibility with org-depend
* org-edna.el (org-edna-finder/siblings-wrap):
(org-edna-finder/rest-of-siblings): New functions
(org-edna-finder/chain-find): Finder for org-depend's chain-find-next
---
org-edna.el | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 80 insertions(+)
diff --git a/org-edna.el b/org-edna.el
index 720db92..0c00145 100644
--- a/org-edna.el
+++ b/org-edna.el
@@ -237,6 +237,32 @@ IDS are all UUIDs as understood by `org-id-find'."
(push (point-marker) markers)))
(nreverse markers))))
+(defun org-edna-finder/siblings-wrap ()
+ (org-with-wide-buffer
+ (let ((self (and (ignore-errors (org-back-to-heading t)) (point)))
+ (markers))
+ ;; Go from this heading to the end
+ (while (org-get-next-sibling)
+ (unless (equal (point) self)
+ (push (point-marker) markers)))
+ ;; Go to the first heading
+ (org-up-heading-safe)
+ (org-goto-first-child)
+ (while (not (equal (point) self))
+ (push (point-marker) markers)
+ (org-get-next-sibling))
+ (nreverse markers))))
+
+(defun org-edna-finder/rest-of-siblings ()
+ (org-with-wide-buffer
+ (let ((self (and (ignore-errors (org-back-to-heading t)) (point)))
+ (markers))
+ ;; Go from this heading to the end
+ (while (org-get-next-sibling)
+ (unless (equal (point) self)
+ (push (point-marker) markers)))
+ (nreverse markers))))
+
(defun org-edna-finder/next-sibling ()
(org-with-wide-buffer
(and (org-get-next-sibling)
@@ -295,6 +321,60 @@ IDS are all UUIDs as understood by `org-id-find'."
(with-current-buffer (find-file-noselect (expand-file-name file
org-directory))
(list (point-min-marker))))
+(defun org-edna-finder/chain-find (&rest options)
+ ;; sortfun - function to use to sort elements
+ ;; filterufn - Function to use to filter elements
+ ;; Both should handle positioning point
+ (let (targets sortfun filterfun)
+ (dolist (opt options)
+ (pcase (intern opt)
+ ('from-top
+ (setq targets (org-edna-finder/siblings)))
+ ('from-bottom
+ (setq targets (seq-reverse (org-edna-finder/siblings))))
+ ('from-current
+ (setq targets (org-edna-finder/siblings-wrap)))
+ ('no-wrap
+ (setq targets (org-edna-finder/rest-of-siblings)))
+ ('todo-only
+ (setq filterfun
+ (lambda (target)
+ (org-entry-get target "TODO"))))
+ ('todo-and-done-only
+ (setq filterfun
+ (lambda (target)
+ (member (org-entry-get target "TODO") org-done-keywords))))
+ ('priority-up
+ (setq sortfun
+ (lambda (lhs rhs)
+ (let ((priority-lhs (org-entry-get lhs "PRIORITY"))
+ (priority-rhs (org-entry-get rhs "PRIORITY")))
+ (not (string-lessp priority-lhs priority-rhs))))))
+ ('priority-down
+ (setq sortfun
+ (lambda (lhs rhs)
+ (let ((priority-lhs (org-entry-get lhs "PRIORITY"))
+ (priority-rhs (org-entry-get rhs "PRIORITY")))
+ (string-lessp priority-lhs priority-rhs)))))
+ ('effort-up
+ (setq sortfun
+ (lambda (lhs rhs)
+ (let ((effort-lhs (org-duration-to-minutes (org-entry-get lhs
"EFFORT")))
+ (effort-rhs (org-duration-to-minutes (org-entry-get rhs
"EFFORT"))))
+ (not (< effort-lhs effort-rhs))))))
+ ('effort-down
+ (setq sortfun
+ (lambda (lhs rhs)
+ (let ((effort-lhs (org-duration-to-minutes (org-entry-get lhs
"EFFORT")))
+ (effort-rhs (org-duration-to-minutes (org-entry-get rhs
"EFFORT"))))
+ (< effort-lhs effort-rhs)))))))
+ (when (and targets sortfun)
+ (setq targets (seq-sort sortfun targets)))
+ (when (and targets filterfun)
+ (setq targets (seq-filter filterfun targets)))
+ (when targets
+ (seq-elt 0 targets))))
+
;; Set TODO state
- [elpa] scratch/org-edna 0977b83 20/72: Don't assume arguments will be symbols or strings, (continued)
- [elpa] scratch/org-edna 0977b83 20/72: Don't assume arguments will be symbols or strings, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 8a8cfd6 12/72: Cleaned up condition handling, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna b40f7f0 05/72: Added initial documentation, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 4a54e3b 09/72: Fixed headings condition, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna dcbb344 18/72: Fixed up indenting, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna ef34291 26/72: Fixed chain-find, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 6cd8a40 28/72: Added test for parsing multiple forms, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 3e1ed0c 29/72: Added re-search condition, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna c49aeba 36/72: Fixed consideration handling, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 1dfc66f 01/72: Initial Commit., Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna f05cf5e 23/72: Created finders for compatibility with org-depend,
Ian Dunn <=
- [elpa] scratch/org-edna e8fc9d5 33/72: Added test for todo action, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 70f949c 35/72: Added note about quoting file names to documentation., Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 24a2837 38/72: Added tests for considerations, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 4b91a43 25/72: Added file for tests, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna bb284dc 27/72: Fixed parsing bug, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna d248565 21/72: Fix uses of substring, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 7978874 24/72: Added tests for ids and match finders, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 6448307 30/72: Added test for empty argument list, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 9e4d833 32/72: Fixed error in re-search, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna d022d2f 40/72: Added copyright and licensing information to all files, Ian Dunn, 2017/05/21