Commit Graph

25199 Commits

Author SHA1 Message Date
Ihor Radchenko 8f59e8d93f
Fix native-comp warnings
* lisp/org-fold.el (org-fold-show-set-visibility--text-properties):
Resolve unused variable warning.

* lisp/ob-core.el (org-attach-dir):
* lisp/ob-latex.el (org-at-heading-p):
(org-back-to-heading):
(org-next-visible-heading):
* lisp/org.el (org-agenda-todo-yesterday):
* lisp/ox-ascii.el (org-at-heading-p):
(org-back-to-heading):
(org-next-visible-heading):
* lisp/ox-html.el (org-at-heading-p):
(org-back-to-heading):
(org-next-visible-heading):
* lisp/ox-icalendar.el (org-at-heading-p):
(org-back-to-heading):
(org-next-visible-heading):
* lisp/ox-latex.el (engrave-faces-latex-gen-preamble-line):
(engrave-faces-get-theme):
(engrave-faces-latex-output-style):
(engrave-faces-current-preset-style):
(engrave-faces-latex-mathescape):
* lisp/ox-odt.el (org-at-heading-p):
(org-back-to-heading):
(org-next-visible-heading):
* lisp/ox-publish.el (org-at-heading-p):
(org-back-to-heading):
(org-next-visible-heading):
* lisp/ox.el (org-at-heading-p):
(org-back-to-heading):
(org-next-visible-heading): Add declarations.
2022-06-16 13:19:10 +08:00
Ihor Radchenko e273fa96e5
Fix function declarations
* lisp/org-macro.el (org-file-contents):
* lisp/ob-exp.el (org-in-commented-heading-p):
(org-in-archived-heading-p): Add missing argument to function
declarations.
2022-06-16 12:35:52 +08:00
Ihor Radchenko b061e7b61c
org-cite-list-citations: Cache footnote-definition searches
* lisp/oc.el (org-cite-list-citations): Avoid quadratic complexity.
Pre-calculate list of all footnote definitions and cache the footnote
label search hits.  Do not make `org-element-map' accumulate unused
result.
2022-06-16 10:43:29 +08:00
Ihor Radchenko 37a447ae08
org-element-map: Avoid repetitive `plist-get' call
* lisp/org-element.el (org-element-map): Do not call `(plist-get info
:ignore-list)' on every iteration.
2022-06-16 09:28:27 +08:00
Ihor Radchenko a158b263a6
org-export-data: Concatenate strings in temporary buffer for performance
* lisp/ox.el (org-export-data): Use temporary buffer to collect export
data instead of `mapconcat'.  Using buffer puts less load on garbage
collector.
2022-06-16 08:32:25 +08:00
Ihor Radchenko 3684c79672
doc/Makefile: Disable GC during export
* doc/Makefile (org.texi):
(orgguide.texi): Set `gc-cons-threshold` to `most-positive=fixnum' and
thus disable garbage collection while exporting manuals.  This reduces
the manual generation time.
2022-06-16 08:32:24 +08:00
Ihor Radchenko 076dd92acc
org-export-as: Do not update buffer settings when not modified
* lisp/ox.el (org-export-as): Use `buffer-chars-modified-tick' and
avoid extra invocations of `org-set-regexps-and-options' and
`org-update-radio-target-regexp' when the buffer is not changed.
Also, disable folding checks.  Folding is irrelevant inside export
buffer.
2022-06-16 08:32:20 +08:00
Ignacio Casso aa789b89d7
Do not mark buffer as modified with org-preserve-local-variables
* lisp/org-macs.el (org-preserve-local-variables): Do not mark buffer
as modified or alter `buffer-undo-list' when body does not actually
modify the buffer.

This commit fixes a bug with `org-copy-subtree', which marked the
buffer as modified and added an entry to the undo list when the visited
file had local variables.
2022-06-14 22:02:10 +08:00
Ignacio Casso f9ea6c61ed
Use `set-default-toplevel-value' in `defcustom' setters
* lisp/ob-lilypond.el (org-babel-lilypond-commands):
* lisp/ob-shell.el (org-babel-shell-names):
* lisp/org-capture.el (org-capture-templates):
* lisp/org-clock.el (org-clock-ask-before-exiting):
* lisp/org-duration.el (org-duration-units):
* lisp/org-faces.el (org-set-tag-faces):
* lisp/org-footnote.el (org-footnote-section):
* lisp/org-list.el (org-plain-list-ordered-item-terminator):
(org-list-allow-alphabetical):
* lisp/org.el (org-babel-do-load-languages):
(org-set-modules):
(org-export-backends):
(org-use-fast-todo-selection):
(org-enforce-todo-dependencies):
(org-enforce-todo-checkbox-dependencies):
(org-display-custom-times):
(org-set-packages-alist):
(org-set-emph-re):
* lisp/ox-odt.el (org-odt-schema-dir): Use
`set-default-toplevel-value' instead of `set' or `set-default' in
`defcustom' :set argument.

This commit fixes a bug that occurred when using an autoload function
inside a let-binding for a custom variable when the feature defining
both the function and the custom variable had not been loaded yet.

See bug#54399 and
https://lists.gnu.org/archive/html/emacs-orgmode/2022-03/msg00085.html,
https://lists.gnu.org/archive/html/emacs-orgmode/2022-06/msg00226.html
2022-06-14 21:54:45 +08:00
Ryan Scott 226119124d
ob-core.el/babel: Special handling for attachment links in src block
* ob-core.el (org-babel-merge-params): Specifying the symbol 'attach`
or string "'attach" as the value of the `:dir' header now functions as
":dir (org-attach-dir nil t) :mkdirp t".
(org-babel-result-to-file): Optional TYPE argument accepts symbol
'attachment to fixup up paths under `(org-attach-dir)' and use the
link type "attachment:" when that is detected.
(org-babel-insert-result): Pass symbol `attachment' as TYPE to
`org-babel-result-to-file'.
* org-attach.el (org-attach-dir): Added autoload header to simplify
dependencies necessary to support this feature (called in
`org-babel-merge-params').
* test-ob.el (test-ob-core/dir-attach): Added unit test for the new
attach feature.
2022-06-14 21:44:25 +08:00
Robert Pluim 3baac35b55 Don't quote symbols in defcustom types
* lisp/org-fold-core.el (org-fold-core-style):
* lisp/org-persist.el (org-persist-remote-files):
(org-persist-default-expiry):
Don't quote the symbol given as value for a const.
2022-06-14 16:05:17 +03:00
Ihor Radchenko 0cdbc63a0b
org-mode: Do not re-bind `bidi-paragraph-direction'
* lisp/org.el (org-mode): Remove the old performance workaround for
right-to-left text in Org buffers.  With newer Emacs settings, it is
the 'left-to-right value of `bidi-paragraph-direction' that causes the
slowdown; not the vice versa.

Old discussion on overriding the defaults:
https://lists.gnu.org/archive/html/emacs-devel/2011-09/msg00285.html
The new discussion with example file demonstrating the performance
problem:
https://orgmode.org/list/87a6iqo7x8.fsf@localhost
2022-06-14 13:16:15 +08:00
TEC ae168d5c8c
org-lint: don't complain about #+include URL
* lisp/org-lint.el (org-lint-wrong-include-link-parameter): When the
included file is a URL, skip the usual file checks.
2022-06-12 18:02:25 +08:00
TEC e3bf83fe82
ox: Support #+include-ing URLs
* lisp/ox.el (org-export--prepare-file-contents,
org-export--inclusion-absolute-lines): Replace instances of
`(insert-file-contents FILE)' with `(insert (org-file-contents FILE))',
as in `org--collect-keywords-1'.
(org-export-expand-include-keyword): Tweak to accept a URL as FILE, and
not perform the standard "file exists and is readable" check.

* etc/ORG-NEWS: Mention this change in behaviour.
2022-06-12 18:02:25 +08:00
Ihor Radchenko f5c9ce8f06
org-babel-exp-process-buffer: Disable edit control while processing
* lisp/ob-exp.el (org-babel-exp-process-buffer): Do not track buffer
changes in element cache and org-fold after-change hooks while
updating src blocks.  `org-babel-exp-process-buffer' makes a large
number of changes, which would overload the element cache and degrade
performance.
2022-06-12 14:11:11 +08:00
Ihor Radchenko 84c89ea7cb
org-export-resolve-id-link: Pre-cache all the ids in the parse tree
* lisp/ox.el (org-export-resolve-id-link): Pre-cache all the ids in
the parse tree for faster lookup.
2022-06-12 13:32:35 +08:00
Ihor Radchenko 792cd4b0a6
org-export-resolve-fuzyy-link: Pre-cache all possible search cells
* lisp/ox.el (org-export-resolve-fuzzy-link): Before matching LINK,
pre-process and cache all the non-nil search cells in the parse tree.
When matching, use the pre-processed info.  Fix the :test function for
the cache hash table.
2022-06-12 13:06:47 +08:00
Ihor Radchenko f51c286716
org-export-get-footnote-definition: Pre-cache references in parse tree
* lisp/ox.el (org-export-get-footnote-definition): Pre-process parse
tree once to filter out all non-footnote elements.  This speeds up
subsequent footnote definition searches.
2022-06-12 13:05:16 +08:00
Ihor Radchenko 147ca39750
org-in-commented-heading-p: Do not parse section unless already cached
* lisp/org.el (org-in-commented-heading-p): When element at point is
not yet in cache, parse the parent headline instead of also parsing
section up to point.
2022-06-12 13:04:25 +08:00
Ihor Radchenko 2f8e688516
org-back-to-heading-or-point-min: Rely less on cache
* lisp/org.el (org-before-first-heading-p): Do not try to parse the
whole section when there is no cached element at point.
2022-06-12 13:03:30 +08:00
Ihor Radchenko 8a0b03fb3b
org-element-headline-parser: Fix headings like * COMMENTnospace
* lisp/org-element.el (org-element-headline-parser): Do not parse
headings like * COMMENTnospace as commented.
2022-06-12 13:02:39 +08:00
Ihor Radchenko ed6f8dc67f
org-list: Do not move point and change space when promoting/demoting items
* lisp/org-list.el (org-list-struct-apply-struct): Make sure the
origin marker is not moved to bol when promoting/demoting item in
special case:
 - item
 - <point> ::
Do not remove the trailing space after point as well.
(org-insert-item): Do not expect point to remain at bol after writing
list struct.

* testing/lisp/test-org-list.el (test-org-list/indent-item): Add tests.

Fixes https://orgmode.org/list/87o88hlkvv.fsf@gmail.com
2022-06-11 20:17:29 +08:00
Robert Pluim a8b32247d9
doc/org-manual.org: Reference org-cyclic and org-block
* doc/org-manual.org (Footnotes): Add `org-cyclic' and `org-block' to
note about org diary functions.  Add function indices for `org-date',
`org-anniversary', `org-cyclic', and `org-block'.
2022-06-11 12:48:48 +08:00
Ihor Radchenko 3825ca6ccb
Fix make doc failure introduced by 93821b431
* lisp/org-element.el (org-element--cache-for-removal): Parse
secondary :title value required by exporter.

See https://list.orgmode.org/87mtek1t63.fsf_-_@gmail.com/T/#md63481c471181c96dfb6248c1551fba219b11f30
2022-06-10 23:01:08 +08:00
Sébastien Miquel 1425a86ae7 org.el: With an active region, act with latex-preview
* lisp/org.el (org-latex-preview): With an active region, display
images for all fragments in the region. With universal prefix
argument, remove all images in the region.
2022-06-10 17:30:44 +03:00
Ihor Radchenko 57d64cf78c
Date/time prompt: Allow input of relative time in hours (e.g. +1h)
* lisp/org.el (org-read-date-analyze): Match relative hour specifier.

Fixes https://orgmode.org/list/C9A76EFA-1D76-4C5D-941D-AFA288A64CD0@icloud.com
2022-06-09 21:36:15 +08:00
Rudolf Adamkovič d9963c58dc
lisp/ol.el: Fix shadowed radio targets
* lisp/ol.el (org-update-radio-target-regexp): Sort radio targets
before building the regexp that matches them.
* testing/lisp/test-org.el: Test shadowed radio targets.  The bug
occurs when two targets share the same prefix and when and the longer
target appears first.
2022-06-09 16:22:44 +08:00
Ihor Radchenko 0e7033e0ca
org-capture: Expand sexps in template with Org mode being active
* lisp/org-capture.el (org-capture-fill-template): Enable `org-mode'
in the temporary template expansion buffer.  Update docstring
accordingly.
(org-capture-templates): Clarify that %(sexp) expansion happens in a
temporary Org mode buffer.

Fixes https://orgmode.org/list/CABUh-776V-_+_JAZwcKQm9ATcs0WUV9SmGwjooGFbt=CtwQj8g@mail.gmail.com
2022-06-09 16:12:38 +08:00
Ihor Radchenko 4487acc630
org-element-cache: Do not compare buffer positions with cache keys
* lisp/org-element.el (org-element--cache-key-less-p): Clarify that
comparison between buffer points and cache keys is not reliable.
(org-element--cache-find): Do not compare POS with cache keys.
(org-element-at-point): Use cache BEG field to determine the cached
buffer portion.
2022-06-09 15:10:18 +08:00
Ihor Radchenko 819409baab
org-get-buffer-tags: Improve performance
* lisp/org.el (org-get-buffer-tags): Use hash table to accumulate
unique tags only.  The old approach also used hash tables under the
hood of `delete-dups', but required extra memory allocation to store
the full tag list.
2022-06-09 15:07:49 +08:00
Ihor Radchenko 93821b431c
org-element--cache-for-removal: Improve performance
* lisp/org-element.el (org-element--cache-for-removal): Directly check
for headline at point instead of running full
`org-element--current-element' that is matching a large number of
regexps.
2022-06-09 15:07:38 +08:00
Ihor Radchenko 46df681336
org.el: Improve performance of deletion commands
* lisp/org.el (org-delete-char):
(org-delete-backward-char): Wrap into
`org-fold-core-ignore-modifications'.  These commands are for
interactive use anyway and they have no risk of not inheriting folding
properties.
2022-06-09 15:07:29 +08:00
Ihor Radchenko 96746438c0
org-element--cache-find: Do not hash section/org-data/table elements
* lisp/org-element.el (org-element--cache-find): Never use hashed
elements with children that can have the same :begin property.
2022-06-09 15:07:04 +08:00
Ihor Radchenko c02c0d660d
org-do-emphasis-faces: Remove link folds if any
* lisp/org.el (org-do-emphasis-faces): Reveal hidden parts of links
fontified by `org-activate-link', if any.

Partially fixes
https://list.orgmode.org/t7np1d$vu8$1@ciao.gmane.io/T/#u
The proper fix should also involve `org-activate-link' not hitting
false-positives inside verbatim.
2022-06-08 21:39:19 +08:00
Nick Dokos 9fd5349d0a
org-lint: Fix invocation with C-u prefix argument
* lisp/org-lint.el (org-lint): Fix the order of the arguments in
the `assoc-string' call when calculating the list of checkers to
invoke.

`C-u M-x org-lint' was failing to run any checkers, no matter what
category of checkers was chosen, because the calculation of the list
of checkers always returned `nil'.
2022-06-08 21:26:31 +08:00
Daniel Fleischer 1105da80a7 doc/org-manual.org: variable rename
* doc/org-manual.org: (invisible edits) org-fold-catch-invisible-edits

Suggested-by: Yury Kholodkov <marleng@disroot.org>
2022-06-06 09:34:30 +03:00
Leo Vivier cde5c5d78f
lisp/org-persist.el (org-persist-gc): Fix pcase pattern
* lisp/org-persist.el (org-persist-gc): Fix pcase pattern.

Otherwise, `(pred #'numberp)' expands to `(function numberp foo)'
where foo is the first arg of pcase.
2022-06-04 19:13:58 +08:00
Ihor Radchenko e156e54251
org-clone-local-variables: Prevent carrying over cache data
* lisp/org-macs.el (org-unique-local-variables): Add newly added cache
variables.  They must not be copied by `org-clone-local-variables'.
Otherwise, random failure may happen when cache does not correspond to
the buffer text.
2022-06-04 11:51:00 +08:00
Ihor Radchenko 548632a15e
fixup! org-element: Implement tree search caching 2022-06-03 22:09:07 +08:00
Bastien 7c5132938f Merge branch 'bugfix' 2022-06-03 08:38:29 +02:00
Bastien e0b05b0752 lisp/org.el: Bump version to 9.5.4 2022-06-03 08:37:30 +02:00
Ihor Radchenko 962b796900
org-element: Implement tree search caching
* lisp/org-element.el (org-element--cache-hash-size):
(org-element--cache-hash-statistics):
(org-element--cache-hash-nocache):
(org-element--cache-hash-size):
(org-element--cache-hash-left):
(org-element--cache-hash-right): Implement recent search cache for
`org-element--cache-find'.  The cache stores recent cache tree queries
as a vector with O(1) access time.

(org-element--cache-find): Make use of `org-element--cache-hash-left'
and `org-element--cache-hash-right' when cached query element starts
at POS and SIDE is nil.  Record statistics.

(org-element-cache-reset): Reset search cache on init.

(org-element-cache-hash-show-statistics): Provide a command reporting
the new caching efficiency.  Can be used for debugging/survey
purposes.

* lisp/org-macs.el (org-knuth-hash): Implement multiplicative hash
function.

Preliminary testing reveals that this simple strategy can reduce query
time from O(Log N) down to O(1) for ~30%-50% cache queries.
2022-06-03 09:59:58 +08:00
Ihor Radchenko b18635f745
org-persist: Disable when Emacs is called with -Q arg
* lisp/org-persist.el (org-persist-disable-when-emacs-Q): New
variable.
(org-persist-gc):
(org-persist-read):
(org-persist-write): Do nothing when
`org-persist-disable-when-emacs-Q' is non-nil and
`emacs-user-directory' is nil.
2022-06-02 11:06:53 +08:00
TEC 4197fcc641
org-plot: Run `org-plot/gnuplot-script' in org buf
* lisp/org-plot.el (org-plot/gnuplot): Instead of running
`org-plot/gnuplot-script' in a temp buffer, run it in the original Org
buffer to preserve file-local variables in the event the user has
configured `org-plot/gnuplot-term-extra' or
`org-plot/gnuplot-script-preamble' to functions that reply on local
variables.
2022-06-01 23:48:25 +08:00
Ihor Radchenko 4dda0d7a8d
org-element: Fix org-element-timestamp-parser for incomplete ranges
* lisp/org-element.el (org-element-timestamp-parser): Use more strict
regexp to match second timestamp in timestamp--timestamp range.

Fixes https://list.orgmode.org/orgmode/87tuh88kjv.fsf@localhost/
2022-05-30 19:42:34 +08:00
Ihor Radchenko 1525a5a64e
org-babel-load-file: Do not rely on `org-babel-tangle-file' making changes
* lisp/org.el (org-babel-load-file): Update modification time even
when `org-babel-tangle-file' does not actually modify the tangled
file.  This makes sure that modify-time comparison logic does not make
Org re-tangle Org file that had been changed but the changes did not
affect the tangled code.

See https://orgmode.org/list/t5j75h$dbo$1@ciao.gmane.io
2022-05-30 11:02:08 +08:00
Ihor Radchenko f6f26d4ce4
org-babel-tangle: Do not overwrite when contents does not change
* lisp/ob-tangle.el (org-babel-tangle): Do not overwrite existing
tangled files if their contents is exactly the same as we are going to
write during tangle process.  This avoids unneeded disk writes and can
speed up tangling significantly when many small files are tangled from
a single .org source.

An example of performance improvement when tangling an .org file into
~200 files:
(benchmark-run 10 (org-babel-tangle))
Before the commit (on SSD): (76.33826743 8 11.551725374)
After the commit:           (43.628606052 4 5.751274237)
2022-05-30 11:02:07 +08:00
Ihor Radchenko a407a89c5f
org-footnote.el:org-footnote-section: Fix typo in docstring
Reported in https://list.orgmode.org/c43cc980-108a-176b-accc-e5649264ba53@gmail.com/T/#u
2022-05-29 20:55:01 +08:00
Ihor Radchenko d37e4dc0f2
ox-latex: Scale inlinetasks according to column width
* lisp/ox-latex.el (org-latex-format-inlinetask-default-function): Set
inlinetask box width relative to \linewidth in current column.  Using
\textwidth scales the box wider than column in multi-column documents.
2022-05-29 18:06:12 +08:00
Ihor Radchenko 66528468a1
org-src-font-lock-fontify-block: Do not transfer non-existing properties
* lisp/org-src.el (org-src-font-lock-fontify-block): Never set
font-lock properties when `get-text-property' returns nil.  This
usually means that the property is not present in the position
property list.  The old behavior could, for example, set 'invisible
property to nil explicitly and prevent folding completely.

Fixes https://list.orgmode.org/CA+G3_PN6RvcRcvN2fM=vfK1K6UsT=nNPJ7SUucmA1Ypc=Emorg@mail.gmail.com/T/#u
2022-05-28 09:35:32 +08:00