Commit graph

907 commits

Author SHA1 Message Date
Kyle Meyer 1e353648ef Merge branch 'bugfix' 2023-12-04 23:33:47 -05:00
Kyle Meyer 3cdb637fcf Merge branch 'km/from-emacs-29' into bugfix 2023-12-04 23:27:04 -05:00
Stefan Kangas dc1230a3b5 Backport commit 5f923ff1a from Emacs
; Fix typos
5f923ff1a6a8a9ff6f06dc49c8e0e2ceee111567
Stefan Kangas
Sun Dec 3 23:31:30 2023 +0100
2023-12-04 23:23:45 -05:00
Ihor Radchenko 08c9664a42
Merge branch 'bugfix' 2023-12-04 15:52:16 +01:00
Ihor Radchenko a5e3a06b2e
org-element--cache-process-request: Fix edge case
* lisp/org-element.el (org-element--cache-process-request): Avoid
applying OFFSET during Phase 3 twice in already offseted elements that
are before an obsolete element.

Reported-by: Sharon Kimble
2023-12-04 15:51:43 +01:00
Ihor Radchenko 4b1154e32d
lisp/org-element.el: Use consistent warning types for warnings
(org-element--cache-log-message):
(org-element--cache-warn): Use org-element warning type.
(org-element-at-point): Assign warning type.
2023-11-23 13:09:51 +02:00
Ihor Radchenko 5bbd58d34f
* lisp/org-element.el: Fix checkdoc warnings
(org-element--cache-persist-after-read): Make docstring less than 80
columns wide.
* lisp/org-persist.el (org-persist-load): Document all the function
arguments.
2023-11-13 11:28:55 +02:00
Ihor Radchenko 6f960f3c6a
* lisp/org-element.el: Fix checkdoc warnings
(org-element-inlinetask-parser): Document LIMIT function argument.
(org-element--list-struct): Add docstring.
(org-element-map): Capitalize Lisp.
(org-element--cache-diagnostics-ring): Make docstring 80 chars wide
with single sentence as the first line.
(org-element--cache-log-message):
(org-element--cache-warn):
(org-element--cache-active-p):
(org-element--cache-after-change):  Document the function arguments.
(org-element--parse-to):
(org-element-cache-map): Do not put "." at the end of error messages.
(org-element--cache-avoid-synchronous-headline-re-parsing): Escape (
at bol in the docstring.
(org-element--cache-persist-before-write):
(org-element--cache-persist-before-read):
(org-element--cache-persist-after-read): Add detailed docstring and
document all the function arguments.
2023-11-11 13:34:47 +02:00
Ihor Radchenko 089fda1219
Merge branch 'bugfix' 2023-11-05 17:51:55 +02:00
Ihor Radchenko bf7a0cdcef
* lisp/org-element.el (org-element--cache-remove): Fix `throw' error symbol 2023-11-05 17:50:36 +02:00
Ihor Radchenko fac55324ac
org-element-at-point: Demote error to warning when called from non-Org buffer
* lisp/org-element.el (org-element-at-point): Do not throw an error
when `org-element-at-point' is called from non-Org buffer.  A number
of third-party packages are incorrectly using `org-element-at-point'
this way, relying upon `org-element-at-point' working in certain
scenarios.  Throwing an error (as was done previously) made an urgent
call to fix this problem, even when `org-element-at-point' happened to
work in a particular scenario.  Now, we just display a warning to give
package author more time to address or work around this.

See https://github.com/alphapapa/org-web-tools/issues/61:

    @yantar92 I understand why this change was made, but perhaps it
    was a bit premature, given how much breakage it's causing
    downstream? It would seem appropriate to at least make it a
    warning for a full major version before making it an error, to
    give downstream devs and users a break.
2023-11-05 14:12:54 +02:00
Ihor Radchenko 9c255cacfe
org-element-ignored-local-variables: Add missing variables
This fixes ox-hugo bug when Org buffer copy cache is corrupted.

* lisp/org-element.el (org-element--cache-variables): Add
more state variables.  Move above
`org-element-ignored-local-variables' definition.
(org-element-ignored-local-variables): Make use of the value of
`org-element--cache-variables'.
*
testing/lisp/test-org-element.el (test-org-element/cache-ignored-locals):
Add guard against adding new cache state variables that are not listed
in `org-element--cache-variables'.

Reported-by: George Kettleborough <kettleg@gmail.com>
Link: https://orgmode.org/list/41acf96e-8f62-4ed5-9853-b4ff4e0e2fa9@gmail.com
2023-10-25 11:00:51 +03:00
Ihor Radchenko b3c8a7c360
* lisp/org-element.el (org-element-entity-parser): Add comment 2023-10-19 11:17:58 +03:00
Ihor Radchenko e34d7781f0
org-element-entity-parser: Refactor entity regexp using `rx'
* lisp/org-element.el (org-element-entity-parser): Rewrite entity
regexp using more readable `rx' form.
* testing/lisp/test-org-element.el (test-org-element/entity-parser):
Add new test cases for whitespace entities.
2023-10-19 11:15:45 +03:00
Ihor Radchenko 73485aa063
org-element-parse-secondary-string: Fix Emacs 27 compatibility
* lisp/org-compat.el (org-get-buffer-create): Add compatibility
function.
* lisp/org-element.el (org-element-parse-secondary-string):
* lisp/org-id.el (org-id-find-id-in-file): Use it.

Reported-by: Yasushi SHOJI <yasushi.shoji@gmail.com>
Link: https://orgmode.org/list/CAELBRWJUQ=kupUbYev_W9dqEmYKnN3400t+W4_Q69EHNp-KMgA@mail.gmail.com
2023-10-16 11:24:29 +03:00
Ihor Radchenko 0d214ef008
org-element--current-element: Fix edge case with affiliated keywords
* lisp/org-element.el (org-element--collect-affiliated-keywords): Fix
edge case when a keyword matching affiliated keyword is preceding an
element that is not allowed to have such.  We need to handle this case
specially here rather than in `org-element--current-element' to avoid
the default paragraph fallback.
(org-element--current-element): Add a comment describing the pitfall.
*
testing/lisp/test-org-element.el (test-org-element/affiliated-keywords-parser):
Add more tests.

Reported-by: Tom Alexander <tom@fizz.buzz>
Link: https://orgmode.org/list/e2be976d-1bcf-4136-9968-33212dcd1f83@app.fastmail.com
2023-10-13 15:14:57 +03:00
Ihor Radchenko 0e3d0e3d19
org-element--collect-affiliated-keywords: Fix keywords before comment
* lisp/org-element.el (org-element--collect-affiliated-keywords):
Disallow affiliated keywords before a comment.
*
testing/lisp/test-org-element.el (test-org-element/affiliated-keywords-parser):
Add new test.
*
testing/lisp/test-org-element.el (test-org-element/cache-affiliated):
Fix test.

Reported-by: Tom Alexander <tom@fizz.buzz>
Link: https://orgmode.org/list/87c20267-d12e-4641-a1eb-3a7ac8181069@app.fastmail.com
2023-10-12 14:24:35 +03:00
Ihor Radchenko 07ae6ba58d
* lisp/org-element.el (org-element--current-element): Add a comment 2023-10-12 14:24:24 +03:00
Ihor Radchenko 9ba1fc778a
* lisp/org-element.el (org-element--cache-sync): Do not reset cache warning
Do not reset `org-element--cache-change-warning' at the end of
synchronization.  It is an error to do so if synchronization is
called while submitting a new request.

Add the comment in the code.

The test logs used to narrow down the error are not public.

Reported-by: Paul Stansell <paulstansell@gmail.com>
Link: https://list.orgmode.org/orgmode/CAMJKaZz12j-qm5tzjZyg1sLfhN-Z1Cqzy65sbARxty_xHeMfmg@mail.gmail.com/
2023-10-12 14:01:52 +03:00
Ihor Radchenko fba3fd56c4
org-element-org-data-parser: Allow leading blank lines before property drawer
* lisp/org-element.el (org-element--get-global-node-properties):
(org-element-org-data-parser):
(org-element--current-element): Allow blank lines at the beginning of
Org document.  Blank lines where allowed in the past (:contents-begin
started after the blank lines), but it was previously not possible to
have top-level property drawer in an Org document starting from blank
lines.  Now, it is possible.

* testing/lisp/test-org-element.el (test-org-element/org-data-parser):
Add new tests.

Reported-by: Tom Alexander <tom@fizz.buzz>
Link: https://orgmode.org/list/0ec8c4ae-4f5b-4e37-8c5c-f92ef497a461@app.fastmail.com
2023-10-12 13:34:08 +03:00
Ihor Radchenko a52c74e962
org-element-org-data-parser: Fix deferred property parsing
* lisp/org-element.el (org-element--get-node-properties): Pass parent
element as a new optional argument to derive relative offset from.
Calculate deferred property values according to the :begin of the
parent element.
(org-element--headline-deferred):
(org-element--get-global-node-properties): Explicitly pass the parent
headline/org-data to calculate deferred offsets correctly.

Reported-by: Tom Alexander <tom@fizz.buzz>
Link: https://orgmode.org/list/0ec8c4ae-4f5b-4e37-8c5c-f92ef497a461@app.fastmail.com
2023-10-12 13:31:49 +03:00
Ihor Radchenko f660afc506
fixup! org-element-parse-secondary-string: Prevent altering current buffer cache
Get rid of `org-export..' function call.
2023-10-12 11:16:59 +03:00
Ihor Radchenko fe23bec607
* lisp/org-element.el (org-element-subscript-parser): Fix edge case
Fix when both subscript and underline object match in
`org-element--object-lex'.
*
testing/lisp/test-org-element.el (test-org-element/underline-parser):
Add new test.

Reported-by: Tom Alexander <tom@fizz.buzz>
Link: https://orgmode.org/list/dad964f5-c764-4dd5-9829-ca38e3fbeb0d@app.fastmail.com
2023-10-10 15:05:38 +03:00
Ihor Radchenko 37d6bde27f
org-element-parse-secondary-string: Prevent altering current buffer cache
* lisp/org-element.el (org-element-ignored-local-variables):
* lisp/ox.el (org-export-ignored-local-variables):
* lisp/org-compat.el (org-export-ignored-local-variables): Rename and
move to org-element.el.  Declare the old name obsolete.
* lisp/org-element.el (org-element--generate-copy-script):
* lisp/ox.el (org-export--generate-copy-script): Rename and move to
org-element.el.
* lisp/org-element.el (org-element-copy-buffer):
(org-element-with-buffer-copy): New function and macro like
`org-export-copy-buffer' and `org-element-with-buffer-copy', but not
processing #+bind keywords.
(org-element-parse-secondary-string): Use
`org-element-with-buffer-copy' that takes care about not copying
element cache object by reference and thus not modifying that cache if
the buffer happens to be modified.
* lisp/ox.el (org-export--set-variables): New helper function that
sets an alist of variable/value pairs in current buffer.
(org-export-copy-buffer): Make use of `org-element-copy-buffer'.
(org-export-with-buffer-copy): Make use of
`org-element-with-buffer-copy'.

Reported-by: Edgar Lux <edgarlux@mailfence.com>
2023-10-10 13:53:07 +03:00
Ihor Radchenko 4edfb69f86
* lisp/org-element.el (org-element--cache-for-removal): Add more logging
Log cache warning value when updating robust cached elements.
2023-10-06 14:27:22 +03:00
Ihor Radchenko 7efd5bba0a
org-element-cache: Add switch to verify cache before writing to disk
*
lisp/org-element.el (org-element--cache-self-verify-before-persisting):
New internal variable toggling full verification pass before writing
cache to disk.

* lisp/org-element.el (org-element--cache-persist-before-write):
Verify cache and throw error on failure when
`org-element--cache-self-verify-before-persisting' is non-nil.
2023-09-22 11:42:52 +03:00
Ihor Radchenko 266aac1186
org-element--cache-persist-before-write: Warn when writing incorrect cache
* lisp/org-element.el (org-element--cache-persist-before-write): When
the cache being written has elements without parent, warn the user.
2023-09-20 14:22:31 +03:00
Ihor Radchenko 2e5db7a591
org-element-cache: Catch problems with persistent cache and abort loading
* lisp/org-element.el (org-element--cache-persist-after-read): When
the persistent cache has elements without parent, do not use such
cache and report a warning to user.
2023-09-16 11:52:27 +03:00
Ihor Radchenko e90a8a69a7
org-element-cache: Log recovered persisted elements during loading
* lisp/org-element.el (org-element--cache-persist-before-read):
(org-element--cache-persist-after-read): Record diagnostics messages
when loading persistent cache.
2023-09-15 13:30:27 +03:00
Ihor Radchenko 20162f5a5c
org-element-dynamic-block-open-re-nogroup: Demand block name
* lisp/org-element.el (org-element-dynamic-block-open-re-nogroup): Fix
inconsistency with `org-element-dynamic-block-open-re' - block name is
mandatory.
*
testing/lisp/test-org-element.el (test-org-element/dynamic-block-parser):
Add test.
2023-09-12 11:15:17 +03:00
Allen Li c905565fa8
org-element: Raise gc-cons-threshold for org-element-cache-map
This garbage collects many times when calling
`org-get-buffer-tags' (such as during tag completion) in a large file
with many tags.  Raise `gc-cons-threshold' as this may affect other
callers in large files.

Note that `org-element-parse-buffer' also raises `gc-cons-threshold'
as a precedent.

This has no effect on most callers and increases performance for
extreme cases.

* lisp/org-element.el (org-element-cache-map): Raise
`gc-cons-threshold'.
2023-08-23 12:54:43 +03:00
Ihor Radchenko 53c9d91d3c
org-element: Fix post-blank shared between items
* lisp/org-element.el (org-element-item-parser): Do not parse beyond
LIMIT - they may extend :post-blank beyond parent list contents.
(org-element-plain-list-parser): Make sure that plain list always owns
the trailing blank lines.
(org-element-cache-version): Bump cache version.
* testing/lisp/test-org-element.el (test-org-element/item-parser): Add
test.

Reported-by: Tom Alexander <tom@fizz.buzz>
Link: https://orgmode.org/list/1c833eb8-c556-437b-ac5b-be360ebcc869@app.fastmail.com
2023-08-22 11:25:59 +03:00
Ihor Radchenko 7219b006bd
org-element: Fix loading obsolete persistent caches
* lisp/org-element.el (org-element-cache-version): New constant
defining the current cache version.
(org-element-cache-reset): Use the new variable.
* lisp/org.el (org-mode): Assert loading the correct cache version.

Reported-by: Gregor Zattler <telegraph@gmx.net>
Link: https://orgmode.org/list/87350cvm3d.fsf@no.lan
2023-08-21 13:24:41 +03:00
Ihor Radchenko f86a2fb726
org-element--string-cache: Use hash table instead of obarray
* lisp/org-element.el (org-element--string-cache): Change the value to
hash table.  Update the docstring.
(org-element--get-cached-string): Use hash table.

obarrays have a number of rough edges when used for purposes other
than interning symbols.  Using obarrays may cause unexpected problems
and hash tables are preferred.  Credit: Stefan Monnier.
2023-08-20 10:14:57 +03:00
Ihor Radchenko f1359546ad
org-element-at-point: Throw an error when not in org-mode
* lisp/org-element.el (org-element-at-point): Explicitly throw an
error when not in org-mode buffer.  The parser expects certain
buffer-local constants and may fail otherwise.  It is better to
indicate the problem explicitly instead of dealing with cryptic
generic errors.
(org-element-plain-list-interpreter):
* testing/lisp/test-ox.el (test-org-export/expand-include/links): Make
sure that we never invoke parser in non-Org buffers.
2023-08-18 11:11:17 +03:00
Ihor Radchenko 933d282881
Fix Emacs 27 false-positive warnings
* lisp/org-element-ast.el (org-element--plist-property): Shield
annoying warning spam with `with-no-warnings'.  The warnings are not
present in newer Emacs.
* lisp/org-element.el (org-element--interpret-affiliated-keywords):
Suppress warning about two token unused `_' arguments.
* lisp/org-id.el (org-id-find-id-in-file): Suppress warning about
number of arguments.
2023-08-18 11:08:56 +03:00
Ihor Radchenko e4504853b5
Merge branch 'bugfix' 2023-08-16 11:43:12 +03:00
Ihor Radchenko 27a41d418d
org-element--cache-before-change: Fix edge case creating heading
* lisp/org-element.el (org-element--cache-before-change): Fix edge
case when a heading is created because we insert a newline right
before ****.
* testing/lisp/test-org-element.el (test-org-element/cache-headline):
Add tests.

Reported-by: Rodrigo Morales <moralesrodrigo1100@gmail.com>
Link: https://orgmode.org/list/CAGxMbPbbqc33iaqJ=EceyKrLaf4maJAxaUmJGaPOvG_Rpw+xcQ@mail.gmail.com
2023-08-16 11:41:31 +03:00
Ihor Radchenko 54c09c84e9
org-element-context: Fix when point is at the beginning of parsed value
* lisp/org-element.el (org-element-context): When point is at the
first point in parsed affiliated keyword value, do not return parent
"keyword".

Reported-by: Tom Gillespie <tgbugs@gmail.com>
Link: https://orgmode.org/list/CA+G3_PNt7WqkCzChV+dx1FeSPgTEVkNSE41a3qC5wv3g+jTwrQ@mail.gmail.com
2023-08-16 11:06:08 +03:00
Ihor Radchenko 572d01ab7e
Merge branch 'bugfix' 2023-08-15 12:59:18 +03:00
Ihor Radchenko 561c1d0db0
org-element-at-point: Fix cache initialization in indirect buffer
* lisp/org-element.el (org-element-at-point): Always check cache
variable in base buffer.

Reported-by: Adam Beckmeyer <adam_git@thebeckmeyers.xyz>
Link: https://orgmode.org/list/E1qVc9n-0006Ti-92@rmmprod06.runbox
2023-08-15 11:52:26 +03:00
Ihor Radchenko e340dde63e
org-element-export-snippet-parser: Fix when no closing @@
* lisp/org-element.el (org-element-export-snippet-parser): Return nil
when there is no closing @@.
* testing/lisp/test-org-element.el (test-org-element/context): Add
test.

Reported-by: Tom Alexander <tom@fizz.buzz>
Link: https://orgmode.org/list/fb61ea28-f004-4c25-adf7-69fc55683ed4@app.fastmail.com
2023-08-15 11:37:37 +03:00
Ihor Radchenko 1c7444dc3a
org-element: Bump AST version
* lisp/org-element.el (org-element-cache-reset): Bump AST version to
avoid clashes with previous caches after bfe1179dc.
2023-08-11 12:48:24 +03:00
Ihor Radchenko bfe1179dcb
org-element: Fix consistency between incremental and recursive parsers
* lisp/org-element.el (org-element--parse-to): Remove numerous special
conditions added to satisfy tests in `test-org-element/at-point'.
They create divergence with `org-element-parse-buffer' by sometimes
parsing inner elements up to beyond parent's :contents-end.  Instead,
modify org-data, section, and headline parsers to make their contents
include trailing blank lines.  This way, `org-element-at-point' will
naturally transcend inside section at the end of a heading.
(org-element-headline-parser):
(org-element-org-data-parser):
(org-element-section-parser): Span :contents-end all the way up to
:end.  Set :post-blank to 0 all the time.  Adjust :robust-end.
(org-element--open-end-p): Remove no longer used function.

Reported-by: Tom Alexander <tom@fizz.buzz>
Link: https://orgmode.org/list/6dd08eb7-9468-402d-bf88-eefb01442b99@app.fastmail.com
2023-08-11 12:09:36 +03:00
Ihor Radchenko 453c47b57d
fixup! org-element--cache-for-removal: Fix changing heading granularity
* lisp/org-element.el:
(org-element--cache-for-removal): Explicitly assign :granularity to
not deceive parser when parsing for different granularity than cache.
Cache is always using 'element granularity.

This commit is only needed on bugfix.  On main, :granularity is set
correctly.
2023-08-05 11:14:26 +03:00
Ihor Radchenko 2c4c5fdd8b
Merge branch 'bugfix' 2023-08-03 08:29:54 +03:00
Ihor Radchenko bf45090f4c
org-element--cache-for-removal: Fix changing heading granularity
* lisp/org-element.el (org-element--cache-for-removal): Do not update
heading using object granularity.  `org-element-at-point' parses
headings without :title objects and cache updates should not change
this.
2023-08-03 08:28:01 +03:00
Ihor Radchenko 28b6a231e9
org-element-normalize-contents: Fix when ELEMENT is anonymous
* lisp/org-element.el (org-element-normalize-contents): Use
`org-element-set-contents' to set contents instead of assuming
(TYPE PROP CONTENTS) structure.
2023-08-02 12:04:30 +03:00
Ihor Radchenko 1967aa43e5
org-src-preserve-indentation: Refactor handling src block flags
* lisp/org-src.el (org-src-preserve-indentation-p): New function
checking whether block should preserve indentation.  This function
abstracts away the check for block type, indentation flag, and
customized `org-src-preserve-indentation' value.
(org-src--edit-element):
* lisp/ob-core.el (org-babel--normalize-body):
(org-babel-read-element):
(org-babel-update-block-body):
* lisp/ob-exp.el (org-babel-exp-process-buffer):
* lisp/org-element.el (org-element-example-block-interpreter):
(org-element-src-block-interpreter):
* lisp/org.el (org-fixup-indentation):
(org-indent-region):
* lisp/ox.el (org-export-unravel-code): Use the new function instead
of duplicating code.

* lisp/ob-haskell.el (org-babel-haskell-export-to-lhs): Add FIXME.  We
do not have access to the block element here and cannot easily check
the flag.

* lisp/ob-tangle.el (org-babel-tangle-single-block):
* lisp/org-src.el (org-src-font-lock-fontify-block):
* lisp/org.el (org-indent-line): Check block flag in addition to `org-src-preserve-indentation'.

This commit unifies logic deciding whether to preserve block
indentation into a single place to avoid confusion.
2023-07-13 11:51:15 +03:00
Ilya Chernyshov c74c4ab18d
lisp/org-element.el: Add new timestamp property :range-type
The new property is needed to reduce ambiguity when interpreting the
parsed data.

* lisp/org-element.el (org-element-timestamp-interpreter): Preserve old
behavior when :range-type is `nil'.  Take into account :range-type
value when interpreting ranges.  When :range-type is `timerange',
return a timerange (<YYYY-mm-DD HH:MM-HH:MM>).  If :range-type is
`daterange' return a daterange (<...>--<...>).  When :range-type is
nil, return a daterange (as it was before).  When :range-type is
`daterange' or `timerange' and :type is `active'/`inactive', throw an
error.
(org-element-timestamp-parser): Add :range-type property.

* lisp/org.el (org-timestamp-split-range): Make sure that :range-type
is nil for a split timestamp.

* testing/lisp/test-org-element.el
(test-org-element/timestamp-interpreter): Add new tests.
(test-org-element/timestamp-parser): Add tests for :range-type
property.

* etc/ORG-NEWS (Major changes and additions to Org API): Add news about this property.

Link: https://list.orgmode.org/orgmode/87y1ot6dqz.fsf@gmail.com/
2023-07-12 11:12:46 +03:00