Compare commits
2 commits
master
...
wip/todo-k
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be7e8f1bcd | ||
|
|
6d9f9b21df |
78
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
|
|
@ -1,78 +0,0 @@
|
||||||
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
|
|
@ -1,5 +0,0 @@
|
||||||
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.
|
|
||||||
45
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
|
|
@ -1,45 +0,0 @@
|
||||||
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
|
|
||||||
|
|
||||||
81
.github/workflows/test.yml
vendored
|
|
@ -1,81 +0,0 @@
|
||||||
# * test.yml --- Test Emacs packages using makem.sh on GitHub Actions
|
|
||||||
|
|
||||||
# URL: https://github.com/alphapapa/makem.sh
|
|
||||||
# Version: 0.3
|
|
||||||
|
|
||||||
# * Commentary:
|
|
||||||
|
|
||||||
# Based on Steve Purcell's examples at
|
|
||||||
# <https://github.com/purcell/setup-emacs/blob/master/.github/workflows/test.yml>,
|
|
||||||
# <https://github.com/purcell/package-lint/blob/master/.github/workflows/test.yml>.
|
|
||||||
|
|
||||||
# * License:
|
|
||||||
|
|
||||||
# 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
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
# * Code:
|
|
||||||
|
|
||||||
name: "CI"
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
push:
|
|
||||||
# Comment out this section to enable testing of all branches.
|
|
||||||
# branches:
|
|
||||||
# - master
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
emacs_version:
|
|
||||||
- 27.1
|
|
||||||
- 27.2
|
|
||||||
- 28.1
|
|
||||||
- 28.2
|
|
||||||
- 29.1
|
|
||||||
- 29.2
|
|
||||||
- 29.3
|
|
||||||
- 29.4
|
|
||||||
- snapshot
|
|
||||||
steps:
|
|
||||||
- uses: purcell/setup-emacs@master
|
|
||||||
with:
|
|
||||||
version: ${{ matrix.emacs_version }}
|
|
||||||
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Initialize sandbox
|
|
||||||
run: |
|
|
||||||
SANDBOX_DIR=$(mktemp -d) || exit 1
|
|
||||||
echo "SANDBOX_DIR=$SANDBOX_DIR" >> $GITHUB_ENV
|
|
||||||
./makem.sh -vv --sandbox=$SANDBOX_DIR --install-deps --install-linters
|
|
||||||
|
|
||||||
# The "all" rule is not used, because it treats compilation warnings
|
|
||||||
# as failures, so linting and testing are run as separate steps.
|
|
||||||
|
|
||||||
- name: Lint
|
|
||||||
# NOTE: Uncomment this line to treat lint failures as passing
|
|
||||||
# so the job doesn't show failure.
|
|
||||||
continue-on-error: true
|
|
||||||
run: ./makem.sh -vv --sandbox=$SANDBOX_DIR lint
|
|
||||||
|
|
||||||
- name: Test
|
|
||||||
if: always() # Run test even if linting fails.
|
|
||||||
run: ./makem.sh -vv --sandbox=$SANDBOX_DIR test
|
|
||||||
|
|
||||||
# Local Variables:
|
|
||||||
# eval: (outline-minor-mode)
|
|
||||||
# End:
|
|
||||||
7
.gitignore
vendored
|
|
@ -2,10 +2,3 @@
|
||||||
.#*
|
.#*
|
||||||
/scratch.el
|
/scratch.el
|
||||||
.cask
|
.cask
|
||||||
/sandbox/
|
|
||||||
/.sandbox/
|
|
||||||
/scratch.org
|
|
||||||
/scratch/
|
|
||||||
/worktrees/
|
|
||||||
/worktree/
|
|
||||||
/NOTES.org
|
|
||||||
|
|
|
||||||
10
Cask
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
(package-file "org-ql.el")
|
||||||
|
|
||||||
|
(files "org-ql.el" "org-ql-agenda.el")
|
||||||
|
|
||||||
|
(source gnu)
|
||||||
|
(source melpa)
|
||||||
|
|
||||||
|
(development
|
||||||
|
(depends-on "buttercup")
|
||||||
|
(depends-on "xr"))
|
||||||
48
Makefile
|
|
@ -1,46 +1,11 @@
|
||||||
# * makem.sh/Makefile --- Script to aid building and testing Emacs Lisp packages
|
# * Verbosity
|
||||||
|
|
||||||
# URL: https://github.com/alphapapa/makem.sh
|
|
||||||
# Version: 0.5
|
|
||||||
|
|
||||||
# * Arguments
|
|
||||||
|
|
||||||
# For consistency, we use only var=val options, not hyphen-prefixed options.
|
|
||||||
|
|
||||||
# NOTE: I don't like duplicating the arguments here and in makem.sh,
|
|
||||||
# but I haven't been able to find a way to pass arguments which
|
|
||||||
# conflict with Make's own arguments through Make to the script.
|
|
||||||
# Using -- doesn't seem to do it.
|
|
||||||
|
|
||||||
ifdef install-deps
|
|
||||||
INSTALL_DEPS = "--install-deps"
|
|
||||||
endif
|
|
||||||
ifdef install-linters
|
|
||||||
INSTALL_LINTERS = "--install-linters"
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifdef sandbox
|
|
||||||
ifeq ($(sandbox), t)
|
|
||||||
SANDBOX = --sandbox
|
|
||||||
else
|
|
||||||
SANDBOX = --sandbox=$(sandbox)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifdef debug
|
|
||||||
DEBUG = "--debug"
|
|
||||||
endif
|
|
||||||
|
|
||||||
# ** Verbosity
|
|
||||||
|
|
||||||
# Since the "-v" in "make -v" gets intercepted by Make itself, we have
|
# Since the "-v" in "make -v" gets intercepted by Make itself, we have
|
||||||
# to use a variable.
|
# to use a variable.
|
||||||
|
|
||||||
verbose = $(v)
|
verbose = $(v)
|
||||||
|
|
||||||
ifneq (,$(findstring vvv,$(verbose)))
|
ifneq (,$(findstring vv,$(verbose)))
|
||||||
VERBOSE = "-vvv"
|
|
||||||
else ifneq (,$(findstring vv,$(verbose)))
|
|
||||||
VERBOSE = "-vv"
|
VERBOSE = "-vv"
|
||||||
else ifneq (,$(findstring v,$(verbose)))
|
else ifneq (,$(findstring v,$(verbose)))
|
||||||
VERBOSE = "-v"
|
VERBOSE = "-v"
|
||||||
|
|
@ -48,12 +13,5 @@ endif
|
||||||
|
|
||||||
# * Rules
|
# * Rules
|
||||||
|
|
||||||
# TODO: Handle cases in which "test" or "tests" are called and a
|
|
||||||
# directory by that name exists, which can confuse Make.
|
|
||||||
|
|
||||||
%:
|
%:
|
||||||
@./makem.sh $(DEBUG) $(VERBOSE) $(SANDBOX) $(INSTALL_DEPS) $(INSTALL_LINTERS) $(@)
|
@./makem.sh $(VERBOSE) $(@)
|
||||||
|
|
||||||
.DEFAULT: init
|
|
||||||
init:
|
|
||||||
@./makem.sh $(DEBUG) $(VERBOSE) $(SANDBOX) $(INSTALL_DEPS) $(INSTALL_LINTERS)
|
|
||||||
|
|
|
||||||
1
NOTES
|
|
@ -1 +0,0 @@
|
||||||
Note: Notes are kept in the file "NOTES.org" in the "meta/notes" branch.
|
|
||||||
964
README.org
203
examples.org
|
|
@ -2,83 +2,12 @@
|
||||||
|
|
||||||
* Contents
|
* Contents
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:TOC: :include siblings :ignore this
|
:TOC: this
|
||||||
:END:
|
:END:
|
||||||
:CONTENTS:
|
- [[#find-entries-matching-a-certain-custom_id][Find entries matching a certain CUSTOM_ID]]
|
||||||
- [[#custom-predicates][Custom predicates]]
|
- [[#show-entries-with-recent-timestamps][Show entries with recent timestamps]]
|
||||||
- [[#agenda-like-view][Agenda-like view]]
|
- [[#stuck-projects-block-agenda][Stuck projects block agenda]]
|
||||||
- [[#entries-from-the-past-week][Entries from the past week]]
|
- [[#listing-bills-coming-due][Listing bills coming due]]
|
||||||
- [[#find-entries-matching-a-certain-custom_id][Find entries matching a certain CUSTOM_ID]]
|
|
||||||
- [[#listing-bills-coming-due][Listing bills coming due]]
|
|
||||||
- [[#music-database][Music database]]
|
|
||||||
- [[#return-org-elements][Return Org elements]]
|
|
||||||
- [[#set-tags-on-certain-entries][Set tags on certain entries]]
|
|
||||||
- [[#show-entries-with-recent-timestamps][Show entries with recent timestamps]]
|
|
||||||
- [[#stuck-projects-block-agenda][Stuck projects block agenda]]
|
|
||||||
- [[#subproject-and-subtask-queries][Subproject and subtask queries]]
|
|
||||||
- [[#task-list-for-files-in-subdirectories][Task list for files in subdirectories]]
|
|
||||||
:END:
|
|
||||||
|
|
||||||
* Custom predicates
|
|
||||||
|
|
||||||
+ [[file:examples/defpred.org][Custom predicate tutorial]]
|
|
||||||
|
|
||||||
* Agenda-like view
|
|
||||||
|
|
||||||
Show an agenda-like view, similar to a "traditional" Org Agenda with Log Mode turned on.
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp
|
|
||||||
(org-ql-search (org-agenda-files)
|
|
||||||
'(or (and (not (done))
|
|
||||||
(or (habit)
|
|
||||||
(deadline auto)
|
|
||||||
(scheduled :to today)
|
|
||||||
(ts-active :on today)))
|
|
||||||
(closed :on today))
|
|
||||||
:sort '(todo priority date))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
Another example, showing grouping with [[https://github.com/alphapapa/org-super-agenda][org-super-agenda]]:
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp
|
|
||||||
(org-ql-search "~/src/emacs/org-super-agenda/test/test.org"
|
|
||||||
'(and (or (ts-active :on today)
|
|
||||||
(deadline auto)
|
|
||||||
(scheduled :to today))
|
|
||||||
(not (done)))
|
|
||||||
:title "My Agenda View"
|
|
||||||
;; The `org-super-agenda-groups' setting is used automatically when set, or it
|
|
||||||
;; may be overriden by specifying it here:
|
|
||||||
:super-groups '((:name "Bills"
|
|
||||||
:tag "bills")
|
|
||||||
(:todo ("SOMEDAY" "TO-READ" "CHECK" "TO-WATCH" "WATCHING")
|
|
||||||
:order 7)
|
|
||||||
(:name "Personal"
|
|
||||||
:habit t
|
|
||||||
:tag "personal"
|
|
||||||
:order 3)
|
|
||||||
(:todo "WAITING"
|
|
||||||
:order 6)
|
|
||||||
(:priority "A" :order 1)
|
|
||||||
(:priority "B" :order 2)
|
|
||||||
(:priority "C" :order 2)))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
Which displays this buffer:
|
|
||||||
|
|
||||||
[[images/screenshot.png]]
|
|
||||||
|
|
||||||
* Entries from the past week
|
|
||||||
|
|
||||||
Show entries that have any timestamp within the past week. Group by date using =org-super-agenda= with the =:auto-ts= group.
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp
|
|
||||||
(org-ql-search (org-agenda-files)
|
|
||||||
'(ts :from -7 :to today)
|
|
||||||
:title "Recent Items"
|
|
||||||
:sort '(todo priority date)
|
|
||||||
:super-groups '((:auto-ts t)))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
* Find entries matching a certain =CUSTOM_ID=
|
* Find entries matching a certain =CUSTOM_ID=
|
||||||
|
|
||||||
|
|
@ -94,58 +23,6 @@ Since queries can contain both built-in =org-ql= predicate expressions and arbit
|
||||||
|
|
||||||
Using the =property= predicate as the first clause of the two clauses joined with =and= allows =org-ql= to optimize the query by searching through the buffer directly to entries that set the =CUSTOM_ID= property, which is much faster than testing every entry in a buffer. Also, If the query were only the =string-match= call, it would signal an error on entries that didn't have the property set, because =org-entry-get= would return nil.
|
Using the =property= predicate as the first clause of the two clauses joined with =and= allows =org-ql= to optimize the query by searching through the buffer directly to entries that set the =CUSTOM_ID= property, which is much faster than testing every entry in a buffer. Also, If the query were only the =string-match= call, it would signal an error on entries that didn't have the property set, because =org-entry-get= would return nil.
|
||||||
|
|
||||||
* Listing bills coming due
|
|
||||||
|
|
||||||
This uses the example in the readme file, but maps across the elements returned by ~org-ql~ to present a simple list of titles and deadlines.
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp
|
|
||||||
(org-ql-query
|
|
||||||
:select '(list (substring-no-properties (org-get-heading t t))
|
|
||||||
(org-entry-get (point) "DEADLINE"))
|
|
||||||
:from (org-agenda-files)
|
|
||||||
:where '(and (not (done))
|
|
||||||
(tags "bills")
|
|
||||||
(deadline auto))
|
|
||||||
:order-by 'deadline)
|
|
||||||
;;=> (("Electric bill" "<2018-08-23 Thu +1m>")
|
|
||||||
;; ("Rent" "<2018-09-01 Sat +1m>"))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
This could also be put in a script, which could use desktop notifications to remind of bills coming due: [[examples/org-bills-due.el][org-bills-due.el]].
|
|
||||||
|
|
||||||
* Music database
|
|
||||||
|
|
||||||
If you kept a database of music in an Org file, you could run a query like this to find tracks composed by Chopin that do not have their key recorded in the database.
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp
|
|
||||||
(org-ql-search "~/org/music.org"
|
|
||||||
'(and (property "genre" "classical")
|
|
||||||
(property "composer" "Chopin")
|
|
||||||
(not (property "key"))))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
* Return Org elements
|
|
||||||
|
|
||||||
Return a list of Org entry elements in the file =~/org/main.org= which have the =SOMEDAY= to-do keyword, are tagged =Emacs=, and have priority B or higher. =org-ql= is the macro version of =org-ql-select=; it does not require quoting the query sexp.
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp
|
|
||||||
(org-ql "~/org/main.org"
|
|
||||||
(and (todo "SOMEDAY")
|
|
||||||
(tags "Emacs")
|
|
||||||
(priority >= "B")))
|
|
||||||
;;=> ((headline (:raw-value "org-board" :begin 1220270 :end 1220403 ...)) ...)
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
* Set tags on certain entries
|
|
||||||
|
|
||||||
Set the tag =Emacs= on every entry in the inbox file that mentions =Emacs=. The bare-string query ="Emacs"= is equivalent to ~(regexp "Emacs")~.
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp
|
|
||||||
(org-ql-select "~/org/inbox.org"
|
|
||||||
"Emacs"
|
|
||||||
:action '(org-toggle-tag "Emacs" 'on))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
* Show entries with recent timestamps
|
* Show entries with recent timestamps
|
||||||
|
|
||||||
You can also access these views with the command ~org-ql-view~.
|
You can also access these views with the command ~org-ql-view~.
|
||||||
|
|
@ -182,71 +59,27 @@ With this =org-ql-block= agenda view, like:
|
||||||
((org-ql-block-header "Stuck Projects")))))))
|
((org-ql-block-header "Stuck Projects")))))))
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
* Subproject and subtask queries
|
* Listing bills coming due
|
||||||
|
|
||||||
|
This uses the example in the readme file, but maps across the elements returned by ~org-ql~ to present a simple list of titles and deadlines.
|
||||||
|
|
||||||
#+BEGIN_SRC elisp
|
#+BEGIN_SRC elisp
|
||||||
;; Search for subprojects.
|
(org-ql (org-agenda-files)
|
||||||
(org-ql-search (org-agenda-files)
|
|
||||||
'(and (todo "PROJECT")
|
|
||||||
(ancestors (todo "PROJECT"))))
|
|
||||||
|
|
||||||
;; Search for all subtasks of projects, grouped by parent heading.
|
|
||||||
(org-ql-search (org-agenda-files)
|
|
||||||
'(and (todo)
|
|
||||||
(ancestors (todo "PROJECT")))
|
|
||||||
:super-groups '((:auto-parent t)))
|
|
||||||
|
|
||||||
;; Search for direct top-level tasks of projects.
|
|
||||||
(org-ql-search (org-agenda-files)
|
|
||||||
'(and (todo)
|
|
||||||
(parent (todo "PROJECT")))
|
|
||||||
:super-groups '((:auto-parent t)))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
Of course, all of those presume using a =PROJECT= keyword to define projects. If one defines a project as any task which has an ancestor task, one could use queries like:
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp
|
|
||||||
;; Search for all subtasks of top-level projects, grouped by parent heading.
|
|
||||||
(org-ql-search (org-agenda-files)
|
|
||||||
'(and (todo)
|
|
||||||
(ancestors
|
|
||||||
(and (todo)
|
|
||||||
(not (parent)))))
|
|
||||||
:super-groups '((:auto-parent t)))
|
|
||||||
|
|
||||||
;; Search for all subtasks of all projects, including subprojects, grouped by project.
|
|
||||||
(org-ql-search (org-agenda-files)
|
|
||||||
'(and (todo)
|
|
||||||
(ancestors (todo)))
|
|
||||||
:super-groups '((:auto-parent t)))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
Other interesting queries:
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp
|
|
||||||
;; Subtasks of upcoming deadline items.
|
|
||||||
(org-ql-search (org-agenda-files)
|
|
||||||
'(and (todo)
|
|
||||||
(ancestors
|
|
||||||
(and (not (done))
|
(and (not (done))
|
||||||
(deadline auto))))
|
(tags "bills")
|
||||||
:super-groups '((:auto-parent t)))
|
(deadline auto))
|
||||||
|
:action (list (substring-no-properties (org-get-heading t t))
|
||||||
;; TODO items whose ancestor is already DONE, and should therefore be
|
(org-entry-get (point) "DEADLINE"))
|
||||||
;; either marked DONE or CANCELLED.
|
:sort deadline)
|
||||||
(org-ql-search (org-agenda-files)
|
;;=> (("Electric bill" "<2018-08-23 Thu +1m>")
|
||||||
'(and (todo)
|
;; ("Rent" "<2018-09-01 Sat +1m>"))
|
||||||
(ancestors (done)))
|
|
||||||
:super-groups '((:auto-parent t)))
|
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
* Task list for files in subdirectories
|
This could also be put in a script, which could use desktop notifications to remind of bills coming due: [[examples/org-bills-due.el][org-bills-due.el]].
|
||||||
|
|
||||||
[[images/org-ql-search-snippet.png]]
|
|
||||||
|
|
||||||
* COMMENT Code :noexport:
|
* COMMENT Code :noexport:
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:TOC: :ignore (this descendants)
|
:TOC: ignore
|
||||||
:END:
|
:END:
|
||||||
|
|
||||||
** File-local variables
|
** File-local variables
|
||||||
|
|
|
||||||
|
|
@ -1,766 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
||||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
|
||||||
<head>
|
|
||||||
<!-- 2020-11-23 Mon 03:31 -->
|
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
||||||
<title>Org QL Custom Predicates Tutorial</title>
|
|
||||||
<meta name="generator" content="Org mode" />
|
|
||||||
<style type="text/css">
|
|
||||||
<!--/*--><![CDATA[/*><!--*/
|
|
||||||
.title { text-align: center;
|
|
||||||
margin-bottom: .2em; }
|
|
||||||
.subtitle { text-align: center;
|
|
||||||
font-size: medium;
|
|
||||||
font-weight: bold;
|
|
||||||
margin-top:0; }
|
|
||||||
.todo { font-family: monospace; color: red; }
|
|
||||||
.done { font-family: monospace; color: green; }
|
|
||||||
.priority { font-family: monospace; color: orange; }
|
|
||||||
.tag { background-color: #eee; font-family: monospace;
|
|
||||||
padding: 2px; font-size: 80%; font-weight: normal; }
|
|
||||||
.timestamp { color: #bebebe; }
|
|
||||||
.timestamp-kwd { color: #5f9ea0; }
|
|
||||||
.org-right { margin-left: auto; margin-right: 0px; text-align: right; }
|
|
||||||
.org-left { margin-left: 0px; margin-right: auto; text-align: left; }
|
|
||||||
.org-center { margin-left: auto; margin-right: auto; text-align: center; }
|
|
||||||
.underline { text-decoration: underline; }
|
|
||||||
#postamble p, #preamble p { font-size: 90%; margin: .2em; }
|
|
||||||
p.verse { margin-left: 3%; }
|
|
||||||
pre {
|
|
||||||
border: 1px solid #ccc;
|
|
||||||
box-shadow: 3px 3px 3px #eee;
|
|
||||||
padding: 8pt;
|
|
||||||
font-family: monospace;
|
|
||||||
overflow: auto;
|
|
||||||
margin: 1.2em;
|
|
||||||
}
|
|
||||||
pre.src {
|
|
||||||
position: relative;
|
|
||||||
overflow: visible;
|
|
||||||
padding-top: 1.2em;
|
|
||||||
}
|
|
||||||
pre.src:before {
|
|
||||||
display: none;
|
|
||||||
position: absolute;
|
|
||||||
background-color: white;
|
|
||||||
top: -10px;
|
|
||||||
right: 10px;
|
|
||||||
padding: 3px;
|
|
||||||
border: 1px solid black;
|
|
||||||
}
|
|
||||||
pre.src:hover:before { display: inline;}
|
|
||||||
/* Languages per Org manual */
|
|
||||||
pre.src-asymptote:before { content: 'Asymptote'; }
|
|
||||||
pre.src-awk:before { content: 'Awk'; }
|
|
||||||
pre.src-C:before { content: 'C'; }
|
|
||||||
/* pre.src-C++ doesn't work in CSS */
|
|
||||||
pre.src-clojure:before { content: 'Clojure'; }
|
|
||||||
pre.src-css:before { content: 'CSS'; }
|
|
||||||
pre.src-D:before { content: 'D'; }
|
|
||||||
pre.src-ditaa:before { content: 'ditaa'; }
|
|
||||||
pre.src-dot:before { content: 'Graphviz'; }
|
|
||||||
pre.src-calc:before { content: 'Emacs Calc'; }
|
|
||||||
pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
|
|
||||||
pre.src-fortran:before { content: 'Fortran'; }
|
|
||||||
pre.src-gnuplot:before { content: 'gnuplot'; }
|
|
||||||
pre.src-haskell:before { content: 'Haskell'; }
|
|
||||||
pre.src-java:before { content: 'Java'; }
|
|
||||||
pre.src-js:before { content: 'Javascript'; }
|
|
||||||
pre.src-latex:before { content: 'LaTeX'; }
|
|
||||||
pre.src-ledger:before { content: 'Ledger'; }
|
|
||||||
pre.src-lisp:before { content: 'Lisp'; }
|
|
||||||
pre.src-lilypond:before { content: 'Lilypond'; }
|
|
||||||
pre.src-lua:before { content: 'Lua'; }
|
|
||||||
pre.src-matlab:before { content: 'MATLAB'; }
|
|
||||||
pre.src-mscgen:before { content: 'Mscgen'; }
|
|
||||||
pre.src-ocaml:before { content: 'Objective Caml'; }
|
|
||||||
pre.src-octave:before { content: 'Octave'; }
|
|
||||||
pre.src-org:before { content: 'Org mode'; }
|
|
||||||
pre.src-oz:before { content: 'OZ'; }
|
|
||||||
pre.src-plantuml:before { content: 'Plantuml'; }
|
|
||||||
pre.src-processing:before { content: 'Processing.js'; }
|
|
||||||
pre.src-python:before { content: 'Python'; }
|
|
||||||
pre.src-R:before { content: 'R'; }
|
|
||||||
pre.src-ruby:before { content: 'Ruby'; }
|
|
||||||
pre.src-sass:before { content: 'Sass'; }
|
|
||||||
pre.src-scheme:before { content: 'Scheme'; }
|
|
||||||
pre.src-screen:before { content: 'Gnu Screen'; }
|
|
||||||
pre.src-sed:before { content: 'Sed'; }
|
|
||||||
pre.src-sh:before { content: 'shell'; }
|
|
||||||
pre.src-sql:before { content: 'SQL'; }
|
|
||||||
pre.src-sqlite:before { content: 'SQLite'; }
|
|
||||||
/* additional languages in org.el's org-babel-load-languages alist */
|
|
||||||
pre.src-forth:before { content: 'Forth'; }
|
|
||||||
pre.src-io:before { content: 'IO'; }
|
|
||||||
pre.src-J:before { content: 'J'; }
|
|
||||||
pre.src-makefile:before { content: 'Makefile'; }
|
|
||||||
pre.src-maxima:before { content: 'Maxima'; }
|
|
||||||
pre.src-perl:before { content: 'Perl'; }
|
|
||||||
pre.src-picolisp:before { content: 'Pico Lisp'; }
|
|
||||||
pre.src-scala:before { content: 'Scala'; }
|
|
||||||
pre.src-shell:before { content: 'Shell Script'; }
|
|
||||||
pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
|
|
||||||
/* additional language identifiers per "defun org-babel-execute"
|
|
||||||
in ob-*.el */
|
|
||||||
pre.src-cpp:before { content: 'C++'; }
|
|
||||||
pre.src-abc:before { content: 'ABC'; }
|
|
||||||
pre.src-coq:before { content: 'Coq'; }
|
|
||||||
pre.src-groovy:before { content: 'Groovy'; }
|
|
||||||
/* additional language identifiers from org-babel-shell-names in
|
|
||||||
ob-shell.el: ob-shell is the only babel language using a lambda to put
|
|
||||||
the execution function name together. */
|
|
||||||
pre.src-bash:before { content: 'bash'; }
|
|
||||||
pre.src-csh:before { content: 'csh'; }
|
|
||||||
pre.src-ash:before { content: 'ash'; }
|
|
||||||
pre.src-dash:before { content: 'dash'; }
|
|
||||||
pre.src-ksh:before { content: 'ksh'; }
|
|
||||||
pre.src-mksh:before { content: 'mksh'; }
|
|
||||||
pre.src-posh:before { content: 'posh'; }
|
|
||||||
/* Additional Emacs modes also supported by the LaTeX listings package */
|
|
||||||
pre.src-ada:before { content: 'Ada'; }
|
|
||||||
pre.src-asm:before { content: 'Assembler'; }
|
|
||||||
pre.src-caml:before { content: 'Caml'; }
|
|
||||||
pre.src-delphi:before { content: 'Delphi'; }
|
|
||||||
pre.src-html:before { content: 'HTML'; }
|
|
||||||
pre.src-idl:before { content: 'IDL'; }
|
|
||||||
pre.src-mercury:before { content: 'Mercury'; }
|
|
||||||
pre.src-metapost:before { content: 'MetaPost'; }
|
|
||||||
pre.src-modula-2:before { content: 'Modula-2'; }
|
|
||||||
pre.src-pascal:before { content: 'Pascal'; }
|
|
||||||
pre.src-ps:before { content: 'PostScript'; }
|
|
||||||
pre.src-prolog:before { content: 'Prolog'; }
|
|
||||||
pre.src-simula:before { content: 'Simula'; }
|
|
||||||
pre.src-tcl:before { content: 'tcl'; }
|
|
||||||
pre.src-tex:before { content: 'TeX'; }
|
|
||||||
pre.src-plain-tex:before { content: 'Plain TeX'; }
|
|
||||||
pre.src-verilog:before { content: 'Verilog'; }
|
|
||||||
pre.src-vhdl:before { content: 'VHDL'; }
|
|
||||||
pre.src-xml:before { content: 'XML'; }
|
|
||||||
pre.src-nxml:before { content: 'XML'; }
|
|
||||||
/* add a generic configuration mode; LaTeX export needs an additional
|
|
||||||
(add-to-list 'org-latex-listings-langs '(conf " ")) in .emacs */
|
|
||||||
pre.src-conf:before { content: 'Configuration File'; }
|
|
||||||
|
|
||||||
table { border-collapse:collapse; }
|
|
||||||
caption.t-above { caption-side: top; }
|
|
||||||
caption.t-bottom { caption-side: bottom; }
|
|
||||||
td, th { vertical-align:top; }
|
|
||||||
th.org-right { text-align: center; }
|
|
||||||
th.org-left { text-align: center; }
|
|
||||||
th.org-center { text-align: center; }
|
|
||||||
td.org-right { text-align: right; }
|
|
||||||
td.org-left { text-align: left; }
|
|
||||||
td.org-center { text-align: center; }
|
|
||||||
dt { font-weight: bold; }
|
|
||||||
.footpara { display: inline; }
|
|
||||||
.footdef { margin-bottom: 1em; }
|
|
||||||
.figure { padding: 1em; }
|
|
||||||
.figure p { text-align: center; }
|
|
||||||
.inlinetask {
|
|
||||||
padding: 10px;
|
|
||||||
border: 2px solid gray;
|
|
||||||
margin: 10px;
|
|
||||||
background: #ffffcc;
|
|
||||||
}
|
|
||||||
#org-div-home-and-up
|
|
||||||
{ text-align: right; font-size: 70%; white-space: nowrap; }
|
|
||||||
textarea { overflow-x: auto; }
|
|
||||||
.linenr { font-size: smaller }
|
|
||||||
.code-highlighted { background-color: #ffff00; }
|
|
||||||
.org-info-js_info-navigation { border-style: none; }
|
|
||||||
#org-info-js_console-label
|
|
||||||
{ font-size: 10px; font-weight: bold; white-space: nowrap; }
|
|
||||||
.org-info-js_search-highlight
|
|
||||||
{ background-color: #ffff00; color: #000000; font-weight: bold; }
|
|
||||||
.org-svg { width: 90%; }
|
|
||||||
/*]]>*/-->
|
|
||||||
</style>
|
|
||||||
<link rel="stylesheet" type="text/css" href="export/styles/darksun/css/darksun.css"/>
|
|
||||||
<script type="text/javascript" src="export/styles/darksun/js/jquery-1.11.0.min.js"></script>
|
|
||||||
<script type="text/javascript" src="export/styles/darksun/js/jquery-ui-1.10.2.min.js"></script>
|
|
||||||
<script type="text/javascript" src="export/styles/darksun/js/jquery.localscroll-min.js"></script>
|
|
||||||
<script type="text/javascript" src="export/styles/darksun/js/jquery.scrollTo-1.4.3.1-min.js"></script>
|
|
||||||
<script type="text/javascript" src="export/styles/darksun/js/jquery.zclip.min.js"></script>
|
|
||||||
<script type="text/javascript" src="export/styles/darksun/js/darksun.js"></script>
|
|
||||||
<script type="text/javascript" src="export/styles/lib/js/jquery.stickytableheaders.min.js"></script>
|
|
||||||
<script type="text/javascript">
|
|
||||||
/*
|
|
||||||
@licstart The following is the entire license notice for the
|
|
||||||
JavaScript code in this tag.
|
|
||||||
|
|
||||||
Copyright (C) 2012-2013 Free Software Foundation, Inc.
|
|
||||||
|
|
||||||
The JavaScript code in this tag is free software: you can
|
|
||||||
redistribute it and/or modify it under the terms of the GNU
|
|
||||||
General Public License (GNU GPL) as published by the Free Software
|
|
||||||
Foundation, either version 3 of the License, or (at your option)
|
|
||||||
any later version. The code is distributed WITHOUT ANY WARRANTY;
|
|
||||||
without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
||||||
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
|
|
||||||
|
|
||||||
As additional permission under GNU GPL version 3 section 7, you
|
|
||||||
may distribute non-source (e.g., minimized or compacted) forms of
|
|
||||||
that code without the copy of the GNU GPL normally required by
|
|
||||||
section 4, provided you include this license notice and a URL
|
|
||||||
through which recipients can access the Corresponding Source.
|
|
||||||
|
|
||||||
|
|
||||||
@licend The above is the entire license notice
|
|
||||||
for the JavaScript code in this tag.
|
|
||||||
*/
|
|
||||||
<!--/*--><![CDATA[/*><!--*/
|
|
||||||
function CodeHighlightOn(elem, id)
|
|
||||||
{
|
|
||||||
var target = document.getElementById(id);
|
|
||||||
if(null != target) {
|
|
||||||
elem.cacheClassElem = elem.className;
|
|
||||||
elem.cacheClassTarget = target.className;
|
|
||||||
target.className = "code-highlighted";
|
|
||||||
elem.className = "code-highlighted";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function CodeHighlightOff(elem, id)
|
|
||||||
{
|
|
||||||
var target = document.getElementById(id);
|
|
||||||
if(elem.cacheClassElem)
|
|
||||||
elem.className = elem.cacheClassElem;
|
|
||||||
if(elem.cacheClassTarget)
|
|
||||||
target.className = elem.cacheClassTarget;
|
|
||||||
}
|
|
||||||
/*]]>*///-->
|
|
||||||
</script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="content">
|
|
||||||
<h1 class="title">Org QL Custom Predicates Tutorial</h1>
|
|
||||||
<div id="table-of-contents">
|
|
||||||
<h2>Table of Contents</h2>
|
|
||||||
<div id="text-table-of-contents">
|
|
||||||
<ul>
|
|
||||||
<li><a href="#Using%20built-in%20predicates">Using built-in predicates</a></li>
|
|
||||||
<li><a href="#A%20custom%20~%28person%29~%20predicate">A custom <code>(person)</code> predicate</a></li>
|
|
||||||
<li><a href="#Searching%20for%20multiple%20people%20at%20once">Searching for multiple people at once</a></li>
|
|
||||||
<li><a href="#Normalizing%20queries%20to%20rewrite%20arguments">Normalizing queries to rewrite arguments</a></li>
|
|
||||||
<li><a href="#Non-sexp%20query%20syntax">Non-sexp query syntax</a></li>
|
|
||||||
<li><a href="#Using%20multiple%20predicates">Using multiple predicates</a></li>
|
|
||||||
<li><a href="#Predicate%20aliases">Predicate aliases</a></li>
|
|
||||||
<li><a href="#Be%20formless">Be formless</a></li>
|
|
||||||
<li><a href="#Conclusion">Conclusion</a></li>
|
|
||||||
<li><a href="#Appendix%3A%20Anaphoric%20macros">Appendix: Anaphoric macros</a></li>
|
|
||||||
<li><a href="#Example%20data">Example data</a>
|
|
||||||
<ul>
|
|
||||||
<li><a href="#Loud%20pet%20parakeet">Loud pet parakeet   <span class="tag"><span class="personAlice">personAlice</span></span></a></li>
|
|
||||||
<li><a href="#Missing%20sticky%20notes">Missing sticky notes   <span class="tag"><span class="personAlice">personAlice</span></span></a></li>
|
|
||||||
<li><a href="#Dirty%20dishes%20in%20sink">Dirty dishes in sink   <span class="tag"><span class="personAlice">personAlice</span></span></a></li>
|
|
||||||
<li><a href="#Stinky%20coffee%20breath">Stinky coffee breath</a></li>
|
|
||||||
</ul>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<p>
|
|
||||||
<span class="timestamp-wrapper"><span class="timestamp">[2020-11-22 Sun 22:35] </span></span> Imagine you have weekly meetings with other people, and during the week you take notes about items to discuss at each meeting. When the time for a meeting comes, you want to quickly and easily search for all of the items to discuss at the meeting.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
You've been experimenting with different ways to track such data in Org. You've tried using tags, but some of the names in question conflict with other tags in your data (e.g. someone's named Charles, but you also work with a firm named Charles, Inc., and you'd prefer to continue using the tag <code>Charles</code> for entries about that firm), so you've been using tags like <code>:personNAME:</code>, which seems awkward. You've tried using a <code>:person: NAME</code> property on entries, which has the advantage of not cluttering the tags list, but also the disadvantage of not being readily visible in an outline.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
So you haven't decided on a long-term solution, but the meetings aren't going to wait–you need to search that data now, and you have a mix of both tags and properties in your entries. What you need is to be able to search for all of the entries about Alice (which you've tagged <code>:personAlice:</code>) when you're meeting with her, and all of the entries about Bob (which have the property <code>:person: Bob</code>) when you're meeting with him. What do you do?
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div id="outline-container-Using%20built-in%20predicates" class="outline-2">
|
|
||||||
<h2 id="Using%20built-in%20predicates">Using built-in predicates</h2>
|
|
||||||
<div class="outline-text-2" id="text-Using%20built-in%20predicates">
|
|
||||||
<p>
|
|
||||||
You could start by using built-in Org QL predicates to search your data. For example:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="org-src-container">
|
|
||||||
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql-query</span><span style="color: #3d85b7;"> </span><span style="color: #3d85b7; font-weight: bold;">:select</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">org-get-heading </span><span style="color: #78880e; font-weight: bold;">:no-tags</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:from</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">current-buffer</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:where</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e; font-weight: bold;">or</span><span style="color: #78880e;"> (</span><span style="color: #3d8b85; text-decoration: underline;">tags</span><span style="color: #3d8b85;"> </span><span style="color: #65bc957591ca;">"personAlice"</span><span style="color: #78880e;">)</span>
|
|
||||||
<span style="color: #78880e;">(</span><span style="color: #3d8b85; text-decoration: underline;">property</span><span style="color: #3d8b85;"> </span><span style="color: #65bc957591ca;">"person"</span> <span style="color: #65bc957591ca;">"Bob"</span><span style="color: #78880e;">)</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<ul class="org-ul">
|
|
||||||
<li>[#A] Loud pet parakeet</li>
|
|
||||||
<li>[#C] Missing sticky notes</li>
|
|
||||||
<li>[#C] Dirty dishes in sink</li>
|
|
||||||
<li>[#A] Stinky coffee breath</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
That was easy enough, but it's not very…semantic. You have to think about the implementation details: Alice uses tags, Bob uses properties, and what if Charlie uses both? It starts to feel complicated, and it's a lot to type out every time. Is there an easier way?
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="outline-container-A%20custom%20~%28person%29~%20predicate" class="outline-2">
|
|
||||||
<h2 id="A%20custom%20~%28person%29~%20predicate">A custom <code>(person)</code> predicate</h2>
|
|
||||||
<div class="outline-text-2" id="text-A%20custom%20~%28person%29~%20predicate">
|
|
||||||
<p>
|
|
||||||
Enter <code>org-ql</code> custom search predicates. Let's start simple, by defining a predicate to search for just the <code>:person:</code> property, one person at a time. The predicate will take one argument, a person's name, and search for that property. It would look like this:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="org-src-container">
|
|
||||||
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; font-weight: bold;">org-ql-defpred</span><span style="color: #3d85b7;"> person (</span><span style="color: #78880e;">name</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #73139976b41e;">"Search for entries with the \"person\" property being NAME."</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:body</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">property</span><span style="color: #78880e;"> </span><span style="color: #921da24c26e6;">"person"</span> <span style="color: #78880e;">name</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
Now, let's see what results we get for searching this file for entries about Bob:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="org-src-container">
|
|
||||||
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql-query</span><span style="color: #3d85b7;"> </span><span style="color: #3d85b7; font-weight: bold;">:select</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">org-get-heading </span><span style="color: #78880e; font-weight: bold;">:no-tags</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:from</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">current-buffer</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:where</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">person </span><span style="color: #921da24c26e6;">"Bob"</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<ul class="org-ul">
|
|
||||||
<li>[#C] Missing sticky notes</li>
|
|
||||||
<li>[#C] Dirty dishes in sink</li>
|
|
||||||
<li>[#A] Stinky coffee breath</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
Hmm, looks like we need to remind Bob to wash his mug and take some mints after lunch. Now what do we need to discuss with Alice?
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="org-src-container">
|
|
||||||
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql-query</span><span style="color: #3d85b7;"> </span><span style="color: #3d85b7; font-weight: bold;">:select</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">org-get-heading </span><span style="color: #78880e; font-weight: bold;">:no-tags</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:from</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">current-buffer</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:where</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">person </span><span style="color: #921da24c26e6;">"Alice"</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<pre class="example">
|
|
||||||
</pre>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
Nothing? Oh, right, Alice's entries use the <code>:personAlice:</code> tag, so we'll also need to search those kind of entries. Let's make the predicate do that, too:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="org-src-container">
|
|
||||||
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; font-weight: bold;">org-ql-defpred</span><span style="color: #3d85b7;"> person (</span><span style="color: #78880e;">name</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #73139976b41e;">"Search for entries with the \"person\" property being NAME or having the tag \"personNAME\"."</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:body</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; font-weight: bold;">or</span><span style="color: #78880e;"> (</span><span style="color: #3d8b85; text-decoration: underline;">property</span><span style="color: #3d8b85;"> </span><span style="color: #65bc957591ca;">"person"</span> <span style="color: #3d8b85;">name</span><span style="color: #78880e;">)</span>
|
|
||||||
<span style="color: #78880e;">(</span><span style="color: #3d8b85; text-decoration: underline;">tags</span><span style="color: #3d8b85;"> (</span><span style="color: #a17e11; text-decoration: underline;">concat</span><span style="color: #a17e11;"> </span><span style="color: #b86396762cce;">"person"</span> <span style="color: #a17e11;">name</span><span style="color: #3d8b85;">)</span><span style="color: #78880e;">)</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
How about now?
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="org-src-container">
|
|
||||||
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql-query</span><span style="color: #3d85b7;"> </span><span style="color: #3d85b7; font-weight: bold;">:select</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">org-get-heading </span><span style="color: #78880e; font-weight: bold;">:no-tags</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:from</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">current-buffer</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:where</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">person </span><span style="color: #921da24c26e6;">"Alice"</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<ul class="org-ul">
|
|
||||||
<li>[#A] Loud pet parakeet</li>
|
|
||||||
<li>[#C] Missing sticky notes</li>
|
|
||||||
<li>[#C] Dirty dishes in sink</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
Hmm, I thought we already told her to leave Polly at home.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="outline-container-Searching%20for%20multiple%20people%20at%20once" class="outline-2">
|
|
||||||
<h2 id="Searching%20for%20multiple%20people%20at%20once">Searching for multiple people at once</h2>
|
|
||||||
<div class="outline-text-2" id="text-Searching%20for%20multiple%20people%20at%20once">
|
|
||||||
<p>
|
|
||||||
Oh, wait, this week is shortened due to holidays, so we're having a combined meeting. How do we search for entries about either of them? Well, this is the obvious solution:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="org-src-container">
|
|
||||||
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql-query</span><span style="color: #3d85b7;"> </span><span style="color: #3d85b7; font-weight: bold;">:select</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">org-get-heading </span><span style="color: #78880e; font-weight: bold;">:no-tags</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:from</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">current-buffer</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:where</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e; font-weight: bold;">or</span><span style="color: #78880e;"> (</span><span style="color: #3d8b85;">person </span><span style="color: #65bc957591ca;">"Alice"</span><span style="color: #78880e;">)</span>
|
|
||||||
<span style="color: #78880e;">(</span><span style="color: #3d8b85;">person </span><span style="color: #65bc957591ca;">"Bob"</span><span style="color: #78880e;">)</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<ul class="org-ul">
|
|
||||||
<li>[#A] Loud pet parakeet</li>
|
|
||||||
<li>[#C] Missing sticky notes</li>
|
|
||||||
<li>[#C] Dirty dishes in sink</li>
|
|
||||||
<li>[#A] Stinky coffee breath</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
And that works fine. But it seems like a lot to type. Could we make the <code>person</code> predicate accept multiple names instead?
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="org-src-container">
|
|
||||||
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; font-weight: bold;">org-ql-defpred</span><span style="color: #3d85b7;"> person (</span><span style="color: #78880e;">&rest</span><span style="color: #78880e;"> names</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #73139976b41e;">"Search for entries about any of NAMES."</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:body</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; font-weight: bold;">cl-loop</span><span style="color: #78880e;"> for name in names</span>
|
|
||||||
<span style="color: #78880e;"> thereis (</span><span style="color: #3d8b85; font-weight: bold;">or</span><span style="color: #3d8b85;"> (</span><span style="color: #a17e11; text-decoration: underline;">property</span><span style="color: #a17e11;"> </span><span style="color: #b86396762cce;">"person"</span> <span style="color: #a17e11;">name</span><span style="color: #3d8b85;">)</span>
|
|
||||||
<span style="color: #3d8b85;">(</span><span style="color: #a17e11; text-decoration: underline;">tags</span><span style="color: #a17e11;"> (</span><span style="color: #3d85b7; text-decoration: underline;">concat</span><span style="color: #3d85b7;"> </span><span style="color: #73139976b41e;">"person"</span> <span style="color: #3d85b7;">name</span><span style="color: #a17e11;">)</span><span style="color: #3d8b85;">)</span><span style="color: #78880e;">)</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
Now let's search again:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="org-src-container">
|
|
||||||
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql-query</span><span style="color: #3d85b7;"> </span><span style="color: #3d85b7; font-weight: bold;">:select</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">org-get-heading </span><span style="color: #78880e; font-weight: bold;">:no-tags</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:from</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">current-buffer</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:where</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">person </span><span style="color: #921da24c26e6;">"Alice"</span> <span style="color: #921da24c26e6;">"Bob"</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<ul class="org-ul">
|
|
||||||
<li>[#A] Loud pet parakeet</li>
|
|
||||||
<li>[#C] Missing sticky notes</li>
|
|
||||||
<li>[#C] Dirty dishes in sink</li>
|
|
||||||
<li>[#A] Stinky coffee breath</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
That was easy!
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="outline-container-Normalizing%20queries%20to%20rewrite%20arguments" class="outline-2">
|
|
||||||
<h2 id="Normalizing%20queries%20to%20rewrite%20arguments">Normalizing queries to rewrite arguments</h2>
|
|
||||||
<div class="outline-text-2" id="text-Normalizing%20queries%20to%20rewrite%20arguments">
|
|
||||||
<p>
|
|
||||||
Now, all this is well and good if you don't have hundreds of thousands of Org entries in your files. But what if you do? All that <code>concat</code>'ing happening on every entry could add up, and the query might take a few seconds. What if we could do that stringing-along just once, before running the query? We want to turn our <code>(person "Alice" "Bob")</code> query into this, with the <code>:personNAME:</code> strings already made and the per-person <code>(property ...)</code> predicates also included:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="org-src-container">
|
|
||||||
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; font-weight: bold;">or</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">tags</span><span style="color: #78880e;"> </span><span style="color: #921da24c26e6;">"personAlice"</span> <span style="color: #921da24c26e6;">"personBob"</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #3d85b7;">(</span><span style="color: #78880e; text-decoration: underline;">property</span><span style="color: #78880e;"> </span><span style="color: #921da24c26e6;">"person"</span> <span style="color: #921da24c26e6;">"Alice"</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #3d85b7;">(</span><span style="color: #78880e; text-decoration: underline;">property</span><span style="color: #78880e;"> </span><span style="color: #921da24c26e6;">"person"</span> <span style="color: #921da24c26e6;">"Bob"</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
Can we do that? In fact, we can, by using a query normalizer. Normalizers are <code>pcase</code> forms (I <i>know</i>) that normalize query expressions before execution. We can use one to rewrite the query ahead of time, like this:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="org-src-container">
|
|
||||||
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; font-weight: bold;">org-ql-defpred</span><span style="color: #3d85b7;"> person (</span><span style="color: #78880e;">&rest</span><span style="color: #78880e;"> names</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #73139976b41e;">"Search for entries about any of NAMES."</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:normalizers</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e;">(</span><span style="color: #3d8b85;">`(</span><span style="color: #a17e11;">person . ,names</span><span style="color: #3d8b85;">)</span>
|
|
||||||
<span style="color: #3d8b85;">`(</span><span style="color: #a17e11; font-weight: bold;">or</span><span style="color: #a17e11;"> (</span><span style="color: #3d85b7; text-decoration: underline;">tags</span><span style="color: #3d85b7;"> ,@(</span><span style="color: #78880e; font-weight: bold;">cl-loop</span><span style="color: #78880e;"> for name in names</span>
|
|
||||||
<span style="color: #78880e;"> collect (</span><span style="color: #3d8b85; text-decoration: underline;">concat</span><span style="color: #3d8b85;"> </span><span style="color: #65bc957591ca;">"person"</span> <span style="color: #3d8b85;">name</span><span style="color: #78880e;">)</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
|
|
||||||
<span style="color: #a17e11;">,@(</span><span style="color: #3d85b7; font-weight: bold;">cl-loop</span><span style="color: #3d85b7;"> for name in names</span>
|
|
||||||
<span style="color: #3d85b7;"> collect `(</span><span style="color: #78880e;">property </span><span style="color: #921da24c26e6;">"person"</span> <span style="color: #78880e;">,name</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span><span style="color: #3d8b85;">)</span><span style="color: #78880e;">)</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:body</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; font-weight: bold;">cl-loop</span><span style="color: #78880e;"> for name in names</span>
|
|
||||||
<span style="color: #78880e;"> thereis (</span><span style="color: #3d8b85; font-weight: bold;">or</span><span style="color: #3d8b85;"> (</span><span style="color: #a17e11; text-decoration: underline;">property</span><span style="color: #a17e11;"> </span><span style="color: #b86396762cce;">"person"</span> <span style="color: #a17e11;">name</span><span style="color: #3d8b85;">)</span>
|
|
||||||
<span style="color: #3d8b85;">(</span><span style="color: #a17e11; text-decoration: underline;">tags</span><span style="color: #a17e11;"> name</span><span style="color: #3d8b85;">)</span><span style="color: #78880e;">)</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
Now, don't faint from all the backquoting and unquoting–it's just Lisp, nothing to be afraid of! Let's slow down a moment and see what the normalized query looks like to be sure we're doing it correctly:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="org-src-container">
|
|
||||||
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql--normalize-query</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">person </span><span style="color: #921da24c26e6;">"Alice"</span> <span style="color: #921da24c26e6;">"Bob"</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="org-src-container">
|
|
||||||
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; font-weight: bold;">or</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">tags</span><span style="color: #78880e;"> </span><span style="color: #921da24c26e6;">"personAlice"</span> <span style="color: #921da24c26e6;">"personBob"</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #3d85b7;">(</span><span style="color: #78880e; text-decoration: underline;">property</span><span style="color: #78880e;"> </span><span style="color: #921da24c26e6;">"person"</span> <span style="color: #921da24c26e6;">"Alice"</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #3d85b7;">(</span><span style="color: #78880e; text-decoration: underline;">property</span><span style="color: #78880e;"> </span><span style="color: #921da24c26e6;">"person"</span> <span style="color: #921da24c26e6;">"Bob"</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
And, as they say, Bob's your uncle! Or even if he isn't, let's see if it works:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="org-src-container">
|
|
||||||
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql-query</span><span style="color: #3d85b7;"> </span><span style="color: #3d85b7; font-weight: bold;">:select</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">org-get-heading </span><span style="color: #78880e; font-weight: bold;">:no-tags</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:from</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">current-buffer</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:where</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">person </span><span style="color: #921da24c26e6;">"Alice"</span> <span style="color: #921da24c26e6;">"Bob"</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<ul class="org-ul">
|
|
||||||
<li>[#A] Loud pet parakeet</li>
|
|
||||||
<li>[#C] Missing sticky notes</li>
|
|
||||||
<li>[#C] Dirty dishes in sink</li>
|
|
||||||
<li>[#A] Stinky coffee breath</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
Yep, same result as the non-normalized query. And look at how much simpler it is to write <code>(person "Alice" "Bob")</code> than to write <code>(or (tags "personAlice" "personBob") (property "person" "Alice") (property "person" "Bob"))</code>.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="outline-container-Non-sexp%20query%20syntax" class="outline-2">
|
|
||||||
<h2 id="Non-sexp%20query%20syntax">Non-sexp query syntax</h2>
|
|
||||||
<div class="outline-text-2" id="text-Non-sexp%20query%20syntax">
|
|
||||||
<p>
|
|
||||||
But wait, that's not all! If you order now, we'll throw in non-sexp query syntax for free! That's right, your search could be as simple as typing <code>person:Alice,Bob</code>!
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="org-src-container">
|
|
||||||
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql-search</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">current-buffer</span><span style="color: #3d85b7;">)</span> <span style="color: #73139976b41e;">"person:Alice,Bob"</span><span style="color: #a17e11;">)</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
Don't believe me? Well, you see, queries in this syntax are converted to the sexp syntax, like:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="org-src-container">
|
|
||||||
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql--query-string-to-sexp</span><span style="color: #3d85b7;"> </span><span style="color: #73139976b41e;">"person:Alice,Bob"</span><span style="color: #a17e11;">)</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="org-src-container">
|
|
||||||
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7;">person </span><span style="color: #73139976b41e;">"Alice"</span> <span style="color: #73139976b41e;">"Bob"</span><span style="color: #a17e11;">)</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
And that happens automatically when you use a search command like <code>org-ql-search</code>. If you have <code>org-ql</code> installed already, you could even click this link: <a href="person:Alice,Bob">Alice or Bob</a>. Which, in Org syntax, looks like:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="org-src-container">
|
|
||||||
<pre class="src src-org"><span style="color: #b58900; text-decoration: underline;"><a href="org-ql-search:person:Alice,Bob">org-ql-search:person:Alice,Bob</a></span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
And that would open an Agenda Mode buffer that looks like this:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<pre class="example">
|
|
||||||
Query: (person "Alice" "Bob") In:meetings.org
|
|
||||||
[#A] Loud pet parakeet :personAlice:
|
|
||||||
[#C] Missing sticky notes :personAlice:
|
|
||||||
[#C] Dirty dishes in sink :personAlice:
|
|
||||||
[#A] Stinky coffee breath
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="outline-container-Using%20multiple%20predicates" class="outline-2">
|
|
||||||
<h2 id="Using%20multiple%20predicates">Using multiple predicates</h2>
|
|
||||||
<div class="outline-text-2" id="text-Using%20multiple%20predicates">
|
|
||||||
<p>
|
|
||||||
Oops, you forgot that there's a birthday party in 20 minutes, so you only have time to talk about the highest priority items at this joint meeting today.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
No problem, let's just select high-priority items:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="org-src-container">
|
|
||||||
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql-search</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">current-buffer</span><span style="color: #3d85b7;">)</span> <span style="color: #73139976b41e;">"person:Alice,Bob priority:A"</span><span style="color: #a17e11;">)</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
Which shows:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<pre class="example">
|
|
||||||
Query: (and (person "Alice" "Bob") (priority "A")) In:meetings.org
|
|
||||||
[#A] Loud pet parakeet :personAlice:
|
|
||||||
[#A] Stinky coffee breath
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="outline-container-Predicate%20aliases" class="outline-2">
|
|
||||||
<h2 id="Predicate%20aliases">Predicate aliases</h2>
|
|
||||||
<div class="outline-text-2" id="text-Predicate%20aliases">
|
|
||||||
<p>
|
|
||||||
And, you know what, if you're just so busy that you don't even have time to type the word <code>person</code>, you can add an abbreviated alias, <code>p</code>, like this:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="org-src-container">
|
|
||||||
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; font-weight: bold;">org-ql-defpred</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e;">person p</span><span style="color: #3d85b7;">)</span> <span style="color: #3d85b7;">(</span><span style="color: #78880e;">&rest</span><span style="color: #78880e;"> names</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #73139976b41e;">"Search for entries about any of NAMES."</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:normalizers</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e;">(</span><span style="color: #3d8b85;">`(</span><span style="color: #a17e11;">,predicate-names . ,names</span><span style="color: #3d8b85;">)</span>
|
|
||||||
<span style="color: #3d8b85;">`(</span><span style="color: #a17e11; font-weight: bold;">or</span><span style="color: #a17e11;"> (</span><span style="color: #3d85b7; text-decoration: underline;">tags</span><span style="color: #3d85b7;"> ,@(</span><span style="color: #78880e; font-weight: bold;">cl-loop</span><span style="color: #78880e;"> for name in names</span>
|
|
||||||
<span style="color: #78880e;"> collect (</span><span style="color: #3d8b85; text-decoration: underline;">concat</span><span style="color: #3d8b85;"> </span><span style="color: #65bc957591ca;">"person"</span> <span style="color: #3d8b85;">name</span><span style="color: #78880e;">)</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
|
|
||||||
<span style="color: #a17e11;">,@(</span><span style="color: #3d85b7; font-weight: bold;">cl-loop</span><span style="color: #3d85b7;"> for name in names</span>
|
|
||||||
<span style="color: #3d85b7;"> collect `(</span><span style="color: #78880e;">property </span><span style="color: #921da24c26e6;">"person"</span> <span style="color: #78880e;">,name</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span><span style="color: #3d8b85;">)</span><span style="color: #78880e;">)</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:body</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; font-weight: bold;">cl-loop</span><span style="color: #78880e;"> for name in names</span>
|
|
||||||
<span style="color: #78880e;"> thereis (</span><span style="color: #3d8b85; font-weight: bold;">or</span><span style="color: #3d8b85;"> (</span><span style="color: #a17e11; text-decoration: underline;">property</span><span style="color: #a17e11;"> </span><span style="color: #b86396762cce;">"person"</span> <span style="color: #a17e11;">name</span><span style="color: #3d8b85;">)</span>
|
|
||||||
<span style="color: #3d8b85;">(</span><span style="color: #a17e11; text-decoration: underline;">tags</span><span style="color: #a17e11;"> (</span><span style="color: #3d85b7; text-decoration: underline;">concat</span><span style="color: #3d85b7;"> </span><span style="color: #73139976b41e;">"person"</span> <span style="color: #3d85b7;">name</span><span style="color: #a17e11;">)</span><span style="color: #3d8b85;">)</span><span style="color: #78880e;">)</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
Let's try it:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="org-src-container">
|
|
||||||
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql-search</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">current-buffer</span><span style="color: #3d85b7;">)</span> <span style="color: #73139976b41e;">"p:Alice,Bob priority:A"</span><span style="color: #a17e11;">)</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
And that shows:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<pre class="example">
|
|
||||||
Query: (and (person "Alice" "Bob") (priority "A")) In:meetings.org
|
|
||||||
[#A] Loud pet parakeet :personAlice:
|
|
||||||
[#A] Stinky coffee breath
|
|
||||||
</pre>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
(It's up to you to remember whether <code>p</code> means <code>person</code> or <code>priority</code>, but code can't solve everything.)
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="outline-container-Be%20formless" class="outline-2">
|
|
||||||
<h2 id="Be%20formless">Be formless</h2>
|
|
||||||
<div class="outline-text-2" id="text-Be%20formless">
|
|
||||||
<p>
|
|
||||||
We can even go a step further: since the normalizer rewrites the query to call the <code>property</code> and <code>tags</code> predicates instead, this <code>person</code> predicate doesn't even need a body form!
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="org-src-container">
|
|
||||||
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; font-weight: bold;">org-ql-defpred</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e;">person p</span><span style="color: #3d85b7;">)</span> <span style="color: #3d85b7;">(</span><span style="color: #78880e;">&rest</span><span style="color: #78880e;"> names</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #73139976b41e;">"Search for entries about any of NAMES."</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:normalizers</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e;">(</span><span style="color: #3d8b85;">`(</span><span style="color: #a17e11;">,predicate-names . ,names</span><span style="color: #3d8b85;">)</span>
|
|
||||||
<span style="color: #3d8b85;">`(</span><span style="color: #a17e11; font-weight: bold;">or</span><span style="color: #a17e11;"> (</span><span style="color: #3d85b7; text-decoration: underline;">tags</span><span style="color: #3d85b7;"> ,@(</span><span style="color: #78880e; font-weight: bold;">cl-loop</span><span style="color: #78880e;"> for name in names</span>
|
|
||||||
<span style="color: #78880e;"> collect (</span><span style="color: #3d8b85; text-decoration: underline;">concat</span><span style="color: #3d8b85;"> </span><span style="color: #65bc957591ca;">"person"</span> <span style="color: #3d8b85;">name</span><span style="color: #78880e;">)</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
|
|
||||||
<span style="color: #a17e11;">,@(</span><span style="color: #3d85b7; font-weight: bold;">cl-loop</span><span style="color: #3d85b7;"> for name in names</span>
|
|
||||||
<span style="color: #3d85b7;"> collect `(</span><span style="color: #78880e;">property </span><span style="color: #921da24c26e6;">"person"</span> <span style="color: #78880e;">,name</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span><span style="color: #3d8b85;">)</span><span style="color: #78880e;">)</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
Will it still work?
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="org-src-container">
|
|
||||||
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql-query</span><span style="color: #3d85b7;"> </span><span style="color: #3d85b7; font-weight: bold;">:select</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">org-get-heading </span><span style="color: #78880e; font-weight: bold;">:no-tags</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:from</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">current-buffer</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:where</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">person </span><span style="color: #921da24c26e6;">"Alice"</span> <span style="color: #921da24c26e6;">"Bob"</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<ul class="org-ul">
|
|
||||||
<li>[#A] Loud pet parakeet</li>
|
|
||||||
<li>[#C] Missing sticky notes</li>
|
|
||||||
<li>[#C] Dirty dishes in sink</li>
|
|
||||||
<li>[#A] Stinky coffee breath</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
It does!
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="outline-container-Conclusion" class="outline-2">
|
|
||||||
<h2 id="Conclusion">Conclusion</h2>
|
|
||||||
<div class="outline-text-2" id="text-Conclusion">
|
|
||||||
<p>
|
|
||||||
In this tutorial, we've gone from having to write lengthy, complex query expressions for accommodating idiosyncratic requirements, to being able to write simple query expressions that abstract away ugly details, to rewriting those query expressions into a more optimal form before a search is even run. The end result is an Org Query Language that is customized to meet your specific needs.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
What new custom predicates will you write next?
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="outline-container-Appendix%3A%20Anaphoric%20macros" class="outline-2">
|
|
||||||
<h2 id="Appendix%3A%20Anaphoric%20macros">Appendix: Anaphoric macros</h2>
|
|
||||||
<div class="outline-text-2" id="text-Appendix%3A%20Anaphoric%20macros">
|
|
||||||
<p>
|
|
||||||
Finally, if you're a Lisper who appreciates anaphora, you might prefer a more syntactically concise definition of the predicate using Dash macros:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="org-src-container">
|
|
||||||
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; font-weight: bold;">org-ql-defpred</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e;">person p</span><span style="color: #3d85b7;">)</span> <span style="color: #3d85b7;">(</span><span style="color: #78880e;">&rest</span><span style="color: #78880e;"> names</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #73139976b41e;">"Search for entries about any of NAMES."</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:normalizers</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e;">(</span><span style="color: #3d8b85;">`(</span><span style="color: #a17e11;">,predicate-names . ,names</span><span style="color: #3d8b85;">)</span>
|
|
||||||
<span style="color: #3d8b85;">`(</span><span style="color: #a17e11; font-weight: bold;">or</span><span style="color: #a17e11;"> (</span><span style="color: #3d85b7; text-decoration: underline;">tags</span><span style="color: #3d85b7;"> ,@(</span><span style="color: #78880e; font-weight: bold;">--map</span><span style="color: #78880e;"> `(</span><span style="color: #3d8b85;">concat </span><span style="color: #65bc957591ca;">"person"</span> <span style="color: #3d8b85;">,</span><span style="color: #3d8b85;">it</span><span style="color: #78880e;">)</span> <span style="color: #78880e;">names</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
|
|
||||||
<span style="color: #a17e11;">,@(</span><span style="color: #3d85b7; font-weight: bold;">--map</span><span style="color: #3d85b7;"> `(</span><span style="color: #78880e;">property </span><span style="color: #921da24c26e6;">"person"</span> <span style="color: #78880e;">,</span><span style="color: #78880e;">it</span><span style="color: #3d85b7;">)</span> <span style="color: #3d85b7;">names</span><span style="color: #a17e11;">)</span><span style="color: #3d8b85;">)</span><span style="color: #78880e;">)</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
Let's make sure it works:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="org-src-container">
|
|
||||||
<pre class="src src-elisp"><span style="color: #a17e11;">(</span><span style="color: #3d85b7; text-decoration: underline;">org-ql-query</span><span style="color: #3d85b7;"> </span><span style="color: #3d85b7; font-weight: bold;">:select</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">org-get-heading </span><span style="color: #78880e; font-weight: bold;">:no-tags</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:from</span><span style="color: #3d85b7;"> (</span><span style="color: #78880e; text-decoration: underline;">current-buffer</span><span style="color: #3d85b7;">)</span>
|
|
||||||
<span style="color: #3d85b7; font-weight: bold;">:where</span><span style="color: #3d85b7;"> '(</span><span style="color: #78880e;">person </span><span style="color: #921da24c26e6;">"Alice"</span> <span style="color: #921da24c26e6;">"Bob"</span><span style="color: #3d85b7;">)</span><span style="color: #a17e11;">)</span>
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<ul class="org-ul">
|
|
||||||
<li>[#A] Loud pet parakeet</li>
|
|
||||||
<li>[#C] Missing sticky notes</li>
|
|
||||||
<li>[#C] Dirty dishes in sink</li>
|
|
||||||
<li>[#A] Stinky coffee breath</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
Lisp is fun!
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="outline-container-Example%20data" class="outline-2">
|
|
||||||
<h2 id="Example%20data">Example data</h2>
|
|
||||||
<div class="outline-text-2" id="text-Example%20data">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="outline-container-Loud%20pet%20parakeet" class="outline-3">
|
|
||||||
<h3 id="Loud%20pet%20parakeet">Loud pet parakeet   <span class="tag"><span class="personAlice">personAlice</span></span></h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="outline-container-Missing%20sticky%20notes" class="outline-3">
|
|
||||||
<h3 id="Missing%20sticky%20notes">Missing sticky notes   <span class="tag"><span class="personAlice">personAlice</span></span></h3>
|
|
||||||
<div class="outline-text-3" id="text-Missing%20sticky%20notes">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="outline-container-Dirty%20dishes%20in%20sink" class="outline-3">
|
|
||||||
<h3 id="Dirty%20dishes%20in%20sink">Dirty dishes in sink   <span class="tag"><span class="personAlice">personAlice</span></span></h3>
|
|
||||||
<div class="outline-text-3" id="text-Dirty%20dishes%20in%20sink">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="outline-container-Stinky%20coffee%20breath" class="outline-3">
|
|
||||||
<h3 id="Stinky%20coffee%20breath">Stinky coffee breath</h3>
|
|
||||||
<div class="outline-text-3" id="text-Stinky%20coffee%20breath">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div id="postamble" class="status">
|
|
||||||
<p class="date">Created: 2020-11-23 Mon 03:31</p>
|
|
||||||
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
@ -1,390 +0,0 @@
|
||||||
#+TITLE: Org QL Custom Predicates Tutorial
|
|
||||||
#+OPTIONS: author:nil creator:nil created:nil date:nil num:nil title:t broken-links:t
|
|
||||||
#+SETUPFILE: export/setup/theme-darksun-local.setup
|
|
||||||
|
|
||||||
[2020-11-22 Sun 22:35] Imagine you have weekly meetings with other people, and during the week you take notes about items to discuss at each meeting. When the time for a meeting comes, you want to quickly and easily search for all of the items to discuss at the meeting.
|
|
||||||
|
|
||||||
You've been experimenting with different ways to track such data in Org. You've tried using tags, but some of the names in question conflict with other tags in your data (e.g. someone's named Charles, but you also work with a firm named Charles, Inc., and you'd prefer to continue using the tag =Charles= for entries about that firm), so you've been using tags like ~:personNAME:~, which seems awkward. You've tried using a ~:person: NAME~ property on entries, which has the advantage of not cluttering the tags list, but also the disadvantage of not being readily visible in an outline.
|
|
||||||
|
|
||||||
So you haven't decided on a long-term solution, but the meetings aren't going to wait--you need to search that data now, and you have a mix of both tags and properties in your entries. What you need is to be able to search for all of the entries about Alice (which you've tagged ~:personAlice:~) when you're meeting with her, and all of the entries about Bob (which have the property ~:person: Bob~) when you're meeting with him. What do you do?
|
|
||||||
|
|
||||||
* Contents :noexport:
|
|
||||||
:PROPERTIES:
|
|
||||||
:TOC: :include siblings :ignore this
|
|
||||||
:END:
|
|
||||||
:CONTENTS:
|
|
||||||
- [[#using-built-in-predicates][Using built-in predicates]]
|
|
||||||
- [[#a-custom-person-predicate][A custom (person) predicate]]
|
|
||||||
- [[#searching-for-multiple-people-at-once][Searching for multiple people at once]]
|
|
||||||
- [[#normalizing-queries-to-rewrite-arguments][Normalizing queries to rewrite arguments]]
|
|
||||||
- [[#non-sexp-query-syntax][Non-sexp query syntax]]
|
|
||||||
- [[#using-multiple-predicates][Using multiple predicates]]
|
|
||||||
- [[#predicate-aliases][Predicate aliases]]
|
|
||||||
- [[#be-formless][Be formless]]
|
|
||||||
- [[#conclusion][Conclusion]]
|
|
||||||
- [[#appendix-anaphoric-macros][Appendix: Anaphoric macros]]
|
|
||||||
:END:
|
|
||||||
|
|
||||||
* Using built-in predicates
|
|
||||||
|
|
||||||
You could start by using built-in Org QL predicates to search your data. For example:
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp :results list :exports both :cache yes
|
|
||||||
(org-ql-query :select '(org-get-heading :no-tags)
|
|
||||||
:from (current-buffer)
|
|
||||||
:where '(or (tags "personAlice")
|
|
||||||
(property "person" "Bob")))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
#+RESULTS[91a413cda23cb65d6bb99212e111f283e5a5c910]:
|
|
||||||
- [#A] Loud pet parakeet
|
|
||||||
- [#C] Missing sticky notes
|
|
||||||
- [#C] Dirty dishes in sink
|
|
||||||
- [#A] Stinky coffee breath
|
|
||||||
|
|
||||||
That was easy enough, but it's not very...semantic. You have to think about the implementation details: Alice uses tags, Bob uses properties, and what if Charlie uses both? It starts to feel complicated, and it's a lot to type out every time. Is there an easier way?
|
|
||||||
|
|
||||||
* A custom ~(person)~ predicate
|
|
||||||
|
|
||||||
Enter =org-ql= custom search predicates. Let's start simple, by defining a predicate to search for just the ~:person:~ property, one person at a time. The predicate will take one argument, a person's name, and search for that property. It would look like this:
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp :results silent :exports code
|
|
||||||
(org-ql-defpred person (name)
|
|
||||||
"Search for entries with the \"person\" property being NAME."
|
|
||||||
:body (property "person" name))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
Now, let's see what results we get for searching this file for entries about Bob:
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp :results list :exports both :cache yes
|
|
||||||
(org-ql-query :select '(org-get-heading :no-tags)
|
|
||||||
:from (current-buffer)
|
|
||||||
:where '(person "Bob"))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
#+RESULTS[c11a4ce2c4f179d7487c9b46eff9f72766bc2bc4]:
|
|
||||||
- [#C] Missing sticky notes
|
|
||||||
- [#C] Dirty dishes in sink
|
|
||||||
- [#A] Stinky coffee breath
|
|
||||||
|
|
||||||
Hmm, looks like we need to remind Bob to wash his mug and take some mints after lunch. Now what do we need to discuss with Alice?
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp :results list :exports both :cache yes
|
|
||||||
(org-ql-query :select '(org-get-heading :no-tags)
|
|
||||||
:from (current-buffer)
|
|
||||||
:where '(person "Alice"))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
#+RESULTS[1f12f437042bbc077a4696d707805c1367f2ca3d]:
|
|
||||||
#+BEGIN_EXAMPLE
|
|
||||||
|
|
||||||
#+END_EXAMPLE
|
|
||||||
|
|
||||||
Nothing? Oh, right, Alice's entries use the ~:personAlice:~ tag, so we'll also need to search those kind of entries. Let's make the predicate do that, too:
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp :results silent :exports code
|
|
||||||
(org-ql-defpred person (name)
|
|
||||||
"Search for entries with the \"person\" property being NAME or having the tag \"personNAME\"."
|
|
||||||
:body (or (property "person" name)
|
|
||||||
(tags (concat "person" name))))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
How about now?
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp :results list :exports both :cache yes
|
|
||||||
(org-ql-query :select '(org-get-heading :no-tags)
|
|
||||||
:from (current-buffer)
|
|
||||||
:where '(person "Alice"))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
#+RESULTS[1f12f437042bbc077a4696d707805c1367f2ca3d]:
|
|
||||||
- [#A] Loud pet parakeet
|
|
||||||
- [#C] Missing sticky notes
|
|
||||||
- [#C] Dirty dishes in sink
|
|
||||||
|
|
||||||
Hmm, I thought we already told her to leave Polly at home.
|
|
||||||
|
|
||||||
* Searching for multiple people at once
|
|
||||||
|
|
||||||
Oh, wait, this week is shortened due to holidays, so we're having a combined meeting. How do we search for entries about either of them? Well, this is the obvious solution:
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp :results list :exports both :cache yes
|
|
||||||
(org-ql-query :select '(org-get-heading :no-tags)
|
|
||||||
:from (current-buffer)
|
|
||||||
:where '(or (person "Alice")
|
|
||||||
(person "Bob")))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
#+RESULTS[4e4c75bde4fbceaadb076a53410c1625d1283e06]:
|
|
||||||
- [#A] Loud pet parakeet
|
|
||||||
- [#C] Missing sticky notes
|
|
||||||
- [#C] Dirty dishes in sink
|
|
||||||
- [#A] Stinky coffee breath
|
|
||||||
|
|
||||||
And that works fine. But it seems like a lot to type. Could we make the =person= predicate accept multiple names instead?
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp :results silent :exports code
|
|
||||||
(org-ql-defpred person (&rest names)
|
|
||||||
"Search for entries about any of NAMES."
|
|
||||||
:body (cl-loop for name in names
|
|
||||||
thereis (or (property "person" name)
|
|
||||||
(tags (concat "person" name)))))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
Now let's search again:
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp :results list :exports both :cache yes
|
|
||||||
(org-ql-query :select '(org-get-heading :no-tags)
|
|
||||||
:from (current-buffer)
|
|
||||||
:where '(person "Alice" "Bob"))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
#+RESULTS[4f5971c56616f01d8d3c28a66ef380495ee3e158]:
|
|
||||||
- [#A] Loud pet parakeet
|
|
||||||
- [#C] Missing sticky notes
|
|
||||||
- [#C] Dirty dishes in sink
|
|
||||||
- [#A] Stinky coffee breath
|
|
||||||
|
|
||||||
That was easy!
|
|
||||||
|
|
||||||
* Normalizing queries to rewrite arguments
|
|
||||||
|
|
||||||
Now, all this is well and good if you don't have hundreds of thousands of Org entries in your files. But what if you do? All that =concat='ing happening on every entry could add up, and the query might take a few seconds. What if we could do that stringing-along just once, before running the query? We want to turn our ~(person "Alice" "Bob")~ query into this, with the =:personNAME:= strings already made and the per-person ~(property ...)~ predicates also included:
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp
|
|
||||||
(or (tags "personAlice" "personBob")
|
|
||||||
(property "person" "Alice")
|
|
||||||
(property "person" "Bob"))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
Can we do that? In fact, we can, by using a query normalizer. Normalizers are =pcase= forms (I /know/) that normalize query expressions before execution. We can use one to rewrite the query ahead of time, like this:
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp :results silent :exports code
|
|
||||||
(org-ql-defpred person (&rest names)
|
|
||||||
"Search for entries about any of NAMES."
|
|
||||||
:normalizers ((`(person . ,names)
|
|
||||||
`(or (tags ,@(cl-loop for name in names
|
|
||||||
collect (concat "person" name)))
|
|
||||||
,@(cl-loop for name in names
|
|
||||||
collect `(property "person" ,name)))))
|
|
||||||
:body (cl-loop for name in names
|
|
||||||
thereis (or (property "person" name)
|
|
||||||
(tags name))))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
/NOTE: Normalizers are applied to a query repeatedly until the query is fully normalized, so normalizers should be carefully written to avoid infinite loops. In this example, there is no risk of an infinite loop, because the normalized query no longer contains the ~person~ predicate, so the normalizer only applies to the query once./
|
|
||||||
|
|
||||||
Now, don't faint from all the backquoting and unquoting--it's just Lisp, nothing to be afraid of! Let's slow down a moment and see what the normalized query looks like to be sure we're doing it correctly:
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp :results code :exports both :cache yes
|
|
||||||
(org-ql--normalize-query '(person "Alice" "Bob"))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
#+RESULTS[ebc46fff31b72359353dda539a26c95b7d650df2]:
|
|
||||||
#+BEGIN_SRC elisp
|
|
||||||
(or (tags "personAlice" "personBob")
|
|
||||||
(property "person" "Alice")
|
|
||||||
(property "person" "Bob"))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
And, as they say, Bob's your uncle! Or even if he isn't, let's see if it works:
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp :results list :exports both :cache yes
|
|
||||||
(org-ql-query :select '(org-get-heading :no-tags)
|
|
||||||
:from (current-buffer)
|
|
||||||
:where '(person "Alice" "Bob"))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
#+RESULTS[4f5971c56616f01d8d3c28a66ef380495ee3e158]:
|
|
||||||
- [#A] Loud pet parakeet
|
|
||||||
- [#C] Missing sticky notes
|
|
||||||
- [#C] Dirty dishes in sink
|
|
||||||
- [#A] Stinky coffee breath
|
|
||||||
|
|
||||||
Yep, same result as the non-normalized query. And look at how much simpler it is to write ~(person "Alice" "Bob")~ than to write ~(or (tags "personAlice" "personBob") (property "person" "Alice") (property "person" "Bob"))~.
|
|
||||||
|
|
||||||
* Non-sexp query syntax
|
|
||||||
|
|
||||||
But wait, that's not all! If you order now, we'll throw in non-sexp query syntax for free! That's right, your search could be as simple as typing ~person:Alice,Bob~!
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp :results none :exports code
|
|
||||||
(org-ql-search (current-buffer) "person:Alice,Bob")
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
Don't believe me? Well, you see, queries in this syntax are converted to the sexp syntax, like:
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp :results code :exports both :cache yes
|
|
||||||
(org-ql--query-string-to-sexp "person:Alice,Bob")
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
#+RESULTS[a60655544956644605c23c152570185c329faa87]:
|
|
||||||
#+BEGIN_SRC elisp
|
|
||||||
(person "Alice" "Bob")
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
And that happens automatically when you use a search command like =org-ql-search=. If you have =org-ql= installed already, you could even click this link: [[org-ql-search:person:Alice,Bob][Alice or Bob]]. Which, in Org syntax, looks like:
|
|
||||||
|
|
||||||
#+BEGIN_SRC org
|
|
||||||
[[org-ql-search:person:Alice,Bob]]
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
And that would open an Agenda Mode buffer that looks like this:
|
|
||||||
|
|
||||||
#+BEGIN_EXAMPLE
|
|
||||||
Query: (person "Alice" "Bob") In:meetings.org
|
|
||||||
[#A] Loud pet parakeet :personAlice:
|
|
||||||
[#C] Missing sticky notes :personAlice:
|
|
||||||
[#C] Dirty dishes in sink :personAlice:
|
|
||||||
[#A] Stinky coffee breath
|
|
||||||
#+END_EXAMPLE
|
|
||||||
|
|
||||||
* Using multiple predicates
|
|
||||||
|
|
||||||
Oops, you forgot that there's a birthday party in 20 minutes, so you only have time to talk about the highest priority items at this joint meeting today.
|
|
||||||
|
|
||||||
No problem, let's just select high-priority items:
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp :results silent :exports code
|
|
||||||
(org-ql-search (current-buffer) "person:Alice,Bob priority:A")
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
Which shows:
|
|
||||||
|
|
||||||
#+BEGIN_EXAMPLE
|
|
||||||
Query: (and (person "Alice" "Bob") (priority "A")) In:meetings.org
|
|
||||||
[#A] Loud pet parakeet :personAlice:
|
|
||||||
[#A] Stinky coffee breath
|
|
||||||
#+END_EXAMPLE
|
|
||||||
|
|
||||||
* Predicate aliases
|
|
||||||
|
|
||||||
And, you know what, if you're just so busy that you don't even have time to type the word =person=, you can add an abbreviated alias, =p=, like this:
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp :results silent :exports code
|
|
||||||
(org-ql-defpred (person p) (&rest names)
|
|
||||||
"Search for entries about any of NAMES."
|
|
||||||
:normalizers ((`(,predicate-names . ,names)
|
|
||||||
`(or (tags ,@(cl-loop for name in names
|
|
||||||
collect (concat "person" name)))
|
|
||||||
,@(cl-loop for name in names
|
|
||||||
collect `(property "person" ,name)))))
|
|
||||||
:body (cl-loop for name in names
|
|
||||||
thereis (or (property "person" name)
|
|
||||||
(tags (concat "person" name)))))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
Let's try it:
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp :results silent :exports code
|
|
||||||
(org-ql-search (current-buffer) "p:Alice,Bob priority:A")
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
And that shows:
|
|
||||||
|
|
||||||
#+BEGIN_EXAMPLE
|
|
||||||
Query: (and (person "Alice" "Bob") (priority "A")) In:meetings.org
|
|
||||||
[#A] Loud pet parakeet :personAlice:
|
|
||||||
[#A] Stinky coffee breath
|
|
||||||
#+END_EXAMPLE
|
|
||||||
|
|
||||||
(It's up to you to remember whether =p= means =person= or =priority=, but code can't solve everything.)
|
|
||||||
|
|
||||||
* Be formless
|
|
||||||
|
|
||||||
We can even go a step further: since the normalizer rewrites the query to call the =property= and =tags= predicates instead, this =person= predicate doesn't even need a body form!
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp :results silent :exports code
|
|
||||||
(org-ql-defpred (person p) (&rest names)
|
|
||||||
"Search for entries about any of NAMES."
|
|
||||||
:normalizers ((`(,predicate-names . ,names)
|
|
||||||
`(or (tags ,@(cl-loop for name in names
|
|
||||||
collect (concat "person" name)))
|
|
||||||
,@(cl-loop for name in names
|
|
||||||
collect `(property "person" ,name))))))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
Will it still work?
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp :results list :exports both :cache yes
|
|
||||||
(org-ql-query :select '(org-get-heading :no-tags)
|
|
||||||
:from (current-buffer)
|
|
||||||
:where '(person "Alice" "Bob"))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
#+RESULTS[4f5971c56616f01d8d3c28a66ef380495ee3e158]:
|
|
||||||
- [#A] Loud pet parakeet
|
|
||||||
- [#C] Missing sticky notes
|
|
||||||
- [#C] Dirty dishes in sink
|
|
||||||
- [#A] Stinky coffee breath
|
|
||||||
|
|
||||||
It does!
|
|
||||||
|
|
||||||
* Conclusion
|
|
||||||
|
|
||||||
In this tutorial, we've gone from having to write lengthy, complex query expressions for accommodating idiosyncratic requirements, to being able to write simple query expressions that abstract away ugly details, to rewriting those query expressions into a more optimal form before a search is even run. The end result is an Org Query Language that is customized to meet your specific needs.
|
|
||||||
|
|
||||||
What new custom predicates will you write next?
|
|
||||||
|
|
||||||
* Appendix: Anaphoric macros
|
|
||||||
|
|
||||||
Finally, if you're a Lisper who appreciates anaphora, you might prefer a more syntactically concise definition of the predicate using Dash macros:
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp :results silent :exports code
|
|
||||||
(org-ql-defpred (person p) (&rest names)
|
|
||||||
"Search for entries about any of NAMES."
|
|
||||||
:normalizers ((`(,predicate-names . ,names)
|
|
||||||
`(or (tags ,@(--map (concat "person" it) names))
|
|
||||||
,@(--map `(property "person" ,it) names)))))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
Let's make sure it normalizes correctly:
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp :results code :exports both :cache yes
|
|
||||||
(org-ql--normalize-query '(person "Alice" "Bob"))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
#+RESULTS[ebc46fff31b72359353dda539a26c95b7d650df2]:
|
|
||||||
#+BEGIN_SRC elisp
|
|
||||||
(or (tags "personAlice" "personBob")
|
|
||||||
(property "person" "Alice")
|
|
||||||
(property "person" "Bob"))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
It does, so the query also produces the correct results:
|
|
||||||
|
|
||||||
#+BEGIN_SRC elisp :results list :exports both :cache yes
|
|
||||||
(org-ql-query :select '(org-get-heading :no-tags)
|
|
||||||
:from (current-buffer)
|
|
||||||
:where '(person "Alice" "Bob"))
|
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
#+RESULTS[4f5971c56616f01d8d3c28a66ef380495ee3e158]:
|
|
||||||
- [#A] Loud pet parakeet
|
|
||||||
- [#C] Missing sticky notes
|
|
||||||
- [#C] Dirty dishes in sink
|
|
||||||
- [#A] Stinky coffee breath
|
|
||||||
|
|
||||||
Lisp is fun!
|
|
||||||
|
|
||||||
* Example data
|
|
||||||
:PROPERTIES:
|
|
||||||
:TOC: :ignore (this descendants)
|
|
||||||
:END:
|
|
||||||
|
|
||||||
** [#A] Loud pet parakeet :personAlice:
|
|
||||||
|
|
||||||
** [#C] Missing sticky notes :personAlice:
|
|
||||||
:PROPERTIES:
|
|
||||||
:person: Bob
|
|
||||||
:END:
|
|
||||||
|
|
||||||
** [#C] Dirty dishes in sink :personAlice:
|
|
||||||
:PROPERTIES:
|
|
||||||
:person: Bob
|
|
||||||
:END:
|
|
||||||
|
|
||||||
** [#A] Stinky coffee breath
|
|
||||||
:PROPERTIES:
|
|
||||||
:person: Bob
|
|
||||||
:END:
|
|
||||||
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
# -*- mode: org; -*-
|
|
||||||
|
|
||||||
# The files that hide sections and display a navbar and ToC are commented out.
|
|
||||||
|
|
||||||
# #+HTML_HEAD: <link rel="stylesheet" type="text/css" href="export/styles/darksun/css/htmlize.css"/>
|
|
||||||
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="export/styles/darksun/css/darksun.css"/>
|
|
||||||
# #+HTML_HEAD: <link rel="stylesheet" type="text/css" href="export/styles/darksun/css/hideshow.css"/>
|
|
||||||
|
|
||||||
#+HTML_HEAD: <script type="text/javascript" src="export/styles/darksun/js/jquery-1.11.0.min.js"></script>
|
|
||||||
#+HTML_HEAD: <script type="text/javascript" src="export/styles/darksun/js/jquery-ui-1.10.2.min.js"></script>
|
|
||||||
|
|
||||||
#+HTML_HEAD: <script type="text/javascript" src="export/styles/darksun/js/jquery.localscroll-min.js"></script>
|
|
||||||
#+HTML_HEAD: <script type="text/javascript" src="export/styles/darksun/js/jquery.scrollTo-1.4.3.1-min.js"></script>
|
|
||||||
#+HTML_HEAD: <script type="text/javascript" src="export/styles/darksun/js/jquery.zclip.min.js"></script>
|
|
||||||
#+HTML_HEAD: <script type="text/javascript" src="export/styles/darksun/js/darksun.js"></script>
|
|
||||||
# #+HTML_HEAD: <script type="text/javascript" src="export/styles/darksun/js/hideshow.js"></script>
|
|
||||||
#+HTML_HEAD: <script type="text/javascript" src="export/styles/lib/js/jquery.stickytableheaders.min.js"></script>
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
# -*- mode: org; -*-
|
|
||||||
|
|
||||||
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/darksun/css/htmlize.css"/>
|
|
||||||
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/darksun/css/darksun.css"/>
|
|
||||||
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/darksun/css/hideshow.css"/>
|
|
||||||
|
|
||||||
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/darksun/js/jquery-1.11.0.min.js"></script>
|
|
||||||
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/darksun/js/jquery-ui-1.10.2.min.js"></script>
|
|
||||||
|
|
||||||
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/darksun/js/jquery.localscroll-min.js"></script>
|
|
||||||
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/darksun/js/jquery.scrollTo-1.4.3.1-min.js"></script>
|
|
||||||
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/darksun/js/jquery.zclip.min.js"></script>
|
|
||||||
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/darksun/js/darksun.js"></script>
|
|
||||||
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/darksun/js/hideshow.js"></script>
|
|
||||||
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/lib/js/jquery.stickytableheaders.min.js"></script>
|
|
||||||
|
|
@ -1,264 +0,0 @@
|
||||||
* {
|
|
||||||
border-color: #657b83;
|
|
||||||
}
|
|
||||||
a {
|
|
||||||
color: #268bd2 !important;
|
|
||||||
}
|
|
||||||
a:visited {
|
|
||||||
color: #6c71c4 !important;
|
|
||||||
}
|
|
||||||
body {
|
|
||||||
background-color: #002b36 !important;
|
|
||||||
color: #839496 !important;
|
|
||||||
font-family: Libre Baskerville, serif;
|
|
||||||
}
|
|
||||||
html {
|
|
||||||
background-color: #002b36 !important;
|
|
||||||
}
|
|
||||||
input,
|
|
||||||
textarea {
|
|
||||||
background-color: #073642 !important;
|
|
||||||
color: #839496 !important;
|
|
||||||
}
|
|
||||||
blockquote,
|
|
||||||
code,
|
|
||||||
pre {
|
|
||||||
background-color: #073642 !important;
|
|
||||||
border: 1px solid #094352 !important;
|
|
||||||
border-radius: 2px;
|
|
||||||
box-shadow: none;
|
|
||||||
color: #839496 !important;
|
|
||||||
}
|
|
||||||
code {
|
|
||||||
font-size: 1.2em;
|
|
||||||
}
|
|
||||||
img {
|
|
||||||
margin: 0.5em;
|
|
||||||
}
|
|
||||||
.buttons {
|
|
||||||
background-color: #073642 !important;
|
|
||||||
color: #93a1a1 !important;
|
|
||||||
font-family: sans-serif;
|
|
||||||
font-size: 1.5rem;
|
|
||||||
}
|
|
||||||
.hsReviewPanel {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
.title {
|
|
||||||
border: 0;
|
|
||||||
}
|
|
||||||
#postamble {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
#banner {
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
#tabs {
|
|
||||||
background-color: #073642 !important;
|
|
||||||
float: left;
|
|
||||||
margin: 0px 0px 20px 0px;
|
|
||||||
padding: 0;
|
|
||||||
width: 100%;
|
|
||||||
font-family: sans-serif;
|
|
||||||
}
|
|
||||||
#tabs ul {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
#tabs li {
|
|
||||||
float: left;
|
|
||||||
list-style-type: none;
|
|
||||||
margin: 0px 2px 0px 0px;
|
|
||||||
padding: 0px 0px 0px 0px;
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
#tabs li a {
|
|
||||||
display: block;
|
|
||||||
font-size: 120%;
|
|
||||||
font-weight: bold;
|
|
||||||
margin: 0;
|
|
||||||
padding: 4px 10px 4px 10px;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
#tabs li a:hover {
|
|
||||||
color: #90c5eb !important;
|
|
||||||
}
|
|
||||||
#tabs li.ui-tabs-active a {
|
|
||||||
background-color: #094352 !important;
|
|
||||||
color: #59a9e1 !important;
|
|
||||||
}
|
|
||||||
#content {
|
|
||||||
clear: both;
|
|
||||||
width: 80%;
|
|
||||||
}
|
|
||||||
#content > p {
|
|
||||||
margin: 1em;
|
|
||||||
}
|
|
||||||
#content > div > h2 {
|
|
||||||
margin: 0.25rem;
|
|
||||||
}
|
|
||||||
#postamble {
|
|
||||||
text-align: right;
|
|
||||||
}
|
|
||||||
blockquote {
|
|
||||||
background-color: #073642 !important;
|
|
||||||
padding-left: 0.75em;
|
|
||||||
padding-right: 0.75em;
|
|
||||||
padding-top: 0.01em;
|
|
||||||
padding-bottom: 0.01em;
|
|
||||||
overflow: hidden;
|
|
||||||
margin-left: 0;
|
|
||||||
}
|
|
||||||
.outline-text-2,
|
|
||||||
.outline-text-3,
|
|
||||||
.outline-text-4,
|
|
||||||
.outline-text-5,
|
|
||||||
.outline-text-6 {
|
|
||||||
padding-left: 4%;
|
|
||||||
}
|
|
||||||
.outline-3 {
|
|
||||||
padding-left: 4%;
|
|
||||||
}
|
|
||||||
.outline-4 {
|
|
||||||
padding-left: 4%;
|
|
||||||
}
|
|
||||||
.outline-5 {
|
|
||||||
padding-left: 4%;
|
|
||||||
}
|
|
||||||
.outline-6 {
|
|
||||||
padding-left: 4%;
|
|
||||||
}
|
|
||||||
h1,
|
|
||||||
h2,
|
|
||||||
h3,
|
|
||||||
h4,
|
|
||||||
h5,
|
|
||||||
h6 {
|
|
||||||
font-family: sans-serif;
|
|
||||||
border-bottom: 2px solid;
|
|
||||||
border-color: #094352 !important;
|
|
||||||
}
|
|
||||||
a:hover {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
#search {
|
|
||||||
display: block;
|
|
||||||
float: right;
|
|
||||||
}
|
|
||||||
.tag {
|
|
||||||
background-color: #002b36 !important;
|
|
||||||
color: #93a1a1 !important;
|
|
||||||
border: 0px;
|
|
||||||
}
|
|
||||||
.tag span {
|
|
||||||
background-color: #094352 !important;
|
|
||||||
margin: 0.25em;
|
|
||||||
padding: 0.25em;
|
|
||||||
}
|
|
||||||
#table-of-contents {
|
|
||||||
display: table;
|
|
||||||
float: right;
|
|
||||||
}
|
|
||||||
#table-of-contents h2 {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
#table-of-contents li {
|
|
||||||
list-style-type: none;
|
|
||||||
}
|
|
||||||
#table-of-contents a:hover {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
#minitoc {
|
|
||||||
background-color: #073642 !important;
|
|
||||||
position: fixed;
|
|
||||||
top: 0px;
|
|
||||||
right: -5px;
|
|
||||||
padding: 0.5em;
|
|
||||||
z-index: 200;
|
|
||||||
width: 18%;
|
|
||||||
word-wrap: normal;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
#minitoc ul {
|
|
||||||
margin: 0.5em;
|
|
||||||
padding-left: 1em;
|
|
||||||
}
|
|
||||||
#minitoc h2 {
|
|
||||||
margin-top: 0;
|
|
||||||
margin-bottom: 0;
|
|
||||||
font-size: 110%;
|
|
||||||
}
|
|
||||||
#minitoc a {
|
|
||||||
display: block;
|
|
||||||
font-family: sans-serif;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
#minitoc a:hover {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
/* #minitoc a { */
|
|
||||||
/* display: none; */
|
|
||||||
/* } */
|
|
||||||
#minitoc:hover a {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
#toTop {
|
|
||||||
top: -100px;
|
|
||||||
position: fixed;
|
|
||||||
text-align: center;
|
|
||||||
z-index: 999;
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
#toTop:hover {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
#left-panel-wrapper {
|
|
||||||
display: none;
|
|
||||||
position: fixed;
|
|
||||||
z-index: 200;
|
|
||||||
}
|
|
||||||
#left-panel-contents {
|
|
||||||
display: none;
|
|
||||||
position: fixed;
|
|
||||||
text-align: left;
|
|
||||||
top: 0;
|
|
||||||
z-index: 200;
|
|
||||||
}
|
|
||||||
#left-panel-button {
|
|
||||||
transform: rotate(90deg);
|
|
||||||
left: -23px;
|
|
||||||
position: fixed;
|
|
||||||
top: 50%;
|
|
||||||
z-index: 200;
|
|
||||||
}
|
|
||||||
#right-panel-wrapper {
|
|
||||||
position: fixed;
|
|
||||||
z-index: 200;
|
|
||||||
}
|
|
||||||
#right-panel-contents {
|
|
||||||
display: none;
|
|
||||||
z-index: 200;
|
|
||||||
position: fixed;
|
|
||||||
text-align: left;
|
|
||||||
top: 0;
|
|
||||||
}
|
|
||||||
.snippet-copy-to-clipboard {
|
|
||||||
display: none;
|
|
||||||
position: absolute;
|
|
||||||
left: 50px;
|
|
||||||
top: 50px;
|
|
||||||
}
|
|
||||||
.org-ol > li,
|
|
||||||
.org-dl > dt {
|
|
||||||
margin-top: 0.5em;
|
|
||||||
}
|
|
||||||
.org-ul {
|
|
||||||
margin-top: 1em;
|
|
||||||
margin-bottom: 1em;
|
|
||||||
}
|
|
||||||
.org-ul li {
|
|
||||||
margin-top: 0.5em;
|
|
||||||
}
|
|
||||||
.org-ul > li > a {
|
|
||||||
font-family: sans-serif;
|
|
||||||
}
|
|
||||||
|
|
@ -1,110 +0,0 @@
|
||||||
/* hideshow.css --- HideShow CSS file */
|
|
||||||
|
|
||||||
/* Copyright (C) 2014 All Right Reserved, Fabrice Niessen */
|
|
||||||
|
|
||||||
/* This file is free software: you can redistribute it and/or */
|
|
||||||
/* modify it under the terms of the GNU General Public License as */
|
|
||||||
/* published by the Free Software Foundation, either version 3 of */
|
|
||||||
/* the License, or (at your option) any later version. */
|
|
||||||
|
|
||||||
/* This file is distributed in the hope that it will be useful, */
|
|
||||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
|
||||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
|
||||||
/* GNU General Public License for more details. */
|
|
||||||
|
|
||||||
/* Author: Fabrice Niessen <(concat "fniessen" at-sign "pirilampo.org")> */
|
|
||||||
/* URL: https://github.com/fniessen/hide-show/ */
|
|
||||||
/* Version: 20140912.1722 */
|
|
||||||
|
|
||||||
.hsExpanded.hsAnchor {background: #EE7700;}
|
|
||||||
|
|
||||||
.buttons {
|
|
||||||
padding: 0px 7px 13px 0px;
|
|
||||||
background: #0A3F69;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hsButton {
|
|
||||||
color: white;
|
|
||||||
float: right;
|
|
||||||
font-size: 70%;
|
|
||||||
margin-left: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hsButton:hover {
|
|
||||||
text-decoration: underline;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ellipsis {
|
|
||||||
color: #999999;
|
|
||||||
/* background-color: #FFF8C0; */
|
|
||||||
/* float: right; */
|
|
||||||
margin-left: 0.6em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hsReview {
|
|
||||||
border: 1px solid #A4A4A4;
|
|
||||||
background-color: white;
|
|
||||||
z-index: 500; /* must be greater then z-index of hsOverlay */
|
|
||||||
position: relative; /* required for z-index to work */
|
|
||||||
}
|
|
||||||
|
|
||||||
#hsOverlay {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
position: fixed;
|
|
||||||
left: 0px;
|
|
||||||
top: 0px;
|
|
||||||
background-color: #000;
|
|
||||||
opacity: .70;
|
|
||||||
z-index: 250; /* must be greater than any other z-index (except the one for .hsReview */
|
|
||||||
}
|
|
||||||
|
|
||||||
.hsReviewPanel {
|
|
||||||
background-color: #757176;
|
|
||||||
color: white;
|
|
||||||
line-height: 1.1em;
|
|
||||||
margin: 10px 0px;
|
|
||||||
padding: 10px;
|
|
||||||
position: fixed;
|
|
||||||
width: auto;
|
|
||||||
bottom: 0px;
|
|
||||||
right: 0px;
|
|
||||||
z-index: 501;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hsReviewPanel.hsReviewing {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hsReviewPanel:hover {
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hsReviewingPanel {
|
|
||||||
background-color: white;
|
|
||||||
color: #757176;
|
|
||||||
line-height: 1.1em;
|
|
||||||
margin: 10px 0px;
|
|
||||||
padding: 10px;
|
|
||||||
position: fixed;
|
|
||||||
width: auto;
|
|
||||||
bottom: 0px;
|
|
||||||
right: 0px;
|
|
||||||
z-index: 501;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hsReviewButton:hover {
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hsUnselectable {
|
|
||||||
-webkit-touch-callout: none;
|
|
||||||
-webkit-user-select: none;
|
|
||||||
-khtml-user-select: none;
|
|
||||||
-moz-user-select: none;
|
|
||||||
-ms-user-select: none;
|
|
||||||
user-select: none;
|
|
||||||
}
|
|
||||||
|
|
@ -1,145 +0,0 @@
|
||||||
.org-bold { /* bold */ font-weight: bold; }
|
|
||||||
.org-bold-italic { /* bold-italic */ font-weight: bold; font-style: italic; }
|
|
||||||
.org-buffer-menu-buffer { /* buffer-menu-buffer */ font-weight: bold; }
|
|
||||||
.org-builtin { /* font-lock-builtin-face */ color: #7a378b; }
|
|
||||||
.org-button { /* button */ text-decoration: underline; }
|
|
||||||
.org-calendar-today { /* calendar-today */ text-decoration: underline; }
|
|
||||||
.org-change-log-acknowledgement { /* change-log-acknowledgement */ color: #b22222; }
|
|
||||||
.org-change-log-conditionals { /* change-log-conditionals */ color: #a0522d; }
|
|
||||||
.org-change-log-date { /* change-log-date */ color: #8b2252; }
|
|
||||||
.org-change-log-email { /* change-log-email */ color: #a0522d; }
|
|
||||||
.org-change-log-file { /* change-log-file */ color: #0000ff; }
|
|
||||||
.org-change-log-function { /* change-log-function */ color: #a0522d; }
|
|
||||||
.org-change-log-list { /* change-log-list */ color: #a020f0; }
|
|
||||||
.org-change-log-name { /* change-log-name */ color: #008b8b; }
|
|
||||||
.org-comint-highlight-input { /* comint-highlight-input */ font-weight: bold; }
|
|
||||||
.org-comint-highlight-prompt { /* comint-highlight-prompt */ color: #00008b; }
|
|
||||||
.org-comment { /* font-lock-comment-face */ color: #b22222; }
|
|
||||||
.org-comment-delimiter { /* font-lock-comment-delimiter-face */ color: #b22222; }
|
|
||||||
.org-completions-annotations { /* completions-annotations */ font-style: italic; }
|
|
||||||
.org-completions-common-part { /* completions-common-part */ color: #000000; background-color: #ffffff; }
|
|
||||||
.org-completions-first-difference { /* completions-first-difference */ font-weight: bold; }
|
|
||||||
.org-constant { /* font-lock-constant-face */ color: #008b8b; }
|
|
||||||
.org-diary { /* diary */ color: #ff0000; }
|
|
||||||
.org-diff-context { /* diff-context */ color: #7f7f7f; }
|
|
||||||
.org-diff-file-header { /* diff-file-header */ background-color: #b3b3b3; font-weight: bold; }
|
|
||||||
.org-diff-function { /* diff-function */ background-color: #cccccc; }
|
|
||||||
.org-diff-header { /* diff-header */ background-color: #cccccc; }
|
|
||||||
.org-diff-hunk-header { /* diff-hunk-header */ background-color: #cccccc; }
|
|
||||||
.org-diff-index { /* diff-index */ background-color: #b3b3b3; font-weight: bold; }
|
|
||||||
.org-diff-nonexistent { /* diff-nonexistent */ background-color: #b3b3b3; font-weight: bold; }
|
|
||||||
.org-diff-refine-change { /* diff-refine-change */ background-color: #d9d9d9; }
|
|
||||||
.org-dired-directory { /* dired-directory */ color: #0000ff; }
|
|
||||||
.org-dired-flagged { /* dired-flagged */ color: #ff0000; font-weight: bold; }
|
|
||||||
.org-dired-header { /* dired-header */ color: #228b22; }
|
|
||||||
.org-dired-ignored { /* dired-ignored */ color: #7f7f7f; }
|
|
||||||
.org-dired-mark { /* dired-mark */ color: #008b8b; }
|
|
||||||
.org-dired-marked { /* dired-marked */ color: #ff0000; font-weight: bold; }
|
|
||||||
.org-dired-perm-write { /* dired-perm-write */ color: #b22222; }
|
|
||||||
.org-dired-symlink { /* dired-symlink */ color: #a020f0; }
|
|
||||||
.org-dired-warning { /* dired-warning */ color: #ff0000; font-weight: bold; }
|
|
||||||
.org-doc { /* font-lock-doc-face */ color: #8b2252; }
|
|
||||||
.org-escape-glyph { /* escape-glyph */ color: #a52a2a; }
|
|
||||||
.org-file-name-shadow { /* file-name-shadow */ color: #7f7f7f; }
|
|
||||||
.org-flyspell-duplicate { /* flyspell-duplicate */ color: #cdad00; font-weight: bold; text-decoration: underline; }
|
|
||||||
.org-flyspell-incorrect { /* flyspell-incorrect */ color: #ff4500; font-weight: bold; text-decoration: underline; }
|
|
||||||
.org-fringe { /* fringe */ background-color: #f2f2f2; }
|
|
||||||
.org-function-name { /* font-lock-function-name-face */ color: #0000ff; }
|
|
||||||
.org-header-line { /* header-line */ color: #333333; background-color: #e5e5e5; }
|
|
||||||
.org-help-argument-name { /* help-argument-name */ font-style: italic; }
|
|
||||||
.org-highlight { /* highlight */ background-color: #b4eeb4; }
|
|
||||||
.org-holiday { /* holiday */ background-color: #ffc0cb; }
|
|
||||||
.org-isearch { /* isearch */ color: #b0e2ff; background-color: #cd00cd; }
|
|
||||||
.org-isearch-fail { /* isearch-fail */ background-color: #ffc1c1; }
|
|
||||||
.org-italic { /* italic */ font-style: italic; }
|
|
||||||
.org-keyword { /* font-lock-keyword-face */ color: #a020f0; }
|
|
||||||
.org-lazy-highlight { /* lazy-highlight */ background-color: #afeeee; }
|
|
||||||
.org-link { /* link */ color: #0000ff; text-decoration: underline; }
|
|
||||||
.org-link-visited { /* link-visited */ color: #8b008b; text-decoration: underline; }
|
|
||||||
.org-log-edit-header { /* log-edit-header */ color: #a020f0; }
|
|
||||||
.org-log-edit-summary { /* log-edit-summary */ color: #0000ff; }
|
|
||||||
.org-log-edit-unknown-header { /* log-edit-unknown-header */ color: #b22222; }
|
|
||||||
.org-match { /* match */ background-color: #ffff00; }
|
|
||||||
.org-next-error { /* next-error */ background-color: #eedc82; }
|
|
||||||
.org-nobreak-space { /* nobreak-space */ color: #a52a2a; text-decoration: underline; }
|
|
||||||
.org-org-archived { /* org-archived */ color: #7f7f7f; }
|
|
||||||
.org-org-block { /* org-block */ color: #7f7f7f; }
|
|
||||||
.org-org-block-begin-line { /* org-block-begin-line */ color: #b22222; }
|
|
||||||
.org-org-block-end-line { /* org-block-end-line */ color: #b22222; }
|
|
||||||
.org-org-checkbox { /* org-checkbox */ font-weight: bold; }
|
|
||||||
.org-org-checkbox-statistics-done { /* org-checkbox-statistics-done */ color: #228b22; font-weight: bold; }
|
|
||||||
.org-org-checkbox-statistics-todo { /* org-checkbox-statistics-todo */ color: #ff0000; font-weight: bold; }
|
|
||||||
.org-org-clock-overlay { /* org-clock-overlay */ background-color: #ffff00; }
|
|
||||||
.org-org-code { /* org-code */ color: #7f7f7f; }
|
|
||||||
.org-org-column { /* org-column */ background-color: #e5e5e5; }
|
|
||||||
.org-org-column-title { /* org-column-title */ background-color: #e5e5e5; font-weight: bold; text-decoration: underline; }
|
|
||||||
.org-org-date { /* org-date */ color: #a020f0; text-decoration: underline; }
|
|
||||||
.org-org-document-info { /* org-document-info */ color: #191970; }
|
|
||||||
.org-org-document-info-keyword { /* org-document-info-keyword */ color: #7f7f7f; }
|
|
||||||
.org-org-document-title { /* org-document-title */ color: #191970; font-size: 144%; font-weight: bold; }
|
|
||||||
.org-org-done { /* org-done */ color: #228b22; font-weight: bold; }
|
|
||||||
.org-org-drawer { /* org-drawer */ color: #0000ff; }
|
|
||||||
.org-org-ellipsis { /* org-ellipsis */ color: #b8860b; text-decoration: underline; }
|
|
||||||
.org-org-footnote { /* org-footnote */ color: #a020f0; text-decoration: underline; }
|
|
||||||
.org-org-formula { /* org-formula */ color: #b22222; }
|
|
||||||
.org-org-headline-done { /* org-headline-done */ color: #bc8f8f; }
|
|
||||||
.org-org-hide { /* org-hide */ color: #ffffff; }
|
|
||||||
.org-org-latex-and-export-specials { /* org-latex-and-export-specials */ color: #8b4513; }
|
|
||||||
.org-org-level-1 { /* org-level-1 */ color: #0000ff; }
|
|
||||||
.org-org-level-2 { /* org-level-2 */ color: #a0522d; }
|
|
||||||
.org-org-level-3 { /* org-level-3 */ color: #a020f0; }
|
|
||||||
.org-org-level-4 { /* org-level-4 */ color: #b22222; }
|
|
||||||
.org-org-level-5 { /* org-level-5 */ color: #228b22; }
|
|
||||||
.org-org-level-6 { /* org-level-6 */ color: #008b8b; }
|
|
||||||
.org-org-level-7 { /* org-level-7 */ color: #7a378b; }
|
|
||||||
.org-org-level-8 { /* org-level-8 */ color: #8b2252; }
|
|
||||||
.org-org-link { /* org-link */ color: #0000ff; text-decoration: underline; }
|
|
||||||
.org-org-meta-line { /* org-meta-line */ color: #b22222; }
|
|
||||||
.org-org-mode-line-clock { /* org-mode-line-clock */ color: #000000; background-color: #bfbfbf; }
|
|
||||||
.org-org-mode-line-clock-overrun { /* org-mode-line-clock-overrun */ color: #000000; background-color: #ff0000; }
|
|
||||||
.org-org-quote { /* org-quote */ color: #7f7f7f; }
|
|
||||||
.org-org-scheduled { /* org-scheduled */ color: #006400; }
|
|
||||||
.org-org-scheduled-previously { /* org-scheduled-previously */ color: #b22222; }
|
|
||||||
.org-org-scheduled-today { /* org-scheduled-today */ color: #006400; }
|
|
||||||
.org-org-sexp-date { /* org-sexp-date */ color: #a020f0; }
|
|
||||||
.org-org-special-keyword { /* org-special-keyword */ color: #a020f0; }
|
|
||||||
.org-org-table { /* org-table */ color: #0000ff; }
|
|
||||||
.org-org-tag { /* org-tag */ font-weight: bold; }
|
|
||||||
.org-org-target { /* org-target */ text-decoration: underline; }
|
|
||||||
.org-org-time-grid { /* org-time-grid */ color: #b8860b; }
|
|
||||||
.org-org-todo { /* org-todo */ color: #ff0000; font-weight: bold; }
|
|
||||||
.org-org-upcoming-deadline { /* org-upcoming-deadline */ color: #b22222; }
|
|
||||||
.org-org-verbatim { /* org-verbatim */ color: #7f7f7f; }
|
|
||||||
.org-org-verse { /* org-verse */ color: #7f7f7f; }
|
|
||||||
.org-org-warning { /* org-warning */ color: #ff0000; font-weight: bold; }
|
|
||||||
.org-outline-1 { /* outline-1 */ color: #0000ff; }
|
|
||||||
.org-outline-2 { /* outline-2 */ color: #a0522d; }
|
|
||||||
.org-outline-3 { /* outline-3 */ color: #a020f0; }
|
|
||||||
.org-outline-4 { /* outline-4 */ color: #b22222; }
|
|
||||||
.org-outline-5 { /* outline-5 */ color: #228b22; }
|
|
||||||
.org-outline-6 { /* outline-6 */ color: #008b8b; }
|
|
||||||
.org-outline-7 { /* outline-7 */ color: #7a378b; }
|
|
||||||
.org-outline-8 { /* outline-8 */ color: #8b2252; }
|
|
||||||
.org-preprocessor { /* font-lock-preprocessor-face */ color: #7a378b; }
|
|
||||||
.org-query-replace { /* query-replace */ color: #b0e2ff; background-color: #cd00cd; }
|
|
||||||
.org-regexp-grouping-backslash { /* font-lock-regexp-grouping-backslash */ font-weight: bold; }
|
|
||||||
.org-regexp-grouping-construct { /* font-lock-regexp-grouping-construct */ font-weight: bold; }
|
|
||||||
.org-region { /* region */ background-color: #eedc82; }
|
|
||||||
.org-secondary-selection { /* secondary-selection */ background-color: #ffff00; }
|
|
||||||
.org-shadow { /* shadow */ color: #7f7f7f; }
|
|
||||||
.org-show-paren-match { /* show-paren-match */ background-color: #40e0d0; }
|
|
||||||
.org-show-paren-mismatch { /* show-paren-mismatch */ color: #ffffff; background-color: #a020f0; }
|
|
||||||
.org-string { /* font-lock-string-face */ color: #8b2252; }
|
|
||||||
.org-tool-bar { /* tool-bar */ color: #000000; background-color: #bfbfbf; }
|
|
||||||
.org-tooltip { /* tooltip */ color: #000000; background-color: #ffffe0; }
|
|
||||||
.org-trailing-whitespace { /* trailing-whitespace */ background-color: #ff0000; }
|
|
||||||
.org-type { /* font-lock-type-face */ color: #228b22; }
|
|
||||||
.org-underline { /* underline */ text-decoration: underline; }
|
|
||||||
.org-variable-name { /* font-lock-variable-name-face */ color: #a0522d; }
|
|
||||||
.org-warning { /* font-lock-warning-face */ color: #ff0000; font-weight: bold; }
|
|
||||||
.org-widget-button { /* widget-button */ font-weight: bold; }
|
|
||||||
.org-widget-button-pressed { /* widget-button-pressed */ color: #ff0000; }
|
|
||||||
.org-widget-documentation { /* widget-documentation */ color: #006400; }
|
|
||||||
.org-widget-field { /* widget-field */ background-color: #d9d9d9; }
|
|
||||||
.org-widget-inactive { /* widget-inactive */ color: #7f7f7f; }
|
|
||||||
.org-widget-single-line-field { /* widget-single-line-field */ background-color: #d9d9d9; }
|
|
||||||
|
Before Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 625 B |
|
Before Width: | Height: | Size: 3 KiB |
|
Before Width: | Height: | Size: 4.3 KiB |
|
Before Width: | Height: | Size: 4.5 KiB |
|
Before Width: | Height: | Size: 4.3 KiB |
|
Before Width: | Height: | Size: 3 KiB |
|
Before Width: | Height: | Size: 4.2 KiB |
|
|
@ -1,524 +0,0 @@
|
||||||
// darksun.js --- darksun JS file
|
|
||||||
//
|
|
||||||
// Copyright (C) 2011-2016 All Right Reserved, Fabrice Niessen
|
|
||||||
//
|
|
||||||
// This file is free software: you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of
|
|
||||||
// the License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This file is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// Author: Fabrice Niessen <(concat "fniessen" at-sign "pirilampo.org")>
|
|
||||||
// URL: https://github.com/fniessen/org-html-themes/
|
|
||||||
// Version: 20140515.1841
|
|
||||||
|
|
||||||
$(function() {
|
|
||||||
$('p').
|
|
||||||
html(function(index, old) {
|
|
||||||
return old.replace('FIXME',
|
|
||||||
'<span class="fixme">FIXME</span>');
|
|
||||||
});
|
|
||||||
$('p').
|
|
||||||
html(function(index, old) {
|
|
||||||
return old.replace('XXX',
|
|
||||||
'<span class="fixme">XXX</span>');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Remove leading section number
|
|
||||||
$(function() {
|
|
||||||
$('.section-number-2').text("");
|
|
||||||
for (var i = 3; i <= 5; i++) {
|
|
||||||
$('.section-number-' + i).each(function() {
|
|
||||||
$(this).text($(this).text().replace(/^[0-9]+\./g, ""));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$(function() {
|
|
||||||
$('<div id="minitoc" class="dontprint"></div>').prependTo('body');
|
|
||||||
});
|
|
||||||
|
|
||||||
// generate contents of minitoc
|
|
||||||
function generateMiniToc(divId) {
|
|
||||||
$('#minitoc-content').empty().append('<h2>In this section</h2><ul></ul>');
|
|
||||||
$('#' + divId).find('h3').each(function(i) {
|
|
||||||
// [2018-09-03 Mon 03:48] Get text up to non-breaking space,
|
|
||||||
// to omit the tags. If there are no tags, there will be no
|
|
||||||
// , so get all the text. (This fixes a bug in the
|
|
||||||
// original code.)
|
|
||||||
let text = null;
|
|
||||||
let pos = $(this).text().search(/ | ►/);
|
|
||||||
if (pos > 0) {
|
|
||||||
text = $(this).text().substring(0, pos);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
text = $(this).text();
|
|
||||||
}
|
|
||||||
$("#minitoc-content>ul").append("<li><a href='#" + $(this).attr("id") + "'>"
|
|
||||||
+ text + "</a></li>");
|
|
||||||
});
|
|
||||||
// Ensure that the target is expanded (hideShow)
|
|
||||||
$('#minitoc-content a[href^="#"]').click(function() {
|
|
||||||
var href = $(this).attr('href');
|
|
||||||
hsExpandAnchor(href);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// display tabs
|
|
||||||
function tabifySections() {
|
|
||||||
|
|
||||||
// hide TOC (if present)
|
|
||||||
$('#table-of-contents').hide();
|
|
||||||
|
|
||||||
// grab the list of `h2' from the page
|
|
||||||
var allSections = [];
|
|
||||||
$('h2')
|
|
||||||
.each(function() {
|
|
||||||
// Remove TODO keywords and tags (contained in spans)
|
|
||||||
var tabText = $(this).clone().find('span').remove().end()
|
|
||||||
.text().trim();
|
|
||||||
var tabId = $(this).parent().attr('id');
|
|
||||||
if (tabText) {
|
|
||||||
// - remove heading number (all leading digits)
|
|
||||||
// - remove progress logging (between square brackets)
|
|
||||||
// - remove leading and trailing spaces
|
|
||||||
tabText = tabText.replace(/^\d+\s+/, '').replace(/\[[\d/%]+\]/, '').trim();
|
|
||||||
|
|
||||||
allSections.push({
|
|
||||||
text: tabText,
|
|
||||||
id: tabId
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// create the tab links
|
|
||||||
var tabs = $('<ul id="tabs"></ul>');
|
|
||||||
for (i = 0; i < allSections.length; i++) {
|
|
||||||
var item = allSections[i];
|
|
||||||
html = $('<li><a href="#' + item.id + '">' + item.text + '</a></li>');
|
|
||||||
tabs.append(html);
|
|
||||||
}
|
|
||||||
|
|
||||||
// insert tabs menu after title (`h1'), or at the beginning of the content
|
|
||||||
if($('.title').length !== 0) {
|
|
||||||
$('.title').after(tabs);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$('#content').prepend(tabs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function selectTabAndScroll(href) {
|
|
||||||
// At this point we assume that href is local (starts with #)
|
|
||||||
// alert(href);
|
|
||||||
|
|
||||||
// Find the tab to activate
|
|
||||||
var targetTab = $(href).closest('.ui-tabs-panel');
|
|
||||||
var targetTabId = targetTab.attr('id');
|
|
||||||
var targetTabAriaLabel = targetTab.attr('aria-labelledby');
|
|
||||||
|
|
||||||
var targetTabIndex = $("#content ul li")
|
|
||||||
.index($('[aria-labelledby="' + targetTabAriaLabel + '"]'));
|
|
||||||
|
|
||||||
// Activate target tab
|
|
||||||
$('#content').tabs('option', 'active', targetTabIndex);
|
|
||||||
|
|
||||||
// Rebuild minitoc
|
|
||||||
generateMiniToc(targetTabId);
|
|
||||||
|
|
||||||
// Set the location hash
|
|
||||||
// document.location.hash = href;
|
|
||||||
|
|
||||||
// Scroll to top if href was a tab
|
|
||||||
if (href == '#' + targetTabId) {
|
|
||||||
// alert(targetTabId);
|
|
||||||
$.scrollTo(0);
|
|
||||||
}
|
|
||||||
// Scroll to href if href was not a tab
|
|
||||||
else {
|
|
||||||
$.scrollTo(href);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
|
||||||
$('#preamble').remove();
|
|
||||||
$('#table-of-contents').remove();
|
|
||||||
|
|
||||||
// Initialize hideShow
|
|
||||||
hsInit();
|
|
||||||
|
|
||||||
// Prepare for tabs
|
|
||||||
tabifySections();
|
|
||||||
|
|
||||||
// Build the tabs from the #content div
|
|
||||||
$('#content').tabs();
|
|
||||||
|
|
||||||
// Set default animation
|
|
||||||
$('#content').tabs('option', 'show', true);
|
|
||||||
|
|
||||||
// Rebuild minitoc when a tab is activated
|
|
||||||
$('#content').tabs({
|
|
||||||
activate: function(event, ui) {
|
|
||||||
var divId = ui.newTab.attr('aria-controls');
|
|
||||||
generateMiniToc(divId);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Required to get the link of the tab in URL
|
|
||||||
$('#content ul').localScroll({
|
|
||||||
target: '#content',
|
|
||||||
duration: 0,
|
|
||||||
hash: true
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle hash in URL
|
|
||||||
if ($('#content') && document.location.hash) {
|
|
||||||
hsExpandAnchor(document.location.hash);
|
|
||||||
selectTabAndScroll(document.location.hash);
|
|
||||||
}
|
|
||||||
// If no hash, build the minitoc anyway for selected tab
|
|
||||||
else {
|
|
||||||
var divId = $('#content div[aria-expanded=true]').attr('id');
|
|
||||||
generateMiniToc(divId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle click on internal links
|
|
||||||
$('.ui-tabs-panel a[href^="#"]').click(function(e) {
|
|
||||||
var href = $(this).attr('href');
|
|
||||||
hsExpandAnchor(href);
|
|
||||||
selectTabAndScroll(href);
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
|
|
||||||
// add sticky headers to tables
|
|
||||||
$('table').stickyTableHeaders();
|
|
||||||
});
|
|
||||||
|
|
||||||
function copyToClipboard(text)
|
|
||||||
{
|
|
||||||
if (window.clipboardData && window.clipboardData.setData) { // Internet Explorer
|
|
||||||
window.clipboardData.setData("Text", text);
|
|
||||||
}
|
|
||||||
else { // Fallback solution
|
|
||||||
window.prompt("Copy to clipboard: Ctrl+C, Enter", text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
|
||||||
// Assuming that the ZeroClipboard swf file is in the same folder than darksun,
|
|
||||||
// get the path to it (it will be relative to the current page location).
|
|
||||||
var bbScriptPath = $('script[src$="darksun.js"]').attr('src'); // the js file path
|
|
||||||
var bbPathToZeroClipboardSwf = bbScriptPath.replace('darksun.js', 'ZeroClipboard.swf');
|
|
||||||
|
|
||||||
// Add copy to clipboard snippets
|
|
||||||
$('.org-src-container').prepend('<div class="snippet-copy-to-clipboard"><span class="copy-to-clipboard-button">[copy]</span></div>');
|
|
||||||
|
|
||||||
// Display/hide snippets on source block mouseenter/mouseleave
|
|
||||||
$(document).on('mouseenter', '.org-src-container', function () {
|
|
||||||
$(this).find('.snippet-copy-to-clipboard').show();
|
|
||||||
|
|
||||||
// Need to call zclip here, once the button is visible.
|
|
||||||
// Beacause when the button is not visible, zclip does nothing.
|
|
||||||
if ((window.location.protocol != 'file:') && ($(this).find('.zclip').length == 0)) {
|
|
||||||
$(this).find('.copy-to-clipboard-button').zclip({
|
|
||||||
//path: 'http://www.steamdev.com/zclip/js/ZeroClipboard.swf',
|
|
||||||
//path: 'styles/darksun/js/ZeroClipboard.swf',
|
|
||||||
path: bbPathToZeroClipboardSwf,
|
|
||||||
copy: function() {
|
|
||||||
return $(this).parent().parent().find('.src').text();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}).on('mouseleave', '.org-src-container', function () {
|
|
||||||
$(this).find('.snippet-copy-to-clipboard').hide();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle copy to clipboard (here, for a local file only 'file://...'
|
|
||||||
if (window.location.protocol == 'file:') { // if local file use browser-specific code
|
|
||||||
$('.copy-to-clipboard-button').click(function() {
|
|
||||||
// Get the text to be copied
|
|
||||||
var text = $(this).parent().parent().find('.src').text();
|
|
||||||
text = text.replace(/\n/g, "\r\n");
|
|
||||||
// alert(text);
|
|
||||||
copyToClipboard(text);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$(function() {
|
|
||||||
$('li > code :contains("[X]")')
|
|
||||||
.parent()
|
|
||||||
.addClass('checked')
|
|
||||||
.end()
|
|
||||||
.remove();
|
|
||||||
$('li > code :contains("[-]")')
|
|
||||||
.parent()
|
|
||||||
.addClass('halfchecked')
|
|
||||||
.end()
|
|
||||||
.remove();
|
|
||||||
$('li > code :contains("[ ]")')
|
|
||||||
.parent()
|
|
||||||
.addClass('unchecked')
|
|
||||||
.end()
|
|
||||||
.remove();
|
|
||||||
});
|
|
||||||
|
|
||||||
$(function() {
|
|
||||||
$('i :contains("[#A]")')
|
|
||||||
.replaceWith('<i><span style="color: #F67777;">[#A]</span></i>');
|
|
||||||
$('i :contains("[#B]")')
|
|
||||||
.replaceWith('<i><span style="color: #B6E864;">[#B]</span></i>');
|
|
||||||
$('i :contains("[#C]")')
|
|
||||||
.replaceWith('<i><span style="color: #C3DCFF;">[#C]</span></i>');
|
|
||||||
});
|
|
||||||
|
|
||||||
function togglePanel(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
$("#left-panel-contents").toggleClass('active').toggle(200);
|
|
||||||
$("#right-panel-contents").toggleClass('active').toggle(200);
|
|
||||||
|
|
||||||
var slidePos =
|
|
||||||
$("#left-panel-button").css("left") == "-23px"? '182px': '-23px';
|
|
||||||
|
|
||||||
$("#left-panel-button").
|
|
||||||
animate({"left": slidePos, "opacity": 0.9}, {duration: "200" });
|
|
||||||
|
|
||||||
// if ($("#left-panel-contents").hasClass('active')) {
|
|
||||||
// hsHideTodoKeyword('done');
|
|
||||||
// } else {
|
|
||||||
// hsShowTodoKeyword('done');
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$(function() {
|
|
||||||
$('<div id="left-panel-wrapper" class="dontprint"><div id="left-panel-contents" style="opacity: 0.9"></div><div id="left-panel-button" class="dontprint"><a href="#">Dashboard</a></div></div>')
|
|
||||||
.appendTo('body');
|
|
||||||
|
|
||||||
$('<div id="right-panel-wrapper" class="dontprint"><div id="right-panel-contents" style="opacity: 0.9"></div></div>')
|
|
||||||
.appendTo('body');
|
|
||||||
|
|
||||||
$('#left-panel-button').click(togglePanel);
|
|
||||||
});
|
|
||||||
|
|
||||||
$(function() {
|
|
||||||
var ul = $('<ul id="listOfTodo"></ul>').appendTo('#left-panel-contents');
|
|
||||||
var countOfTodo = {}, listOfTodo = [], totalOfTodo = 0;
|
|
||||||
|
|
||||||
// assign the counts (avoid double-counting elements from the ToC)
|
|
||||||
$('span.todo').not($('#table-of-contents span.todo')).each(function() {
|
|
||||||
var $thisTodo = $(this).text().trim();
|
|
||||||
|
|
||||||
if ($.inArray($thisTodo, listOfTodo) == -1) {
|
|
||||||
countOfTodo[$thisTodo] = 1;
|
|
||||||
listOfTodo.push($thisTodo);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
countOfTodo[$thisTodo] += 1;
|
|
||||||
totalOfTodo += 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
function scoreTodo(t) {
|
|
||||||
switch (t) {
|
|
||||||
case 'NEW': return 1;
|
|
||||||
case 'TODO': return 2;
|
|
||||||
case 'STRT': return 3;
|
|
||||||
case 'WAIT': return 4;
|
|
||||||
case 'DLGT': return 5;
|
|
||||||
case 'SDAY': return 6;
|
|
||||||
case 'DFRD': return 7;
|
|
||||||
case 'DONE': return 8;
|
|
||||||
case 'CANX': return 9;
|
|
||||||
default: return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function compareTodo(a, b) {
|
|
||||||
if (scoreTodo(a) < scoreTodo(b)) return -1;
|
|
||||||
if (scoreTodo(a) > scoreTodo(b)) return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
listOfTodo.sort(compareTodo);
|
|
||||||
|
|
||||||
// display
|
|
||||||
for (i = 0; i < listOfTodo.length; i++) {
|
|
||||||
var $thisTodo = listOfTodo[i];
|
|
||||||
$(ul).append('<li><span class="todo ' + $thisTodo + '">'+ $thisTodo + '</span>'
|
|
||||||
+ ' <small>(' + countOfTodo[$thisTodo] + ')</small></li>');
|
|
||||||
}
|
|
||||||
|
|
||||||
$('#listOfTodo')
|
|
||||||
.before('<b>Next Actions</b> <small>(' + totalOfTodo + ')</small>:<br>');
|
|
||||||
});
|
|
||||||
|
|
||||||
$(function() {
|
|
||||||
var ul = $('<ul id="listOfDone"></ul>').appendTo('#left-panel-contents');
|
|
||||||
var countOfDone = {}, listOfDone = [], totalOfDone = 0;
|
|
||||||
|
|
||||||
// assign the counts (avoid double-counting elements from the ToC)
|
|
||||||
$('span.done').not($('#table-of-contents span.done')).each(function() {
|
|
||||||
var $thisDone = $(this).text().trim();
|
|
||||||
|
|
||||||
if ($.inArray($thisDone, listOfDone) == -1) {
|
|
||||||
countOfDone[$thisDone] = 1;
|
|
||||||
listOfDone.push($thisDone);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
countOfDone[$thisDone] += 1;
|
|
||||||
totalOfDone += 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
// display
|
|
||||||
for (i = 0; i < listOfDone.length; i++) {
|
|
||||||
var $thisDone = listOfDone[i];
|
|
||||||
$(ul).append('<li><span class="done ' + $thisDone + '">'+ $thisDone + '</span>'
|
|
||||||
+ ' <small>(' + countOfDone[$thisDone] + ')</small></li>');
|
|
||||||
}
|
|
||||||
|
|
||||||
$('#listOfDone')
|
|
||||||
.before('<b>Done Actions</b> <small>(' + totalOfDone + '):</small><br>');
|
|
||||||
});
|
|
||||||
|
|
||||||
$(function() {
|
|
||||||
var ul = $('<ul id="listOfTags"></ul>').appendTo('#right-panel-contents');
|
|
||||||
var countOfTags = {}, listOfTags = [], totalOfTags = 0;
|
|
||||||
|
|
||||||
// assign the counts (avoid double-counting elements from the ToC)
|
|
||||||
$('span.tag').not($('#table-of-contents span.tag')).each(function() {
|
|
||||||
var $thisTagGroup = $(this).text().trim().split(/\s/);
|
|
||||||
// \s matches spaces, tabs, new lines, etc.
|
|
||||||
|
|
||||||
for (tag in $thisTagGroup) {
|
|
||||||
if ($.inArray($thisTagGroup[tag], listOfTags) == -1) {
|
|
||||||
countOfTags[$thisTagGroup[tag]] = 1;
|
|
||||||
listOfTags.push($thisTagGroup[tag]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
countOfTags[$thisTagGroup[tag]] += 1;
|
|
||||||
totalOfTags += 1;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
listOfTags.sort();
|
|
||||||
|
|
||||||
// display
|
|
||||||
for (i = 0; i < listOfTags.length; i++) {
|
|
||||||
var $thisTag = listOfTags[i];
|
|
||||||
// $(ul).append('<li><span class="tag ' + $thisTag + '">'+
|
|
||||||
// $thisTag + '</span> <small>(' + countOfTags[$thisTag] + ')</small></li>');
|
|
||||||
$(ul).append('<li><span class="tag"><span class="' + $thisTag + '">' + $thisTag
|
|
||||||
+ '</span></span>'
|
|
||||||
+ ' <small>(' + countOfTags[$thisTag] + ')</small></li>');
|
|
||||||
}
|
|
||||||
|
|
||||||
$('#listOfTags')
|
|
||||||
.before('<b>Contexts</b> <small>(' + totalOfTags + '):</small><br>');
|
|
||||||
});
|
|
||||||
|
|
||||||
$(function() {
|
|
||||||
$('.done').parent(':header').parent().find(':header').addClass('DONEheader');
|
|
||||||
$('.done').parent(':header').parent().css({color: '#999999'});
|
|
||||||
});
|
|
||||||
|
|
||||||
$(function() {
|
|
||||||
$('span.todo').click(function(e) {
|
|
||||||
var orgKeyword = $(this).text().trim();
|
|
||||||
$('.' + orgKeyword).toggleClass('selected');
|
|
||||||
$('#content .' + orgKeyword).parent().parent()
|
|
||||||
.toggleClass('match' + orgKeyword);
|
|
||||||
$('#left-panel-wrapper .' + orgKeyword).parent()
|
|
||||||
.toggleClass('match' + orgKeyword);
|
|
||||||
e.preventDefault();
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
$(function() {
|
|
||||||
$('.tag span').click(function(e) {
|
|
||||||
var orgTag = $(this).text().trim();
|
|
||||||
$('.' + orgTag).toggleClass('selected');
|
|
||||||
$('#content .' + orgTag).parent().parent().parent()
|
|
||||||
.toggleClass('matchtag');
|
|
||||||
$('#right-panel-wrapper .' + orgTag).parent().parent()
|
|
||||||
.toggleClass('matchtag');
|
|
||||||
e.preventDefault();
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
function clickPreviousTab() {
|
|
||||||
var active = $('#content').tabs('option', 'active');
|
|
||||||
// Avoid going back to last tab
|
|
||||||
if (active == 0) return;
|
|
||||||
|
|
||||||
$('#content').tabs('option', 'active', active - 1);
|
|
||||||
|
|
||||||
// Set the location href
|
|
||||||
var href = $('#content div[aria-expanded=true]').attr('id');
|
|
||||||
document.location.hash = href;
|
|
||||||
$.scrollTo(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
function clickNextTab() {
|
|
||||||
var active = $('#content').tabs('option', 'active');
|
|
||||||
$('#content').tabs('option', 'active', active + 1);
|
|
||||||
|
|
||||||
// Set the location href
|
|
||||||
var href = $('#content div[aria-expanded=true]').attr('id');
|
|
||||||
document.location.hash = href;
|
|
||||||
$.scrollTo(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
function orgDefkey(e) {
|
|
||||||
if (!e)
|
|
||||||
var e = window.event;
|
|
||||||
var keycode = (e.keyCode) ? e.keyCode : e.which;
|
|
||||||
var actualkey = String.fromCharCode(keycode);
|
|
||||||
switch (actualkey) {
|
|
||||||
case "?": // help (dashboard)
|
|
||||||
case "h":
|
|
||||||
togglePanel(e);
|
|
||||||
break;
|
|
||||||
case "n": // next
|
|
||||||
clickNextTab();
|
|
||||||
break;
|
|
||||||
case "p": // previous
|
|
||||||
clickPreviousTab();
|
|
||||||
break;
|
|
||||||
// case "b": // scroll down - should be mapped to Shift-SPC
|
|
||||||
// $(window).scrollTop($(window).scrollTop()-$(window).height());
|
|
||||||
// break;
|
|
||||||
case "<": // scroll to top
|
|
||||||
$(window).scrollTop(0);
|
|
||||||
break;
|
|
||||||
case ">": // scroll to bottom
|
|
||||||
$(window).scrollTop($(document).height());
|
|
||||||
break;
|
|
||||||
case "-": // collapse all
|
|
||||||
hsCollapseAll();
|
|
||||||
break;
|
|
||||||
case "+": // expand all
|
|
||||||
hsExpandAll();
|
|
||||||
break;
|
|
||||||
case "r": // go to next task
|
|
||||||
hsReviewTaskNext();
|
|
||||||
break;
|
|
||||||
case "R": // go to previous task
|
|
||||||
hsReviewTaskPrev();
|
|
||||||
break;
|
|
||||||
case "q": // quit reviewing
|
|
||||||
hsReviewTaskQuit();
|
|
||||||
break;
|
|
||||||
case "g": // refresh the page (from the server, rather than the cache)
|
|
||||||
location.reload(true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
document.onkeypress = orgDefkey;
|
|
||||||
|
|
@ -1,335 +0,0 @@
|
||||||
// hideshow.js --- HideShow JS file
|
|
||||||
//
|
|
||||||
// Copyright (C) 2014 All Right Reserved, Fabrice Niessen
|
|
||||||
//
|
|
||||||
// This file is free software: you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of
|
|
||||||
// the License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This file is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// Author: Fabrice Niessen <(concat "fniessen" at-sign "pirilampo.org")>
|
|
||||||
// URL: https://github.com/fniessen/hide-show/
|
|
||||||
// Version: 20140912.1722
|
|
||||||
|
|
||||||
// var HS_COLLAPSIBLE_HEADERS = $('h3, h4, h5'); // collapsible headers
|
|
||||||
|
|
||||||
if (typeof HS_STARTUP_FOLDED === 'undefined') {
|
|
||||||
var HS_STARTUP_FOLDED = false; // Show just the overview, or show all.
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof HS_SHOW_ALL_TEXT === 'undefined') {
|
|
||||||
var HS_SHOW_ALL_TEXT = 'Expand';
|
|
||||||
}
|
|
||||||
if (typeof HS_HIDE_ALL_TEXT === 'undefined') {
|
|
||||||
var HS_HIDE_ALL_TEXT = 'Collapse';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof HS_ALWAYS_DISPLAY_ICON === 'undefined') {
|
|
||||||
var HS_ALWAYS_DISPLAY_ICON = false; // Display an icon for all states, or
|
|
||||||
// just when closed.
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof HS_ICON_CLOSED === 'undefined') {
|
|
||||||
var HS_ICON_CLOSED = '►'; // black right-pointing pointer
|
|
||||||
}
|
|
||||||
if (typeof HS_ICON_OPEN === 'undefined') {
|
|
||||||
var HS_ICON_OPEN = '▼'; // black down-pointing triangle
|
|
||||||
}
|
|
||||||
if (typeof HS_ICON_EMPTY === 'undefined') {
|
|
||||||
var HS_ICON_EMPTY = '■'; // black square
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof HS_SHOW_ALL_OPEN_DONE_TREES === 'undefined') {
|
|
||||||
var HS_SHOW_ALL_OPEN_DONE_TREES = false; // Expand all will open DONE trees.
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof HS_CLASS === 'undefined') {
|
|
||||||
var HS_CLASS = 'hsCollapsible';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Expand a header
|
|
||||||
function hsExpand(header) {
|
|
||||||
hsExpand2(header, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Expand a header
|
|
||||||
function hsExpand2(header, expandDoneHeader) {
|
|
||||||
// Ignore non collapsible entries
|
|
||||||
if (!header.parent().hasClass(HS_CLASS)) return;
|
|
||||||
|
|
||||||
// Do not expand DONE node if not required
|
|
||||||
if (hsIsDoneHeader(header) && !expandDoneHeader) return;
|
|
||||||
|
|
||||||
header.children('span[class="ellipsis"]').remove();
|
|
||||||
if (HS_ALWAYS_DISPLAY_ICON == true) {
|
|
||||||
header.append('<span class="ellipsis"> ' + HS_ICON_OPEN + '</span>');
|
|
||||||
}
|
|
||||||
header.parent().removeClass('hsCollapsed').addClass('hsExpanded');
|
|
||||||
header.nextAll().show();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Expand a header and all its parents
|
|
||||||
function hsExpandParents(header) {
|
|
||||||
hsExpand(header);
|
|
||||||
header.parents('.hsCollapsed').each(function() {
|
|
||||||
hsExpand($(this).children(':header'));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collapse a header and all its parents
|
|
||||||
function hsCollapseParents(header) {
|
|
||||||
hsCollapse(header);
|
|
||||||
header.parents('.hsExpanded').each(function() {
|
|
||||||
hsCollapse($(this).children(':header'));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collapse a header
|
|
||||||
function hsCollapse(header) {
|
|
||||||
// Ignore non collapsible entries
|
|
||||||
if (!header.parent().hasClass(HS_CLASS)) return;
|
|
||||||
|
|
||||||
header.children('span[class="ellipsis"]').remove();
|
|
||||||
header.append('<span class="ellipsis"> ' + HS_ICON_CLOSED + '</span>');
|
|
||||||
header.parent().removeClass('hsExpanded').addClass('hsCollapsed');
|
|
||||||
// header.nextAll().hide('fast');
|
|
||||||
header.nextAll().hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Toggle a header
|
|
||||||
function hsToggleCollapsing(header) {
|
|
||||||
if (header.parent().hasClass('hsCollapsed'))
|
|
||||||
hsExpand(header);
|
|
||||||
else if (header.parent().hasClass('hsExpanded'))
|
|
||||||
hsCollapse(header);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Expand all headers
|
|
||||||
function hsExpandAll() {
|
|
||||||
$('#content .hsCollapsed').each(function() {
|
|
||||||
hsExpand2($(this).children(':header'), HS_SHOW_ALL_OPEN_DONE_TREES);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collapse all headers
|
|
||||||
function hsCollapseAll() {
|
|
||||||
$('#content .hsExpanded').each(function() {
|
|
||||||
hsCollapse($(this).children(':header'));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collapse all visible headers
|
|
||||||
function hsCollapseAllVisible() {
|
|
||||||
$('#content .hsExpanded:visible').each(function() {
|
|
||||||
hsCollapse($(this).children(':header'));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add click events to H3/H4/H5 headers which have contents.
|
|
||||||
function hsInit() {
|
|
||||||
for (var i = 3; i <= 5; i++) {
|
|
||||||
$('#content .outline-' + i).each(function() {
|
|
||||||
var header = $(this).children(':header');
|
|
||||||
if (header.siblings().length > 0) {
|
|
||||||
$(this).addClass(HS_CLASS);
|
|
||||||
header.css({cursor: 'pointer'});
|
|
||||||
header.click(function() {
|
|
||||||
hsToggleCollapsing($(this)); });
|
|
||||||
|
|
||||||
// Allow to override global Collapse/Expand default on an entry
|
|
||||||
// basis (see property `:HTML_CONTAINER_CLASS:')
|
|
||||||
if (header.parent().hasClass('hsCollapsed')) {
|
|
||||||
hsCollapse(header);
|
|
||||||
} else if (header.parent().hasClass('hsExpanded')) {
|
|
||||||
hsExpand(header);
|
|
||||||
} else {
|
|
||||||
hsSetDefaultVisibility(header);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (HS_ALWAYS_DISPLAY_ICON == true) {
|
|
||||||
header.append('<span class="ellipsis"> ' + HS_ICON_EMPTY
|
|
||||||
+ '</span>');
|
|
||||||
}
|
|
||||||
$(this).addClass('hsEmpty');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add div to hold minitoc content (so it can be cleared without deleting the buttons)
|
|
||||||
$('#minitoc').append($('<div id="minitoc-content"></div>'));
|
|
||||||
|
|
||||||
// Add buttons
|
|
||||||
$('#minitoc').append($('<div class="buttons dontprint"></div>'));
|
|
||||||
$('.buttons').append($('<span>' + HS_SHOW_ALL_TEXT + '</span>')
|
|
||||||
.addClass('hsButton')
|
|
||||||
.click(hsExpandAll));
|
|
||||||
$('.buttons').append($('<span>' + HS_HIDE_ALL_TEXT + '</span>')
|
|
||||||
.addClass('hsButton')
|
|
||||||
.click(hsCollapseAll));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns true if a header is a DONE header
|
|
||||||
function hsIsDoneHeader(header) {
|
|
||||||
return $('span.done', header).length;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sets the default visibility state to a header
|
|
||||||
function hsSetDefaultVisibility(header) {
|
|
||||||
if (HS_STARTUP_FOLDED) {
|
|
||||||
hsCollapse(header);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (!hsIsDoneHeader(header) | HS_SHOW_ALL_OPEN_DONE_TREES) {
|
|
||||||
hsExpand(header);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
hsCollapse(header);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Expands an anchor, i.e. expand all parent headers
|
|
||||||
function hsExpandAnchor(id) {
|
|
||||||
// alert(id);
|
|
||||||
if (id) {
|
|
||||||
// alert($(id + '.hsNode').length);
|
|
||||||
$(id).parents('.hsCollapsed').each(function() {
|
|
||||||
hsExpand2($(this).children(':header'), true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Search for next task to review, starting from beginning of current tab.
|
|
||||||
// If BACKWARD is true, search in the reverse direction.
|
|
||||||
function hsReviewTaskNext(backward) {
|
|
||||||
// If no tasks to review at all, do nothing.
|
|
||||||
if ($('.outline-2 span.todo').length == 0) return;
|
|
||||||
|
|
||||||
if ($('.hsReviewing').length == 0) { // reviewing is starting
|
|
||||||
$('body').addClass('hsReviewing');
|
|
||||||
$('.hsReviewPanel').addClass('hsReviewing');
|
|
||||||
$('body').prepend('<div id="hsOverlay"></div>');
|
|
||||||
hsAddReviewingPanels();
|
|
||||||
|
|
||||||
hsCollapseAll();
|
|
||||||
// Get first task to review on each tab and expand it
|
|
||||||
$('.outline-2').each(function(){
|
|
||||||
var firstTodo = $(this).find('span.todo:first').parent().parent();
|
|
||||||
firstTodo.addClass('hsReview');
|
|
||||||
hsExpandParents($(firstTodo).children(':header'));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Get all todos
|
|
||||||
var todosElements = $('.outline-2:visible span.todo').parent().parent();
|
|
||||||
// alert(todosElements.length);
|
|
||||||
var todos = jQuery.makeArray(todosElements);
|
|
||||||
if (backward) {
|
|
||||||
todos = todos.reverse();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find current review item and review the next one
|
|
||||||
var foundReview = false;
|
|
||||||
var index;
|
|
||||||
for (index = 0; index < todos.length; ++index) {
|
|
||||||
var todo = todos[index];
|
|
||||||
if (foundReview) {
|
|
||||||
$(todo).addClass('hsReview');
|
|
||||||
hsExpandParents($(todo).children(':header'));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if ($(todo).hasClass('hsReview')) {
|
|
||||||
foundReview = true;
|
|
||||||
if (index < todos.length - 1) {
|
|
||||||
$(todo).removeClass('hsReview');
|
|
||||||
hsCollapseParents($(todo).children(':header'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update reviewing panel
|
|
||||||
if (index < todos.length) {
|
|
||||||
var reviewItem = index + 1;
|
|
||||||
if (backward) {
|
|
||||||
reviewItem = todos.length - index;
|
|
||||||
}
|
|
||||||
|
|
||||||
$('.outline-2:visible .hsReviewingPanel .hsReviewItem').text(reviewItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scroll to the current review item
|
|
||||||
$('html, body').animate({
|
|
||||||
scrollTop: $(".hsReview:visible").offset().top
|
|
||||||
}, 200);
|
|
||||||
}
|
|
||||||
|
|
||||||
// go to previous task to review
|
|
||||||
function hsReviewTaskPrev() {
|
|
||||||
hsReviewTaskNext(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// stop reviewing tasks
|
|
||||||
function hsReviewTaskQuit() {
|
|
||||||
$('body').removeClass('hsReviewing');
|
|
||||||
$('.hsReviewPanel').removeClass('hsReviewing');
|
|
||||||
$('.hsReview').removeClass('hsReview');
|
|
||||||
$('#hsOverlay').remove();
|
|
||||||
$('.hsReviewingPanel').remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
function hsHideTodoKeyword(kw) {
|
|
||||||
$('span.' + kw).addClass('hsHidden').parent().parent().hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
function hsShowTodoKeyword(kw) {
|
|
||||||
$('span.' + kw).removeClass('hsHidden').parent().parent().show();
|
|
||||||
// XXX Show if parent is not collapsed!
|
|
||||||
}
|
|
||||||
|
|
||||||
function hsAddReviewPanels() {
|
|
||||||
$('.outline-2').each(function(e) {
|
|
||||||
var nbItems = $(this).find('span.todo').length;
|
|
||||||
if (nbItems > 0) {
|
|
||||||
$(this).prepend('<div class="hsReviewPanel hsUnselectable" onclick="hsReviewTaskNext()">'
|
|
||||||
+ 'Press r or click here<br>'
|
|
||||||
+ 'to review ' + nbItems + ' tasks<br>'
|
|
||||||
+ '(out of ' + nbReviewTotalTasks + ' tasks)</div>');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function hsAddReviewingPanels() {
|
|
||||||
$('.outline-2').each(function(e) {
|
|
||||||
var nbItems = $(this).find('span.todo').length;
|
|
||||||
if (nbItems > 0) {
|
|
||||||
$(this).prepend('<div class="hsReviewingPanel hsUnselectable">Reviewing task <span class="hsReviewItem">1</span> / ' + nbItems + '<br>'
|
|
||||||
+ '(out of ' + nbReviewTotalTasks + ' tasks)<br>'
|
|
||||||
+ 'Shortcuts: '
|
|
||||||
+ '<span class="hsReviewButton" onclick="hsReviewTaskNext()">r (next)</span> - '
|
|
||||||
+ '<span class="hsReviewButton" onclick="hsReviewTaskPrev()">R (previous)</span>'
|
|
||||||
+ '</div>');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$(this).prepend('<div class="hsReviewingPanel hsUnselectable">No task to review<br>'
|
|
||||||
+ '(out of ' + nbReviewTotalTasks + ' tasks)<br>'
|
|
||||||
+ 'Shortcuts: '
|
|
||||||
+ '<span class="hsReviewButton" onclick="hsReviewTaskNext()">r (next)</span> - '
|
|
||||||
+ '<span class="hsReviewButton" onclick="hsReviewTaskPrev()">R (previous)</span>'
|
|
||||||
+ '</div>');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var nbReviewTotalTasks;
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
|
||||||
nbReviewTotalTasks = $('.outline-2 span.todo').length;
|
|
||||||
hsAddReviewPanels();
|
|
||||||
});
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
/**
|
|
||||||
* jQuery.LocalScroll - Animated scrolling navigation, using anchors.
|
|
||||||
* Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
|
|
||||||
* Dual licensed under MIT and GPL.
|
|
||||||
* Date: 3/11/2009
|
|
||||||
* @author Ariel Flesler
|
|
||||||
* @version 1.2.7
|
|
||||||
**/
|
|
||||||
;(function($){var l=location.href.replace(/#.*/,'');var g=$.localScroll=function(a){$('body').localScroll(a)};g.defaults={duration:1e3,axis:'y',event:'click',stop:true,target:window,reset:true};g.hash=function(a){if(location.hash){a=$.extend({},g.defaults,a);a.hash=false;if(a.reset){var e=a.duration;delete a.duration;$(a.target).scrollTo(0,a);a.duration=e}i(0,location,a)}};$.fn.localScroll=function(b){b=$.extend({},g.defaults,b);return b.lazy?this.bind(b.event,function(a){var e=$([a.target,a.target.parentNode]).filter(d)[0];if(e)i(a,e,b)}):this.find('a,area').filter(d).bind(b.event,function(a){i(a,this,b)}).end().end();function d(){return!!this.href&&!!this.hash&&this.href.replace(this.hash,'')==l&&(!b.filter||$(this).is(b.filter))}};function i(a,e,b){var d=e.hash.slice(1),f=document.getElementById(d)||document.getElementsByName(d)[0];if(!f)return;if(a)a.preventDefault();var h=$(b.target);if(b.lock&&h.is(':animated')||b.onBefore&&b.onBefore.call(b,a,f,h)===false)return;if(b.stop)h.stop(true);if(b.hash){var j=f.id==d?'id':'name',k=$('<a> </a>').attr(j,d).css({position:'absolute',top:$(window).scrollTop(),left:$(window).scrollLeft()});f[j]='';$('body').prepend(k);location=e.hash;k.remove();f[j]=d}h.scrollTo(f,b).trigger('notify.serialScroll',[f])}})(jQuery);
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright (c) 2007-2012 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
|
|
||||||
* Dual licensed under MIT and GPL.
|
|
||||||
* @author Ariel Flesler
|
|
||||||
* @version 1.4.3.1
|
|
||||||
*/
|
|
||||||
;(function($){var h=$.scrollTo=function(a,b,c){$(window).scrollTo(a,b,c)};h.defaults={axis:'xy',duration:parseFloat($.fn.jquery)>=1.3?0:1,limit:true};h.window=function(a){return $(window)._scrollable()};$.fn._scrollable=function(){return this.map(function(){var a=this,isWin=!a.nodeName||$.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!isWin)return a;var b=(a.contentWindow||a).document||a.ownerDocument||a;return/webkit/i.test(navigator.userAgent)||b.compatMode=='BackCompat'?b.body:b.documentElement})};$.fn.scrollTo=function(e,f,g){if(typeof f=='object'){g=f;f=0}if(typeof g=='function')g={onAfter:g};if(e=='max')e=9e9;g=$.extend({},h.defaults,g);f=f||g.duration;g.queue=g.queue&&g.axis.length>1;if(g.queue)f/=2;g.offset=both(g.offset);g.over=both(g.over);return this._scrollable().each(function(){if(e==null)return;var d=this,$elem=$(d),targ=e,toff,attr={},win=$elem.is('html,body');switch(typeof targ){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(targ)){targ=both(targ);break}targ=$(targ,this);if(!targ.length)return;case'object':if(targ.is||targ.style)toff=(targ=$(targ)).offset()}$.each(g.axis.split(''),function(i,a){var b=a=='x'?'Left':'Top',pos=b.toLowerCase(),key='scroll'+b,old=d[key],max=h.max(d,a);if(toff){attr[key]=toff[pos]+(win?0:old-$elem.offset()[pos]);if(g.margin){attr[key]-=parseInt(targ.css('margin'+b))||0;attr[key]-=parseInt(targ.css('border'+b+'Width'))||0}attr[key]+=g.offset[pos]||0;if(g.over[pos])attr[key]+=targ[a=='x'?'width':'height']()*g.over[pos]}else{var c=targ[pos];attr[key]=c.slice&&c.slice(-1)=='%'?parseFloat(c)/100*max:c}if(g.limit&&/^\d+$/.test(attr[key]))attr[key]=attr[key]<=0?0:Math.min(attr[key],max);if(!i&&g.queue){if(old!=attr[key])animate(g.onAfterFirst);delete attr[key]}});animate(g.onAfter);function animate(a){$elem.animate(attr,f,g.easing,a&&function(){a.call(this,e,g)})}}).end()};h.max=function(a,b){var c=b=='x'?'Width':'Height',scroll='scroll'+c;if(!$(a).is('html,body'))return a[scroll]-$(a)[c.toLowerCase()]();var d='client'+c,html=a.ownerDocument.documentElement,body=a.ownerDocument.body;return Math.max(html[scroll],body[scroll])-Math.min(html[d],body[d])};function both(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
!function(a,b){"use strict";function c(c,g){var h=this;h.$el=a(c),h.el=c,h.id=e++,h.$window=a(b),h.$document=a(document),h.$el.bind("destroyed",a.proxy(h.teardown,h)),h.$clonedHeader=null,h.$originalHeader=null,h.isSticky=!1,h.hasBeenSticky=!1,h.leftOffset=null,h.topOffset=null,h.init=function(){h.$el.each(function(){var b=a(this);b.css("padding",0),h.$originalHeader=a("thead:first",this),h.$clonedHeader=h.$originalHeader.clone(),b.trigger("clonedHeader."+d,[h.$clonedHeader]),h.$clonedHeader.addClass("tableFloatingHeader"),h.$clonedHeader.css("display","none"),h.$originalHeader.addClass("tableFloatingHeaderOriginal"),h.$originalHeader.after(h.$clonedHeader),h.$printStyle=a('<style type="text/css" media="print">.tableFloatingHeader{display:none !important;}.tableFloatingHeaderOriginal{position:static !important;}</style>'),a("head").append(h.$printStyle)}),h.setOptions(g),h.updateWidth(),h.toggleHeaders(),h.bind()},h.destroy=function(){h.$el.unbind("destroyed",h.teardown),h.teardown()},h.teardown=function(){h.isSticky&&h.$originalHeader.css("position","static"),a.removeData(h.el,"plugin_"+d),h.unbind(),h.$clonedHeader.remove(),h.$originalHeader.removeClass("tableFloatingHeaderOriginal"),h.$originalHeader.css("visibility","visible"),h.$printStyle.remove(),h.el=null,h.$el=null},h.bind=function(){h.$scrollableArea.on("scroll."+d,h.toggleHeaders),h.isWindowScrolling||(h.$window.on("scroll."+d+h.id,h.setPositionValues),h.$window.on("resize."+d+h.id,h.toggleHeaders)),h.$scrollableArea.on("resize."+d,h.toggleHeaders),h.$scrollableArea.on("resize."+d,h.updateWidth)},h.unbind=function(){h.$scrollableArea.off("."+d,h.toggleHeaders),h.isWindowScrolling||(h.$window.off("."+d+h.id,h.setPositionValues),h.$window.off("."+d+h.id,h.toggleHeaders)),h.$scrollableArea.off("."+d,h.updateWidth)},h.toggleHeaders=function(){h.$el&&h.$el.each(function(){var b,c=a(this),d=h.isWindowScrolling?isNaN(h.options.fixedOffset)?h.options.fixedOffset.outerHeight():h.options.fixedOffset:h.$scrollableArea.offset().top+(isNaN(h.options.fixedOffset)?0:h.options.fixedOffset),e=c.offset(),f=h.$scrollableArea.scrollTop()+d,g=h.$scrollableArea.scrollLeft(),i=h.isWindowScrolling?f>e.top:d>e.top,j=(h.isWindowScrolling?f:0)<e.top+c.height()-h.$clonedHeader.height()-(h.isWindowScrolling?0:d);i&&j?(b=e.left-g+h.options.leftOffset,h.$originalHeader.css({position:"fixed","margin-top":h.options.marginTop,left:b,"z-index":3}),h.leftOffset=b,h.topOffset=d,h.$clonedHeader.css("display",""),h.isSticky||(h.isSticky=!0,h.updateWidth()),h.setPositionValues()):h.isSticky&&(h.$originalHeader.css("position","static"),h.$clonedHeader.css("display","none"),h.isSticky=!1,h.resetWidth(a("td,th",h.$clonedHeader),a("td,th",h.$originalHeader)))})},h.setPositionValues=function(){var a=h.$window.scrollTop(),b=h.$window.scrollLeft();!h.isSticky||0>a||a+h.$window.height()>h.$document.height()||0>b||b+h.$window.width()>h.$document.width()||h.$originalHeader.css({top:h.topOffset-(h.isWindowScrolling?0:a),left:h.leftOffset-(h.isWindowScrolling?0:b)})},h.updateWidth=function(){if(h.isSticky){h.$originalHeaderCells||(h.$originalHeaderCells=a("th,td",h.$originalHeader)),h.$clonedHeaderCells||(h.$clonedHeaderCells=a("th,td",h.$clonedHeader));var b=h.getWidth(h.$clonedHeaderCells);h.setWidth(b,h.$clonedHeaderCells,h.$originalHeaderCells),h.$originalHeader.css("width",h.$clonedHeader.width())}},h.getWidth=function(c){var d=[];return c.each(function(c){var e,f=a(this);if("border-box"===f.css("box-sizing"))e=f[0].getBoundingClientRect().width;else{var g=a("th",h.$originalHeader);if("collapse"===g.css("border-collapse"))if(b.getComputedStyle)e=parseFloat(b.getComputedStyle(this,null).width);else{var i=parseFloat(f.css("padding-left")),j=parseFloat(f.css("padding-right")),k=parseFloat(f.css("border-width"));e=f.outerWidth()-i-j-k}else e=f.width()}d[c]=e}),d},h.setWidth=function(a,b,c){b.each(function(b){var d=a[b];c.eq(b).css({"min-width":d,"max-width":d})})},h.resetWidth=function(b,c){b.each(function(b){var d=a(this);c.eq(b).css({"min-width":d.css("min-width"),"max-width":d.css("max-width")})})},h.setOptions=function(c){h.options=a.extend({},f,c),h.$scrollableArea=a(h.options.scrollableArea),h.isWindowScrolling=h.$scrollableArea[0]===b},h.updateOptions=function(a){h.setOptions(a),h.unbind(),h.bind(),h.updateWidth(),h.toggleHeaders()},h.init()}var d="stickyTableHeaders",e=0,f={fixedOffset:0,leftOffset:0,marginTop:0,scrollableArea:b};a.fn[d]=function(b){return this.each(function(){var e=a.data(this,"plugin_"+d);e?"string"==typeof b?e[b].apply(e):e.updateOptions(b):"destroy"!==b&&a.data(this,"plugin_"+d,new c(this,b))})}}(jQuery,window);
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
Copyright (c) 2011 Jonas Mosbech
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
a copy of this software and associated documentation files (the
|
|
||||||
"Software"), to deal in the Software without restriction, including
|
|
||||||
without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be
|
|
||||||
included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
;; From MELPA
|
;; From MELPA
|
||||||
(require 'dash)
|
(require 'dash)
|
||||||
|
(require 'dash-functional)
|
||||||
(require 's)
|
(require 's)
|
||||||
|
|
||||||
;; org-ql
|
;; org-ql
|
||||||
|
|
|
||||||
235
helm-org-ql.el
|
|
@ -1,235 +0,0 @@
|
||||||
;;; helm-org-ql.el --- Helm support for org-ql -*- lexical-binding: t; -*-
|
|
||||||
|
|
||||||
;; Author: Adam Porter <adam@alphapapa.net>
|
|
||||||
;; URL: https://github.com/alphapapa/org-ql
|
|
||||||
;; Version: 0.6.2
|
|
||||||
;; 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"))
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library includes Helm commands for `org-ql'. Note that Helm
|
|
||||||
;; is not declared as a package dependency, so this does not cause
|
|
||||||
;; Helm to be installed. In the future, this file may have its own
|
|
||||||
;; package recipe, which would allow it to be installed separately and
|
|
||||||
;; declare a dependency on Helm.
|
|
||||||
|
|
||||||
;;; License:
|
|
||||||
|
|
||||||
;; 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
|
|
||||||
;; the Free Software Foundation, either version 3 of the License, or
|
|
||||||
;; (at your option) any later version.
|
|
||||||
|
|
||||||
;; This program is distributed in the hope that it will be useful,
|
|
||||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
;; GNU General Public License for more details.
|
|
||||||
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
;;;; Requirements
|
|
||||||
|
|
||||||
(require 'cl-lib)
|
|
||||||
(require 'org)
|
|
||||||
|
|
||||||
(require 'compat)
|
|
||||||
(require 'dash)
|
|
||||||
(require 's)
|
|
||||||
|
|
||||||
(require 'helm)
|
|
||||||
(require 'helm-org)
|
|
||||||
|
|
||||||
(require 'org-ql)
|
|
||||||
(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
|
|
||||||
|
|
||||||
(defvar helm-org-ql-map
|
|
||||||
(let ((map (make-sparse-keymap))
|
|
||||||
(mappings '("C-x C-s" helm-org-ql-save)))
|
|
||||||
(cl-loop for (key fn) on mappings by #'cddr
|
|
||||||
do (define-key map (kbd key) fn))
|
|
||||||
(make-composed-keymap map helm-map))
|
|
||||||
"Keymap for `helm-org-ql' sessions.
|
|
||||||
Based on `helm-map'.")
|
|
||||||
|
|
||||||
(defvar helm-org-ql-views-source
|
|
||||||
(helm-make-source "Org QL Views" 'helm-source-sync
|
|
||||||
:candidates (lambda ()
|
|
||||||
(->> org-ql-views
|
|
||||||
(-map #'car)
|
|
||||||
(-sort #'string<)))
|
|
||||||
:action (list (cons "Show view" #'org-ql-view)))
|
|
||||||
"Helm source for `org-ql-views'.")
|
|
||||||
|
|
||||||
(defvar-local helm-org-ql-buffers-files nil
|
|
||||||
"Used for `helm-org-ql-save'.")
|
|
||||||
|
|
||||||
;;;; Customization
|
|
||||||
|
|
||||||
(defgroup helm-org-ql nil
|
|
||||||
"Options for `helm-org-ql'."
|
|
||||||
:group 'org-ql
|
|
||||||
:group 'helm)
|
|
||||||
|
|
||||||
(defcustom helm-org-ql-reverse-paths t
|
|
||||||
"Whether to reverse Org outline paths in `helm-org-ql' results."
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defcustom helm-org-ql-input-idle-delay 0.25
|
|
||||||
"Seconds to wait after typing stops before running query."
|
|
||||||
:type 'number)
|
|
||||||
|
|
||||||
(defcustom helm-org-ql-actions
|
|
||||||
(list (cons "Show heading in source buffer" 'helm-org-ql-show-marker)
|
|
||||||
(cons "Show heading in indirect buffer" 'helm-org-ql-show-marker-indirect))
|
|
||||||
"Alist of actions for `helm-org-ql' commands."
|
|
||||||
:type '(alist :key-type (string :tag "Description")
|
|
||||||
:value-type (function :tag "Command")))
|
|
||||||
|
|
||||||
;;;; Commands
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(cl-defun helm-org-ql (buffers-files
|
|
||||||
&key (boolean 'and) (name "helm-org-ql"))
|
|
||||||
"Display results in BUFFERS-FILES for an `org-ql' non-sexp query using Helm.
|
|
||||||
Interactively, search the current buffer. Note that this command
|
|
||||||
only accepts non-sexp, \"plain\" queries.
|
|
||||||
|
|
||||||
NAME is passed to `helm-org-ql-source', which see.
|
|
||||||
|
|
||||||
NOTE: Atoms in the query are turned into strings where
|
|
||||||
appropriate, which makes it unnecessary to type quotation marks
|
|
||||||
around words that are intended to be searched for as independent
|
|
||||||
strings.
|
|
||||||
|
|
||||||
All query tokens are wrapped in the operator BOOLEAN (default
|
|
||||||
`and'; with prefix, `or').
|
|
||||||
|
|
||||||
For example, this raw input:
|
|
||||||
|
|
||||||
Emacs git
|
|
||||||
|
|
||||||
Is transformed into this query:
|
|
||||||
|
|
||||||
(and \"Emacs\" \"git\")
|
|
||||||
|
|
||||||
However, quoted strings remain quoted, so this input:
|
|
||||||
|
|
||||||
\"something else\" (tags \"funny\")
|
|
||||||
|
|
||||||
Is transformed into this query:
|
|
||||||
|
|
||||||
(and \"something else\" (tags \"funny\"))"
|
|
||||||
(interactive (list (current-buffer)))
|
|
||||||
(let ((boolean (if current-prefix-arg 'or boolean))
|
|
||||||
(helm-input-idle-delay helm-org-ql-input-idle-delay))
|
|
||||||
(helm :prompt (format "Query (boolean %s): " (-> boolean symbol-name upcase))
|
|
||||||
:sources (helm-org-ql-source buffers-files :name name))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun helm-org-ql-agenda-files ()
|
|
||||||
"Search agenda files with `helm-org-ql', which see."
|
|
||||||
(interactive)
|
|
||||||
(helm-org-ql (org-agenda-files) :name "Org Agenda Files"))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun helm-org-ql-org-directory ()
|
|
||||||
"Search Org files in `org-directory' with `helm-org-ql'."
|
|
||||||
(interactive)
|
|
||||||
(helm-org-ql (org-ql-search-directories-files)
|
|
||||||
:name "Org Directory Files"))
|
|
||||||
|
|
||||||
(defun helm-org-ql-show-marker (marker)
|
|
||||||
"Show heading at MARKER."
|
|
||||||
(interactive)
|
|
||||||
;; This function is necessary because `helm-org-goto-marker' calls
|
|
||||||
;; `re-search-backward' to go backward to the start of a heading,
|
|
||||||
;; which, when the marker is already at the desired heading, causes
|
|
||||||
;; it to go to the previous heading. I don't know why it does that.
|
|
||||||
(switch-to-buffer (marker-buffer marker))
|
|
||||||
(goto-char marker)
|
|
||||||
(helm-org-ql--show-entry))
|
|
||||||
|
|
||||||
(defun helm-org-ql-show-marker-indirect (marker)
|
|
||||||
"Show heading at MARKER with `org-tree-to-indirect-buffer'."
|
|
||||||
(interactive)
|
|
||||||
(helm-org-ql-show-marker marker)
|
|
||||||
(org-tree-to-indirect-buffer))
|
|
||||||
|
|
||||||
(defun helm-org-ql-save ()
|
|
||||||
"Show `helm-org-ql' search in an `org-ql-search' buffer."
|
|
||||||
(interactive)
|
|
||||||
(let ((buffers-files (with-current-buffer (helm-buffer-get)
|
|
||||||
helm-org-ql-buffers-files))
|
|
||||||
(query (org-ql--query-string-to-sexp helm-pattern)))
|
|
||||||
(helm-run-after-exit #'org-ql-search buffers-files query)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun helm-org-ql-views ()
|
|
||||||
"Show an `org-ql' view selected with Helm."
|
|
||||||
(interactive)
|
|
||||||
(helm :sources helm-org-ql-views-source))
|
|
||||||
|
|
||||||
;;;; Functions
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(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'."
|
|
||||||
;; Expansion of `helm-build-sync-source' macro.
|
|
||||||
(helm-make-source name 'helm-source-sync
|
|
||||||
:candidates (lambda ()
|
|
||||||
(let* ((query (org-ql--query-string-to-sexp helm-pattern))
|
|
||||||
(window-width (window-width (helm-window))))
|
|
||||||
(when query
|
|
||||||
(with-current-buffer (helm-buffer-get)
|
|
||||||
(setq helm-org-ql-buffers-files buffers-files))
|
|
||||||
(ignore-errors
|
|
||||||
;; Ignore errors that might be caused by partially typed queries.
|
|
||||||
(org-ql-select buffers-files query
|
|
||||||
:action `(helm-org-ql--heading ,window-width))))))
|
|
||||||
:match #'identity
|
|
||||||
:fuzzy-match nil
|
|
||||||
:multimatch nil
|
|
||||||
:nohighlight t
|
|
||||||
:volatile t
|
|
||||||
:keymap helm-org-ql-map
|
|
||||||
:action helm-org-ql-actions))
|
|
||||||
|
|
||||||
(defun helm-org-ql--heading (window-width)
|
|
||||||
"Return string for Helm for heading at point.
|
|
||||||
WINDOW-WIDTH should be the width of the Helm window."
|
|
||||||
(font-lock-ensure (pos-bol) (pos-eol))
|
|
||||||
;; 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
|
|
||||||
;; buffer, unless we manually called `org-ql' in each buffer, which
|
|
||||||
;; I'd prefer not to do. Maybe I should add a feature to `org-ql' to
|
|
||||||
;; call a setup function in a buffer before running queries.
|
|
||||||
(let* ((prefix (concat (buffer-name) ":"))
|
|
||||||
(width (- window-width (length prefix)))
|
|
||||||
(heading (org-get-heading t))
|
|
||||||
(path (-> (org-get-outline-path)
|
|
||||||
(org-format-outline-path width nil "")
|
|
||||||
(org-split-string "")))
|
|
||||||
(path (if helm-org-ql-reverse-paths
|
|
||||||
(concat heading "\\" (s-join "\\" (nreverse path)))
|
|
||||||
(concat (s-join "/" path) "/" heading))))
|
|
||||||
(cons (concat prefix path) (point-marker))))
|
|
||||||
|
|
||||||
;;;; Footer
|
|
||||||
|
|
||||||
(provide 'helm-org-ql)
|
|
||||||
|
|
||||||
;;; helm-org-ql.el ends here
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# * Commit parameters
|
|
||||||
# Unused now, but good for future reference. See man 5 githooks.
|
|
||||||
|
|
||||||
remote="$1"
|
|
||||||
url="$2"
|
|
||||||
|
|
||||||
read local_ref local_sha remote_ref remote_sha
|
|
||||||
|
|
||||||
# * Run tests
|
|
||||||
|
|
||||||
# Not using sandbox and auto-install, because "git push" shouldn't
|
|
||||||
# cause remote code to be downloaded and executed (i.e. what would
|
|
||||||
# happen by installing packages). It can be done manually when needed.
|
|
||||||
|
|
||||||
# Only run when pushing master.
|
|
||||||
|
|
||||||
if [[ $local_ref = refs/heads/master ]]
|
|
||||||
then
|
|
||||||
make sandbox=.sandbox test
|
|
||||||
fi
|
|
||||||
|
|
@ -1,202 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# NOTE: Run "setxkbmap us" before running. See https://github.com/jordansissel/xdotool/issues/49
|
|
||||||
|
|
||||||
# NOTE: <f1> should be bound to this function in the Emacs window, like this:
|
|
||||||
|
|
||||||
# (global-set-key [f1]
|
|
||||||
# (defun gif-screencast-start-or-stop ()
|
|
||||||
# (interactive)
|
|
||||||
# (if gif-screencast-mode
|
|
||||||
# (progn
|
|
||||||
# (gif-screencast-stop)
|
|
||||||
# (setq gc-cons-threshold gc-cons-threshold-original))
|
|
||||||
# (setq gc-cons-threshold-original gc-cons-threshold)
|
|
||||||
# (setq gc-cons-threshold (* 1024 1024 500))
|
|
||||||
# (gif-screencast))))
|
|
||||||
|
|
||||||
# * Functions
|
|
||||||
|
|
||||||
function ensure_window_name {
|
|
||||||
if ! [[ $(xdotool getwindowfocus getwindowname) = $1 ]]
|
|
||||||
then
|
|
||||||
echo "Wrong window!" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function key {
|
|
||||||
xdotool key "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
function input {
|
|
||||||
raw_input "$@"
|
|
||||||
|
|
||||||
# Correct for Helm's input idle delay by sending extra commands to
|
|
||||||
# make the screenshots be taken. Not sure why two are necessary,
|
|
||||||
# but they seem to be.
|
|
||||||
key ctrl+p
|
|
||||||
sleep 0.26
|
|
||||||
key ctrl+p
|
|
||||||
}
|
|
||||||
|
|
||||||
function raw_input {
|
|
||||||
xdotool type --delay 200 "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
# * Script
|
|
||||||
|
|
||||||
# No matter what I try, xdotool is not working properly to focus/raise/select
|
|
||||||
# a window. And for some bizarre reason, the "xdotool selectwindow" command
|
|
||||||
# outputs a completely different window ID than "xdotool search" outputs. In
|
|
||||||
# fact, the window ID it outputs does not even appear in the output of
|
|
||||||
# "xprop" for that window. I have no idea where it's getting that ID.
|
|
||||||
|
|
||||||
# So rather than cleanly selecting the proper window in the script, we have to
|
|
||||||
# do a hacky workaround by sleeping and checking the name of the active
|
|
||||||
# window.
|
|
||||||
|
|
||||||
sleep 3
|
|
||||||
ensure_window_name "data.org"
|
|
||||||
|
|
||||||
# Start gif-screencast
|
|
||||||
key F1
|
|
||||||
sleep 5
|
|
||||||
|
|
||||||
# M-x helm-org-ql RET
|
|
||||||
key alt+x
|
|
||||||
sleep 0.2
|
|
||||||
raw_input "helm-org-ql"
|
|
||||||
key ctrl+e
|
|
||||||
sleep 0.5
|
|
||||||
key Return
|
|
||||||
sleep 0.5
|
|
||||||
|
|
||||||
# "Emacs"
|
|
||||||
input Emacs
|
|
||||||
sleep 1
|
|
||||||
|
|
||||||
# "tags:Emacs"
|
|
||||||
key ctrl+a
|
|
||||||
input 'tags:'
|
|
||||||
sleep 1.5
|
|
||||||
|
|
||||||
# "tags&:Emacs,elisp"
|
|
||||||
key Left
|
|
||||||
input "&"
|
|
||||||
key ctrl+e
|
|
||||||
input ",elisp"
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
# "universe"
|
|
||||||
key ctrl+a ctrl+k
|
|
||||||
input "universe"
|
|
||||||
sleep 1
|
|
||||||
|
|
||||||
# "tags:universe,space"
|
|
||||||
key ctrl+a
|
|
||||||
input "tags:"
|
|
||||||
key ctrl+e
|
|
||||||
input ",space"
|
|
||||||
sleep 1
|
|
||||||
|
|
||||||
# "tags&:universe,space"
|
|
||||||
key ctrl+a Right Right Right Right
|
|
||||||
input "&"
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
# "deadline:"
|
|
||||||
key ctrl+a ctrl+k
|
|
||||||
input "deadline:"
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
# "deadline:to=2017-07-06"
|
|
||||||
input "to=2019-10-06"
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
# "deadline:to=2017-07-07"
|
|
||||||
key BackSpace
|
|
||||||
sleep 0.5
|
|
||||||
input "7"
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
# "scheduled:"
|
|
||||||
key ctrl+a ctrl+k
|
|
||||||
input "scheduled:"
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
# "scheduled:on=2017-07-04"
|
|
||||||
input "on=2019-10-04"
|
|
||||||
sleep 1
|
|
||||||
|
|
||||||
# "scheduled:on=2017-07-05"
|
|
||||||
key BackSpace
|
|
||||||
sleep 0.5
|
|
||||||
input "5"
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
# property:agenda-group
|
|
||||||
key ctrl+a ctrl+k
|
|
||||||
input "property:agenda-group"
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
# property:agenda-group=plans
|
|
||||||
input "=plans"
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
# category:ambition
|
|
||||||
key ctrl+a ctrl+k
|
|
||||||
input "category:ambition"
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
# ts-inactive:
|
|
||||||
key ctrl+a ctrl+k
|
|
||||||
input "ts-inactive:"
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
# closed:
|
|
||||||
key ctrl+a ctrl+k
|
|
||||||
input "closed:"
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
# Show match in persistent buffer
|
|
||||||
key ctrl+j
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
# closed:on=2017-07-04 (which is a day too early)
|
|
||||||
input "on=2019-10-04"
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
# closed:on=2017-07-05 (which is the closed date)
|
|
||||||
key BackSpace
|
|
||||||
input 5
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
# done:
|
|
||||||
key ctrl+a ctrl+k
|
|
||||||
input "done:"
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
# "todo:"
|
|
||||||
key ctrl+a ctrl+k
|
|
||||||
input "todo:"
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
# "todo: priority:"
|
|
||||||
input " priority:"
|
|
||||||
sleep 1
|
|
||||||
|
|
||||||
# "todo: priority:A"
|
|
||||||
input "A"
|
|
||||||
sleep 1
|
|
||||||
|
|
||||||
# "todo: priority:A,B"
|
|
||||||
input ",B"
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
# Save to a view buffer
|
|
||||||
key ctrl+x ctrl+s
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
# Stop the screencast
|
|
||||||
key F1
|
|
||||||
|
|
@ -1,166 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# NOTE: Run "setxkbmap us" before running. See https://github.com/jordansissel/xdotool/issues/49
|
|
||||||
|
|
||||||
# NOTE: <f1> should be bound to this function in the Emacs window, like this:
|
|
||||||
|
|
||||||
# (global-set-key [f1]
|
|
||||||
# (defun gif-screencast-start-or-stop ()
|
|
||||||
# (interactive)
|
|
||||||
# (if gif-screencast-mode
|
|
||||||
# (progn
|
|
||||||
# (gif-screencast-stop)
|
|
||||||
# (setq gc-cons-threshold gc-cons-threshold-original))
|
|
||||||
# (setq gc-cons-threshold-original gc-cons-threshold)
|
|
||||||
# (setq gc-cons-threshold (* 1024 1024 500))
|
|
||||||
# (gif-screencast))))
|
|
||||||
|
|
||||||
# * Functions
|
|
||||||
|
|
||||||
function ensure_window_name {
|
|
||||||
if ! [[ $(xdotool getwindowfocus getwindowname) = $1 ]]
|
|
||||||
then
|
|
||||||
echo "Wrong window!" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function key {
|
|
||||||
xdotool key "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
function input {
|
|
||||||
raw_input "$@"
|
|
||||||
|
|
||||||
# Correct for Helm's input idle delay by sending extra commands to
|
|
||||||
# make the screenshots be taken. Not sure why two are necessary,
|
|
||||||
# but they seem to be.
|
|
||||||
key ctrl+p
|
|
||||||
sleep 0.26
|
|
||||||
key ctrl+p
|
|
||||||
}
|
|
||||||
|
|
||||||
function raw_input {
|
|
||||||
xdotool type --delay 200 "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
function view-dispatch {
|
|
||||||
key v
|
|
||||||
sleep 2
|
|
||||||
}
|
|
||||||
function view-refresh {
|
|
||||||
key r
|
|
||||||
sleep 2
|
|
||||||
}
|
|
||||||
|
|
||||||
function clear-input {
|
|
||||||
key ctrl+a ctrl+k
|
|
||||||
sleep 0.5
|
|
||||||
}
|
|
||||||
function set-field {
|
|
||||||
key $1
|
|
||||||
shift
|
|
||||||
sleep 1
|
|
||||||
clear-input
|
|
||||||
raw_input "$@"
|
|
||||||
sleep 1
|
|
||||||
key Return
|
|
||||||
sleep 1
|
|
||||||
}
|
|
||||||
|
|
||||||
function set-field-with-unique-completion {
|
|
||||||
# "$@" should be a unique completion.
|
|
||||||
key $1
|
|
||||||
shift
|
|
||||||
sleep 0.5
|
|
||||||
clear-input
|
|
||||||
key Tab
|
|
||||||
sleep 0.5
|
|
||||||
raw_input "$@"
|
|
||||||
key Tab
|
|
||||||
sleep 0.75
|
|
||||||
key Return
|
|
||||||
sleep 1
|
|
||||||
}
|
|
||||||
|
|
||||||
function complete-in-steps {
|
|
||||||
# Assumes input is clear.
|
|
||||||
key Tab
|
|
||||||
sleep 0.75
|
|
||||||
key Tab
|
|
||||||
sleep 0.75
|
|
||||||
|
|
||||||
for s in "$@"
|
|
||||||
do
|
|
||||||
raw_input "$s"
|
|
||||||
key Tab
|
|
||||||
sleep 0.75
|
|
||||||
done
|
|
||||||
sleep 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# * Script
|
|
||||||
|
|
||||||
# No matter what I try, xdotool is not working properly to focus/raise/select
|
|
||||||
# a window. And for some bizarre reason, the "xdotool selectwindow" command
|
|
||||||
# outputs a completely different window ID than "xdotool search" outputs. In
|
|
||||||
# fact, the window ID it outputs does not even appear in the output of
|
|
||||||
# "xprop" for that window. I have no idea where it's getting that ID.
|
|
||||||
|
|
||||||
# So rather than cleanly selecting the proper window in the script, we have to
|
|
||||||
# do a hacky workaround by sleeping and checking the name of the active
|
|
||||||
# window.
|
|
||||||
|
|
||||||
sleep 3
|
|
||||||
ensure_window_name "data.org"
|
|
||||||
|
|
||||||
# Start gif-screencast
|
|
||||||
key F1
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
# M-x org-ql-view RET, TAB, Ov TAB, Ag TAB, RET
|
|
||||||
key alt+x
|
|
||||||
sleep 0.2
|
|
||||||
raw_input "org-ql-view"
|
|
||||||
sleep 1
|
|
||||||
key Return
|
|
||||||
sleep 1
|
|
||||||
|
|
||||||
complete-in-steps Ov Ag
|
|
||||||
key Return
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
# Edit view.
|
|
||||||
view-dispatch
|
|
||||||
set-field t "Space-related"
|
|
||||||
set-field q "tags:space,spaceship"
|
|
||||||
set-field-with-unique-completion g pri
|
|
||||||
view-refresh
|
|
||||||
|
|
||||||
# Save query
|
|
||||||
view-dispatch
|
|
||||||
key ctrl+s
|
|
||||||
sleep 1
|
|
||||||
key Return
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
# New query: Ambition
|
|
||||||
view-dispatch
|
|
||||||
set-field t Ambition
|
|
||||||
set-field q "category:ambition"
|
|
||||||
set-field s "priority"
|
|
||||||
set-field g "parent"
|
|
||||||
view-refresh
|
|
||||||
|
|
||||||
view-dispatch
|
|
||||||
set-field t "Upcoming: ambition"
|
|
||||||
set-field g ts
|
|
||||||
view-refresh
|
|
||||||
|
|
||||||
# Save view.
|
|
||||||
view-dispatch
|
|
||||||
key ctrl+s
|
|
||||||
sleep 0.75
|
|
||||||
key Return
|
|
||||||
|
|
||||||
key F1
|
|
||||||
BIN
images/dog.png
|
Before Width: | Height: | Size: 11 KiB |
BIN
images/dont-tread-on-emacs-150.png
Normal file
|
After Width: | Height: | Size: 5.5 KiB |
|
Before Width: | Height: | Size: 833 KiB |
|
Before Width: | Height: | Size: 92 KiB |
|
Before Width: | Height: | Size: 1.8 MiB |
|
Before Width: | Height: | Size: 640 KiB |
996
org-ql-agenda.el
Normal file
|
|
@ -0,0 +1,996 @@
|
||||||
|
;;; org-ql-agenda.el --- Agenda-like view based on org-ql -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
|
;; Author: Adam Porter <adam@alphapapa.net>
|
||||||
|
;; Url: https://github.com/alphapapa/org-ql
|
||||||
|
|
||||||
|
;;; Commentary:
|
||||||
|
|
||||||
|
;; This library is part of the package `org-ql'; it's not a standalone
|
||||||
|
;; library. It displays buffers similar to Org Agenda buffers, based
|
||||||
|
;; on `org-ql' queries.
|
||||||
|
|
||||||
|
;;; License:
|
||||||
|
|
||||||
|
;; 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
|
||||||
|
;; the Free Software Foundation, either version 3 of the License, or
|
||||||
|
;; (at your option) any later version.
|
||||||
|
|
||||||
|
;; This program is distributed in the hope that it will be useful,
|
||||||
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;; GNU General Public License for more details.
|
||||||
|
|
||||||
|
;; You should have received a copy of the GNU General Public License
|
||||||
|
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
;;; Code:
|
||||||
|
|
||||||
|
(require 'cl-lib)
|
||||||
|
(require 'map)
|
||||||
|
(require 'org)
|
||||||
|
(require 'org-element)
|
||||||
|
(require 'org-agenda)
|
||||||
|
(require 'seq)
|
||||||
|
(require 'rx)
|
||||||
|
|
||||||
|
(require 'org-ql)
|
||||||
|
|
||||||
|
(require 'dash)
|
||||||
|
(require 's)
|
||||||
|
|
||||||
|
;;;; Compatibility
|
||||||
|
|
||||||
|
(defvar org-super-agenda-auto-selector-keywords)
|
||||||
|
(defvar org-super-agenda-groups)
|
||||||
|
(defvar org-super-agenda-mode)
|
||||||
|
(declare-function org-super-agenda--group-items "ext:org-super-agenda")
|
||||||
|
|
||||||
|
(when (version< org-version "9.2")
|
||||||
|
(defalias 'org-get-tags #'org-get-tags-at))
|
||||||
|
|
||||||
|
;;;; Faces
|
||||||
|
|
||||||
|
(defface org-ql-agenda-due-date
|
||||||
|
'((t (:slant italic :weight bold)))
|
||||||
|
"Face for due dates in `org-ql-agenda' views."
|
||||||
|
:group 'org-ql)
|
||||||
|
|
||||||
|
;;;; Variables
|
||||||
|
|
||||||
|
(defvar org-ql-agenda-buffer-name "*Org-QL-Agenda*"
|
||||||
|
"Name of default `org-ql-agenda' buffer.")
|
||||||
|
|
||||||
|
(defvar org-ql-view-map
|
||||||
|
(let ((map (copy-keymap org-agenda-mode-map)))
|
||||||
|
(define-key map "g" #'org-ql-search-refresh)
|
||||||
|
(define-key map (kbd "C-x C-s") #'org-ql-search-save)
|
||||||
|
map)
|
||||||
|
"Keymap for `org-ql-agenda', `org-ql-search', and `org-ql-views' views.
|
||||||
|
Based on `org-agenda-mode-map'.")
|
||||||
|
|
||||||
|
(defvar org-ql-block-header nil
|
||||||
|
"A string to override the default header in `org-ql-block' agenda blocks.")
|
||||||
|
|
||||||
|
(defvar org-ql-todo-keyword-length nil)
|
||||||
|
|
||||||
|
;; For refreshing results buffers.
|
||||||
|
(defvar org-ql-buffers-files)
|
||||||
|
(defvar org-ql-query)
|
||||||
|
(defvar org-ql-sort)
|
||||||
|
(defvar org-ql-narrow)
|
||||||
|
(defvar org-ql-super-groups)
|
||||||
|
(defvar org-ql-title)
|
||||||
|
|
||||||
|
;;;; Customization
|
||||||
|
|
||||||
|
(defcustom org-ql-views
|
||||||
|
(list (cons "Agenda-like" (lambda ()
|
||||||
|
(interactive)
|
||||||
|
(org-ql-search (org-agenda-files)
|
||||||
|
'(and (not (done))
|
||||||
|
(or (habit)
|
||||||
|
(deadline auto)
|
||||||
|
(scheduled :to today)
|
||||||
|
(ts-active :on today)))
|
||||||
|
:sort '(date priority todo)
|
||||||
|
:groups (when (boundp org-super-agenda-groups)
|
||||||
|
org-super-agenda-groups))))
|
||||||
|
(cons "Recent entries" #'org-ql-view-recent-items)
|
||||||
|
(cons "Review (to-do keyword without timestamp in past 2 weeks)"
|
||||||
|
(lambda ()
|
||||||
|
(interactive)
|
||||||
|
(org-ql-search (org-agenda-files)
|
||||||
|
'(and (todo)
|
||||||
|
(not (ts :from -14)))
|
||||||
|
:title "Review"
|
||||||
|
:sort '(date priority todo)
|
||||||
|
:groups '((:auto-parent t)))))
|
||||||
|
(cons "Stuck Projects" (lambda ()
|
||||||
|
(interactive)
|
||||||
|
(org-ql-search (org-agenda-files)
|
||||||
|
'(and (todo)
|
||||||
|
(children)
|
||||||
|
(not (children (todo "NEXT"))))
|
||||||
|
:title "Stuck Projects"
|
||||||
|
:sort '(priority date)))))
|
||||||
|
"Alist of `org-ql-view' commands.
|
||||||
|
Each value should be a function that calls,
|
||||||
|
e.g. `org-ql-search' as desired."
|
||||||
|
:group 'org-ql
|
||||||
|
:type '(alist :key-type string
|
||||||
|
:value-type function))
|
||||||
|
|
||||||
|
;;;; Macros
|
||||||
|
|
||||||
|
;; TODO: DRY these two macros.
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(cl-defmacro org-ql-agenda (&rest args)
|
||||||
|
"Display an agenda-like buffer of entries in FILES that match QUERY.
|
||||||
|
|
||||||
|
FILES-OR-QUERY is a sexp that is evaluated to get the list of
|
||||||
|
buffers and files to scan.
|
||||||
|
|
||||||
|
QUERY is an `org-ql' query. The query may be passed as
|
||||||
|
FILES-OR-QUERY and QUERY may be left nil, in which case the list
|
||||||
|
of files will automatically be set to the value of calling
|
||||||
|
`org-agenda-files'.
|
||||||
|
|
||||||
|
SORT is passed to `org-ql', which see..
|
||||||
|
|
||||||
|
NARROW, when non-nil, means to respect narrowing in buffers.
|
||||||
|
When nil, buffers are widened before being searched.
|
||||||
|
|
||||||
|
BUFFER, when non-nil, is a buffer or buffer name to display the
|
||||||
|
agenda in, rather than the default.
|
||||||
|
|
||||||
|
SUPER-GROUPS is used to bind variable `org-super-agenda-groups',
|
||||||
|
which see. If t, the existing value of `org-super-agenda-groups'
|
||||||
|
is used, rather than binding it locally."
|
||||||
|
(declare (indent defun)
|
||||||
|
(advertised-calling-convention (files-or-query &optional query &key sort narrow buffer super-groups title) nil))
|
||||||
|
(cl-macrolet ((set-keyword-args (args)
|
||||||
|
`(setq sort (plist-get ,args :sort)
|
||||||
|
narrow (plist-get ,args :narrow)
|
||||||
|
buffer (plist-get ,args :buffer)
|
||||||
|
super-groups (plist-get ,args :super-groups)
|
||||||
|
title (plist-get ,args :title))))
|
||||||
|
(let ((files '(org-agenda-files))
|
||||||
|
query sort narrow buffer super-groups title)
|
||||||
|
;; Parse args manually (so we can leave FILES nil for a default argument).
|
||||||
|
;; TODO: DRY this and org-ql, I think.
|
||||||
|
(pcase args
|
||||||
|
(`(,arg-files ,arg-pred . ,(and rest (guard (keywordp (car rest)))))
|
||||||
|
;; Files, query, and keyword args (FIXME: Can I combine this and the next one? Does it
|
||||||
|
;; matter if rest is nil or starts with a keyword?)
|
||||||
|
(setq files arg-files
|
||||||
|
query arg-pred)
|
||||||
|
(set-keyword-args rest))
|
||||||
|
(`(,arg-pred . ,(and rest (guard (keywordp (car rest)))))
|
||||||
|
;; Query and keyword args, no files
|
||||||
|
(setq query arg-pred)
|
||||||
|
(set-keyword-args rest))
|
||||||
|
(`(,arg-files ,arg-pred)
|
||||||
|
;; Files and query, no keywords
|
||||||
|
(setq files arg-files
|
||||||
|
query arg-pred))
|
||||||
|
(`(,arg-pred)
|
||||||
|
;; Only query
|
||||||
|
(setq query arg-pred)))
|
||||||
|
(when (eq super-groups t)
|
||||||
|
(setq super-groups org-super-agenda-groups))
|
||||||
|
;; Call --agenda
|
||||||
|
`(org-ql-agenda--agenda ,files
|
||||||
|
;; TODO: Probably better to just use eval on org-ql rather than reimplementing parts of it here.
|
||||||
|
',query
|
||||||
|
:sort ',sort
|
||||||
|
:buffer ,buffer
|
||||||
|
:narrow ,narrow
|
||||||
|
:super-groups ',super-groups
|
||||||
|
:title ,title))))
|
||||||
|
|
||||||
|
(cl-defmacro org-ql-agenda* (&rest args)
|
||||||
|
"Display an agenda-like buffer of entries in FILES that match QUERY.
|
||||||
|
|
||||||
|
FILES-OR-QUERY is a sexp that is evaluated to get the list of
|
||||||
|
buffers and files to scan.
|
||||||
|
|
||||||
|
QUERY is an `org-ql' query. The query may be passed as
|
||||||
|
FILES-OR-QUERY and QUERY may be left nil, in which case the list
|
||||||
|
of files will automatically be set to the value of calling
|
||||||
|
`org-agenda-files'.
|
||||||
|
|
||||||
|
SORT is passed to `org-ql', which see..
|
||||||
|
|
||||||
|
NARROW, when non-nil, means to respect narrowing in buffers.
|
||||||
|
When nil, buffers are widened before being searched.
|
||||||
|
|
||||||
|
BUFFER, when non-nil, is a buffer or buffer name to display the
|
||||||
|
agenda in, rather than the default.
|
||||||
|
|
||||||
|
SUPER-GROUPS is used to bind variable `org-super-agenda-groups',
|
||||||
|
which see. If t, the existing value of `org-super-agenda-groups'
|
||||||
|
is used, rather than binding it locally."
|
||||||
|
(declare (indent defun)
|
||||||
|
(advertised-calling-convention (files-or-query &optional query &key sort narrow buffer super-groups) nil))
|
||||||
|
(cl-macrolet ((set-keyword-args (args)
|
||||||
|
`(setq sort (plist-get ,args :sort)
|
||||||
|
narrow (plist-get ,args :narrow)
|
||||||
|
buffer (plist-get ,args :buffer)
|
||||||
|
super-groups (plist-get ,args :super-groups))))
|
||||||
|
(let ((files '(org-agenda-files))
|
||||||
|
query sort narrow buffer super-groups)
|
||||||
|
;; Parse args manually (so we can leave FILES nil for a default argument).
|
||||||
|
;; TODO: DRY this and org-ql, I think.
|
||||||
|
(pcase args
|
||||||
|
(`(,arg-files ,arg-pred . ,(and rest (guard (keywordp (car rest)))))
|
||||||
|
;; Files, query, and keyword args (FIXME: Can I combine this and the next one? Does it
|
||||||
|
;; matter if rest is nil or starts with a keyword?)
|
||||||
|
(setq files arg-files
|
||||||
|
query arg-pred)
|
||||||
|
(set-keyword-args rest))
|
||||||
|
(`(,arg-pred . ,(and rest (guard (keywordp (car rest)))))
|
||||||
|
;; Query and keyword args, no files
|
||||||
|
(setq query arg-pred)
|
||||||
|
(set-keyword-args rest))
|
||||||
|
(`(,arg-files ,arg-pred)
|
||||||
|
;; Files and query, no keywords
|
||||||
|
(setq files arg-files
|
||||||
|
query arg-pred))
|
||||||
|
(`(,arg-pred)
|
||||||
|
;; Only query
|
||||||
|
(setq query arg-pred)))
|
||||||
|
(when (eq super-groups t)
|
||||||
|
(setq super-groups org-super-agenda-groups))
|
||||||
|
;; Call --agenda
|
||||||
|
`(org-ql-agenda--agenda* ,files
|
||||||
|
;; TODO: Probably better to just use eval on org-ql rather than reimplementing parts of it here.
|
||||||
|
',query
|
||||||
|
:sort ',sort
|
||||||
|
:buffer ,buffer
|
||||||
|
:narrow ,narrow
|
||||||
|
:super-groups ',super-groups))))
|
||||||
|
|
||||||
|
(cl-defmacro org-ql-agenda** (&rest args)
|
||||||
|
"Display an agenda-like buffer of entries in FILES that match QUERY.
|
||||||
|
|
||||||
|
FILES-OR-QUERY is a sexp that is evaluated to get the list of
|
||||||
|
buffers and files to scan.
|
||||||
|
|
||||||
|
QUERY is an `org-ql' query. The query may be passed as
|
||||||
|
FILES-OR-QUERY and QUERY may be left nil, in which case the list
|
||||||
|
of files will automatically be set to the value of calling
|
||||||
|
`org-agenda-files'.
|
||||||
|
|
||||||
|
SORT is passed to `org-ql', which see..
|
||||||
|
|
||||||
|
NARROW, when non-nil, means to respect narrowing in buffers.
|
||||||
|
When nil, buffers are widened before being searched.
|
||||||
|
|
||||||
|
BUFFER, when non-nil, is a buffer or buffer name to display the
|
||||||
|
agenda in, rather than the default.
|
||||||
|
|
||||||
|
SUPER-GROUPS is used to bind variable `org-super-agenda-groups',
|
||||||
|
which see. If t, the existing value of `org-super-agenda-groups'
|
||||||
|
is used, rather than binding it locally."
|
||||||
|
(declare (indent defun)
|
||||||
|
(advertised-calling-convention (files-or-query &optional query &key sort narrow buffer super-groups) nil))
|
||||||
|
(cl-macrolet ((set-keyword-args (args)
|
||||||
|
`(setq sort (plist-get ,args :sort)
|
||||||
|
narrow (plist-get ,args :narrow)
|
||||||
|
buffer (plist-get ,args :buffer)
|
||||||
|
super-groups (plist-get ,args :super-groups))))
|
||||||
|
(let ((files '(org-agenda-files))
|
||||||
|
query sort narrow buffer super-groups)
|
||||||
|
;; Parse args manually (so we can leave FILES nil for a default argument).
|
||||||
|
;; TODO: DRY this and org-ql, I think.
|
||||||
|
(pcase args
|
||||||
|
(`(,arg-files ,arg-pred . ,(and rest (guard (keywordp (car rest)))))
|
||||||
|
;; Files, query, and keyword args (FIXME: Can I combine this and the next one? Does it
|
||||||
|
;; matter if rest is nil or starts with a keyword?)
|
||||||
|
(setq files arg-files
|
||||||
|
query arg-pred)
|
||||||
|
(set-keyword-args rest))
|
||||||
|
(`(,arg-pred . ,(and rest (guard (keywordp (car rest)))))
|
||||||
|
;; Query and keyword args, no files
|
||||||
|
(setq query arg-pred)
|
||||||
|
(set-keyword-args rest))
|
||||||
|
(`(,arg-files ,arg-pred)
|
||||||
|
;; Files and query, no keywords
|
||||||
|
(setq files arg-files
|
||||||
|
query arg-pred))
|
||||||
|
(`(,arg-pred)
|
||||||
|
;; Only query
|
||||||
|
(setq query arg-pred)))
|
||||||
|
(when (eq super-groups t)
|
||||||
|
(setq super-groups org-super-agenda-groups))
|
||||||
|
;; Call --agenda
|
||||||
|
`(org-ql-agenda--agenda** ,files
|
||||||
|
;; TODO: Probably better to just use eval on org-ql rather than reimplementing parts of it here.
|
||||||
|
',query
|
||||||
|
:sort ',sort
|
||||||
|
:buffer ,buffer
|
||||||
|
:narrow ,narrow
|
||||||
|
:super-groups ',super-groups))))
|
||||||
|
|
||||||
|
;;;; Commands
|
||||||
|
|
||||||
|
;; TODO: This is called `org-ql-search' but it's in org-ql-agenda.el because
|
||||||
|
;; it uses `org-ql-agenda--agenda'. Maybe this could be better organized.
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(cl-defun org-ql-search (buffers-files query &key narrow groups sort title)
|
||||||
|
"Read QUERY and search with `org-ql'.
|
||||||
|
Interactively, prompt for these variables:
|
||||||
|
|
||||||
|
BUFFERS-FILES: A list of buffers and/or files to search.
|
||||||
|
Interactively, may also be:
|
||||||
|
|
||||||
|
- `buffer': search the current buffer
|
||||||
|
- `all': search all Org buffers
|
||||||
|
- `agenda': search buffers returned by the function `org-agenda-files'
|
||||||
|
- An expression which evaluates to a list of files/buffers
|
||||||
|
- A space-separated list of file or buffer names
|
||||||
|
|
||||||
|
GROUPS: An `org-super-agenda' group set. See variable
|
||||||
|
`org-super-agenda-groups'.
|
||||||
|
|
||||||
|
NARROW: When non-nil, don't widen buffers before
|
||||||
|
searching. Interactively, with prefix, leave narrowed.
|
||||||
|
|
||||||
|
SORT: One or a list of `org-ql' sorting functions, like `date' or
|
||||||
|
`priority'.
|
||||||
|
|
||||||
|
TITLE: An optional string displayed in the header."
|
||||||
|
(declare (indent defun))
|
||||||
|
(interactive (list (pcase-exhaustive (completing-read "Buffers/Files: "
|
||||||
|
(list 'buffer 'agenda 'all))
|
||||||
|
("agenda" (org-agenda-files))
|
||||||
|
("all" (--select (equal (buffer-local-value 'major-mode it) 'org-mode)
|
||||||
|
(buffer-list)))
|
||||||
|
("buffer" (current-buffer))
|
||||||
|
((and form (guard (rx bos "("))) (-flatten (eval (read form))))
|
||||||
|
(else (s-split (rx (1+ space)) else)))
|
||||||
|
(read-minibuffer "Query: ")
|
||||||
|
:narrow (eq current-prefix-arg '(4))
|
||||||
|
:groups (pcase (completing-read "Group by: "
|
||||||
|
(append (list "Don't group"
|
||||||
|
"Global groups")
|
||||||
|
(when (bound-and-true-p org-super-agenda-auto-selector-keywords)
|
||||||
|
(cl-loop for type in org-super-agenda-auto-selector-keywords
|
||||||
|
collect (substring (symbol-name type) 6)))))
|
||||||
|
("Global groups" org-super-agenda-groups)
|
||||||
|
("Don't group" nil)
|
||||||
|
(property (list (list (intern (concat ":auto-" property))))))
|
||||||
|
:sort (pcase (completing-read "Sort by: "
|
||||||
|
(list "Don't sort"
|
||||||
|
"date"
|
||||||
|
"deadline"
|
||||||
|
"priority"
|
||||||
|
"scheduled"
|
||||||
|
"todo"))
|
||||||
|
("Don't sort" nil)
|
||||||
|
(sort (intern sort)))))
|
||||||
|
(org-ql-agenda--agenda buffers-files
|
||||||
|
query
|
||||||
|
:narrow narrow
|
||||||
|
:sort sort
|
||||||
|
:super-groups groups
|
||||||
|
:title title
|
||||||
|
:buffer "*Org QL Search*"))
|
||||||
|
|
||||||
|
(defun org-ql-search-refresh ()
|
||||||
|
"Refresh current `org-ql-search' buffer."
|
||||||
|
(interactive)
|
||||||
|
(let ((current-line (buffer-substring-no-properties (line-beginning-position) (line-end-position)))
|
||||||
|
(old-pos (point)))
|
||||||
|
(org-ql-agenda--agenda org-ql-buffers-files
|
||||||
|
org-ql-query
|
||||||
|
:sort org-ql-sort
|
||||||
|
:narrow org-ql-narrow
|
||||||
|
:super-groups org-ql-super-groups
|
||||||
|
:title org-ql-title
|
||||||
|
:buffer (current-buffer))
|
||||||
|
(goto-char (point-min))
|
||||||
|
(or (search-forward current-line nil t)
|
||||||
|
(goto-char old-pos))
|
||||||
|
(beginning-of-line)))
|
||||||
|
|
||||||
|
(defun org-ql-search-save ()
|
||||||
|
"Save current `org-ql-search' buffer to `org-ql-views'."
|
||||||
|
(interactive)
|
||||||
|
(let* ((name (read-string "Save view as: "))
|
||||||
|
(buffers-files-sexp (cl-etypecase org-ql-buffers-files
|
||||||
|
(string org-ql-buffers-files)
|
||||||
|
(list `(list ,@org-ql-buffers-files))
|
||||||
|
(null nil)))
|
||||||
|
(function `(lambda ()
|
||||||
|
(interactive)
|
||||||
|
(org-ql-search ,buffers-files-sexp
|
||||||
|
',org-ql-query
|
||||||
|
:sort ',org-ql-sort
|
||||||
|
:narrow ,org-ql-narrow
|
||||||
|
:groups ',org-ql-super-groups
|
||||||
|
:title ,name))))
|
||||||
|
(map-put org-ql-views name function #'equal)
|
||||||
|
(customize-set-variable 'org-ql-views org-ql-views)
|
||||||
|
(customize-mark-to-save 'org-ql-views)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun org-ql-view (&optional view)
|
||||||
|
"Choose and display a view stored in `org-ql-views'."
|
||||||
|
(interactive (list (completing-read "View: " (mapcar #'car org-ql-views))))
|
||||||
|
(call-interactively (alist-get view org-ql-views nil nil #'string=)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(cl-defun org-ql-view-recent-items
|
||||||
|
(&key days type
|
||||||
|
(files (org-agenda-files))
|
||||||
|
(groups '((:auto-parent t)
|
||||||
|
(:auto-todo t))))
|
||||||
|
"Show items in FILES from last DAYS days with timestamps of TYPE.
|
||||||
|
TYPE may be `ts', `ts-active', `ts-inactive', `clocked', or
|
||||||
|
`closed'."
|
||||||
|
(interactive (list :days (read-number "Days: ")
|
||||||
|
:type (->> '(ts ts-active ts-inactive clocked closed)
|
||||||
|
(completing-read "Timestamp type: ")
|
||||||
|
intern)))
|
||||||
|
;; It doesn't make much sense to use other date-based selectors to
|
||||||
|
;; look into the past, so to prevent confusion, we won't allow them.
|
||||||
|
(-let* ((query (pcase-exhaustive type
|
||||||
|
((or 'ts 'ts-active 'ts-inactive)
|
||||||
|
;; These predicates look forward by default, so we must invert the number.
|
||||||
|
`(,type :from ,(- days) :to 0))
|
||||||
|
((or 'clocked 'closed)
|
||||||
|
`(,type :from ,days :to 0)))))
|
||||||
|
(org-ql-search files
|
||||||
|
query
|
||||||
|
:title "Recent items"
|
||||||
|
:sort '(date priority todo)
|
||||||
|
:groups groups)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(cl-defun org-ql-sparse-tree (query &key keep-previous (buffer (current-buffer)))
|
||||||
|
"Show a sparse tree for QUERY in BUFFER and return number of results.
|
||||||
|
The tree will show the lines where the query matches, and any
|
||||||
|
other context defined in `org-show-context-detail', which see.
|
||||||
|
|
||||||
|
QUERY is an `org-ql' query sexp (quoted, since this is a
|
||||||
|
function). BUFFER defaults to the current buffer.
|
||||||
|
|
||||||
|
When KEEP-PREVIOUS is non-nil (interactively, with prefix), the
|
||||||
|
outline is not reset to the overview state before finding
|
||||||
|
matches, which allows stacking calls to this command.
|
||||||
|
|
||||||
|
Runs `org-occur-hook' after making the sparse tree."
|
||||||
|
;; Code based on `org-occur'.
|
||||||
|
;; TODO: Use `helm-org-ql' plain-text query processing.
|
||||||
|
(interactive (list (read-minibuffer "Query: ")
|
||||||
|
:keep-previous current-prefix-arg))
|
||||||
|
(with-current-buffer buffer
|
||||||
|
(unless keep-previous
|
||||||
|
;; We don't do highlighting, because queries aren't regexps, but
|
||||||
|
;; we remove existing `org-occur' highlights, just in case.
|
||||||
|
(org-remove-occur-highlights nil nil t)
|
||||||
|
(org-overview))
|
||||||
|
(let ((num-results 0))
|
||||||
|
(org-ql-select buffer query
|
||||||
|
:action (lambda ()
|
||||||
|
(org-show-context 'occur-tree)
|
||||||
|
(cl-incf num-results)))
|
||||||
|
(unless org-sparse-tree-open-archived-trees
|
||||||
|
(org-hide-archived-subtrees (point-min) (point-max)))
|
||||||
|
(run-hooks 'org-occur-hook)
|
||||||
|
(unless (get-buffer-window buffer)
|
||||||
|
(pop-to-buffer buffer))
|
||||||
|
(message "%d matches" num-results)
|
||||||
|
num-results)))
|
||||||
|
|
||||||
|
;;;; Functions
|
||||||
|
|
||||||
|
(cl-defun org-ql-agenda--agenda (buffers-files query &key entries strings sort buffer narrow super-groups title)
|
||||||
|
"FIXME: Docstring"
|
||||||
|
;; TODO: Rename `entries' to `elements'.
|
||||||
|
(declare (indent defun))
|
||||||
|
(when (and super-groups (not org-super-agenda-mode))
|
||||||
|
(user-error "`org-super-agenda-mode' must be activated to use grouping"))
|
||||||
|
(when (and entries strings)
|
||||||
|
(user-error "Only one of ENTRIES or STRINGS may be provided"))
|
||||||
|
(let* ((org-super-agenda-groups super-groups)
|
||||||
|
(buffer (cl-etypecase buffer
|
||||||
|
(string (org-ql-agenda--buffer buffer))
|
||||||
|
(null (org-ql-agenda--buffer buffer))
|
||||||
|
(buffer buffer)))
|
||||||
|
(inhibit-read-only t)
|
||||||
|
string)
|
||||||
|
(cond (entries)
|
||||||
|
(strings (setf string (s-join "\n" strings)))
|
||||||
|
(query (setf entries (org-ql-select buffers-files
|
||||||
|
query
|
||||||
|
:sort sort
|
||||||
|
:narrow narrow
|
||||||
|
:action 'element-with-markers)))
|
||||||
|
(t (user-error "One of QUERY, ENTRIES, or STRINGS must be provided")))
|
||||||
|
(unless string
|
||||||
|
(setf string (--> entries
|
||||||
|
(mapcar #'org-ql-agenda--format-element it)
|
||||||
|
(cond ((bound-and-true-p org-super-agenda-mode) (org-super-agenda--group-items it))
|
||||||
|
(t it))
|
||||||
|
(s-join "\n" it))))
|
||||||
|
(with-current-buffer buffer
|
||||||
|
(use-local-map org-ql-view-map)
|
||||||
|
;; Prepare buffer, saving data for refreshing.
|
||||||
|
(setq-local org-ql-buffers-files buffers-files)
|
||||||
|
(setq-local org-ql-query query)
|
||||||
|
(setq-local org-ql-sort sort)
|
||||||
|
(setq-local org-ql-narrow narrow)
|
||||||
|
(setq-local org-ql-super-groups super-groups)
|
||||||
|
(setq-local org-ql-title title)
|
||||||
|
(setq-local header-line-format (org-ql-agenda--header-line-format buffers-files query title))
|
||||||
|
;; Clear buffer, insert entries, etc.
|
||||||
|
(erase-buffer)
|
||||||
|
(insert string)
|
||||||
|
(pop-to-buffer (current-buffer))
|
||||||
|
(org-agenda-finalize)
|
||||||
|
(goto-char (point-min)))))
|
||||||
|
|
||||||
|
(cl-defun org-ql-agenda--agenda* (buffers-files query &key entries sort buffer narrow super-groups)
|
||||||
|
"FIXME: Docstring"
|
||||||
|
(declare (indent defun))
|
||||||
|
(when (and super-groups (not org-super-agenda-mode))
|
||||||
|
(user-error "`org-super-agenda-mode' must be activated to use grouping"))
|
||||||
|
(let* ((org-super-agenda-groups super-groups)
|
||||||
|
(entries (or entries
|
||||||
|
(--> (org-ql-select buffers-files
|
||||||
|
query
|
||||||
|
:sort sort
|
||||||
|
:narrow narrow
|
||||||
|
:action (lambda ()
|
||||||
|
(->> (org-element-headline-parser (line-end-position))
|
||||||
|
org-ql--add-markers))))))
|
||||||
|
(org-ql-todo-keyword-length (cl-loop for e in entries
|
||||||
|
for todo-keyword = (org-element-property :todo-keyword e)
|
||||||
|
when todo-keyword
|
||||||
|
maximizing (length todo-keyword)))
|
||||||
|
(string (--> entries
|
||||||
|
(mapcar #'org-ql-agenda--format-element* it)
|
||||||
|
(cond ((bound-and-true-p org-super-agenda-mode) (org-super-agenda--group-items it))
|
||||||
|
(t it))
|
||||||
|
(s-join "\n" it)))
|
||||||
|
(buffer (cl-etypecase buffer
|
||||||
|
(string (org-ql-agenda--buffer buffer))
|
||||||
|
(null (org-ql-agenda--buffer buffer))
|
||||||
|
(buffer buffer)))
|
||||||
|
(map (copy-keymap org-agenda-mode-map))
|
||||||
|
(inhibit-read-only t))
|
||||||
|
(define-key map "g" #'org-ql-search-refresh)
|
||||||
|
(with-current-buffer buffer
|
||||||
|
(use-local-map map)
|
||||||
|
;; Prepare buffer, saving data for refreshing.
|
||||||
|
(setq-local org-ql-buffers-files buffers-files)
|
||||||
|
(setq-local org-ql-query query)
|
||||||
|
(setq-local org-ql-sort sort)
|
||||||
|
(setq-local org-ql-narrow narrow)
|
||||||
|
(setq-local org-ql-super-groups super-groups)
|
||||||
|
(setq-local header-line-format (org-ql-agenda--header-line-format buffers-files query))
|
||||||
|
;; Clear buffer, insert entries, etc.
|
||||||
|
(erase-buffer)
|
||||||
|
(insert string)
|
||||||
|
(pop-to-buffer (current-buffer))
|
||||||
|
(org-agenda-finalize)
|
||||||
|
(goto-char (point-min)))))
|
||||||
|
|
||||||
|
(defun org-ql-agenda-todo-keyword-max-length ()
|
||||||
|
"FIXME: Docstring."
|
||||||
|
(->> org-todo-keywords
|
||||||
|
(-map #'cdr)
|
||||||
|
-flatten
|
||||||
|
(--remove (string= "|" it))
|
||||||
|
(--map (progn
|
||||||
|
(string-match (rx (1+ (not (in "(")))) it)
|
||||||
|
(length (match-string 0 it))))
|
||||||
|
(apply #'max)))
|
||||||
|
|
||||||
|
(defvar org-ql-agenda-todo-format)
|
||||||
|
|
||||||
|
(cl-defun org-ql-agenda--agenda** (buffers-files query &key entries sort buffer narrow super-groups)
|
||||||
|
"FIXME: Docstring"
|
||||||
|
(declare (indent defun))
|
||||||
|
(when (and super-groups (not org-super-agenda-mode))
|
||||||
|
(user-error "`org-super-agenda-mode' must be activated to use grouping"))
|
||||||
|
(let* ((org-super-agenda-groups super-groups)
|
||||||
|
(entries (or entries
|
||||||
|
(--> (org-ql-select buffers-files
|
||||||
|
query
|
||||||
|
:sort sort
|
||||||
|
:narrow narrow
|
||||||
|
:action (lambda ()
|
||||||
|
(->> (org-element-headline-parser (line-end-position))
|
||||||
|
org-ql--add-markers))))))
|
||||||
|
(org-ql-todo-keyword-length (org-ql-agenda-todo-keyword-max-length))
|
||||||
|
(org-ql-agenda-todo-format (concat "%" (number-to-string org-ql-todo-keyword-length) "s"))
|
||||||
|
(string (--> entries
|
||||||
|
(mapcar #'org-ql-agenda--format-element* it)
|
||||||
|
(cond ((bound-and-true-p org-super-agenda-mode) (org-super-agenda--group-items it))
|
||||||
|
(t it))
|
||||||
|
(s-join "\n" it)))
|
||||||
|
(buffer (cl-etypecase buffer
|
||||||
|
(string (org-ql-agenda--buffer buffer))
|
||||||
|
(null (org-ql-agenda--buffer buffer))
|
||||||
|
(buffer buffer)))
|
||||||
|
(map (copy-keymap org-agenda-mode-map))
|
||||||
|
(inhibit-read-only t))
|
||||||
|
(define-key map "g" #'org-ql-search-refresh)
|
||||||
|
(with-current-buffer buffer
|
||||||
|
(use-local-map map)
|
||||||
|
;; Prepare buffer, saving data for refreshing.
|
||||||
|
(setq-local org-ql-buffers-files buffers-files)
|
||||||
|
(setq-local org-ql-query query)
|
||||||
|
(setq-local org-ql-sort sort)
|
||||||
|
(setq-local org-ql-narrow narrow)
|
||||||
|
(setq-local org-ql-super-groups super-groups)
|
||||||
|
(setq-local header-line-format (org-ql-agenda--header-line-format buffers-files query))
|
||||||
|
;; Clear buffer, insert entries, etc.
|
||||||
|
(erase-buffer)
|
||||||
|
(insert string)
|
||||||
|
(pop-to-buffer (current-buffer))
|
||||||
|
(org-agenda-finalize)
|
||||||
|
(goto-char (point-min)))))
|
||||||
|
|
||||||
|
(defun org-ql-agenda-block (query)
|
||||||
|
"Insert items for QUERY into current buffer.
|
||||||
|
QUERY should be an `org-ql' query form. Intended to be used as a
|
||||||
|
user-defined function in `org-agenda-custom-commands'. QUERY
|
||||||
|
corresponds to the `match' item in the custom command form.
|
||||||
|
|
||||||
|
Like other agenda block commands, it searches files returned by
|
||||||
|
function `org-agenda-files'. Inserts a newline after the block.
|
||||||
|
|
||||||
|
If `org-ql-block-header' is non-nil, it is used as the header
|
||||||
|
string for the block, otherwise a the header is formed
|
||||||
|
automatically from the query."
|
||||||
|
(when-let* ((from (org-agenda-files nil 'ifmode))
|
||||||
|
(items (org-ql-select from
|
||||||
|
query :action 'element-with-markers)))
|
||||||
|
;; Not sure if calling the prepare function is necessary, but let's follow the pattern.
|
||||||
|
(org-agenda-prepare)
|
||||||
|
;; TODO: `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.
|
||||||
|
;; (org-agenda--insert-overriding-header (or org-ql-block-header (org-ql-agenda--header-line-format from query)))
|
||||||
|
(insert (org-add-props (or org-ql-block-header (org-ql-agenda--header-line-format from query))
|
||||||
|
nil 'face 'org-agenda-structure) "\n")
|
||||||
|
;; 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.
|
||||||
|
;; But we do call `org-agenda-finalize-entries', which allows `org-super-agenda' to work.
|
||||||
|
(->> items
|
||||||
|
(-map #'org-ql-agenda--format-element)
|
||||||
|
org-agenda-finalize-entries
|
||||||
|
insert)
|
||||||
|
(insert "\n")))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defalias 'org-ql-block 'org-ql-agenda-block)
|
||||||
|
|
||||||
|
(defun org-ql-agenda--header-line-format (buffers-files query &optional title)
|
||||||
|
"Return header-line-format for BUFFERS-FILES and QUERY."
|
||||||
|
(let* ((title (if title
|
||||||
|
(concat (propertize "View:" 'face 'org-agenda-structure)
|
||||||
|
title " ")
|
||||||
|
""))
|
||||||
|
(query-formatted (format "%S" query))
|
||||||
|
(query-formatted (propertize (org-ql-agenda--font-lock-string 'emacs-lisp-mode query-formatted)
|
||||||
|
'help-echo query-formatted))
|
||||||
|
(query-width (length query-formatted))
|
||||||
|
(available-width (max 0 (- (window-width)
|
||||||
|
(length "In: ")
|
||||||
|
(length "Query: ")
|
||||||
|
query-width 4)))
|
||||||
|
(buffers-files-formatted (format "%S" buffers-files))
|
||||||
|
(buffers-files-formatted (propertize (->> buffers-files-formatted
|
||||||
|
(org-ql-agenda--font-lock-string 'emacs-lisp-mode)
|
||||||
|
(s-truncate available-width))
|
||||||
|
'help-echo buffers-files-formatted)))
|
||||||
|
(concat title
|
||||||
|
(propertize "Query:" 'face 'org-agenda-structure)
|
||||||
|
query-formatted " "
|
||||||
|
(propertize "In:" 'face 'org-agenda-structure)
|
||||||
|
buffers-files-formatted)))
|
||||||
|
|
||||||
|
(defun org-ql-agenda--font-lock-string (mode s)
|
||||||
|
"Return string S font-locked according to MODE."
|
||||||
|
;; TODO: Is this the proper way to do this? It works, but I feel like there must be a built-in way...
|
||||||
|
(with-temp-buffer
|
||||||
|
(delay-mode-hooks
|
||||||
|
(insert s)
|
||||||
|
(funcall mode)
|
||||||
|
(font-lock-ensure)
|
||||||
|
(buffer-string))))
|
||||||
|
|
||||||
|
(defun org-ql-agenda--buffer (&optional name)
|
||||||
|
"Return Agenda NG buffer, creating it if necessary.
|
||||||
|
If NAME is non-nil, return buffer by that name instead of using
|
||||||
|
default buffer."
|
||||||
|
(with-current-buffer (get-buffer-create (or name org-ql-agenda-buffer-name))
|
||||||
|
(unless (eq major-mode 'org-agenda-mode)
|
||||||
|
(org-agenda-mode))
|
||||||
|
(current-buffer)))
|
||||||
|
|
||||||
|
(defun org-ql-agenda--format-relative-date (difference)
|
||||||
|
;; MAYBE: Make this a `defsubst'.
|
||||||
|
"Return relative date string for DIFFERENCE.
|
||||||
|
DIFFERENCE should be an integer number of days, positive for
|
||||||
|
dates in the past, and negative for dates in the future."
|
||||||
|
(cond ((> difference 0)
|
||||||
|
(format "%sd ago" difference))
|
||||||
|
((< difference 0)
|
||||||
|
(format "in %sd" (* -1 difference)))
|
||||||
|
(t "today")))
|
||||||
|
|
||||||
|
;;;; Faces/properties
|
||||||
|
|
||||||
|
(defun org-ql-agenda--format-element (element)
|
||||||
|
;; This essentially needs to do what `org-agenda-format-item' does,
|
||||||
|
;; which is a lot. We are a long way from that, but it's a start.
|
||||||
|
"Return ELEMENT as a string with text-properties set by its property list.
|
||||||
|
Its property list should be the second item in the list, as
|
||||||
|
returned by `org-element-parse-buffer'. If ELEMENT is nil,
|
||||||
|
return an empty string."
|
||||||
|
(if (not element)
|
||||||
|
""
|
||||||
|
(let* ((properties (cadr element))
|
||||||
|
;; Remove the :parent property, which so bloats the size of
|
||||||
|
;; the properties list that it makes it essentially
|
||||||
|
;; impossible to debug, because Emacs takes approximately
|
||||||
|
;; forever to show it in the minibuffer or with
|
||||||
|
;; `describe-text-properties'. TODO: Shouldn't be necessary
|
||||||
|
;; anymore since we're not parsing the whole buffer.
|
||||||
|
|
||||||
|
;; Also, remove ":" from key symbols. TODO: It would be
|
||||||
|
;; better to avoid this somehow. At least, we should use a
|
||||||
|
;; function to convert plists to alists, if possible.
|
||||||
|
(properties (cl-loop for (key val) on properties by #'cddr
|
||||||
|
for symbol = (intern (cl-subseq (symbol-name key) 1))
|
||||||
|
unless (member symbol '(parent))
|
||||||
|
append (list symbol val)))
|
||||||
|
;; TODO: --add-faces is used to add the :relative-due-date property, but that fact is
|
||||||
|
;; hidden by doing it through --add-faces (which calls --add-scheduled-face and
|
||||||
|
;; --add-deadline-face), and doing it in this form that gets the title hides it even more.
|
||||||
|
;; 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-agenda--add-faces element)
|
||||||
|
(org-element-property :raw-value it)
|
||||||
|
(org-link-display-format it)))
|
||||||
|
(todo-keyword (-some--> (org-element-property :todo-keyword element)
|
||||||
|
(org-ql-agenda--add-todo-face it)))
|
||||||
|
;; TODO: Figure out whether I should use `org-agenda-use-tag-inheritance' or `org-use-tag-inheritance', etc.
|
||||||
|
(tag-list (if org-use-tag-inheritance
|
||||||
|
;; NOTE: Tag inheritance cannot be used here unless markers are added, otherwise
|
||||||
|
;; we can't go to the item's buffer to look for inherited tags. (Or does
|
||||||
|
;; `org-element-headline-parser' parse inherited tags too? I forget...)
|
||||||
|
(if-let ((marker (or (org-element-property :org-hd-marker element)
|
||||||
|
(org-element-property :org-marker element))))
|
||||||
|
(with-current-buffer (marker-buffer marker)
|
||||||
|
;; I wish `org-get-tags' used the correct buffer automatically.
|
||||||
|
(org-get-tags marker (not org-use-tag-inheritance)))
|
||||||
|
;; No marker found.
|
||||||
|
;; MAYBE: Issue some kind of warning when no marker is found, because it's
|
||||||
|
;; likely a mistake. But we don't want to be annoying in case it's intentional.
|
||||||
|
(org-element-property :tags element))
|
||||||
|
(org-element-property :tags element)))
|
||||||
|
(tag-string (when tag-list
|
||||||
|
(--> tag-list
|
||||||
|
(s-join ":" it)
|
||||||
|
(s-wrap it ":")
|
||||||
|
(org-add-props it nil 'face 'org-tag))))
|
||||||
|
;; (category (org-element-property :category element))
|
||||||
|
(priority-string (-some->> (org-element-property :priority element)
|
||||||
|
(char-to-string)
|
||||||
|
(format "[#%s]")
|
||||||
|
(org-ql-agenda--add-priority-face)))
|
||||||
|
(habit-property (org-with-point-at (org-element-property :begin element)
|
||||||
|
(when (org-is-habit-p)
|
||||||
|
(org-habit-parse-todo))))
|
||||||
|
(due-string (pcase (org-element-property :relative-due-date element)
|
||||||
|
('nil "")
|
||||||
|
(string (format " %s " (org-add-props string nil 'face 'org-ql-agenda-due-date)))))
|
||||||
|
(string (s-join " " (-non-nil (list todo-keyword priority-string title due-string tag-string)))))
|
||||||
|
(remove-list-of-text-properties 0 (length string) '(line-prefix) string)
|
||||||
|
;; Add all the necessary properties and faces to the whole string
|
||||||
|
(--> string
|
||||||
|
;; TODO: Use agenda-like format strings.
|
||||||
|
(concat " " it)
|
||||||
|
(org-add-props it properties
|
||||||
|
'todo-state todo-keyword
|
||||||
|
'tags tag-list
|
||||||
|
'org-habit-p habit-property)))))
|
||||||
|
|
||||||
|
(defun org-ql-agenda--format-element* (element)
|
||||||
|
;; This essentially needs to do what `org-agenda-format-item' does,
|
||||||
|
;; which is a lot. We are a long way from that, but it's a start.
|
||||||
|
"Return ELEMENT as a string with text-properties set by its property list.
|
||||||
|
Its property list should be the second item in the list, as
|
||||||
|
returned by `org-element-parse-buffer'. If ELEMENT is nil,
|
||||||
|
return an empty string."
|
||||||
|
(if (not element)
|
||||||
|
""
|
||||||
|
(let* ((properties (cadr element))
|
||||||
|
;; Remove the :parent property, which so bloats the size of
|
||||||
|
;; the properties list that it makes it essentially
|
||||||
|
;; impossible to debug, because Emacs takes approximately
|
||||||
|
;; forever to show it in the minibuffer or with
|
||||||
|
;; `describe-text-properties'. FIXME: Shouldn't be necessary
|
||||||
|
;; anymore since we're not parsing the whole buffer.
|
||||||
|
|
||||||
|
;; Also, remove ":" from key symbols. FIXME: It would be
|
||||||
|
;; better to avoid this somehow. At least, we should use a
|
||||||
|
;; function to convert plists to alists, if possible.
|
||||||
|
(properties (cl-loop for (key val) on properties by #'cddr
|
||||||
|
for symbol = (intern (cl-subseq (symbol-name key) 1))
|
||||||
|
unless (member symbol '(parent))
|
||||||
|
append (list symbol val)))
|
||||||
|
;; TODO: --add-faces is used to add the :relative-due-date property, but that fact is
|
||||||
|
;; hidden by doing it through --add-faces (which calls --add-scheduled-face and
|
||||||
|
;; --add-deadline-face), and doing it in this form that gets the title hides it even more.
|
||||||
|
;; 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-agenda--add-faces element)
|
||||||
|
(org-element-property :raw-value it)
|
||||||
|
(org-link-display-format it)))
|
||||||
|
(todo-keyword (-some--> (org-element-property :todo-keyword element)
|
||||||
|
(org-ql-agenda--add-todo-face it)
|
||||||
|
(format org-ql-agenda-todo-format it)))
|
||||||
|
;; FIXME: Figure out whether I should use `org-agenda-use-tag-inheritance' or `org-use-tag-inheritance', etc.
|
||||||
|
(tag-list (if org-use-tag-inheritance
|
||||||
|
;; FIXME: Note that tag inheritance cannot be used here unless markers are
|
||||||
|
;; added, otherwise we can't go to the item's buffer to look for inherited
|
||||||
|
;; tags. (Or does `org-element-headline-parser' parse inherited tags too? I
|
||||||
|
;; forget...)
|
||||||
|
(if-let ((marker (or (org-element-property :org-hd-marker element)
|
||||||
|
(org-element-property :org-marker element))))
|
||||||
|
(with-current-buffer (marker-buffer marker)
|
||||||
|
;; I wish `org-get-tags' used the correct buffer automatically.
|
||||||
|
(org-get-tags marker (not org-use-tag-inheritance)))
|
||||||
|
;; No marker found
|
||||||
|
(warn "No marker found for item: %s" title)
|
||||||
|
(org-element-property :tags element))
|
||||||
|
(org-element-property :tags element)))
|
||||||
|
(tag-string (when tag-list
|
||||||
|
(--> tag-list
|
||||||
|
(s-join ":" it)
|
||||||
|
(s-wrap it ":")
|
||||||
|
(org-add-props it nil 'face 'org-tag))))
|
||||||
|
;; (category (org-element-property :category element))
|
||||||
|
(priority-string (-some->> (org-element-property :priority element)
|
||||||
|
(char-to-string)
|
||||||
|
(format "[#%s]")
|
||||||
|
(org-ql-agenda--add-priority-face)))
|
||||||
|
(habit-property (org-with-point-at (org-element-property :begin element)
|
||||||
|
(when (org-is-habit-p)
|
||||||
|
(org-habit-parse-todo))))
|
||||||
|
(due-string (pcase (org-element-property :relative-due-date element)
|
||||||
|
('nil " ")
|
||||||
|
(string (format "%8s" (org-add-props string nil 'face 'org-ql-agenda-due-date)))))
|
||||||
|
(string (s-join " " (-non-nil (list due-string todo-keyword priority-string title tag-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
|
||||||
|
'todo-state todo-keyword
|
||||||
|
'tags tag-list
|
||||||
|
'org-habit-p habit-property)))))
|
||||||
|
|
||||||
|
(defun org-ql-agenda--add-faces (element)
|
||||||
|
"Return ELEMENT with deadline and scheduled faces added."
|
||||||
|
(->> element
|
||||||
|
(org-ql-agenda--add-scheduled-face)
|
||||||
|
(org-ql-agenda--add-deadline-face)))
|
||||||
|
|
||||||
|
(defun org-ql-agenda--add-priority-face (string)
|
||||||
|
"Return STRING with priority face added."
|
||||||
|
(when (string-match "\\(\\[#\\(.\\)\\]\\)" string)
|
||||||
|
(let ((face (org-get-priority-face (string-to-char (match-string 2 string)))))
|
||||||
|
(org-add-props string nil 'face face 'font-lock-fontified t))))
|
||||||
|
|
||||||
|
(defun org-ql-agenda--add-scheduled-face (element)
|
||||||
|
"Add faces to ELEMENT's title for its scheduled status."
|
||||||
|
;; NOTE: Also adding prefix
|
||||||
|
(if-let ((scheduled-date (org-element-property :scheduled element)))
|
||||||
|
(let* ((todo-keyword (org-element-property :todo-keyword element))
|
||||||
|
(today-day-number (org-today))
|
||||||
|
;; (current-day-number
|
||||||
|
;; NOTE: Not currently used, but if we ever implement a more "traditional" agenda that
|
||||||
|
;; shows perspective of multiple days at once, we'll need this, so I'll leave it for now.
|
||||||
|
;; ;; NOTE: This is supposed to be the, shall we say,
|
||||||
|
;; ;; pretend, or perspective, day number that this pass
|
||||||
|
;; ;; through the agenda is being made for. We need to
|
||||||
|
;; ;; either set this in the calling function, set it here,
|
||||||
|
;; ;; or accomplish this in a different way. See
|
||||||
|
;; ;; `org-agenda-get-scheduled' and where `date' is set in
|
||||||
|
;; ;; `org-agenda-list'.
|
||||||
|
;; today-day-number)
|
||||||
|
(scheduled-day-number (org-time-string-to-absolute
|
||||||
|
(org-element-timestamp-interpreter scheduled-date 'ignore)))
|
||||||
|
(difference-days (- today-day-number scheduled-day-number))
|
||||||
|
(relative-due-date (org-add-props (org-ql-agenda--format-relative-date difference-days) nil
|
||||||
|
'help-echo (org-element-property :raw-value scheduled-date)))
|
||||||
|
;; NOTE: Unused for now:
|
||||||
|
;; (show-all (or (eq org-agenda-repeating-timestamp-show-all t)
|
||||||
|
;; (member todo-keyword org-agenda-repeating-timestamp-show-all)))
|
||||||
|
;; NOTE: Unused for now: (sexp-p (string-prefix-p "%%" raw-value))
|
||||||
|
;; NOTE: Unused for now: (raw-value (org-element-property :raw-value scheduled-date))
|
||||||
|
;; NOTE: I don't remember what `repeat-day-number' was for, but we aren't using it.
|
||||||
|
;; But I'll leave it here for now.
|
||||||
|
;; (repeat-day-number (cond (sexp-p (org-time-string-to-absolute scheduled-date))
|
||||||
|
;; ((< today-day-number scheduled-day-number) scheduled-day-number)
|
||||||
|
;; (t (org-time-string-to-absolute
|
||||||
|
;; raw-value
|
||||||
|
;; (if show-all
|
||||||
|
;; current-day-number
|
||||||
|
;; today-day-number)
|
||||||
|
;; 'future
|
||||||
|
;; ;; NOTE: I don't like
|
||||||
|
;; ;; calling `current-buffer'
|
||||||
|
;; ;; here. If the element has
|
||||||
|
;; ;; a marker, we should use
|
||||||
|
;; ;; that.
|
||||||
|
;; (current-buffer)
|
||||||
|
;; (org-element-property :begin element)))))
|
||||||
|
(face (cond ((member todo-keyword org-done-keywords) 'org-agenda-done)
|
||||||
|
((= today-day-number scheduled-day-number) 'org-scheduled-today)
|
||||||
|
((> today-day-number scheduled-day-number) 'org-scheduled-previously)
|
||||||
|
(t 'org-scheduled)))
|
||||||
|
(title (--> (org-element-property :raw-value element)
|
||||||
|
(org-add-props it nil
|
||||||
|
'face face)))
|
||||||
|
(properties (--> (cadr element)
|
||||||
|
(plist-put it :title title)
|
||||||
|
(plist-put it :relative-due-date relative-due-date))))
|
||||||
|
(list (car element)
|
||||||
|
properties))
|
||||||
|
;; Not scheduled
|
||||||
|
element))
|
||||||
|
|
||||||
|
(defun org-ql-agenda--add-deadline-face (element)
|
||||||
|
"Add faces to ELEMENT's title for its deadline status.
|
||||||
|
Also store relative due date as string in `:relative-due-date'
|
||||||
|
property."
|
||||||
|
;; FIXME: In my config, doesn't apply orange for approaching deadline the same way the Org Agenda does.
|
||||||
|
(if-let ((deadline-date (org-element-property :deadline element)))
|
||||||
|
(let* ((today-day-number (org-today))
|
||||||
|
(deadline-day-number (org-time-string-to-absolute
|
||||||
|
(org-element-timestamp-interpreter deadline-date 'ignore)))
|
||||||
|
(difference-days (- today-day-number deadline-day-number))
|
||||||
|
(relative-due-date (org-add-props (org-ql-agenda--format-relative-date difference-days) nil
|
||||||
|
'help-echo (org-element-property :raw-value deadline-date)))
|
||||||
|
;; NOTE: Unused for now: (todo-keyword (org-element-property :todo-keyword element))
|
||||||
|
;; NOTE: Unused for now: (done-p (member todo-keyword org-done-keywords))
|
||||||
|
;; NOTE: Unused for now: (today-p (= today-day-number deadline-day-number))
|
||||||
|
(deadline-passed-fraction (--> (- deadline-day-number today-day-number)
|
||||||
|
(float it)
|
||||||
|
(/ it (max org-deadline-warning-days 1))
|
||||||
|
(- 1 it)))
|
||||||
|
(face (org-agenda-deadline-face deadline-passed-fraction))
|
||||||
|
(title (--> (org-element-property :raw-value element)
|
||||||
|
(org-add-props it nil
|
||||||
|
'face face)))
|
||||||
|
(properties (--> (cadr element)
|
||||||
|
(plist-put it :title title)
|
||||||
|
(plist-put it :relative-due-date relative-due-date))))
|
||||||
|
(list (car element)
|
||||||
|
properties))
|
||||||
|
;; No deadline
|
||||||
|
element))
|
||||||
|
|
||||||
|
(defun org-ql-agenda--add-todo-face (keyword)
|
||||||
|
"Return KEYWORD with TODO face added."
|
||||||
|
(when-let ((face (org-get-todo-face keyword)))
|
||||||
|
(org-add-props keyword nil 'face face)))
|
||||||
|
|
||||||
|
;;;; Footer
|
||||||
|
|
||||||
|
(provide 'org-ql-agenda)
|
||||||
|
|
||||||
|
;;; org-ql-agenda.el ends here
|
||||||
|
|
@ -1,402 +0,0 @@
|
||||||
;;; org-ql-completing-read.el --- Completing read of Org entries using org-ql -*- lexical-binding: t; -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2022-2023 Adam Porter
|
|
||||||
|
|
||||||
;; Author: Adam Porter <adam@alphapapa.net>
|
|
||||||
|
|
||||||
;; 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
|
|
||||||
;; the Free Software Foundation, either version 3 of the License, or
|
|
||||||
;; (at your option) any later version.
|
|
||||||
|
|
||||||
;; This program is distributed in the hope that it will be useful,
|
|
||||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
;; GNU General Public License for more details.
|
|
||||||
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library provides completing-read of Org entries using `org-ql'
|
|
||||||
;; search.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(require 'org-ql)
|
|
||||||
|
|
||||||
(declare-function org-ql-search "org-ql-search")
|
|
||||||
(declare-function org-ql--normalize-query "org-ql" t t)
|
|
||||||
|
|
||||||
;;;; 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
|
|
||||||
"Completing-read of Org entries using `org-ql' search."
|
|
||||||
:group 'org-ql)
|
|
||||||
|
|
||||||
(defcustom org-ql-completing-read-reverse-paths t
|
|
||||||
"Whether to reverse Org outline paths in `org-ql-completing-read' results."
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defcustom org-ql-completing-read-snippet-function #'org-ql-completing-read--snippet-simple
|
|
||||||
;; TODO(v0.9): Performance of completion annotations seems to be
|
|
||||||
;; much improved now (whether due to changes in Emacs, Vertico, or
|
|
||||||
;; both, I don't know). It may be reasonable to make the context
|
|
||||||
;; snippet the default now.
|
|
||||||
"Function used to annotate results in `org-ql-completing-read'.
|
|
||||||
Function is called at entry beginning. (When set to
|
|
||||||
`org-ql-completing-read--snippet-regexp', it is called with a
|
|
||||||
regexp matching plain query tokens.)"
|
|
||||||
:type '(choice (function-item :tag "Show context around search terms" org-ql-completing-read--snippet-regexp)
|
|
||||||
(function-item :tag "Show first N characters" org-ql-completing-read--snippet-simple)
|
|
||||||
(function :tag "Custom function")))
|
|
||||||
|
|
||||||
(defcustom org-ql-completing-read-snippet-length 51
|
|
||||||
"Size of snippets of entry content to include in completion annotations.
|
|
||||||
Only used when `org-ql-completing-read-snippet-function' is set
|
|
||||||
to `org-ql-completing-read--snippet-regexp'."
|
|
||||||
:type 'integer)
|
|
||||||
|
|
||||||
(defcustom org-ql-completing-read-snippet-minimum-token-length 3
|
|
||||||
"Query tokens shorter than this many characters are ignored.
|
|
||||||
That is, they are not included when gathering entry snippets.
|
|
||||||
This avoids too-small tokens causing performance problems."
|
|
||||||
:type 'integer)
|
|
||||||
|
|
||||||
(defcustom org-ql-completing-read-snippet-prefix nil
|
|
||||||
"String prepended to snippets.
|
|
||||||
For an experience like `org-rifle', use a newline."
|
|
||||||
:type '(choice (const :tag "None (shown on same line)" nil)
|
|
||||||
(const :tag "New line (shown under heading)" "\n")
|
|
||||||
string))
|
|
||||||
|
|
||||||
(defface org-ql-completing-read-snippet '((t (:inherit font-lock-comment-face)))
|
|
||||||
"Snippets.")
|
|
||||||
|
|
||||||
(defvar org-ql-completing-read-input-regexp nil
|
|
||||||
"Current regexp for `org-ql-completing-read' input.
|
|
||||||
To be used in, e.g. annotation functions.")
|
|
||||||
|
|
||||||
;;;; 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 (pos-bol) (pos-eol))
|
|
||||||
(cons (org-link-display-format (org-entry-get nil "ITEM")) (point-marker)))
|
|
||||||
|
|
||||||
(defun org-ql-completing-read-snippet (marker)
|
|
||||||
"Return snippet for entry at MARKER.
|
|
||||||
Returns value returned by function
|
|
||||||
`org-ql-completing-read-snippet-function' or
|
|
||||||
`org-ql-completing-read--snippet-simple', whichever returns a
|
|
||||||
value, or nil."
|
|
||||||
(pcase (while-no-input
|
|
||||||
;; 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 org-rifle-style snippets.
|
|
||||||
(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))))
|
|
||||||
(`t ;; Interrupted: return nil (which can be concatted).
|
|
||||||
nil)
|
|
||||||
(else (propertize (concat " " else)
|
|
||||||
'face 'org-ql-completing-read-snippet))))
|
|
||||||
|
|
||||||
(defun org-ql-completing-read-path (marker)
|
|
||||||
"Return formatted outline path for entry at MARKER."
|
|
||||||
(org-with-point-at marker
|
|
||||||
(let ((path (thread-first (org-get-outline-path nil t)
|
|
||||||
(org-format-outline-path (window-width) nil "")
|
|
||||||
(org-split-string ""))))
|
|
||||||
(if org-ql-completing-read-reverse-paths
|
|
||||||
(concat "\\" (string-join (reverse path) "\\"))
|
|
||||||
(concat "/" (string-join path "/"))))))
|
|
||||||
|
|
||||||
;;;;; 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 narrowp
|
|
||||||
(action #'org-ql-completing-read-action)
|
|
||||||
;; FIXME: Unused argument.
|
|
||||||
;; (annotate #'org-ql-completing-read-snippet)
|
|
||||||
(snippet #'org-ql-completing-read-snippet)
|
|
||||||
(path #'org-ql-completing-read-path)
|
|
||||||
(action-filter #'list)
|
|
||||||
(prompt "Find entry: "))
|
|
||||||
"Return marker at entry in BUFFERS-FILES selected with `org-ql'.
|
|
||||||
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
|
|
||||||
the user (e.g. use \"heading:\" to only search headings, easily
|
|
||||||
creating a custom command that saves the user from having to type
|
|
||||||
it).
|
|
||||||
|
|
||||||
QUERY-FILTER may be a function through which the query the user
|
|
||||||
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)."
|
|
||||||
(declare (indent defun))
|
|
||||||
;; Emacs's completion API is not always easy to understand, especially when using "programmed
|
|
||||||
;; completion." This code was made possible by the example Clemens Radermacher shared at
|
|
||||||
;; <https://github.com/radian-software/selectrum/issues/114#issuecomment-744041532>.
|
|
||||||
|
|
||||||
;; NOTE: I don't usually leave commented-out debugging code, but due to the incredibly tedious
|
|
||||||
;; complexity of the "Programmed Completion" API and the time spent trying to get this reasonably
|
|
||||||
;; close to "correct," I'm leaving it in, because I will undoubtedly have to go through this
|
|
||||||
;; process again.
|
|
||||||
|
|
||||||
;; (message "ORG-QL-COMPLETING-READ: Starts.")
|
|
||||||
(let ((table (make-hash-table :test #'equal))
|
|
||||||
(disambiguations (make-hash-table :test #'equal))
|
|
||||||
(window-width (window-width))
|
|
||||||
last-input org-outline-path-cache query-tokens)
|
|
||||||
(cl-labels (;; (debug-message
|
|
||||||
;; (f &rest args) (apply #'message (concat "ORG-QL-COMPLETING-READ: " f) args))
|
|
||||||
(action ()
|
|
||||||
(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)))
|
|
||||||
(when string
|
|
||||||
(if (string-empty-p string)
|
|
||||||
;; A heading's string can be empty, but we can't use one because it
|
|
||||||
;; wouldn't be useful to the user; and if one is found, it's very
|
|
||||||
;; likely to indicate an unnoticed mistake or corruption in the
|
|
||||||
;; file: so display a warning and don't record it as a candidate.
|
|
||||||
(display-warning 'org-ql-completing-read (format-message "Empty heading at %S" marker))
|
|
||||||
(when (gethash string table)
|
|
||||||
;; Disambiguate string (even adding the path isn't enough, because that could
|
|
||||||
;; also be duplicated).
|
|
||||||
(if-let ((suffix (gethash string disambiguations)))
|
|
||||||
(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)
|
|
||||||
(org-format-outline-path window-width nil "")
|
|
||||||
(org-split-string "")))
|
|
||||||
(formatted-path (if org-ql-completing-read-reverse-paths
|
|
||||||
(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)) " ")
|
|
||||||
""))
|
|
||||||
(affix (completions)
|
|
||||||
;; (debug-message "AFFIX:%S" completions)
|
|
||||||
(cl-loop for completion in completions
|
|
||||||
for marker = (get-text-property 0 'org-marker completion)
|
|
||||||
for prefix = (todo marker)
|
|
||||||
for suffix = (concat (funcall path marker) " " (funcall snippet marker))
|
|
||||||
collect (list completion prefix suffix)))
|
|
||||||
(annotate (candidate)
|
|
||||||
;; (debug-message "ANNOTATE:%S" candidate)
|
|
||||||
(while-no-input
|
|
||||||
;; 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
|
|
||||||
;; org-rifle-style snippets.
|
|
||||||
(or (funcall snippet (get-text-property 0 'org-marker candidate)) "")))
|
|
||||||
(group (candidate transform)
|
|
||||||
(pcase transform
|
|
||||||
(`nil (buffer-name (marker-buffer (get-text-property 0 'org-marker candidate))))
|
|
||||||
(_ candidate)))
|
|
||||||
(try (string _collection _pred point &optional _metadata)
|
|
||||||
;; (debug-message "TRY: STRING:%S" string)
|
|
||||||
(cons string point))
|
|
||||||
(all (string table pred _point)
|
|
||||||
;; (debug-message "all: STRING:%S" string)
|
|
||||||
;; (debug-message "all-completions RETURNS: %S" (all-completions string table pred))
|
|
||||||
(all-completions string table pred))
|
|
||||||
(collection (input _pred flag)
|
|
||||||
(pcase flag
|
|
||||||
('metadata (list 'metadata
|
|
||||||
(cons 'category 'org-heading)
|
|
||||||
(cons 'group-function #'group)
|
|
||||||
(cons 'affixation-function #'affix)
|
|
||||||
(cons 'annotation-function #'annotate)
|
|
||||||
(cons 'display-sort-function
|
|
||||||
(lambda (strings)
|
|
||||||
(let ((quoted-tokens (mapcar #'regexp-quote query-tokens)))
|
|
||||||
(sort strings
|
|
||||||
(lambda (a b)
|
|
||||||
(cl-labels ((matches
|
|
||||||
(s) (cl-loop for token in quoted-tokens
|
|
||||||
count (string-match-p token s))))
|
|
||||||
(> (matches a) (matches b))))))))))
|
|
||||||
(`t
|
|
||||||
;; (debug-message "COLLECTION:t INPUT:%S KEYS:%S"
|
|
||||||
;; input (hash-table-keys table))
|
|
||||||
;; It's not ideal to call `run-query' unconditionally here, but due to
|
|
||||||
;; the complexity of the "Programmed Completion" API, it's basically
|
|
||||||
;; necessary, and org-ql's caching should make it nearly free.
|
|
||||||
(run-query input)
|
|
||||||
(hash-table-keys table))
|
|
||||||
('lambda
|
|
||||||
;; (debug-message "COLLECTION:lambda INPUT:%S KEYS:%S"
|
|
||||||
;; input (hash-table-keys table))
|
|
||||||
(if (not (hash-table-empty-p table))
|
|
||||||
(when (gethash input table)
|
|
||||||
t)
|
|
||||||
(run-query input)
|
|
||||||
(when (gethash input table)
|
|
||||||
;; (debug-message "COLLECTION:lambda INPUT:%S FOUND" input)
|
|
||||||
t)))
|
|
||||||
(`nil
|
|
||||||
;; (debug-message "COLLECTION:nil INPUT:%S" input)
|
|
||||||
(if (not (hash-table-empty-p table))
|
|
||||||
(when (gethash input table)
|
|
||||||
t)
|
|
||||||
(run-query input)
|
|
||||||
;; (debug-message "COLLECTION:nil INPUT:%S KEYS:%S"
|
|
||||||
;; input (hash-table-keys table))
|
|
||||||
(cond ((hash-table-empty-p table)
|
|
||||||
nil)
|
|
||||||
((gethash input table)
|
|
||||||
t)
|
|
||||||
(t
|
|
||||||
;; FIXME: "it should return the longest common prefix
|
|
||||||
;; substring of all matches otherwise"...but there's no
|
|
||||||
;; function to compute that? At least returning an empty
|
|
||||||
;; string doesn't seem to break anything.
|
|
||||||
input))))
|
|
||||||
(`(boundaries . ,suffix)
|
|
||||||
;; (debug-message "COLLECTION:boundaries INPUT:%S SUFFIX:%S KEYS:%S"
|
|
||||||
;; input suffix (hash-table-keys table))
|
|
||||||
;; FIXME: This is unlikely to be correct, but I'm not even sure if it
|
|
||||||
;; can be correct in this case since the input (e.g. "todo: foo")
|
|
||||||
;; usually won't match a completion candidate directly.
|
|
||||||
`(boundaries 0 . ,(length suffix)))))
|
|
||||||
(run-query (input)
|
|
||||||
;; (debug-message "RUN-QUERY:%S" input)
|
|
||||||
(when query-prefix
|
|
||||||
(setf input (concat query-prefix input)))
|
|
||||||
(unless (or (string-empty-p input)
|
|
||||||
(equal last-input input))
|
|
||||||
;; (debug-message "RUN-QUERY:%S RUNNING" input)
|
|
||||||
(setf last-input input)
|
|
||||||
;; Clear hash table each time the user changes the input.
|
|
||||||
(clrhash table)
|
|
||||||
(clrhash disambiguations)
|
|
||||||
(when query-filter
|
|
||||||
(setf input (funcall query-filter input)))
|
|
||||||
(setf query-tokens
|
|
||||||
;; Remove any tokens that specify predicates or are too short.
|
|
||||||
(--select (not (or (string-match-p (rx bos (1+ (not (any ":"))) ":") it)
|
|
||||||
(< (length it) org-ql-completing-read-snippet-minimum-token-length)))
|
|
||||||
(split-string input nil t (rx blank)))
|
|
||||||
org-ql-completing-read-input-regexp
|
|
||||||
(when query-tokens
|
|
||||||
;; Limiting each context word to 15 characters prevents
|
|
||||||
;; excessively long, non-word strings from ending up in
|
|
||||||
;; snippets, which can adversely affect performance.
|
|
||||||
(rx-to-string `(seq (optional (repeat 1 3 (repeat 1 15 (not space)) (0+ space)))
|
|
||||||
bow (or ,@query-tokens) (0+ (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)
|
|
||||||
:narrow narrowp
|
|
||||||
:action #'action))))
|
|
||||||
(unless (listp buffers-files)
|
|
||||||
;; Since we map across this argument, we ensure it's a list.
|
|
||||||
(setf buffers-files (list buffers-files)))
|
|
||||||
;; NOTE: It seems that the `completing-read' machinery can call, abort, and re-call the
|
|
||||||
;; collection function while the user is typing, which can interrupt the machinery Org uses to
|
|
||||||
;; prepare an Org buffer when an Org file is loaded. This results in, e.g. the buffer being
|
|
||||||
;; left in fundamental-mode, unprepared to be used as an Org buffer, which breaks many things
|
|
||||||
;; and is very confusing for the user. Ideally, of course, we would solve this in
|
|
||||||
;; `org-ql-select', and we already attempt to, but that function is called by the
|
|
||||||
;; `completing-read' machinery, which interrupts it, so we must work around this problem by
|
|
||||||
;; ensuring all of the BUFFERS-FILES are loaded and initialized before calling
|
|
||||||
;; `completing-read'.
|
|
||||||
(mapc #'org-ql--ensure-buffer buffers-files)
|
|
||||||
(let* ((completion-styles '(org-ql-completing-read))
|
|
||||||
(completion-styles-alist (cons (list 'org-ql-completing-read #'try #'all "Org QL Find")
|
|
||||||
completion-styles-alist))
|
|
||||||
(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
|
|
||||||
;; (e.g. a heading "foo" that matches a query "todo:"), `completing-read' will not
|
|
||||||
;; select it automatically, so we return it ourselves. But note that this is not
|
|
||||||
;; necessarily correct. For example, if the user types "todo:" and gets a list of
|
|
||||||
;; completions ("foo" "bar"), and then changes the input to "ba" and presses RET
|
|
||||||
;; immediately (without getting a new list of completions), the table will include "foo"
|
|
||||||
;; and "bar", and we will return "foo"'s value rather than the first match for the query
|
|
||||||
;; "ba", because `completing-read' will not cause the COLLECTION function to run a new
|
|
||||||
;; query for the new input.
|
|
||||||
(car (hash-table-values table))
|
|
||||||
(user-error "No results for input"))))))
|
|
||||||
|
|
||||||
(defun org-ql-completing-read--snippet-simple (&optional _input-regexp)
|
|
||||||
"Return a snippet of the current entry.
|
|
||||||
Returns up to `org-ql-completing-read-snippet-length' characters."
|
|
||||||
(save-excursion
|
|
||||||
(org-end-of-meta-data t)
|
|
||||||
(unless (org-at-heading-p)
|
|
||||||
(let ((end (min (+ (point) org-ql-completing-read-snippet-length)
|
|
||||||
(org-entry-end-position))))
|
|
||||||
(concat org-ql-completing-read-snippet-prefix
|
|
||||||
(truncate-string-to-width
|
|
||||||
(replace-regexp-in-string "\n" " " (buffer-substring (point) end)
|
|
||||||
t t)
|
|
||||||
50 nil nil t))))))
|
|
||||||
|
|
||||||
(defun org-ql-completing-read--snippet-regexp (&optional input-regexp)
|
|
||||||
"Return a snippet of the current entry's matches for INPUT-REGEXP."
|
|
||||||
;; REGEXP may be nil if there are no qualifying tokens in the query.
|
|
||||||
(when input-regexp
|
|
||||||
(save-excursion
|
|
||||||
(org-end-of-meta-data t)
|
|
||||||
(unless (org-at-heading-p)
|
|
||||||
(let* ((end (org-entry-end-position))
|
|
||||||
(snippets (cl-loop while (re-search-forward input-regexp end t)
|
|
||||||
concat (match-string 0) concat "…"
|
|
||||||
do (goto-char (match-end 0)))))
|
|
||||||
(unless (string-empty-p snippets)
|
|
||||||
(concat org-ql-completing-read-snippet-prefix
|
|
||||||
(replace-regexp-in-string (rx (1+ "\n")) " " snippets t t))))))))
|
|
||||||
|
|
||||||
;;;; Footer
|
|
||||||
|
|
||||||
(provide 'org-ql-completing-read)
|
|
||||||
|
|
||||||
;;; org-ql-completing-read.el ends here
|
|
||||||
233
org-ql-find.el
|
|
@ -1,233 +0,0 @@
|
||||||
;;; org-ql-find.el --- Find headings with completion using org-ql -*- lexical-binding: t; -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2022-2023 Adam Porter
|
|
||||||
|
|
||||||
;; Author: Adam Porter <adam@alphapapa.net>
|
|
||||||
|
|
||||||
;; 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
|
|
||||||
;; the Free Software Foundation, either version 3 of the License, or
|
|
||||||
;; (at your option) any later version.
|
|
||||||
|
|
||||||
;; This program is distributed in the hope that it will be useful,
|
|
||||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
;; GNU General Public License for more details.
|
|
||||||
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library provides a way to quickly find and go to Org entries
|
|
||||||
;; selected with Emacs's built-in completions API (so it works with
|
|
||||||
;; packages that extend it, like Vertico, Marginalia, etc). It works
|
|
||||||
;; like `helm-org-ql' but does not require Helm.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(require 'cl-lib)
|
|
||||||
|
|
||||||
(require 'org)
|
|
||||||
(require 'org-ql)
|
|
||||||
(require 'org-ql-search)
|
|
||||||
(require 'org-ql-completing-read)
|
|
||||||
|
|
||||||
(declare-function org-ql--normalize-query "org-ql" t t)
|
|
||||||
|
|
||||||
;;;; Customization
|
|
||||||
|
|
||||||
(defgroup org-ql-find nil
|
|
||||||
"Options for `org-ql-find'."
|
|
||||||
:group 'org-ql)
|
|
||||||
|
|
||||||
(defcustom org-ql-find-goto-hook '(org-show-entry org-reveal)
|
|
||||||
"Functions called when selecting an entry."
|
|
||||||
;; TODO: Add common choices, including `org-tree-to-indirect-buffer'.
|
|
||||||
:type 'hook)
|
|
||||||
|
|
||||||
(defcustom org-ql-find-display-buffer-action '(display-buffer-same-window)
|
|
||||||
"Display buffer action list for `org-ql-find'.
|
|
||||||
See function `display-buffer'."
|
|
||||||
:type 'sexp)
|
|
||||||
|
|
||||||
;;;; Commands
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(cl-defun org-ql-find (buffers-files &key query-prefix query-filter widen
|
|
||||||
(prompt "Find entry: "))
|
|
||||||
"Go to an Org entry in BUFFERS-FILES selected by searching entries with `org-ql'.
|
|
||||||
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 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
|
|
||||||
\"heading:\" to only search headings, easily creating a custom
|
|
||||||
command that saves the user from having to type it).
|
|
||||||
|
|
||||||
QUERY-FILTER may be a function through which the query the user
|
|
||||||
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 (org-ql-find--buffers
|
|
||||||
:read-buffer-p (equal '(16) current-prefix-arg))
|
|
||||||
: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-filter query-filter
|
|
||||||
:prompt prompt))))
|
|
||||||
(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)
|
|
||||||
"Refile current entry to MARKER (interactively, one selected with `org-ql').
|
|
||||||
Interactive completion uses files listed in `org-refile-targets',
|
|
||||||
which see (but only the files are used)."
|
|
||||||
(interactive (let ((buffers-files (delete-dups
|
|
||||||
;; Always include the current buffer.
|
|
||||||
(cons (current-buffer)
|
|
||||||
(cl-loop for (files-spec . _candidate-spec) in org-refile-targets
|
|
||||||
append (cl-typecase files-spec
|
|
||||||
(null (list (current-buffer)))
|
|
||||||
(symbol (pcase (funcall files-spec)
|
|
||||||
((and (pred stringp) file) (list file))
|
|
||||||
((and (pred listp) files) files)))
|
|
||||||
(list files-spec)))))))
|
|
||||||
(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
|
|
||||||
;; The RFLOC argument:
|
|
||||||
(list
|
|
||||||
;; Name
|
|
||||||
(org-with-point-at marker
|
|
||||||
(nth 4 (org-heading-components)))
|
|
||||||
;; File
|
|
||||||
(buffer-file-name buffer)
|
|
||||||
;; nil
|
|
||||||
nil
|
|
||||||
;; Position
|
|
||||||
marker))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun org-ql-find-in-agenda ()
|
|
||||||
"Call `org-ql-find' on `org-agenda-files'."
|
|
||||||
(interactive)
|
|
||||||
(org-ql-find (org-agenda-files)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun org-ql-find-in-org-directory ()
|
|
||||||
"Call `org-ql-find' on files in `org-directory'."
|
|
||||||
(interactive)
|
|
||||||
(org-ql-find (org-ql-search-directories-files)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(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 buffers-files)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(cl-defun org-ql-open-link (buffers-files &key query-prefix query-filter
|
|
||||||
(prompt "Open link: "))
|
|
||||||
"Open a link selected with `org-ql-completing-read'.
|
|
||||||
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.
|
|
||||||
|
|
||||||
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
|
|
||||||
:prompt prompt
|
|
||||||
:action-filter #'identity
|
|
||||||
:action (lambda ()
|
|
||||||
(save-excursion
|
|
||||||
(cl-loop with limit = (org-entry-end-position)
|
|
||||||
while (re-search-forward org-link-any-re limit t)
|
|
||||||
for link = (string-trim (match-string 0))
|
|
||||||
do (progn
|
|
||||||
(set-text-properties 0 (length link) '(face org-link) link)
|
|
||||||
(setf link (org-link-display-format link)))
|
|
||||||
collect (cons link (copy-marker (match-beginning 0))))))
|
|
||||||
:snippet (lambda (&rest _)
|
|
||||||
"")
|
|
||||||
:path (lambda (marker)
|
|
||||||
(org-with-point-at marker
|
|
||||||
(let* ((path (thread-first (org-get-outline-path t t)
|
|
||||||
(org-format-outline-path (window-width) nil "")
|
|
||||||
(org-split-string "")))
|
|
||||||
(formatted-path (if org-ql-completing-read-reverse-paths
|
|
||||||
(concat "\\" (string-join (reverse path) "\\"))
|
|
||||||
(concat "/" (string-join path "/")))))
|
|
||||||
formatted-path))))))
|
|
||||||
(org-with-point-at marker
|
|
||||||
(org-open-at-point))))
|
|
||||||
|
|
||||||
;;;; Functions
|
|
||||||
|
|
||||||
(cl-defun org-ql-find--buffers (&key read-buffer-p)
|
|
||||||
"Return buffer or 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. If
|
|
||||||
READ-BUFFER-P, read a list of buffers in `org-mode' with
|
|
||||||
completion. To be used in `org-ql-find' commands' interactive
|
|
||||||
forms."
|
|
||||||
(if read-buffer-p
|
|
||||||
(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
|
|
||||||
432
org-ql-search.el
|
|
@ -1,14 +1,13 @@
|
||||||
;;; org-ql-search.el --- Search commands for org-ql -*- lexical-binding: t; -*-
|
;;; org-ql-search.el --- Search commands for org-ql -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
;; Copyright (C) 2019-2023 Adam Porter
|
|
||||||
|
|
||||||
;; 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
|
||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
|
|
||||||
;; This library is part of the package `org-ql'; it's not a standalone
|
;; This library is part of the package `org-ql'; it's not a standalone
|
||||||
;; library. It implements search commands for Org buffers.
|
;; library. It displays buffers similar to Org Agenda buffers, based
|
||||||
|
;; on `org-ql' queries.
|
||||||
|
|
||||||
;;; License:
|
;;; License:
|
||||||
|
|
||||||
|
|
@ -27,131 +26,37 @@
|
||||||
|
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
;;;; Requirements
|
|
||||||
|
|
||||||
(require 'cl-lib)
|
(require 'cl-lib)
|
||||||
|
|
||||||
(require 'dash)
|
(require 'dash)
|
||||||
(require 'f)
|
|
||||||
(require 'map)
|
|
||||||
(require 'org-super-agenda)
|
|
||||||
(require 's)
|
(require 's)
|
||||||
|
|
||||||
(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
|
|
||||||
|
|
||||||
(defalias 'org-ql-search--link-heading-search-string
|
|
||||||
(cond ((fboundp 'org-link--normalize-string) #'org-link--normalize-string)
|
|
||||||
((fboundp 'org-link-heading-search-string) #'org-link-heading-search-string)
|
|
||||||
((fboundp 'org-make-org-heading-search-string) #'org-make-org-heading-search-string)
|
|
||||||
(t (error "org-ql: Unable to define alias `org-ql-search--link-heading-search-string'. This may affect links in dynamic blocks. Please report this as a bug"))))
|
|
||||||
|
|
||||||
(defalias 'org-ql-search--org-make-link-string
|
|
||||||
(cond ((fboundp 'org-link-make-string) #'org-link-make-string)
|
|
||||||
((fboundp 'org-make-link-string) #'org-make-link-string)
|
|
||||||
(t (error "org-ql: Unable to define alias `org-ql-search--org-make-link-string'. Please report this as a bug"))))
|
|
||||||
|
|
||||||
(defalias 'org-ql-search--org-link-store-props
|
|
||||||
(cond ((fboundp 'org-link-store-props) #'org-link-store-props)
|
|
||||||
((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
|
;;;; Variables
|
||||||
|
|
||||||
(defvar org-ql-block-header nil
|
(defvar org-ql-views)
|
||||||
"Optional string overriding default header in `org-ql-block' agenda blocks.")
|
|
||||||
|
|
||||||
;;;; Customization
|
;; From `org-super-agenda'.
|
||||||
|
(defvar org-super-agenda-mode)
|
||||||
|
(defvar org-super-agenda-groups)
|
||||||
|
(defvar org-super-agenda-auto-selector-keywords)
|
||||||
|
(declare-function org-super-agenda--group-items "ext:org-super-agenda")
|
||||||
|
|
||||||
(defgroup org-ql-search nil
|
;; For refreshing results buffers.
|
||||||
"Options for `org-ql-search' commands."
|
(defvar org-ql-view-buffers-files)
|
||||||
:group 'org-ql)
|
(defvar org-ql-view-query)
|
||||||
|
(defvar org-ql-view-sort)
|
||||||
(defcustom org-ql-search-directories-files-regexp "\.org$"
|
(defvar org-ql-view-narrow)
|
||||||
"Regular expression to match Org filenames in `org-directory'.
|
(defvar org-ql-view-super-groups)
|
||||||
Files matching this regexp will be searched. By default,
|
(defvar org-ql-view-title)
|
||||||
\".org\" files are matched, but you may also select to include
|
|
||||||
\".org_archive\" files, or use a custom regexp."
|
|
||||||
:type '(radio (const :tag "Normal \".org\" files" :value "\.org$")
|
|
||||||
(const :tag "Also include \".org_archive\" files" "\.org\\(_archive\\)?$")
|
|
||||||
(string :tag "Custom regular expression")))
|
|
||||||
|
|
||||||
(defcustom org-ql-search-directories-files-recursive nil
|
|
||||||
"Recurse into subdirectories by default in `org-ql-search-directories-files'.
|
|
||||||
This should probably be disabled by default, because
|
|
||||||
e.g. `org-directory' may include deeply nested directories of
|
|
||||||
non-Org files, such as a \".git\" directory, Org attachments
|
|
||||||
directories, etc, which would make it slow to list the
|
|
||||||
`org-directory' files recursively."
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
;;;; Commands
|
;;;; Commands
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(cl-defun org-ql-sparse-tree (query &key keep-previous (buffer (current-buffer)))
|
(cl-defun org-ql-search (buffers-files query &key buffer narrow super-groups sort title)
|
||||||
"Show a sparse tree for QUERY in BUFFER and return number of results.
|
"Read QUERY and search with `org-ql'.
|
||||||
The tree will show the lines where the query matches, and any
|
|
||||||
other context defined in `org-show-context-detail', which see.
|
|
||||||
|
|
||||||
QUERY is an `org-ql' query in either sexp or string form (see
|
|
||||||
Info node `(org-ql)Queries').
|
|
||||||
|
|
||||||
When KEEP-PREVIOUS is non-nil (interactively, with prefix), the
|
|
||||||
outline is not reset to the overview state before finding
|
|
||||||
matches, which allows stacking calls to this command.
|
|
||||||
|
|
||||||
Runs `org-occur-hook' after making the sparse tree."
|
|
||||||
;; Code based on `org-occur'.
|
|
||||||
(interactive (list (read-string "Query: ")
|
|
||||||
:keep-previous current-prefix-arg))
|
|
||||||
(with-current-buffer buffer
|
|
||||||
(unless keep-previous
|
|
||||||
;; We don't do highlighting, because queries aren't regexps, but
|
|
||||||
;; we remove existing `org-occur' highlights, just in case.
|
|
||||||
(org-remove-occur-highlights nil nil t)
|
|
||||||
(org-overview))
|
|
||||||
(let ((num-results 0)
|
|
||||||
(query (pcase-exhaustive query
|
|
||||||
((and (pred stringp)
|
|
||||||
(rx bos (0+ blank) (or "(" "\"")))
|
|
||||||
;; Read sexp query from string.
|
|
||||||
(read query))
|
|
||||||
((pred stringp)
|
|
||||||
;; Parse string query into sexp query.
|
|
||||||
(org-ql--query-string-to-sexp query))
|
|
||||||
((pred listp)
|
|
||||||
;; Sexp query.
|
|
||||||
query))))
|
|
||||||
(org-ql-select buffer query
|
|
||||||
:action (lambda ()
|
|
||||||
(org-ql--org-show-context 'occur-tree)
|
|
||||||
(cl-incf num-results)))
|
|
||||||
(unless org-sparse-tree-open-archived-trees
|
|
||||||
(org-ql--org-hide-archived-subtrees (point-min) (point-max)))
|
|
||||||
(run-hooks 'org-occur-hook)
|
|
||||||
(unless (get-buffer-window buffer)
|
|
||||||
(pop-to-buffer buffer))
|
|
||||||
(message "%d matches" num-results)
|
|
||||||
num-results)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(cl-defun org-ql-search (buffers-files query &key narrow super-groups sort title
|
|
||||||
(buffer org-ql-view-buffer))
|
|
||||||
"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.
|
BUFFERS-FILES: A list of buffers and/or files to search.
|
||||||
|
|
@ -160,56 +65,56 @@ Interactively, may 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'
|
- An expression which evaluates to a list of files/buffers
|
||||||
- A space-separated list of file or buffer names
|
- A space-separated list of file or buffer names
|
||||||
|
|
||||||
QUERY: An `org-ql' query in either sexp or non-sexp form (see
|
|
||||||
Info node `(org-ql)Queries').
|
|
||||||
|
|
||||||
SUPER-GROUPS: An `org-super-agenda' group set. See variable
|
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'.
|
||||||
selectors'.
|
|
||||||
|
|
||||||
NARROW: When non-nil, don't widen buffers before
|
NARROW: When non-nil, don't widen buffers before
|
||||||
searching. Interactively, with prefix, leave narrowed.
|
searching. Interactively, with prefix, leave narrowed.
|
||||||
|
|
||||||
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'.
|
||||||
|
|
||||||
TITLE: An optional string displayed in the header.
|
TITLE: An optional string displayed in the header.
|
||||||
|
|
||||||
BUFFER: Optionally, a buffer or name of a buffer in which to
|
BUFFER: Optionally, a buffer or name of a buffer in which to
|
||||||
display the results. By default, the value of
|
display the results. Set automatically when nil."
|
||||||
`org-ql-view-buffer' is used, and a new buffer is created if
|
|
||||||
necessary."
|
|
||||||
(declare (indent defun))
|
(declare (indent defun))
|
||||||
(interactive (list (org-ql-view--complete-buffers-files)
|
(interactive (list (pcase-exhaustive (completing-read "Buffers/Files: "
|
||||||
(read-string "Query: " (when org-ql-view-query
|
(list 'buffer 'agenda 'all))
|
||||||
(format "%S" org-ql-view-query)))
|
("agenda" (org-agenda-files))
|
||||||
:narrow (or org-ql-view-narrow (equal current-prefix-arg '(4)))
|
("all" (--select (equal (buffer-local-value 'major-mode it) 'org-mode)
|
||||||
:super-groups (org-ql-view--complete-super-groups)
|
(buffer-list)))
|
||||||
:sort (org-ql-view--complete-sort)))
|
("buffer" (current-buffer))
|
||||||
;; NOTE: Using `with-temp-buffer' is a hack to work around the fact that `make-local-variable'
|
((and form (guard (rx bos "("))) (-flatten (eval (read form))))
|
||||||
;; does not work reliably from inside a `let' form when the target buffer is current on entry
|
(else (s-split (rx (1+ space)) else)))
|
||||||
;; to or exit from the `let', even though `make-local-variable' is actually done in
|
(read-minibuffer "Query: ")
|
||||||
;; `org-ql-view--display'. So we do all this within a temp buffer, which works around it.
|
:narrow (eq current-prefix-arg '(4))
|
||||||
(with-temp-buffer
|
:super-groups (when (bound-and-true-p org-super-agenda-auto-selector-keywords)
|
||||||
(let* ((query (cl-etypecase query
|
(pcase (completing-read "Group by: "
|
||||||
(string (if (or (string-prefix-p "(" query)
|
(append (list "Don't group"
|
||||||
(string-prefix-p "\"" query))
|
"Global super-groups")
|
||||||
;; Read sexp query.
|
(cl-loop for type in org-super-agenda-auto-selector-keywords
|
||||||
(read query)
|
collect (substring (symbol-name type) 6))))
|
||||||
;; Parse non-sexp query into sexp query.
|
("Global super-groups" org-super-agenda-groups)
|
||||||
(org-ql--query-string-to-sexp query)))
|
("Don't group" nil)
|
||||||
(list query)))
|
(property (list (list (intern (concat ":auto-" property)))))))
|
||||||
(results (org-ql-select buffers-files query
|
:sort (pcase (completing-read "Sort by: "
|
||||||
|
(list "Don't sort"
|
||||||
|
"date"
|
||||||
|
"deadline"
|
||||||
|
"priority"
|
||||||
|
"scheduled"
|
||||||
|
"todo"))
|
||||||
|
("Don't sort" nil)
|
||||||
|
(sort (intern sort)))))
|
||||||
|
(let* ((results (org-ql-select buffers-files 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))))
|
|
||||||
(header (org-ql-view--header-line-format
|
|
||||||
:buffers-files buffers-files :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 buffers-files)
|
||||||
(org-ql-view-query query)
|
(org-ql-view-query query)
|
||||||
|
|
@ -218,207 +123,78 @@ necessary."
|
||||||
(org-ql-view-super-groups super-groups)
|
(org-ql-view-super-groups super-groups)
|
||||||
(org-ql-view-title title))
|
(org-ql-view-title title))
|
||||||
(when super-groups
|
(when super-groups
|
||||||
(let ((org-super-agenda-groups (cl-etypecase super-groups
|
(setf strings (org-super-agenda--group-items strings)))
|
||||||
(symbol (symbol-value super-groups))
|
(org-ql-view--display
|
||||||
(list super-groups))))
|
:buffer (or buffer
|
||||||
(setf strings (org-super-agenda--group-items strings))))
|
(format "*Org QL Search: %s*"
|
||||||
(org-ql-view--display :buffer buffer :header header :strings strings))))
|
(or title
|
||||||
|
(format "%S in %S" query buffers-files))))
|
||||||
|
:header (org-ql-view--header-line-format buffers-files query title)
|
||||||
|
:string (s-join "\n" strings))))
|
||||||
|
|
||||||
;;;###autoload
|
(defun org-ql-search-refresh ()
|
||||||
(defun org-ql-search-block (args)
|
"Refresh current `org-ql-search' buffer."
|
||||||
"Insert items for ARGS into current buffer.
|
(interactive)
|
||||||
Intended to be used as a user-defined function in
|
(let ((old-pos (point)))
|
||||||
`org-agenda-custom-commands'. ARGS corresponds to the `match'
|
(org-ql-search org-ql-view-buffers-files
|
||||||
item in the custom command form. It should be a list of
|
org-ql-view-query
|
||||||
arguments which may be applied to `org-ql-select', which see, but
|
:sort org-ql-view-sort
|
||||||
not including its BUFFERS-FILES argument (which is supplied
|
:narrow org-ql-view-narrow
|
||||||
through the Agenda). An additional `:header' keyword argument
|
:super-groups org-ql-view-super-groups
|
||||||
may be supplied as a string, like that supplied to
|
:title org-ql-view-title
|
||||||
`org-ql-view--display'.
|
:buffer (current-buffer))
|
||||||
|
(goto-char old-pos)))
|
||||||
|
|
||||||
Like other agenda block commands, it searches files returned by
|
(defun org-ql-search-save ()
|
||||||
function `org-agenda-files'. Inserts a newline after the block.
|
"Save current `org-ql-search' buffer to `org-ql-views'."
|
||||||
|
(interactive)
|
||||||
|
(let* ((name (read-string "Save view as: "))
|
||||||
|
(buffers-files-sexp (cl-etypecase org-ql-view-buffers-files
|
||||||
|
(string org-ql-view-buffers-files)
|
||||||
|
(list `(list ,@org-ql-view-buffers-files))
|
||||||
|
(null nil)))
|
||||||
|
(function `(lambda ()
|
||||||
|
(interactive)
|
||||||
|
(org-ql-search ,buffers-files-sexp
|
||||||
|
',org-ql-view-query
|
||||||
|
:sort ',org-ql-view-sort
|
||||||
|
:narrow ,org-ql-view-narrow
|
||||||
|
:groups ',org-ql-view-super-groups
|
||||||
|
:title ,name))))
|
||||||
|
(map-put org-ql-views name function #'equal)
|
||||||
|
(customize-set-variable 'org-ql-views org-ql-views)
|
||||||
|
(customize-mark-to-save 'org-ql-views)))
|
||||||
|
|
||||||
If `org-ql-block-header' is non-nil, it is used as the header
|
(defun org-ql-search-block (query)
|
||||||
string for the block, otherwise the header is formed
|
"Insert items for QUERY into current buffer.
|
||||||
automatically from the query."
|
QUERY should be an `org-ql' query form. Like other agenda block
|
||||||
(pcase-let ((`(,query . ,(map :header :sort)) args)
|
commands, it searches files returned by function
|
||||||
(narrow-p) (old-beg) (old-end))
|
`org-agenda-files'. Intended to be used as a user-defined
|
||||||
(when-let* ((from (pcase org-agenda-restrict
|
function in `org-agenda-custom-commands'. QUERY corresponds to
|
||||||
('nil (org-agenda-files nil 'ifmode))
|
the `match' item in the custom command form. Inserts a newline
|
||||||
(_ (prog1 org-agenda-restrict
|
after the block."
|
||||||
(with-current-buffer org-agenda-restrict
|
(when-let* ((from (org-agenda-files nil 'ifmode))
|
||||||
;; Narrow the buffer; remember to widen it later.
|
(items (org-ql-select from
|
||||||
(setf old-beg (point-min) old-end (point-max)
|
query :action 'element-with-markers)))
|
||||||
narrow-p t)
|
|
||||||
(narrow-to-region org-agenda-restrict-begin org-agenda-restrict-end))))))
|
|
||||||
(items (org-ql-select from query
|
|
||||||
:action 'element-with-markers
|
|
||||||
:narrow narrow-p :sort sort)))
|
|
||||||
(when narrow-p
|
|
||||||
;; Restore buffer's previous restrictions.
|
|
||||||
(with-current-buffer from
|
|
||||||
(narrow-to-region old-beg old-end)))
|
|
||||||
;; Not sure if calling the prepare function is necessary, but let's follow the pattern.
|
;; Not sure if calling the prepare function is necessary, but let's follow the pattern.
|
||||||
(org-agenda-prepare)
|
(org-agenda-prepare)
|
||||||
;; 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 (org-ql-search--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 (org-ql-view--header-line-format from query)
|
||||||
(insert (org-add-props (or org-ql-block-header header
|
|
||||||
(org-ql-view--header-line-format
|
|
||||||
: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
|
||||||
(defalias 'org-ql-block 'org-ql-search-block)
|
(defalias 'org-ql-block 'org-ql-search-block)
|
||||||
|
|
||||||
;;;; Dynamic blocks
|
|
||||||
|
|
||||||
;; This section implements support for Org dynamic blocks. See Info node `(org)Dynamic blocks'.
|
|
||||||
|
|
||||||
(require 'org-table)
|
|
||||||
|
|
||||||
(cl-defun org-dblock-write:org-ql (params)
|
|
||||||
"Insert content for org-ql dynamic block at point according to PARAMS.
|
|
||||||
Valid parameters include:
|
|
||||||
|
|
||||||
:query An Org QL query expression in either sexp or string
|
|
||||||
form.
|
|
||||||
|
|
||||||
:columns A list of columns, including `heading', `todo',
|
|
||||||
`property',`priority',`deadline',`scheduled',`closed'.
|
|
||||||
Each column may also be specified as a list with the
|
|
||||||
second element being a header string. For example,
|
|
||||||
to abbreviate the priority column: (priority \"P\").
|
|
||||||
For certain columns, like `property', arguments may
|
|
||||||
be passed by specifying the column type itself as a
|
|
||||||
list. For example, to display a column showing the
|
|
||||||
values of a property named \"milestone\", with the
|
|
||||||
header being abbreviated to \"M\":
|
|
||||||
|
|
||||||
((property \"milestone\") \"M\").
|
|
||||||
|
|
||||||
:sort One or a list of Org QL sorting methods
|
|
||||||
(see `org-ql-select').
|
|
||||||
|
|
||||||
:take Optionally take a number of results from the front (a
|
|
||||||
positive number) or the end (a negative number) of
|
|
||||||
the results.
|
|
||||||
|
|
||||||
:ts-format Optional format string used to format
|
|
||||||
timestamp-based columns.
|
|
||||||
|
|
||||||
For example, an org-ql dynamic block header could look like
|
|
||||||
this (must be a single line in the Org buffer):
|
|
||||||
|
|
||||||
#+BEGIN: org-ql :query (todo \"UNDERWAY\")
|
|
||||||
:columns (priority todo heading) :sort (priority date)
|
|
||||||
:ts-format \"%Y-%m-%d %H:%M\""
|
|
||||||
(-let* (((&plist :query :columns :sort :ts-format :take) params)
|
|
||||||
(query (cl-etypecase query
|
|
||||||
(string (org-ql--query-string-to-sexp query))
|
|
||||||
(list ;; SAFETY: Query is in sexp form: ask for confirmation, because it could contain arbitrary code.
|
|
||||||
(org-ql--ask-unsafe-query query)
|
|
||||||
query)))
|
|
||||||
(columns (or columns '(heading todo (priority "P"))))
|
|
||||||
;; MAYBE: Custom column functions.
|
|
||||||
(format-fns
|
|
||||||
;; NOTE: Backquoting this alist prevents the lambdas from seeing
|
|
||||||
;; the variable `ts-format', so we use `list' and `cons'.
|
|
||||||
(list (cons 'todo (lambda (element)
|
|
||||||
(org-element-property :todo-keyword element)))
|
|
||||||
(cons 'heading (lambda (element)
|
|
||||||
(let ((normalized-heading
|
|
||||||
(org-ql-search--link-heading-search-string (org-element-property :raw-value element))))
|
|
||||||
(org-ql-search--org-make-link-string normalized-heading (org-link-display-format normalized-heading)))))
|
|
||||||
(cons 'priority (lambda (element)
|
|
||||||
(--when-let (org-element-property :priority element)
|
|
||||||
(char-to-string it))))
|
|
||||||
(cons 'deadline (lambda (element)
|
|
||||||
(--when-let (org-element-property :deadline element)
|
|
||||||
(ts-format ts-format (ts-parse-org-element it)))))
|
|
||||||
(cons 'scheduled (lambda (element)
|
|
||||||
(--when-let (org-element-property :scheduled element)
|
|
||||||
(ts-format ts-format (ts-parse-org-element it)))))
|
|
||||||
(cons 'closed (lambda (element)
|
|
||||||
(--when-let (org-element-property :closed element)
|
|
||||||
(ts-format ts-format (ts-parse-org-element it)))))
|
|
||||||
(cons 'property (lambda (element property)
|
|
||||||
(org-element-property (intern (concat ":" (upcase property))) element)))))
|
|
||||||
(elements (org-ql-query :from (current-buffer)
|
|
||||||
:where query
|
|
||||||
:select '(org-ql-view--resolve-element-properties
|
|
||||||
(org-element-headline-parser (line-end-position)))
|
|
||||||
:order-by sort)))
|
|
||||||
(when take
|
|
||||||
(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)))
|
|
||||||
""))
|
|
||||||
" | ")))
|
|
||||||
;; Table header
|
|
||||||
(insert "| " (string-join (--map (pcase it
|
|
||||||
((pred symbolp) (capitalize (symbol-name it)))
|
|
||||||
(`(,_ ,name) name))
|
|
||||||
columns)
|
|
||||||
" | ")
|
|
||||||
" |" "\n")
|
|
||||||
(insert "|- \n") ; Separator hline
|
|
||||||
(dolist (element elements)
|
|
||||||
(insert "| " (format-element element) " |" "\n"))
|
|
||||||
(delete-char -1)
|
|
||||||
(org-table-align))))
|
|
||||||
|
|
||||||
;;;; Functions
|
|
||||||
|
|
||||||
(defvar org-ql-search-directories-files-error
|
|
||||||
;; Workaround to silence byte-compiler which thinks having this string in an
|
|
||||||
;; argument's default value form is a too-long docstring.
|
|
||||||
"No DIRECTORIES given, and `org-directory' doesn't exist")
|
|
||||||
|
|
||||||
(cl-defun org-ql-search-directories-files
|
|
||||||
(&key (directories
|
|
||||||
(if (file-exists-p org-directory)
|
|
||||||
(list org-directory)
|
|
||||||
(user-error org-ql-search-directories-files-error)))
|
|
||||||
(recurse org-ql-search-directories-files-recursive)
|
|
||||||
(regexp org-ql-search-directories-files-regexp))
|
|
||||||
"Return list of matching files in DIRECTORIES.
|
|
||||||
When RECURSE is non-nil, recurse into subdirectories. When
|
|
||||||
REGEXP is non-nil, only return files that match REGEXP."
|
|
||||||
(let ((files (->> directories
|
|
||||||
(--map (f-files it nil recurse))
|
|
||||||
-flatten)))
|
|
||||||
(if regexp
|
|
||||||
(--select (string-match regexp it)
|
|
||||||
files)
|
|
||||||
files)))
|
|
||||||
|
|
||||||
;;;; Footer
|
;;;; Footer
|
||||||
|
|
||||||
(provide 'org-ql-search)
|
(provide 'org-ql-search)
|
||||||
|
|
|
||||||
980
org-ql-view.el
2230
org-ql.info
|
|
@ -1,16 +0,0 @@
|
||||||
# This file is currently used to test org-file-tags.
|
|
||||||
|
|
||||||
#+FILETAGS: :food:
|
|
||||||
|
|
||||||
* Fruit :fruit:
|
|
||||||
|
|
||||||
** Blueberry
|
|
||||||
|
|
||||||
** Strawberry
|
|
||||||
|
|
||||||
* Vegetable :vegetable:
|
|
||||||
|
|
||||||
** Broccoli
|
|
||||||
|
|
||||||
** Potato
|
|
||||||
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
* Alpha
|
|
||||||
|
|
||||||
Let us link to: [[id:74d357ac-fb9c-40d1-a63f-eca8a227321d][Bravo [a phrase in brackets]]].
|
|
||||||
|
|
||||||
* Bravo [a phrase in brackets]
|
|
||||||
:PROPERTIES:
|
|
||||||
:ID: 74d357ac-fb9c-40d1-a63f-eca8a227321d
|
|
||||||
:END:
|
|
||||||
|
|
||||||
* Charlie
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
#+title: org-ql test data for ~src~ predicate
|
|
||||||
|
|
||||||
* Alpha
|
|
||||||
|
|
||||||
#+begin_src elisp
|
|
||||||
(message "foo")
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
#+begin_src python
|
|
||||||
print("foo")
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
#+begin_src js
|
|
||||||
console.log("foo")
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
* Bravo
|
|
||||||
|
|
||||||
#+begin_src elisp
|
|
||||||
(message "bar")
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
#+begin_src python
|
|
||||||
print("bar")
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
* Charlie
|
|
||||||
|
|
||||||
This entry has no source block.
|
|
||||||
|
|
@ -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./
|
|
||||||
|
|
||||||
492
tests/data.org
|
|
@ -1,51 +1,55 @@
|
||||||
#+TODO: TODO TODAY NEXT STARTED IN-PROGRESS UNDERWAY WAITING SOMEDAY MAYBE CHECK | DONE CANCELED
|
#+TODO: TODO TODAY NEXT STARTED IN-PROGRESS UNDERWAY WAITING SOMEDAY MAYBE CHECK | DONE CANCELED
|
||||||
|
|
||||||
# Will try to open the agenda view as if it was [2017-07-05 Wed]
|
* Test data
|
||||||
|
|
||||||
* TODO [#A] Take over the universe :universe:ambition:
|
Rather than using my personal agenda every time I want to take a screenshot, how about this.
|
||||||
|
|
||||||
|
Will try to open the agenda view as if it was [2017-07-05 Wed]
|
||||||
|
|
||||||
|
** TODO [#A] Take over the universe :universe:ambition:
|
||||||
DEADLINE: <2017-07-15 Sat -1m>
|
DEADLINE: <2017-07-15 Sat -1m>
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:agenda-group: plans
|
:agenda-group: plans
|
||||||
:CATEGORY: ambition
|
:CATEGORY: ambition
|
||||||
:END:
|
:END:
|
||||||
|
|
||||||
** TODO [#A] Take over the world :world:
|
*** TODO [#A] Take over the world :world:
|
||||||
DEADLINE: <2017-07-07 Fri>
|
DEADLINE: <2017-07-07 Fri>
|
||||||
|
|
||||||
I'd like to be finished with this before the weekend...
|
I'd like to be finished with this before the weekend...
|
||||||
|
|
||||||
*** TODO [#A] Skype with president of Antarctica :world:meetings:
|
**** TODO [#A] Skype with president of Antarctica :world:meetings:
|
||||||
SCHEDULED: <2017-07-04 Tue 21:00>
|
SCHEDULED: <2017-07-04 Tue 21:00>
|
||||||
|
|
||||||
Not sure what his timezone is...
|
Not sure what his timezone is...
|
||||||
|
|
||||||
** TODO [#B] Take over Mars
|
*** TODO [#B] Take over Mars
|
||||||
|
|
||||||
*** TODO Visit Mars :space:travel:planet:
|
**** TODO Visit Mars :space:travel:planet:
|
||||||
DEADLINE: <2017-09-20 Wed -3m>
|
DEADLINE: <2017-09-20 Wed -3m>
|
||||||
|
|
||||||
Ah, the red planet...
|
Ah, the red planet...
|
||||||
|
|
||||||
** TODO [#C] Take over the moon
|
*** TODO [#C] Take over the moon
|
||||||
|
|
||||||
*** WAITING Visit the moon :space:travel:
|
**** WAITING Visit the moon :space:travel:
|
||||||
DEADLINE: <2017-08-27 Sun -2m>
|
DEADLINE: <2017-08-27 Sun -2m>
|
||||||
:LOGBOOK:
|
:LOGBOOK:
|
||||||
- State "WAITING" from [2017-07-24 Mon 19:01]
|
- State "WAITING" from [2017-07-24 Mon 19:01]
|
||||||
:END:
|
:END:
|
||||||
|
|
||||||
Just waiting on that callback from NASA...
|
Just waiting on that callback from NASA...
|
||||||
|
|
||||||
** TODO Practice leaping tall buildings in a single bound :personal:
|
*** TODO Practice leaping tall buildings in a single bound :personal:
|
||||||
SCHEDULED: <2017-07-05 Wed .+2d/3d>
|
SCHEDULED: <2017-07-05 Wed +2d>
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:STYLE: habit
|
:STYLE: habit
|
||||||
:END:
|
:END:
|
||||||
|
|
||||||
** TODO [#B] Renew membership in supervillain club
|
*** TODO [#B] Renew membership in supervillain club
|
||||||
DEADLINE: <2017-07-10 Mon 23:59 -1w>
|
DEADLINE: <2017-07-10 Mon -1w>
|
||||||
|
|
||||||
** DONE [#B] Learn universal sign language
|
*** DONE [#B] Learn universal sign language
|
||||||
CLOSED: [2017-07-05 Wed 03:02]
|
CLOSED: [2017-07-05 Wed 03:02]
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:ID: 729de245-75fa-43b4-845a-57af61109485
|
:ID: 729de245-75fa-43b4-845a-57af61109485
|
||||||
|
|
@ -56,71 +60,469 @@ CLOSED: [2017-07-05 Wed 03:02]
|
||||||
CLOCK: [2017-07-05 Wed 02:00]--[2017-07-05 Wed 03:02] => 1:02
|
CLOCK: [2017-07-05 Wed 02:00]--[2017-07-05 Wed 03:02] => 1:02
|
||||||
:END:
|
:END:
|
||||||
|
|
||||||
* TODO Order a pizza :food:dinner:
|
** TODO Order a pizza :food:dinner:
|
||||||
SCHEDULED: <2017-07-05 Wed 18:00>
|
SCHEDULED: <2017-07-05 Wed 18:00>
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:Effort: 5
|
:Effort: 5
|
||||||
:END:
|
:END:
|
||||||
|
|
||||||
* TODO [#C] Get haircut :personal:@town:
|
** TODO [#C] Get haircut :personal:@town:
|
||||||
SCHEDULED: <2017-07-05 Wed>
|
SCHEDULED: <2017-07-05 Wed>
|
||||||
|
|
||||||
Should probably do this before I take over the world. Want to look my best. (Not that it will matter once I'm in charge.)
|
Should probably do this before I take over the world. Want to look my best. (Not that it will matter once I'm in charge.)
|
||||||
|
|
||||||
* TODO [#B] Internet :bills:
|
** TODO [#B] Internet :bills:
|
||||||
DEADLINE: <2017-07-21 Fri -1m>
|
DEADLINE: <2017-07-21 Fri -1m>
|
||||||
|
|
||||||
* TODO [#A] Spaceship lease :bills:spaceship:
|
** TODO [#A] Spaceship lease :bills:spaceship:
|
||||||
DEADLINE: <2017-08-01 Tue -1m>
|
DEADLINE: <2017-08-01 Tue -1m>
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:agenda-group: bills
|
:agenda-group: bills
|
||||||
:END:
|
:END:
|
||||||
|
|
||||||
* TODO [#B] Fix flux capacitor :spaceship:shopping:@computer:
|
** TODO [#B] Fix flux capacitor :spaceship:shopping:@computer:
|
||||||
SCHEDULED: <2017-07-05 Wed>
|
SCHEDULED: <2017-07-05 Wed>
|
||||||
|
|
||||||
If I don't, the frobnicator will probably fall off halfway to Mars...
|
If I don't, the frobnicator will probably fall off halfway to Mars...
|
||||||
|
|
||||||
Gotta buy one first, though. [[https://example.com/][This one]] looks suitable.
|
Gotta buy one first, though.
|
||||||
|
|
||||||
* Recurring
|
** Recurring
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:agenda-group: recurring
|
:agenda-group: recurring
|
||||||
:END:
|
:END:
|
||||||
|
|
||||||
** CHECK /r/emacs :website:Emacs:
|
*** CHECK /r/emacs :website:Emacs:
|
||||||
DEADLINE: <2017-07-05 Wed .+1w>
|
DEADLINE: <2017-07-05 Wed +1w>
|
||||||
|
|
||||||
+ [[http://reddit.com/r/emacs][Link to /r/emacs]]
|
*** TODO Shop for groceries :food:shopping:@town:
|
||||||
|
SCHEDULED: <2017-07-05 Wed +1w>
|
||||||
|
:PROPERTIES:
|
||||||
|
:Effort: 30
|
||||||
|
:END:
|
||||||
|
|
||||||
** TODO Shop for groceries :food:shopping:@town:
|
*** Sunrise/sunset
|
||||||
SCHEDULED: <2017-07-05 Wed +1w>
|
|
||||||
:PROPERTIES:
|
|
||||||
:Effort: 30
|
|
||||||
:END:
|
|
||||||
|
|
||||||
** Sunrise/sunset
|
|
||||||
|
|
||||||
%%(org-super-agenda--test-diary-sunrise)
|
%%(org-super-agenda--test-diary-sunrise)
|
||||||
%%(org-super-agenda--test-diary-sunset)
|
%%(org-super-agenda--test-diary-sunset)
|
||||||
|
|
||||||
* Ideas
|
** Ideas
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:CATEGORY: ideas
|
:CATEGORY: ideas
|
||||||
:END:
|
:END:
|
||||||
|
|
||||||
** SOMEDAY Rewrite Emacs in Common Lisp :Emacs:elisp:computers:software:programming:
|
*** SOMEDAY Rewrite Emacs in Common Lisp :Emacs:elisp:computers:software:programming:
|
||||||
SCHEDULED: <2017-07-05 Wed>
|
SCHEDULED: <2017-07-05 Wed>
|
||||||
:LOGBOOK:
|
:LOGBOOK:
|
||||||
- State "SOMEDAY" from "MAYBE" [2017-07-24 Mon 18:59]
|
- State "SOMEDAY" from "MAYBE" [2017-07-24 Mon 18:59]
|
||||||
- State "MAYBE" from [2017-07-24 Mon 18:58]
|
- State "MAYBE" from [2017-07-24 Mon 18:58]
|
||||||
:END:
|
:END:
|
||||||
|
|
||||||
I mean, since no one has ever tried doing it before...
|
I mean, since no one has ever tried doing it before...
|
||||||
|
|
||||||
** SOMEDAY Write a symphony :music:
|
*** SOMEDAY Write a symphony :music:
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:agenda-group: plans
|
:agenda-group: plans
|
||||||
:END:
|
:END:
|
||||||
|
|
||||||
I don't know when I'll get to this, so it's undated.
|
I don't know when I'll get to this, so it's undated.
|
||||||
|
|
||||||
|
* Code
|
||||||
|
|
||||||
|
#+BEGIN_SRC elisp
|
||||||
|
(org-time-string-to-absolute (org-entry-get (point) "SCHEDULED"))
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
#+BEGIN_SRC elisp :results none
|
||||||
|
;; Setup code
|
||||||
|
(require 'org-super-agenda)
|
||||||
|
(org-super-agenda-mode 1)
|
||||||
|
(require 'org-habit)
|
||||||
|
(setq org-todo-keywords
|
||||||
|
'((sequence "TODO(t!)" "TODAY(a!)" "NEXT(n!)" "STARTED(s!)" "IN-PROGRESS(p!)" "UNDERWAY(u!)" "WAITING(w@)" "SOMEDAY(o!)" "MAYBE(m!)" "|" "DONE(d@)" "CANCELED(c@)")
|
||||||
|
(sequence "CHECK(k!)" "|" "DONE(d@)")
|
||||||
|
(sequence "TO-READ(r!)" "READING(R!)" "|" "HAVE-READ(d@)")
|
||||||
|
(sequence "TO-WATCH(!)" "WATCHING(!)" "SEEN(!)")))
|
||||||
|
(with-current-buffer "test.org" (revert-buffer))
|
||||||
|
|
||||||
|
(defmacro with-org-today-date (date &rest body)
|
||||||
|
"Run BODY with the `org-today' function set to return simply DATE.
|
||||||
|
DATE should be a date-time string (both date and time must be included)."
|
||||||
|
(declare (indent defun))
|
||||||
|
`(let ((day (date-to-day ,date))
|
||||||
|
(orig (symbol-function 'org-today)))
|
||||||
|
(unwind-protect
|
||||||
|
(progn
|
||||||
|
(fset 'org-today (lambda () day))
|
||||||
|
,@body)
|
||||||
|
(fset 'org-today orig))))
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
#+BEGIN_SRC elisp :results none
|
||||||
|
(defun diary-sunrise ()
|
||||||
|
(let ((dss (diary-sunrise-sunset)))
|
||||||
|
(with-temp-buffer
|
||||||
|
(insert dss)
|
||||||
|
(goto-char (point-min))
|
||||||
|
(search-forward ",")
|
||||||
|
(buffer-substring (point-min) (match-beginning 0)))))
|
||||||
|
|
||||||
|
(defun diary-sunset ()
|
||||||
|
(let ((dss (diary-sunrise-sunset))
|
||||||
|
start end)
|
||||||
|
(with-temp-buffer
|
||||||
|
(insert dss)
|
||||||
|
(goto-char (point-min))
|
||||||
|
(search-forward ", ")
|
||||||
|
(setq start (match-end 0))
|
||||||
|
(search-forward " at")
|
||||||
|
(setq end (match-beginning 0))
|
||||||
|
(goto-char start)
|
||||||
|
(capitalize-word 1)
|
||||||
|
(buffer-substring start end))))
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
*Note:* Removing tests from here as they're added to =test.el=.
|
||||||
|
|
||||||
|
#+BEGIN_SRC elisp
|
||||||
|
|
||||||
|
(org-super-agenda--test-with-org-today-date "2017-07-05 00:00"
|
||||||
|
(let ((org-agenda-files (list "~/src/emacs/org-super-agenda/test/test.org"))
|
||||||
|
(org-agenda-span 'day)
|
||||||
|
(org-super-agenda-groups
|
||||||
|
'((:name "Time grid items in all-uppercase with RosyBrown1 foreground"
|
||||||
|
:time-grid t
|
||||||
|
:transformer (--> it
|
||||||
|
(upcase it)
|
||||||
|
(propertize it 'face '(:foreground "RosyBrown1"))))
|
||||||
|
(:name "Priority >= C items underlined, on black background"
|
||||||
|
:face (:background "black" :underline t)
|
||||||
|
:not (:priority>= "C")
|
||||||
|
:order 100))))
|
||||||
|
(org-agenda nil "a")))
|
||||||
|
(org-super-agenda--test-with-org-today-date "2017-07-05 00:00"
|
||||||
|
(let ((org-agenda-files (list "~/src/emacs/org-super-agenda/test/test.org"))
|
||||||
|
(org-agenda-span 'day)
|
||||||
|
(org-super-agenda-groups
|
||||||
|
'((:name none
|
||||||
|
:time-grid t)
|
||||||
|
(:name "Should be all-uppercase RosyBrown1 on black"
|
||||||
|
:face (:background "black" :foreground "RosyBrown1")
|
||||||
|
:transformer #'upcase
|
||||||
|
:not (:priority>= "C")
|
||||||
|
:order 100))))
|
||||||
|
(org-agenda nil "a")))
|
||||||
|
|
||||||
|
(with-org-today-date "2017-07-05 00:00"
|
||||||
|
(let ((org-agenda-files (list "~/src/org-super-agenda/test/test.org"))
|
||||||
|
(org-agenda-span 'day)
|
||||||
|
(org-super-agenda-groups
|
||||||
|
'((:name none
|
||||||
|
:time-grid t)
|
||||||
|
(:name none
|
||||||
|
:not (:priority>= "C")
|
||||||
|
:order 100))))
|
||||||
|
(org-agenda nil "a")))
|
||||||
|
|
||||||
|
(with-org-today-date "2017-07-05 00:00"
|
||||||
|
(let ((org-agenda-files (list "~/src/org-super-agenda/test/test.org"))
|
||||||
|
(org-agenda-span 'day)
|
||||||
|
(org-super-agenda-groups
|
||||||
|
'((:name "Items with child TODOs"
|
||||||
|
:children todo))))
|
||||||
|
(org-agenda nil "a")))
|
||||||
|
|
||||||
|
(with-org-today-date "2017-07-05 00:00"
|
||||||
|
(let ((org-agenda-files (list "~/src/org-super-agenda/test/test.org"))
|
||||||
|
(org-agenda-span 'day)
|
||||||
|
(org-super-agenda-groups
|
||||||
|
'((:name "Items with child TODOs"
|
||||||
|
:children "CHECK"))))
|
||||||
|
(org-agenda nil "a")))
|
||||||
|
|
||||||
|
(with-org-today-date "2017-07-05 00:00"
|
||||||
|
(let ((org-agenda-files (list "~/src/org-super-agenda/test/test.org"))
|
||||||
|
(org-agenda-span 'day)
|
||||||
|
(org-agenda-custom-commands
|
||||||
|
'(("u" "Super view"
|
||||||
|
((agenda "" ((org-super-agenda-groups
|
||||||
|
'((:name "Today"
|
||||||
|
:time-grid t
|
||||||
|
:scheduled today
|
||||||
|
:deadline today)))))
|
||||||
|
(todo "" ((org-super-agenda-groups
|
||||||
|
'((:name "Projects"
|
||||||
|
:children t)
|
||||||
|
(:discard (:anything t)))))))))))
|
||||||
|
(org-agenda nil "u")))
|
||||||
|
|
||||||
|
(with-org-today-date "2017-07-05 00:00"
|
||||||
|
(let ((org-agenda-files (list "~/src/org-super-agenda/test/test.org"))
|
||||||
|
(org-agenda-span 'day)
|
||||||
|
(org-agenda-custom-commands
|
||||||
|
'(("u" "Super view"
|
||||||
|
((agenda "" ((org-super-agenda-groups
|
||||||
|
'((:name "Today"
|
||||||
|
:time-grid today)))))
|
||||||
|
(todo "" ((org-super-agenda-groups
|
||||||
|
'((:name "Projects"
|
||||||
|
:children t)
|
||||||
|
(:discard (:anything t)))))))))))
|
||||||
|
(org-agenda nil "u")))
|
||||||
|
|
||||||
|
(with-org-today-date "2017-07-05 00:00"
|
||||||
|
(let ((org-agenda-files (list "~/src/org-super-agenda/test/test.org"))
|
||||||
|
(org-agenda-span 'day)
|
||||||
|
(org-agenda-custom-commands
|
||||||
|
'(("u" "Super view"
|
||||||
|
((agenda "" ((org-super-agenda-groups
|
||||||
|
'((:name "Schedule"
|
||||||
|
:time-grid t
|
||||||
|
:date today)
|
||||||
|
(:name "Due today"
|
||||||
|
:deadline today)
|
||||||
|
(:name "Due soon"
|
||||||
|
:deadline t)))))
|
||||||
|
(todo "" ((org-agenda-overriding-header "")
|
||||||
|
(org-super-agenda-groups
|
||||||
|
'((:name "Projects"
|
||||||
|
:children t)
|
||||||
|
(:discard (:anything t)))))))))))
|
||||||
|
(org-agenda nil "u")))
|
||||||
|
|
||||||
|
(with-org-today-date "2017-07-05 00:00"
|
||||||
|
(let ((org-agenda-files (list "~/src/org-super-agenda/test/test.org"))
|
||||||
|
(org-agenda-span 'day)
|
||||||
|
(org-super-agenda-groups
|
||||||
|
'((:scheduled (before "2017-07-06")))))
|
||||||
|
(org-agenda nil "a")))
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
#+BEGIN_SRC elisp
|
||||||
|
|
||||||
|
(with-org-today-date "2017-07-05 00:00"
|
||||||
|
(let ((org-super-agenda-groups
|
||||||
|
'((:todo "WAITING")))
|
||||||
|
(org-agenda-files (list "~/src/org-super-agenda/test/test.org")))
|
||||||
|
(org-todo-list)))
|
||||||
|
|
||||||
|
(with-org-today-date "2017-07-05 00:00"
|
||||||
|
(let ((org-super-agenda-groups
|
||||||
|
'((:todo "SOMEDAY")))
|
||||||
|
(org-agenda-files (list "~/src/org-super-agenda/test/test.org")))
|
||||||
|
(org-tags-view nil "Emacs")))
|
||||||
|
|
||||||
|
(with-org-today-date "2017-07-05 00:00"
|
||||||
|
(let ((org-super-agenda-groups
|
||||||
|
'((:todo "CHECK")))
|
||||||
|
(org-agenda-files (list "~/src/org-super-agenda/test/test.org")))
|
||||||
|
;; org-search-view doesn't seem to set the todo-state property, so the matcher doesn't work
|
||||||
|
(org-search-view nil "Emacs")))
|
||||||
|
|
||||||
|
(with-org-today-date "2017-07-05 00:00"
|
||||||
|
(let ((org-super-agenda-groups
|
||||||
|
'((:regexp ("moon" "mars"))))
|
||||||
|
(org-agenda-files (list "~/src/org-super-agenda/test/test.org")))
|
||||||
|
(org-search-view nil "space")))
|
||||||
|
|
||||||
|
(with-org-today-date "2017-07-05 00:00"
|
||||||
|
(let ((org-super-agenda-groups
|
||||||
|
'((:todo "SOMEDAY")))
|
||||||
|
(org-agenda-files (list "~/src/org-super-agenda/test/test.org")))
|
||||||
|
(org-agenda-list nil nil 'day)))
|
||||||
|
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
** Agenda examining
|
||||||
|
|
||||||
|
This helps a lot.
|
||||||
|
|
||||||
|
#+BEGIN_SRC elisp
|
||||||
|
(defun data-debug-show-string-with-properties (s)
|
||||||
|
(with-current-buffer (get-buffer-create "argh")
|
||||||
|
(erase-buffer)
|
||||||
|
(print s (current-buffer))
|
||||||
|
|
||||||
|
;; Convert string reader representations to plain lists that can be set
|
||||||
|
(cl-loop for (match replace) in '(("#(" "'(")
|
||||||
|
("#<" "'(")
|
||||||
|
(">" ")"))
|
||||||
|
do (progn
|
||||||
|
(goto-char (point-min))
|
||||||
|
(while (search-forward match nil 'noerror)
|
||||||
|
(replace-match replace 'fixedcase 'literal))))
|
||||||
|
|
||||||
|
;; Surround content in a list which `argh' is set to, then eval
|
||||||
|
;; the buffer to do it
|
||||||
|
(goto-char (point-min))
|
||||||
|
(insert "(setq argh (list '")
|
||||||
|
(delete-forward-char 2)
|
||||||
|
(goto-char (point-max))
|
||||||
|
(insert "))")
|
||||||
|
|
||||||
|
;; Okay, sure, eval'ing the buffer is dangerous and bad and wrong.
|
||||||
|
;; But this is the only way I can find to make this work. (Maybe
|
||||||
|
;; `text-properties-at' could be used to get actual lists...)
|
||||||
|
(eval-buffer)
|
||||||
|
|
||||||
|
(data-debug-show-stuff argh "argh")
|
||||||
|
;; (switch-to-buffer (current-buffer))
|
||||||
|
))
|
||||||
|
|
||||||
|
(defun data-debug-show-current-line-with-properties ()
|
||||||
|
(interactive)
|
||||||
|
(data-debug-show-string-with-properties (buffer-substring (line-beginning-position) (line-end-position))))
|
||||||
|
|
||||||
|
(with-current-buffer "*Org Agenda*"
|
||||||
|
(data-debug-show-string-with-properties (seq-subseq (split-string (buffer-string) "\n")
|
||||||
|
0 5)))
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
** Agenda censoring
|
||||||
|
|
||||||
|
For sharing screenshots of the agenda without revealing private data.
|
||||||
|
|
||||||
|
#+BEGIN_SRC elisp
|
||||||
|
(defun org-agenda-sharpie ()
|
||||||
|
"Censor the text of items in the agenda."
|
||||||
|
(interactive)
|
||||||
|
(let (regexp old-heading new-heading properties)
|
||||||
|
;; Save face properties of line in agenda to reapply to changed text
|
||||||
|
(setq properties (text-properties-at (point)))
|
||||||
|
|
||||||
|
;; Go to source buffer
|
||||||
|
(org-with-point-at (org-find-text-property-in-string 'org-marker
|
||||||
|
(buffer-substring (line-beginning-position)
|
||||||
|
(line-end-position)))
|
||||||
|
;; Save old heading text and ask for new text
|
||||||
|
(line-beginning-position)
|
||||||
|
(unless (org-at-heading-p)
|
||||||
|
;; Not sure if necessary
|
||||||
|
(org-back-to-heading))
|
||||||
|
(setq old-heading (when (looking-at org-complex-heading-regexp)
|
||||||
|
(match-string 4))))
|
||||||
|
(setq new-heading (read-from-minibuffer "Overwrite visible heading with: "))
|
||||||
|
(add-text-properties 0 (length new-heading) properties new-heading)
|
||||||
|
;; Back to agenda buffer
|
||||||
|
(save-excursion
|
||||||
|
(when (and old-heading new-heading)
|
||||||
|
;; Replace agenda text
|
||||||
|
(let ((inhibit-read-only t))
|
||||||
|
(goto-char (line-beginning-position))
|
||||||
|
(when (search-forward old-heading (line-end-position))
|
||||||
|
(replace-match new-heading 'fixedcase 'literal)))))))
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
** Auto grouping
|
||||||
|
|
||||||
|
|
||||||
|
#+BEGIN_SRC elisp
|
||||||
|
(with-org-today-date "2017-07-05 00:00"
|
||||||
|
(let ((org-super-agenda-groups
|
||||||
|
'((:auto-group t)))
|
||||||
|
(org-agenda-files (list "~/src/org-super-agenda/test/test.org")))
|
||||||
|
(org-agenda-list nil nil 'day)))
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
** Auto categories
|
||||||
|
|
||||||
|
#+BEGIN_SRC elisp
|
||||||
|
(let ((org-super-agenda-groups
|
||||||
|
'((:auto-category t))))
|
||||||
|
(org-agenda-list nil nil 'day))
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
** Date
|
||||||
|
|
||||||
|
#+BEGIN_SRC elisp
|
||||||
|
(with-org-today-date "2017-07-05 00:00"
|
||||||
|
(-let* ((org-agenda-files (list "~/src/org-super-agenda/test/test.org"))
|
||||||
|
(org-agenda-span 'day)
|
||||||
|
((sec minute hour day month year dow dst utcoff) (list 0 0 0 5 7 2017 3 t nil))
|
||||||
|
(last-day-of-month
|
||||||
|
;; A hack that seems to work fine
|
||||||
|
(1+ (calendar-last-day-of-month month year)))
|
||||||
|
(target-date (format "%d-%02d-%02d" year month last-day-of-month))
|
||||||
|
(org-super-agenda-groups
|
||||||
|
`((:deadline (before ,target-date))
|
||||||
|
(:discard (:anything t)))))
|
||||||
|
(org-todo-list)))
|
||||||
|
|
||||||
|
(with-org-today-date "2017-07-05 00:00"
|
||||||
|
(-let* ((org-agenda-files (list "~/src/org-super-agenda/test/test.org"))
|
||||||
|
(org-agenda-span 'day)
|
||||||
|
((sec minute hour day month year dow dst utcoff) (list 0 0 0 5 7 2017 3 t nil))
|
||||||
|
(last-day-of-month (calendar-last-day-of-month month year))
|
||||||
|
(target-date (format "%d-%02d-%02d" year month last-day-of-month))
|
||||||
|
(org-super-agenda-groups
|
||||||
|
`((:deadline (before ,target-date))
|
||||||
|
(:discard (:anything t)))))
|
||||||
|
(org-todo-list)))
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
** Effort
|
||||||
|
|
||||||
|
#+BEGIN_SRC elisp
|
||||||
|
(with-org-today-date "2017-07-05 00:00"
|
||||||
|
(let ((org-agenda-files (list "~/src/org-super-agenda/test/test.org"))
|
||||||
|
(org-super-agenda-groups
|
||||||
|
'((:effort< "0:06"))))
|
||||||
|
(org-agenda-list nil nil 'day)))
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
** Misc
|
||||||
|
|
||||||
|
*** let-plist
|
||||||
|
|
||||||
|
I don't need this right now, but it might come in handy here or elsewhere.
|
||||||
|
|
||||||
|
#+BEGIN_SRC elisp
|
||||||
|
(defmacro osa/let-plist (keys plist &rest body)
|
||||||
|
"`cl-destructuring-bind' without the boilerplate for plists."
|
||||||
|
;; See https://emacs.stackexchange.com/q/22542/3871
|
||||||
|
|
||||||
|
;; I really don't understand why Emacs doesn't have this already.
|
||||||
|
;; So many things come close to it: pcase, pcase-let, map-let,
|
||||||
|
;; cl-destructuring-bind, -let...but none of them let you simply
|
||||||
|
;; bind all the values of a plist to variables with the same name as
|
||||||
|
;; their keys. You always have to type the name of the key twice.
|
||||||
|
|
||||||
|
;; For example, compare these two forms:
|
||||||
|
|
||||||
|
;; (-let (((&keys :from from :to to :date date :subject subject) email))
|
||||||
|
;; (list from to date subject))
|
||||||
|
|
||||||
|
;; (osa/let-plist (:from :to :date :subject) email
|
||||||
|
;; (list from to date subject))
|
||||||
|
|
||||||
|
;; Now, sure, sometimes you need to bind values to differently named
|
||||||
|
;; variables. But when you don't, I know which one I prefer.
|
||||||
|
(declare (indent defun))
|
||||||
|
(setq keys (cl-loop for key in keys
|
||||||
|
collect (intern (replace-regexp-in-string (rx bol ":") ""
|
||||||
|
(symbol-name key)))))
|
||||||
|
`(cl-destructuring-bind
|
||||||
|
(&key ,@keys &allow-other-keys)
|
||||||
|
,plist
|
||||||
|
,@body))
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
** Profiling
|
||||||
|
|
||||||
|
#+BEGIN_SRC elisp :results none
|
||||||
|
(defmacro profile-it (times &rest body)
|
||||||
|
`(let (output)
|
||||||
|
(dolist (p '("org-super-agenda-" "map" "org-" "string-" "s-" "buffer-" "append" "delq" "map" "list" "car" "save-" "outline-" "delete-dups" "sort" "line-" "nth" "concat" "char-to-string" "rx-" "goto-" "when" "search-" "re-"))
|
||||||
|
(elp-instrument-package p))
|
||||||
|
(dotimes (x ,times)
|
||||||
|
,@body)
|
||||||
|
(elp-results)
|
||||||
|
(elp-restore-all)
|
||||||
|
(point-min)
|
||||||
|
(forward-line 20)
|
||||||
|
(delete-region (point) (point-max))
|
||||||
|
(setq output (buffer-substring-no-properties (point-min) (point-max)))
|
||||||
|
(kill-buffer)
|
||||||
|
(delete-window)
|
||||||
|
output))
|
||||||
|
#+END_SRC
|
||||||
|
|
|
||||||