Compare commits
1 commit
master
...
wip/skip-s
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
772116a843 |
1 changed files with 27 additions and 15 deletions
42
org-ql.el
42
org-ql.el
|
|
@ -18,7 +18,7 @@
|
||||||
;;;; Macros
|
;;;; Macros
|
||||||
|
|
||||||
(cl-defmacro org-ql (buffers-or-files pred-body &key (action-fn '#'identity)
|
(cl-defmacro org-ql (buffers-or-files pred-body &key (action-fn '#'identity)
|
||||||
sort narrow markers)
|
sort narrow markers match-next-fn)
|
||||||
"Find entries in BUFFERS-OR-FILES that match PRED-BODY, and return the results of running ACTION-FN on each matching entry.
|
"Find entries in BUFFERS-OR-FILES that match PRED-BODY, and return the results of running ACTION-FN on each matching entry.
|
||||||
|
|
||||||
ACTION-FN should take a single argument, which will be the result
|
ACTION-FN should take a single argument, which will be the result
|
||||||
|
|
@ -65,7 +65,8 @@ buffer."
|
||||||
(list 'quote sort))
|
(list 'quote sort))
|
||||||
(_
|
(_
|
||||||
;; Other expression to evaluate
|
;; Other expression to evaluate
|
||||||
sort))))
|
sort))
|
||||||
|
:match-next-fn ,match-next-fn))
|
||||||
|
|
||||||
(defmacro org-ql--fmap (fns &rest body)
|
(defmacro org-ql--fmap (fns &rest body)
|
||||||
(declare (indent defun) (debug (listp body)))
|
(declare (indent defun) (debug (listp body)))
|
||||||
|
|
@ -76,7 +77,7 @@ buffer."
|
||||||
|
|
||||||
;;;; Functions
|
;;;; Functions
|
||||||
|
|
||||||
(cl-defun org-ql--query (buffers-or-files pred &key (action-fn #'identity) narrow sort)
|
(cl-defun org-ql--query (buffers-or-files pred &key (action-fn #'identity) narrow sort match-next-fn)
|
||||||
"FIXME: Add docstring."
|
"FIXME: Add docstring."
|
||||||
;; MAYBE: Set :narrow t for buffers and nil for files.
|
;; MAYBE: Set :narrow t for buffers and nil for files.
|
||||||
(declare (indent defun))
|
(declare (indent defun))
|
||||||
|
|
@ -95,7 +96,8 @@ buffer."
|
||||||
(find-file-noselect it)
|
(find-file-noselect it)
|
||||||
(user-error "Can't open file: %s" it))))
|
(user-error "Can't open file: %s" it))))
|
||||||
(mapcar action-fn
|
(mapcar action-fn
|
||||||
(org-ql--filter-buffer :pred pred :narrow narrow)))
|
(org-ql--filter-buffer :pred pred :narrow narrow
|
||||||
|
:match-next-fn match-next-fn)))
|
||||||
buffers-or-files))))
|
buffers-or-files))))
|
||||||
(cl-typecase sort
|
(cl-typecase sort
|
||||||
(list (org-ql--sort-by items sort))
|
(list (org-ql--sort-by items sort))
|
||||||
|
|
@ -120,7 +122,7 @@ Or, when possible, fix the problem."
|
||||||
(org-ql--sanity-check-form (cdr elem)))
|
(org-ql--sanity-check-form (cdr elem)))
|
||||||
else do (check elem))))
|
else do (check elem))))
|
||||||
|
|
||||||
(cl-defun org-ql--filter-buffer (&key pred narrow)
|
(cl-defun org-ql--filter-buffer (&key pred narrow match-next-fn)
|
||||||
"Return positions of matching headings in current buffer.
|
"Return positions of matching headings in current buffer.
|
||||||
Headings should return non-nil for any ANY-PREDS and nil for all
|
Headings should return non-nil for any ANY-PREDS and nil for all
|
||||||
NONE-PREDS. If NARROW is non-nil, buffer will not be widened
|
NONE-PREDS. If NARROW is non-nil, buffer will not be widened
|
||||||
|
|
@ -140,16 +142,26 @@ first."
|
||||||
(regexp #'org-ql--regexp-p)
|
(regexp #'org-ql--regexp-p)
|
||||||
(level #'org-ql--level-p)
|
(level #'org-ql--level-p)
|
||||||
(org-back-to-heading #'outline-back-to-heading))
|
(org-back-to-heading #'outline-back-to-heading))
|
||||||
(save-excursion
|
(let ((match-next-fn (or match-next-fn #'outline-next-heading)))
|
||||||
(save-restriction
|
(save-excursion
|
||||||
(unless narrow
|
(save-restriction
|
||||||
(widen))
|
(unless narrow
|
||||||
(goto-char (point-min))
|
(widen))
|
||||||
(when (org-before-first-heading-p)
|
(goto-char (point-min))
|
||||||
(outline-next-heading))
|
(when (org-before-first-heading-p)
|
||||||
(cl-loop when (funcall pred)
|
(outline-next-heading))
|
||||||
collect (org-element-headline-parser (line-end-position))
|
(cl-loop if (funcall pred)
|
||||||
while (outline-next-heading))))))
|
collect (org-element-headline-parser (line-end-position))
|
||||||
|
and do (funcall match-next-fn)
|
||||||
|
else do (outline-next-heading)
|
||||||
|
until (eobp)))))))
|
||||||
|
|
||||||
|
(defun org-ql--outline-next-heading-same-level ()
|
||||||
|
"FIXME"
|
||||||
|
(cl-loop with level = (org-outline-level)
|
||||||
|
while (outline-next-heading)
|
||||||
|
when (= level (org-outline-level))
|
||||||
|
return t))
|
||||||
|
|
||||||
;;;;; Predicates
|
;;;;; Predicates
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue