Commit Graph

24622 Commits

Author SHA1 Message Date
Ihor Radchenko 8ceb9e7902
Add NEWS entry for new element cache 2021-10-17 13:57:11 +08:00
Ihor Radchenko eeb04504ef
Use XDG cache dir as default dir for cache persistance
* lisp/org-persist.el (org-persist-path): Change default dir to XDG
cache dir and fall back to `user-emacs-directory' as the last resort.
2021-10-17 12:24:32 +08:00
Ihor Radchenko 85712d6456
Add comments documenting cache diagnostics 2021-10-17 12:23:58 +08:00
Ihor Radchenko 07ca988bb4
Fix compatibility with Emacs 27
* lisp/org-compat.el: Remove `length>' alias
* lisp/org-element.el (org-element-cache-map): Suppress compiler
warning.
* lisp/org-persist.el (org-persist-register): Do not `push' into
`plist-get'.  Not supported yet in Emacs 27.
(org-persist-unregister): Do not use `length>'.  Use
`org-directory-empty-p'.
(org-persist-gc): Use `org-directory-empty-p'.
2021-10-17 11:44:33 +08:00
Ihor Radchenko abe7222ed8
Add declares to suppress compiler warnings 2021-10-17 00:01:56 +08:00
Ihor Radchenko 885808fd58
Fix incorrectly written test
* testing/lisp/test-org.el (test-org/entry-get): The test was passing
in the past because of bug in org.el.
2021-10-17 00:00:21 +08:00
Ihor Radchenko 3c4290e668
org.el/org-scan-tags: Make use of fast `org-element-cache-map' 2021-10-17 00:00:01 +08:00
Ihor Radchenko 85e0a69567
Avoid frequent cache updates in some functions
* lisp/org.el (org-promote-subtree, org-demote-subtree,
org-paste-subtree, org--align-node-property): Group buffer changes
together and call after-change-functions once to avoid performance
degradation during cache updates.
2021-10-16 23:58:40 +08:00
Ihor Radchenko 5aeeb4f739
Use `org-element-at-point-no-context' in performance-critical places
* lisp/org-compat.el (org-mode-flyspell-verify, org-indent-line,
org-indent-region, org-indent-drawer, org-indent-block): Use
`org-element-at-point-no-context' in place of `org-element-at-point'
when we are doing changes.
* lisp/org.el (org-collect-keywords): Use direct parsing in place of
`org-elemnt-at-point'
2021-10-16 23:56:29 +08:00
Ihor Radchenko e70a8aac59
Use org-element-cache in place of text property cache in agenda
* lisp/org-agenda.el (org-agenda-skip): Use
`org-in-archived-heading-p' and `org-in-commented-heading-p' in place
of text property cache.

(org-agenda-get-todos, org-agenda-get-timestamps,
org-agenda-get-sexps, org-agenda-get-progress,
org-agenda-get-deadlines, org-agenda-get-scheduled,
org-agenda-get-blocks): Do not use text property cache in favour of
Org API functions.  The API functions use cache now.

* lisp/org-clock.el (org-element--cache-active-p): Declare function to
suppress compiler warning.

(org-clock-in): Do not use text property cache when element cache is
active.

* lisp/org-duration.el (org-duration-to-minutes): Do not change match
data.  It is needed to not break agenda---agenda relies on match data
not being altered.

* lisp/org.el (org-run-like-in-org-mode): Use element cache.
(org-refresh-category-properties): Use element cache.
(org-make-tags-matcher, org-agenda-prepare-buffers): Do not rely on
text property cache.

* testing/lisp/test-org.el (test-org/refresh-category-properties): Do
not use text property cache.
2021-10-16 23:50:21 +08:00
Ihor Radchenko 60c927f8b8
Add new element parser and cache tests 2021-10-16 23:42:30 +08:00
Ihor Radchenko fe6cefdaaf
ox.el: Support cache during export
* lisp/ox.el (org-export-ignored-local-variables): Preserve cache
state in export buffer.
(org-export--generate-copy-script): Fix cache confusion about buffer
change tic.
2021-10-16 23:41:00 +08:00
Ihor Radchenko fede2588e4
org.el/org-in-archived-heading-p: Support cache and passing element arg 2021-10-16 23:40:28 +08:00
Ihor Radchenko 86345df9ab
org.el/org-in-commented-heading-p: Support cache and passing element arg 2021-10-16 23:40:14 +08:00
Ihor Radchenko 399a29c4f4
org.el/org-up-heading-safe: Add cache support 2021-10-16 23:39:43 +08:00
Ihor Radchenko ec737554d0
org.el/org-end-of-subtree: Support cache and passing element arg 2021-10-16 23:39:11 +08:00
Ihor Radchenko d43781707b
org.el/org-goto-first-child: Support cache and passing element arg 2021-10-16 23:38:46 +08:00
Ihor Radchenko 5d162b7bcf
org.el/org-back-to-heading: Handle inlinetasks correctly
* lisp/org.el(org-back-to-heading): Rewrite `outline-back-to-heading'
considering inlinetasks.
2021-10-16 23:37:15 +08:00
Ihor Radchenko 5bf5fdbc28
org.el/org-entry-get-with-inheritance: Support cache and passing element arg
* lisp/org.el (org-entry-get-with-inheritance): Add cache support.
Add new optional argument---an element to get properties from.  Fix
getting top-level properties when a headline is located at BOB.
2021-10-16 23:33:10 +08:00
Ihor Radchenko 7b83168295
org.el/org--property-local-values: Support cache and passing element arg 2021-10-16 23:32:39 +08:00
Ihor Radchenko 78abbcd052
org.el/org-get-tags: Support cache and passing element arg
* lisp/org.el (org-fast-tag-selection): Allowing passing an element or
position as first argument.  Add cache support.
2021-10-16 23:31:15 +08:00
Ihor Radchenko 38b632d2ea
org.el/org--get-local-tags: Add cache support 2021-10-16 23:30:52 +08:00
Ihor Radchenko 7159ec0be0
org.el/org-at-planning-p: Add cache support 2021-10-16 23:30:13 +08:00
Ihor Radchenko 68a44eadac
org.el/org-narrow-to-subtree: Support cache and passing element arg 2021-10-16 23:29:11 +08:00
Ihor Radchenko bc52c4d9ab
Fix compatibility for older Emacs versions
* lisp/org-compat.el (org-length>, org-file-name-concat): Add backward
compatibility for `length>' and `org-file-name-concat'.
2021-10-16 23:26:43 +08:00
Ihor Radchenko fc80d052db
Re-implement org-element-cache and add headline support
* lisp/org-element.el (org-element-with-disabled-cache): New macro.

(org-element-greater-elements): Add new org-data element.  It
functions like a virtual headline containing the whole buffer.  The
org-data properties are like headlie properties, but according to the
top-level drawer.  org-data's category is the buffer's category as
defined by top-level property drawer, #+CATEGORY keyworsd, and the
buffer file name.

(org-element--cache-element-properties, org-element-set-element): New
variable containing properties to be transferred when updating changed
element in cache in `org-element-set-element'.

(org-element--get-node-properties): Allow parsing node propreties in
top-level drawer when new optional argument is passed.  Respect
PROPERTY+ syntax.

(org-element--get-global-node-properties): New function.  It returns
node properties for top-level property drawer.

(org-element-org-data-parser, org-element-org-data-interpreter):
Implement the new org-data element.

(org-element-headline-parser, org-element-section-parser): Add new
:robust-begin and :robust-end
properties delimiting safe changes that do not modify headline
element.

(org-element--list-struct): Fix cache update when adding a headline
inside list.

(org-element--current-element): Implement cache support.  Record
parsing mode (:mode) and parsing granularity (:granularity) in the
element properties.

(org-element-parse-buffer, org-element--next-mode): Support new
org-data element.

(org-element--parse-elements): Record parsing granularity in the
returned tree

(org-element-use-cache): Enable cache by default.

(org-element-cache-persistent): New variable controlling cache
persistance across sessions.  Enabled by default.

(org-element--cache-self-verify,
org-element--cache-self-verify-frequency,
org-element--cache-diagnostics, org-element--cache-map-statistics,
org-element--cache-map-statistics-threshold,
org-element--cache-diagnostics-level,
org-element--cache-diagnostics-ring,
org-element--cache-diagnostics-ring-size): New variables controlling
cache diagnostics and self-diagnostics.  Greatly simplifies cache
debugging.

(org-element--cache, org-element--cache-sync-requests,
org-element--cache-sync-timer): Make cache buffer-local by default.

(org-element--headline-cache): Implement separate cache storing only
headlines and inlinetasks.

(org-element--cache-size, org-element--headline-cache-size): New
variables containing cache sizes.  This is much faster than
`avl-tree-size'.

(org-element--cache-sync-requests): Update docstring explaning the
request list structure.

(org-element--cache-sync-keys-value): New variable replacing
`org-element--cache-sync-keys' hash table.  The hash table was not
reliable because it was using elements as keys.  Upon any cached
element update/shift, the keys were invalidated making cache ordering
incorrect and breaking the cache badly.  Now, the cache keys are
stored as :org-element--cache-sync-key element property and the new
variable stores marker value indicating the current sync request
cycle.  See `org-element--cache-key' for more details.

(org-element--cache-change-tic): New variable controlling buffer
modification count that is registered in cache.  This variable allows
catching "stealth" edits.

(org-element--cache-non-modifying-commands): New variable listing
commands that will not be slown down if we fill cache on the fly.

(org-element--request-key, org-element--request-beg,
org-element--request-end, org-element--request-offset,
org-element--request-parent, org-element--request-phase): New macros.
They improve code readability (especially when using nameless-mode).

(org-element--format-element, org-element--cache-log-message,
org-element--cache-warn): New macros implementing generic logging
functionality.

(org-element--cache-key): Add section and org-data element support.
Change cache key storage from hash map to :org-element--cache-sync-key
element property + `org-element--cache-sync-keys-value'.  We use the
latter to group all the cache keys during a single cache request
sequence.  Once sync request is fully complete, the
`org-element--cache-sync-keys-value' is updated making all the old
sync keys obsolete (they will still be store as element properties).

(org-element--headline-cache-root): New function returning headline
cache root.

(org-element--cache-active-p): Prevent cache updates when
`inhibit-modification-hooks' is non-nil, unless non-nil optional
argument is provided.

(org-element--cache-find): Share cache between indirect buffers and
the base buffer.  We have to do it because after-change hooks for
indirect buffer are not called in the base buffer and vice versa.  Add
support for section and org-data elements.

(org-element--cache-put): Implement new approach for cache key
storage.  Add diagnostics.  Indicate cached elements using :cached
element property.  Support cache size calculation.

(org-element--cache-remove): Invalidate parent contents when removing
element.  Support cache size calculation.  Detect cache corruption due
to misordered elements.

(org-element--cache-shift-positions): Support :robust-begin and
:robust-end element properties.

(org-element--cache-sync): Add diagnostics.  Add detailed comments.
Prevent slowdown when large cache chunks need to be deleted forcing
O(N) complexity cutoff.  In phase 2, fix cases when next request
contains deleted cache key.  In phase 2, fix scenario when newly
inserted element intersects with existing elements in cache.  In phase
2, detect obsolete parents removed from cache.

(org-element--open-end-p): New function checking if an element can
have blank lines right after its :contents-end.

(org-element--parse-to): Do not alter match data.  Process complex
parsing mode changes correctly.  Support headlines in cache.  Support
org-data parsing.  Add detailed comments.  Add diagnostics.

(org-element--cache-sensitive-re): Make list lines sensitive.

(org-element--cache-change-warning): Update docstring.  Now, the
variable can have t, nil, and number values.  Numbers are used to
provide more details about changed headlines.

(org-element--cache-before-change, org-element--cache-after-change):
Handle headline hierarchy.  Properly handle cache in indirect
buffers.

(org-element--cache-after-change): Update docstring clarifying the
return values.  Add special handling for headline and org-data
elements updating them in-place instead of removing together with the
whole contents when possible.  Use :robust-begin/:robust-end element
properties to detect robust changes.

(org-element--cache-submit-request): Add detailed comments.  Correctly
handle cache in indirect buffers.  Delegate element modifications to
`org-element--cache-for-removal'.

(org-element--cache-verify-element): New function for cache
self-verification.

(org-element--cache-persist-before-write,
org-element--cache-persist-before-read,
org-element--cache-persist-after-read): Implement cache persistance.

(org-element-cache-reset): Correctly handle cache in indirect
buffers.  Support cache persistance.  Support new cache size
calculation and new cache key schema.

(org-element-cache-map): New function analagous to `org-element-map',
but much faster.  The function overperforms org-ql written by Adam
Porter aka alphapapa [1] and reuses some ideas from there (namely,
fast element skipping via regexps).

[1] https://github.com/alphapapa/org-ql/

(org-element-at-point): The returned elements are now guaranteed to
have correct parents up to org-data.  New optional argument
CACHED-ONLY limits element search to current cache---if element is not
in cache and current command is not in cache
`org-element--cache-non-modifying-commands', the cache is not updated
and the function returns nil.  Also, support cache verification.

(org-element-at-point-no-context): New function.  It is analogous of
older `org-element-at-point' with no guarantee that :parent properties
are correct beyond direct parent heading.  This function does not
update cache and can be useful when cache updates should be avoided
for performance reasons.

* lisp/ob-core.el (org-babel-where-is-src-block-result): Support
section and org-data elements in cache.

* lisp/org-macro.el (org-macro-replace-all,
org-macro--find-keyword-value): Support org-element-cache.

* lisp/org-table.el (orgtbl-to-generic): Support org-element-cache.

* lisp/org.el (org-mode): Add cache persistance.

(org-up-element): Preserve old behaviour when error is returned for
section and org-data element.

*
testing/lisp/test-org-archive.el (test-org-archive/update-status-cookie):
Fix test when cache is active.

* testing/lisp/test-org-colview.el (test-org-colview/columns-update):
Fix test.

* testing/lisp/test-org-element.el (test-org-element/extract-element):
Add suport for new org-data element.

* testing/lisp/test-org-element.el (test-org-element/parent-property):
Fix equality check.  Parents returned by cache and `org-element-map'
may not be `eq' now.  Just `equal'.

* testing/lisp/test-org-element.el (test-org-element/context): Support
section and headline parents.
2021-10-16 23:22:18 +08:00
Ihor Radchenko 6933c1ad78
lisp/org-persist.el: New library to store data across sessions 2021-10-16 21:16:11 +08:00
Nicolas Goaziou 8799422a32 Merge branch 'bugfix' 2021-10-13 22:23:03 +02:00
Nicolas Goaziou 009900d7fa oc: Add autoload cookie for `org-cite-insert'
* lisp/oc.el (org-cite-insert): Autoload function.
2021-10-13 22:22:22 +02:00
Nicolas Goaziou c83fe001c7 oc: Fix error message
* lisp/oc.el (org-cite-insert): Fix copy-pasta in error message.
2021-10-13 22:20:11 +02:00
Nicolas Goaziou 2b1fc6ba72 Merge branch 'bugfix' 2021-10-11 23:59:00 +02:00
Nicolas Goaziou 17e25c3f14 oc-csl: Map § and §§ o section locators
* lisp/oc-csl.el (org-cite-csl--label-alist): Map § and §§ o section
locators.
2021-10-11 23:58:17 +02:00
Marco Wahl d0b55739c0 org: Fix: Respect TAB in property drawer as separator
* lisp/org.el (org-property-drawer-re): Allow TAB as first
character after the property name's colon.
2021-10-11 14:08:01 +02:00
Nicolas Goaziou b5713f4f1b Merge branch 'bugfix' 2021-10-11 11:39:22 +02:00
Nicolas Goaziou 18dca3478a oc: Upon inserting citations, add a space between keys
* lisp/oc.el (org-cite-make-insert-processor): Add a space in addition
to the semicolon.
2021-10-11 11:38:18 +02:00
Nicolas Goaziou 880d4fada6 Merge branch 'bugfix' 2021-10-11 11:21:48 +02:00
Nicolas Goaziou eb40091929 oc-csl: Improve an error message
* lisp/oc-csl.el (org-cite-csl--style-file): Add missing placeholder
for format string.
2021-10-11 11:21:00 +02:00
Nicolas Goaziou 3bb0cb9398 oc: Fix § locator name
* lisp/oc-csl.el (org-cite-csl--label-regexp): § is not a word start,
so adjust regexp accordingly.  Also fix mistake introduced in
c4a357f192.
(org-cite-csl--parse-reference): Ignore any space after locator name.
2021-10-11 11:18:40 +02:00
Nicolas Goaziou ee6e4892a1 Merge branch 'bugfix' 2021-10-10 23:11:35 +02:00
Nicolas Goaziou 596ec7a167 oc-biblatex: Fix docstring
* lisp/oc-biblatex.el (org-cite-biblatex-export-citation): Fix docstring.
2021-10-10 23:11:05 +02:00
Nicolas Goaziou 2fad7be9e7 oc-biblatex: Support bare variant for noauthor style
* lisp/oc-biblatex.el (org-cite-biblatex-export-citation): Support
bare variant for noauthor style.
2021-10-10 22:18:31 +02:00
Nicolas Goaziou d872506ad3 Merge branch 'bugfix' 2021-10-10 12:12:35 +02:00
Nicolas Goaziou c4a357f192 oc-csl: Allow nbsp after locator label
* lisp/oc-csl.el (org-cite-csl--label-regexp): Allow nbsp between
locator label and value.

Reported-by: M. ‘quintus’ Gülker <post+orgmodeml@guelker.eu>
<http://lists.gnu.org/r/emacs-orgmode/2021-10/msg00423.html>
2021-10-10 12:11:26 +02:00
Nicolas Goaziou f5faffb142 Merge branch 'bugfix' 2021-10-09 23:02:41 +02:00
Nicolas Goaziou 8dfc056fcc oc: Fix failing test about `org-cite-list-citations'
* lisp/oc.el (org-cite-list-citations): Properly implement
a simplified version of `org-export-get-footnote-definition'.
2021-10-09 23:01:35 +02:00
Kyle Meyer f0c66dc4c4 Merge branch 'bugfix' 2021-10-09 16:18:17 -04:00
Nicholas Vollmer b71474ff7f lisp/org.el: (org-save-all-org-buffers): Prevent `org-mode' reload
* lisp/org.el: (org-save-all-org-buffers): Ensure `save-some-buffers' PRED returns boolean.

As of this upstream commit:

https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=a9ad3d477441feefa3bf6107d58281cb64e0e78a

`save-some-buffers' will call its PRED argument if it returns a function.
Since (derived-mode-p 'org-mode) returns the symbol org-mode,
and org-mode is a function, org-mode is reloaded in modified Org
buffers when calling `org-save-all-org-buffers'. Among other
undesirable behavior, this will cause the buffer's visibility to be
reset to its initial visibility.
2021-10-09 15:23:33 -04:00
Nicolas Goaziou dc154f0d18 Merge branch 'bugfix' 2021-10-09 16:10:30 +02:00
Nicolas Goaziou 11f450da80 oc-biblatex: Declare missing "nocite" style
* lisp/oc-biblatex.el (biblatex): Declare the processor provides
a "nocite" citation style.
2021-10-09 16:09:33 +02:00
Nicolas Goaziou 6717826d5a oc-bibtex: Pacify byte-compiler 2021-10-08 22:45:22 +02:00