Commit graph

716 commits

Author SHA1 Message Date
Ihor Radchenko 77aa9be5ac
Implement overlay- and text-property-based versions of some functions 2022-04-25 19:39:54 +08:00
Ihor Radchenko fa7530c7b4
Rename old function call to use org-fold 2022-04-25 19:39:53 +08:00
Ihor Radchenko 96529e933b
org-element-export-snippet-parser: Fix snippets without ending @@
* lisp/org-element.el (org-element-export-snippet-parser): Do not
recognise snippets without closing @@ as empty "@@backend:" snippets.

Example:
@@html:fo aksjdaksjd ajs d

askdjas aksj daj sao@@

Reported in
https://github.com/lucasvreis/org-parser/blob/master/SPEC.org#export-snippets
2022-04-24 13:00:12 +08:00
Nicolas Goaziou ef66660cf4 Merge branch 'bugfix' 2022-02-28 15:46:06 +01:00
Nicolas Goaziou bafeaf161c element: Fix parsing of inline footnotes
* lisp/org-element.el (org-element--pair-round-table):
(org-element--pair-square-table):
(org-element--pair-curly-table): De-activate all but one pair of
parenthesis.
* testing/lisp/test-org-element.el (test-org-element/footnote-reference-parser):
Add test.

Reported-by: Greg Minshall <minshall@umich.edu>
<http://lists.gnu.org/r/emacs-orgmode/2022-02/msg00369.html>
2022-02-28 15:45:25 +01:00
Ihor Radchenko c5a0113367
org-element-org-data-parser: Fix when invoked from indirect buffer
* lisp/org-element.el (org-element-org-data-parser): Consider base
buffer file name when calculating Org buffer category.
2022-02-20 15:26:11 +08:00
Ihor Radchenko bb8aa14923
org-element-cache: Add more self-consistency checks
* lisp/org-element.el (org-element--parse-to):
(org-element--cache-verify-element): Add check asserting that all the
parsed elements are assigned with non-nil parent (except org-data).
2022-02-05 19:18:00 +08:00
Ihor Radchenko 5da9d6810b
org-element--cache-before-change: Fix handling sensitive edits at bol
* lisp/org-element.el (org-element--cache-before-change): Fix
optimisation when edits are involving element :end position.  Checking
that END is at BOL fails when we insert at the beginning of a
headline.
2022-02-05 19:17:59 +08:00
Ihor Radchenko e29fea256d
org-element--parse-to: Simplify code 2022-02-05 19:17:59 +08:00
Ihor Radchenko 2b49d6fd9c
org-id-update-id-locations: Disable cache in throwaway buffers
* lisp/org-macs.el (org-element-with-disabled-cache): Move from
org-element.el to org-macs.el
2022-01-30 15:40:14 +08:00
Ihor Radchenko f0e0716f54
org-element: Use new cache container format 2022-01-29 17:08:47 +08:00
Ihor Radchenko 38a681fdae
org-element-cache-reset: Do not persist caches for non-file buffers 2022-01-29 17:03:54 +08:00
Ihor Radchenko edd7f2962f
org-persist: Reimplement using more generic approach 2022-01-29 16:55:57 +08:00
Ihor Radchenko 1587e445be
org-element-cache: Suggest to share warning text as well in the warnings
Multiple users reported that they saw the warning, but did not
actually report the warning text.  It's better to ask about sharing
explicitly.
2022-01-23 12:06:56 +08:00
Ihor Radchenko 5d05f5911a
org-element-cache: Allow detecting changes from indirect non-Org buffers
* lisp/org-element.el (org-element--cache-before-change):
(org-element--cache-after-change): Do not prevent trigerring if the
current indirect buffer is not in Org mode, but its base buffer is in
Org mode.
2022-01-19 17:37:34 +08:00
Ihor Radchenko 9b58ead467
org-element-context: Use element cache
* lisp/org-element.el (org-element-context): Use
`org-element-at-point', which makes use of cache.
* testing/lisp/test-org-element.el (test-org-element/lineage): Expect
full lineage up to org-data from `org-element-context'.
2022-01-17 20:20:57 +08:00
Ihor Radchenko 6631b3f7bb
org-element--parse-to: Fix limit when pasting top-comment and no cache
* lisp/org-element.el (org-element--parse-to): Manually parse org-data
and set appropriate parser mode when POS is before first headline and
cache is disabled.
(org-element-org-data-parser--recurse): New variable flagging if
`org-element-data-parser' is called recursively.
(org-element-org-data-parser): Handle recursive calls from inside `org-element-at-point-no-context'.

This also fixes false-positives in `org-element--cache-verify-element'.
2022-01-14 14:29:16 +08:00
Ihor Radchenko 1f48d2d751
org-element-cache-map: Do not byte-compile FUNC
Byte compilation can unpredictably break agenda searches in some Emacs
builds.

See https://list.orgmode.org/PAXPR08MB6640260AFA03FCDFABE245A3A34F9@PAXPR08MB6640.eurprd08.prod.outlook.com/T/#t
2022-01-10 22:32:38 +08:00
Ihor Radchenko dc4b2772e3
org-element-cache-map: Fix an edge case with org-element-cache-continue-from
* lisp/org-element.el (org-element-cache-map): Make sure that START is
never set to -1.  It may cause infinite loops in some scenarios.
* testing/lisp/test-org.el (test-org/map-entries): Add a test catching
the reported situation.

Reported in https://list.orgmode.org/CADywB5JHAyPX99Vr02SvAqiMTD+7ss4VWVipOhKfm=iGirDPhA@mail.gmail.com/T/#t
2022-01-07 22:10:22 +08:00
Ihor Radchenko 515ce56d4e
org-element-cache: Fix transforming keywords to affiliated
* lisp/org-element.el (org-element--cache-for-removal): Consider
preceding keywords to be updated unconditionally.
(org-element-cache-map): Fix infinite loop revealed by the new test.

* testing/lisp/test-org-element.el (test-org-element/cache-affiliated):
New test.
2022-01-07 21:24:43 +08:00
Ihor Radchenko a98ae424d2
org-element-cache: Give user more control over silent modificatoin checks
* lisp/org-element.el (org-element--cache-silent-modification-check):
New variable allowing the user to suppress modification checks completely.
* lisp/org-element.el (org-element--cache-sync): Support
`org-element--cache-silent-modification-check'.

The existing heuristics for built-in non-modifying commands that
change `buffer-chars-modified-tick' is not sufficient.  At least
`capitalize-word' changes the tick regardless whether the buffer was
actually modified or not.  Yet, `capitalize-word' does not call
`after-change-functions' if the buffer is not really modified.

Reported in https://list.orgmode.org/2022-01-06T12-13-17@devnull.Karl-Voit.at/T/#mb3771758f81b31721ba2f420878a4d16081dc483
2022-01-06 20:16:00 +08:00
Kyle Meyer aae2ac3a68 Merge branch 'bugfix' 2022-01-01 15:21:37 -05:00
Kyle Meyer 5a229cbc44 Update copyright year to 2022 2022-01-01 15:17:08 -05:00
Ihor Radchenko 06f58e4759
org-element-cache-map: Fix when FUNC deletes current element
* lisp/org-element.el (org-element-cache-map-continue-from): New
variable forcing `org-element-cache-map' to continue from a custom
point in buffer.
(org-element-cache-map): Add support for
`org-element-cache-map-continue-from'.  Update docstring accordingly.
Also, make sure that mapping terminates correctly when FUNC deletes
all elements in buffer.
* testing/lisp/test-org.el (test-org/map-entries): Add test.

Fixes https://orgmode.org/list/CADywB5KOJ1p0NpvA=iX-ybHsO=huGA8qL3xMpUTETmS2qp7_ng@mail.gmail.com
2022-01-01 14:13:26 +08:00
Ihor Radchenko 8f50ea2d69
org-element--parse-to: Get rid of unnecessary cache lookup
* lisp/org-element.el (org-element--parse-to): Disable cache in
`org-element--current-element'.  When calling it here, we know for
sure that element at point is not yet in cache.
2021-12-24 12:30:09 +08:00
Ihor Radchenko 4426d8009f
org-element-cache: Fix Phase 1 when new parent overlaps future edits
* lisp/org-element.el (org-element--cache-process-request): New OFFSET
argument used to correct newly added parents during Phase 1.  The
`org-element--parse-to' call inside Phase 1 may add new elements to
cache that intersect with future edits.  Boundaries of these elements
may be shifted twice, so we have to offset the future shift.

(org-element--cache-sync): New OFFSET argument providing future change
info to `org-element--cache-process-request'.

(org-element--cache-submit-request): Provide offset value in
`org-elemnt--cache-sync' call.

(org-element--cache-submit-request):
(org-element--cache-process-request):
(org-element--cache-sync): Never use %d format for region boundaries.
It may be a marker and cause error.  Use %S instead.

(org-element--cache-process-request): Use unique symbols for
catch-throw.

Fixes https://list.orgmode.org/CAFyQvY3Qv5xn-ET83L6Rzg-V1zOVu4y1gt+-_CpfaWNAdt87xA@mail.gmail.com/T/#t
2021-12-17 22:48:20 +08:00
Ihor Radchenko e2a8e95576
org-element-cache: Fix when edit extends previous element
* lisp/org-element.el (org-element--cache-after-change): Always extend
changed region to bol.
* testing/lisp/test-org-element.el (test-org-element/cache): Add test
checking the new fix.  Amend some tests around making sure that cache
is active during testing.
2021-12-17 20:23:50 +08:00
Ihor Radchenko d6e6a9a3bc
org-element.el: Silence compiler 2021-12-17 20:23:11 +08:00
Ihor Radchenko 092e921423
org-element-cache-map: Fix when start is nil after buffer modification 2021-12-16 23:17:05 +08:00
Ihor Radchenko 3338f37061
org-element--cache-process-request: Fix format specifier allowing marker
Fixes https://list.orgmode.org/CAFyQvY2=M6-JO7k=dF74injM7kHCcGUgdCCZXM6TZPWDTGbR4A@mail.gmail.com/T/#t
2021-12-16 23:16:31 +08:00
Ihor Radchenko 325b06bde4
org-element-cache: Do not carry over warning after sync
* lisp/org-element.el (org-element--cache-sync): Set
`org-element--cache-warning' to nil at the end of synchronisation.
We do not need to consider that next request might be merged with
existing request in such scenario.
(org-element--cache-before-change): Add comment explaining the use of `org-element--cache-warning'.
2021-12-16 21:39:26 +08:00
Ihor Radchenko d267486002
org-element-cache: Fix some edits right after indent at :begin
* lisp/org-element.el (org-element--cache-after-change): Extend
changed region to bol when we are editing near beginning of an element
within or right after indentation.  Such edits potentially change
:post-blank value of the previous element.
* testing/lisp/test-org-element.el (test-org-element/cache): Add test
checking one of such cases.
2021-12-16 21:39:25 +08:00
Ihor Radchenko 5840e4d61a
org-element-cache Do not make headline non-robust after changes at :end
* lisp/org-element.el (org-element--cache-for-removal): When changes
involve :end of a headline, allow it to be re-parsed synchronously.
2021-12-16 11:39:23 +08:00
Ihor Radchenko 69985367cd
org-element-cache: Consider non-PROPERTIES drawers robust
* lisp/org-element.el (org-element--cache-for-removal): Drawers are
generally robust elements (they cannot be changed if a non-sensitive
change is made inside their contents).  The only exception is
PROPERTIES drawer that may switch back and forth between ordinary
drawer and properties drawer depending on its contents.  The old code
treated all possible drawer as non-robust for this reason, degrading
performance on large LOGBOOK drawers that are now processed much
faster since they do not need to be removed and re-parsed on every
single change.
2021-12-16 11:26:54 +08:00
Ihor Radchenko 6339c622f8
org-element-cache: Do not consider BEGIN lines of elements sensitive
* lisp/org-element.el (org-element--cache-sensitive-re): Remove
 #+begin_ and \begin{ lines from sensitive regexp.  Such changes can
 be handled without a need to re-parse from earlier position.  If a
 change introduces a new element, the new element will be recognised
 and the unupdated elements not intersecting with the new element will
 be handled during Phase 1.
2021-12-16 11:23:33 +08:00
Ihor Radchenko fd93ad698a
org-element-cache: Do not treat inserting newline at :begin sensitive
* lisp/org-element.el (org-element--cache-before-change): Do not match
`org-element--cache-sensitive-re' against an element starting at END
when END is at bol.  Such changes never break an element structure (as
opposed to inserting non-newline right at :begin of an element).
2021-12-16 11:20:32 +08:00
Ihor Radchenko cfe4b17d96
org-element-cache: Optimise changed property drawer detection
* lisp/org-element.el (org-element--cache-for-removal): Only force
re-parsing headlines when the changed region falls within the headline
before property drawer end position.
2021-12-16 11:18:00 +08:00
Ihor Radchenko 798435be85
org-element-cache: Fix merging intersecting Phase 0 requests
* lisp/org-element.el (org-element--cache-submit-request): Extend
calculation of affected parent elements to the full changed region.
The previous behaviour could miss some outer elements to be removed.
2021-12-12 16:13:16 +08:00
Ihor Radchenko 9c7acaa02d
Re-implement 54534eebb more efficiently
* lisp/org-element.el (org-element--cache-sensitive-re): Do not treat
properties inside property drawers as global sensitive change. It can
cause cache drop on large logbook drawers where a new clock entry is
inserted.
(org-element--cache-for-removal): Use the same technique used for
detecting property drawer <-> ordinary drawer changes under headlines
for org-data.
2021-12-12 12:51:56 +08:00
Ihor Radchenko edddc7d149
org-element-cache-map: Reduce memory allocation and time re-search
* lisp/org-element.el (org-element-cache-map): Move all possible
let-bindings outside the loop to avoid remory re-allocation on every
iteration.  Track statistics for `re-search-forward' calls.
2021-12-11 10:08:40 +08:00
Ihor Radchenko 54534eebbb
org-element-cache: Handle some edits in top-level property drawer
* lisp/org-element.el (org-element--cache-sensitive-re): Make proprety
drawer lines sensitive.
(org-element--cache-for-removal): Make sensitive edits inside cache
gap right after org-data re-parse the org-data.  Make sensitive
top-section edits re-parse org-data.

The specific error has been reported in
https://github.com/yantar92/org/issues/40
The recepy involves loading org-contrib:
1. emacs -Q -L ~/.emacs.d/.local/straight/repos/org/lisp -L ~/.emacs.d/.local/straight/repos/org-contrib/lisp -l org
 -l org-eldoc
 2. Create a test.org file with the following content:
 :PROPERTIES:
:ID:       test
:END:

Test.
3.
(goto-char (point-min))
(org-entry-put nil "ID" "test")
(save-buffer)
(org-entry-get nil "ID")
Return value is nil, while should be "test"
2021-12-08 10:31:37 +08:00
Ihor Radchenko 9843670d11
org-element--cache-sync: Another take on false positive warnings
* lisp/org-element.el (org-element--cache-sync): Suppress silent edit
warnings for Emacs <28.  In older Emacs, Emacs internal functions can
modify `buffer-chars-modified-tick' and cannot be distinguished from
dangerous edits under `inhibit-modification-hooks'.  Some of the
functions even have the same footprint with the edits we want to
avoid.
2021-12-04 12:52:16 +08:00
Ihor Radchenko b59ccbf55b
org-element-at-point: Improve warning message
* lisp/org-element.el (org-element-at-point): Describe warning as
parser error when `org-element--parse-to' throws an error.  The error
may be thrown when parser encounters issue not related to cache.

Fixes confusion in https://list.orgmode.org/871r2vpblx.fsf@yandex.com/T/#u
2021-12-02 18:15:55 +08:00
Ihor Radchenko 328be6df40
org-element--parse-to: Fix skipping sibling optimisation
* lisp/org-element.el (org-element--parse-to): Fallback to normal
parsing when there are no siblings between POS and ELEM-END.

Reported in
https://github.com/yantar92/org/issues/38#issuecomment-982830497
2021-12-02 09:17:51 +08:00
Ihor Radchenko b170b23a5b
Update adadb5b55 for Emacs 26 2021-12-02 08:40:06 +08:00
Ihor Radchenko adadb5b554
org-element--cachy-sync: Add exception for unregistered changes
* lisp/org-element.el (org-element--cache-sync): Another special case
when Emacs <28 silently changes `buffer-chars-modified-tick'.

Fixes https://list.orgmode.org/so53mm$obe$1@ciao.gmane.io/T/#mad982a75885b1eda669d8cf7decee15c3917957b
2021-11-30 20:32:28 +08:00
Ihor Radchenko 8868f0fddd
org-archive-subtree: Speed up archiving
* lisp/org-element.el (org-element--cache-avoid-synchronous-headline-re-parsing):
  New internal variable controlling latency of cache
  `after-change-functions'.

(org-element--cache-for-removal): Use
`org-element--cache-avoid-synchronous-headline-re-parsing' to decide
if we re-parse changed headlines immidiately.
* lisp/org-archive.el (org-archive-subtree): Let-bind
`org-element--cache-avoid-synchronous-headline-re-parsing' to t while
archiving for better speed.
2021-11-30 20:17:56 +08:00
Ihor Radchenko d8a1f34cf6
org-element--current-element: Use explicit regexp to match headline
* lisp/org-element.el (org-element--current-element): Do not call
`org-at-heading-p' to determine if we are at headline element.
`org-at-heading-p' calls `beginning-of-line' and may match
non-headlines as headlines.
2021-11-30 20:17:56 +08:00
Ihor Radchenko 4a2cf81dfb
org-element--cache-for-removal: Fix handling edits before first section
* lisp/org-element.el (org-element--cache-for-removal): Consider edits
within blank before first section destructive and make cache delete
the section even though the edits are technically before its
beginning.
2021-11-30 20:17:55 +08:00
Ihor Radchenko c84c71b093
org-element-at-point: Report POM when parser throws error
* lisp/org-element.el (org-element-at-point): Mention the value of POM
in warning text when `org-element--parse-to' fails with error.
2021-11-27 12:20:33 +08:00