GithubHelp home page GithubHelp logo

alphapapa / org-ql Goto Github PK

View Code? Open in Web Editor NEW
1.4K 30.0 110.0 7.32 MB

A searching tool for Org-mode, including custom query languages, commands, saved searches and agenda-like views, etc.

License: GNU General Public License v3.0

Emacs Lisp 83.64% Makefile 0.46% Shell 15.90%
emacs org-mode org-agenda

org-ql's Introduction

org-ql

This package provides a query language for Org files. It offers two syntax styles: Lisp-like sexps and search engine-like keywords.

It includes three libraries: The org-ql library is flexible and may be used as a backend for other tools. The libraries org-ql-search and helm-org-ql (a separate package) provide interactive search commands and saved views.

Contents

Screenshots

images/org-ql-search.gif

images/org-ql-view-dispatch.gif

images/helm-org-ql.gif

images/org-ql-view-sidebar.gif

Installation

The package org-ql may be installed directly from MELPA or with other tools like Quelpa.

After installation, you can use the commands without additional configuration. To use the functions and macros in your own Elisp code, use libraries org-ql and org-ql-view.

Quelpa

Installing with Quelpa is easy:

  1. Install quelpa-use-package (which can be installed directly from MELPA).
  2. Add this form to your init file:
(use-package org-ql
  :quelpa (org-ql :fetcher github :repo "alphapapa/org-ql"
            :files (:defaults (:exclude "helm-org-ql.el"))))

Helm support

The command helm-org-ql is available in the package helm-org-ql. It may be installed from MELPA, or with Quelpa, like so:

(use-package helm-org-ql
  :quelpa (helm-org-ql :fetcher github :repo "alphapapa/org-ql"
                       :files ("helm-org-ql.el")))

Usage

Feedback on these APIs is welcome. Eventually, after being tested and polished, they will be considered stable.

Lisp code examples are in examples.org.

Commands

org-ql-find

Note: These commands use non-sexp queries.

These commands jump to a heading selected using Emacs’s built-in completion facilities with an Org QL query:

  • org-ql-find searches in the current buffer.
  • org-ql-find-path searches outline paths in the current buffer.
  • org-ql-find-in-agenda searches in (org-agenda-files).
  • org-ql-find-in-org-directory searches in org-directory.

Note that these commands are compatible with Embark: the embark-act command can be called on a completion candidate (i.e. a search result) to act on it immediately, without having to visit the entry in its source Org buffer, and embark-export may be called to show the results in an org-ql-view buffer.

images/org-ql-find.png

org-ql-open-link

This command finds links in entries matching the input query and offers them for selection; the selected link is then opened with org-open-at-point.

The input is matched using the default predicate, which means it searches both entry content and outline paths. This is helpful when a collection of links are kept in Org files: rather than having to first visit the entry containing the desired link, then locate it within the entry, and then open it, the user can simply select the link and open it directly. For example, if an entry with the heading Emacs contained a link named mailing list, one could search for Emacs list and open the link to the mailing list directly.

org-ql-refile

This command refiles the current Org entry to one selected by searching with Org QL completion. It searches files listed in org-refile-targets as well as the current buffer.

org-ql-search

Note: This command supports both sexp queries and non-sexp queries.

Read QUERY and search with org-ql. Interactively, prompt for these variables:

BUFFERS-FILES: A list of buffers and/or files to search. Interactively, may also be:

  • buffer: search the current buffer
  • all: search all Org buffers
  • agenda: search buffers returned by the function org-agenda-files
  • A space-separated list of file or buffer names

GROUPS: An org-super-agenda group set. See variable org-super-agenda-groups.

NARROW: When non-nil, don’t widen buffers before searching. Interactively, with prefix, leave narrowed.

SORT: One or a list of org-ql sorting functions, like date or priority.

Bindings: Keys bound in results buffer.

  • r: Refresh results. With prefix, prompt to adjust search parameters.
  • v: Show transient view dispatcher (like Magit’s popups).
  • C-x C-s: Save query to variable org-ql-views (accessible with command org-ql-view).

Note: The view buffer is currently put in org-agenda-mode, which means that some Org Agenda commands work, such as jumping to entries and changing item priorities (without necessarily updating the view). This feature is experimental and not guaranteed to work correctly with all commands. (It works to the extent it does because the appropriate text properties are placed on each item, imitating an Agenda buffer.)

Note: Also, this buffer is compatible with Embark: the embark-act command can be called on an entry to act on it immediately, without having to visit the entry in its source Org buffer.

helm-org-ql

Note: This command uses non-sexp queries. It is available separately in the package =helm-org-ql=.

This command displays matches with Helm.

  • Press C-x C-s in the Helm session to save the results to an org-ql-search buffer.

org-ql-view

Choose and display a view stored in org-ql-views.

Bindings: Keys bound in view buffer.

  • g, r: Refresh results. With prefix, prompt to adjust search parameters.
  • v: Show transient view dispatcher (like Magit’s popups).
  • C-x C-s: Save query to variable org-ql-views (accessible with command org-ql-view).

org-ql-view-sidebar

Show a sidebar window listing views stored in org-ql-views for easy access. In the sidebar, press RET or mouse-1 to show the view at point, and press c to customize the view at point.

org-ql-view-recent-items

Show items in FILES from last DAYS days with timestamps of TYPE. TYPE may be ts, ts-active, ts-inactive, clocked, closed, deadline, planning, or scheduled. FILES defaults to those returned by the function org-agenda-files.

org-ql-sparse-tree

Arguments: (query &key keep-previous (buffer (current-buffer)))

Show a sparse tree for QUERY in BUFFER and return number of results. The tree will show the lines where the query matches, and any other context defined in org-show-context-detail, which see.

QUERY is an org-ql query sexp (quoted, since this is a function). BUFFER defaults to the current buffer. When KEEP-PREVIOUS is non-nil (interactively, with prefix), the outline is not reset to the overview state before finding matches, which allows stacking calls to this command. Runs org-occur-hook after making the sparse tree.

Queries

An org-ql query is a Lisp expression which may contain arbitrary expressions, as well as calling certain built-in predicates. It is byte-compiled into a predicate function which is tested with point on each heading in an Org buffer; when it returns non-nil, the heading matches the query. When possible, certain built-in predicates are optimized away to whole-buffer regular expression searches, which are much faster to search for than testing the predicate on each heading.

Notes:

  • Bare strings like ~”string”~ are automatically converted to (regexp "string") predicates.
  • Standard numeric comparator function symbols (<, <=, >, >=, = ) need not be quoted when passed as an argument to predicates which accept them. The resemblance to infix notation is coincidental.

Non-sexp query syntax

The command org-ql-search also accepts, and the command helm-org-ql only accepts, an alternative, non-sexp query syntax. The syntax is simple, and a few examples of queries in both syntaxes should suffice. By default, when multiple predicates are used, they are combined with boolean and.

Sexp syntaxNon-sexp syntax
(todo)todo:
(todo "SOMEDAY")todo:SOMEDAY
(todo "SOMEDAY" "WAITING")todo:SOMEDAY,WAITING
(ts :on today)ts:on=today
(ts-active :from "2017-01-01" :to "2018-01-01")ts-active:from=2017-01-01,to=2018-01-01
(clocked :on -1)clocked:on=-1
(heading "quoted phrase" "word")heading:"quoted phrase",word
(and (tags "book" "books") (priority "A"))tags:book,books priority:A
(src :lang "elisp" :regexps ("defun"))src:defun,lang=elisp or src:lang=elisp,defun
(and (tags "space") (not (regexp "moon")))tags:space !moon
(priority >= B)priority:A,B

Note that the effort, level, and priority predicates do not support comparators in the non-sexp syntax, so multiple arguments should be passed instead, as seen in the last example.

General predicates

Arguments are listed next to predicate names, where applicable.

blocked
Return non-nil if current heading is blocked. Calls org-entry-blocked-p, which see.
category (&optional categories)
Return non-nil if current heading is in one or more of CATEGORIES (a list of strings).
done
Return non-nil if entry’s TODO keyword is in org-done-keywords.
effort (&optional effort-or-comparator effort)
Return non-nil if current heading’s effort property matches arguments. The following forms are accepted: (effort DURATION): Matches if effort is DURATION. (effort DURATION DURATION): Matches if effort is between DURATIONs, inclusive. (effort COMPARATOR DURATION): Matches if effort compares to DURATION with COMPARATOR. COMPARATOR may be <, <=, >, or >=. DURATION should be an Org effort string, like 5 or 0:05.
habit
Return non-nil if entry is a habit.
heading (&rest strings)
Return non-nil if current entry’s heading matches all STRINGS. Matching is done case-insensitively.
  • Aliases: h.
heading-regexp (&rest regexps)
Return non-nil if current entry’s heading matches all REGEXPS (regexp strings). Matching is done case-insensitively.
  • Aliases: h*.
level (level-or-comparator &optional level)
Return non-nil if current heading’s outline level matches arguments. The following forms are accepted: (level NUMBER): Matches if heading level is NUMBER. (level NUMBER NUMBER): Matches if heading level is equal to or between NUMBERs. (level COMPARATOR NUMBER): Matches if heading level compares to NUMBER with COMPARATOR. COMPARATOR may be <, <=, >, or >=.
link (&optional description-or-target &key description target regexp-p)
Return non-nil if current heading contains a link matching arguments. DESCRIPTION-OR-TARGET is matched against the link’s description and target. Alternatively, one or both of DESCRIPTION and TARGET may be matched separately. Without arguments, return non-nil if any link is found.
outline-path (&rest strings)
Return non-nil if current node’s outline path matches all of STRINGS. Each string may appear as a substring in any part of the node’s outline path. For example, the path Food/Fruits/Grapes would match (olp "Fruit" "Grape").
  • Aliases: olp.
outline-path-segment (&rest strings)
Return non-nil if current node’s outline path matches STRINGS. Matches STRINGS as a contiguous segment of the outline path. Each string is compared as a substring. For example the path Food/Fruits/Grapes would match (olps "Fruit" "Grape") but not (olps "Food" "Grape").
  • Aliases: olps.
path (&rest regexps)
Return non-nil if current heading’s buffer’s filename path matches any of REGEXPS (regexp strings). Without arguments, return non-nil if buffer is file-backed.
priority (&rest args)
Return non-nil if current heading has a certain priority. ARGS may be either a list of one or more priority letters as strings, or a comparator function symbol followed by a priority letter string. For example: (priority "A") (priority "A" "B") (priority '>= "B") Note that items without a priority cookie never match this predicate (while Org itself considers items without a cookie to have the default priority, which, by default, is equal to priority B).
property (property &optional value &key inherit)
Return non-nil if current entry has PROPERTY (a string), and optionally VALUE (a string). If INHERIT is nil, only match entries with PROPERTY set on the entry; if t, also match entries with inheritance. If INHERIT is not specified, use the value of org-use-property-inheritance, which see.
regexp (&rest regexps)
Return non-nil if current entry matches all of REGEXPS (regexp strings). Matches against entire entry, from beginning of its heading to the next heading.
  • Aliases: r.
rifle (&rest strings)
Return non-nil if each string is found in either the entry or its outline path. Works like org-rifle. This is probably the most useful, intuitive, general-purpose predicate.
  • Aliases: smart.
  • Note: By default, this is the default predicate used for plain-string query tokens (i.e. given without a specified predicate). This can be customized with the option org-ql-default-predicate.
src (&key lang regexps)
Return non-nil if current entry contains an Org Babel source block. If LANG is non-nil, match blocks of that language. If REGEXPS is non-nil, require that block’s contents match all regexps. Matching is done case-insensitively.
tags (&optional tags)
Return non-nil if current heading has one or more of TAGS (a list of strings). Tests both inherited and local tags.
tags-inherited (&optional tags)
Return non-nil if current heading’s inherited tags include one or more of TAGS (a list of strings). If TAGS is nil, return non-nil if heading has any inherited tags.
  • Aliases: inherited-tags, tags-i, itags.
tags-local (&optional tags)
Return non-nil if current heading’s local tags include one or more of TAGS (a list of strings). If TAGS is nil, return non-nil if heading has any local tags.
  • Aliases: local-tags, tags-l, ltags.
tags-all (tags)
Return non-nil if current heading includes all of TAGS. Tests both inherited and local tags.
  • Aliases: tags&.
tags-regexp (&rest regexps)
Return non-nil if current heading has tags matching one or more of REGEXPS. Tests both inherited and local tags.
  • Aliases: tags*.
todo (&optional keywords)
Return non-nil if current heading is a TODO item. With KEYWORDS, return non-nil if its keyword is one of KEYWORDS (a list of strings). When called without arguments, only matches non-done tasks (i.e. does not match keywords in org-done-keywords).

Ancestor/descendant predicates

ancestors (&optional query)
Return non-nil if current heading has ancestor headings. If QUERY, return non-nil if an ancestor heading matches it. This selector may be nested.
children (&optional query)
Return non-nil if current heading has direct child headings. If QUERY, return non-nil if a child heading matches it. This selector may be nested, e.g. to match grandchild headings.
descendants (&optional query)
Return non-nil if current heading has descendant headings. If QUERY, return non-nil if a descendant heading matches it. This selector may be nested (if you can grok the nesting!).
parent (&optional query)
Return non-nil if current heading has a direct parent heading. If QUERY, return non-nil if the parent heading matches it. This selector may be nested, e.g. to match grandparent headings.

Date/time predicates

These predicates take optional keyword arguments:

  • :from: Match entries whose timestamp is on or after timestamp :from.
  • :to: Match entries whose timestamp is on or before timestamp :to.
  • :on: Match entries whose timestamp is on date :on.
  • :with-time: If unspecified, match timestamps with or without times (i.e. HH:MM). If nil, match timestamps without times. If t, match timestamps with times.

Timestamp/date arguments should be either a number of days (positive to look forward, or negative to look backward), a string parseable by parse-time-string (the string may omit the time value), the symbol today, or a ts struct.

  • Predicates
    ts
    Return non-nil if current entry has a timestamp in given period. Without arguments, return non-nil if entry has a timestamp.
    ts-active, ts-a
    Like ts, but only matches active timestamps.
    ts-inactive, ts-i
    Like ts, but only matches inactive timestamps.

The following predicates, in addition to the keyword arguments, can also take a single argument, a number, which looks backward or forward a number of days. The number can be negative to invert the direction.

These two predicates interpret a single number argument as if it were passed to the :from keyword argument, which eases the common case of searching for items clocked or closed in the past few days:

  • Backward-looking
    clocked
    Return non-nil if current entry was clocked in given period. Without arguments, return non-nil if entry was ever clocked. Note: Clock entries are expected to be clocked out. Currently clocked entries (i.e. with unclosed timestamp ranges) are ignored.
    closed
    Return non-nil if current entry was closed in given period. Without arguments, return non-nil if entry is closed.

These predicates interpret a single number argument as if it were passed to the :to keyword argument, which eases the common case of searching for items planned in the next few days:

  • Forward-looking
    deadline
    Return non-nil if current entry has deadline in given period. If argument is auto, return non-nil if entry has deadline within org-deadline-warning-days. Without arguments, return non-nil if entry has any deadline.
    planning
    Return non-nil if current entry has planning timestamp (i.e. its deadline, scheduled, or closed timestamp) in given period. Without arguments, return non-nil if entry has any planning timestamp.
    scheduled
    Return non-nil if current entry is scheduled in given period. Without arguments, return non-nil if entry is scheduled.

Functions / Macros

Agenda-like views

Function: org-ql-block

For use as a custom agenda block type in org-agenda-custom-commands. For example, you could define a custom series command like this, which would list all priority A items tagged Emacs with to-do keyword SOMEDAY, followed by the standard agenda view, in a single buffer:

(setq org-agenda-custom-commands
      '(("ces" "Custom: Agenda and Emacs SOMEDAY [#A] items"
         ((org-ql-block '(and (todo "SOMEDAY")
                              (tags "Emacs")
                              (priority "A"))
                        ((org-ql-block-header "SOMEDAY :Emacs: High-priority")))
          (agenda)))))

Which would be equivalent to a tags-todo search like this:

(setq org-agenda-custom-commands
      '(("ces" "Custom: Agenda and Emacs SOMEDAY [#A] items"
         ((tags-todo "PRIORITY=\"A\"+Emacs/!SOMEDAY")
          (agenda)))))

However, the org-ql-block version runs in about 1/5th the time.

The variable org-ql-block-header may be bound to a string to use as the block header, otherwise the header is formed automatically.

Listing / acting-on results

Caching

Org QL uses a per-buffer cache to speed up subsequent searches. It’s keyed on query expressions and match actions, which means that, for the same query and same match action in the same buffer, if the buffer has not been modified since the last time the query was run, the cached match-action result will be returned, and the query will not be evaluated in that buffer again.

Therefore, since neither query expressions nor match actions are guaranteed to be evaluated when the following functions are called, they should be free of side effects. Or, if a side effect is required, the cache should be invalidated (e.g. by incrementing the buffer’s modified tick, or by using a query expression or match action that has yet to be cached). Note: Future improvements will allow the cache to be more easily disabled or cleared.

Function: org-ql-select

Arguments: (buffers-or-files query &key action narrow sort)

Return items matching QUERY in BUFFERS-OR-FILES.

BUFFERS-OR-FILES is a one or a list of files and/or buffers.

QUERY is an org-ql query sexp (quoted, since this is a function).

ACTION is a function which is called on each matching entry with point at the beginning of its heading. It may be:

  • element or nil: Equivalent to org-element-headline-parser.
  • element-with-markers: Equivalent to calling org-element-headline-parser, with markers added using org-ql--add-markers. Suitable for formatting with org-ql-agenda--format-element, allowing insertion into an Org Agenda-like buffer.
  • A sexp, which will be byte-compiled into a lambda function.
  • A function symbol.

If NARROW is non-nil, buffers are not widened (the default is to widen and search the entire buffer).

SORT is either nil, in which case items are not sorted; or one or a list of defined org-ql sorting methods (date, deadline, scheduled, closed, todo, priority, or random); or a user-defined comparator function that accepts two items as arguments and returns nil or non-nil.

Examples:

;; Return list of to-do headings in inbox file with tags and to-do keywords:
(org-ql-select "~/org/inbox.org"
  '(todo)
  :action #'org-get-heading)
;; => ("TODO Practice leaping tall buildings in a single bound  :personal:" ...)

;; Without tags and to-do keywords:
(org-ql-select "~/org/inbox.org"
  '(todo)
  :action '(org-get-heading t t))
;; => ("Practice leaping tall buildings in a single bound" ...)

;; Return WAITING heading elements in agenda files:
(org-ql-select (org-agenda-files)
  '(todo "WAITING")
  :action 'element)
;; => ((headline (:raw-value "Visit the moon" ...) ...) ...)

;; Since `element' is the default for ACTION, it may be omitted:
(org-ql-select (org-agenda-files)
  '(todo "WAITING"))
;; => ((headline (:raw-value "Visit the moon" ...) ...) ...)

Function: org-ql-query

Arguments: (&key (select 'element-with-markers) from where order-by narrow)

Like org-ql-select, but arguments are named more like a SQL query.

  • SELECT corresponds to the org-ql-select argument ACTION.
  • FROM corresponds to the org-ql-select argument BUFFERS-OR-FILES.
  • WHERE corresponds to the org-ql-select argument QUERY.
  • ORDER-BY corresponds to the org-ql-select argument SORT, which see.
  • NARROW corresponds to the org-ql-select argument NARROW.

Examples:

;; Return list of to-do headings in inbox file with tags and to-do keywords:
(org-ql-query
  :select #'org-get-heading
  :from "~/org/inbox.org"
  :where '(todo))
;; => ("TODO Practice leaping tall buildings in a single bound  :personal:" ...)

;; Without tags and to-do keywords:
(org-ql-query
  :select '(org-get-heading t t)
  :from "~/org/inbox.org"
  :where '(todo))
;; => ("Practice leaping tall buildings in a single bound" ...)

;; Return WAITING heading elements in agenda files:
(org-ql-query
  :select 'element
  :from (org-agenda-files)
  :where '(todo "WAITING"))
;; => ((headline (:raw-value "Visit the moon" ...) ...) ...)

;; Since `element' is the default for SELECT, it may be omitted:
(org-ql-query
  :from (org-agenda-files)
  :where '(todo "WAITING"))
;; => ((headline (:raw-value "Visit the moon" ...) ...) ...)

Macro: org-ql (deprecated)

Arguments: (buffers-or-files query &key sort narrow markers action)

Expands into a call to org-ql-select with the same arguments. For convenience, arguments should be unquoted.

Note: This macro is deprecated and will be removed in v0.7.

Custom predicates

Macro: org-ql-defpred

Arguments: (name args docstring &key body preambles normalizers)

Define an org-ql selector predicate named org-ql--predicate-NAME. NAME may be a symbol or a list of symbols: if a list, the first is used as NAME and the rest are aliases. A function is only created for NAME, not for aliases, so a normalizer should be used to replace aliases with NAME in queries (keep reading).

ARGS is a cl-defun-style argument list. DOCSTRING is the function’s docstring.

BODY is the body of the predicate. It will be evaluated with point on the beginning of an Org heading and should return non-nil if the heading’s entry is a match.

PREAMBLES and NORMALIZERS are lists of pcase forms matched against Org QL query sexps. They are spliced into pcase forms in the definitions of the functions org-ql--query-preamble and org-ql--normalize-query, which see. Those functions are redefined when this macro is expanded, unless variable org-ql-defpred-defer is non-nil, in which case those functions should be redefined manually after defining predicates by calling org-ql--define-query-preamble-fn and org-ql--define-normalize-query-fn.

NORMALIZERS are used to normalize query expressions to standard forms. For example, when the predicate has aliases, the aliases should be replaced with predicate names using a normalizer. Also, predicate arguments may be put into a more optimal form so that the predicate has less work to do at query time. NOTE: Normalizers are applied to a query repeatedly until the query is fully normalized, so normalizers should be carefully written to avoid infinite loops.

PREAMBLES refer to regular expressions which may be used to search through a buffer directly to a potential match rather than testing the predicate body on each heading. (Naming things is hard.) In each pcase form in PREAMBLES, the pcase expression (not the pattern) should be a plist with the following keys, each value of which should be an expression which may refer to variables bound in the pattern:

:regexp Regular expression which searches directly to a potential match.

:case-fold Bound to case-fold-search around the regexp search.

:query Expression which should replace the query expression, or query if it should not be changed (e.g. if the regexp is insufficient to determine whether a heading matches, in which case the predicate’s body needs to be tested on the heading). If the regexp guarantees a match, this may be simply t, leaving the query expression with no work to do, which improves performance.

For convenience, within the pcase patterns, the symbol predicate-names is a special form which is replaced with a pattern matching any of the predicate’s name and aliases. For example, if NAME were:

(heading h)

Then if NORMALIZERS were:

((`(,predicate-names . ,args) `(heading ,@args)))

It would be expanded to:

((`(,(or 'heading 'h) . ,args) `(heading ,@args)))

Dynamic block

Org QL provides a dynamic block that lists entries in the current document matching a query. In the header, these parameters are supported:

  • :query: An Org QL query expression in either sexp or non-sexp form.
  • :columns A list of columns, including heading, todo, property, priority, deadline, scheduled, closed.
    • Each column may also be specified as a list with the second element being a header string. For example, to abbreviate the priority column: (priority "P").
    • For certain columns, like property, arguments may be passed by specifying the column type itself as a list. For example, to display a column showing the values of a property named milestone, with the header being abbreviated to M: ((property "milestone") "M").
  • :sort One or a list of Org QL sorting methods (see org-ql-select).
  • :take Optionally take a number of results from the front (a positive number) or the end (a negative number) of the results.
  • :ts-format Optional format string used to format timestamp-based columns.

The heading column is formatted as a link to the heading (not shown in the following example).

For example, this dynamic block shows the first seven headings that are to-do items with priority A or B, sorted by deadline then priority, with certain columns (including the value of the agenda-group property with a custom header) and timestamp format:

#+BEGIN: org-ql :query "todo: priority:A,B" :columns (todo (priority "P") ((property "agenda-group") "Group") deadline heading) :sort (deadline priority) :take 7 :ts-format "%Y-%m-%d %H:%M"
| Todo | P | Group | Deadline         | Heading                               |
|------+---+-------+------------------+---------------------------------------|
| TODO | A |       | 2017-07-07 00:00 | Take over the world                   |
| TODO | B |       | 2017-07-10 00:00 | Renew membership in supervillain club |
| TODO | A | plans | 2017-07-15 00:00 | Take over the universe                |
| TODO | B |       | 2017-07-21 00:00 | Internet                              |
| TODO | A | bills | 2017-08-01 00:00 | Spaceship lease                       |
| TODO | A |       |                  | Skype with president of Antarctica    |
| TODO | B |       |                  | Take over Mars                        |
#+END:

Links

Org QL View searches may be accessed by opening org-ql-search: links in an Org file.

In an Org QL View buffer, the command org-store-link (i.e. C-c l) stores a link to the current search, and it may be inserted into an Org buffer with the command org-insert-link (C-c C-l). The stored link records all of the view settings, like title, sorting, and grouping.

Simple links may also be written manually in either sexp or non-sexp form, like:

[[org-ql-search:todo:NEXT priority:A]]
[[org-ql-search:(and (todo "NEXT") (priority "A"))]]

Tips

  • Org QL View buffers can be bookmarked with Emacs bookmark commands, e.g. C-x r m. This also integrates with org-sidebar and Burly.

Changelog

Note: Breaking changes may be made before version 1.0, but in the event of major changes, attempts at backward compatibility will be made with obsolescence declarations, translation of arguments, etc. Users who need stability guarantees before 1.0 may choose to use tagged stable releases.

0.9-pre

Compatibility

helm-org-ql

Tagged v0.6.2, fixing a compilation warning.

0.8.7

Fixes

  • Timestamps with internal time ranges (e.g. <2024-06-26 10:00-11:00>) are matched for simple queries. (This support is not yet comprehensive, e.g. a query that depends on the specific inner time range may not behave as expected. Previously such timestamps were not matched at all. See #237 and #371. Thanks to Ihor Radchenko.)
  • Timestamps with day-of-the-week abbreviations are matched more flexibly (allowing, e.g. a period in French locales). (See #429, #432. Thanks to Florian D. for reporting.)
  • Command org-ql-search did not narrow properly when called interactively.

Compatibility

  • Dynamic blocks work with Org 9.7. (#431. Thanks to Jez Cope for reporting.)

0.8.6

Fixes

  • Bookmarking org-ql-view buffers when the buffers-files argument is a symbol (like org-agenda-files).

0.8.5

Fixes

  • Predicate heading incorrectly matched strings as regular expressions, sometimes returning incorrect results. (See discussion. Thanks to Alex Popescu for reporting.)
  • Predicates ancestor and parent did not normalize their sub-queries, sometimes returning incorrect results. (#365. Thanks to Gabriele Mongiano for reporting.)

0.8.4

Fixes

  • Command org-ql-find goes to the selected entry in the base buffer (rather than potentially an indirect buffer, whose narrowing could leave the selected entry hidden. The nuances around going to entries in buffers that may be indirect and/or narrowed are surprisingly complicated. Hopefully this is the last fix).

0.8.3

Fixes

0.8.2

Fixes

  • Command org-ql-find incorrectly restored the buffer after jumping when not using indirect buffers. (See #380. Thanks to Bram Schoenmakers for reporting.)

0.8.1

Fixes

  • Command org-ql-find widens the buffer before going to the selected entry.
  • In org-ql-view buffers, links in headings remain clickable links. (Fixes #282. Thanks to Jacob Boxerman for reporting.)

0.8

Additions

  • Function org-ql-completing-read, used by command org-ql-find, now specifies the completion category as org-heading, providing compatibility with Embark. (This is a powerful feature, as it means any org-ql-find result can be acted on from inside the search results with Embark, which provides common actions from Org Agenda and Org speed keys bindings.) (#299. Thanks to Omar Antolín Camarena, Daniel Mendler, and Akira Komamura.)
    • Command org-ql-completing-read-export, bound to C-c C-e or embark-export while in an org-ql-completing-read session, exits and shows an org-ql-view buffer for the current search.
  • Command org-ql-find may be called in an org-agenda or org-ql-view buffer to search the buffers which contributed to the agenda/view buffer.
  • Command org-ql-find-path, which searches outline paths in the current buffer.
  • Command org-ql-open-link, which finds links in entries matching the given query, and opens the selected one with org-open-at-point. (This is helpful when a collection of links are kept in Org files: rather than having to first visit the entry containing the desired link, then locate it within the entry, and then open it, the user can simply select the link and open it directly.)
  • Items in org-ql-view buffers now include the org-category text property, like Org Agenda buffers, which allows grouping with org-super-agenda’s category-related selectors. (#363. Thanks to Gabriele Mongiano for reporting.)

Fixes

  • Predicate property correctly uses the value of org-use-property-inheritance when not specified. (#346, #356. Thanks to Bram Schoenmakers.)

Compatibility

  • Emacs 27.1 or later is now required.
  • Org v9.7’s org-element API changes required some adjustments. (#364. Thanks to several users for reporting, and to Ihor Radchenko for his feedback.)

0.7.4

Fixes

  • Ignore empty quoted strings in plain-string queries (#383).

0.7.3

Fixes

  • Disable case-fold-search when collecting headings in outline paths. (Headings that started with a word that is also a to-do keyword but with different capitalization would be matched incorrectly.)
  • Saving of org-ql-view views. (#378. Thanks to Pentaquark1 for reporting.)
  • Command org-ql-find didn’t move point to the selected entry. (#380. Thanks to Omar Antolín Camarena for reporting.)

0.7.2

Fixes

  • Timestamp predicates are more tolerant of partial input (e.g. preventing errors while the user is typing a query into org-ql-find).
  • Query parser ignores leading whitespace (e.g. preventing errors while the user is typing a query into org-ql-find).
  • Use of org-ql-find with :query-prefix argument prevented selection of results. (#351. Thanks to Daniel Fleischer for reporting.)
  • Handle narrowed buffers correctly in org-ql-find.
  • Warn about empty headings in org-ql-completing-read (the Org format allows a heading line to have no text, but it’s useless for this purpose, and usually indicates unnoticed corruption).

0.7.1

Fixes

  • Function org-ql-completing-read is more compatible with default Emacs completion. (See #338. Thanks to arozbiz for reporting.)
  • Function org-ql-completing-read would sometimes stop updating with changes in input. (See #350. Thanks to Ankit Raj Pandey for reporting and fixing, and to Daniel Mendler for advising.)
  • In org-ql-completing-read, format links for display, and use org-entry-get internally rather than org-get-heading.

0.7

Added

  • Command org-ql-find, which jumps to entries selected using Emacs’s built-in completion facilities and Org QL queries (like helm-org-ql, but doesn’t require Helm.).
  • Command org-ql-refile, which refiles the entry at point to one selected using Org QL completion.
  • Predicate rifle, which matches an entry if each of the given arguments is found in either the entry’s contents or its outline path. This provides very intuitive results, mimicing the behavior of =org-rifle=. In fact, the results are so useful that it’s now the default predicate for plain-string query tokens. (It is also aliased to smart, since it’s so “smart,” and not all users have used org-rifle.)
  • Option org-ql-default-predicate, applied to plain-string query tokens (before, the regexp predicate was always used, but now it may be customized).
  • Alias c for predicate category.
  • Predicate property now accepts the argument :inherit to match entries with property inheritance, and when unspecified, the option org-use-property-inheritance controls whether inheritance is used.
  • Predicate blocked. (Thanks to Akira Komamura.)

Changed

  • Give more useful error message for invalid queries.
  • Predicate src now matches case-insensitively.
  • Command org-ql-sparse-tree accepts both string and sexp queries. (Thanks to Akira Komamura.)

Fixed

  • Predicate link matches links whose descriptions contain escaped brackets (changed in Org 9.3). (Thanks to Daniel Borchmann for reporting.)
  • Predicate src’s matching of begin/end block lines, normalization of arguments, and handling in non-sexp queries. (Thanks to Akira Komamura for reporting.)
  • Predicate src’s behavior with various arguments.
  • Various compilation warnings.

Internal

  • Certain query predicates, when called multiple times in an and sub-expression, are optimized to a single call.
  • Use buffer-chars-modified-tick instead of buffer-modified-tick. (Thanks to Ihor Radchenko.)
  • Implemented tests for src predicate.

Credits

0.6.3

Fixed

  • Non-sexp query parsing with updated version 1.0.1 of the peg package. (Fixes #314, #316. Thanks to Akira Komamura and Joon Ro for reporting.)
  • Require library org-duration (apparently necessary in newer Org versions).

0.6.2

Fixed

  • link predicate when used in an or‘ed query. (#279. Thanks to Marc Fargas for reporting.)

0.6.1

Fixed

Updated

0.6

Added

  • Macro org-ql-defpred, used to define search predicates. (See tutorial.)
  • Predicate effort.
  • Predicate heading-regexp, which matches regular expressions against heading text (alias: h*).
  • Timestamp-related predicates now accept an optional :with-time argument, which allows matching timestamps with or without times (i.e. HH:MM).
  • Sorting methods:
    • reverse
    • closed (Thanks to Ryan Ye.)
  • Dynamic block column closed. (Thanks to Ryan Ye.)
  • Abbreviate filenames in bookmarks. (Thanks to Akira Komamura.)

Changed

  • The order in which sorting functions is applied has been reversed. For example, :sort '(todo priority date) now does what :sort '(date priority todo) did in earlier versions. (This change is made to enable the new reverse sorting method.) Users who have customized org-ql-views will need to update the stored views’ sorting methods to preserve the desired sort order.
  • Helm support (including the command helm-org-ql) has been moved to a separate package, helm-org-ql.
  • Predicate heading now matches plain strings instead of regular expressions.
  • Update dash dependency, and remove dependency on obsolete dash-functional. (Fixes #179, #209. Thanks to Mark Hudnall, Akira Komamura, Nathanael kinfe, Pablo Stafforini, Jason May, and Basil L. Contovounesios.)

Removed

  • Obsolete macro org-ql (obsolete since 0.5, replaced by functions org-ql-select and org-ql-query).

Fixed

  • Timestamp-related predicates called with relative-date arguments did not properly invalidate the query cache. (Fixes #223. Thanks to Ihor Radchenko for reporting.)

Internal

  • Predicates are now defined more cleanly with a macro (org-ql-defpred) that consolidates functionality related to each predicate. This will also allow users to more easily define custom predicates.
  • Version 1.0 of library peg is now required.
  • Improvements to how arguments to timestamp-related predicates are processed.
  • Predicate normalizers are now applied repeatedly until a query is fully normalized. (Normalizers should be written with this in mind to avoid infinite loops.)

0.5.2

Fixed

0.5.1

Fixed

  • Custom sorting functions could corrupt the cache, causing items to disappear after refreshing an org-ql-search buffer. (#186, #187. Thanks to Nathanael kinfe.)

0.5

Added

  • View dispatcher using transient.el (like Magit), bound to v in search/view buffers.
  • Predicate link, which matches descriptions and targets in Org links.
  • Predicate tags-regexp (alias: tags*), which matches regexps against entry tags (e.g, helpful when a tag might end in “s”).
  • Emacs bookmark support: Org QL View buffers can be bookmarked with, e.g. C-x r m and shown with, e.g. C-x r b. (This also enables view restoration with Burly.)
  • Dynamic block support.
  • Org link support (storing and opening links to Org QL View searches).
  • Mascot.

Changed

  • Binding to refresh search/view buffers changed to r.

Internal

  • When formatting entries for Org QL View buffers, use internal function for retrieving heading tags. This improves speed by using our cache, and it removes the need for a compatibility alias for Org versions before 9.3.

Deprecated

  • Macro org-ql is marked obsolete. It will be removed in v0.7. Functions org-ql-select and org-ql-query should be used instead. (The macro serves only to confuse with regard to quoting arguments.)

Acknowledgments

  • tpeacock19 for extensive help testing new features in this version.

0.4.9

Fixed

0.4.8

Fixed

  • Multiple sorters not preserved when refreshing views. (Fixes #136, #137. Thanks to Imran Khan.)

0.4.7

Fixed

  • Give a useful error if org-ql-search-directories-files is called without a directories argument and org-directory doesn’t exist. (Fixes #139. Thanks to Matt Huszagh for reporting.)

0.4.6

Fixed

  • Compatibility with newer versions of the peg library, which removed a macro used by this package. (Fixes #75. Thanks to Karl Voit and @karlicoss for reporting.)

0.4.5

Fixed

  • Non-case-folding predicates like (todo) unnecessarily disabled case-folding for other predicates. (Issue #114. Thanks to @bitclick for reporting.)

0.4.4

Fixed

  • Compatibility with Org Agenda remote editing commands (some of which were broken by 0.4.3). (Fixes #102. Thanks to Alois Janíček for reporting.)

0.4.3

Fixed

  • When org-ql-view-refresh is called, ensure the buffer is an Org QL View buffer.

0.4.2

Fixed

  • Items’ to-do keywords were not shown in views.

0.4.1

Fixed

  • level predicate used with arguments in plain queries. (Thanks to Akira Komamura for reporting.)

0.4

Note: The next release, 0.5, may include changes which will require minor updates to written queries (e.g. a few predicates may be renamed). Users who wish to avoid those changes happening unexpectedly in their configs should avoid upgrading org-ql beyond 0.4 automatically, as they will be pushed to the master branch when ready.

Added

  • Commands
    • helm-org-ql-views, which shows one of org-ql-views selected with Helm.
    • org-ql-search can search files in org-directory; customization options are available in the org-ql-search group.
    • org-ql-view-refresh can be called with a prefix argument to adjust search parameters.
  • Queries
    • Negation of terms in plain queries using !. For example, tags:space !moon to exclude entries which contain moon.
    • Predicates outline-path (alias olp) and outline-path-segment (alias olps).
    • Predicate src, which matches Org Babel source blocks.
    • Predicates parent and ancestors. (Thanks to Josh Moller-Mara.)
    • Alias h for heading predicate.
    • Alias r for regexp predicate. (Thanks to Feng Shu.)
  • Info manual.
  • Function helm-org-ql-source, which returns a Helm source that searches given buffers/files with helm-org-ql. It can be used for custom Helm commands that search certain files.
  • Display a message when views are refreshed. (Thanks to xeijin.)
  • Respect Org Agenda restriction in org-ql-block. (Thanks to Ihor Radchenko for reporting.)
  • Option org-ql-view-sidebar-sort-views.
  • Mouseover help-echo text for org-ql-views default view names.
  • “Dangling tasks” default view in org-ql-views. (Users who have modified org-ql-views from the default will not see the new view unless they copy it into their config.)

Changed

  • Some default org-ql-view views (users who have modified org-ql-views from the default will not see the new views unless they copy them into their config):
    • Rename some views.
    • “Stuck projects” view (now uses descendants instead of children, which is more useful.

Fixed

  • Inherit file tags when org-tag-inheritance is enabled. (Fixes #55. Thanks to Mikhail Skorzhinskiy.)
  • Call helm-make-source directly instead of using helm-build-sync-source macro. (Fixes #60. Thanks to Matt Huszagh for reporting.)
  • Search/view buffers now always end with a newline, which prevents side-scrolling of the window when calling end-of-buffer.
  • Face for done to-do keywords in org-ql-view buffers. (Thanks to Yiming Chen.)
  • Make view buffers read-only. (Fixes #72. Thanks to xeijin.)
  • Sorting with single sorter specified as an atom. (Thanks to Jeff Filipovits.)
  • Autoload for org-ql-block agenda block. (Fixes #53. Thanks to reports from Gus Cantieni, Karl Voit, rieje, and Jake | Junxuan.)

Internal

  • Added generic node data cache to speed up recursive, tree-based queries.

0.3.2

Fixed

  • In org-ql-search, accept symbol as :super-groups argument.
  • In the This week and Next week default org-ql-views views, set timestamps for beginning-of-week to 00:00:00 and end-of-week to 23:59:59.
  • Plain quoted-phrases in non-sexp queries.

0.3.1

Fixed

0.3

Added

  • Alternative, non-sexp query syntax for commands org-ql-search and helm-org-ql. See documentation.
  • Command helm-org-ql.
  • Command org-ql-sparse-tree, like org-sparse-tree for org-ql queries. (Thanks to Akira Komamura.)
  • Command org-ql-view-sidebar.
  • Per-buffer, per-heading tag caching, which increases the speed of tags-related queries by 6-7x.
  • More tags-related predicates and aliases:
    • For inherited tags: tags-inherited, inherited-tags, tags-i, itags.
    • For heading-local tags: tags-local, local-tags, tags-l, ltags.
    • tags-all, tags&: Matches all given tags using boolean AND (rather than boolean OR, which the tags predicate uses).
  • Variable org-ql-block-header, which overrides the default header in org-ql-block agenda blocks.
  • Predicate (path).
  • Option org-ql-views may now be customized in a guided, structured way with the customization UI (e.g. M-x customize-option RET org-ql-views RET, or press c in the org-ql-view-sidebar buffer).
  • Enable more Org Agenda commands in org-ql-view buffers (e.g. setting deadlines and scheduling). (Fixes #35. Thanks to Milan Zamazal and Mikhail Skorzhinskii.)
  • Function org-ql-select’s buffers-files argument can be a function which returns a list of buffers and/or files.

Changed

  • Predicate heading now accepts multiple regexps, which are matched with boolean AND.
  • Predicate regexp now matches its regexp arguments with boolean AND.
  • Package org-super-agenda is now a dependency. This removes the need for awkward code to handle the case where it’s not installed, and makes grouping features always available. Of course, the global minor mode org-super-agenda-mode is not activated by org-ql, so no behavior is changed in Org Agenda or org-ql; it only means that commands like org-ql-search will always provide grouping when called with the appropriate arguments.

Removed

  • Macro org-ql-agenda. Instead, use function org-ql-search. See also command org-ql-view, etc.

Fixed

  • Predicate heading now matches only against heading text, i.e. not including tags at the end of the line, to-do keyword, etc.
  • Predicate todo now matches case-sensitively, avoiding non-todo-keyword matches (e.g. a heading which begins Waiting on will no longer match for a todo keyword WAITING).
  • Interactive completion in org-ql-search.

Internal

  • Refactored code from file org-ql-agenda.el into files org-ql-search.el and org-ql-view.el. Function and variable names have been changed accordingly.

0.2.3

Fixed

  • Priority queries could fail to match headings whose to-do keywords had non-alphabetic characters, like TO-READ.

0.2.2

Fixed

  • (deadline auto) selector matched entries whose deadlines had a warning period that had not yet been entered (org-deadline-warning-days too soon).

0.2.1

Fixed

  • (descendants) selector matched against parent heading instead of only descendants.

0.2

Added

  • Function org-ql-query, like org-ql-select but with arguments named more like a SQL query.
  • Bare strings like ~”string”~ can be used in queries, which are converted to (regexp "string") automatically.
  • Selector (regexp) accepts multiple regexps to test.
  • Macro org-ql and functions org-ql-query and org-ql-select now also accept a comparator function in their :sort argument.
  • Function org-ql-block, which works as an Org Agenda series/composite/block command, usable in custom agenda commands defined in variable org-agenda-custom-commands. (Inspired by Benson Chu’s config.)
  • Function org-ql-agenda--agenda optionally takes a list of entries as an argument.
  • Selectors ts-a and ts-i, aliases for ts-active and ts-inactive.
  • Selector ts now accepts a :type argument.
  • Face org-ql-agenda-due-date.
  • Selectors (children) and (descendants).
  • Function org-ql-search and macro org-ql-agenda accept a :title argument, which is displayed in the header.
  • Command org-ql-search offers global org-super-agenda-groups in completion.
  • Customization group org-ql.
  • Command org-ql-view, which displays views saved to variable org-ql-views, which can be saved from org-ql-search buffers with command org-ql-search-save, which is bound to C-x C-s in view buffers.
  • Variable org-ql-view-map, active in view buffers displayed by org-ql-search, org-ql-agenda, and org-ql-view.
  • random sort method.
  • Save position when refreshing search buffers.

Changed

  • Function org-ql-query renamed to org-ql-select. org-ql-query now refers to a new function.
  • Macro org-ql no longer accepts a :markers argument. Instead, use argument :action element-with-markers. See function org-ql-select, which org-ql calls.
  • Selector (todo) no longer matches “done” keywords when used without arguments (i.e. the ones in variable org-done-keywords).
  • Overhauled date/time-based predicates. See documentation for new argument signatures.

Removed

  • Selector (date), replaced by (ts).

Fixed

  • Handle date ranges in date-based selectors. (Thanks to Cody Goodman, Samuel W. Flint, and Vikas Rawal.)
  • Don’t overwrite bindings in org-agenda-mode-map.
  • Don’t search buffers without headings, and show a message if the user attempts it.
  • Don’t search hidden/special buffers.
  • Properly accept arbitrary sort functions in org-ql-select, etc. (Fixes #37. Thanks to Milan Zamazal.)
  • Planning-line-related predicates searched too far into entries.
  • Add autoloads. (Fixes #36. Thanks to Akira Komamura.)

Compatibility

Internal

  • Optimizations for some query selectors, e.g. regexp and todo. These can provide a significant improvement for some queries. See benchmarks in notes.org.
  • Library ts is now used for parsing and comparing timestamps.

0.1

First tagged release.

Development

Bug reports, feature requests, and suggestions are welcome. For patches, see below.

Copyright assignment

While Org QL is currently distributed in MELPA, it’s intended to merge Org QL into Org mode. When that happens, it will become a part of Emacs and Org, and therefore cumulative contributions of more than 15 lines of code will require that the author assign copyright of such contributions to the FSF. Authors who are interested in doing so may contact [email protected] to request the appropriate form.

Notes

Comparison with Org Agenda searches

Of course, queries like these can already be written with Org Agenda searches, but the syntax can be complex. For example, this query would be difficult to write in a standard Org Agenda search, because it matches against a to-do keyword and a plain-text search. As described in the advanced searching tutorial, it would require using org-search-view with a query with specific regular expression syntax, like this:

+lisp +{^\*+\s-+TO-READ\s-}

But with org-ql-search, you would write a query like lisp todo:TO-READ, or in Lisp syntax, (and "lisp" (todo "TO-READ")).

org-sidebar

This package is used by org-sidebar, which presents a customizable agenda-like view in a sidebar window.

License

GPLv3

org-ql's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

org-ql's Issues

Could we map `org-ql-view-refresh` to 'r' in org-ql-view buffers?

Right now pressing the 'r' key in a search buffer shows the message Rebuilding agenda... but doesn't actually refresh. I'm guessing because this isn't a 'true' agenda buffer. If that's the case could we remap org-ql-view-refresh to 'r' instead which does refresh it as desired?

possible for a todo/headline to be displayed again in multiple groups?

I suspect the answer to this is no, since it sort of goes against how the agenda fundamentally works, nevertheless:

If I have two groups, one that captures completed items & one that captures items tagged :TODAY:, and a headline could be part of both (i.e. is completed & tagged :TODAY:`` is there a way to have org-ql` repeat the task in both?

btw: sorry for all the spam, this tool has already been a game-changer for how I use org, so thank you so much!

Symbol's function definition is void: org-ql-block

Hi there, for me it looks like org-ql-block is pointing to a non-existent function. When I run the example usage:

(setq org-agenda-custom-commands
      '(("t" "Custom: Agenda and Emacs SOMEDAY [#A] items"
         ((org-ql-block '(and (todo "SOMEDAY")
                              (tags "Emacs")
                              (priority "A"))
                        ((org-ql-block-header "SOMEDAY :Emacs: High-priority")))
          (agenda)))))

When I try to run this I get Symbol's function definition is void: org-ql-block. Additionally, when I call describe-function on org-ql-block I get:

org-ql-block is an alias for ‘org-ql-search-block’, which is not
defined.  Please make a bug report.


Not documented.

How to force clear the org-ql's cache?

Repeated application of the following

(defun query-ql (files res-list min max)
  (interactive)
    (org-ql-agenda files
      (and
       (todo "TODO")
       (when (property "R")
         (if res-list
             (member-if-not 'null (mapcar (lambda (arg) (string-match-p arg (property "R"))) res-list))
             t)
         )
       (when (property "E")
         (string-match-p (concat "[" (number-to-string min) "-" (number-to-string max) "]") (property "E"))))))

causes weird, indeterministic behavior. Sometimes it just works as expected. Sometimes I get errors like this:

Debugger entered--Lisp error: (error "Before first heading")
  signal(error ("Before first heading"))
  error("Before first heading")
  org-back-to-heading(t)
  (save-excursion (org-back-to-heading t) (and (let ((case-fold-search nil)) (looking-at org-todo-line-regexp)) (match-end 2) (match-string 2)))
  org-get-todo-state()
  todo("TODO")
  #f(compiled-function () #<bytecode 0x4ce37f5>)()
  org-ql--select(:predicate #f(compiled-function () #<bytecode 0x4ce37f5>) :action #f(compiled-function () #<bytecode 0x1838839>) :narrow nil)
  apply(org-ql--select (:predicate #f(compiled-function () #<bytecode 0x4ce37f5>) :action #f(compiled-function () #<bytecode 0x1838839>) :narrow nil))
  org-ql--select-cached(:predicate #f(compiled-function () #<bytecode 0x4ce37f5>) :action #f(compiled-function () #<bytecode 0x1838839>) :narrow nil)
  #f(compiled-function (it) #<bytecode 0x35b7edd>)(#<buffer SimulaOKR.org_archive>)
  mapcar(#f(compiled-function (it) #<bytecode 0x35b7edd>) (#<buffer SimulaOKR.org> #<buffer SimulaOKR.org_archive> #<buffer SimulaDebug.org> #<buffer SimulaDebug.org_archive> #<buffer SimulaGdwlrootsPlan.org> #<buffer OtherOKR.org> #<buffer OtherOKR.org_archive> #<buffer MathNotebook.org> #<buffer MathNotebook.org_archive> #<buffer FinanceOKR.org> #<buffer FinanceOKR.org_archive>))
  org-ql--query(("/home/george/SimulaOKR/SimulaOKR.org" "/home/george/SimulaOKR/SimulaOKR.org_archive" "/home/george/SimulaOKR/SimulaDebug.org" "/home/george/SimulaOKR/SimulaDebug.org_archive" "/home/george/SimulaOKR/SimulaGdwlrootsPlan.org" "/home/george/PrivateOKR/OtherOKR.org" "/home/george/PrivateOKR/OtherOKR.org_archive" "/home/george/PrivateOKR/MathNotebook.org" "/home/george/PrivateOKR/MathNotebook.org_archive" "/home/george/PrivateOKR/FinanceOKR.org" "/home/george/PrivateOKR/FinanceOKR.org_archive") (and (todo "TODO") (when (property "R") (if res-list (member-if-not 'null (mapcar (lambda (arg) (string-match-p arg (property "R"))) res-list)) t)) (when (property "E") (string-match-p (concat "[" (number-to-string min) "-" (number-to-string max) "]") (property "E")))) :action (lambda nil (->> (org-element-headline-parser (line-end-position)) org-ql--add-markers)) :narrow nil :sort nil)
  (org-ql '("/home/george/SimulaOKR/SimulaOKR.org" "/home/george/SimulaOKR/SimulaOKR.org_archive" "/home/george/SimulaOKR/SimulaDebug.org" "/home/george/SimulaOKR/SimulaDebug.org_archive" "/home/george/SimulaOKR/SimulaGdwlrootsPlan.org" "/home/george/PrivateOKR/OtherOKR.org" "/home/george/PrivateOKR/OtherOKR.org_archive" "/home/george/PrivateOKR/MathNotebook.org" "/home/george/PrivateOKR/MathNotebook.org_archive" "/home/george/PrivateOKR/FinanceOKR.org" "/home/george/PrivateOKR/FinanceOKR.org_archive") (and (todo "TODO") (when (property "R") (if res-list (member-if-not 'null (mapcar (lambda (arg) (string-match-p arg (property "R"))) res-list)) t)) (when (property "E") (string-match-p (concat "[" (number-to-string min) "-" (number-to-string max) "]") (property "E")))) :sort nil :markers t :narrow nil)
  eval((org-ql '("/home/george/SimulaOKR/SimulaOKR.org" "/home/george/SimulaOKR/SimulaOKR.org_archive" "/home/george/SimulaOKR/SimulaDebug.org" "/home/george/SimulaOKR/SimulaDebug.org_archive" "/home/george/SimulaOKR/SimulaGdwlrootsPlan.org" "/home/george/PrivateOKR/OtherOKR.org" "/home/george/PrivateOKR/OtherOKR.org_archive" "/home/george/PrivateOKR/MathNotebook.org" "/home/george/PrivateOKR/MathNotebook.org_archive" "/home/george/PrivateOKR/FinanceOKR.org" "/home/george/PrivateOKR/FinanceOKR.org_archive") (and (todo "TODO") (when (property "R") (if res-list (member-if-not 'null (mapcar (lambda (arg) (string-match-p arg (property "R"))) res-list)) t)) (when (property "E") (string-match-p (concat "[" (number-to-string min) "-" (number-to-string max) "]") (property "E")))) :sort nil :markers t :narrow nil))
  org-ql-agenda--agenda(("/home/george/SimulaOKR/SimulaOKR.org" "/home/george/SimulaOKR/SimulaOKR.org_archive" "/home/george/SimulaOKR/SimulaDebug.org" "/home/george/SimulaOKR/SimulaDebug.org_archive" "/home/george/SimulaOKR/SimulaGdwlrootsPlan.org" "/home/george/PrivateOKR/OtherOKR.org" "/home/george/PrivateOKR/OtherOKR.org_archive" "/home/george/PrivateOKR/MathNotebook.org" "/home/george/PrivateOKR/MathNotebook.org_archive" "/home/george/PrivateOKR/FinanceOKR.org" "/home/george/PrivateOKR/FinanceOKR.org_archive") (and (todo "TODO") (when (property "R") (if res-list (member-if-not 'null (mapcar (lambda (arg) (string-match-p arg (property "R"))) res-list)) t)) (when (property "E") (string-match-p (concat "[" (number-to-string min) "-" (number-to-string max) "]") (property "E")))) :sort nil :buffer nil :narrow nil :super-groups nil)
  query-ql(("/home/george/SimulaOKR/SimulaOKR.org" "/home/george/SimulaOKR/SimulaOKR.org_archive" "/home/george/SimulaOKR/SimulaDebug.org" "/home/george/SimulaOKR/SimulaDebug.org_archive" "/home/george/SimulaOKR/SimulaGdwlrootsPlan.org" "/home/george/PrivateOKR/OtherOKR.org" "/home/george/PrivateOKR/OtherOKR.org_archive" "/home/george/PrivateOKR/MathNotebook.org" "/home/george/PrivateOKR/MathNotebook.org_archive" "/home/george/PrivateOKR/FinanceOKR.org" "/home/george/PrivateOKR/FinanceOKR.org_archive") nil 0 4)
  eval((query-ql all nil 0 4) nil)
  elisp--eval-last-sexp(nil)
  #f(compiled-function (eval-last-sexp-arg-internal) "Evaluate sexp before point; print value in the echo area.\nInteractively, with a non `-' prefix argument, print output into\ncurrent buffer.\n\nNormally, this function truncates long output according to the\nvalue of the variables `eval-expression-print-length' and\n`eval-expression-print-level'.  With a prefix argument of zero,\nhowever, there is no such truncation.  Such a prefix argument\nalso causes integers to be printed in several additional formats\n(octal, hexadecimal, and character when the prefix argument is\n-1 or the integer is `eval-expression-print-maximum-character' or\nless).\n\nIf `eval-expression-debug-on-error' is non-nil, which is the default,\nthis command arranges for all errors to enter the debugger." (interactive "P") #<bytecode 0x2726ab>)(nil)
  ad-Advice-eval-last-sexp(#f(compiled-function (eval-last-sexp-arg-internal) "Evaluate sexp before point; print value in the echo area.\nInteractively, with a non `-' prefix argument, print output into\ncurrent buffer.\n\nNormally, this function truncates long output according to the\nvalue of the variables `eval-expression-print-length' and\n`eval-expression-print-level'.  With a prefix argument of zero,\nhowever, there is no such truncation.  Such a prefix argument\nalso causes integers to be printed in several additional formats\n(octal, hexadecimal, and character when the prefix argument is\n-1 or the integer is `eval-expression-print-maximum-character' or\nless).\n\nIf `eval-expression-debug-on-error' is non-nil, which is the default,\nthis command arranges for all errors to enter the debugger." (interactive "P") #<bytecode 0x2726ab>) nil)
  apply(ad-Advice-eval-last-sexp #f(compiled-function (eval-last-sexp-arg-internal) "Evaluate sexp before point; print value in the echo area.\nInteractively, with a non `-' prefix argument, print output into\ncurrent buffer.\n\nNormally, this function truncates long output according to the\nvalue of the variables `eval-expression-print-length' and\n`eval-expression-print-level'.  With a prefix argument of zero,\nhowever, there is no such truncation.  Such a prefix argument\nalso causes integers to be printed in several additional formats\n(octal, hexadecimal, and character when the prefix argument is\n-1 or the integer is `eval-expression-print-maximum-character' or\nless).\n\nIf `eval-expression-debug-on-error' is non-nil, which is the default,\nthis command arranges for all errors to enter the debugger." (interactive "P") #<bytecode 0x2726ab>) nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  call-interactively(eval-last-sexp nil nil)
  command-execute(eval-last-sexp)

and sometimes I get

Warning: function ‘member-if-not’ from cl package called at runtime

EDIT: And sometimes I get blank agenda searches, even when there should be matches.
EDIT2: Just to be clear, the first application of the function works as expected.

Docs to tryout org-ql in place of current agenda

Perhaps it would be most convenient if org-agenda-ql (or a new org-agenda-ql-compat function) supported copy/pasting normal org custom commands. This way you could slowly migrate to using org-ql.

It wasn't immediately clear to me if or how I could do that with the current examples.

orq-ql--value-at - misbehave

Starting with a simple org file:

* first
* second

Calling

(org-ql--value-at 1 #'org-get-heading)

on first heading gives me first as expected.

Then deleting first two lines to move second heading to where first heading was and calling:

(org-ql--value-at 1 #'point)
(org-ql--value-at 1 #'org-get-heading)

Returns first instead of the expected second.

This is most certainly due to not setting value-cache to nil in org-ql--value-at when cache is invalid. And then using (map-put value-cache fn new-value) on the value-cache which still includes other fn than point, org-get-local in this case. So this adds the position value cache with the new modified tick including other fn than the current one.

Or maybe it's just too late ... 🍺

Failure to respect org-tags-exclude-from-inheritance

I tried the documented example of a stuck projects block agenda.

This did not appear to respect my setting of org-tags-exclude-from-inheritance, which I have set to ignore PROJECT tags.

After doing org-agenda , I see

Query:(and (tags "PROJECT") (not (done)) (not (descendants (todo "NEXT"))) (not (descendants (scheduled))))  In:("~/Software/try-org-ql/gtd.or...
  NEXT Second thing 
  TODO Third thing 
  TODO This is a stuck project                                     :PROJECT:

but would expect to see

Query:(and (tags "PROJECT") (not (done)) (not (descendants (todo "NEXT"))) (not (descendants (scheduled))))  In:("~/Software/try-org-ql/gtd.or...
  TODO This is a stuck project                                     :PROJECT:

My minimal init file looked like

;;; Minimal setup

(require 'package)

(add-to-list 'package-archives
             '("melpa" . "https://melpa.org/packages/") t)

(package-initialize)

(setq use-package-always-ensure t)
(defvar use-package-verbose t)
(eval-when-compile
  (require 'use-package))

(use-package org-ql
  :ensure t
  :config (require 'org-ql-agenda))

(setq org-agenda-files (quote ("/path/to/gtd.org")))

(setq org-tags-exclude-from-inheritance '("PROJECT"))

(setq org-agenda-custom-commands
      '(("s" "Stuck Projects"
         ((org-ql-block '(and (tags "PROJECT")
                              (not (done))
                              (not (descendants (todo "NEXT")))
                              (not (descendants (scheduled)))))))))

and the minimal gtd.org file was

* Tasks
** TODO This is a project with subtasks                            :PROJECT:
*** DONE First thing
*** NEXT Second thing
*** TODO Third thing
** TODO This is a stuck project                                    :PROJECT:

What's the performance

A brief look through the codebase reveals that here we are using a lot of high-level commands to do the matching.

Org mode on the other hand constructs regular expressions and does the searching in very clever order to maximize performance (for example not even bothering with tags when doing full-text search since that has much higher hit-probabilty, doing the tag-match afterwards is cheap and fast post-process).

Did you do some benchmarks? My agenda spans hundreds of thousands of lines and so a slowdown even just 100% will be quite noticeable.

Symbol’s value as variable is void: accessor-init

Hi,

I've been trying to install recent versions of org-ql (both 20190912.302 from melpa and 0.2.1 from melpa-stable) on Emacs 26.3, but got these errors:

Leaving directory ‘/Users/xor-xor/.emacs.d/elpa/ts-20190819.102’

Compiling file /Users/xor-xor/.emacs.d/elpa/ts-20190819.102/ts.el at Sun Sep 15 21:03:04 2019
Entering directory ‘/Users/xor-xor/.emacs.d/elpa/ts-20190819.102/’

In ts-defstruct:
ts.el:95:48:Warning: attempt to let-bind constant ‘:aliases’
ts.el:108:50:Warning: reference to free variable ‘accessor-init’
ts.el:126:41:Warning: reference to free variable ‘aliases’
ts.el:146:1:Error: Attempt to set a constant symbol: :aliases

Compiling no file at Sun Sep 15 21:03:05 2019
Leaving directory ‘/Users/xor-xor/.emacs.d/elpa/org-ql-20190912.302’

Compiling file /Users/xor-xor/.emacs.d/elpa/org-ql-20190912.302/helm-org-ql.el at Sun Sep 15 21:03:05 2019
Entering directory ‘/Users/xor-xor/.emacs.d/elpa/org-ql-20190912.302/’
helm-org-ql.el:35:1:Error: Symbol’s value as variable is void: accessor-init

Compiling file /Users/xor-xor/.emacs.d/elpa/org-ql-20190912.302/org-ql-agenda.el at Sun Sep 15 21:03:05 2019
org-ql-agenda.el:37:1:Error: Symbol’s value as variable is void: accessor-init

Compiling file /Users/xor-xor/.emacs.d/elpa/org-ql-20190912.302/org-ql.el at Sun Sep 15 21:03:05 2019
org-ql.el:44:1:Error: Symbol’s value as variable is void: accessor-init

and:

Leaving directory ‘/Users/xor-xor/.emacs.d/elpa/org-ql-0.2.1’

Compiling file /Users/xor-xor/.emacs.d/elpa/org-ql-0.2.1/org-ql-agenda.el at Sun Sep 15 21:07:24 2019
Entering directory ‘/Users/xor-xor/.emacs.d/elpa/org-ql-0.2.1/’
org-ql-agenda.el:37:1:Error: Symbol’s value as variable is void: accessor-init

Compiling file /Users/xor-xor/.emacs.d/elpa/org-ql-0.2.1/org-ql.el at Sun Sep 15 21:07:24 2019
org-ql.el:43:1:Error: Symbol’s value as variable is void: accessor-init

(tried both on Emacs Mac and vanilla Emacs from Homebrew)

Support Ivy and/or completing-read

For example:

  (defun ivy-org-ql-agenda-files ()
    (interactive)
    (let ((files (org-agenda-files)))
      (ivy-read
       "Query: "
       #'(lambda (input)
           (let ((query (org-ql--plain-query input)))
             (when query
               (ignore-errors
                 (org-ql-select files query
                   :action (lambda ()
                             (propertize (org-get-heading t)
                                         'marker (copy-marker (point)))))))))
       :dynamic-collection t
       :action #'ivy-org-ql-agenda-goto)))

  (defun ivy-org-ql-agenda-goto (headline)
    (interactive)
    (let ((marker (get-text-property 0 'marker headline)))
      (when (markerp marker)
        (switch-to-buffer (marker-buffer marker))
        (goto-char marker)
        (org-show-entry))))

org-ql-agenda API proposal

Hi @alphapapa,

Thanks for another great library. I was wondering if you think something like the following API would make sense for org-ql-agenda:

(org-ql-agenda
  :groups (let ((entries (org-ql (org-agenda-files)
                            (and (done))))
                (highlights (org-ql "~/org/highlights.org")))
            '((:name "Done today"
               :entries (closed-today entries))
              (:name "Done this week"
               :entries (closed-this-week-before-today entries))
              (:name "Done this month"
               :entries (closed-this-month-before-this-week entries))
              (:name "Month highlights"
               :entries (month-highlights highlights)))))

Where closed-today, closed-this-week-before-today, closed-this-month-before-this-week and month-highlights are just examples of functions that take org entries returned by org-ql as input, do arbitrary filtering and return org entries.

That way it would be possible to build arbitrarily complex agendas, with groups possibly using distinct sources and queries.

Thanks again for all the work you put into making our lives inside Emacs better!

helm-org-ql option to remove filename from query results

Would it be feasible to add an option to suppress the filename from query results? I imagine the current behavior is best for most use cases. However, I do almost all of my queries in a single file and so, for me, the filename simply takes up horizontal real estate.

In case it's unclear what I'm asking, take the following example.
file:

* a
** b

current query:

Query (boolean AND): a
helm-org-ql
tmp.org:a\

proposed query:

Query (boolean AND): a
helm-org-ql
a\

Sorting by priorities broken in orq-ql-block

When I use org-ql-block, apparently org-agenda-sorting-strategy is used to sort the entries. However, there is something wrong with sorting by priorities, when using `priority-down' in org-agenda-sorting-strategy. Entries with defined properties are sorted in the opposite direction, e.g. C-B-A rather than A-B-C. This is different from sorting in standard agendas, without org-ql-block. Entries without defined priorities are put last, which is correct.

Jump-to-date commands

First of all, my thanks @alphapapa for this work. It's changing my life!

I just did a research test recorded with the command C-x C-s
It works perfectly but I wonder how to delete a saved search?
Thank you!

Passing arguments to :action

It would be nice to be able to pass arguments to the function given as :action in org-ql-select. Right now I'm using a lambda with a closure but I think it would cleaner and more convenient if you could do something like ('myfunc arg1 arg2...).

Changes to heading and regexp predicates

                                ;; Heading text.
                                ;; MAYBE: Adjust regexp to avoid matching in tag list.
                                (`(heading ,regexp)
                                 ;; Only one regexp: match with preamble, then let predicate confirm (because
                                 ;; the match could be in e.g. the tags rather than the heading text).
                                 (setq org-ql-preamble (rx-to-string `(seq bol (1+ "*") (1+ blank) (0+ nonl)
                                                                           ,regexp)
                                                                     'no-group))
                                 element)

(rx-to-string `(seq bol (1+ "*") (1+ blank) (0+ nonl)
                    "[a][b]"))

Package.el Library header

This package looks pretty cool! I'm gonna have a play with it. 😻

Skimming the sources, I note that you're depending on dash.el, but your main file lacks the metadata package.el parses to install dependencies. You might like to have a skim of the Emacs documentation on Library headers, and adapt the headers from another package, e.g. flycheck. Sorting the headers out is a prerequisite for getting your code on MELPA down the track. :)

You might also consider using seq.el to remove the dependency on dash, though I'm sure there's some work there. There's something to be said for sticking with the stuff shipped with Emacs out-of-the-box. :)

#+FILETAGS are ignored by tags-inherited

I've tried several styles to specify filetags, unfortunately none of them are working. Example file:

#+FILETAGS: :Peter:Boss:Secret:
#+FILETAGS: :Boss:
#+FILETAGS: Secret

* Meeting with the French group      :work:
** Summary by Frank                  :boss:notes:
*** TODO Prepare slides for him      :action:

Inheritance from headline works OK:

(org-ql-search "~/testfile.org"
  '(tags "work")) => 3 items

And none of the filetags are matched:

(org-ql-search "~/testfile.org"
  '(tags "Peter")) => 0 items
(org-ql-search "~/testfile.org"
  '(tags "Boss")) => 0 items
(org-ql-search "~/testfile.org"
  '(tags "Secret")) => 0 items

org-ql Package In Melpa Stable Has Requirement On Package In Regular Melpa

The org-ql package in Melpa Stable requires org-super-agenda >= 1.2-1, but the most current version of org-super-agenda available in Melpa stables is 1.1.1.

I don't know if this is the proper place for a bug like this, so I apologize in advance if that's the case. In the end I would like to be able to install org-ql using Melpa Stable.

Error when both sort and action-fn are given

Hello,

Since sorting is done after action-fn is applied [1][2], org-ql raises an error if both of the following conditions are satisfied:

  • action-fn is a function that does not return an Org element
  • sort is given as a list

[1] https://github.com/alphapapa/org-agenda-ng/blob/master/org-ql.el#L75
[2] https://github.com/alphapapa/org-agenda-ng/blob/master/org-ql.el#L79

This means you can't use the built-in sorting method if you work on multiple files, right? As far as I understand, org elements do not contain information on the original buffer, so you can't get the marker to each element retrieved by org-ql.

What to do with empty buffers?

This package fails on me if I have an empty org buffer. In this case I had archived everything in empty.org, then tried to query agenda for (todo "TODO") with grouping parent.

Backtrace:

signal(error ("Before first headline at position 21 in buffer emp..."))
error("Before first headline at position %d in buffer %s" 21 #<buffer empty.org>)
org-back-to-heading(t)
org-get-todo-state()
todo("TODO")
#f(compiled-function () #<bytecode 0x17dc9d1>)()
org-ql--select(:predicate #f(compiled-function () #<bytecode 0x17dc9d1>) :action #f(compiled-function () #<bytecode 0x17dc9e5>) :narrow nil)
apply(org-ql--select (:predicate #f(compiled-function () #<bytecode 0x17dc9d1>) :action #f(compiled-function () #<bytecode 0x17dc9e5>) :narrow nil))
org-ql--select-cached(:predicate #f(compiled-function () #<bytecode 0x17dc9d1>) :action #f(compiled-function () #<bytecode 0x17dc9e5>) :narrow nil)
#f(compiled-function (it) #<bytecode 0x17dca09>)(#<buffer empty.org>)

void-function if-let*

Hello, running org-ql from master and evaluating (org-ql "~/org/notes.org" (todo "TODO")) I get:

Debugger entered--Lisp error: (void-function if-let*)
  (if-let* ((buffer-cache (gethash (current-buffer) org-ql-cache)) (query-cache (car (cdr buffer-cache))) (modified-tick (car buffer-cache)) (buffer-unmodified-p (eq (buffer-modified-tick) modified-tick)) (cached-result (gethash args query-cache))) (if (eq cached-result (quote org-ql-nil)) (let nil nil) (let nil cached-result)) (let ((new-result (apply (function org-ql--select) args))) (cond ((or (not query-cache) (not buffer-unmodified-p)) (puthash (current-buffer) (list (buffer-modified-tick) (let (...) (puthash args ... table) table)) org-ql-cache)) (t (puthash args (or new-result (quote org-ql-nil)) query-cache))) new-result))
  org-ql--select-cached(:predicate #[0 "\300\301!\207" [todo "TODO"] 2] :action #[0 "\300\301 !\207" [org-element-headline-parser line-end-position] 2] :narrow nil)
  (save-current-buffer (set-buffer it) (if (derived-mode-p (quote org-mode)) nil (user-error "Not an Org buffer: %s" (buffer-name))) (org-ql--select-cached :predicate predicate :action action :narrow narrow))
  (closure ((action . #[0 "\300\301 !\207" [org-element-headline-parser line-end-position] 2]) (predicate . #[0 "\300\301!\207" [todo "TODO"] 2]) (sources "~/org/notes.org") (sort) (narrow) (action closure (t) nil (org-element-headline-parser (line-end-position))) (--cl-rest-- :action (closure (t) nil (org-element-headline-parser (line-end-position))) :narrow nil :sort nil) (query todo "TODO") (buffers-or-files . "~/org/notes.org") t) (it) (save-current-buffer (set-buffer it) (if (derived-mode-p (quote org-mode)) nil (user-error "Not an Org buffer: %s" (buffer-name))) (org-ql--select-cached :predicate predicate :action action :narrow narrow)))(#<buffer notes.org>)
  mapcar((closure ((action . #[0 "\300\301 !\207" [org-element-headline-parser line-end-position] 2]) (predicate . #[0 "\300\301!\207" [todo "TODO"] 2]) (sources "~/org/notes.org") (sort) (narrow) (action closure (t) nil (org-element-headline-parser (line-end-position))) (--cl-rest-- :action (closure (t) nil (org-element-headline-parser (line-end-position))) :narrow nil :sort nil) (query todo "TODO") (buffers-or-files . "~/org/notes.org") t) (it) (save-current-buffer (set-buffer it) (if (derived-mode-p (quote org-mode)) nil (user-error "Not an Org buffer: %s" (buffer-name))) (org-ql--select-cached :predicate predicate :action action :narrow narrow))) (#<buffer notes.org>))
  (-flatten-n 1 (mapcar (function (lambda (it) (save-current-buffer (set-buffer it) (if (derived-mode-p (quote org-mode)) nil (user-error "Not an Org buffer: %s" (buffer-name))) (org-ql--select-cached :predicate predicate :action action :narrow narrow)))) (mapcar (function (lambda (it) (cond ((bufferp it) it) ((stringp it) (or ... ... ...)) ((error "cl-etypecase failed: %s, %s" it ...) nil)))) sources)))
  (let* ((sources (cond ((null buffers-or-files) (let nil (list (current-buffer)))) ((listp buffers-or-files) (let nil buffers-or-files)) (t (let nil (list buffers-or-files))))) (predicate (byte-compile (list (quote lambda) nil (list (quote cl-symbol-macrolet) (quote (... ... ... ... ... ...)) query)))) (action (byte-compile action)) (org-ql--today (org-today)) (items (-flatten-n 1 (mapcar (function (lambda (it) (save-current-buffer ... ... ...))) (mapcar (function (lambda ... ...)) sources))))) (cond ((null sort) (let nil items)) ((and sort (setq sort (-list sort)) (let* ((--cl-var-- sort) (elem nil) (--cl-flag-- t)) (while (and (consp --cl-var--) (progn ... ...)) (setq --cl-var-- (cdr --cl-var--))) (if --cl-flag-- (progn t) nil))) (let nil (org-ql--sort-by items sort))) (t (let nil (user-error "SORT must be either nil, or one or a list of the defined sorting methods (see documentation)")))))
  (progn (let ((--cl-keys-- --cl-rest--)) (while --cl-keys-- (cond ((memq (car --cl-keys--) (quote (:action :narrow :sort :allow-other-keys))) (setq --cl-keys-- (cdr (cdr --cl-keys--)))) ((car (cdr (memq ... --cl-rest--))) (setq --cl-keys-- nil)) (t (error "Keyword argument %s not one of (:action :narrow :sort)" (car --cl-keys--)))))) (let* ((sources (cond ((null buffers-or-files) (let nil (list ...))) ((listp buffers-or-files) (let nil buffers-or-files)) (t (let nil (list buffers-or-files))))) (predicate (byte-compile (list (quote lambda) nil (list (quote cl-symbol-macrolet) (quote ...) query)))) (action (byte-compile action)) (org-ql--today (org-today)) (items (-flatten-n 1 (mapcar (function (lambda ... ...)) (mapcar (function ...) sources))))) (cond ((null sort) (let nil items)) ((and sort (setq sort (-list sort)) (let* ((--cl-var-- sort) (elem nil) (--cl-flag-- t)) (while (and ... ...) (setq --cl-var-- ...)) (if --cl-flag-- (progn t) nil))) (let nil (org-ql--sort-by items sort))) (t (let nil (user-error "SORT must be either nil, or one or a list of the defined sorting methods (see documentation)"))))))
  (let* ((action (car (cdr (plist-member --cl-rest-- (quote :action))))) (narrow (car (cdr (plist-member --cl-rest-- (quote :narrow))))) (sort (car (cdr (plist-member --cl-rest-- (quote :sort)))))) (progn (let ((--cl-keys-- --cl-rest--)) (while --cl-keys-- (cond ((memq (car --cl-keys--) (quote ...)) (setq --cl-keys-- (cdr ...))) ((car (cdr ...)) (setq --cl-keys-- nil)) (t (error "Keyword argument %s not one of (:action :narrow :sort)" (car --cl-keys--)))))) (let* ((sources (cond ((null buffers-or-files) (let nil ...)) ((listp buffers-or-files) (let nil buffers-or-files)) (t (let nil ...)))) (predicate (byte-compile (list (quote lambda) nil (list ... ... query)))) (action (byte-compile action)) (org-ql--today (org-today)) (items (-flatten-n 1 (mapcar (function ...) (mapcar ... sources))))) (cond ((null sort) (let nil items)) ((and sort (setq sort (-list sort)) (let* (... ... ...) (while ... ...) (if --cl-flag-- ... nil))) (let nil (org-ql--sort-by items sort))) (t (let nil (user-error "SORT must be either nil, or one or a list of the defined sorting methods (see documentation)")))))))
  org-ql--query("~/org/notes.org" (todo "TODO") :action (closure (t) nil (org-element-headline-parser (line-end-position))) :narrow nil :sort nil)
  eval((org-ql--query "~/org/notes.org" (quote (todo "TODO")) :action (function (lambda nil (org-element-headline-parser (line-end-position)))) :narrow nil :sort (quote nil)) t)
  eval-expression((org-ql "~/org/notes.org" (todo "TODO")) nil)
  funcall-interactively(eval-expression (org-ql "~/org/notes.org" (todo "TODO")) nil)
  call-interactively(eval-expression nil nil)
  command-execute(eval-expression)

Seems to be this function:

(defun org-ql--select-cached (&rest args)
  "Return results for ARGS and current buffer using cache."
  ;; MAYBE: Timeout cached queries.  Probably not necessarily since they will be removed when a
  ;; buffer is closed, or when a query is run after modifying a buffer.
  (if-let* ((buffer-cache (gethash (current-buffer) org-ql-cache))
            (query-cache (cadr buffer-cache))
            (modified-tick (car buffer-cache))
            (buffer-unmodified-p (eq (buffer-modified-tick) modified-tick))
            (cached-result (gethash args query-cache)))
      (pcase cached-result
        ('org-ql-nil nil)
        (_ cached-result))
    (let ((new-result (apply #'org-ql--select args)))
      (cond ((or (not query-cache)
                 (not buffer-unmodified-p))
             (puthash (current-buffer)
                      (list (buffer-modified-tick)
                            (let ((table (make-hash-table :test 'org-ql-hash-test)))
                              (puthash args (or new-result 'org-ql-nil) table)
                              table))
                      org-ql-cache))
            (t (puthash args (or new-result 'org-ql-nil) query-cache)))
      new-result)))

I thought maybe it was the dash.el -if-let* function, but fixing the function name just causes other errors to appear.

org-ql-agenda: Custom formatter support

Is there a way to force org-ql-agenda to show the name of the buffer from which each task is derived? I tried adding :auto-category t to :super-groups but it didn't work (i.e., it probably groups by category but still doesn't show the name of the category).

Skipping subtrees

I sometimes need only an overview of tasks in a file. For example, I might need only top-level headings of a file. org-agenda has org-agenda-todo-list-sublevels option (which is actually the default). Would you add an option to skip subtrees in org-ql (and org-agenda-ng)?

Add more examples with clocked times

Hi! First thanks for this great package (and org-super-agenda).

This is not really an issue but I'm unsure where else to ask. Stackoverflow, reddit?

I track all my time in org and org-ql sounds nice to query some interesting stats
but I just can't figure out how. Most of it are related to clocked times.
E.g.:

  • Show me how many hours I spend per week in a task with a certain tag (e.g. meeting)
  • Show me the datetime of the first clock-in and last clock-out per day (per project/file) so I can see when I started working and when I ended.
  • Show me all projects (which is a task that has sub-tasks, so the clock from the sub-tasks should be included) where I worked more than X hours on.

As this is not an issue I'll close it in a few days even without an answer (or you can close it right away of course), but I think having more examples is always nice to give people an idea what you can do with it.

Thanks.

peek at parent/grandparent?

I'm wondering how to find the next heading in the following:

* [#A] project                                               :project:active:
** goal
the goal of this project is to get comfy with org mode.
** inbox
*** todo look at  a thing
** actions
*** NEXT task 1
:PROPERTIES:
:TRIGGER:  next-sibling chain!("TRIGGER")  todo!("NEXT") self delete-property!("TRIGGER")
:END:

*** TODO task 2
*** TODO task 3

while ignoring NEXT headings on the same level under a project tagged with :inactive:, like: * [#A] project :project:inactive:

edit: side note, thanks for the projects you work on and what you bring to the emacs community.

void-function org-ql--todo-p and other strange errors

On MacOS, fresh emacs session emacs -q and I'm getting alot of strange errors

Debugger entered--Lisp error: (void-function org-ql--todo-p)   org-ql--todo-p("MEETING")   apply(org-ql--todo-p "MEETING")   done()   #f(compiled-function () #<bytecode 0x40f26bb5>)()   org-ql--select(:predicate #f(compiled-function () #<bytecode 0x40f26bb5>) :action #f(compiled-function () #<bytecode 0x40f26b95>) :narrow nil)Debugger entered--Lisp error: (void-function org-ql--todo-p)   org-ql--todo-p("MEETING")   apply(org-ql--todo-p "MEETING")   done()   #f(compiled-function () #<bytecode 0x40f26bb5>)()   org-ql--select(:predicate #f(compiled-function () #<bytecode 0x40f26bb5>) :action #f(compiled-function () #<bytecode 0x40f26b95>) :narrow nil)

This is my init file:

(require 'package)
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
                    (not (gnutls-available-p))))
       (proto (if no-ssl "http" "https")))
  (when no-ssl
    (warn "\
Your version of Emacs does not support SSL connections,
which is unsafe because it allows man-in-the-middle attacks.
There are two things you can do about this warning:
1. Install an Emacs version that does support SSL and be safe.
2. Remove this warning from your init file so you won't see it again."))
  ;; Comment/uncomment these two lines to enable/disable MELPA and MELPA Stable as desired
  (add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
  ;;(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t)
  (when (< emacs-major-version 24)
    ;; For important compatibility libraries like cl-lib
    (add-to-list 'package-archives (cons "gnu" (concat proto "://elpa.gnu.org/packages/")))))
(package-initialize)

(package-install 'quelpa)
(require 'quelpa)
(quelpa '(org-super-agenda :fetcher github :repo "alphapapa/org-super-agenda"))
(quelpa '(org-ql :fetcher github :repo "alphapapa/org-ql"))

(require 'org-ql-agenda)
(org-super-agenda-mode)
(require 'org-habit)

(org-ql-agenda "~/org/main.org"
  (or (tags "@ThisPerson")
      (todo "MEETING"))
  
  :super-groups ((:name "Some Group"
			:tag "@SomePerson")
		 (:todo ("MEETING"))
		 (:priority "B")))

(org-ql-agenda "~/org/main.org"
  (and (or (date = today)
           (deadline <=)
           (scheduled <= today))
       (not (done)))
  ;; The `org-super-agenda-groups' setting is used automatically when set, or it
  ;; may be overriden by specifying it here:
  :super-groups ((:name "Bills"
                        :tag "bills")
                 (:todo ("SOMEDAY" "TO-READ" "CHECK" "TO-WATCH" "WATCHING")
                        :order 7)
                 (:name "Personal"
                        :habit t
                        :tag "personal"
                        :order 3)
                 (:todo "WAITING"
                        :order 6)
                 (:priority "A" :order 1)
                 (:priority "B" :order 2)
                 (:priority "C" :order 2)))

helm-org-ql default predicate

Would it be possible to add a customization option to set a default predicate? For instance, if I have the buffer

* a
** b
*** c
**** bc

I typically want to pattern match the whole outline path, so i'll do something like
olp:a olp:b olp:c (or olp:a,b,c). Is it feasible to add a customization option so that I could simply type a b c and get the same behavior?

Thanks a lot for this package, I've really enjoyed using it so far!

Unable to run usual org functions like refile or schedule on results from org-ql or org-ql-search

I've just noticed that you can't use functions like org-agenda-refile or org-agenda-schedule on result items when using org-ql or org-ql-search. I even tried putting org-ql-block into org-agenda-custom-commands as shown in README, and I got same result.
For example running org-agenda-schedule returns org-agenda-check-type: No Org agenda currently displayed.
I kind of understand that org-ql buffers probably aren't usual org-agenda buffers and that org-ql is still in development, so at this point I am just asking if this is an expected behavior or some kind of issue on my side and if former, is there currently any way to use org-ql and be able to manipulate org items directly from results' buffer?

Unexpected Result

2018-12-14-10-31-22

I have the following snippet:

(org-ql-agenda "~/org/notes.org"
  (todo)
  
  ;; The `org-super-agenda-groups' setting is used automatically when set, or it
  ;; may be overriden by specifying it here:
  :super-groups '((:name "TODO" :todo ("TODO"))
                           (:name "DONE" :todo ("DONE"))))

But I get the following agenda view:

  TODO  Nix Configuration  
  TODO  util  
  TODO  overlays [0/3]  
  TODO  unstable  
  TODO  python  
  TODO  stable  
  TODO  modules [0/2]  
  TODO  nixos  
  TODO  home  
  DONE  Handle unmanaged dotfiles  
  DONE  Learn about SystemD units  
  TODO  Employment  
  TODO  pywal theming [3/5]  
  DONE  Xresources  
  DONE  Emacs  
  TODO  Qtile  
  TODO  Rofi  
  DONE  TWMN  
  TODO  recap README  
  TODO  Improve qutebrowser config-source efficiency  

(TODO and DONE are shown as unicode in the image because of prettify-symbols-mode).

Why are the items not separated by the groups? Why are there no titles?

Wrong `regexp' predicate documentation

The documentation says:

regexp (regexp)
    Return non-nil if current entry matches REGEXP (a regexp string).

However, an rx expression is expected, not a string. A string may be provided but then it's escaped rather than interpreted as a regexp.

Byte-compilation obscures lexically-bound variables in query, breaking caching

I'm having an issue with (I believe anyway) caching.

(defun tl/test (search)
  (org-ql "~/test.org"
    (and
     (todo)
     (tags search))))

with test.org looking something like:

* TODO test one   :test:
* TODO nottesttwo :nottest:

these two calls both return the first todo.

(tl/test "test")
(tl/test "nottest")

I suspect caching because if I save the test.org file between the two calls to tl/test it works as expected, even if test.org hasn't changed (structure). I'm assuming the save invalidates the cache or something.

Thanks!

make org-ql more robust to badly formed habits

Given an org file:

* TODO meditation
  SCHEDULED: <2015-01-30 Fri 08:00 .+1d>
  :PROPERTIES:
  :STYLE:        habit
  :END:
* TODO jog
  SCHEDULED: <2015-01-28 Wed 19:30-19:45 .+1d>

This org-ql query:

(org-ql FILE (scheduled <= today))

gives error:

if: Unknown date-element type: active-range

I think it would be better if this error didn't break the org-ql function.

After adding the habit property things work fine, but it would be more robust to return results if possible.

ts argument for the current week?

Hello alphapapa, and thank you so much for this great tool!

Is there any way to query for timestamps within the current week (like the default org agenda view)? I see how it's possible to do 7 days prior, but I'd like to drop last week's tail items if possible.

I could imagine doing it either in the query or in a :discard group, but I'm not sure what selector I would use.

Any guidance would be greatly appreciated!

Argument handling in org-agenda-ql

Hi, I probably shouldn't be using the issue tracker to bother you with something as small as this. But this example in the README doesn't work:

(org-ql-agenda "~/org-super-agenda/test/test.org"
  (and (or (date = today)
           (deadline <=)
           (scheduled <= today))
       (not (done))))

This particular example incidentally errors with a (void-variable todo-keyword) but right now I don't mean this.

The form: (org-ql-agenda "~/path/to/file" query) in general doesn't work unless a keyword argument is provided in the end (such as :sort nil). This seems to be a shortcoming in the pcase based argument matching in org-ql-agenda macro. I had to add another case handling condition to make it work:

    (`(,arg-files ,arg-pred)
     (setq files arg-files
           query arg-pred))

But you may have some other cleaner means in mind.

org-ql-block "Query:" headers sometimes not put on a new line

"Query:" headers are sometimes attached to the preceding line rather than put on the next line, when using multiple org-ql-block entries in a single agenda. For example:

Query:(todo "FEEDBACK")  In:("~/org/...")
  FEEDBACK [#B] xxx
  FEEDBACK yyy Query:(todo "TODO")  In:("~/org/...")
  TODO [#A] zzz

User-defined sorting signals an error in org-ql-select

When I pass a function symbol as `sort' argument to org-ql-select, I get error "SORT must be either nil, or one or a list of the defined sorting methods (see documentation)". I think this is because of the line

(setq sort (-list sort))

that changes the type of `sort' from a function symbol to a list.

querying clocked in time

I'm trying to write a query that basically says, "show me the items that I worked on last week." Any advice on how to achieve this would be greatly welcomed!

Error installing org-ql with straight package manager

I have the following:

(use-package org-super-agenda
    :after '(org org-ql)
    :straight
    (org-super-agenda
      :type git
      :host github
      :repo "alphapapa/org-super-agenda"))

(use-package org-ql-agenda
    :after '(org org-ql)
    :straight
    (org-ql-agenda
      :type git
      :host github
      :repo "alphapapa/org-agenda-ng"
      :files ("org-ql-agenda.el")))

(use-package org-ql
    :after '(org)
    :straight
    (org-ql
      :type git
      :host github
      :repo "alphapapa/org-agenda-ng"
      :files ("org-ql.el")))

After evaluating that I attempt to use org-ql-search. After finishing the selections I get the error:

helm-M-x: Symbol’s value as variable is void: org-super-agenda-auto-selector-keywords

Any ideas?

Set scope to tree or region

Org-map-entries has a scope argument that determines the scope of the command.

It supports the following values among others:

tree    The subtree started with the entry at point
region  The entries within the active region, if any

Can this be done with org-ql (limit the headlines parsed to a subtree or region)?

org-ql-agenda: void-function date

Edit: Looks like the date predicate was commented-out, submitted a PR as assuming this was unintentional

Hi thanks for fixing the other issue, I've run into another

Trying to execute this example from the docs:

;; Example agenda view from docs
(org-ql-agenda "P:/test/test.org"
  (and (or (date = today)
           (deadline <=)
           (scheduled <= today))
       (not (done)))
  ;; The `org-super-agenda-groups' setting is used automatically when set, or it
  ;; may be overriden by specifying it here:
  :super-groups ((:name "Bills"
                        :tag "bills")
                 (:todo ("TODO" "MEETING" "DONE")
                        :order 7)
                 (:name "Personal"
                        :habit t
                        :tag "personal"
                        :order 3)
                 (:todo "WAITING"
                        :order 6)
                 (:priority "A" :order 1)
                 (:priority "B" :order 2)
                 (:priority "C" :order 2)))

And I get:

Debugger entered--Lisp error: (void-function date)
  date(= 737219)
  #f(compiled-function () #<bytecode 0x2a1085d>)()
  funcall(#f(compiled-function () #<bytecode 0x2a1085d>))
  (if (funcall predicate) (progn (setq --cl-var-- (cons (funcall action) --cl-var--))))
  (progn (if (funcall predicate) (progn (setq --cl-var-- (cons (funcall action) --cl-var--)))) (outline-next-heading))
  (while (progn (if (funcall predicate) (progn (setq --cl-var-- (cons (funcall action) --cl-var--)))) (outline-next-heading)))
  (let* ((--cl-var-- nil)) (while (progn (if (funcall predicate) (progn (setq --cl-var-- (cons (funcall action) --cl-var--)))) (outline-next-heading))) (nreverse --cl-var--))
  (save-restriction (if narrow nil (widen)) (goto-char (point-min)) (if (org-before-first-heading-p) (progn (outline-next-heading))) (let* ((--cl-var-- nil)) (while (progn (if (funcall predicate) (progn (setq --cl-var-- (cons (funcall action) --cl-var--)))) (outline-next-heading))) (nreverse --cl-var--)))
  (save-excursion (save-restriction (if narrow nil (widen)) (goto-char (point-min)) (if (org-before-first-heading-p) (progn (outline-next-heading))) (let* ((--cl-var-- nil)) (while (progn (if (funcall predicate) (progn (setq --cl-var-- (cons (funcall action) --cl-var--)))) (outline-next-heading))) (nreverse --cl-var--))))
  (progn (let ((list org-ql-predicates) (it-index 0)) (while list (let ((it (car list))) (fset (plist-get it :name) (plist-get it :fn))) (setq it-index (1+ it-index)) (setq list (cdr list)))) (save-excursion (save-restriction (if narrow nil (widen)) (goto-char (point-min)) (if (org-before-first-heading-p) (progn (outline-next-heading))) (let* ((--cl-var-- nil)) (while (progn (if (funcall predicate) (progn (setq --cl-var-- (cons (funcall action) --cl-var--)))) (outline-next-heading))) (nreverse --cl-var--)))))
  (unwind-protect (progn (let ((list org-ql-predicates) (it-index 0)) (while list (let ((it (car list))) (fset (plist-get it :name) (plist-get it :fn))) (setq it-index (1+ it-index)) (setq list (cdr list)))) (save-excursion (save-restriction (if narrow nil (widen)) (goto-char (point-min)) (if (org-before-first-heading-p) (progn (outline-next-heading))) (let* ((--cl-var-- nil)) (while (progn (if (funcall predicate) (progn (setq --cl-var-- (cons (funcall action) --cl-var--)))) (outline-next-heading))) (nreverse --cl-var--))))) (let ((list orig-fns) (it-index 0)) (while list (let ((it (car list))) (fset (plist-get it :name) (plist-get it :fn))) (setq it-index (1+ it-index)) (setq list (cdr list)))))
  (let (orig-fns) (let ((list org-ql-predicates) (it-index 0)) (while list (let ((it (car list))) (let ((name (plist-get it :name))) (setq orig-fns (cons (list :name name :fn (symbol-function name)) orig-fns)))) (setq it-index (1+ it-index)) (setq list (cdr list)))) (unwind-protect (progn (let ((list org-ql-predicates) (it-index 0)) (while list (let ((it (car list))) (fset (plist-get it :name) (plist-get it :fn))) (setq it-index (1+ it-index)) (setq list (cdr list)))) (save-excursion (save-restriction (if narrow nil (widen)) (goto-char (point-min)) (if (org-before-first-heading-p) (progn (outline-next-heading))) (let* ((--cl-var-- nil)) (while (progn (if (funcall predicate) (progn (setq --cl-var-- (cons (funcall action) --cl-var--)))) (outline-next-heading))) (nreverse --cl-var--))))) (let ((list orig-fns) (it-index 0)) (while list (let ((it (car list))) (fset (plist-get it :name) (plist-get it :fn))) (setq it-index (1+ it-index)) (setq list (cdr list))))))
  (progn (let ((--cl-keys-- --cl-rest--)) (while --cl-keys-- (cond ((memq (car --cl-keys--) '(:predicate :action :narrow :allow-other-keys)) (setq --cl-keys-- (cdr (cdr --cl-keys--)))) ((car (cdr (memq ':allow-other-keys --cl-rest--))) (setq --cl-keys-- nil)) (t (error "Keyword argument %s not one of (:predicate :action :narrow)" (car --cl-keys--)))))) (let (orig-fns) (let ((list org-ql-predicates) (it-index 0)) (while list (let ((it (car list))) (let ((name (plist-get it :name))) (setq orig-fns (cons (list :name name :fn (symbol-function name)) orig-fns)))) (setq it-index (1+ it-index)) (setq list (cdr list)))) (unwind-protect (progn (let ((list org-ql-predicates) (it-index 0)) (while list (let ((it (car list))) (fset (plist-get it :name) (plist-get it :fn))) (setq it-index (1+ it-index)) (setq list (cdr list)))) (save-excursion (save-restriction (if narrow nil (widen)) (goto-char (point-min)) (if (org-before-first-heading-p) (progn (outline-next-heading))) (let* ((--cl-var-- nil)) (while (progn (if (funcall predicate) (progn (setq --cl-var-- (cons (funcall action) --cl-var--)))) (outline-next-heading))) (nreverse --cl-var--))))) (let ((list orig-fns) (it-index 0)) (while list (let ((it (car list))) (fset (plist-get it :name) (plist-get it :fn))) (setq it-index (1+ it-index)) (setq list (cdr list)))))))
  (let* ((predicate (car (cdr (plist-member --cl-rest-- ':predicate)))) (action (car (cdr (plist-member --cl-rest-- ':action)))) (narrow (car (cdr (plist-member --cl-rest-- ':narrow))))) (progn (let ((--cl-keys-- --cl-rest--)) (while --cl-keys-- (cond ((memq (car --cl-keys--) '(:predicate :action :narrow :allow-other-keys)) (setq --cl-keys-- (cdr (cdr --cl-keys--)))) ((car (cdr (memq ':allow-other-keys --cl-rest--))) (setq --cl-keys-- nil)) (t (error "Keyword argument %s not one of (:predicate :action :narrow)" (car --cl-keys--)))))) (let (orig-fns) (let ((list org-ql-predicates) (it-index 0)) (while list (let ((it (car list))) (let ((name (plist-get it :name))) (setq orig-fns (cons (list :name name :fn (symbol-function name)) orig-fns)))) (setq it-index (1+ it-index)) (setq list (cdr list)))) (unwind-protect (progn (let ((list org-ql-predicates) (it-index 0)) (while list (let ((it (car list))) (fset (plist-get it :name) (plist-get it :fn))) (setq it-index (1+ it-index)) (setq list (cdr list)))) (save-excursion (save-restriction (if narrow nil (widen)) (goto-char (point-min)) (if (org-before-first-heading-p) (progn (outline-next-heading))) (let* ((--cl-var-- nil)) (while (progn (if (funcall predicate) (progn (setq --cl-var-- (cons (funcall action) --cl-var--)))) (outline-next-heading))) (nreverse --cl-var--))))) (let ((list orig-fns) (it-index 0)) (while list (let ((it (car list))) (fset (plist-get it :name) (plist-get it :fn))) (setq it-index (1+ it-index)) (setq list (cdr list))))))))
  org-ql--select(:predicate #f(compiled-function () #<bytecode 0x2a1085d>) :action #f(compiled-function () #<bytecode 0x2a10f8d>) :narrow nil)
  apply(org-ql--select (:predicate #f(compiled-function () #<bytecode 0x2a1085d>) :action #f(compiled-function () #<bytecode 0x2a10f8d>) :narrow nil))
  (let ((new-result (apply (function org-ql--select) args))) (cond ((or (not query-cache) (not buffer-unmodified-p)) (puthash (current-buffer) (list (buffer-modified-tick) (let ((table (make-hash-table :test 'org-ql-hash-test))) (puthash args (or new-result 'org-ql-nil) table) table)) org-ql-cache)) (t (puthash args (or new-result 'org-ql-nil) query-cache))) new-result)
  (if cached-result (if (eq cached-result 'org-ql-nil) (progn nil) cached-result) (let ((new-result (apply (function org-ql--select) args))) (cond ((or (not query-cache) (not buffer-unmodified-p)) (puthash (current-buffer) (list (buffer-modified-tick) (let ((table (make-hash-table :test 'org-ql-hash-test))) (puthash args (or new-result 'org-ql-nil) table) table)) org-ql-cache)) (t (puthash args (or new-result 'org-ql-nil) query-cache))) new-result))
  (let* ((buffer-cache (and t (gethash (current-buffer) org-ql-cache))) (query-cache (and buffer-cache (car (cdr buffer-cache)))) (modified-tick (and query-cache (car buffer-cache))) (buffer-unmodified-p (and modified-tick (eq (buffer-modified-tick) modified-tick))) (cached-result (and buffer-unmodified-p (gethash args query-cache)))) (if cached-result (if (eq cached-result 'org-ql-nil) (progn nil) cached-result) (let ((new-result (apply (function org-ql--select) args))) (cond ((or (not query-cache) (not buffer-unmodified-p)) (puthash (current-buffer) (list (buffer-modified-tick) (let ((table (make-hash-table :test 'org-ql-hash-test))) (puthash args (or new-result 'org-ql-nil) table) table)) org-ql-cache)) (t (puthash args (or new-result 'org-ql-nil) query-cache))) new-result)))
  org-ql--select-cached(:predicate #f(compiled-function () #<bytecode 0x2a1085d>) :action #f(compiled-function () #<bytecode 0x2a10f8d>) :narrow nil)
  (save-current-buffer (set-buffer it) (if (derived-mode-p 'org-mode) nil (user-error "Not an Org buffer: %s" (buffer-name))) (org-ql--select-cached :predicate predicate :action action :narrow narrow))
  (closure ((action . #f(compiled-function () #<bytecode 0x2a10f8d>)) (predicate . #f(compiled-function () #<bytecode 0x2a1085d>)) (sources "P:/test/test.org") (sort) (narrow) (action lambda nil (->> (org-element-headline-parser (line-end-position)) org-ql--add-markers)) (--cl-rest-- :action (lambda nil (->> (org-element-headline-parser (line-end-position)) org-ql--add-markers)) :narrow nil :sort nil) (query and (or (date = today) (deadline <=) (scheduled <= today)) (not (done))) (buffers-or-files . "P:/test/test.org") t) (it) (save-current-buffer (set-buffer it) (if (derived-mode-p 'org-mode) nil (user-error "Not an Org buffer: %s" (buffer-name))) (org-ql--select-cached :predicate predicate :action action :narrow narrow)))(#<buffer test.org>)
  mapcar((closure ((action . #f(compiled-function () #<bytecode 0x2a10f8d>)) (predicate . #f(compiled-function () #<bytecode 0x2a1085d>)) (sources "P:/test/test.org") (sort) (narrow) (action lambda nil (->> (org-element-headline-parser (line-end-position)) org-ql--add-markers)) (--cl-rest-- :action (lambda nil (->> (org-element-headline-parser (line-end-position)) org-ql--add-markers)) :narrow nil :sort nil) (query and (or (date = today) (deadline <=) (scheduled <= today)) (not (done))) (buffers-or-files . "P:/test/test.org") t) (it) (save-current-buffer (set-buffer it) (if (derived-mode-p 'org-mode) nil (user-error "Not an Org buffer: %s" (buffer-name))) (org-ql--select-cached :predicate predicate :action action :narrow narrow))) (#<buffer test.org>))
  (-flatten-n 1 (mapcar (function (lambda (it) (save-current-buffer (set-buffer it) (if (derived-mode-p 'org-mode) nil (user-error "Not an Org buffer: %s" (buffer-name))) (org-ql--select-cached :predicate predicate :action action :narrow narrow)))) (mapcar (function (lambda (it) (cond ((bufferp it) it) ((stringp it) (or (find-buffer-visiting it) (if (file-readable-p it) (progn (find-file-noselect it))) (user-error "Can't open file: %s" it))) ((error "cl-etypecase failed: %s, %s" it '(buffer string)) nil)))) sources)))
  (let* ((sources (cond ((null buffers-or-files) (list (current-buffer))) ((listp buffers-or-files) buffers-or-files) (t (list buffers-or-files)))) (predicate (byte-compile (list 'lambda nil (list 'let '(from to on) (list 'cl-macrolet '((clocked (&key from to on) (when on (setq from on to on)) (when from (setq from (org-ql--parse-time-string from))) (when to (setq to (org-ql--parse-time-string to 'end))) `(org-ql--predicate-clocked :from ,from :to ,to)) (ts (&key from to on) (when on (setq from on to on)) (when from (setq from (org-ql--parse-time-string from))) (when to (setq to (org-ql--parse-time-string to 'end))) `(org-ql--predicate-ts :from ,from :to ,to)) (ts-active (&key from to on) (when on (setq from on to on)) (when from (setq from (org-ql--parse-time-string from))) (when to (setq to (org-ql--parse-time-string to 'end))) `(org-ql--predicate-ts-active :from ,from :to ,to)) (ts-inactive (&key from to on) (when on (setq from on to on)) (when from (setq from (org-ql--parse-time-string from))) (when to (setq to (org-ql--parse-time-string to 'end))) `(org-ql--predicate-ts-inactive :from ,from :to ,to))) (list 'cl-symbol-macrolet '((today org-ql--today) (= (function =)) (< (function <)) (> (function >)) (<= (function <=)) (>= (function >=))) query)))))) (action (byte-compile action)) (org-ql--today (org-today)) (items (-flatten-n 1 (mapcar (function (lambda (it) (save-current-buffer (set-buffer it) (if (derived-mode-p 'org-mode) nil (user-error "Not an Org buffer: %s" (buffer-name))) (org-ql--select-cached :predicate predicate :action action :narrow narrow)))) (mapcar (function (lambda (it) (cond ((bufferp it) it) ((stringp it) (or (find-buffer-visiting it) (if (file-readable-p it) (progn (find-file-noselect it))) (user-error "Can't open file: %s" it))) ((error "cl-etypecase failed: %s, %s" it '(buffer string)) nil)))) sources))))) (cond ((null sort) items) ((and sort (setq sort (-list sort)) (let* ((--cl-var-- sort) (elem nil) (--cl-flag-- t)) (while (and (consp --cl-var--) (progn (setq elem (car --cl-var--)) (setq --cl-flag-- (memq elem '(date deadline scheduled todo priority))))) (setq --cl-var-- (cdr --cl-var--))) (if --cl-flag-- (progn t) nil))) (org-ql--sort-by items sort)) (t (user-error "SORT must be either nil, or one or a list of the defined sorting methods (see documentation)"))))
  (progn (let ((--cl-keys-- --cl-rest--)) (while --cl-keys-- (cond ((memq (car --cl-keys--) '(:action :narrow :sort :allow-other-keys)) (setq --cl-keys-- (cdr (cdr --cl-keys--)))) ((car (cdr (memq ':allow-other-keys --cl-rest--))) (setq --cl-keys-- nil)) (t (error "Keyword argument %s not one of (:action :narrow :sort)" (car --cl-keys--)))))) (let* ((sources (cond ((null buffers-or-files) (list (current-buffer))) ((listp buffers-or-files) buffers-or-files) (t (list buffers-or-files)))) (predicate (byte-compile (list 'lambda nil (list 'let '(from to on) (list 'cl-macrolet '((clocked (&key from to on) (when on (setq from on to on)) (when from (setq from (org-ql--parse-time-string from))) (when to (setq to (org-ql--parse-time-string to 'end))) `(org-ql--predicate-clocked :from ,from :to ,to)) (ts (&key from to on) (when on (setq from on to on)) (when from (setq from (org-ql--parse-time-string from))) (when to (setq to (org-ql--parse-time-string to 'end))) `(org-ql--predicate-ts :from ,from :to ,to)) (ts-active (&key from to on) (when on (setq from on to on)) (when from (setq from (org-ql--parse-time-string from))) (when to (setq to (org-ql--parse-time-string to 'end))) `(org-ql--predicate-ts-active :from ,from :to ,to)) (ts-inactive (&key from to on) (when on (setq from on to on)) (when from (setq from (org-ql--parse-time-string from))) (when to (setq to (org-ql--parse-time-string to 'end))) `(org-ql--predicate-ts-inactive :from ,from :to ,to))) (list 'cl-symbol-macrolet '((today org-ql--today) (= (function =)) (< (function <)) (> (function >)) (<= (function <=)) (>= (function >=))) query)))))) (action (byte-compile action)) (org-ql--today (org-today)) (items (-flatten-n 1 (mapcar (function (lambda (it) (save-current-buffer (set-buffer it) (if (derived-mode-p 'org-mode) nil (user-error "Not an Org buffer: %s" (buffer-name))) (org-ql--select-cached :predicate predicate :action action :narrow narrow)))) (mapcar (function (lambda (it) (cond ((bufferp it) it) ((stringp it) (or (find-buffer-visiting it) (if (file-readable-p it) (progn (find-file-noselect it))) (user-error "Can't open file: %s" it))) ((error "cl-etypecase failed: %s, %s" it '(buffer string)) nil)))) sources))))) (cond ((null sort) items) ((and sort (setq sort (-list sort)) (let* ((--cl-var-- sort) (elem nil) (--cl-flag-- t)) (while (and (consp --cl-var--) (progn (setq elem (car --cl-var--)) (setq --cl-flag-- (memq elem '(date deadline scheduled todo priority))))) (setq --cl-var-- (cdr --cl-var--))) (if --cl-flag-- (progn t) nil))) (org-ql--sort-by items sort)) (t (user-error "SORT must be either nil, or one or a list of the defined sorting methods (see documentation)")))))
  (let* ((action (car (cdr (plist-member --cl-rest-- ':action)))) (narrow (car (cdr (plist-member --cl-rest-- ':narrow)))) (sort (car (cdr (plist-member --cl-rest-- ':sort))))) (progn (let ((--cl-keys-- --cl-rest--)) (while --cl-keys-- (cond ((memq (car --cl-keys--) '(:action :narrow :sort :allow-other-keys)) (setq --cl-keys-- (cdr (cdr --cl-keys--)))) ((car (cdr (memq ':allow-other-keys --cl-rest--))) (setq --cl-keys-- nil)) (t (error "Keyword argument %s not one of (:action :narrow :sort)" (car --cl-keys--)))))) (let* ((sources (cond ((null buffers-or-files) (list (current-buffer))) ((listp buffers-or-files) buffers-or-files) (t (list buffers-or-files)))) (predicate (byte-compile (list 'lambda nil (list 'let '(from to on) (list 'cl-macrolet '((clocked (&key from to on) (when on (setq from on to on)) (when from (setq from (org-ql--parse-time-string from))) (when to (setq to (org-ql--parse-time-string to 'end))) `(org-ql--predicate-clocked :from ,from :to ,to)) (ts (&key from to on) (when on (setq from on to on)) (when from (setq from (org-ql--parse-time-string from))) (when to (setq to (org-ql--parse-time-string to 'end))) `(org-ql--predicate-ts :from ,from :to ,to)) (ts-active (&key from to on) (when on (setq from on to on)) (when from (setq from (org-ql--parse-time-string from))) (when to (setq to (org-ql--parse-time-string to 'end))) `(org-ql--predicate-ts-active :from ,from :to ,to)) (ts-inactive (&key from to on) (when on (setq from on to on)) (when from (setq from (org-ql--parse-time-string from))) (when to (setq to (org-ql--parse-time-string to 'end))) `(org-ql--predicate-ts-inactive :from ,from :to ,to))) (list 'cl-symbol-macrolet '((today org-ql--today) (= (function =)) (< (function <)) (> (function >)) (<= (function <=)) (>= (function >=))) query)))))) (action (byte-compile action)) (org-ql--today (org-today)) (items (-flatten-n 1 (mapcar (function (lambda (it) (save-current-buffer (set-buffer it) (if (derived-mode-p 'org-mode) nil (user-error "Not an Org buffer: %s" (buffer-name))) (org-ql--select-cached :predicate predicate :action action :narrow narrow)))) (mapcar (function (lambda (it) (cond ((bufferp it) it) ((stringp it) (or (find-buffer-visiting it) (if (file-readable-p it) (progn (find-file-noselect it))) (user-error "Can't open file: %s" it))) ((error "cl-etypecase failed: %s, %s" it '(buffer string)) nil)))) sources))))) (cond ((null sort) items) ((and sort (setq sort (-list sort)) (let* ((--cl-var-- sort) (elem nil) (--cl-flag-- t)) (while (and (consp --cl-var--) (progn (setq elem (car --cl-var--)) (setq --cl-flag-- (memq elem '(date deadline scheduled todo priority))))) (setq --cl-var-- (cdr --cl-var--))) (if --cl-flag-- (progn t) nil))) (org-ql--sort-by items sort)) (t (user-error "SORT must be either nil, or one or a list of the defined sorting methods (see documentation)"))))))
  org-ql-query("P:/test/test.org" (and (or (date = today) (deadline <=) (scheduled <= today)) (not (done))) :action (lambda nil (->> (org-element-headline-parser (line-end-position)) org-ql--add-markers)) :narrow nil :sort nil)
  (org-ql '"P:/test/test.org" (and (or (date = today) (deadline <=) (scheduled <= today)) (not (done))) :sort nil :markers t :narrow nil)
  eval((org-ql '"P:/test/test.org" (and (or (date = today) (deadline <=) (scheduled <= today)) (not (done))) :sort nil :markers t :narrow nil))
  org-ql-agenda--agenda("P:/test/test.org" (and (or (date = today) (deadline <=) (scheduled <= today)) (not (done))) :sort nil :buffer nil :narrow nil :super-groups ((:name "Bills" :tag "bills") (:todo ("TODO" "MEETING" "DONE") :order 7) (:name "Personal" :habit t :tag "personal" :order 3) (:todo "WAITING" :order 6) (:priority "A" :order 1) (:priority "B" :order 2) (:priority "C" :order 2)))
  eval((org-ql-agenda--agenda "P:/test/test.org" '(and (or (date = today) (deadline <=) (scheduled <= today)) (not (done))) :sort 'nil :buffer nil :narrow nil :super-groups '((:name "Bills" :tag "bills") (:todo ("TODO" "MEETING" "DONE") :order 7) (:name "Personal" :habit t :tag "personal" :order 3) (:todo "WAITING" :order 6) (:priority "A" :order 1) (:priority "B" :order 2) (:priority "C" :order 2))) nil)
  elisp--eval-last-sexp(nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  call-interactively(eval-last-sexp nil nil)
  command-execute(eval-last-sexp)

Here's my init (note using straight.el rather than quelpa as it was causing other issues)

;; boostrap straight.el
(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 5))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

;; install use-package
(straight-use-package 'use-package)

;; install org-super-agenda and org-ql
(use-package org-super-agenda
	     :straight t
	     :config (org-super-agenda-mode))

(use-package org-ql
	     :straight (org-ql :type git :host github :repo "alphapapa/org-ql")
	     :config (require 'org-ql-agenda))

This works fine:

;; Test org-ql-agenda
(org-ql-agenda "P:/test/test.org"
  (or (tags "@SomePerson")
      (todo "TODO"))
  
  :super-groups ((:name "Some Group"
			:tag "@SomePerson")
		 (:todo ("TODO"))))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.