Merge remote-tracking branch 'gh/master' into fixmerge

This commit is contained in:
Salih Muhammed 2024-01-25 21:42:20 +02:00
commit 500cb3ea77
13 changed files with 967 additions and 547 deletions

78
.github/ISSUE_TEMPLATE/bug_report.yml vendored Normal file
View file

@ -0,0 +1,78 @@
name: Bug Report
description: File a bug report
# labels: ["bug"]
# assignees:
# - alphapapa
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this bug report!
- type: input
id: os-platform
attributes:
label: OS/platform
description: What operating system or platform are you running Emacs on?
validations:
required: true
- type: textarea
id: emacs-provenance
attributes:
label: Emacs version and provenance
description: What version of Emacs are you using, where did you acquire it, and how did you install it?
validations:
required: true
- type: input
id: emacs-command
attributes:
label: Emacs command
description: By what method did you run Emacs? (i.e. what command did you run?)
validations:
required: true
- type: textarea
id: org-provenance
attributes:
label: Org version and provenance
description: What version of Org are you using, where did you acquire it, and how did you install it?
validations:
required: true
- type: input
id: package-provenance
attributes:
label: org-ql package version and provenance
description: What version of org-ql are you using, where did you acquire it, and how did you install it?
validations:
required: true
- type: textarea
id: actions
attributes:
label: Actions taken
description: What actions did you take, step-by-step, in order, before the problem was noticed?
validations:
required: true
- type: textarea
id: results
attributes:
label: Observed results
description: What behavior did you observe that seemed wrong?
validations:
required: true
- type: textarea
id: expected
attributes:
label: Expected results
description: What behavior did you expect to observe?
validations:
required: true
- type: textarea
id: backtrace
attributes:
label: Backtrace
description: If an error was signaled, please use `M-x toggle-debug-on-error RET` and cause the error to happen again, then paste the contents of the `*Backtrace*` buffer here.
render: elisp
- type: textarea
id: etc
attributes:
label: Etc.
description: Any other information that seems relevant

5
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View file

@ -0,0 +1,5 @@
blank_issues_enabled: true
contact_links:
- name: Support questions
url: https://github.com/alphapapa/org-ql/discussions
about: Please ask and answer support questions here.

View file

@ -0,0 +1,45 @@
name: Feature Request
description: File a feature request
labels: ["enhancement"]
body:
- type: input
id: os-platform
attributes:
label: OS/platform
description: What operating system or platform are you running Emacs on?
validations:
required: true
- type: textarea
id: emacs-provenance
attributes:
label: Emacs version and provenance
description: What version of Emacs are you using, where did you acquire it, and how did you install it?
validations:
required: true
- type: textarea
id: org-provenance
attributes:
label: Org version and provenance
description: What version of Org are you using, where did you acquire it, and how did you install it?
validations:
required: true
- type: input
id: package-provenance
attributes:
label: org-ql package version and provenance
description: What version of org-ql are you using, where did you acquire it, and how did you install it?
validations:
required: true
- type: textarea
id: description
attributes:
label: Description
description: Describe your request.
validations:
required: true
- type: textarea
id: etc
attributes:
label: Etc.
description: Any other information that seems relevant

View file

@ -41,7 +41,6 @@ jobs:
fail-fast: false
matrix:
emacs_version:
- 26.3
- 27.1
- 27.2
- 28.1

View file

@ -115,7 +115,7 @@ These commands jump to a heading selected using Emacs's built-in completion faci
- ~org-ql-find-in-agenda~ searches in ~(org-agenda-files)~.
- ~org-ql-find-in-org-directory~ searches in ~org-directory~.
Note that these commands are compatible with [[https://github.com/oantolin/embark][Embark]]: the ~embark-act~ command can be called on a completion candidate (i.e. a search result) to act on it immediately, without having to visit the entry in its source Org buffer.
Note that these commands are compatible with [[https://github.com/oantolin/embark][Embark]]: the ~embark-act~ command can be called on a completion candidate (i.e. a search result) to act on it immediately, without having to visit the entry in its source Org buffer, and ~embark-export~ may be called to show the results in an ~org-ql-view~ buffer.
[[images/org-ql-find.png]]
@ -248,7 +248,7 @@ Arguments are listed next to predicate names, where applicable.
- Aliases: ~olps~.
+ =path (&rest regexps)= :: Return non-nil if current heading's buffer's filename path matches any of ~REGEXPS~ (regexp strings). Without arguments, return non-nil if buffer is file-backed.
+ =priority (&rest args)= :: Return non-nil if current heading has a certain priority. ~ARGS~ may be either a list of one or more priority letters as strings, or a comparator function symbol followed by a priority letter string. For example: ~(priority "A") (priority "A" "B") (priority '>= "B")~ Note that items without a priority cookie never match this predicate (while Org itself considers items without a cookie to have the default priority, which, by default, is equal to priority ~B~).
+ =property (property &optional value &key inherit)= :: Return non-nil if current entry has ~PROPERTY~ (a string), and optionally ~VALUE~ (a string). If ~INHERIT~ is nil, only match entries with ~PROPERTY~ set on the entry; if t, also match entries with inheritance. If ~INHERIT~ is not specified, use the Boolean value of ~org-use-property-inheritance~, which see (i.e. it is only interpreted as nil or non-nil).
+ =property (property &optional value &key inherit)= :: Return non-nil if current entry has ~PROPERTY~ (a string), and optionally ~VALUE~ (a string). If ~INHERIT~ is nil, only match entries with ~PROPERTY~ set on the entry; if t, also match entries with inheritance. If ~INHERIT~ is not specified, use the value of ~org-use-property-inheritance~, which see.
+ =regexp (&rest regexps)= :: Return non-nil if current entry matches all of ~REGEXPS~ (regexp strings). Matches against entire entry, from beginning of its heading to the next heading.
- Aliases: =r=.
+ =rifle (&rest strings)= :: Return non-nil if each string is found in either the entry or its outline path. Works like =org-rifle=. This is probably the most useful, intuitive, general-purpose predicate.
@ -553,19 +553,60 @@ Simple links may also be written manually in either sexp or non-sexp form, like:
/Note:/ Breaking changes may be made before version 1.0, but in the event of major changes, attempts at backward compatibility will be made with obsolescence declarations, translation of arguments, etc. Users who need stability guarantees before 1.0 may choose to use tagged stable releases.
** 0.8-pre
** 0.9-pre
Nothing new yet.
** 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
*Fixes*
+ Command ~org-ql-find~ widens the buffer before going to the selected entry.
+ In ~org-ql-view~ buffers, links in headings remain clickable links. (Fixes [[https://github.com/alphapapa/org-ql/issues/282][#282]]. Thanks to [[https://github.com/jakebox][Jacob Boxerman]] for reporting.)
** 0.8
*Additions*
+ Function ~org-ql-completing-read~, used by command ~org-ql-find~, now specifies the completion category as ~org-heading~, providing compatibility with [[https://github.com/oantolin/embark][Embark]]. (This is a powerful feature, as it means any ~org-ql-find~ result can be acted on from inside the search results with Embark, which provides common actions from Org Agenda and Org speed keys bindings.) ([[https://github.com/alphapapa/org-ql/issues/299][#299]]. Thanks to [[https://github.com/oantolin][Omar Antolín Camarena]], [[https://github.com/minad][Daniel Mendler]], and [[https://github.com/akirak][Akira Komamura]].)
- Command ~org-ql-completing-read-export~, bound to ~C-c C-e~ or ~embark-export~ while in an ~org-ql-completing-read~ session, exits and shows an ~org-ql-view~ buffer for the current search.
+ Command ~org-ql-find~ may be called in an ~org-agenda~ or ~org-ql-view~ buffer to search the buffers which contributed to the agenda/view buffer.
+ Command ~org-ql-find-path~, which searches outline paths in the current buffer.
+ Command ~org-ql-open-link~, which finds links in entries matching the given query, and opens the selected one with ~org-open-at-point~. (This is helpful when a collection of links are kept in Org files: rather than having to first visit the entry containing the desired link, then locate it within the entry, and then open it, the user can simply select the link and open it directly.)
+ Items in ~org-ql-view~ buffers now include the ~org-category~ text property, like Org Agenda buffers, which allows grouping with ~org-super-agenda~'s category-related selectors. ([[https://github.com/alphapapa/org-ql/issues/363][#363]]. Thanks to [[https://github.com/kofm][Gabriele Mongiano]] for reporting.)
*Fixes*
+ Predicate ~property~ correctly uses the value of ~org-use-property-inheritance~ when not specified. ([[https://github.com/alphapapa/org-ql/pull/346][#346]], [[https://github.com/alphapapa/org-ql/issues/356][#356]]. Thanks to [[https://github.com/bram85][Bram Schoenmakers]].)
*Compatibility*
+ Emacs 27.1 or later is now required.
+ Org v9.7's ~org-element~ API changes required some adjustments. ([[https://github.com/alphapapa/org-ql/issues/364][#364]]. Thanks to several users for reporting, and to [[https://github.com/yantar92][Ihor Radchenko]] for his feedback.)
** 0.7.4
*Fixes*
+ Ignore empty quoted strings in plain-string queries ([[https://github.com/alphapapa/org-ql/issues/383][#383]]).
** 0.7.3
*Fixes*
@ -592,7 +633,7 @@ Simple links may also be written manually in either sexp or non-sexp form, like:
** 0.7
*Added*
+ Commands ~org-ql-find~, ~org-ql-find-heading~, and ~org-ql-find-path~, which jump to entries selected using Emacs's built-in completion facilities and Org QL queries (like ~helm-org-ql~, but doesn't require Helm.).
+ Command ~org-ql-find~, which jumps to entries selected using Emacs's built-in completion facilities and Org QL queries (like ~helm-org-ql~, but doesn't require Helm.).
+ Command ~org-ql-refile~, which refiles the entry at point to one selected using Org QL completion.
+ Predicate ~rifle~, which matches an entry if each of the given arguments is found in either the entry's contents or its outline path. This provides very intuitive results, mimicing the behavior of [[https://github.com/alphapapa/org-rifle][=org-rifle=]]. In fact, the results are so useful that it's now the default predicate for plain-string query tokens. (It is also aliased to ~smart~, since it's so "smart," and not all users have used =org-rifle=.)
+ Option ~org-ql-default-predicate~, applied to plain-string query tokens (before, the ~regexp~ predicate was always used, but now it may be customized).

View file

@ -3,7 +3,7 @@
# * makem.sh --- Script to aid building and testing Emacs Lisp packages
# URL: https://github.com/alphapapa/makem.sh
# Version: 0.6-pre
# Version: 0.7
# * Commentary:
@ -112,6 +112,12 @@ Source files are automatically discovered from git, or may be
specified with options. Package dependencies are discovered from
"Package-Requires" headers in source files, from -pkg.el files, and
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
}
@ -177,6 +183,7 @@ function elisp-checkdoc-file {
(setq makem-checkdoc-errors-p t)
;; Return nil because we *are* generating a buffered list of errors.
nil))))
(put 'ispell-buffer-session-localwords 'safe-local-variable #'list-of-strings-p)
(mapcar #'checkdoc-file files)
(when makem-checkdoc-errors-p
(kill-emacs 1))))
@ -379,6 +386,36 @@ function byte-compile-file {
# ** 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 {
# Echo list of directories to be used in load path.
files-project-feature | dirnames
@ -387,7 +424,7 @@ function dirs-project {
function files-project-elisp {
# Echo list of Elisp files in project.
git ls-files 2>/dev/null \
files-project 2>/dev/null \
| egrep "\.el$" \
| filter-files-exclude-default \
| filter-files-exclude-args
@ -396,13 +433,13 @@ function files-project-elisp {
function files-project-feature {
# Echo list of Elisp files that are not tests and provide a feature.
files-project-elisp \
| egrep -v "$test_files_regexp" \
| grep -E -v "$test_files_regexp" \
| filter-files-feature
}
function files-project-test {
# Echo list of Elisp test files.
files-project-elisp | egrep "$test_files_regexp"
files-project-elisp | grep -E "$test_files_regexp"
}
function dirnames {
@ -415,7 +452,7 @@ function dirnames {
function filter-files-exclude-default {
# Filter out paths (STDIN) which should be excluded by default.
egrep -v "(/\.cask/|-autoloads.el|.dir-locals)"
grep -E -v "(/\.cask/|-autoloads\.el|\.dir-locals)"
}
function filter-files-exclude-args {
@ -441,7 +478,7 @@ function filter-files-feature {
# Read paths on STDIN and echo ones that (provide 'a-feature).
while read path
do
egrep "^\\(provide '" "$path" &>/dev/null \
grep -E "^\\(provide '" "$path" &>/dev/null \
&& echo "$path"
done
}
@ -489,7 +526,7 @@ function ert-tests-p {
function package-main-file {
# Echo the package's main file.
file_pkg=$(git ls-files ./*-pkg.el 2>/dev/null)
file_pkg=$(files-project "*-pkg.el" 2>/dev/null)
if [[ $file_pkg ]]
then
@ -512,23 +549,23 @@ function dependencies {
# 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.
egrep -a -i '^;; Package-Requires: ' $(files-project-feature) $(files-project-test) \
| egrep -o '\([^([:space:]][^)]*\)' \
| egrep -o '^[^[:space:])]+' \
grep -E -a -i '^;; Package-Requires: ' $(files-project-feature) $(files-project-test) \
| grep -E -o '\([^([:space:]][^)]*\)' \
| grep -E -o '^[^[:space:])]+' \
| sed -r 's/\(//g' \
| egrep -v '^emacs$' # Ignore Emacs version requirement.
| grep -E -v '^emacs$' # Ignore Emacs version requirement.
# Search Cask file.
if [[ -r Cask ]]
then
egrep '\(depends-on "[^"]+"' Cask \
grep -E '\(depends-on "[^"]+"' Cask \
| sed -r -e 's/\(depends-on "([^"]+)".*/\1/g'
fi
# Search -pkg.el file.
if [[ $(git ls-files ./*-pkg.el 2>/dev/null) ]]
if [[ $(files-project "*-pkg.el" 2>/dev/null) ]]
then
sed -nr 's/.*\(([-[:alnum:]]+)[[:blank:]]+"[.[:digit:]]+"\).*/\1/p' $(git ls-files ./*-pkg.el 2>/dev/null)
sed -nr 's/.*\(([-[:alnum:]]+)[[:blank:]]+"[.[:digit:]]+"\).*/\1/p' $(files-project- -- -pkg.el 2>/dev/null)
fi
}
@ -581,6 +618,9 @@ function sandbox {
local deps=($(dependencies))
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[@]}"
do
args_sandbox_package_install+=(--eval "(package-install '$package)")
@ -1193,6 +1233,9 @@ paths_temp+=("$package_initialize_file")
trap cleanup EXIT INT TERM
# Change to project root directory first.
cd "$(project-root)"
# Discover project files.
files_project_feature=($(files-project-feature))
files_project_test=($(files-project-test))

View file

@ -1,6 +1,6 @@
;;; org-ql-completing-read.el --- Completing read of Org entries using org-ql -*- lexical-binding: t; -*-
;; Copyright (C) 2022 Adam Porter
;; Copyright (C) 2022-2023 Adam Porter
;; Author: Adam Porter <adam@alphapapa.net>
@ -26,6 +26,18 @@
(require 'org-ql)
(declare-function org-ql-search "org-ql-search")
;;;; Variables
(defvar-keymap org-ql-completing-read-map
:doc "Active during `org-ql-completing-read' sessions."
"C-c C-e" #'org-ql-completing-read-export)
;; `embark-collect' doesn't work for `org-ql-completing-read', so remap
;; it to `embark-export' (which `keymap-set', et al doesn't allow).
(define-key org-ql-completing-read-map [remap embark-collect] 'embark-export)
;;;; Customization
(defgroup org-ql-completing-read nil
@ -82,7 +94,7 @@ To be used in, e.g. annotation functions.")
(defun org-ql-completing-read-action ()
"Default action for `org-ql-completing-read'.
Returns (STRING . MARKER) cons for entry at point."
(font-lock-ensure (point-at-bol) (point-at-eol))
(font-lock-ensure (pos-bol) (pos-eol))
(cons (org-link-display-format (org-entry-get nil "ITEM")) (point-marker)))
(defun org-ql-completing-read-snippet (marker)
@ -114,12 +126,17 @@ value, or nil."
;;;;; Completing read
(defun org-ql-completing-read-export ()
"Show `org-ql-view' buffer for current `org-ql-completing-read'-based search."
(interactive)
(user-error "Not in an `org-ql-completing-read' session"))
;;;###autoload
(cl-defun org-ql-completing-read
(buffers-files &key query-prefix query-filter
(action #'org-ql-completing-read-action)
;; FIXME: Unused argument.
(annotate #'org-ql-completing-read-snippet)
;; (annotate #'org-ql-completing-read-snippet)
(snippet #'org-ql-completing-read-snippet)
(path #'org-ql-completing-read-path)
(action-filter #'list)
@ -155,7 +172,7 @@ single predicate)."
(cl-labels (;; (debug-message
;; (f &rest args) (apply #'message (concat "ORG-QL-COMPLETING-READ: " f) args))
(action ()
(font-lock-ensure (point-at-bol) (point-at-eol))
(font-lock-ensure (pos-bol) (pos-eol))
;; This function needs to handle multiple candidates per
;; call, so we loop over a list of values by default.
(pcase-dolist (`(,string . ,marker) (funcall action-filter (funcall action)))
@ -173,7 +190,6 @@ single predicate)."
(setf string (format "%s <%s>" string (cl-incf suffix)))
(setf string (format "%s <%s>" string (puthash string 2 disambiguations)))))
(puthash (propertize string 'org-marker marker) marker table)))))
(path (marker)
(org-with-point-at marker
(let* ((path (thread-first (org-get-outline-path nil t)
@ -183,10 +199,10 @@ single predicate)."
(concat "\\" (string-join (reverse path) "\\"))
(concat "/" (string-join path "/")))))
formatted-path)))
(todo
(marker) (if-let (it (org-entry-get marker "TODO"))
(concat (propertize it 'face (org-get-todo-face it)) " ")
""))
(todo (marker)
(if-let (it (org-entry-get marker "TODO"))
(concat (propertize it 'face (org-get-todo-face it)) " ")
""))
(affix (completions)
;; (debug-message "AFFIX:%S" completions)
(cl-loop for completion in completions
@ -201,14 +217,14 @@ single predicate)."
;; e.g. Helm while typing, but it seems to help a little when using the
;; org-rifle-style snippets.
(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)))
(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)
(pcase transform
(`nil (buffer-name (marker-buffer (get-text-property 0 'org-marker candidate))))
@ -322,7 +338,23 @@ single predicate)."
(mapc #'org-ql--ensure-buffer buffers-files)
(let* ((completion-styles '(org-ql-completing-read))
(completion-styles-alist (list (list 'org-ql-completing-read #'try #'all "Org QL Find")))
(selected (completing-read prompt #'collection nil t)))
(selected
(minibuffer-with-setup-hook
(lambda ()
(use-local-map (make-composed-keymap org-ql-completing-read-map (current-local-map))))
(cl-letf* (((symbol-function 'org-ql-completing-read-export)
(lambda ()
(interactive)
(run-at-time 0 nil
#'org-ql-search
buffers-files
(minibuffer-contents-no-properties))
(if (fboundp 'minibuffer-quit-recursive-edit)
(minibuffer-quit-recursive-edit)
(abort-recursive-edit))))
((symbol-function 'embark-export)
(symbol-function 'org-ql-completing-read-export)))
(completing-read prompt #'collection nil t)))))
;; (debug-message "SELECTED:%S KEYS:%S" selected (hash-table-keys table))
(or (gethash selected table)
;; If there are completions in the table, but none of them exactly match the user input

View file

@ -1,6 +1,6 @@
;;; org-ql-find.el --- Find headings with completion using org-ql -*- lexical-binding: t; -*-
;; Copyright (C) 2022 Adam Porter
;; Copyright (C) 2022-2023 Adam Porter
;; Author: Adam Porter <adam@alphapapa.net>
@ -49,7 +49,7 @@
See function `display-buffer'."
:type 'sexp)
;;;; Functions
;;;; Commands
;;;###autoload
(cl-defun org-ql-find (buffers-files &key query-prefix query-filter
@ -70,28 +70,29 @@ types is filtered before execution (e.g. it could replace spaces
with commas to turn multiple tokens, which would normally be
treated as multiple predicates, into multiple arguments to a
single predicate)."
(interactive
(list (if current-prefix-arg
(mapcar #'get-buffer
(completing-read-multiple
"Buffers: "
(cl-loop for buffer in (buffer-list)
when (eq 'org-mode (buffer-local-value 'major-mode buffer))
collect (buffer-name buffer))
nil t))
(cond ((derived-mode-p 'org-agenda-mode) (or org-ql-view-buffers-files
org-agenda-contributing-files))
((derived-mode-p 'org-mode) (current-buffer))
(t (user-error "This is not an Org-related buffer: %S" (current-buffer)))))))
(interactive (list (org-ql-find--buffers)))
(let ((marker (org-ql-completing-read buffers-files
:query-prefix query-prefix
:query-filter query-filter
:prompt prompt)))
(set-buffer (marker-buffer marker))
(goto-char marker)
(display-buffer (current-buffer) org-ql-find-display-buffer-action)
(select-window (get-buffer-window (current-buffer)))
(run-hook-with-args 'org-ql-find-goto-hook)))
(set-buffer (or (buffer-base-buffer (marker-buffer marker))
(marker-buffer marker)))
(pop-to-buffer (current-buffer) org-ql-find-display-buffer-action)
(without-restriction
(goto-char marker)
(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
(defun org-ql-refile (marker)
@ -135,11 +136,16 @@ which see (but only the files are used)."
(org-ql-find (org-ql-search-directories-files)))
;;;###autoload
(defun org-ql-find-path ()
"Call `org-ql-find' to search outline paths in the current buffer."
(interactive)
(defun org-ql-find-path (buffers-files)
"Call `org-ql-find' to search outline paths in BUFFERS-FILES.
Interactively, search the buffers and files relevant to the
current buffer (i.e. in `org-agenda-mode', the value of
`org-ql-view-buffers-files' or `org-agenda-contributing-files';
in `org-mode', that buffer). With universal prefix, select
multiple buffers to search with completion and PROMPT."
(interactive (list (org-ql-find--buffers)))
(let ((org-ql-default-predicate 'outline-path))
(org-ql-find (current-buffer))))
(org-ql-find buffers-files)))
;;;###autoload
(cl-defun org-ql-open-link (buffers-files &key query-prefix query-filter
@ -149,21 +155,14 @@ Links found in entries matching the input query are offered as
candidates, and the selected one is opened with
`org-open-at-point'. Arguments BUFFERS-FILES, QUERY-FILTER,
QUERY-PREFIX, and PROMPT are passed to `org-ql-completing-read',
which see."
(interactive
;; FIXME: Factor this out.
(list (if current-prefix-arg
(mapcar #'get-buffer
(completing-read-multiple
"Buffers: "
(cl-loop for buffer in (buffer-list)
when (eq 'org-mode (buffer-local-value 'major-mode buffer))
collect (buffer-name buffer))
nil t))
(progn
(unless (eq major-mode 'org-mode)
(user-error "This is not an Org buffer: %S" (current-buffer)))
(current-buffer)))))
which see.
Interactively, search the buffers and files relevant to the
current buffer (i.e. in `org-agenda-mode', the value of
`org-ql-view-buffers-files' or `org-agenda-contributing-files';
in `org-mode', that buffer). With universal prefix, select
multiple buffers to search with completion and PROMPT."
(interactive (list (org-ql-find--buffers)))
(let* ((marker (org-ql-completing-read buffers-files
:query-prefix query-prefix
:query-filter query-filter
@ -192,6 +191,29 @@ which see."
(org-with-point-at marker
(org-open-at-point))))
;;;; Functions
(defun org-ql-find--buffers ()
"Return list of buffers to search in.
In a mode derived from `org-agenda-mode', return the value of
`org-ql-view-buffers-files' or `org-agenda-contributing-files'.
In a mode derived from `org-mode', return the current buffer.
When `current-prefix-arg', read a list of buffers in `org-mode'
with completion. To be used in `org-ql-find' commands'
interactive forms."
(if current-prefix-arg
(mapcar #'get-buffer
(completing-read-multiple
"Buffers: "
(cl-loop for buffer in (buffer-list)
when (eq 'org-mode (buffer-local-value 'major-mode buffer))
collect (buffer-name buffer))
nil t))
(cond ((derived-mode-p 'org-agenda-mode) (or org-ql-view-buffers-files
org-agenda-contributing-files))
((derived-mode-p 'org-mode) (current-buffer))
(t (user-error "This is not an Org-related buffer: %S" (current-buffer))))))
(provide 'org-ql-find)
;;; org-ql-find.el ends here

View file

@ -1,5 +1,7 @@
;;; org-ql-search.el --- Search commands for org-ql -*- lexical-binding: t; -*-
;; Copyright (C) 2019-2023 Adam Porter
;; Author: Adam Porter <adam@alphapapa.net>
;; Url: https://github.com/alphapapa/org-ql
@ -56,6 +58,16 @@
((fboundp 'org-store-link-props) #'org-store-link-props)
(t (error "org-ql: Unable to define alias `org-ql-search--org-link-store-props'. Please report this as a bug"))))
(defalias 'org-ql--org-hide-archived-subtrees
(if (version<= "9.6" org-version)
'org-fold-hide-archived-subtrees
'org-hide-archived-subtrees))
(defalias 'org-ql--org-show-context
(if (version<= "9.6" org-version)
'org-fold-show-context
'org-show-context))
;;;; Variables
(defvar org-ql-block-header nil
@ -124,10 +136,10 @@ Runs `org-occur-hook' after making the sparse tree."
query))))
(org-ql-select buffer query
:action (lambda ()
(org-show-context 'occur-tree)
(org-ql--org-show-context 'occur-tree)
(cl-incf num-results)))
(unless org-sparse-tree-open-archived-trees
(org-hide-archived-subtrees (point-min) (point-max)))
(org-ql--org-hide-archived-subtrees (point-min) (point-max)))
(run-hooks 'org-occur-hook)
(unless (get-buffer-window buffer)
(pop-to-buffer buffer))
@ -208,8 +220,7 @@ necessary."
(symbol (symbol-value super-groups))
(list super-groups))))
(setf strings (org-super-agenda--group-items strings))))
(org-ql-view--display :buffer buffer :header header
:string (s-join "\n" strings)))))
(org-ql-view--display :buffer buffer :header header :strings strings))))
;;;###autoload
(defun org-ql-search-block (query)
@ -341,17 +352,17 @@ this (must be a single line in the Org buffer):
(setf elements (cl-etypecase take
((and integer (satisfies cl-minusp)) (-take-last (abs take) elements))
(integer (-take take elements)))))
(cl-labels ((format-element
(element) (string-join (cl-loop for column in columns
collect (or (pcase-exhaustive column
((pred symbolp)
(funcall (alist-get column format-fns) element))
(`((,column . ,args) ,_header)
(apply (alist-get column format-fns) element args))
(`(,column ,_header)
(funcall (alist-get column format-fns) element)))
""))
" | ")))
(cl-labels ((format-element (element)
(string-join (cl-loop for column in columns
collect (or (pcase-exhaustive column
((pred symbolp)
(funcall (alist-get column format-fns) element))
(`((,column . ,args) ,_header)
(apply (alist-get column format-fns) element args))
(`(,column ,_header)
(funcall (alist-get column format-fns) element)))
""))
" | ")))
;; Table header
(insert "| " (string-join (--map (pcase it
((pred symbolp) (capitalize (symbol-name it)))

View file

@ -1,5 +1,7 @@
;;; org-ql-view.el --- Agenda-like view based on org-ql -*- lexical-binding: t; -*-
;; Copyright (C) 2019-2023 Adam Porter
;; Author: Adam Porter <adam@alphapapa.net>
;; Url: https://github.com/alphapapa/org-ql
@ -302,10 +304,10 @@ SLOT is passed to `display-buffer-in-side-window', which see."
(defun org-ql-view-switch ()
"Switch to view at point."
(interactive)
(let ((key (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
(let ((key (buffer-substring-no-properties (pos-bol) (pos-eol))))
(unless (string-empty-p key)
(ov-clear :org-ql-view-selected)
(ov (point-at-bol) (1+ (point-at-eol)) :org-ql-view-selected t
(ov (pos-bol) (1+ (pos-eol)) :org-ql-view-selected t
'face '(:weight bold :inherit highlight))
(org-ql-view key))))
@ -369,7 +371,7 @@ update search arguments."
(defun org-ql-view-customize ()
"Customize view at point in `org-ql-view-sidebar' buffer."
(interactive)
(let ((key (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
(let ((key (buffer-substring-no-properties (pos-bol) (pos-eol))))
(customize-option 'org-ql-views)
(search-forward (concat "Name: " key))))
@ -406,7 +408,7 @@ update search arguments."
(defvar bookmark-make-record-function)
(cl-defun org-ql-view--display (&key (buffer org-ql-view-buffer) header string)
(cl-defun org-ql-view--display (&key (buffer org-ql-view-buffer) header strings)
"Display STRING in `org-ql-view' BUFFER.
BUFFER may be a buffer, or a string naming a buffer, which is
@ -444,7 +446,9 @@ subsequent refreshing of the buffer: `org-ql-view-buffers-files',
;; Clear buffer, insert entries, etc.
(let ((inhibit-read-only t))
(erase-buffer)
(insert string "\n")
(dolist (string strings)
(insert string "\n"))
(insert "\n")
(pop-to-buffer (current-buffer) org-ql-view-display-buffer-action)
(org-agenda-finalize)
(goto-char (point-min))))))
@ -487,11 +491,11 @@ If TITLE, prepend it to the header."
Makes QUERY more readable, e.g. timestamp objects are replaced
with human-readable strings."
(cl-labels ((rec (form)
(cl-typecase form
(ts (ts-format form))
(cons (cons (rec (car form))
(rec (cdr form))))
(otherwise form))))
(cl-typecase form
(ts (ts-format form))
(cons (cons (rec (car form))
(rec (cdr form))))
(otherwise form))))
(format "%S" (rec query))))
(defun org-ql-view--font-lock-string (mode s)
@ -533,14 +537,14 @@ dates in the past, and negative for dates in the future."
(defun org-ql-view-bookmark-make-record ()
"Return a bookmark record for the current Org QL View buffer."
(cl-labels ((file-nameize
(b-f) (abbreviate-file-name
(cl-typecase b-f
(string b-f)
(buffer (or (buffer-file-name b-f)
(when (buffer-base-buffer b-f)
(buffer-file-name (buffer-base-buffer b-f)))))
(t (user-error "Only file-backed buffers can be bookmarked by Org QL View: %s" b-f))))))
(cl-labels ((file-nameize (b-f)
(abbreviate-file-name
(cl-typecase b-f
(string b-f)
(buffer (or (buffer-file-name b-f)
(when (buffer-base-buffer b-f)
(buffer-file-name (buffer-base-buffer b-f)))))
(t (user-error "Only file-backed buffers can be bookmarked by Org QL View: %s" b-f))))))
(-let* ((plist (org-ql-view--plist (current-buffer)))
((&plist :buffers-files) plist))
;; Replace buffers with their filenames, and signal error if any are not file-backed.
@ -655,23 +659,25 @@ When opened, the link searches the buffer it's opened from."
(when org-ql-view-query
;; Only Org QL View buffers should have `org-ql-view-query' set.
(cl-labels ((prompt-for (buffers-files)
(pcase-exhaustive
(completing-read (format "Make link that searches: ")
'("file link is in" "files currently searched")
nil t nil nil "file link is in")
("file link is in" nil)
("files currently searched" buffers-files)))
(strings-or-file-buffers-p
(thing) (cl-etypecase thing
(list (cl-every #'strings-or-file-buffers-p thing))
(string thing)
(buffer (or (buffer-file-name thing)
;; TODO: Should indirect buffers be allowed? Maybe not, since their narrowing isn't preserved.
;; On the other hand, it's possible to accidentally make a search view for an indirect buffer
;; that's since been widened, and forcing the user to manually change that would be awkward,
;; and trying to communicate the problem would be difficult, so maybe it's okay to allow it.
(when (buffer-base-buffer thing)
(buffer-file-name (buffer-base-buffer thing))))))))
(pcase-exhaustive
(completing-read (format "Make link that searches: ")
'("file link is in" "files currently searched")
nil t nil nil "file link is in")
("file link is in" nil)
("files currently searched" buffers-files)))
(strings-or-file-buffers-p (thing)
(cl-etypecase thing
(list (cl-every #'strings-or-file-buffers-p thing))
(string thing)
(buffer (or (buffer-file-name thing)
;; TODO: Should indirect buffers be allowed? Maybe not, since their
;; narrowing isn't preserved. On the other hand, it's possible to
;; accidentally make a search view for an indirect buffer that's
;; since been widened, and forcing the user to manually change that
;; would be awkward, and trying to communicate the problem would be
;; difficult, so maybe it's okay to allow it.
(when (buffer-base-buffer thing)
(buffer-file-name (buffer-base-buffer thing))))))))
(unless (strings-or-file-buffers-p org-ql-view-buffers-files)
(user-error "%s" "Views that search non-file-backed buffers can't be linked to"))
(let* ((query-string (--if-let (org-ql--query-sexp-to-string org-ql-view-query)
@ -865,8 +871,7 @@ return an empty string."
;; Adding the relative due date property should probably be done explicitly and separately
;; (which would also make it easier to do it independently of faces, etc).
(title (--> (org-ql-view--add-faces element)
(org-element-property :raw-value it)
(org-link-display-format it)))
(org-element-property :raw-value it)))
(todo-keyword (-some--> (org-element-property :todo-keyword element)
(org-ql-view--add-todo-face it)))
(tag-list (if org-use-tag-inheritance
@ -889,17 +894,20 @@ return an empty string."
(s-join ":" it)
(s-wrap it ":")
(org-add-props it nil 'face 'org-tag))))
;; (category (org-element-property :category element))
;; Org Agenda priorities are subtracted from `org-priority-lowest'
;; and multiplied by 1000, so do the same here. Also assume that <65
;; means the priority is a number and covert to its ASCII equivalent,
;; which is what `org-priority-to-value' implicitly does. See also
;; `org-get-priority' and `org-priority-lowest'.
(priority (cl-flet ((adjust (p) (if (>= p 65) p (+ p 48))))
(-if-let (pri (org-element-property :priority element))
(* 1000 (- (adjust org-priority-lowest) pri))
(* 1000 (- (adjust org-priority-lowest)
(adjust org-priority-default))))))
(category (or (org-element-property :CATEGORY element)
(when-let ((marker (or (org-element-property :org-hd-marker element)
(org-element-property :org-marker element))))
(org-with-point-at marker
(or (org-get-category)
(when buffer-file-name
(file-name-sans-extension
(file-name-nondirectory buffer-file-name))))))
""))
(priority-string (-some->> (org-element-property :priority element)
(char-to-string)
(format "[#%s]")
@ -915,14 +923,15 @@ return an empty string."
(remove-list-of-text-properties 0 (length string) '(line-prefix) string)
;; Add all the necessary properties and faces to the whole string
(--> string
;; FIXME: Use proper prefix
(concat " " it)
(org-add-props it properties
'org-agenda-type 'search
'priority priority
'todo-state todo-keyword
'tags tag-list
'org-habit-p habit-property)))))
;; FIXME: Use proper prefix
(concat " " it)
(org-add-props it properties
'org-agenda-type 'search
'priority priority
'org-category category
'todo-state todo-keyword
'tags tag-list
'org-habit-p habit-property)))))
(defun org-ql-view--add-faces (element)
"Return ELEMENT with deadline and scheduled faces added."
@ -1050,11 +1059,11 @@ the variable), \"org-directory\" if it matches the value of
current buffer. Otherwise BUFFERS-FILES is returned unchanged."
;; Used in `org-ql-view--complete-buffers-files' and
;; `org-ql-view--header-line-format'.
(cl-labels ((expand-files
(list) (--map (cl-typecase it
(string (expand-file-name it))
(otherwise it))
list)))
(cl-labels ((expand-files (list)
(--map (cl-typecase it
(string (expand-file-name it))
(otherwise it))
list)))
;; TODO: Test this more exhaustively.
(pcase buffers-files
((pred listp)
@ -1076,10 +1085,10 @@ current buffer. Otherwise BUFFERS-FILES is returned unchanged."
(defun org-ql-view--complete-buffers-files ()
"Return value for `org-ql-view-buffers-files' using completion."
(cl-labels ((initial-input
() (when org-ql-view-buffers-files
(org-ql-view--contract-buffers-files
org-ql-view-buffers-files))))
(cl-labels ((initial-input ()
(when org-ql-view-buffers-files
(org-ql-view--contract-buffers-files
org-ql-view-buffers-files))))
(if (and org-ql-view-buffers-files
(bufferp org-ql-view-buffers-files))
;; Buffers can't be input by name, so if the default value is a buffer, just use it.

456
org-ql.el
View file

@ -1,11 +1,11 @@
;;; org-ql.el --- Org Query Language, search command, and agenda-like view -*- lexical-binding: t; -*-
;; Copyright (C) 2017-2022 Adam Porter
;; Copyright (C) 2017-2023 Adam Porter
;; Author: Adam Porter <adam@alphapapa.net>
;; Url: https://github.com/alphapapa/org-ql
;; Version: 0.8-pre
;; Package-Requires: ((emacs "26.1") (dash "2.18.1") (f "0.17.2") (map "2.1") (org "9.0") (org-super-agenda "1.2") (ov "1.0.6") (peg "1.0.1") (s "1.12.0") (transient "0.1") (ts "0.2-pre"))
;; Version: 0.9-pre
;; Package-Requires: ((emacs "27.1") (compat "29.1") (dash "2.18.1") (f "0.17.2") (map "2.1") (org "9.0") (org-super-agenda "1.2") (ov "1.0.6") (peg "1.0.1") (s "1.12.0") (transient "0.1") (ts "0.2-pre"))
;; Keywords: hypermedia, outlines, Org, agenda
;;; License:
@ -43,6 +43,7 @@
(require 'seq)
(require 'subr-x)
(require 'compat)
(require 'dash)
(require 'map)
(require 'ts)
@ -95,6 +96,12 @@ Necessary because of backward-incompatible changes in Org
`org-bracket-link-regexp' was marked as an obsolete alias for it,
but the match groups were changed, so they are not compatible.")
;;;; Compatibility
(defalias 'org-ql--org-timestamp-format
(if (version<= "9.6" org-version)
'org-format-timestamp
'org-timestamp-format))
;;;; Variables
(defvar org-ql--today nil)
@ -285,6 +292,11 @@ Matches with or without time.")
:link '(custom-manual "(org-ql)Usage")
:link '(url-link "https://github.com/alphapapa/org-ql"))
(defcustom org-ql-signal-peg-failure nil
"Signal an error when parsing a plain-string query fails.
This should only be enabled while debugging."
:type 'boolean)
(defcustom org-ql-ask-unsafe-queries t
"Ask before running a query that could run arbitrary code.
Org QL queries in sexp form can contain arbitrary expressions.
@ -749,38 +761,38 @@ be coalesced."
;; can't be coalesced with it since they don't specify the same
;; language. That could be fixed, but it's probably not worth it.
(cl-labels ((rec (sexp)
(pcase sexp
(`(,(and boolean (or 'or 'not)) . ,sexps)
`(,boolean ,@(mapcar #'rec sexps)))
(`(and . ,sexps)
(anded sexps))
(_ sexp)))
(pcase sexp
(`(,(and boolean (or 'or 'not)) . ,sexps)
`(,boolean ,@(mapcar #'rec sexps)))
(`(and . ,sexps)
(anded sexps))
(_ sexp)))
(anded (sexps)
(let (anded-predicates new-sexp)
(dolist (sexp sexps)
(pcase sexp
(`(,(or 'or 'not) . ,_)
(push (rec sexp) new-sexp))
(`(,predicate . ,args)
(pcase-exhaustive (plist-get (alist-get predicate org-ql-predicates) :coalesce)
(`nil (push sexp new-sexp))
(`t (setf (alist-get predicate anded-predicates)
(append (alist-get predicate anded-predicates) args)))
((and fn (pred functionp))
(if-let (new-args (funcall fn (alist-get predicate anded-predicates) args))
(setf (alist-get predicate anded-predicates) new-args)
(push sexp new-sexp)))))))
(delq nil `(and ,@(nreverse new-sexp) ,@(nreverse anded-predicates))))))
(let (anded-predicates new-sexp)
(dolist (sexp sexps)
(pcase sexp
(`(,(or 'or 'not) . ,_)
(push (rec sexp) new-sexp))
(`(,predicate . ,args)
(pcase-exhaustive (plist-get (alist-get predicate org-ql-predicates) :coalesce)
(`nil (push sexp new-sexp))
(`t (setf (alist-get predicate anded-predicates)
(append (alist-get predicate anded-predicates) args)))
((and fn (pred functionp))
(if-let (new-args (funcall fn (alist-get predicate anded-predicates) args))
(setf (alist-get predicate anded-predicates) new-args)
(push sexp new-sexp)))))))
(delq nil `(and ,@(nreverse new-sexp) ,@(nreverse anded-predicates))))))
(rec query)))
(defun org-ql--sanity-check-form (form)
"Signal error if any forms in FORM do not have preconditions met.
Or, when possible, fix the problem."
(cl-flet ((check (symbol)
(pcase symbol
('done (unless org-done-keywords
;; NOTE: This check needs to be done from within the Org buffer being checked.
(error "Variable `org-done-keywords' is nil. Are you running this from an Org buffer?"))))))
(pcase symbol
('done (unless org-done-keywords
;; NOTE: This check needs to be done from within the Org buffer being checked.
(error "Variable `org-done-keywords' is nil. Are you running this from an Org buffer?"))))))
(cl-loop for elem in form
if (consp elem)
do (progn
@ -802,28 +814,27 @@ respectively."
(and "\\" (0+ "\\\\") (any "[]"))
(and (1+ "\\") (not (any "[]")))))))
(cl-labels
((no-desc
(match) (rx-to-string `(seq (or bol (1+ blank))
"[[" ,link-target-part (regexp ,match) ,link-target-part
"]]")))
(match-both
(description target)
(rx-to-string `(seq (or bol (1+ blank))
"[[" ,link-target-part (regexp ,target) ,link-target-part
"][" (*? anything) (regexp ,description) (*? anything)
"]]")))
((no-desc (match)
(rx-to-string `(seq (or bol (1+ blank))
"[[" ,link-target-part (regexp ,match) ,link-target-part
"]]")))
(match-both (description target)
(rx-to-string `(seq (or bol (1+ blank))
"[[" ,link-target-part (regexp ,target) ,link-target-part
"][" (*? anything) (regexp ,description) (*? anything)
"]]")))
;; Note that these actually allow empty descriptions
;; or targets, depending on what they are matching.
(match-desc
(match) (rx-to-string `(seq (or bol (1+ blank))
"[[" ,link-target-part
"][" (*? anything) (regexp ,match) (*? anything)
"]]")))
(match-target
(match) (rx-to-string `(seq (or bol (1+ blank))
"[[" ,link-target-part (regexp ,match) ,link-target-part
"][" (*? anything)
"]]"))))
(match-desc (match)
(rx-to-string `(seq (or bol (1+ blank))
"[[" ,link-target-part
"][" (*? anything) (regexp ,match) (*? anything)
"]]")))
(match-target (match)
(rx-to-string `(seq (or bol (1+ blank))
"[[" ,link-target-part (regexp ,match) ,link-target-part
"][" (*? anything)
"]]"))))
(cond (description-or-target
(rx-to-string `(or (regexp ,(no-desc description-or-target))
(regexp ,(match-desc description-or-target))
@ -878,48 +889,48 @@ Arguments STRING, POS, FILL, and LEVEL are according to
;; NOTE: The pcases check for both t/nil symbols and strings, because the
;; string queries always return keyword arguments' values as strings.
(cl-macrolet ((clocked (&key from to on)
`(org-ql--predicate-clocked :from ,from :to ,to))
`(org-ql--predicate-clocked :from ,from :to ,to))
(closed (&key from to on (with-time 'not-found))
`(org-ql--predicate-closed :from ,from :to ,to))
`(org-ql--predicate-closed :from ,from :to ,to))
(deadline (&key from to on (with-time 'not-found))
`(org-ql--predicate-deadline
:from ,from :to ,to :with-time ',with-time
:regexp ,(pcase-exhaustive with-time
((or 't "t") org-ql-regexp-deadline-with-time)
((or 'nil "nil") org-ql-regexp-deadline-without-time)
('not-found org-ql-regexp-deadline))))
`(org-ql--predicate-deadline
:from ,from :to ,to :with-time ',with-time
:regexp ,(pcase-exhaustive with-time
((or 't "t") org-ql-regexp-deadline-with-time)
((or 'nil "nil") org-ql-regexp-deadline-without-time)
('not-found org-ql-regexp-deadline))))
(planning (&key from to on (with-time 'not-found))
`(org-ql--predicate-planning
:from ,from :to ,to :with-time ',with-time
:regexp ,(pcase-exhaustive with-time
((or 't "t") org-ql-regexp-planning-with-time)
((or 'nil "nil") org-ql-regexp-planning-without-time)
('not-found org-ql-regexp-planning))))
`(org-ql--predicate-planning
:from ,from :to ,to :with-time ',with-time
:regexp ,(pcase-exhaustive with-time
((or 't "t") org-ql-regexp-planning-with-time)
((or 'nil "nil") org-ql-regexp-planning-without-time)
('not-found org-ql-regexp-planning))))
(scheduled (&key from to on (with-time 'not-found))
`(org-ql--predicate-scheduled
:from ,from :to ,to :with-time ',with-time
:regexp ,(pcase-exhaustive with-time
((or 't "t") org-ql-regexp-scheduled-with-time)
((or 'nil "nil") org-ql-regexp-scheduled-without-time)
('not-found org-ql-regexp-scheduled))))
`(org-ql--predicate-scheduled
:from ,from :to ,to :with-time ',with-time
:regexp ,(pcase-exhaustive with-time
((or 't "t") org-ql-regexp-scheduled-with-time)
((or 'nil "nil") org-ql-regexp-scheduled-without-time)
('not-found org-ql-regexp-scheduled))))
(ts (&key from to on (type 'both) (with-time 'not-found))
;; NOTE: The TYPE argument is elided from the arguments actually passed to the predicate, being converted to the REGEXP argument.
;; MAYBE: Move the :regexp handling out of this macrolet and into the normalizer.
`(org-ql--predicate-ts
:from ,from :to ,to :with-time ',with-time
:regexp ,(pcase type
((or 'nil 'both) (pcase-exhaustive with-time
((or 't "t") org-ql-regexp-ts-both-with-time)
((or 'nil "nil") org-ql-regexp-ts-both-without-time)
('not-found org-ql-regexp-ts-both)))
('active (pcase-exhaustive with-time
((or 't "t") org-ql-regexp-ts-active-with-time)
((or 'nil "nil") org-ql-regexp-ts-active-without-time)
('not-found org-ql-regexp-ts-active)))
('inactive (pcase-exhaustive with-time
((or 't "t") org-ql-regexp-ts-inactive-with-time)
((or 'nil "nil") org-ql-regexp-ts-inactive-without-time)
('not-found org-ql-regexp-ts-inactive)))))))
;; NOTE: The TYPE argument is elided from the arguments actually passed to the predicate, being converted to the REGEXP argument.
;; MAYBE: Move the :regexp handling out of this macrolet and into the normalizer.
`(org-ql--predicate-ts
:from ,from :to ,to :with-time ',with-time
:regexp ,(pcase type
((or 'nil 'both) (pcase-exhaustive with-time
((or 't "t") org-ql-regexp-ts-both-with-time)
((or 'nil "nil") org-ql-regexp-ts-both-without-time)
('not-found org-ql-regexp-ts-both)))
('active (pcase-exhaustive with-time
((or 't "t") org-ql-regexp-ts-active-with-time)
((or 'nil "nil") org-ql-regexp-ts-active-without-time)
('not-found org-ql-regexp-ts-active)))
('inactive (pcase-exhaustive with-time
((or 't "t") org-ql-regexp-ts-inactive-with-time)
((or 'nil "nil") org-ql-regexp-ts-inactive-without-time)
('not-found org-ql-regexp-ts-inactive)))))))
,query)))))
;;;;; String query parsing
@ -950,7 +961,7 @@ value of `org-ql-predicates')."
(term (or (and negation (list positive-term)
;; This is a bit confusing, but it seems to work. There's probably a better way.
`(pred -- (list 'not (car pred))))
positive-term))
positive-term empty-quote))
(positive-term (or (and predicate-with-args `(pred args -- (cons (intern pred) args)))
(and predicate-without-args `(pred -- (list (intern pred))))
(and plain-string `(s -- (list org-ql-default-predicate s)))))
@ -963,6 +974,12 @@ value of `org-ql-predicates')."
(keyword (substring (+ (not (or separator "=" "\"" (syntax-class whitespace))) (any))))
(quoted-arg "\"" (substring (+ (not (or separator "\"")) (any))) "\"")
(unquoted-arg (substring (+ (not (or separator "\"" (syntax-class whitespace))) (any))))
(empty-quote
;; This avoids aborting parsing or signaling an
;; error if the user types in two successive
;; quotation marks while typing a query (e.g. when
;; using electric-pair-mode).
"\"\"")
(negation "!")
(separator "," )))
(closure (lambda (input &optional boolean)
@ -983,7 +1000,10 @@ value of `org-ql-predicates')."
;; have to borrow some code. It ends up that we only have to
;; borrow this `with-peg-rules' call, which isn't too bad.
(eval `(with-peg-rules ,pexs
(peg-run (peg ,(caar pexs)) #'peg-signal-failure))))))
(peg-run (peg ,(caar pexs))
(lambda (failures)
(when org-ql-signal-peg-failure
(peg-signal-failure failures)))))))))
(pcase parsed-sexp
(`(,one-predicate) one-predicate)
(`(,_ . ,_) (cons boolean (reverse parsed-sexp)))
@ -1027,21 +1047,21 @@ This function is defined by calling
`org-ql--define-normalize-query-fn', which uses normalizer forms
defined in `org-ql-predicates' by calling `org-ql-defpred'."
(cl-labels ((rec (element)
(pcase element
(`(or . ,clauses) `(or ,@(mapcar #'rec clauses)))
(`(and . ,clauses) `(and ,@(mapcar #'rec clauses)))
(`(not . ,clauses) `(not ,@(mapcar #'rec clauses)))
(`(when ,condition . ,clauses) `(when ,(rec condition)
,@(mapcar #'rec clauses)))
(`(unless ,condition . ,clauses) `(unless ,(rec condition)
,@(mapcar #'rec clauses)))
;; TODO: Combine (regexp) when appropriate (i.e. inside an OR, not an AND).
((pred stringp) `(,org-ql-default-predicate ,element))
(pcase element
(`(or . ,clauses) `(or ,@(mapcar #'rec clauses)))
(`(and . ,clauses) `(and ,@(mapcar #'rec clauses)))
(`(not . ,clauses) `(not ,@(mapcar #'rec clauses)))
(`(when ,condition . ,clauses) `(when ,(rec condition)
,@(mapcar #'rec clauses)))
(`(unless ,condition . ,clauses) `(unless ,(rec condition)
,@(mapcar #'rec clauses)))
;; TODO: Combine (regexp) when appropriate (i.e. inside an OR, not an AND).
((pred stringp) `(,org-ql-default-predicate ,element))
,@normalizer-patterns
,@normalizer-patterns
;; Any other form: passed through unchanged.
(_ element))))
;; Any other form: passed through unchanged.
(_ element))))
;; Repeat normalization until result doesn't change (limiting to 10 in case of an infinite-loop bug).
(cl-loop with limit = 10 and count = 0
for new-query = (rec query)
@ -1094,18 +1114,18 @@ defined in `org-ql-predicates' by calling `org-ql-defpred'."
(_ (let ((preamble-case-fold t)
org-ql-preamble)
(cl-labels ((rec (element)
(or (when org-ql-preamble
;; Only one preamble is allowed
element)
(pcase element
(`(or _) element)
(or (when org-ql-preamble
;; Only one preamble is allowed
element)
(pcase element
(`(or _) element)
,@preamble-patterns
,@preamble-patterns
(`(and . ,rest)
(let ((clauses (mapcar #'rec rest)))
`(and ,@(-non-nil clauses))))
(_ element)))))
(`(and . ,rest)
(let ((clauses (mapcar #'rec rest)))
`(and ,@(-non-nil clauses))))
(_ element)))))
(setq query (pcase (mapcar #'rec (list query))
((or `(nil)
`((nil))
@ -1121,7 +1141,7 @@ defined in `org-ql-predicates' by calling `org-ql-defpred'."
(byte-compile 'org-ql--query-preamble)))
(cl-defmacro org-ql-defpred (name args docstring &key body preambles normalizers coalesce)
"Define an `org-ql' selector predicate named `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
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
@ -1166,7 +1186,7 @@ to variables bound in the pattern:
:case-fold Bound to `case-fold-search' around the regexp search.
:query Expression which should replace the query expression,
or `query' if it should not be changed (e.g. if the
or \\+`query' if it should not be changed (e.g. if the
regexp is insufficient to determine whether a
heading matches, in which case the predicate's body
needs to be tested on the heading). If the regexp
@ -1193,7 +1213,7 @@ e.g. a predicate takes keyword arguments, so arguments to
multiple calls can't be simply appended.)
For convenience, within the `pcase' patterns, the symbol
`predicate-names' is a special form which is replaced with a
\\+`predicate-names' is a special form which is replaced with a
pattern matching any of the predicate's name and aliases. For
example, if NAME were:
@ -1201,13 +1221,13 @@ example, if NAME were:
Then if NORMALIZERS were:
((`(,predicate-names . ,args)
`(heading ,@args)))
((\\=`(,predicate-names . ,args)
\\=`(heading ,@args)))
It would be expanded to:
((`(,(or 'heading 'h) . ,args)
`(heading ,@args)))"
((\\=`(,(or 'heading 'h) . ,args)
\\=`(heading ,@args)))"
;; FIXME: Update defpred tutorial to include :coalesce.
;; NOTE: The debug form works, completely! For example, use `edebug-defun'
@ -1810,9 +1830,9 @@ interpreted as nil or non-nil)."
(when (keywordp property)
(setf property (substring (symbol-name property) 1)))
(list 'property property value
:inherit (if (plist-member plist :inherit)
(plist-get plist :inherit)
org-use-property-inheritance))))
: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: Support (property) without args.
@ -1959,7 +1979,7 @@ language. Matching is done case-insensitively."
(point)))
(contents-end (progn
(goto-char (match-end 0))
(point-at-bol))))
(pos-bol))))
(cl-loop for re in regexps
do (goto-char contents-beg)
always (re-search-forward re contents-end t))))))))))
@ -1969,8 +1989,8 @@ language. Matching is done case-insensitively."
Tests both inherited and local tags."
;; MAYBE: -all versions for inherited and local.
:body (cl-macrolet ((tags-p (tags)
`(and ,tags
(not (eq 'org-ql-nil ,tags)))))
`(and ,tags
(not (eq 'org-ql-nil ,tags)))))
(-let* (((inherited local) (org-ql--tags-at (point))))
(cl-typecase tags
(null (or (tags-p inherited)
@ -1995,8 +2015,8 @@ If TAGS is nil, return non-nil if heading has any inherited tags."
:normalizers ((`(,predicate-names . ,tags)
`(tags-inherited ,@tags)))
:body (cl-macrolet ((tags-p (tags)
`(and ,tags
(not (eq 'org-ql-nil ,tags)))))
`(and ,tags
(not (eq 'org-ql-nil ,tags)))))
(-let* (((inherited _) (org-ql--tags-at (point))))
(cl-typecase tags
(null (tags-p inherited))
@ -2016,8 +2036,8 @@ If TAGS is nil, return non-nil if heading has any local tags."
t)
:query t)))
:body (cl-macrolet ((tags-p (tags)
`(and ,tags
(not (eq 'org-ql-nil ,tags)))))
`(and ,tags
(not (eq 'org-ql-nil ,tags)))))
(-let* (((_ local) (org-ql--tags-at (point))))
(cl-typecase tags
(null (tags-p local))
@ -2030,8 +2050,8 @@ Tests both inherited and local tags."
:normalizers ((`(,predicate-names . ,regexps)
`(tags-regexp ,@regexps)))
:body (cl-macrolet ((tags-p (tags)
`(and ,tags
(not (eq 'org-ql-nil ,tags)))))
`(and ,tags
(not (eq 'org-ql-nil ,tags)))))
(-let* (((inherited local) (org-ql--tags-at (point))))
(cl-typecase regexps
(null (or (tags-p inherited)
@ -2379,12 +2399,12 @@ any planning prefix); it defaults to 0 (i.e. the whole regexp)."
:body
(cl-macrolet ((next-timestamp ()
`(when (re-search-forward regexp limit t)
(ts-parse-org (match-string match-group))))
`(when (re-search-forward regexp limit t)
(ts-parse-org (match-string match-group))))
(test-timestamps (pred-form)
`(cl-loop for next-ts = (next-timestamp)
while next-ts
thereis ,pred-form)))
`(cl-loop for next-ts = (next-timestamp)
while next-ts
thereis ,pred-form)))
(save-excursion
(cond ((not (or from to)) (re-search-forward regexp limit t))
((and from to) (test-timestamps (ts-in from to next-ts)))
@ -2410,27 +2430,27 @@ PREDICATES is a list of one or more sorting methods, including:
`deadline', `scheduled', `closed' and `priority'."
;; MAYBE: Use macrolet instead of flet.
(cl-flet* ((sorter (symbol)
(pcase symbol
((or 'deadline 'scheduled 'closed)
(apply-partially #'org-ql--date-type< (intern (concat ":" (symbol-name symbol)))))
;; TODO: Rename `date' to `planning'. `date' should be something else.
('date #'org-ql--date<)
('priority #'org-ql--priority<)
('random (lambda (&rest _ignore)
(= 0 (random 2))))
;; NOTE: reverse and todo are handled below.
;; TODO: Add more.
(_ (user-error "Invalid sorting predicate: %s" symbol))))
(pcase symbol
((or 'deadline 'scheduled 'closed)
(apply-partially #'org-ql--date-type< (intern (concat ":" (symbol-name symbol)))))
;; TODO: Rename `date' to `planning'. `date' should be something else.
('date #'org-ql--date<)
('priority #'org-ql--priority<)
('random (lambda (&rest _ignore)
(= 0 (random 2))))
;; NOTE: reverse and todo are handled below.
;; TODO: Add more.
(_ (user-error "Invalid sorting predicate: %s" symbol))))
(sort-by-todo-keyword (items)
(let* ((grouped-items (--group-by (when-let (keyword (org-element-property :todo-keyword it))
(substring-no-properties keyword))
items))
(sorted-groups (cl-sort grouped-items #'<
:key (lambda (keyword)
(or (cl-position (car keyword) org-todo-keywords-1 :test #'string=)
;; Put at end of list if not found
(1+ (length org-todo-keywords-1)))))))
(-flatten-n 1 (-map #'cdr sorted-groups)))))
(let* ((grouped-items (--group-by (when-let (keyword (org-element-property :todo-keyword it))
(substring-no-properties keyword))
items))
(sorted-groups (cl-sort grouped-items #'<
:key (lambda (keyword)
(or (cl-position (car keyword) org-todo-keywords-1 :test #'string=)
;; Put at end of list if not found
(1+ (length org-todo-keywords-1)))))))
(-flatten-n 1 (-map #'cdr sorted-groups)))))
(dolist (pred predicates)
(setq items (pcase pred
;; NOTE: Using `reverse' instead of `nreverse' because my gut
@ -2455,16 +2475,16 @@ A and B are Org headline elements. TYPE should be a symbol like
"Return non-nil if A's deadline or scheduled property is earlier than B's.
Deadline is considered before scheduled."
(cl-macrolet ((ts (item)
`(or (org-element-property :deadline ,item)
(org-element-property :scheduled ,item))))
`(or (org-element-property :deadline ,item)
(org-element-property :scheduled ,item))))
(org-ql--org-timestamp-element< (ts a) (ts b))))
(defun org-ql--org-timestamp-element< (a b)
"Return non-nil if A's date element is earlier than B's.
A and B are Org timestamp elements."
(cl-macrolet ((ts (ts)
`(when ,ts
(org-timestamp-format ,ts "%s"))))
`(when ,ts
(org-ql--org-timestamp-format ,ts "%s"))))
(let* ((a-ts (ts a))
(b-ts (ts b)))
(cond ((and a-ts b-ts)
@ -2476,7 +2496,7 @@ A and B are Org timestamp elements."
"Return non-nil if A's priority is higher than B's.
A and B are Org headline elements."
(cl-macrolet ((priority (item)
`(org-element-property :priority ,item)))
`(org-element-property :priority ,item)))
;; NOTE: Priorities are numbers in Org elements. This might differ from the priority selector logic.
(let ((a-priority (priority a))
(b-priority (priority b)))
@ -2504,66 +2524,66 @@ element should be a regexp string."
If QUERY can't be converted to a string, return nil."
;; This started out pretty simple...but at least it's not just one long function, right?
(cl-labels ((complex-p (query)
(or (contains-p 'or query)
(contains-p 'ancestors query)
(contains-p 'children query)
(contains-p 'descendants query)
(contains-p 'parent query)))
(or (contains-p 'or query)
(contains-p 'ancestors query)
(contains-p 'children query)
(contains-p 'descendants query)
(contains-p 'parent query)))
(contains-p (symbol list)
(cl-loop for element in list
thereis (or (eq symbol element)
(and (listp element)
(contains-p symbol element)))))
(format-args
(args) (let (non-paired paired next-keyword)
(cl-loop for arg in args
do (cond (next-keyword (push (cons next-keyword arg) paired)
(setf next-keyword nil))
((keywordp arg) (setf next-keyword (substring (symbol-name arg) 1)))
(t (push arg non-paired))))
(string-join (append (mapcar #'format-atom non-paired)
(nreverse (--map (format "%s=%s" (car it) (cdr it))
paired)))
",")))
(format-atom
(atom) (cl-typecase atom
(string (if (string-match (rx space) atom)
(format "%S" atom)
(format "%s" atom)))
(t (format "%s" atom))))
(format-form
(form) (pcase form
(`(not . (,rest)) (concat "!" (format-form rest)))
(`(priority . ,_) (format-priority form))
;; FIXME: Convert (src) queries to non-sexp form...someday...
(`(src . ,_) (user-error "Converting (src ...) queries to non-sexp form is not implemented"))
(_ (pcase-let* ((`(,pred . ,args) form)
(args-string (pcase args
('() "")
((guard (= 1 (length args))) (format "%s" (car args)))
(_ (format-args args)))))
(format "%s:%s" pred args-string)))))
(format-and
(form) (pcase-let* ((`(and . ,rest) form))
(string-join (mapcar #'format-form rest) " ")))
(format-priority
(form) (pcase-let* ((`(priority . ,rest) form)
(args (pcase rest
(`(,(and comparator (or '< '<= '> '>= '=)) ,letter)
(priority-letters comparator letter))
(_ rest))))
(concat "priority:" (string-join args ","))))
(priority-letters
(comparator letter) (let* ((char (string-to-char (upcase (symbol-name letter))))
(numeric-priorities '(?A ?B ?C))
;; NOTE: The comparator inversion is intentional.
(others (pcase comparator
('< (--select (> it char) numeric-priorities))
('<= (--select (>= it char) numeric-priorities))
('> (--select (< it char) numeric-priorities))
('>= (--select (<= it char) numeric-priorities))
('= (--select (= it char) numeric-priorities)))))
(mapcar #'char-to-string others))))
(cl-loop for element in list
thereis (or (eq symbol element)
(and (listp element)
(contains-p symbol element)))))
(format-args (args)
(let (non-paired paired next-keyword)
(cl-loop for arg in args
do (cond (next-keyword (push (cons next-keyword arg) paired)
(setf next-keyword nil))
((keywordp arg) (setf next-keyword (substring (symbol-name arg) 1)))
(t (push arg non-paired))))
(string-join (append (mapcar #'format-atom non-paired)
(nreverse (--map (format "%s=%s" (car it) (cdr it))
paired)))
",")))
(format-atom (atom)
(cl-typecase atom
(string (if (string-match (rx space) atom)
(format "%S" atom)
(format "%s" atom)))
(t (format "%s" atom))))
(format-form (form)
(pcase form
(`(not . (,rest)) (concat "!" (format-form rest)))
(`(priority . ,_) (format-priority form))
;; FIXME: Convert (src) queries to non-sexp form...someday...
(`(src . ,_) (user-error "Converting (src ...) queries to non-sexp form is not implemented"))
(_ (pcase-let* ((`(,pred . ,args) form)
(args-string (pcase args
('() "")
((guard (= 1 (length args))) (format "%s" (car args)))
(_ (format-args args)))))
(format "%s:%s" pred args-string)))))
(format-and (form)
(pcase-let* ((`(and . ,rest) form))
(string-join (mapcar #'format-form rest) " ")))
(format-priority (form)
(pcase-let* ((`(priority . ,rest) form)
(args (pcase rest
(`(,(and comparator (or '< '<= '> '>= '=)) ,letter)
(priority-letters comparator letter))
(_ rest))))
(concat "priority:" (string-join args ","))))
(priority-letters (comparator letter)
(let* ((char (string-to-char (upcase (symbol-name letter))))
(numeric-priorities '(?A ?B ?C))
;; NOTE: The comparator inversion is intentional.
(others (pcase comparator
('< (--select (> it char) numeric-priorities))
('<= (--select (>= it char) numeric-priorities))
('> (--select (< it char) numeric-priorities))
('>= (--select (<= it char) numeric-priorities))
('= (--select (= it char) numeric-priorities)))))
(mapcar #'char-to-string others))))
;; FIXME: Error out for ts structs passed to `ts' predicate (very unlikely to be linked to).
(unless (complex-p query)
(pcase query

View file

@ -72,7 +72,13 @@ Functions / Macros
Changelog
* 0.8-pre: 08-pre.
* 0.9-pre: 09-pre.
* 0.8.4: 084.
* 0.8.3: 083.
* 0.8.2: 082.
* 0.8.1: 081.
* 0.8: 08.
* 0.7.4: 074.
* 0.7.3: 073.
* 0.7.2: 072.
* 0.7.1: 071.
@ -236,7 +242,9 @@ completion facilities with an Org QL query:
Note that these commands are compatible with Embark
(https://github.com/oantolin/embark): the embark-act command can be
called on a completion candidate (i.e. a search result) to act on it
immediately, without having to visit the entry in its source Org buffer.
immediately, without having to visit the entry in its source Org buffer,
and embark-export may be called to show the results in an
org-ql-view buffer.

File: README.info, Node: org-ql-open-link, Next: org-ql-refile, Prev: org-ql-find, Up: Commands
@ -520,9 +528,8 @@ Arguments are listed next to predicate names, where applicable.
Return non-nil if current entry has PROPERTY (a string), and
optionally VALUE (a string). If INHERIT is nil, only match
entries with PROPERTY set on the entry; if t, also match entries
with inheritance. If INHERIT is not specified, use the Boolean
value of org-use-property-inheritance, which see (i.e. it is
only interpreted as nil or non-nil).
with inheritance. If INHERIT is not specified, use the value of
org-use-property-inheritance, which see.
regexp (&rest regexps)
Return non-nil if current entry matches all of REGEXPS (regexp
strings). Matches against entire entry, from beginning of its
@ -1026,7 +1033,13 @@ releases.
* Menu:
* 0.8-pre: 08-pre.
* 0.9-pre: 09-pre.
* 0.8.4: 084.
* 0.8.3: 083.
* 0.8.2: 082.
* 0.8.1: 081.
* 0.8: 08.
* 0.7.4: 074.
* 0.7.3: 073.
* 0.7.2: 072.
* 0.7.1: 071.
@ -1058,11 +1071,75 @@ releases.
* 0.1: 01.

File: README.info, Node: 08-pre, Next: 073, Up: Changelog
File: README.info, Node: 09-pre, Next: 084, Up: Changelog
5.1 0.8-pre
5.1 0.9-pre
===========
Nothing new yet.

File: README.info, Node: 084, Next: 083, Prev: 09-pre, Up: Changelog
5.2 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.3 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.4 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.5 0.8.1
=========
*Fixes*
• Command org-ql-find widens the buffer before going to the
selected entry.
• In org-ql-view buffers, links in headings remain clickable links.
(Fixes #282 (https://github.com/alphapapa/org-ql/issues/282).
Thanks to Jacob Boxerman (https://github.com/jakebox) for
reporting.)

File: README.info, Node: 08, Next: 074, Prev: 081, Up: Changelog
5.6 0.8
=======
*Additions*
• Function org-ql-completing-read, used by command org-ql-find,
@ -1075,6 +1152,10 @@ File: README.info, Node: 08-pre, Next: 073, Up: Changelog
Thanks to Omar Antolín Camarena (https://github.com/oantolin),
Daniel Mendler (https://github.com/minad), and Akira Komamura
(https://github.com/akirak).)
• Command org-ql-completing-read-export, bound to C-c C-e or
embark-export while in an org-ql-completing-read session,
exits and shows an org-ql-view buffer for the current
search.
• Command org-ql-find may be called in an org-agenda or
org-ql-view buffer to search the buffers which contributed to the
agenda/view buffer.
@ -1087,18 +1168,42 @@ File: README.info, Node: 08-pre, Next: 073, Up: Changelog
containing the desired link, then locate it within the entry, and
then open it, the user can simply select the link and open it
directly.)
• Items in org-ql-view buffers now include the org-category text
property, like Org Agenda buffers, which allows grouping with
org-super-agendas category-related selectors. (#363
(https://github.com/alphapapa/org-ql/issues/363). Thanks to
Gabriele Mongiano (https://github.com/kofm) for reporting.)
*Fixes*
• Predicate property correctly uses the value of
org-use-property-inheritance when not specified. (#346
(https://github.com/alphapapa/org-ql/pull/346), #356
(https://github.com/alphapapa/org-ql/issues/356). Thanks to Bram
Schoenmakers (https://github.com/bram85).)
*Compatibility*
• Emacs 27.1 or later is now required.
• Org v9.7s org-element API changes required some adjustments.
(#364 (https://github.com/alphapapa/org-ql/issues/364). Thanks to
several users for reporting, and to Ihor Radchenko
(https://github.com/yantar92) for his feedback.)

File: README.info, Node: 073, Next: 072, Prev: 08-pre, Up: Changelog
File: README.info, Node: 074, Next: 073, Prev: 08, Up: Changelog
5.2 0.7.3
5.7 0.7.4
=========
*Fixes*
• Ignore empty quoted strings in plain-string queries (#383
(https://github.com/alphapapa/org-ql/issues/383)).

File: README.info, Node: 073, Next: 072, Prev: 074, Up: Changelog
5.8 0.7.3
=========
*Fixes*
@ -1116,7 +1221,7 @@ File: README.info, Node: 073, Next: 072, Prev: 08-pre, Up: Changelog

File: README.info, Node: 072, Next: 071, Prev: 073, Up: Changelog
5.3 0.7.2
5.9 0.7.2
=========
*Fixes*
@ -1137,8 +1242,8 @@ File: README.info, Node: 072, Next: 071, Prev: 073, Up: Changelog

File: README.info, Node: 071, Next: 07, Prev: 072, Up: Changelog
5.4 0.7.1
=========
5.10 0.7.1
==========
*Fixes*
• Function org-ql-completing-read is more compatible with default
@ -1156,13 +1261,12 @@ File: README.info, Node: 071, Next: 07, Prev: 072, Up: Changelog

File: README.info, Node: 07, Next: 063, Prev: 071, Up: Changelog
5.5 0.7
=======
5.11 0.7
========
*Added*
• Commands org-ql-find, org-ql-find-heading, and
org-ql-find-path, which jump to entries selected using Emacss
built-in completion facilities and Org QL queries (like
• Command org-ql-find, which jumps to entries selected using
Emacss built-in completion facilities and Org QL queries (like
helm-org-ql, but doesnt require Helm.).
• Command org-ql-refile, which refiles the entry at point to one
selected using Org QL completion.
@ -1216,8 +1320,8 @@ File: README.info, Node: 07, Next: 063, Prev: 071, Up: Changelog

File: README.info, Node: 063, Next: 062, Prev: 07, Up: Changelog
5.6 0.6.3
=========
5.12 0.6.3
==========
*Fixed*
• Non-sexp query parsing with updated version 1.0.1 of the peg
@ -1232,8 +1336,8 @@ File: README.info, Node: 063, Next: 062, Prev: 07, Up: Changelog

File: README.info, Node: 062, Next: 061, Prev: 063, Up: Changelog
5.7 0.6.2
=========
5.13 0.6.2
==========
*Fixed*
link predicate when used in an ored query. (#279
@ -1243,8 +1347,8 @@ File: README.info, Node: 062, Next: 061, Prev: 063, Up: Changelog

File: README.info, Node: 061, Next: 06, Prev: 062, Up: Changelog
5.8 0.6.1
=========
5.14 0.6.1
==========
*Fixed*
• In dynamic blocks, links to headings with statistics cookies were
@ -1261,8 +1365,8 @@ File: README.info, Node: 061, Next: 06, Prev: 062, Up: Changelog

File: README.info, Node: 06, Next: 052, Prev: 061, Up: Changelog
5.9 0.6
=======
5.15 0.6
========
*Added*
• Macro org-ql-defpred, used to define search predicates. (See
@ -1328,7 +1432,7 @@ File: README.info, Node: 06, Next: 052, Prev: 061, Up: Changelog

File: README.info, Node: 052, Next: 051, Prev: 06, Up: Changelog
5.10 0.5.2
5.16 0.5.2
==========
*Fixed*
@ -1339,7 +1443,7 @@ File: README.info, Node: 052, Next: 051, Prev: 06, Up: Changelog

File: README.info, Node: 051, Next: 05, Prev: 052, Up: Changelog
5.11 0.5.1
5.17 0.5.1
==========
*Fixed*
@ -1352,7 +1456,7 @@ File: README.info, Node: 051, Next: 05, Prev: 052, Up: Changelog

File: README.info, Node: 05, Next: 049, Prev: 051, Up: Changelog
5.12 0.5
5.18 0.5
========
*Added*
@ -1393,7 +1497,7 @@ File: README.info, Node: 05, Next: 049, Prev: 051, Up: Changelog

File: README.info, Node: 049, Next: 048, Prev: 05, Up: Changelog
5.13 0.4.9
5.19 0.4.9
==========
*Fixed*
@ -1404,7 +1508,7 @@ File: README.info, Node: 049, Next: 048, Prev: 05, Up: Changelog

File: README.info, Node: 048, Next: 047, Prev: 049, Up: Changelog
5.14 0.4.8
5.20 0.4.8
==========
*Fixed*
@ -1416,7 +1520,7 @@ File: README.info, Node: 048, Next: 047, Prev: 049, Up: Changelog

File: README.info, Node: 047, Next: 046, Prev: 048, Up: Changelog
5.15 0.4.7
5.21 0.4.7
==========
*Fixed*
@ -1429,7 +1533,7 @@ File: README.info, Node: 047, Next: 046, Prev: 048, Up: Changelog

File: README.info, Node: 046, Next: 045, Prev: 047, Up: Changelog
5.16 0.4.6
5.22 0.4.6
==========
*Fixed*
@ -1442,7 +1546,7 @@ File: README.info, Node: 046, Next: 045, Prev: 047, Up: Changelog

File: README.info, Node: 045, Next: 044, Prev: 046, Up: Changelog
5.17 0.4.5
5.23 0.4.5
==========
*Fixed*
@ -1454,7 +1558,7 @@ File: README.info, Node: 045, Next: 044, Prev: 046, Up: Changelog

File: README.info, Node: 044, Next: 043, Prev: 045, Up: Changelog
5.18 0.4.4
5.24 0.4.4
==========
*Fixed*
@ -1466,7 +1570,7 @@ File: README.info, Node: 044, Next: 043, Prev: 045, Up: Changelog

File: README.info, Node: 043, Next: 042, Prev: 044, Up: Changelog
5.19 0.4.3
5.25 0.4.3
==========
*Fixed*
@ -1476,7 +1580,7 @@ File: README.info, Node: 043, Next: 042, Prev: 044, Up: Changelog

File: README.info, Node: 042, Next: 041, Prev: 043, Up: Changelog
5.20 0.4.2
5.26 0.4.2
==========
*Fixed*
@ -1485,7 +1589,7 @@ File: README.info, Node: 042, Next: 041, Prev: 043, Up: Changelog

File: README.info, Node: 041, Next: 04, Prev: 042, Up: Changelog
5.21 0.4.1
5.27 0.4.1
==========
*Fixed*
@ -1495,7 +1599,7 @@ File: README.info, Node: 041, Next: 04, Prev: 042, Up: Changelog

File: README.info, Node: 04, Next: 032, Prev: 041, Up: Changelog
5.22 0.4
5.28 0.4
========
_Note:_ The next release, 0.5, may include changes which will require
@ -1576,7 +1680,7 @@ automatically, as they will be pushed to the master branch when ready.

File: README.info, Node: 032, Next: 031, Prev: 04, Up: Changelog
5.23 0.3.2
5.29 0.3.2
==========
*Fixed*
@ -1589,7 +1693,7 @@ File: README.info, Node: 032, Next: 031, Prev: 04, Up: Changelog

File: README.info, Node: 031, Next: 03, Prev: 032, Up: Changelog
5.24 0.3.1
5.30 0.3.1
==========
*Fixed*
@ -1599,7 +1703,7 @@ File: README.info, Node: 031, Next: 03, Prev: 032, Up: Changelog

File: README.info, Node: 03, Next: 023, Prev: 031, Up: Changelog
5.25 0.3
5.31 0.3
========
*Added*
@ -1667,7 +1771,7 @@ File: README.info, Node: 03, Next: 023, Prev: 031, Up: Changelog

File: README.info, Node: 023, Next: 022, Prev: 03, Up: Changelog
5.26 0.2.3
5.32 0.2.3
==========
*Fixed*
@ -1677,7 +1781,7 @@ File: README.info, Node: 023, Next: 022, Prev: 03, Up: Changelog

File: README.info, Node: 022, Next: 021, Prev: 023, Up: Changelog
5.27 0.2.2
5.33 0.2.2
==========
*Fixed*
@ -1688,7 +1792,7 @@ File: README.info, Node: 022, Next: 021, Prev: 023, Up: Changelog

File: README.info, Node: 021, Next: 02, Prev: 022, Up: Changelog
5.28 0.2.1
5.34 0.2.1
==========
*Fixed*
@ -1698,7 +1802,7 @@ File: README.info, Node: 021, Next: 02, Prev: 022, Up: Changelog

File: README.info, Node: 02, Next: 01, Prev: 021, Up: Changelog
5.29 0.2
5.35 0.2
========
*Added*
@ -1781,7 +1885,7 @@ File: README.info, Node: 02, Next: 01, Prev: 021, Up: Changelog

File: README.info, Node: 01, Prev: 02, Up: Changelog
5.30 0.1
5.36 0.1
========
First tagged release.
@ -1839,75 +1943,81 @@ GPLv3

Tag Table:
Node: Top225
Node: Contents1845
Node: Screenshots1968
Node: Installation2086
Node: Quelpa2600
Node: Helm support3128
Node: Usage3531
Node: Commands3929
Node: org-ql-find4394
Node: org-ql-open-link5212
Node: org-ql-refile6067
Node: org-ql-search6395
Node: helm-org-ql8326
Node: org-ql-view8704
Node: org-ql-view-sidebar9234
Node: org-ql-view-recent-items9614
Node: org-ql-sparse-tree10110
Node: Queries10910
Node: Non-sexp query syntax12027
Node: General predicates13786
Node: Ancestor/descendant predicates20773
Node: Date/time predicates21901
Node: Functions / Macros25025
Node: Agenda-like views25323
Ref: Function org-ql-block25485
Node: Listing / acting-on results26746
Ref: Caching26954
Ref: Function org-ql-select27867
Ref: Function org-ql-query30293
Ref: Macro org-ql (deprecated)32067
Node: Custom predicates32382
Ref: Macro org-ql-defpred32606
Node: Dynamic block36047
Node: Links38771
Node: Tips39458
Node: Changelog39782
Node: 08-pre40592
Node: 07342357
Node: 07243092
Node: 07144011
Node: 0744820
Node: 06347744
Node: 06248275
Node: 06148580
Node: 0649148
Node: 05252202
Node: 05152504
Node: 0552929
Node: 04954460
Node: 04854742
Node: 04755091
Node: 04655500
Node: 04555908
Node: 04456269
Node: 04356628
Node: 04256831
Node: 04156992
Node: 0457239
Node: 03261340
Node: 03161743
Node: 0361940
Node: 02365240
Node: 02265474
Node: 02165754
Node: 0265959
Node: 0170037
Node: Notes70138
Node: Comparison with Org Agenda searches70300
Node: org-sidebar71189
Node: License71468
Node: Contents1926
Node: Screenshots2049
Node: Installation2167
Node: Quelpa2681
Node: Helm support3209
Node: Usage3612
Node: Commands4010
Node: org-ql-find4475
Node: org-ql-open-link5383
Node: org-ql-refile6238
Node: org-ql-search6566
Node: helm-org-ql8497
Node: org-ql-view8875
Node: org-ql-view-sidebar9405
Node: org-ql-view-recent-items9785
Node: org-ql-sparse-tree10281
Node: Queries11081
Node: Non-sexp query syntax12198
Node: General predicates13957
Node: Ancestor/descendant predicates20882
Node: Date/time predicates22010
Node: Functions / Macros25134
Node: Agenda-like views25432
Ref: Function org-ql-block25594
Node: Listing / acting-on results26855
Ref: Caching27063
Ref: Function org-ql-select27976
Ref: Function org-ql-query30402
Ref: Macro org-ql (deprecated)32176
Node: Custom predicates32491
Ref: Macro org-ql-defpred32715
Node: Dynamic block36156
Node: Links38880
Node: Tips39567
Node: Changelog39891
Node: 09-pre40782
Node: 08440889
Node: 08341344
Node: 08241685
Node: 08142078
Node: 0842499
Node: 07445223
Node: 07345446
Node: 07246178
Node: 07147097
Node: 0747908
Node: 06350774
Node: 06251307
Node: 06151614
Node: 0652184
Node: 05255240
Node: 05155542
Node: 0555967
Node: 04957498
Node: 04857780
Node: 04758129
Node: 04658538
Node: 04558946
Node: 04459307
Node: 04359666
Node: 04259869
Node: 04160030
Node: 0460277
Node: 03264378
Node: 03164781
Node: 0364978
Node: 02368278
Node: 02268512
Node: 02168792
Node: 0268997
Node: 0173075
Node: Notes73176
Node: Comparison with Org Agenda searches73338
Node: org-sidebar74227
Node: License74506

End Tag Table

View file

@ -648,6 +648,14 @@ with keyword arg NOW in PLIST."
;; TODO: Other predicates.
(it "Ignores empty quoted strings"
(expect (org-ql--query-string-to-sexp "\"\"")
:to-equal nil)
(expect (org-ql--query-string-to-sexp "foo \"\" bar")
:to-equal '(and (rifle "foo") (rifle "bar")))
(expect (org-ql--query-string-to-sexp "foo \"baz\" bar")
:to-equal '(and (rifle "foo") (rifle "baz") (rifle "bar"))))
(it "Negated terms"
(expect (org-ql--query-string-to-sexp "todo: !todo:CHECK,SOMEDAY")
:to-equal '(and (todo) (not (todo "CHECK" "SOMEDAY"))))
@ -1836,14 +1844,14 @@ with keyword arg NOW in PLIST."
;; have a chance to be gathered. So we make a test buffer and run the test in that, with a test heading.
(let ((test-buffer (get-buffer-create "*test-org-ql*")))
(cl-flet ((open-link
(link) (with-current-buffer test-buffer
(erase-buffer)
(org-mode)
(insert "* TODO Test heading \n\n")
(insert link)
(backward-char 1)
(call-interactively #'org-open-at-point))))
(cl-flet ((open-link (link)
(with-current-buffer test-buffer
(erase-buffer)
(org-mode)
(insert "* TODO Test heading \n\n")
(insert link)
(backward-char 1)
(call-interactively #'org-open-at-point))))
(describe "buffers-files parameter"
:var ((quoted-lambda-link "[[org-ql-search:todo:?buffers-files%3D%28lambda%20nil%20%28error%20%22UNSAFE%22%29%29]]")
@ -1998,16 +2006,15 @@ with keyword arg NOW in PLIST."
(when-let ((buffer (find-file-noselect filename 'nowarn)))
(kill-buffer buffer))))
(cl-flet ((var-after-bookmark-set-and-jump
(var buffers-files query &key sort super-groups)
(org-ql-search buffers-files query
:super-groups super-groups
:sort sort :title title :buffer view-buffer)
(set-buffer view-buffer)
(bookmark-set title)
(kill-buffer)
(bookmark-jump title)
(buffer-local-value var (get-buffer (concat "*Org QL View: " title "*")))))
(cl-flet ((var-after-bookmark-set-and-jump (var buffers-files query &key sort super-groups)
(org-ql-search buffers-files query
:super-groups super-groups
:sort sort :title title :buffer view-buffer)
(set-buffer view-buffer)
(bookmark-set title)
(kill-buffer)
(bookmark-jump title)
(buffer-local-value var (get-buffer (concat "*Org QL View: " title "*")))))
(describe "Grouping"
:var ((query '(and (todo "TODO") (regexp "heading")))
@ -2061,18 +2068,18 @@ with keyword arg NOW in PLIST."
(describe "Dynamic blocks"
(describe "warn about sexp queries"
(cl-flet ((test-dblock
(&optional input) (with-current-buffer (get-buffer-create "*TEST DBLOCK*")
(erase-buffer)
(org-mode)
(insert "* TODO Heading 1\n\n"
"#+BEGIN: org-ql :query (or (todo) (regexp \"Heading\")) :columns (todo)\n"
"#+END:")
(goto-char (point-min))
(forward-line 2)
(with-simulated-input input
(org-dblock-update))
(kill-buffer))))
(cl-flet ((test-dblock (&optional input)
(with-current-buffer (get-buffer-create "*TEST DBLOCK*")
(erase-buffer)
(org-mode)
(insert "* TODO Heading 1\n\n"
"#+BEGIN: org-ql :query (or (todo) (regexp \"Heading\")) :columns (todo)\n"
"#+END:")
(goto-char (point-min))
(forward-line 2)
(with-simulated-input input
(org-dblock-update))
(kill-buffer))))
(it "when org-ql-ask-unsafe-queries is non-nil"
;; TODO: Should the query be converted to string form if possible and only warn if not?
@ -2101,39 +2108,37 @@ with keyword arg NOW in PLIST."
(insert "* TODO Test heading\n\n")
(org-mode)))
(cl-flet* ((open-link-in
(link buffer input)
;; Org REDUCED THE NUMBER OF ARGUMENTS TO `org-open-link-from-string'! That BREAKS BACKWARD
;; COMPATIBILITY! So I have to make my own function so these tests can work across Org versions!
(with-current-buffer buffer
(erase-buffer)
(org-mode)
(insert "* TODO Test heading\n\n")
(insert link)
(backward-char 1)
(with-simulated-input input
(org-open-at-point))))
(cl-flet* ((open-link-in (link buffer input)
;; Org REDUCED THE NUMBER OF ARGUMENTS TO `org-open-link-from-string'! That BREAKS BACKWARD
;; COMPATIBILITY! So I have to make my own function so these tests can work across Org versions!
(with-current-buffer buffer
(erase-buffer)
(org-mode)
(insert "* TODO Test heading\n\n")
(insert link)
(backward-char 1)
(with-simulated-input input
(org-open-at-point))))
(var-after-link-save-open
(var buffers-files query &key sort super-groups
(buffer link-buffer) (store-input "RET") open-input)
(org-ql-search buffers-files query
:super-groups super-groups
:sort sort :title title :buffer view-buffer)
(with-current-buffer view-buffer
(cl-assert (member '("org-ql-search" :follow org-ql-view--link-follow :store org-ql-view--link-store)
org-link-parameters)
t)
(with-simulated-input store-input
;; Avoid writing "Stored: ..." to test output.
(let ((inhibit-message t))
(call-interactively #'org-store-link nil)))
(kill-buffer))
(cl-assert (and org-stored-links (caar org-stored-links)) t)
(open-link-in (caar org-stored-links) buffer open-input)
(with-current-buffer (get-buffer (concat "*Org QL View: " title "*"))
(prog1 (buffer-local-value var (current-buffer))
(kill-buffer)))))
(var-after-link-save-open (var buffers-files query &key sort super-groups
(buffer link-buffer) (store-input "RET") open-input)
(org-ql-search buffers-files query
:super-groups super-groups
:sort sort :title title :buffer view-buffer)
(with-current-buffer view-buffer
(cl-assert (member '("org-ql-search" :follow org-ql-view--link-follow :store org-ql-view--link-store)
org-link-parameters)
t)
(with-simulated-input store-input
;; Avoid writing "Stored: ..." to test output.
(let ((inhibit-message t))
(call-interactively #'org-store-link nil)))
(kill-buffer))
(cl-assert (and org-stored-links (caar org-stored-links)) t)
(open-link-in (caar org-stored-links) buffer open-input)
(with-current-buffer (get-buffer (concat "*Org QL View: " title "*"))
(prog1 (buffer-local-value var (current-buffer))
(kill-buffer)))))
(describe "Queries"
:var ((string-query "todo:TODO regexp:heading")