Compare commits

..

8 commits

Author SHA1 Message Date
Adam Porter
ed73a15c69 WIP: (org-ql-search) Rename argument 2024-01-03 18:50:00 -06:00
Adam Porter
2c2d2a1aee WIP: Docstring 2024-01-03 18:50:00 -06:00
Adam Porter
c6348e622c WIP: Docstring 2024-01-03 18:50:00 -06:00
Adam Porter
71c8079e22 WIP: (org-ql-search) Handle narrowing, and improve titles 2024-01-03 18:50:00 -06:00
Adam Porter
1fce6cc364 Comment: Add TODO 2024-01-03 18:50:00 -06:00
Adam Porter
23e44cb6f1 WIP: (org-ql-view) Update header line 2024-01-03 18:50:00 -06:00
Adam Porter
9237f0d93b WIP: (org-ql-select) Tidy, etc. 2024-01-03 18:50:00 -06:00
Adam Porter
e57d50b81c WIP: Accept entry IDs as IN argument 2024-01-03 18:50:00 -06:00
12 changed files with 456 additions and 999 deletions

View file

@ -45,10 +45,6 @@ jobs:
- 27.2 - 27.2
- 28.1 - 28.1
- 28.2 - 28.2
- 29.1
- 29.2
- 29.3
- 29.4
- snapshot - snapshot
steps: steps:
- uses: purcell/setup-emacs@master - uses: purcell/setup-emacs@master

View file

@ -19,7 +19,6 @@ It includes three libraries: The =org-ql= library is flexible and may be used as
- [[#installation][Installation]] - [[#installation][Installation]]
- [[#usage][Usage]] - [[#usage][Usage]]
- [[#changelog][Changelog]] - [[#changelog][Changelog]]
- [[#development][Development]]
:END: :END:
@ -233,7 +232,7 @@ Note that the =effort=, =level=, and =priority= predicates do not support compar
Arguments are listed next to predicate names, where applicable. 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. + =blocked= :: Return non-nil if current heading is blocked. Calls ~org-entry-blocked-p~, which see.
+ =category (&rest categories)= :: Return non-nil if current heading is in one or more of ~CATEGORIES~ (a list of strings). + =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~. + =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=. + =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. + =habit= :: Return non-nil if entry is a habit.
@ -256,16 +255,16 @@ Arguments are listed next to predicate names, where applicable.
- Aliases: ~smart~. - 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~. - *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. + ~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 (&rest tags)= :: Return non-nil if current heading has one or more of ~TAGS~ (a list of strings). Tests both inherited and local tags. + =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 (&rest 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. + =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~. - Aliases: ~inherited-tags~, ~tags-i~, ~itags~.
+ =tags-local (&rest 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. + =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~. - Aliases: ~local-tags~, ~tags-l~, ~ltags~.
+ =tags-all (&rest tags)= :: Return non-nil if current heading includes all of ~TAGS~. Tests both inherited and local tags. + =tags-all (tags)= :: Return non-nil if current heading includes all of ~TAGS~. Tests both inherited and local tags.
- Aliases: ~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. + =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*~. - Aliases: ~tags*~.
+ =todo (&rest 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~). + =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 *** Ancestor/descendant predicates
@ -556,84 +555,7 @@ Simple links may also be written manually in either sexp or non-sexp form, like:
** 0.9-pre ** 0.9-pre
*Additions* Nothing new yet.
+ Face ~org-ql-view-query~, applied to view queries in header line.
+ Face ~org-ql-view-title~, applied to view titles in header line.
+ Option ~org-ql-view-relative-deadline-prefix~.
*Changes*
+ Command ~org-ql-find~ respects narrowing of the current buffer by default, allowing searching within the narrowed region. (Using one ~C-u~ argument widens the current buffer, and using two ~C-u~ arguments prompts for the buffers to search.)
+ Function ~org-ql-completing-read~ accepts a new ~NARROWP~ argument, which is passed to ~org-ql-select~.
*Fixes*
+ Customization group for face ~org-ql-view-due-date~.
+ Apply Org syntax font-locking to items in ~org-ql-view~ buffers.
*** helm-org-ql
Tagged v0.6.2, fixing a compilation warning.
** 0.8.10
*Fixes*
+ Command ~org-ql-refile~ uses the base buffer when refiling to an indirect buffer. ([[https://github.com/alphapapa/org-ql/issues/466][#466]].)
+ Predicate ~link~ could signal an error when searching text that is mistakenly recognized as an Org link (e.g. Bash double-bracket constructs in a source block). (Thanks to [[https://github.com/jwiegley][John Wiegley]] for reporting.)
** 0.8.9
*Fixes*
+ Predicate ~property~ when called with argument form ~(property "PROPERTY-NAME" :inherit t)~. ([[https://github.com/alphapapa/org-ql/issues/460][#460]]. Thanks to [[https://github.com/Stewmath][Stewmath]] for reporting.)
+ Predicate ~level~'s preamble optimizer allows expressions in place of the numeric argument. (See [[https://github.com/alphapapa/org-ql/issues/460][#460]]. Thanks to [[https://github.com/Stewmath][Stewmath]] for reporting.)
+ Reading of view settings from Org links in upcoming Emacs version. ([[https://github.com/alphapapa/org-ql/issues/461][#461]]. Thanks to [[https://github.com/snogge][Ola Nilsson]] for help debugging, and for maintaining [[https://github.com/jorgenschaefer/emacs-buttercup][Buttercup]].)
*Compatibility*
+ Fix compilation error on Emacs 30. ([[https://github.com/alphapapa/org-ql/issues/433][#433]]. Thanks to [[https://github.com/akirak][Akira Komamura]] and [[https://github.com/monnier][Stefan Monnier]].)
** 0.8.8
*Fixes*
+ Remove text properties from to-do keywords before displaying them in an ~org-ql-view~ buffer. (Such text properties could cause them to, e.g. display with extra leading spaces, depending on which other modes might be enabled in the source Org buffer.)
+ Binding of ~completion-styles-alist~ in ~org-ql-completing-read~. (This fixes compatibility with Helm's ~helm~ completion style, as well as default Emacs completion in recursive minibuffers. [[https://github.com/alphapapa/org-ql/issues/337][#337]]. Thanks to [[https://github.com/progfolio][Nicholas Vollmer]], [[https://github.com/9viz][viz]], and [[https://github.com/karthink][Karthik Chikmagalur]] for reporting and suggesting fixes.)
+ Use of the context snippet function for ~org-ql-completing-read~. ([[https://github.com/alphapapa/org-ql/issues/419][#419]]. Thanks to [[https://github.com/tpeacock19][tpeacock19]] for reporting.)
** 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 [[https://github.com/alphapapa/org-ql/pull/237][#237]] and [[https://github.com/alphapapa/org-ql/issues/371][#371]]. Thanks to [[https://github.com/yantar92][Ihor Radchenko]].)
+ Timestamps with day-of-the-week abbreviations are matched more flexibly (allowing, e.g. a period in French locales). (See [[https://github.com/alphapapa/org-ql/discussions/429][#429]], [[https://github.com/alphapapa/org-ql/issues/432][#432]]. Thanks to [[https://github.com/neurolit][Florian D.]] for reporting.)
+ Command ~org-ql-search~ did not narrow properly when called interactively.
*Compatibility*
+ Dynamic blocks work with Org 9.7. ([[https://github.com/alphapapa/org-ql/issues/431][#431]]. Thanks to [[https://github.com/jezcope][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 [[https://github.com/alphapapa/org-ql/discussions/410][discussion]]. Thanks to [[https://github.com/al3xandru][Alex Popescu]] for reporting.)
+ Predicates ~ancestor~ and ~parent~ did not normalize their sub-queries, sometimes returning incorrect results. ([[https://github.com/alphapapa/org-ql/issues/365][#365]]. Thanks to [[https://github.com/kofm][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*
+ Command ~org-ql-find~ incorrectly moved point. (See [[https://github.com/alphapapa/org-ql/issues/380#issuecomment-1881913025][#380]]. Thanks to [[https://github.com/oantolin][Omar Antolín Camarena]] for reporting.)
** 0.8.2
*Fixes*
+ Command ~org-ql-find~ incorrectly restored the buffer after jumping when not using indirect buffers. (See [[https://github.com/alphapapa/org-ql/issues/380#issuecomment-1881913025][#380]]. Thanks to [[https://github.com/bram85][Bram Schoenmakers]] for reporting.)
** 0.8.1 ** 0.8.1
@ -1003,14 +925,6 @@ Tagged v0.6.2, fixing a compilation warning.
First tagged release. 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 [[https://github.com/alphapapa/org-ql/issues/409][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 [[mailto:assign@gnu.org][assign@gnu.org]] to request the appropriate form.
* Notes * Notes
:PROPERTIES: :PROPERTIES:
:TOC: :ignore this :TOC: :ignore this

View file

@ -2,8 +2,8 @@
;; Author: Adam Porter <adam@alphapapa.net> ;; Author: Adam Porter <adam@alphapapa.net>
;; URL: https://github.com/alphapapa/org-ql ;; URL: https://github.com/alphapapa/org-ql
;; Version: 0.6.2 ;; Version: 0.6.1
;; Package-Requires: ((emacs "26.1") (compat "29.1.4.5") (dash "2.18.1") (s "1.12.0") (helm-org "1.0") (org-ql "0.6-pre")) ;; Package-Requires: ((emacs "26.1") (dash "2.18.1") (s "1.12.0") (helm-org "1.0") (org-ql "0.6-pre"))
;;; Commentary: ;;; Commentary:
@ -35,7 +35,6 @@
(require 'cl-lib) (require 'cl-lib)
(require 'org) (require 'org)
(require 'compat)
(require 'dash) (require 'dash)
(require 's) (require 's)
@ -45,15 +44,6 @@
(require 'org-ql) (require 'org-ql)
(require 'org-ql-search) (require 'org-ql-search)
(declare-function org-ql--normalize-query "org-ql" t t)
;;;; Compatibility
(defalias 'helm-org-ql--show-entry
(if (version< org-version "9.6")
'org-show-entry
'org-fold-show-entry))
;;;; Variables ;;;; Variables
(defvar helm-org-ql-map (defvar helm-org-ql-map
@ -112,7 +102,7 @@ NAME is passed to `helm-org-ql-source', which see.
NOTE: Atoms in the query are turned into strings where NOTE: Atoms in the query are turned into strings where
appropriate, which makes it unnecessary to type quotation marks appropriate, which makes it unnecessary to type quotation marks
around words that are intended to be searched for as independent around words that are intended to be searched for as indepenent
strings. strings.
All query tokens are wrapped in the operator BOOLEAN (default All query tokens are wrapped in the operator BOOLEAN (default
@ -161,7 +151,7 @@ Is transformed into this query:
;; it to go to the previous heading. I don't know why it does that. ;; it to go to the previous heading. I don't know why it does that.
(switch-to-buffer (marker-buffer marker)) (switch-to-buffer (marker-buffer marker))
(goto-char marker) (goto-char marker)
(helm-org-ql--show-entry)) (org-show-entry))
(defun helm-org-ql-show-marker-indirect (marker) (defun helm-org-ql-show-marker-indirect (marker)
"Show heading at MARKER with `org-tree-to-indirect-buffer'." "Show heading at MARKER with `org-tree-to-indirect-buffer'."
@ -187,7 +177,7 @@ Is transformed into this query:
;;;###autoload ;;;###autoload
(cl-defun helm-org-ql-source (buffers-files &key (name "helm-org-ql")) (cl-defun helm-org-ql-source (buffers-files &key (name "helm-org-ql"))
"Return Helm source named NAME to search BUFFERS-FILES with `helm-org-ql'." "Return Helm source named NAME that searches BUFFERS-FILES with `helm-org-ql'."
;; Expansion of `helm-build-sync-source' macro. ;; Expansion of `helm-build-sync-source' macro.
(helm-make-source name 'helm-source-sync (helm-make-source name 'helm-source-sync
:candidates (lambda () :candidates (lambda ()
@ -211,7 +201,7 @@ Is transformed into this query:
(defun helm-org-ql--heading (window-width) (defun helm-org-ql--heading (window-width)
"Return string for Helm for heading at point. "Return string for Helm for heading at point.
WINDOW-WIDTH should be the width of the Helm window." WINDOW-WIDTH should be the width of the Helm window."
(font-lock-ensure (pos-bol) (pos-eol)) (font-lock-ensure (point-at-bol) (point-at-eol))
;; TODO: It would be better to avoid calculating the prefix and width ;; TODO: It would be better to avoid calculating the prefix and width
;; at each heading, but there's no easy way to do that once in each ;; at each heading, but there's no easy way to do that once in each
;; buffer, unless we manually called `org-ql' in each buffer, which ;; buffer, unless we manually called `org-ql' in each buffer, which

View file

@ -3,7 +3,7 @@
# * makem.sh --- Script to aid building and testing Emacs Lisp packages # * makem.sh --- Script to aid building and testing Emacs Lisp packages
# URL: https://github.com/alphapapa/makem.sh # URL: https://github.com/alphapapa/makem.sh
# Version: 0.7.1 # Version: 0.6-pre
# * Commentary: # * Commentary:
@ -112,12 +112,6 @@ Source files are automatically discovered from git, or may be
specified with options. Package dependencies are discovered from specified with options. Package dependencies are discovered from
"Package-Requires" headers in source files, from -pkg.el files, and "Package-Requires" headers in source files, from -pkg.el files, and
from a Cask file. from a Cask file.
Checkdoc's spell checker may not recognize some words, causing the
`lint-checkdoc' rule to fail. Custom words can be added in file-local
or directory-local variables using the variable
`ispell-buffer-session-localwords', which should be set to a list of
strings.
EOF EOF
} }
@ -183,7 +177,6 @@ function elisp-checkdoc-file {
(setq makem-checkdoc-errors-p t) (setq makem-checkdoc-errors-p t)
;; Return nil because we *are* generating a buffered list of errors. ;; Return nil because we *are* generating a buffered list of errors.
nil)))) nil))))
(put 'ispell-buffer-session-localwords 'safe-local-variable #'list-of-strings-p)
(mapcar #'checkdoc-file files) (mapcar #'checkdoc-file files)
(when makem-checkdoc-errors-p (when makem-checkdoc-errors-p
(kill-emacs 1)))) (kill-emacs 1))))
@ -307,6 +300,7 @@ function elisp-package-initialize-file {
(setq package-archives (list (cons "gnu" "https://elpa.gnu.org/packages/") (setq package-archives (list (cons "gnu" "https://elpa.gnu.org/packages/")
(cons "melpa" "https://melpa.org/packages/") (cons "melpa" "https://melpa.org/packages/")
(cons "melpa-stable" "https://stable.melpa.org/packages/"))) (cons "melpa-stable" "https://stable.melpa.org/packages/")))
$elisp_org_package_archive
(package-initialize) (package-initialize)
EOF EOF
echo $file echo $file
@ -385,36 +379,6 @@ function byte-compile-file {
# ** Files # ** Files
function submodules {
# Echo a list of submodules's paths relative to the repo root.
# TODO: Parse with bash regexp instead of cut.
git submodule status | awk '{print $2}'
}
function project-root {
# Echo the root of the project (or superproject, if running from
# within a submodule).
root_dir=$(git rev-parse --show-superproject-working-tree)
[[ $root_dir ]] || root_dir=$(git rev-parse --show-toplevel)
[[ $root_dir ]] || error "Can't find repo root."
echo "$root_dir"
}
function files-project {
# Echo a list of files in project; or with $1, files in it
# matching that pattern with "git ls-files". Excludes submodules.
[[ $1 ]] && pattern="/$1" || pattern="."
local excludes
for submodule in $(submodules)
do
excludes+=(":!:$submodule")
done
git ls-files -- "$pattern" "${excludes[@]}"
}
function dirs-project { function dirs-project {
# Echo list of directories to be used in load path. # Echo list of directories to be used in load path.
files-project-feature | dirnames files-project-feature | dirnames
@ -423,7 +387,7 @@ function dirs-project {
function files-project-elisp { function files-project-elisp {
# Echo list of Elisp files in project. # Echo list of Elisp files in project.
files-project 2>/dev/null \ git ls-files 2>/dev/null \
| egrep "\.el$" \ | egrep "\.el$" \
| filter-files-exclude-default \ | filter-files-exclude-default \
| filter-files-exclude-args | filter-files-exclude-args
@ -432,13 +396,13 @@ function files-project-elisp {
function files-project-feature { function files-project-feature {
# Echo list of Elisp files that are not tests and provide a feature. # Echo list of Elisp files that are not tests and provide a feature.
files-project-elisp \ files-project-elisp \
| grep -E -v "$test_files_regexp" \ | egrep -v "$test_files_regexp" \
| filter-files-feature | filter-files-feature
} }
function files-project-test { function files-project-test {
# Echo list of Elisp test files. # Echo list of Elisp test files.
files-project-elisp | grep -E "$test_files_regexp" files-project-elisp | egrep "$test_files_regexp"
} }
function dirnames { function dirnames {
@ -451,7 +415,7 @@ function dirnames {
function filter-files-exclude-default { function filter-files-exclude-default {
# Filter out paths (STDIN) which should be excluded by default. # Filter out paths (STDIN) which should be excluded by default.
grep -E -v "(/\.cask/|-autoloads\.el|\.dir-locals)" egrep -v "(/\.cask/|-autoloads.el|.dir-locals)"
} }
function filter-files-exclude-args { function filter-files-exclude-args {
@ -477,7 +441,7 @@ function filter-files-feature {
# Read paths on STDIN and echo ones that (provide 'a-feature). # Read paths on STDIN and echo ones that (provide 'a-feature).
while read path while read path
do do
grep -E "^\\(provide '" "$path" &>/dev/null \ egrep "^\\(provide '" "$path" &>/dev/null \
&& echo "$path" && echo "$path"
done done
} }
@ -525,7 +489,7 @@ function ert-tests-p {
function package-main-file { function package-main-file {
# Echo the package's main file. # Echo the package's main file.
file_pkg=$(files-project "*-pkg.el" 2>/dev/null) file_pkg=$(git ls-files ./*-pkg.el 2>/dev/null)
if [[ $file_pkg ]] if [[ $file_pkg ]]
then then
@ -548,23 +512,23 @@ function dependencies {
# Search package headers. Use -a so grep won't think that an Elisp file containing # Search package headers. Use -a so grep won't think that an Elisp file containing
# control characters (rare, but sometimes necessary) is binary and refuse to search it. # control characters (rare, but sometimes necessary) is binary and refuse to search it.
grep -E -a -i '^;; Package-Requires: ' $(files-project-feature) $(files-project-test) \ egrep -a -i '^;; Package-Requires: ' $(files-project-feature) $(files-project-test) \
| grep -E -o '\([^([:space:]][^)]*\)' \ | egrep -o '\([^([:space:]][^)]*\)' \
| grep -E -o '^[^[:space:])]+' \ | egrep -o '^[^[:space:])]+' \
| sed -r 's/\(//g' \ | sed -r 's/\(//g' \
| grep -E -v '^emacs$' # Ignore Emacs version requirement. | egrep -v '^emacs$' # Ignore Emacs version requirement.
# Search Cask file. # Search Cask file.
if [[ -r Cask ]] if [[ -r Cask ]]
then then
grep -E '\(depends-on "[^"]+"' Cask \ egrep '\(depends-on "[^"]+"' Cask \
| sed -r -e 's/\(depends-on "([^"]+)".*/\1/g' | sed -r -e 's/\(depends-on "([^"]+)".*/\1/g'
fi fi
# Search -pkg.el file. # Search -pkg.el file.
if [[ $(files-project "*-pkg.el" 2>/dev/null) ]] if [[ $(git ls-files ./*-pkg.el 2>/dev/null) ]]
then then
sed -nr 's/.*\(([-[:alnum:]]+)[[:blank:]]+"[.[:digit:]]+"\).*/\1/p' $(files-project- -- -pkg.el 2>/dev/null) sed -nr 's/.*\(([-[:alnum:]]+)[[:blank:]]+"[.[:digit:]]+"\).*/\1/p' $(git ls-files ./*-pkg.el 2>/dev/null)
fi fi
} }
@ -617,9 +581,6 @@ function sandbox {
local deps=($(dependencies)) local deps=($(dependencies))
debug "Installing dependencies: ${deps[@]}" debug "Installing dependencies: ${deps[@]}"
# Ensure built-in packages get upgraded to newer versions from ELPA.
args_sandbox_package_install+=(--eval "(setq package-install-upgrade-built-in t)")
for package in "${deps[@]}" for package in "${deps[@]}"
do do
args_sandbox_package_install+=(--eval "(package-install '$package)") args_sandbox_package_install+=(--eval "(package-install '$package)")
@ -1123,15 +1084,21 @@ args_package_archives=(
--eval "(add-to-list 'package-archives '(\"melpa\" . \"https://melpa.org/packages/\") t)" --eval "(add-to-list 'package-archives '(\"melpa\" . \"https://melpa.org/packages/\") t)"
) )
args_org_package_archives=(
--eval "(add-to-list 'package-archives '(\"org\" . \"https://orgmode.org/elpa/\") t)"
)
args_package_init=( args_package_init=(
--eval "(package-initialize)" --eval "(package-initialize)"
) )
elisp_org_package_archive="(add-to-list 'package-archives '(\"org\" . \"https://orgmode.org/elpa/\") t)"
# * Args # * Args
args=$(getopt -n "$0" \ args=$(getopt -n "$0" \
-o dhce:E:i:s::vf:C \ -o dhce:E:i:s::vf:CO \
-l compile-batch,exclude:,emacs:,install-deps,install-linters,debug,debug-load-path,help,install:,verbose,file:,no-color,no-compile,sandbox:: \ -l compile-batch,exclude:,emacs:,install-deps,install-linters,debug,debug-load-path,help,install:,verbose,file:,no-color,no-compile,no-org-repo,sandbox:: \
-- "$@") \ -- "$@") \
|| { usage; exit 1; } || { usage; exit 1; }
eval set -- "$args" eval set -- "$args"
@ -1195,6 +1162,9 @@ do
shift shift
args_files+=("$1") args_files+=("$1")
;; ;;
-O|--no-org-repo)
unset elisp_org_package_archive
;;
--no-color) --no-color)
unset color unset color
;; ;;
@ -1223,9 +1193,6 @@ paths_temp+=("$package_initialize_file")
trap cleanup EXIT INT TERM trap cleanup EXIT INT TERM
# Change to project root directory first.
cd "$(project-root)"
# Discover project files. # Discover project files.
files_project_feature=($(files-project-feature)) files_project_feature=($(files-project-feature))
files_project_test=($(files-project-test)) files_project_test=($(files-project-test))

View file

@ -26,9 +26,6 @@
(require 'org-ql) (require 'org-ql)
(declare-function org-ql-search "org-ql-search")
(declare-function org-ql--normalize-query "org-ql" t t)
;;;; Variables ;;;; Variables
(defvar-keymap org-ql-completing-read-map (defvar-keymap org-ql-completing-read-map
@ -50,10 +47,12 @@
:type 'boolean) :type 'boolean)
(defcustom org-ql-completing-read-snippet-function #'org-ql-completing-read--snippet-simple (defcustom org-ql-completing-read-snippet-function #'org-ql-completing-read--snippet-simple
;; TODO(v0.9): Performance of completion annotations seems to be ;; TODO: I'd like to make the -regexp one the default, but with
;; much improved now (whether due to changes in Emacs, Vertico, or ;; default Emacs completion affixation, it can sometimes be a bit
;; both, I don't know). It may be reasonable to make the context ;; slow, and I don't want that to be a user's first impression. It
;; snippet the default now. ;; may be possible to further optimize the -regexp one so that it
;; can be used by default. In the meantime, the -simple one seems
;; fast enough for general use.
"Function used to annotate results in `org-ql-completing-read'. "Function used to annotate results in `org-ql-completing-read'.
Function is called at entry beginning. (When set to Function is called at entry beginning. (When set to
`org-ql-completing-read--snippet-regexp', it is called with a `org-ql-completing-read--snippet-regexp', it is called with a
@ -107,13 +106,11 @@ value, or nil."
;; responsive as, e.g. Helm while typing, but it seems to ;; responsive as, e.g. Helm while typing, but it seems to
;; help a little when using the org-rifle-style snippets. ;; help a little when using the org-rifle-style snippets.
(org-with-point-at marker (org-with-point-at marker
(or (funcall org-ql-completing-read-snippet-function (or (funcall org-ql-completing-read-snippet-function)
org-ql-completing-read-input-regexp)
(org-ql-completing-read--snippet-simple)))) (org-ql-completing-read--snippet-simple))))
(`t ;; Interrupted: return nil (which can be concatted). (`t ;; Interrupted: return nil (which can be concatted).
nil) nil)
(else (propertize (concat " " else) (else else)))
'face 'org-ql-completing-read-snippet))))
(defun org-ql-completing-read-path (marker) (defun org-ql-completing-read-path (marker)
"Return formatted outline path for entry at MARKER." "Return formatted outline path for entry at MARKER."
@ -134,7 +131,7 @@ value, or nil."
;;;###autoload ;;;###autoload
(cl-defun org-ql-completing-read (cl-defun org-ql-completing-read
(buffers-files &key query-prefix query-filter narrowp (buffers-files &key query-prefix query-filter
(action #'org-ql-completing-read-action) (action #'org-ql-completing-read-action)
;; FIXME: Unused argument. ;; FIXME: Unused argument.
;; (annotate #'org-ql-completing-read-snippet) ;; (annotate #'org-ql-completing-read-snippet)
@ -145,8 +142,6 @@ value, or nil."
"Return marker at entry in BUFFERS-FILES selected with `org-ql'. "Return marker at entry in BUFFERS-FILES selected with `org-ql'.
PROMPT is shown to the user. PROMPT is shown to the user.
NARROWP is passed to `org-ql-select', which see.
QUERY-PREFIX may be a string to prepend to the query entered by QUERY-PREFIX may be a string to prepend to the query entered by
the user (e.g. use \"heading:\" to only search headings, easily the user (e.g. use \"heading:\" to only search headings, easily
creating a custom command that saves the user from having to type creating a custom command that saves the user from having to type
@ -219,7 +214,15 @@ single predicate)."
;; Using `while-no-input' here doesn't make it as responsive as, ;; Using `while-no-input' here doesn't make it as responsive as,
;; e.g. Helm while typing, but it seems to help a little when using the ;; e.g. Helm while typing, but it seems to help a little when using the
;; org-rifle-style snippets. ;; org-rifle-style snippets.
(or (funcall snippet (get-text-property 0 'org-marker candidate)) ""))) (or (snippet (get-text-property 0 'org-marker candidate)) "")))
(snippet (marker)
(when-let
((snippet
(org-with-point-at marker
(or (funcall org-ql-completing-read-snippet-function org-ql-completing-read-input-regexp)
(org-ql-completing-read--snippet-simple)))))
(propertize (concat " " snippet)
'face 'org-ql-completing-read-snippet)))
(group (candidate transform) (group (candidate transform)
(pcase transform (pcase transform
(`nil (buffer-name (marker-buffer (get-text-property 0 'org-marker candidate)))) (`nil (buffer-name (marker-buffer (get-text-property 0 'org-marker candidate))))
@ -317,7 +320,6 @@ single predicate)."
bow (or ,@query-tokens) (0+ (not space)) bow (or ,@query-tokens) (0+ (not space))
(optional (repeat 1 3 (0+ space) (repeat 1 15 (not space)))))))) (optional (repeat 1 3 (0+ space) (repeat 1 15 (not space))))))))
(org-ql-select buffers-files (org-ql--query-string-to-sexp input) (org-ql-select buffers-files (org-ql--query-string-to-sexp input)
:narrow narrowp
:action #'action)))) :action #'action))))
(unless (listp buffers-files) (unless (listp buffers-files)
;; Since we map across this argument, we ensure it's a list. ;; Since we map across this argument, we ensure it's a list.
@ -333,8 +335,7 @@ single predicate)."
;; `completing-read'. ;; `completing-read'.
(mapc #'org-ql--ensure-buffer buffers-files) (mapc #'org-ql--ensure-buffer buffers-files)
(let* ((completion-styles '(org-ql-completing-read)) (let* ((completion-styles '(org-ql-completing-read))
(completion-styles-alist (cons (list 'org-ql-completing-read #'try #'all "Org QL Find") (completion-styles-alist (list (list 'org-ql-completing-read #'try #'all "Org QL Find")))
completion-styles-alist))
(selected (selected
(minibuffer-with-setup-hook (minibuffer-with-setup-hook
(lambda () (lambda ()
@ -366,7 +367,7 @@ single predicate)."
(car (hash-table-values table)) (car (hash-table-values table))
(user-error "No results for input")))))) (user-error "No results for input"))))))
(defun org-ql-completing-read--snippet-simple (&optional _input-regexp) (defun org-ql-completing-read--snippet-simple ()
"Return a snippet of the current entry. "Return a snippet of the current entry.
Returns up to `org-ql-completing-read-snippet-length' characters." Returns up to `org-ql-completing-read-snippet-length' characters."
(save-excursion (save-excursion
@ -380,15 +381,15 @@ Returns up to `org-ql-completing-read-snippet-length' characters."
t t) t t)
50 nil nil t)))))) 50 nil nil t))))))
(defun org-ql-completing-read--snippet-regexp (&optional input-regexp) (defun org-ql-completing-read--snippet-regexp (regexp)
"Return a snippet of the current entry's matches for INPUT-REGEXP." "Return a snippet of the current entry's matches for REGEXP."
;; REGEXP may be nil if there are no qualifying tokens in the query. ;; REGEXP may be nil if there are no qualifying tokens in the query.
(when input-regexp (when regexp
(save-excursion (save-excursion
(org-end-of-meta-data t) (org-end-of-meta-data t)
(unless (org-at-heading-p) (unless (org-at-heading-p)
(let* ((end (org-entry-end-position)) (let* ((end (org-entry-end-position))
(snippets (cl-loop while (re-search-forward input-regexp end t) (snippets (cl-loop while (re-search-forward regexp end t)
concat (match-string 0) concat "" concat (match-string 0) concat ""
do (goto-char (match-end 0))))) do (goto-char (match-end 0)))))
(unless (string-empty-p snippets) (unless (string-empty-p snippets)

View file

@ -33,8 +33,6 @@
(require 'org-ql-search) (require 'org-ql-search)
(require 'org-ql-completing-read) (require 'org-ql-completing-read)
(declare-function org-ql--normalize-query "org-ql" t t)
;;;; Customization ;;;; Customization
(defgroup org-ql-find nil (defgroup org-ql-find nil
@ -54,18 +52,14 @@ See function `display-buffer'."
;;;; Commands ;;;; Commands
;;;###autoload ;;;###autoload
(cl-defun org-ql-find (buffers-files &key query-prefix query-filter widen (cl-defun org-ql-find (buffers-files &key query-prefix query-filter
(prompt "Find entry: ")) (prompt "Find entry: "))
"Go to an Org entry in BUFFERS-FILES selected by searching entries with `org-ql'. "Go to an Org entry in BUFFERS-FILES selected by searching entries with `org-ql'.
Interactively, search the buffers and files relevant to the Interactively, search the buffers and files relevant to the
current buffer (i.e. in `org-agenda-mode', the value of current buffer (i.e. in `org-agenda-mode', the value of
`org-ql-view-buffers-files' or `org-agenda-contributing-files'; `org-ql-view-buffers-files' or `org-agenda-contributing-files';
in `org-mode', that buffer). in `org-mode', that buffer). With universal prefix, select
multiple buffers to search with completion and PROMPT.
With one or more universal prefix arguments, WIDEN buffers before
searching (otherwise, respect any narrowing). With two universal
prefix arguments, select multiple buffers to search with
completion and PROMPT.
QUERY-PREFIX may be a string to prepend to the query (e.g. use QUERY-PREFIX may be a string to prepend to the query (e.g. use
\"heading:\" to only search headings, easily creating a custom \"heading:\" to only search headings, easily creating a custom
@ -76,35 +70,15 @@ types is filtered before execution (e.g. it could replace spaces
with commas to turn multiple tokens, which would normally be with commas to turn multiple tokens, which would normally be
treated as multiple predicates, into multiple arguments to a treated as multiple predicates, into multiple arguments to a
single predicate)." single predicate)."
(interactive (list (org-ql-find--buffers (interactive (list (org-ql-find--buffers)))
:read-buffer-p (equal '(16) current-prefix-arg)) (let ((marker (org-ql-completing-read buffers-files
:widen current-prefix-arg))
(let ((marker (save-restriction
(when (and widen (equal (current-buffer) buffers-files))
(widen))
(org-ql-completing-read buffers-files
:narrowp (not widen)
:query-prefix query-prefix :query-prefix query-prefix
:query-filter query-filter :query-filter query-filter
:prompt prompt)))) :prompt prompt)))
(set-buffer (or (buffer-base-buffer (marker-buffer marker)) (set-buffer (marker-buffer marker))
(marker-buffer marker)))
(pop-to-buffer (current-buffer) org-ql-find-display-buffer-action) (pop-to-buffer (current-buffer) org-ql-find-display-buffer-action)
(without-restriction (org-with-point-at marker
(goto-char marker) (run-hook-with-args 'org-ql-find-goto-hook))))
(run-hook-with-args 'org-ql-find-goto-hook))
(when (equal (current-buffer) (marker-buffer marker))
;; Ensure point is still within visible portion of buffer. (If
;; `org-tree-to-indirect-buffer' is used in `org-ql-find-goto-hook',
;; the buffer will have been changed and it won't matter; otherwise,
;; the buffer could have been narrowed to a region excluding the
;; selected entry.)
(let ((end-of-subtree (org-with-point-at marker
(org-end-of-subtree 'invisible-ok))))
(unless (and (<= (point-min) marker)
(>= (point-max) end-of-subtree))
(widen)
(goto-char marker))))))
;;;###autoload ;;;###autoload
(defun org-ql-refile (marker) (defun org-ql-refile (marker)
@ -122,8 +96,6 @@ which see (but only the files are used)."
((and (pred listp) files) files))) ((and (pred listp) files) files)))
(list files-spec))))))) (list files-spec)))))))
(list (org-ql-completing-read buffers-files :prompt "Refile to: ")))) (list (org-ql-completing-read buffers-files :prompt "Refile to: "))))
(let ((buffer (or (buffer-base-buffer (marker-buffer marker))
(marker-buffer marker))))
(org-refile nil nil (org-refile nil nil
;; The RFLOC argument: ;; The RFLOC argument:
(list (list
@ -131,11 +103,11 @@ which see (but only the files are used)."
(org-with-point-at marker (org-with-point-at marker
(nth 4 (org-heading-components))) (nth 4 (org-heading-components)))
;; File ;; File
(buffer-file-name buffer) (buffer-file-name (marker-buffer marker))
;; nil ;; nil
nil nil
;; Position ;; Position
marker)))) marker)))
;;;###autoload ;;;###autoload
(defun org-ql-find-in-agenda () (defun org-ql-find-in-agenda ()
@ -207,15 +179,15 @@ multiple buffers to search with completion and PROMPT."
;;;; Functions ;;;; Functions
(cl-defun org-ql-find--buffers (&key read-buffer-p) (defun org-ql-find--buffers ()
"Return buffer or list of buffers to search in. "Return list of buffers to search in.
In a mode derived from `org-agenda-mode', return the value of In a mode derived from `org-agenda-mode', return the value of
`org-ql-view-buffers-files' or `org-agenda-contributing-files'. `org-ql-view-buffers-files' or `org-agenda-contributing-files'.
In a mode derived from `org-mode', return the current buffer. If In a mode derived from `org-mode', return the current buffer.
READ-BUFFER-P, read a list of buffers in `org-mode' with When `current-prefix-arg', read a list of buffers in `org-mode'
completion. To be used in `org-ql-find' commands' interactive with completion. To be used in `org-ql-find' commands'
forms." interactive forms."
(if read-buffer-p (if current-prefix-arg
(mapcar #'get-buffer (mapcar #'get-buffer
(completing-read-multiple (completing-read-multiple
"Buffers: " "Buffers: "

View file

@ -40,8 +40,6 @@
(require 'org-ql) (require 'org-ql)
(require 'org-ql-view) (require 'org-ql-view)
(declare-function org-ql--normalize-query "org-ql" t t)
;;;; Compatibility ;;;; Compatibility
(defalias 'org-ql-search--link-heading-search-string (defalias 'org-ql-search--link-heading-search-string
@ -149,19 +147,20 @@ Runs `org-occur-hook' after making the sparse tree."
num-results))) num-results)))
;;;###autoload ;;;###autoload
(cl-defun org-ql-search (buffers-files query &key narrow super-groups sort title (cl-defun org-ql-search (in query &key narrow super-groups sort title
(buffer org-ql-view-buffer)) (buffer org-ql-view-buffer))
"Search for QUERY with `org-ql'. "Search for QUERY with `org-ql'.
Interactively, prompt for these variables: Interactively, prompt for these variables:
BUFFERS-FILES: A list of buffers and/or files to search. IN: Passed to `org-ql-select', which see. Interactively, may
Interactively, may also be: also be:
- `buffer': search the current buffer - `buffer': search the current buffer
- `all': search all Org buffers - `all': search all Org buffers
- `agenda': search buffers returned by the function `org-agenda-files' - `agenda': search buffers returned by the function
`org-agenda-files'
- `directory': search Org files in `org-directory' - `directory': search Org files in `org-directory'
- A space-separated list of file or buffer names - A space-separated list of file/buffer names or Org heading IDs
QUERY: An `org-ql' query in either sexp or non-sexp form (see QUERY: An `org-ql' query in either sexp or non-sexp form (see
Info node `(org-ql)Queries'). Info node `(org-ql)Queries').
@ -170,8 +169,9 @@ SUPER-GROUPS: An `org-super-agenda' group set. See variable
`org-super-agenda-groups' and Info node `(org-super-agenda)Group `org-super-agenda-groups' and Info node `(org-super-agenda)Group
selectors'. selectors'.
NARROW: When non-nil, don't widen buffers before NARROW: Passed to `org-ql-select', but set automatically when
searching. Interactively, with prefix, leave narrowed. called interactively based on the value of BUFFERS-FILES; the
user should not need to pass this argument.
SORT: One or a list of `org-ql' sorting functions, like `date' or SORT: One or a list of `org-ql' sorting functions, like `date' or
`priority' (see Info node `(org-ql)Listing / acting-on results'). `priority' (see Info node `(org-ql)Listing / acting-on results').
@ -183,12 +183,19 @@ display the results. By default, the value of
`org-ql-view-buffer' is used, and a new buffer is created if `org-ql-view-buffer' is used, and a new buffer is created if
necessary." necessary."
(declare (indent defun)) (declare (indent defun))
(interactive (list (org-ql-view--complete-buffers-files) (interactive
(read-string "Query: " (when org-ql-view-query (let* ((in (org-ql-view--complete-buffers-files))
(format "%S" org-ql-view-query))) (query (read-string "Query: " (when org-ql-view-query
:narrow (or org-ql-view-narrow (equal current-prefix-arg '(4))) (format "%S" org-ql-view-query))))
(narrow (if (equal in (current-buffer))
(or org-ql-view-narrow
(when (buffer-narrowed-p)
(setf in (or (org-id-get (point-min))
(copy-marker (point-min))))))
org-ql-view-narrow)))
(list in query :narrow narrow
:super-groups (org-ql-view--complete-super-groups) :super-groups (org-ql-view--complete-super-groups)
:sort (org-ql-view--complete-sort))) :sort (org-ql-view--complete-sort))))
;; NOTE: Using `with-temp-buffer' is a hack to work around the fact that `make-local-variable' ;; NOTE: Using `with-temp-buffer' is a hack to work around the fact that `make-local-variable'
;; does not work reliably from inside a `let' form when the target buffer is current on entry ;; does not work reliably from inside a `let' form when the target buffer is current on entry
;; to or exit from the `let', even though `make-local-variable' is actually done in ;; to or exit from the `let', even though `make-local-variable' is actually done in
@ -202,16 +209,16 @@ necessary."
;; Parse non-sexp query into sexp query. ;; Parse non-sexp query into sexp query.
(org-ql--query-string-to-sexp query))) (org-ql--query-string-to-sexp query)))
(list query))) (list query)))
(results (org-ql-select buffers-files query (results (org-ql-select in query
:action 'element-with-markers :action 'element-with-markers
:narrow narrow :narrow narrow
:sort sort)) :sort sort))
(strings (-map #'org-ql-view--format-element results)) (strings (-map #'org-ql-view--format-element results))
(buffer (or buffer (format "%s %s*" org-ql-view-buffer-name-prefix (or title query)))) (buffer (or buffer (format "%s %s*" org-ql-view-buffer-name-prefix (or title query))))
(header (org-ql-view--header-line-format (header (org-ql-view--header-line-format
:buffers-files buffers-files :query query :title title)) :buffers-files in :query query :title title))
;; Bind variables for `org-ql-view--display' to set. ;; Bind variables for `org-ql-view--display' to set.
(org-ql-view-buffers-files buffers-files) (org-ql-view-buffers-files in)
(org-ql-view-query query) (org-ql-view-query query)
(org-ql-view-sort sort) (org-ql-view-sort sort)
(org-ql-view-narrow narrow) (org-ql-view-narrow narrow)
@ -225,25 +232,19 @@ necessary."
(org-ql-view--display :buffer buffer :header header :strings strings)))) (org-ql-view--display :buffer buffer :header header :strings strings))))
;;;###autoload ;;;###autoload
(defun org-ql-search-block (args) (defun org-ql-search-block (query)
"Insert items for ARGS into current buffer. "Insert items for QUERY into current buffer.
Intended to be used as a user-defined function in QUERY should be an `org-ql' query form. Intended to be used as a
`org-agenda-custom-commands'. ARGS corresponds to the `match' user-defined function in `org-agenda-custom-commands'. QUERY
item in the custom command form. It should be a list of corresponds to the `match' item in the custom command form.
arguments which may be applied to `org-ql-select', which see, but
not including its BUFFERS-FILES argument (which is supplied
through the Agenda). An additional `:header' keyword argument
may be supplied as a string, like that supplied to
`org-ql-view--display'.
Like other agenda block commands, it searches files returned by Like other agenda block commands, it searches files returned by
function `org-agenda-files'. Inserts a newline after the block. function `org-agenda-files'. Inserts a newline after the block.
If `org-ql-block-header' is non-nil, it is used as the header If `org-ql-block-header' is non-nil, it is used as the header
string for the block, otherwise the header is formed string for the block, otherwise a the header is formed
automatically from the query." automatically from the query."
(pcase-let ((`(,query . ,(map :header :sort)) args) (let (narrow-p old-beg old-end)
(narrow-p) (old-beg) (old-end))
(when-let* ((from (pcase org-agenda-restrict (when-let* ((from (pcase org-agenda-restrict
('nil (org-agenda-files nil 'ifmode)) ('nil (org-agenda-files nil 'ifmode))
(_ (prog1 org-agenda-restrict (_ (prog1 org-agenda-restrict
@ -254,7 +255,7 @@ automatically from the query."
(narrow-to-region org-agenda-restrict-begin org-agenda-restrict-end)))))) (narrow-to-region org-agenda-restrict-begin org-agenda-restrict-end))))))
(items (org-ql-select from query (items (org-ql-select from query
:action 'element-with-markers :action 'element-with-markers
:narrow narrow-p :sort sort))) :narrow narrow-p)))
(when narrow-p (when narrow-p
;; Restore buffer's previous restrictions. ;; Restore buffer's previous restrictions.
(with-current-buffer from (with-current-buffer from
@ -264,25 +265,16 @@ automatically from the query."
;; FIXME: `org-agenda--insert-overriding-header' is from an Org version newer than ;; FIXME: `org-agenda--insert-overriding-header' is from an Org version newer than
;; I'm using. Should probably declare it as a minimum Org version after upgrading. ;; I'm using. Should probably declare it as a minimum Org version after upgrading.
;; (org-agenda--insert-overriding-header (or org-ql-block-header (org-ql-agenda--header-line-format from query))) ;; (org-agenda--insert-overriding-header (or org-ql-block-header (org-ql-agenda--header-line-format from query)))
;; FIXME: Should we really use `org-ql-block-header' AND `header', or just one of them? (insert (org-add-props (or org-ql-block-header (org-ql-view--header-line-format
(insert (org-add-props (or org-ql-block-header header
(org-ql-view--header-line-format
:buffers-files from :query query)) :buffers-files from :query query))
nil 'face 'org-agenda-structure) "\n") nil 'face 'org-agenda-structure) "\n")
;; Calling `org-agenda-finalize' should be unnecessary, because in a "series" agenda, ;; Calling `org-agenda-finalize' should be unnecessary, because in a "series" agenda,
;; `org-agenda-multi' is bound non-nil, in which case `org-agenda-finalize' does nothing. ;; `org-agenda-multi' is bound non-nil, in which case `org-agenda-finalize' does nothing.
;; But we do call `org-agenda-finalize-entries', which allows `org-super-agenda' to work. ;; But we do call `org-agenda-finalize-entries', which allows `org-super-agenda' to work.
;; However, `org-agenda-finalize-entries' sorts entries with `org-entries-lessp', which
;; overrides the sorting `org-ql' has already done, so we rebind `org-entries-lessp' to
;; prevent it from affecting sort order. (Ideally we would let `org-entries-lessp'
;; handle sorting, but that's not possible, because we can't add the `type' text property
;; it uses to sort entries, because the design of org-ql and org-agenda is fundamentally
;; different. So we have to do the sorting ourselves.)
(cl-letf (((symbol-function 'org-entries-lessp) #'ignore))
(->> items (->> items
(-map #'org-ql-view--format-element) (-map #'org-ql-view--format-element)
org-agenda-finalize-entries org-agenda-finalize-entries
insert)) insert)
(insert "\n")))) (insert "\n"))))
;;;###autoload ;;;###autoload
@ -363,8 +355,7 @@ this (must be a single line in the Org buffer):
(org-element-property (intern (concat ":" (upcase property))) element))))) (org-element-property (intern (concat ":" (upcase property))) element)))))
(elements (org-ql-query :from (current-buffer) (elements (org-ql-query :from (current-buffer)
:where query :where query
:select '(org-ql-view--resolve-element-properties :select '(org-element-headline-parser (line-end-position))
(org-element-headline-parser (line-end-position)))
:order-by sort))) :order-by sort)))
(when take (when take
(setf elements (cl-etypecase take (setf elements (cl-etypecase take

View file

@ -44,7 +44,6 @@
(declare-function org-ql-search "org-ql-search" t) (declare-function org-ql-search "org-ql-search" t)
(declare-function org-ql-search--org-link-store-props "org-ql-search" t) (declare-function org-ql-search--org-link-store-props "org-ql-search" t)
(declare-function org-ql--normalize-query "org-ql" t t)
(require 'dash) (require 'dash)
(require 's) (require 's)
@ -57,18 +56,7 @@
(defface org-ql-view-due-date (defface org-ql-view-due-date
'((t (:slant italic :weight bold))) '((t (:slant italic :weight bold)))
"Face for due dates in `org-ql-view' views." "Face for due dates in `org-ql-view' views."
:group 'org-ql-view) :group 'org-ql)
(defface org-ql-view-query nil
"View query in header line.
This face is added to the formatted query after font-lock faces
are applied to it. It may be used, e.g. to reduce the height so
more of it is visible."
:group 'org-ql-view)
(defface org-ql-view-title '((t :weight bold))
"View title in header line."
:group 'org-ql-view)
;;;; Variables ;;;; Variables
@ -249,12 +237,6 @@ See info node `(elisp)Cyclic Window Ordering'."
(sexp :tag "org-super-agenda grouping expression") (sexp :tag "org-super-agenda grouping expression")
(variable :tag "Variable holding org-super-agenda grouping expression")))))))) (variable :tag "Variable holding org-super-agenda grouping expression"))))))))
(defcustom org-ql-view-relative-deadline-prefix "due "
;; TODO(v0.9): Add one for scheduled, too.
"Prefix for relative deadlines.
Relative deadlines are, e.g. \"in 5d\", \"5d ago\"."
:type 'string)
;;;; Commands ;;;; Commands
;;;###autoload ;;;###autoload
@ -476,8 +458,7 @@ subsequent refreshing of the buffer: `org-ql-view-buffers-files',
If TITLE, prepend it to the header." If TITLE, prepend it to the header."
(let* ((title (if title (let* ((title (if title
(concat (propertize "View:" 'face 'transient-argument) (concat (propertize "View:" 'face 'transient-argument)
(propertize title 'face 'org-ql-view-title) title " ")
" ")
"")) ""))
(query-formatted (when query (query-formatted (when query
(org-ql-view--format-query query))) (org-ql-view--format-query query)))
@ -496,7 +477,6 @@ If TITLE, prepend it to the header."
(org-ql-view--font-lock-string 'emacs-lisp-mode) (org-ql-view--font-lock-string 'emacs-lisp-mode)
(s-truncate available-width)) (s-truncate available-width))
'help-echo buffers-files-formatted)))) 'help-echo buffers-files-formatted))))
(add-face-text-property 0 (length query-propertized) 'org-ql-view-query 'append query-propertized)
(concat title (concat title
(when query (propertize "Query:" 'face 'transient-argument)) (when query (propertize "Query:" 'face 'transient-argument))
(when query query-propertized) (when query query-propertized)
@ -528,22 +508,6 @@ with human-readable strings."
(font-lock-ensure) (font-lock-ensure)
(buffer-string)))) (buffer-string))))
(defun org-ql-view--font-lock-as-org (s)
"Return string S font-locked as in `org-mode'."
;; This works like `org-fontify-like-in-org-mode', but uses a single
;; buffer instead of a new one every time.
;; TODO(C): Submit these improvements upstream.
(let ((buffer (or (get-buffer " *org-ql-view--font-lock-as-org*")
(with-current-buffer (get-buffer-create " *org-ql-view--font-lock-as-org*")
(buffer-disable-undo)
(org-mode)
(current-buffer)))))
(with-current-buffer buffer
(insert s)
(font-lock-ensure)
(prog1 (buffer-string)
(erase-buffer)))))
(defun org-ql-view--buffer (&optional name) (defun org-ql-view--buffer (&optional name)
"Return `org-ql-view' buffer, creating it if necessary. "Return `org-ql-view' buffer, creating it if necessary.
If NAME is non-nil, return buffer by that name instead of using If NAME is non-nil, return buffer by that name instead of using
@ -586,7 +550,6 @@ dates in the past, and negative for dates in the future."
;; Replace buffers with their filenames, and signal error if any are not file-backed. ;; Replace buffers with their filenames, and signal error if any are not file-backed.
(setf plist (plist-put plist :buffers-files (setf plist (plist-put plist :buffers-files
(cl-etypecase buffers-files (cl-etypecase buffers-files
(symbol buffers-files)
(string buffers-files) (string buffers-files)
(buffer (file-nameize buffers-files)) (buffer (file-nameize buffers-files))
(list (mapcar #'file-nameize buffers-files))))) (list (mapcar #'file-nameize buffers-files)))))
@ -646,7 +609,6 @@ The optional, second argument is temporarily _IGNORED for
purposes of compatibility with changes in Org 9.4." purposes of compatibility with changes in Org 9.4."
(require 'url-parse) (require 'url-parse)
(require 'url-util) (require 'url-util)
(declare-function url-path-and-query "url-parse")
(when (version<= "9.3" (org-version)) (when (version<= "9.3" (org-version))
;; Org 9.3+ makes a backward-incompatible change to link escaping. ;; Org 9.3+ makes a backward-incompatible change to link escaping.
;; I don't think it would be a good idea to try to guess whether ;; I don't think it would be a good idea to try to guess whether
@ -661,7 +623,7 @@ purposes of compatibility with changes in Org 9.4."
(query (url-unhex-string query)) (query (url-unhex-string query))
(params (when params (url-parse-query-string params))) (params (when params (url-parse-query-string params)))
;; `url-parse-query-string' returns "improper" alists, which makes this awkward. ;; `url-parse-query-string' returns "improper" alists, which makes this awkward.
(sort (when-let* ((stored-string (car (alist-get "sort" params nil nil #'string=))) (sort (when-let* ((stored-string (alist-get "sort" params nil nil #'string=))
(read-value (read stored-string))) (read-value (read stored-string)))
;; Ensure the value is either a symbol or list of symbols (which excludes lambdas). ;; Ensure the value is either a symbol or list of symbols (which excludes lambdas).
(unless (or (symbolp read-value) (cl-every #'symbolp read-value)) (unless (or (symbolp read-value) (cl-every #'symbolp read-value))
@ -669,19 +631,17 @@ purposes of compatibility with changes in Org 9.4."
read-value)) read-value))
read-value)) read-value))
(org-super-agenda-allow-unsafe-groups nil) ; Disallow unsafe group selectors. (org-super-agenda-allow-unsafe-groups nil) ; Disallow unsafe group selectors.
(groups (--when-let (car (alist-get "super-groups" params nil nil #'string=)) (groups (--when-let (alist-get "super-groups" params nil nil #'string=)
(read it))) (read it)))
(title (--when-let (car (alist-get "title" params nil nil #'string=)) (title (--when-let (alist-get "title" params nil nil #'string=)
(read it))) (read it)))
(buffers-files (--if-let (car (alist-get "buffers-files" params nil nil #'string=)) (buffers-files (--if-let (alist-get "buffers-files" params nil nil #'string=)
(org-ql-view--expand-buffers-files (read it)) (org-ql-view--expand-buffers-files (read it))
(current-buffer)))) (current-buffer))))
(unless (or (bufferp buffers-files) (unless (or (bufferp buffers-files)
(stringp buffers-files) (stringp buffers-files)
(cl-every #'stringp buffers-files)) (cl-every #'stringp buffers-files))
(error "CAUTION: Link not opened because unsafe buffers-files parameter detected: %s" buffers-files)) (error "CAUTION: Link not opened because unsafe buffers-files parameter detected: %s" buffers-files))
(unless (or (stringp title) (null title))
(error "CAUTION: Link not opened because unsafe title parameter detected: %S" title))
(when (or (listp query) (when (or (listp query)
(string-match (rx bol (0+ space) "(") query)) (string-match (rx bol (0+ space) "(") query))
;; SAFETY: Query is in sexp form: ask for confirmation, because it could contain arbitrary code. ;; SAFETY: Query is in sexp form: ask for confirmation, because it could contain arbitrary code.
@ -750,8 +710,6 @@ When opened, the link searches the buffer it's opened from."
;; Transient manual is written very well, not everything is covered in ;; Transient manual is written very well, not everything is covered in
;; it, so I'm having to try to imitate examples from `magit-transient'. ;; it, so I'm having to try to imitate examples from `magit-transient'.
(require 'eieio-core)
(require 'transient) (require 'transient)
(defclass org-ql-view--variable (transient-variable) (defclass org-ql-view--variable (transient-variable)
@ -914,14 +872,8 @@ return an empty string."
;; (which would also make it easier to do it independently of faces, etc). ;; (which would also make it easier to do it independently of faces, etc).
(title (--> (org-ql-view--add-faces element) (title (--> (org-ql-view--add-faces element)
(org-element-property :raw-value it))) (org-element-property :raw-value it)))
;; TODO(B): Needs refactoring. A function like `org-ql-view--add-faces'
;; should return a list of faces to be added.
(title-faces (get-text-property 0 'face title))
(title (org-ql-view--font-lock-as-org title))
(_ (add-face-text-property 0 (length title) title-faces t title))
(todo-keyword (-some--> (org-element-property :todo-keyword element) (todo-keyword (-some--> (org-element-property :todo-keyword element)
(org-ql-view--add-todo-face (org-ql-view--add-todo-face it)))
(substring-no-properties it))))
(tag-list (if org-use-tag-inheritance (tag-list (if org-use-tag-inheritance
;; MAYBE: Use our own variable instead of `org-use-tag-inheritance'. ;; MAYBE: Use our own variable instead of `org-use-tag-inheritance'.
(if-let ((marker (or (org-element-property :org-hd-marker element) (if-let ((marker (or (org-element-property :org-hd-marker element)
@ -1056,9 +1008,7 @@ property."
(deadline-day-number (org-time-string-to-absolute (deadline-day-number (org-time-string-to-absolute
(org-element-timestamp-interpreter deadline-date 'ignore))) (org-element-timestamp-interpreter deadline-date 'ignore)))
(difference-days (- today-day-number deadline-day-number)) (difference-days (- today-day-number deadline-day-number))
(relative-due-date (org-add-props (relative-due-date (org-add-props (org-ql-view--format-relative-date difference-days) nil
(concat org-ql-view-relative-deadline-prefix
(org-ql-view--format-relative-date difference-days)) nil
'help-echo (org-element-property :raw-value deadline-date))) 'help-echo (org-element-property :raw-value deadline-date)))
;; FIXME: Unused for now: (todo-keyword (org-element-property :todo-keyword element)) ;; FIXME: Unused for now: (todo-keyword (org-element-property :todo-keyword element))
;; FIXME: Unused for now: (done-p (member todo-keyword org-done-keywords)) ;; FIXME: Unused for now: (done-p (member todo-keyword org-done-keywords))
@ -1094,38 +1044,60 @@ property."
(declare-function org-ql-search-directories-files "org-ql-search" t) (declare-function org-ql-search-directories-files "org-ql-search" t)
(defun org-ql-view--contract-buffers-files (buffers-files) (defun org-ql-view--contract-buffers-files (in)
"Return BUFFERS-FILES in its \"contracted\" form. "Return IN in its \"contracted\" form.
The contracted form is \"org-agenda-files\" if BUFFERS-FILES The contracted form is \"org-agenda-files\" if IN matches the
matches the value of `org-agenda-files' (either the function or value of `org-agenda-files' (either the function or the
the variable), \"org-directory\" if it matches the value of variable), \"org-directory\" if it matches the value of
`org-ql-search-directories-files', or \"buffer\" if it is the `org-ql-search-directories-files', or \"buffer\" if it is the
current buffer. Otherwise BUFFERS-FILES is returned unchanged." current buffer. Otherwise IN is returned unchanged."
;; Used in `org-ql-view--complete-buffers-files' and ;; Used in `org-ql-view--complete-buffers-files' and
;; `org-ql-view--header-line-format'. ;; `org-ql-view--header-line-format'.
(cl-labels ((expand-files (list) (cl-labels ((expand-elt (it)
(--map (cl-typecase it (cl-typecase it
(string (expand-file-name it)) (string (or (expanded it)
(otherwise it)) (location-of it)
list))) (error "Unknown expansion for %S" it)))
(marker (or (location-of it)
(error "Unknown location for %S" it)))
(otherwise it)))
(expanded (filename)
(when-let ((expanded (expand-file-name filename))
((file-readable-p expanded)))
expanded))
(location-of (place)
(when-let ((marker (cl-etypecase place
(marker place)
(string (org-id-find place 'marker))))
(heading (org-link-display-format (org-entry-get marker "ITEM"))))
(setf heading (if (string-empty-p heading)
place
(or (org-id-get marker)
(string-join (org-with-point-at marker
(org-get-outline-path t))
" ")))
;; FIXME: The help-echo gets overridden elsewhere.
heading (propertize heading 'help-echo (format "%s" place)))
(format "\"%s\" in %S"
heading (abbreviate-file-name (buffer-file-name (marker-buffer marker)))))))
;; TODO: Test this more exhaustively. ;; TODO: Test this more exhaustively.
(pcase buffers-files (pcase in
((pred listp) ((pred listp)
(pcase (expand-files buffers-files) (pcase (mapcar #'expand-elt in)
((pred (seq-set-equal-p (mapcar #'expand-file-name (org-agenda-files)))) ((pred (seq-set-equal-p (mapcar #'expand-file-name (org-agenda-files))))
"org-agenda-files") "org-agenda-files")
((and (guard (file-exists-p org-directory)) ((and (guard (file-exists-p org-directory))
(pred (seq-set-equal-p (org-ql-search-directories-files (pred (seq-set-equal-p (org-ql-search-directories-files
:directories (list org-directory))))) :directories (list org-directory)))))
"org-directory") "org-directory")
(_ buffers-files))) (_ in)))
((pred (equal (current-buffer))) ((pred (equal (current-buffer)))
"buffer") (buffer-name (current-buffer)))
((or 'org-agenda-files '(function org-agenda-files)) ((or 'org-agenda-files '(function org-agenda-files))
"org-agenda-files") "org-agenda-files")
((and (pred bufferp) (guard (buffer-file-name buffers-files))) ((and (pred bufferp) (guard (buffer-file-name in)))
(buffer-file-name buffers-files)) (buffer-file-name in))
(_ buffers-files)))) (_ (expand-elt in)))))
(defun org-ql-view--complete-buffers-files () (defun org-ql-view--complete-buffers-files ()
"Return value for `org-ql-view-buffers-files' using completion." "Return value for `org-ql-view-buffers-files' using completion."

215
org-ql.el
View file

@ -157,9 +157,10 @@ This list should not contain any duplicates."))
(defvar org-ql-regexp-part-ts-date (defvar org-ql-regexp-part-ts-date
(rx (repeat 4 digit) "-" (repeat 2 digit) "-" (repeat 2 digit) (rx (repeat 4 digit) "-" (repeat 2 digit) "-" (repeat 2 digit)
;; Day of week ;; Day of week
(optional " " (1+ (or alpha punct)))) (optional " " (1+ alpha)))
"Matches the inner, date part of an Org timestamp, both active and inactive. "Matches the inner, date part of an Org timestamp, both active and inactive.
Used to build other timestamp regexps.") Also matches optional day-of-week. Used to build other timestamp
regexps.")
(defvar org-ql-regexp-part-ts-repeaters (defvar org-ql-regexp-part-ts-repeaters
;; Repeaters (not sure if the colon is necessary, but it's in the org.el one) ;; Repeaters (not sure if the colon is necessary, but it's in the org.el one)
@ -169,8 +170,7 @@ Used to build other timestamp regexps.")
Includes leading space character.") Includes leading space character.")
(defvar org-ql-regexp-part-ts-time (defvar org-ql-regexp-part-ts-time
(rx " " (repeat 1 2 digit) ":" (repeat 2 digit) (rx " " (repeat 1 2 digit) ":" (repeat 2 digit))
(optional "-" (repeat 1 2 digit) ":" (repeat 2 digit)))
"Matches the inner, time part of an Org timestamp (i.e. HH:MM). "Matches the inner, time part of an Org timestamp (i.e. HH:MM).
Includes leading space character. Used to build other timestamp Includes leading space character. Used to build other timestamp
regexps.") regexps.")
@ -333,11 +333,12 @@ See Info node `(org-ql)Queries'."
(sxhash-equal (prin1-to-string args)))) (sxhash-equal (prin1-to-string args))))
;;;###autoload ;;;###autoload
(cl-defun org-ql-select (buffers-or-files query &key action narrow sort) (cl-defun org-ql-select (in query &key action narrow sort)
"Return items matching QUERY in BUFFERS-OR-FILES. "Return items matching QUERY in IN.
BUFFERS-OR-FILES is a file or buffer, a list of files and/or IN is a buffer, file, or Org entry ID string (i.e. findable with
buffers, or a function which returns such a list. `org-id-goto'), or a list of one or more of such items, or a
function which returns such a list.
QUERY is an `org-ql' query sexp (quoted, since this is a QUERY is an `org-ql' query sexp (quoted, since this is a
function). function).
@ -374,23 +375,27 @@ would appear first. In contrast, `(date reverse priority)' would
also present items with the highest priority first, but within also present items with the highest priority first, but within
each priority the newest items would appear first." each priority the newest items would appear first."
(declare (indent defun)) (declare (indent defun))
(-let* ((buffers (->> (cl-typecase buffers-or-files (-let* ((sources (->> (cl-typecase in
(null (list (current-buffer))) (null (list (current-buffer)))
(function (funcall buffers-or-files)) (list in)
(list buffers-or-files) (otherwise (list in)))
(otherwise (list buffers-or-files))) (--map (pcase-exhaustive it
(--map (cl-etypecase it ;; NOTE: This exhaustive pcase is essential to opening links
;; NOTE: This etypecase is essential to opening links safely, ;; safely, as it rejects, e.g. lambdas in the IN argument.
;; as it rejects, e.g. lambdas in the buffers-files argument. ((cl-type buffer) it)
(buffer it) ((cl-type marker) it)
(string (or (find-buffer-visiting it) ((and (cl-type string)
(pred file-readable-p))
(or (find-buffer-visiting it)
(when (file-readable-p it) (when (file-readable-p it)
;; It feels unintuitive that `find-file-noselect' returns
;; a buffer if the filename doesn't exist.
(find-file-noselect it)) (find-file-noselect it))
(display-warning 'org-ql-select (format "Can't open file: %s" it) :error))))) (display-warning 'org-ql-select (format "Can't open file: %s" it) :error)))
((cl-type string)
(org-id-find it 'marker))
((cl-type function)
(funcall it))))
;; Ignore special/hidden buffers. ;; Ignore special/hidden buffers.
(--remove (string-prefix-p " " (buffer-name it))))) (--remove (and (bufferp it) (string-prefix-p " " (buffer-name it))))))
(query (org-ql--normalize-query query)) (query (org-ql--normalize-query query))
((&plist :query :preamble :preamble-case-fold) (org-ql--query-preamble query)) ((&plist :query :preamble :preamble-case-fold) (org-ql--query-preamble query))
(predicate (org-ql--query-predicate query)) (predicate (org-ql--query-predicate query))
@ -414,6 +419,18 @@ each priority the newest items would appear first."
,action))) ,action)))
(_ (user-error "Invalid action form: %s" action)))) (_ (user-error "Invalid action form: %s" action))))
(org-ql--today (ts-now)) (org-ql--today (ts-now))
(select-in (lambda (it)
(let* ((marker)
(buffer (cl-etypecase it
(buffer it)
(marker (marker-buffer (setf marker it))))))
(with-current-buffer buffer
(unless (derived-mode-p 'org-mode)
(display-warning 'org-ql-select (format "Not an Org buffer: %s" (buffer-name)) :error))
(org-ql--select-cached :query query :preamble preamble
:preamble-case-fold preamble-case-fold
:predicate predicate :action action
:narrow (or marker narrow))))))
(items (let (orig-fns) (items (let (orig-fns)
(unwind-protect (unwind-protect
(progn (progn
@ -424,14 +441,8 @@ each priority the newest items would appear first."
(push (list :name name :fn (symbol-function name)) orig-fns) (push (list :name name :fn (symbol-function name)) orig-fns)
;; Temporarily set new function definition. ;; Temporarily set new function definition.
(fset name fn))) (fset name fn)))
;; Run query on buffers. ;; Collect results.
(->> buffers (-flatten-n 1 (mapcar select-in sources)))
(--map (with-current-buffer it
(unless (derived-mode-p 'org-mode)
(display-warning 'org-ql-select (format "Not an Org buffer: %s" (buffer-name)) :error))
(org-ql--select-cached :query query :preamble preamble :preamble-case-fold preamble-case-fold
:predicate predicate :action action :narrow narrow)))
(-flatten-n 1)))
(--each orig-fns (--each orig-fns
;; Restore original function mappings. ;; Restore original function mappings.
(-let (((&plist :name :fn) it)) (-let (((&plist :name :fn) it))
@ -466,8 +477,7 @@ are returned by this function. It may be:
- A function symbol. - A function symbol.
FROM corresponds to the `org-ql-select' argument BUFFERS-OR-FILES. FROM corresponds to the `org-ql-select' argument IN, which see.
It may be one or a list of file paths and/or buffers.
WHERE corresponds to the `org-ql-select' argument QUERY. It WHERE corresponds to the `org-ql-select' argument QUERY. It
should be an `org-ql' query sexp. should be an `org-ql' query sexp.
@ -491,10 +501,12 @@ NARROW corresponds to the `org-ql-select' argument NARROW."
;; The key must include the preamble, because some queries are replaced by ;; The key must include the preamble, because some queries are replaced by
;; the preamble, leaving a nil query, which would make the key ambiguous. ;; the preamble, leaving a nil query, which would make the key ambiguous.
(list :query query :preamble preamble :action action :preamble-case-fold preamble-case-fold (list :query query :preamble preamble :action action :preamble-case-fold preamble-case-fold
(if narrow :narrow (pcase-exhaustive narrow
;; Use bounds of narrowed portion of buffer. ((cl-type string) narrow)
(cons (point-min) (point-max)) ((cl-type marker) narrow)
nil)))) (`t ;; Use bounds of narrowed portion of buffer.
(cons (point-min) (point-max)))
(`nil nil)))))
(if-let* ((buffer-cache (gethash (current-buffer) org-ql-cache)) (if-let* ((buffer-cache (gethash (current-buffer) org-ql-cache))
(query-cache (cadr buffer-cache)) (query-cache (cadr buffer-cache))
(modified-tick (car buffer-cache)) (modified-tick (car buffer-cache))
@ -529,10 +541,18 @@ PREAMBLE-CASE-FOLD."
;; can't be used, so we do it manually (this is same as the equivalent `flet' expansion). ;; can't be used, so we do it manually (this is same as the equivalent `flet' expansion).
;; Mappings are stored in the variable because it allows predicates to be defined with a ;; Mappings are stored in the variable because it allows predicates to be defined with a
;; macro, which allows documentation to be easily generated for them. ;; macro, which allows documentation to be easily generated for them.
(let (old-restriction)
(save-excursion (save-excursion
(save-restriction (save-restriction
(unless narrow (pcase narrow
(widen)) ((cl-type marker)
(switch-to-buffer (marker-buffer narrow)) ;; Can change buffer!
(setf old-restriction (if (buffer-narrowed-p)
(cons (point-min) (point-max))
t))
(goto-char narrow)
(org-narrow-to-subtree))
(`nil (widen)))
(goto-char (point-min)) (goto-char (point-min))
(when (org-before-first-heading-p) (when (org-before-first-heading-p)
(outline-next-heading)) (outline-next-heading))
@ -546,6 +566,7 @@ PREAMBLE-CASE-FOLD."
nil) nil)
;; Find matching entries. ;; Find matching entries.
;; TODO: Bind `case-fold-search' around the preamble loop. ;; TODO: Bind `case-fold-search' around the preamble loop.
(unwind-protect
(cond (preamble (cl-loop while (let ((case-fold-search preamble-case-fold)) (cond (preamble (cl-loop while (let ((case-fold-search preamble-case-fold))
(re-search-forward preamble nil t)) (re-search-forward preamble nil t))
do (outline-back-to-heading 'invisible-ok) do (outline-back-to-heading 'invisible-ok)
@ -554,7 +575,10 @@ PREAMBLE-CASE-FOLD."
do (outline-next-heading))) do (outline-next-heading)))
(t (cl-loop when (funcall predicate) (t (cl-loop when (funcall predicate)
collect (funcall action) collect (funcall action)
while (outline-next-heading)))))))) while (outline-next-heading))))
(pcase old-restriction
(`t (widen))
(`(,start . ,end) (narrow-to-region start end)))))))))
;;;;; Helpers ;;;;; Helpers
@ -1118,10 +1142,7 @@ defined in `org-ql-predicates' by calling `org-ql-defpred'."
;; Only one preamble is allowed ;; Only one preamble is allowed
element) element)
(pcase element (pcase element
(`(or ,element) (`(or _) element)
;; A predicate with a single name: unwrap the OR. (Pcase doesn't like
;; "one-armed ORs", giving a "Please avoid it" compilation error.)
element)
,@preamble-patterns ,@preamble-patterns
@ -1144,7 +1165,7 @@ defined in `org-ql-predicates' by calling `org-ql-defpred'."
(byte-compile 'org-ql--query-preamble))) (byte-compile 'org-ql--query-preamble)))
(cl-defmacro org-ql-defpred (name args docstring &key body preambles normalizers coalesce) (cl-defmacro org-ql-defpred (name args docstring &key body preambles normalizers coalesce)
"Define an Org QL selector predicate \\=`org-ql--predicate-NAME'. "Define an \\+`org-ql' selector predicate \\=`org-ql--predicate-NAME'.
NAME may be a symbol or a list of symbols: if a list, the first 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 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 created for NAME, not for aliases, so a normalizer should be used
@ -1229,7 +1250,7 @@ Then if NORMALIZERS were:
It would be expanded to: It would be expanded to:
((\\=`(,(or \\='heading \\='h) . ,args) ((\\=`(,(or 'heading 'h) . ,args)
\\=`(heading ,@args)))" \\=`(heading ,@args)))"
;; FIXME: Update defpred tutorial to include :coalesce. ;; FIXME: Update defpred tutorial to include :coalesce.
@ -1464,16 +1485,40 @@ Org effort string, like \"5\" or \"0:05\"."
(list :regexp (rx bol (0+ space) ":STYLE:" (1+ space) "habit" (0+ space) eol)))) (list :regexp (rx bol (0+ space) ":STYLE:" (1+ space) "habit" (0+ space) eol))))
:body (org-is-habit-p)) :body (org-is-habit-p))
(org-ql-defpred (heading h) (&rest _strings) (org-ql-defpred (heading h) (&rest strings)
"Return non-nil if current entry's heading matches all STRINGS. "Return non-nil if current entry's heading matches all STRINGS.
Matching is done case-insensitively." Matching is done case-insensitively."
:coalesce t :coalesce t
:normalizers ((`(,predicate-names . ,args) :normalizers ((`(,predicate-names . ,args)
;; NOTE: Each string argument must be converted to a regexp ;; "h" alias.
;; for testing by the body, so we just normalize to the `(heading ,@args)))
;; `heading-regexp' predicate, leaving this predicate as ;; TODO: Adjust regexp to avoid matching in tag list.
;; one that merely regexp-quotes its arguments. :preambles ((`(,predicate-names)
`(heading-regexp ,@(mapcar #'regexp-quote args))))) ;; This clause protects against the case in which the
;; arguments are nil, which would cause an error in
;; `rx-to-string' in other clauses. This can happen
;; with `org-ql-completing-read', e.g. when the input
;; is "h:" while the user is typing.
(list :regexp (rx bol (1+ "*") (1+ blank) (0+ nonl))
:case-fold t :query query))
(`(,predicate-names ,string)
;; Only one string: match with preamble, then let predicate confirm (because
;; the match could be in e.g. the tags rather than the heading text).
(list :regexp (rx-to-string `(seq bol (1+ "*") (1+ blank) (0+ nonl)
,string)
'no-group)
:case-fold t :query query))
(`(,predicate-names . ,strings)
;; Multiple strings: use preamble to match against first
;; string, then let the predicate match the rest.
(list :regexp (rx-to-string `(seq bol (1+ "*") (1+ blank) (0+ nonl)
,(car strings))
'no-group)
:case-fold t :query query)))
;; TODO: In Org 9.2+, `org-get-heading' takes 2 more arguments.
:body (let ((heading (org-get-heading 'no-tags 'no-todo))
(case-fold-search t))
(--all? (string-match it heading) strings)))
(org-ql-defpred (heading-regexp h*) (&rest regexps) (org-ql-defpred (heading-regexp h*) (&rest regexps)
"Return non-nil if current entry's heading matches all REGEXPS (regexp strings). "Return non-nil if current entry's heading matches all REGEXPS (regexp strings).
@ -1537,8 +1582,7 @@ COMPARATOR may be `<', `<=', `>', or `>='."
;; is "h:" while the user is typing. ;; is "h:" while the user is typing.
(list :regexp (rx bol (1+ "*") " ") (list :regexp (rx bol (1+ "*") " ")
:case-fold t)) :case-fold t))
((and `(,predicate-names ,comparator-or-num ,num) (`(,predicate-names ,comparator-or-num ,num)
(guard (numberp num)))
(let ((repeat (pcase comparator-or-num (let ((repeat (pcase comparator-or-num
('< `(repeat 1 ,(1- num) "*")) ('< `(repeat 1 ,(1- num) "*"))
('<= `(repeat 1 ,num "*")) ('<= `(repeat 1 ,num "*"))
@ -1547,8 +1591,7 @@ COMPARATOR may be `<', `<=', `>', or `>='."
((pred integerp) `(repeat ,comparator-or-num ,num "*"))))) ((pred integerp) `(repeat ,comparator-or-num ,num "*")))))
(list :regexp (rx-to-string `(seq bol ,repeat " ") t) (list :regexp (rx-to-string `(seq bol ,repeat " ") t)
:case-fold t))) :case-fold t)))
((and `(,predicate-names ,num) (`(,predicate-names ,num)
(guard (numberp num)))
(list :regexp (rx-to-string `(seq bol (repeat ,num "*") " ") t) (list :regexp (rx-to-string `(seq bol (repeat ,num "*") " ") t)
:case-fold t))) :case-fold t)))
;; NOTE: It might be necessary to take into account `org-odd-levels'; see docstring for ;; NOTE: It might be necessary to take into account `org-odd-levels'; see docstring for
@ -1626,15 +1669,11 @@ any link is found."
(or (null description) (or (null description)
(string-match-p description (match-string org-ql-link-description-group))))) (string-match-p description (match-string org-ql-link-description-group)))))
(_ (if (and description target) (_ (if (and description target)
(and (and (match-string 1) (and (string-match-p target (match-string 1))
(string-match-p target (match-string 1))) (string-match-p description (match-string org-ql-link-description-group)))
(and (match-string org-ql-link-description-group) (or (string-match-p description-or-target (match-string 1))
(string-match-p description (match-string org-ql-link-description-group))))
(or (and (match-string 1)
(string-match-p description-or-target (match-string 1)))
(and (match-string org-ql-link-description-group)
(string-match-p description-or-target (string-match-p description-or-target
(match-string org-ql-link-description-group)))))))))) (match-string org-ql-link-description-group)))))))))
(org-ql-defpred (rifle smart) (&rest strings) (org-ql-defpred (rifle smart) (&rest strings)
"Return non-nil if each of strings is found in the entry or its outline path. "Return non-nil if each of strings is found in the entry or its outline path.
@ -1808,24 +1847,7 @@ interpreted as nil or non-nil)."
;; predicate test for whether an entry has local ;; predicate test for whether an entry has local
;; properties when no arguments are given. ;; properties when no arguments are given.
(list 'property "")) (list 'property ""))
(`(,predicate-names ,property) (`(,predicate-names ,property ,value . ,plist)
;; Convert keyword property arguments to strings. Non-sexp
;; queries result in keyword property arguments (because to do
;; otherwise would require ugly special-casing in the parsing).
(when (keywordp property)
(setf property (substring (symbol-name property) 1)))
(list 'property property))
(`(,predicate-names ,property . ,rest)
(pcase rest
(`(,value)
;; Convert keyword property arguments to strings. Non-sexp
;; queries result in keyword property arguments (because to do
;; otherwise would require ugly special-casing in the parsing).
(when (keywordp property)
(setf property (substring (symbol-name property) 1)))
(list 'property property value))
((and `(,value . ,plist)
(guard (not (keywordp value))))
;; Convert keyword property arguments to strings. Non-sexp ;; Convert keyword property arguments to strings. Non-sexp
;; queries result in keyword property arguments (because to do ;; queries result in keyword property arguments (because to do
;; otherwise would require ugly special-casing in the parsing). ;; otherwise would require ugly special-casing in the parsing).
@ -1834,36 +1856,25 @@ interpreted as nil or non-nil)."
(list 'property property value (list 'property property value
:inherit (cond ((plist-member plist :inherit) (plist-get plist :inherit)) :inherit (cond ((plist-member plist :inherit) (plist-get plist :inherit))
((listp org-use-property-inheritance) ''selective) ((listp org-use-property-inheritance) ''selective)
(t org-use-property-inheritance)))) (t org-use-property-inheritance)))))
((and plist (guard (keywordp (car rest))))
;; Convert keyword property arguments to strings. Non-sexp
;; queries result in keyword property arguments (because to do
;; otherwise would require ugly special-casing in the parsing).
(when (keywordp property)
(setf property (substring (symbol-name property) 1)))
(list 'property property nil
:inherit (cond ((plist-member plist :inherit) (plist-get plist :inherit))
((listp org-use-property-inheritance) ''selective)
(t org-use-property-inheritance)))))))
;; MAYBE: Should case folding be disabled for properties? What about values? ;; MAYBE: Should case folding be disabled for properties? What about values?
;; MAYBE: Support (property) without args. ;; MAYBE: Support (property) without args.
;; NOTE: When inheritance is enabled, the preamble can't be used, ;; NOTE: When inheritance is enabled, the preamble can't be used,
;; which will make the search slower. ;; which will make the search slower.
:preambles (((and `(,predicate-names ,property ,value) :preambles ((`(,predicate-names ,property ,value . ,(map :inherit))
(guard (atom value)))
;; We do NOT return nil, because the predicate still needs to be tested, ;; We do NOT return nil, because the predicate still needs to be tested,
;; because the regexp could match a string not inside a property drawer. ;; because the regexp could match a string not inside a property drawer.
(list :regexp (rx-to-string `(seq bol (0+ space) ":" ,property ":" (list :regexp (unless inherit
(1+ space) ,value (0+ space) eol)) (rx-to-string `(seq bol (0+ space) ":" ,property ":"
(1+ space) ,value (0+ space) eol)))
:query query)) :query query))
((and `(,predicate-names ,property ,value . ,plist) (`(,predicate-names ,property . ,(map :inherit))
(guard (keywordp (car plist)))) ;; We do NOT return nil, because the predicate still needs to be tested,
;; WE do NOT return nil, because the predicate still needs to be tested,
;; because the regexp could match a string not inside a property drawer. ;; because the regexp could match a string not inside a property drawer.
;; NOTE: The preamble only matches if there appears to be a value. ;; NOTE: The preamble only matches if there appears to be a value.
;; A line like ":ID: " without any other text does not match. ;; A line like ":ID: " without any other text does not match.
(list :regexp (unless (plist-get plist :inherit) (list :regexp (unless inherit
(rx-to-string `(seq bol (0+ space) ":" ,property ":" (1+ space) (rx-to-string `(seq bol (0+ space) ":" ,property ":" (1+ space)
(minimal-match (1+ not-newline)) eol))) (minimal-match (1+ not-newline)) eol)))
:query query))) :query query)))
@ -1875,7 +1886,7 @@ interpreted as nil or non-nil)."
;; Check that PROPERTY exists ;; Check that PROPERTY exists
(org-ql--value-at (org-ql--value-at
(point) (lambda () (point) (lambda ()
(org-entry-get (point) property inherit)))) (org-entry-get (point) property))))
(_ (_
;; Check that PROPERTY has VALUE. ;; Check that PROPERTY has VALUE.
@ -2114,7 +2125,7 @@ With KEYWORDS, return non-nil if its keyword is one of KEYWORDS."
:normalizers ((`(,predicate-names :normalizers ((`(,predicate-names
;; Avoid infinitely compiling already-compiled functions. ;; Avoid infinitely compiling already-compiled functions.
,(and query (guard (not (byte-code-function-p query))))) ,(and query (guard (not (byte-code-function-p query)))))
`(ancestors ,(org-ql--query-predicate (org-ql--normalize-query query)))) `(ancestors ,(org-ql--query-predicate (rec query))))
(`(,predicate-names) '(ancestors (lambda () t)))) (`(,predicate-names) '(ancestors (lambda () t))))
:body :body
(org-with-wide-buffer (org-with-wide-buffer
@ -2126,7 +2137,7 @@ With KEYWORDS, return non-nil if its keyword is one of KEYWORDS."
:normalizers ((`(,predicate-names :normalizers ((`(,predicate-names
;; Avoid infinitely compiling already-compiled functions. ;; Avoid infinitely compiling already-compiled functions.
,(and query (guard (not (byte-code-function-p query))))) ,(and query (guard (not (byte-code-function-p query)))))
`(parent ,(org-ql--query-predicate (org-ql--normalize-query query)))) `(parent ,(org-ql--query-predicate (rec query))))
(`(,predicate-names) '(parent (lambda () t)))) (`(,predicate-names) '(parent (lambda () t))))
:body :body
(org-with-wide-buffer (org-with-wide-buffer

View file

@ -26,7 +26,6 @@ and saved views.
* Installation:: * Installation::
* Usage:: * Usage::
* Changelog:: * Changelog::
* Development::
* Notes:: * Notes::
* License:: * License::
@ -74,15 +73,6 @@ Functions / Macros
Changelog Changelog
* 0.9-pre: 09-pre. * 0.9-pre: 09-pre.
* 0.8.10: 0810.
* 0.8.9: 089.
* 0.8.8: 088.
* 0.8.7: 087.
* 0.8.6: 086.
* 0.8.5: 085.
* 0.8.4: 084.
* 0.8.3: 083.
* 0.8.2: 082.
* 0.8.1: 081. * 0.8.1: 081.
* 0.8: 08. * 0.8: 08.
* 0.7.4: 074. * 0.7.4: 074.
@ -116,14 +106,6 @@ Changelog
* 0.2: 02. * 0.2: 02.
* 0.1: 01. * 0.1: 01.
0.9-pre
* helm-org-ql: helm-org-ql (1).
Development
* Copyright assignment::
Notes Notes
* Comparison with Org Agenda searches:: * Comparison with Org Agenda searches::
@ -136,7 +118,7 @@ File: README.info, Node: Contents, Next: Screenshots, Prev: Top, Up: Top
1 Contents 1 Contents
********** **********
• • • • • • • •
 
File: README.info, Node: Screenshots, Next: Installation, Prev: Contents, Up: Top File: README.info, Node: Screenshots, Next: Installation, Prev: Contents, Up: Top
@ -1035,7 +1017,7 @@ File: README.info, Node: Tips, Prev: Links, Up: Usage
(https://github.com/alphapapa/burly.el). (https://github.com/alphapapa/burly.el).
 
File: README.info, Node: Changelog, Next: Development, Prev: Usage, Up: Top File: README.info, Node: Changelog, Next: Notes, Prev: Usage, Up: Top
5 Changelog 5 Changelog
*********** ***********
@ -1049,15 +1031,6 @@ releases.
* Menu: * Menu:
* 0.9-pre: 09-pre. * 0.9-pre: 09-pre.
* 0.8.10: 0810.
* 0.8.9: 089.
* 0.8.8: 088.
* 0.8.7: 087.
* 0.8.6: 086.
* 0.8.5: 085.
* 0.8.4: 084.
* 0.8.3: 083.
* 0.8.2: 082.
* 0.8.1: 081. * 0.8.1: 081.
* 0.8: 08. * 0.8: 08.
* 0.7.4: 074. * 0.7.4: 074.
@ -1092,206 +1065,19 @@ releases.
* 0.1: 01. * 0.1: 01.
 
File: README.info, Node: 09-pre, Next: 0810, Up: Changelog File: README.info, Node: 09-pre, Next: 081, Up: Changelog
5.1 0.9-pre 5.1 0.9-pre
=========== ===========
*Additions* Nothing new yet.
• Face org-ql-view-query, applied to view queries in header line.
• Face org-ql-view-title, applied to view titles in header line.
• Option org-ql-view-relative-deadline-prefix.
*Changes*
• Command org-ql-find respects narrowing of the current buffer by
default, allowing searching within the narrowed region. (Using one
C-u argument widens the current buffer, and using two C-u
arguments prompts for the buffers to search.)
• Function org-ql-completing-read accepts a new NARROWP argument,
which is passed to org-ql-select.
*Fixes*
• Customization group for face org-ql-view-due-date.
• Apply Org syntax font-locking to items in org-ql-view buffers.
* Menu:
* helm-org-ql: helm-org-ql (1).
 
File: README.info, Node: helm-org-ql (1), Up: 09-pre File: README.info, Node: 081, Next: 08, Prev: 09-pre, Up: Changelog
5.1.1 helm-org-ql 5.2 0.8.1
-----------------
Tagged v0.6.2, fixing a compilation warning.

File: README.info, Node: 0810, Next: 089, Prev: 09-pre, Up: Changelog
5.2 0.8.10
==========
*Fixes*
• Command org-ql-refile uses the base buffer when refiling to an
indirect buffer. (#466
(https://github.com/alphapapa/org-ql/issues/466).)
• Predicate link could signal an error when searching text that is
mistakenly recognized as an Org link (e.g. Bash double-bracket
constructs in a source block). (Thanks to John Wiegley
(https://github.com/jwiegley) for reporting.)

File: README.info, Node: 089, Next: 088, Prev: 0810, Up: Changelog
5.3 0.8.9
========= =========
*Fixes*
• Predicate property when called with argument form (property
"PROPERTY-NAME" :inherit t). (#460
(https://github.com/alphapapa/org-ql/issues/460). Thanks to
Stewmath (https://github.com/Stewmath) for reporting.)
• Predicate levels preamble optimizer allows expressions in place
of the numeric argument. (See #460
(https://github.com/alphapapa/org-ql/issues/460). Thanks to
Stewmath (https://github.com/Stewmath) for reporting.)
• Reading of view settings from Org links in upcoming Emacs version.
(#461 (https://github.com/alphapapa/org-ql/issues/461). Thanks to
Ola Nilsson (https://github.com/snogge) for help debugging, and for
maintaining Buttercup
(https://github.com/jorgenschaefer/emacs-buttercup).)
*Compatibility*
• Fix compilation error on Emacs 30. (#433
(https://github.com/alphapapa/org-ql/issues/433). Thanks to Akira
Komamura (https://github.com/akirak) and Stefan Monnier
(https://github.com/monnier).)

File: README.info, Node: 088, Next: 087, Prev: 089, Up: Changelog
5.4 0.8.8
=========
*Fixes*
• Remove text properties from to-do keywords before displaying them
in an org-ql-view buffer. (Such text properties could cause them
to, e.g. display with extra leading spaces, depending on which
other modes might be enabled in the source Org buffer.)
• Binding of completion-styles-alist in org-ql-completing-read.
(This fixes compatibility with Helms helm completion style, as
well as default Emacs completion in recursive minibuffers. #337
(https://github.com/alphapapa/org-ql/issues/337). Thanks to
Nicholas Vollmer (https://github.com/progfolio), viz
(https://github.com/9viz), and Karthik Chikmagalur
(https://github.com/karthink) for reporting and suggesting fixes.)
• Use of the context snippet function for org-ql-completing-read.
(#419 (https://github.com/alphapapa/org-ql/issues/419). Thanks to
tpeacock19 (https://github.com/tpeacock19) for reporting.)

File: README.info, Node: 087, Next: 086, Prev: 088, Up: Changelog
5.5 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
(https://github.com/alphapapa/org-ql/pull/237) and #371
(https://github.com/alphapapa/org-ql/issues/371). Thanks to Ihor
Radchenko (https://github.com/yantar92).)
• Timestamps with day-of-the-week abbreviations are matched more
flexibly (allowing, e.g. a period in French locales). (See #429
(https://github.com/alphapapa/org-ql/discussions/429), #432
(https://github.com/alphapapa/org-ql/issues/432). Thanks to
Florian D. (https://github.com/neurolit) for reporting.)
• Command org-ql-search did not narrow properly when called
interactively.
*Compatibility*
• Dynamic blocks work with Org 9.7. (#431
(https://github.com/alphapapa/org-ql/issues/431). Thanks to Jez
Cope (https://github.com/jezcope) for reporting.)

File: README.info, Node: 086, Next: 085, Prev: 087, Up: Changelog
5.6 0.8.6
=========
*Fixes*
• Bookmarking org-ql-view buffers when the buffers-files argument
is a symbol (like org-agenda-files).

File: README.info, Node: 085, Next: 084, Prev: 086, Up: Changelog
5.7 0.8.5
=========
*Fixes*
• Predicate heading incorrectly matched strings as regular
expressions, sometimes returning incorrect results. (See
discussion (https://github.com/alphapapa/org-ql/discussions/410).
Thanks to Alex Popescu (https://github.com/al3xandru) for
reporting.)
• Predicates ancestor and parent did not normalize their
sub-queries, sometimes returning incorrect results. (#365
(https://github.com/alphapapa/org-ql/issues/365). Thanks to
Gabriele Mongiano (https://github.com/kofm) for reporting.)

File: README.info, Node: 084, Next: 083, Prev: 085, Up: Changelog
5.8 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).

File: README.info, Node: 083, Next: 082, Prev: 084, Up: Changelog
5.9 0.8.3
=========
*Fixes*
• Command org-ql-find incorrectly moved point. (See #380
(https://github.com/alphapapa/org-ql/issues/380#issuecomment-1881913025).
Thanks to Omar Antolín Camarena (https://github.com/oantolin) for
reporting.)

File: README.info, Node: 082, Next: 081, Prev: 083, Up: Changelog
5.10 0.8.2
==========
*Fixes*
• Command org-ql-find incorrectly restored the buffer after jumping
when not using indirect buffers. (See #380
(https://github.com/alphapapa/org-ql/issues/380#issuecomment-1881913025).
Thanks to Bram Schoenmakers (https://github.com/bram85) for
reporting.)

File: README.info, Node: 081, Next: 08, Prev: 082, Up: Changelog
5.11 0.8.1
==========
*Fixes* *Fixes*
• Command org-ql-find widens the buffer before going to the • Command org-ql-find widens the buffer before going to the
@ -1304,8 +1090,8 @@ File: README.info, Node: 081, Next: 08, Prev: 082, Up: Changelog
 
File: README.info, Node: 08, Next: 074, Prev: 081, Up: Changelog File: README.info, Node: 08, Next: 074, Prev: 081, Up: Changelog
5.12 0.8 5.3 0.8
======== =======
*Additions* *Additions*
@ -1360,8 +1146,8 @@ File: README.info, Node: 08, Next: 074, Prev: 081, Up: Changelog
 
File: README.info, Node: 074, Next: 073, Prev: 08, Up: Changelog File: README.info, Node: 074, Next: 073, Prev: 08, Up: Changelog
5.13 0.7.4 5.4 0.7.4
========== =========
*Fixes* *Fixes*
• Ignore empty quoted strings in plain-string queries (#383 • Ignore empty quoted strings in plain-string queries (#383
@ -1370,8 +1156,8 @@ File: README.info, Node: 074, Next: 073, Prev: 08, Up: Changelog
 
File: README.info, Node: 073, Next: 072, Prev: 074, Up: Changelog File: README.info, Node: 073, Next: 072, Prev: 074, Up: Changelog
5.14 0.7.3 5.5 0.7.3
========== =========
*Fixes* *Fixes*
• Disable case-fold-search when collecting headings in outline • Disable case-fold-search when collecting headings in outline
@ -1388,8 +1174,8 @@ File: README.info, Node: 073, Next: 072, Prev: 074, Up: Changelog
 
File: README.info, Node: 072, Next: 071, Prev: 073, Up: Changelog File: README.info, Node: 072, Next: 071, Prev: 073, Up: Changelog
5.15 0.7.2 5.6 0.7.2
========== =========
*Fixes* *Fixes*
• Timestamp predicates are more tolerant of partial input (e.g. • Timestamp predicates are more tolerant of partial input (e.g.
@ -1409,8 +1195,8 @@ File: README.info, Node: 072, Next: 071, Prev: 073, Up: Changelog
 
File: README.info, Node: 071, Next: 07, Prev: 072, Up: Changelog File: README.info, Node: 071, Next: 07, Prev: 072, Up: Changelog
5.16 0.7.1 5.7 0.7.1
========== =========
*Fixes* *Fixes*
• Function org-ql-completing-read is more compatible with default • Function org-ql-completing-read is more compatible with default
@ -1428,8 +1214,8 @@ File: README.info, Node: 071, Next: 07, Prev: 072, Up: Changelog
 
File: README.info, Node: 07, Next: 063, Prev: 071, Up: Changelog File: README.info, Node: 07, Next: 063, Prev: 071, Up: Changelog
5.17 0.7 5.8 0.7
======== =======
*Added* *Added*
• Command org-ql-find, which jumps to entries selected using • Command org-ql-find, which jumps to entries selected using
@ -1487,8 +1273,8 @@ File: README.info, Node: 07, Next: 063, Prev: 071, Up: Changelog
 
File: README.info, Node: 063, Next: 062, Prev: 07, Up: Changelog File: README.info, Node: 063, Next: 062, Prev: 07, Up: Changelog
5.18 0.6.3 5.9 0.6.3
========== =========
*Fixed* *Fixed*
• Non-sexp query parsing with updated version 1.0.1 of the peg • Non-sexp query parsing with updated version 1.0.1 of the peg
@ -1503,7 +1289,7 @@ File: README.info, Node: 063, Next: 062, Prev: 07, Up: Changelog
 
File: README.info, Node: 062, Next: 061, Prev: 063, Up: Changelog File: README.info, Node: 062, Next: 061, Prev: 063, Up: Changelog
5.19 0.6.2 5.10 0.6.2
========== ==========
*Fixed* *Fixed*
@ -1514,7 +1300,7 @@ File: README.info, Node: 062, Next: 061, Prev: 063, Up: Changelog
 
File: README.info, Node: 061, Next: 06, Prev: 062, Up: Changelog File: README.info, Node: 061, Next: 06, Prev: 062, Up: Changelog
5.20 0.6.1 5.11 0.6.1
========== ==========
*Fixed* *Fixed*
@ -1532,7 +1318,7 @@ File: README.info, Node: 061, Next: 06, Prev: 062, Up: Changelog
 
File: README.info, Node: 06, Next: 052, Prev: 061, Up: Changelog File: README.info, Node: 06, Next: 052, Prev: 061, Up: Changelog
5.21 0.6 5.12 0.6
======== ========
*Added* *Added*
@ -1599,7 +1385,7 @@ File: README.info, Node: 06, Next: 052, Prev: 061, Up: Changelog
 
File: README.info, Node: 052, Next: 051, Prev: 06, Up: Changelog File: README.info, Node: 052, Next: 051, Prev: 06, Up: Changelog
5.22 0.5.2 5.13 0.5.2
========== ==========
*Fixed* *Fixed*
@ -1610,7 +1396,7 @@ File: README.info, Node: 052, Next: 051, Prev: 06, Up: Changelog
 
File: README.info, Node: 051, Next: 05, Prev: 052, Up: Changelog File: README.info, Node: 051, Next: 05, Prev: 052, Up: Changelog
5.23 0.5.1 5.14 0.5.1
========== ==========
*Fixed* *Fixed*
@ -1623,7 +1409,7 @@ File: README.info, Node: 051, Next: 05, Prev: 052, Up: Changelog
 
File: README.info, Node: 05, Next: 049, Prev: 051, Up: Changelog File: README.info, Node: 05, Next: 049, Prev: 051, Up: Changelog
5.24 0.5 5.15 0.5
======== ========
*Added* *Added*
@ -1664,7 +1450,7 @@ File: README.info, Node: 05, Next: 049, Prev: 051, Up: Changelog
 
File: README.info, Node: 049, Next: 048, Prev: 05, Up: Changelog File: README.info, Node: 049, Next: 048, Prev: 05, Up: Changelog
5.25 0.4.9 5.16 0.4.9
========== ==========
*Fixed* *Fixed*
@ -1675,7 +1461,7 @@ File: README.info, Node: 049, Next: 048, Prev: 05, Up: Changelog
 
File: README.info, Node: 048, Next: 047, Prev: 049, Up: Changelog File: README.info, Node: 048, Next: 047, Prev: 049, Up: Changelog
5.26 0.4.8 5.17 0.4.8
========== ==========
*Fixed* *Fixed*
@ -1687,7 +1473,7 @@ File: README.info, Node: 048, Next: 047, Prev: 049, Up: Changelog
 
File: README.info, Node: 047, Next: 046, Prev: 048, Up: Changelog File: README.info, Node: 047, Next: 046, Prev: 048, Up: Changelog
5.27 0.4.7 5.18 0.4.7
========== ==========
*Fixed* *Fixed*
@ -1700,7 +1486,7 @@ File: README.info, Node: 047, Next: 046, Prev: 048, Up: Changelog
 
File: README.info, Node: 046, Next: 045, Prev: 047, Up: Changelog File: README.info, Node: 046, Next: 045, Prev: 047, Up: Changelog
5.28 0.4.6 5.19 0.4.6
========== ==========
*Fixed* *Fixed*
@ -1713,7 +1499,7 @@ File: README.info, Node: 046, Next: 045, Prev: 047, Up: Changelog
 
File: README.info, Node: 045, Next: 044, Prev: 046, Up: Changelog File: README.info, Node: 045, Next: 044, Prev: 046, Up: Changelog
5.29 0.4.5 5.20 0.4.5
========== ==========
*Fixed* *Fixed*
@ -1725,7 +1511,7 @@ File: README.info, Node: 045, Next: 044, Prev: 046, Up: Changelog
 
File: README.info, Node: 044, Next: 043, Prev: 045, Up: Changelog File: README.info, Node: 044, Next: 043, Prev: 045, Up: Changelog
5.30 0.4.4 5.21 0.4.4
========== ==========
*Fixed* *Fixed*
@ -1737,7 +1523,7 @@ File: README.info, Node: 044, Next: 043, Prev: 045, Up: Changelog
 
File: README.info, Node: 043, Next: 042, Prev: 044, Up: Changelog File: README.info, Node: 043, Next: 042, Prev: 044, Up: Changelog
5.31 0.4.3 5.22 0.4.3
========== ==========
*Fixed* *Fixed*
@ -1747,7 +1533,7 @@ File: README.info, Node: 043, Next: 042, Prev: 044, Up: Changelog
 
File: README.info, Node: 042, Next: 041, Prev: 043, Up: Changelog File: README.info, Node: 042, Next: 041, Prev: 043, Up: Changelog
5.32 0.4.2 5.23 0.4.2
========== ==========
*Fixed* *Fixed*
@ -1756,7 +1542,7 @@ File: README.info, Node: 042, Next: 041, Prev: 043, Up: Changelog
 
File: README.info, Node: 041, Next: 04, Prev: 042, Up: Changelog File: README.info, Node: 041, Next: 04, Prev: 042, Up: Changelog
5.33 0.4.1 5.24 0.4.1
========== ==========
*Fixed* *Fixed*
@ -1766,7 +1552,7 @@ File: README.info, Node: 041, Next: 04, Prev: 042, Up: Changelog
 
File: README.info, Node: 04, Next: 032, Prev: 041, Up: Changelog File: README.info, Node: 04, Next: 032, Prev: 041, Up: Changelog
5.34 0.4 5.25 0.4
======== ========
_Note:_ The next release, 0.5, may include changes which will require _Note:_ The next release, 0.5, may include changes which will require
@ -1847,7 +1633,7 @@ automatically, as they will be pushed to the master branch when ready.
 
File: README.info, Node: 032, Next: 031, Prev: 04, Up: Changelog File: README.info, Node: 032, Next: 031, Prev: 04, Up: Changelog
5.35 0.3.2 5.26 0.3.2
========== ==========
*Fixed* *Fixed*
@ -1860,7 +1646,7 @@ File: README.info, Node: 032, Next: 031, Prev: 04, Up: Changelog
 
File: README.info, Node: 031, Next: 03, Prev: 032, Up: Changelog File: README.info, Node: 031, Next: 03, Prev: 032, Up: Changelog
5.36 0.3.1 5.27 0.3.1
========== ==========
*Fixed* *Fixed*
@ -1870,7 +1656,7 @@ File: README.info, Node: 031, Next: 03, Prev: 032, Up: Changelog
 
File: README.info, Node: 03, Next: 023, Prev: 031, Up: Changelog File: README.info, Node: 03, Next: 023, Prev: 031, Up: Changelog
5.37 0.3 5.28 0.3
======== ========
*Added* *Added*
@ -1938,7 +1724,7 @@ File: README.info, Node: 03, Next: 023, Prev: 031, Up: Changelog
 
File: README.info, Node: 023, Next: 022, Prev: 03, Up: Changelog File: README.info, Node: 023, Next: 022, Prev: 03, Up: Changelog
5.38 0.2.3 5.29 0.2.3
========== ==========
*Fixed* *Fixed*
@ -1948,7 +1734,7 @@ File: README.info, Node: 023, Next: 022, Prev: 03, Up: Changelog
 
File: README.info, Node: 022, Next: 021, Prev: 023, Up: Changelog File: README.info, Node: 022, Next: 021, Prev: 023, Up: Changelog
5.39 0.2.2 5.30 0.2.2
========== ==========
*Fixed* *Fixed*
@ -1959,7 +1745,7 @@ File: README.info, Node: 022, Next: 021, Prev: 023, Up: Changelog
 
File: README.info, Node: 021, Next: 02, Prev: 022, Up: Changelog File: README.info, Node: 021, Next: 02, Prev: 022, Up: Changelog
5.40 0.2.1 5.31 0.2.1
========== ==========
*Fixed* *Fixed*
@ -1969,7 +1755,7 @@ File: README.info, Node: 021, Next: 02, Prev: 022, Up: Changelog
 
File: README.info, Node: 02, Next: 01, Prev: 021, Up: Changelog File: README.info, Node: 02, Next: 01, Prev: 021, Up: Changelog
5.41 0.2 5.32 0.2
======== ========
*Added* *Added*
@ -2052,42 +1838,15 @@ File: README.info, Node: 02, Next: 01, Prev: 021, Up: Changelog
 
File: README.info, Node: 01, Prev: 02, Up: Changelog File: README.info, Node: 01, Prev: 02, Up: Changelog
5.42 0.1 5.33 0.1
======== ========
First tagged release. First tagged release.
 
File: README.info, Node: Development, Next: Notes, Prev: Changelog, Up: Top File: README.info, Node: Notes, Next: License, Prev: Changelog, Up: Top
6 Development 6 Notes
*************
Bug reports, feature requests, and suggestions are welcome. For
patches, see below.
* Menu:
* Copyright assignment::

File: README.info, Node: Copyright assignment, Up: Development
6.1 Copyright assignment
========================
While Org QL is currently distributed in MELPA, its intended
(https://github.com/alphapapa/org-ql/issues/409) 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
assign@gnu.org <assign@gnu.org> to request the appropriate form.

File: README.info, Node: Notes, Next: License, Prev: Development, Up: Top
7 Notes
******* *******
* Menu: * Menu:
@ -2098,7 +1857,7 @@ File: README.info, Node: Notes, Next: License, Prev: Development, Up: Top
 
File: README.info, Node: Comparison with Org Agenda searches, Next: org-sidebar, Up: Notes File: README.info, Node: Comparison with Org Agenda searches, Next: org-sidebar, Up: Notes
7.1 Comparison with Org Agenda searches 6.1 Comparison with Org Agenda searches
======================================= =======================================
Of course, queries like these can already be written with Org Agenda Of course, queries like these can already be written with Org Agenda
@ -2118,7 +1877,7 @@ todo:TO-READ, or in Lisp syntax, (and "lisp" (todo "TO-READ")).
 
File: README.info, Node: org-sidebar, Prev: Comparison with Org Agenda searches, Up: Notes File: README.info, Node: org-sidebar, Prev: Comparison with Org Agenda searches, Up: Notes
7.2 org-sidebar 6.2 org-sidebar
=============== ===============
This package is used by org-sidebar This package is used by org-sidebar
@ -2128,7 +1887,7 @@ customizable agenda-like view in a sidebar window.
 
File: README.info, Node: License, Prev: Notes, Up: Top File: README.info, Node: License, Prev: Notes, Up: Top
8 License 7 License
********* *********
GPLv3 GPLv3
@ -2137,90 +1896,78 @@ GPLv3
 
Tag Table: Tag Table:
Node: Top225 Node: Top225
Node: Contents2109 Node: Contents1884
Node: Screenshots2236 Node: Screenshots2007
Node: Installation2354 Node: Installation2125
Node: Quelpa2868 Node: Quelpa2639
Node: Helm support3396 Node: Helm support3167
Node: Usage3799 Node: Usage3570
Node: Commands4197 Node: Commands3968
Node: org-ql-find4662 Node: org-ql-find4433
Node: org-ql-open-link5570 Node: org-ql-open-link5341
Node: org-ql-refile6425 Node: org-ql-refile6196
Node: org-ql-search6753 Node: org-ql-search6524
Node: helm-org-ql8684 Node: helm-org-ql8455
Node: org-ql-view9062 Node: org-ql-view8833
Node: org-ql-view-sidebar9592 Node: org-ql-view-sidebar9363
Node: org-ql-view-recent-items9972 Node: org-ql-view-recent-items9743
Node: org-ql-sparse-tree10468 Node: org-ql-sparse-tree10239
Node: Queries11268 Node: Queries11039
Node: Non-sexp query syntax12385 Node: Non-sexp query syntax12156
Node: General predicates14144 Node: General predicates13915
Node: Ancestor/descendant predicates21069 Node: Ancestor/descendant predicates20840
Node: Date/time predicates22197 Node: Date/time predicates21968
Node: Functions / Macros25321 Node: Functions / Macros25092
Node: Agenda-like views25619 Node: Agenda-like views25390
Ref: Function org-ql-block25781 Ref: Function org-ql-block25552
Node: Listing / acting-on results27042 Node: Listing / acting-on results26813
Ref: Caching27250 Ref: Caching27021
Ref: Function org-ql-select28163 Ref: Function org-ql-select27934
Ref: Function org-ql-query30589 Ref: Function org-ql-query30360
Ref: Macro org-ql (deprecated)32363 Ref: Macro org-ql (deprecated)32134
Node: Custom predicates32678 Node: Custom predicates32449
Ref: Macro org-ql-defpred32902 Ref: Macro org-ql-defpred32673
Node: Dynamic block36343 Node: Dynamic block36114
Node: Links39067 Node: Links38838
Node: Tips39754 Node: Tips39525
Node: Changelog40078 Node: Changelog39849
Node: 09-pre41061 Node: 09-pre40698
Node: helm-org-ql (1)41987 Node: 08140805
Node: 081042128 Node: 0841229
Node: 08942657 Node: 07443953
Node: 08843797 Node: 07344176
Node: 08744873 Node: 07244908
Node: 08646101 Node: 07145827
Node: 08546335 Node: 0746636
Node: 08446991 Node: 06349500
Node: 08347443 Node: 06250031
Node: 08247784 Node: 06150338
Node: 08148179 Node: 0650908
Node: 0848602 Node: 05253964
Node: 07451328 Node: 05154266
Node: 07351553 Node: 0554691
Node: 07252287 Node: 04956222
Node: 07153208 Node: 04856504
Node: 0754019 Node: 04756853
Node: 06356885 Node: 04657262
Node: 06257418 Node: 04557670
Node: 06157725 Node: 04458031
Node: 0658295 Node: 04358390
Node: 05261351 Node: 04258593
Node: 05161653 Node: 04158754
Node: 0562078 Node: 0459001
Node: 04963609 Node: 03263102
Node: 04863891 Node: 03163505
Node: 04764240 Node: 0363702
Node: 04664649 Node: 02367002
Node: 04565057 Node: 02267236
Node: 04465418 Node: 02167516
Node: 04365777 Node: 0267721
Node: 04265980 Node: 0171799
Node: 04166141 Node: Notes71900
Node: 0466388 Node: Comparison with Org Agenda searches72062
Node: 03270489 Node: org-sidebar72951
Node: 03170892 Node: License73230
Node: 0371089
Node: 02374389
Node: 02274623
Node: 02174903
Node: 0275108
Node: 0179186
Node: Development79287
Node: Copyright assignment79520
Node: Notes80110
Node: Comparison with Org Agenda searches80274
Node: org-sidebar81163
Node: License81442
 
End Tag Table End Tag Table

View file

@ -1,29 +0,0 @@
#+title: Timestamp-specific tests
/Timestamps in this file are active ones./
* Single-timestamp ranges
** Single-timestamp, without repeater
<2024-06-25 Tue 08:00-09:00>
** Single-timestamp, with repeater (deadline)
DEADLINE: <2024-06-25 Tue 08:00-09:00 ++7d>
* Multi-timestamp ranges
/Not sure that it would make sense to use repeaters for this kind of range./
** Multi-timestamp, without repeater
<2024-06-25 Tue 08:00>--<2024-06-26 Wed 08:00>
* Day-of-week abbreviations
** French
<2024-07-12 ven.>
* Canary
/This entry should never be matched./

View file

@ -3,7 +3,7 @@
;; Copyright (C) 2019 Adam Porter ;; Copyright (C) 2019 Adam Porter
;; Author: Adam Porter <adam@alphapapa.net> ;; Author: Adam Porter <adam@alphapapa.net>
;; Package-Requires: ((buttercup) (with-simulated-input) (xr)) ;; Package-Requires: ((buttercup) (with-simulated-input))
;; This program is free software; you can redistribute it and/or modify ;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by ;; it under the terms of the GNU General Public License as published by
@ -35,8 +35,6 @@
(require 'xr) (require 'xr)
(declare-function org-ql--normalize-query "org-ql" t t)
;;;; Variables ;;;; Variables
(defvar org-ql-test-buffer nil (defvar org-ql-test-buffer nil
@ -220,8 +218,7 @@ with keyword arg NOW in PLIST."
(it "coalesces a single AND clause that uses two predicates (and preserves predicate order)" (it "coalesces a single AND clause that uses two predicates (and preserves predicate order)"
(expect (org-ql--normalize-query '(and (rifle "foo") (rifle "bar") (expect (org-ql--normalize-query '(and (rifle "foo") (rifle "bar")
(heading "baz") (heading "buz"))) (heading "baz") (heading "buz")))
;; NOTE: `heading' is normalized to `heading-regexp'. :to-equal '(and (rifle :regexps '("foo" "bar")) (heading "baz" "buz"))))
:to-equal '(and (rifle :regexps '("foo" "bar")) (heading-regexp "baz" "buz"))))
(it "preserves independent OR clauses" (it "preserves independent OR clauses"
(expect (org-ql--normalize-query '(and (or (rifle "foo") (rifle "bar")) (expect (org-ql--normalize-query '(and (or (rifle "foo") (rifle "bar"))
(or (rifle "baz") (rifle "buz")))) (or (rifle "baz") (rifle "buz"))))
@ -256,18 +253,6 @@ with keyword arg NOW in PLIST."
(expect (org-ql--normalize-query "\"quoted phrase\"") (expect (org-ql--normalize-query "\"quoted phrase\"")
:to-equal '(rifle :regexps '("\"quoted phrase\"")))) :to-equal '(rifle :regexps '("\"quoted phrase\""))))
(describe "Ancestor/Parent predicates"
;; NOTE: Because the ancestor and parent predicates byte-compile their
;; subquery predicates, we have to test the byte-compiled forms here.
(expect (org-ql--normalize-query '(ancestors "scheduled"))
;; No colon after keyword, so not a predicate query.
:to-equal ;; '(ancestors (rifle :regexps '("scheduled")))
`(ancestors #[nil "\300\301\302\"\207" [rifle :regexps ("scheduled")] 3]))
(expect (org-ql--normalize-query '(parent "scheduled"))
;; No colon after keyword, so not a predicate query.
:to-equal ;; '(parent (rifle :regexps '("scheduled")))
`(parent #[nil "\300\301\302\"\207" [rifle :regexps ("scheduled")] 3])))
(describe "Plain strings" (describe "Plain strings"
(it "normalizes plain strings to the default predicate (using AND)" (it "normalizes plain strings to the default predicate (using AND)"
(expect (org-ql--normalize-query '(and "string1" "string2")) (expect (org-ql--normalize-query '(and "string1" "string2"))
@ -638,11 +623,6 @@ with keyword arg NOW in PLIST."
:to-equal (list :query t :to-equal (list :query t
:preamble (rx bol (repeat 2 4 "*") " ") :preamble (rx bol (repeat 2 4 "*") " ")
:preamble-case-fold t))) :preamble-case-fold t)))
(it "with an expression in level number's place"
(expect (org-ql--query-preamble '(level <= (string-to-number (property "PROPERTY"))))
:to-equal (list :query '(level <= (string-to-number (property "PROPERTY")))
:preamble nil
:preamble-case-fold t)))
(it "<" (it "<"
(expect (org-ql--query-preamble '(level < 3)) (expect (org-ql--query-preamble '(level < 3))
:to-equal (list :query t :to-equal (list :query t
@ -1132,12 +1112,7 @@ with keyword arg NOW in PLIST."
'("Take over the world"))) '("Take over the world")))
(org-ql-it "with two arguments" (org-ql-it "with two arguments"
(org-ql-expect ('(heading "Take over" "world")) (org-ql-expect ('(heading "Take over" "world"))
'("Take over the world"))) '("Take over the world"))))
(org-ql-it "does not match strings as regexps"
(org-ql-expect ('(heading "over"))
'("Take over the universe" "Take over the world" "Take over Mars" "Take over the moon"))
(org-ql-expect ('(heading "[over]"))
nil)))
(describe "(heading-regexp)" (describe "(heading-regexp)"
(org-ql-it "with one argument" (org-ql-it "with one argument"
@ -1344,15 +1319,7 @@ with keyword arg NOW in PLIST."
(org-ql-it "with a property and a value" (org-ql-it "with a property and a value"
(org-ql-expect ('(property "agenda-group" "plans")) (org-ql-expect ('(property "agenda-group" "plans"))
'("Take over the universe" "Write a symphony"))) '("Take over the universe" "Write a symphony"))))
(org-ql-it "with a property and \"nil :inherit t\""
(org-ql-expect ('(property "agenda-group" nil :inherit t))
'("Take over the universe" "Take over the world" "Skype with president of Antarctica" "Take over Mars" "Visit Mars" "Take over the moon" "Visit the moon" "Practice leaping tall buildings in a single bound" "Renew membership in supervillain club" "Learn universal sign language" "Spaceship lease" "Recurring" "/r/emacs" "Shop for groceries" "Sunrise/sunset" "Write a symphony")))
(org-ql-it "with a property and \":inherit t\""
(org-ql-expect ('(property "agenda-group" :inherit t))
'("Take over the universe" "Take over the world" "Skype with president of Antarctica" "Take over Mars" "Visit Mars" "Take over the moon" "Visit the moon" "Practice leaping tall buildings in a single bound" "Renew membership in supervillain club" "Learn universal sign language" "Spaceship lease" "Recurring" "/r/emacs" "Shop for groceries" "Sunrise/sunset" "Write a symphony"))))
(describe "(regexp)" (describe "(regexp)"
@ -1703,36 +1670,7 @@ with keyword arg NOW in PLIST."
(org-ql-expect ((org-ql--query-string-to-sexp "ts-active:with-time=")) (org-ql-expect ((org-ql--query-string-to-sexp "ts-active:with-time="))
'("Take over the universe" "Take over the world" "Visit Mars" "Visit the moon" "Practice leaping tall buildings in a single bound" "Get haircut" "Internet" "Spaceship lease" "Fix flux capacitor" "/r/emacs" "Shop for groceries" "Rewrite Emacs in Common Lisp")) '("Take over the universe" "Take over the world" "Visit Mars" "Visit the moon" "Practice leaping tall buildings in a single bound" "Get haircut" "Internet" "Spaceship lease" "Fix flux capacitor" "/r/emacs" "Shop for groceries" "Rewrite Emacs in Common Lisp"))
(org-ql-expect ((org-ql--query-string-to-sexp "ts-active:with-time=t")) (org-ql-expect ((org-ql--query-string-to-sexp "ts-active:with-time=t"))
'("Skype with president of Antarctica" "Renew membership in supervillain club" "Order a pizza"))) '("Skype with president of Antarctica" "Renew membership in supervillain club" "Order a pizza"))))
(describe "matches timestamps with inner time ranges"
(before-each
(setq org-ql-test-buffer (org-ql-test-data-buffer "data-ts.org")
org-ql-test-num-headings (with-current-buffer org-ql-test-buffer
(org-with-wide-buffer
(goto-char (point-min))
;; Exclude the "Canary" heading.
(1- (cl-loop while (re-search-forward org-heading-regexp nil t)
sum 1))))))
(org-ql-it "without :with-time"
(org-ql-expect ('(ts-active))
'("Single-timestamp, without repeater" "Single-timestamp, with repeater (deadline)" "Multi-timestamp, without repeater" "French")))
(org-ql-it ":with-time t"
(org-ql-expect ('(ts-active :on "2024-06-25" :with-time t))
'("Single-timestamp, without repeater" "Single-timestamp, with repeater (deadline)" "Multi-timestamp, without repeater"))
(org-ql-expect ('(ts-active :on "2024-06-26" :with-time t))
'("Multi-timestamp, without repeater")))
(org-ql-it ":with-time t and with specified time value in :to"
(org-ql-expect ('(ts-active :to "2024-06-25 09:00" :with-time t))
'("Single-timestamp, without repeater" "Single-timestamp, with repeater (deadline)" "Multi-timestamp, without repeater"))
;; FIXME: The test below fails because timestamps with
;; ranges are not yet parsed into multiple timestamps and
;; compared as a range. This will have to be addressed in
;; a new version.
;; (org-ql-expect ('(ts-active :from "2024-06-25 08:30"))
;; '("Single-timestamp, without repeater" "Single-timestamp, with repeater (deadline)" "Multi-timestamp, without repeater"))
)))
(describe "inactive" (describe "inactive"
@ -1871,20 +1809,7 @@ with keyword arg NOW in PLIST."
'("Visit Mars"))) '("Visit Mars")))
(org-ql-then (:now "2019-07-07") (org-ql-then (:now "2019-07-07")
(org-ql-expect ('(ts :on today)) (org-ql-expect ('(ts :on today))
nil)))) nil)))))
(describe "Day-of-week abbreviations"
(before-each
(setq org-ql-test-buffer (org-ql-test-data-buffer "data-ts.org")
org-ql-test-num-headings (with-current-buffer org-ql-test-buffer
(org-with-wide-buffer
(goto-char (point-min))
;; Exclude the "Canary" heading.
(1- (cl-loop while (re-search-forward org-heading-regexp nil t)
sum 1))))))
(org-ql-it "matches French abbreviations (with trailing period)"
(org-ql-expect ('(ts :on "2024-07-12"))
'("French")))))
(describe "Compound queries" (describe "Compound queries"
@ -1986,13 +1911,13 @@ with keyword arg NOW in PLIST."
(expression-link "[[org-ql-search:todo:?title%3D%28error%20%22UNSAFE%22%29]]")) (expression-link "[[org-ql-search:todo:?title%3D%28error%20%22UNSAFE%22%29]]"))
(it "Errors for a quoted lambda" (it "Errors for a quoted lambda"
(expect (open-link quoted-lambda-link) (expect (open-link quoted-lambda-link)
:to-throw 'error '("CAUTION: Link not opened because unsafe title parameter detected: (lambda (_ _) (error \"UNSAFE\"))"))) :to-throw 'wrong-type-argument '(characterp lambda)))
(it "Errors for an unquoted lambda" (it "Errors for an unquoted lambda"
(expect (open-link unquoted-lambda-link) (expect (open-link unquoted-lambda-link)
:to-throw 'error '("CAUTION: Link not opened because unsafe title parameter detected: (lambda (_ _) (error \"UNSAFE\"))"))) :to-throw 'wrong-type-argument '(characterp lambda)))
(it "Errors for an expression" (it "Errors for an expression"
(expect (open-link expression-link) (expect (open-link expression-link)
:to-throw 'error '("CAUTION: Link not opened because unsafe title parameter detected: (error \"UNSAFE\")")))) :to-throw 'wrong-type-argument '(characterp error))))
(describe "sort parameter" (describe "sort parameter"
:var ((quoted-lambda-link "[[org-ql-search:todo:?sort%3D%28lambda%20%28_%20_%29%20%28error%20%22UNSAFE%22%29%29]]") :var ((quoted-lambda-link "[[org-ql-search:todo:?sort%3D%28lambda%20%28_%20_%29%20%28error%20%22UNSAFE%22%29%29]]")
@ -2018,7 +1943,7 @@ with keyword arg NOW in PLIST."
(describe "View saving/loading" (describe "View saving/loading"
:var* ((temp-dir (make-temp-file "test-org-ql-" 'dir)) :var* ((temp-dir (make-temp-file "test-org-ql-" 'dir))
(temp-filenames (cl-loop for file in '("test1.org" "test2.org") (temp-filenames (cl-loop for file in '("test1.org" "test2.org")
collect (abbreviate-file-name (expand-file-name file temp-dir)))) collect (expand-file-name file temp-dir)))
(file-contents (with-temp-buffer (file-contents (with-temp-buffer
(insert "#+TITLE: Test data\n\n" (insert "#+TITLE: Test data\n\n"
"* TODO Heading 1\n" "* TODO Heading 1\n"