Commit Graph

979 Commits

Author SHA1 Message Date
Ihor Radchenko 2289739ed4
Prefer `write-region' to `save-file'
* lisp/ob-haskell.el (org-babel-haskell-export-to-lhs): Use
non-interactive `insert-file-contents' + `write-region' to avoid
triggering various interactive hooks.  Ensure that temp files are
always deleted.
* lisp/org-agenda.el (org-agenda-write):
* lisp/org-table.el: Simplify code using `write-region'.
* lisp/ox-odt.el (org-odt-template): Use `insert-file-contents' +
`write-region' instead of `find-file-noselect' that may trigger
various hooks.  The new approach makes `revert-buffer' not
necessary (and do not trigger `revert-buffer' hooks).  Also, the
problem with backups will no longer exists.

Original idea: https://list.orgmode.org/orgmode/20221002035931.12191-1-dafydd.lukes@gmail.com/
2023-04-02 16:25:44 +02:00
Ihor Radchenko 15c519b84c
Do not assume that `org-string-width' preserves match data
* lisp/org-table.el (org-table-blank-field):
(org-table-clean-line): Avoid `org-string-width' modifying match data.

As long as `org-string-width' creates a new window buffer, third-party
modes and Emacs distributions might modify the match data in buffer
hooks.  Hence, we cannot assume that match data is not modified even
though `org-string-width' code itself does not alter the match data.

Note: Adding `save-match-data' around function calls is generally a
good practice when the surrounding code relies on the match data being
intact.  Elisp conventions don't prohibit functions to modify match
data without notice in their docstring.

Reported-by: Thomas Schneider <qsx@chaotikum.eu>
Link: https://orgmode.org/list/wwufsc7edzu.fsf@chaotikum.eu
2023-01-20 12:01:24 +03:00
Ihor Radchenko 3454021483
Revert "org-babel-read: Obey `org-confirm-babel-evaluate'"
This reverts commit 10e857d428.

* lisp/ob-core.el:
(org-babel-merge-params):
(org-babel-process-params):
(org-babel-read):
* lisp/org-table.el: Add FIXME comments to places where arbitrary code
execution may happen.

The extra query is reverted until we develop a better code execution
safety system for Org.  The commit introduced too many user queries,
making the whole idea of asking users to execute code from Org files
not useful.

Link: https://orgmode.org/list/878rinadlq.fsf@localhost
2023-01-02 10:49:45 +03:00
Eli Zaretskii e0815d7545 Backport commit cae528457 from Emacs
; Add 2023 to copyright years.
cae528457cb862dc886a34240c9d4c73035b6659
Eli Zaretskii
Sun Jan 1 05:31:12 2023 -0500
2023-01-01 12:44:47 -05:00
Kyle Meyer 269dce9fe7 org-table: Require org-fold-core
* lisp/org-table.el: Explicitly load org-fold-core.

'make single' warns that org-fold-core-ignore-modifications in
org-table.el (introduced a few commits back) is not known to be
defined, and the Emacs repo would show the same warning.
2022-12-10 16:15:16 -05:00
Ihor Radchenko 76a725317e
orgtbl-to-generic: Improve performance
* lisp/org-table.el (orgtbl-to-generic): Disable org-fold checks in
temporary buffer.  Folding state is irrelevant there.

Reported-by: Majzoub, Eric <eric.majzoub@umsl.edu>
Link: https://orgmode.org/list/tn0s4e$84u$1@ciao.gmane.io
2022-12-10 08:48:29 +03:00
Ihor Radchenko 97a780f0be
org-table-justify-field-maybe: Do not allow newlines inside cells
* lisp/org-table.el (org-table-justify-field-maybe): Remove newlines
from cell values, when present.  Newlines will alter the table cell
structure.

Reported-by: Julien Palard <julien@palard.fr>
Link: https://orgmode.org/list/638faf1b.050a0220.2bd96.904b@mx.google.com
2022-12-07 16:59:21 +03:00
Ihor Radchenko c72d5ee840
org-table-convert-refs-to-rc: Fix failing test
* lisp/org-table.el (org-table-convert-refs-to-an): Leave $0
references (current row) unchanged during conversion.
*
testing/lisp/test-org-table.el (test-org-table/org-table-convert-refs-to-an/2):
Re-enable the failing test.
2022-11-25 14:45:09 +08:00
Ihor Radchenko f995425d06
org-table-convert-region: Update docstring
* lisp/org-table.el (org-table-convert-region): Mention when an error
can be thrown in the docstring.
2022-11-22 10:11:33 +08:00
Ihor Radchenko 514e3a9cd2
org-export: Suppress cache persistence in buffer copies during export
* lisp/org-element.el (org-element-cache-reset): Add new optional
argument that suppresses all persistence-related calculations.
* lisp/org-table.el (org-element-cache-reset):
* lisp/org.el (org-element-cache-reset): Update function signature.
* lisp/ox.el (org-export--generate-copy-script): Do not try to use
cache persistence in throwaway buffer copies.

Reported-by: Rudolf Adamkovič <salutis@me.com>
Link: https://list.orgmode.org/m2zgef774u.fsf@me.com/T/#t
2022-10-07 13:15:17 +08:00
Ihor Radchenko f0b7dfb3a0
org-table: Repair table before inserting rows/columns
* lisp/org-table.el (org-table-insert-column):
(org-table-insert-row): Repair the table as needed before inserting.
The internal insertion logic assumes that the table is valid.  The
rapair checks are copied from `org-table-insert-hline'.

Reported-by: Mauro Aranda <maurooaranda@gmail.com>
Link: https://orgmode.org/list/87o8csah5t.fsf@localhost
2022-10-06 16:22:57 +08:00
Ihor Radchenko ceb99b8600
org-table-fix-formulas: Ensure shifting columns after removing invalid
* lisp/org-table.el (org-table-fix-formulas): Search from the
beginning of table formula when shifting moved column numbers.

Reported-by: Uwe Brauer <oub@mat.ucm.es>
Link: https://orgmode.org/list/87r1gaw0av.fsf@mat.ucm.es
2022-10-05 13:13:36 +08:00
Kyle Meyer 42c418693f Merge branch 'km/from-emacs-master' 2022-10-04 18:37:42 -04:00
Stefan Kangas c2c8e66e5d Backport commit b7e867b84 from Emacs
Make point-at-eol and point-at-bol obsolete
b7e867b841f47dcff3aeaef9b5608a237386ce70
Stefan Kangas
Tue Aug 23 04:54:57 2022 +0200

[ km: This was independently covered on the main branch with
  e73c5b7d0.  I'm applying it here too for bookkeeping/traceability
  purposes. ]
2022-10-04 17:18:04 -04:00
Paul Eggert 723af4afae Backport commit 8ef37913d from Emacs
* lisp/ol.el (org-store-link):
* lisp/org-clock.el (org-clock-sum)
(org-clock-update-time-maybe):
* lisp/org-colview.el (org-colview-construct-allowed-dates):
* lisp/org-macro.el (org-macro--vc-modified-time):
* lisp/org-macs.el (org-2ft, org-matcher-time):
* lisp/org-table.el (org-table-eval-formula):
* lisp/org.el (org-read-date, org-display-custom-time)
(org-time-string-to-time, org-timestamp-change):
Don’t assume Emacs 27 encode-time, since standalone Org still
works with Emacs 25 and it’s easier if we minimize differences
from standalone Org.  Problem reported by Max Nikulin (Bug#54731).
This reverts much of 2021-12-16T17:40:21Z!eggert@cs.ucla.edu.

Port Org encode-time usage back to Emacs 25
8ef37913d3be5ff518018acb6b0144d6e559b5ba
Paul Eggert
Tue Apr 5 17:52:34 2022 -0700

[ km: See main's 8908a1bda (org-macs.el: Introduce a helper for
  `encode-time', 2022-07-17). ]
2022-10-04 16:59:15 -04:00
Paul Eggert 772c44779c Backport commit dd0727e1e from Emacs
* lisp/ol.el (org-store-link):
* lisp/org-clock.el (org-clock-sum)
(org-clock-update-time-maybe):
* lisp/org-colview.el (org-colview-construct-allowed-dates):
* lisp/org-macro.el (org-macro--vc-modified-time):
* lisp/org-macs.el (org-2ft, org-matcher-time):
* lisp/org-table.el (org-table-eval-formula):
* lisp/org.el (org-read-date, org-display-custom-time)
(org-time-string-to-time, org-timestamp-change):
Prefer (encode-time L) to (apply #'encode-time L) where either will do.
* lisp/org-clock.el (org-clocktable-steps):
Prefer (encode-time S M ...) to (apply #'encode-time (list S M ...)).

encode-time simplifications
dd0727e1ec1f535b9b06be88173b4d3ccd55abcb
Paul Eggert
Thu Dec 16 11:17:25 2021 -0800

[ km: Note that these changes will be reverted by the port of Emacs's
  8ef37913d. ]
2022-10-04 16:55:56 -04:00
Ihor Radchenko 9dde82411a
org-table: Prevent Emacs from merging displayed separator spaces
* lisp/org-table.el (org-table-separator-space): Remove.
(org-table--separator-space-pre):
(org-table--separator-space-post): Use non-`eq' spaces as table cell
boundaries.  This way, Emacs display engine will not merge the two
spaces with `eq' 'display properties in empty table cells.

(org-table--make-shrinking-overlay):
(org-table--align-field): Use the new constants for table alignment.

Fixes https://debbugs.gnu.org/cgi/bugreport.cgi?bug=45915
2022-09-22 20:00:03 +08:00
Ihor Radchenko e73c5b7d0d
Fix Emacs 29 compiler warnings
* lisp/oc-basic.el (org-cite-basic--parse-bibliography): Do not use
obsolete `buffer-file-name' generalized variable.  Prefer
`set-visited-file-name'.
* lisp/ol-bibtex.el (org-indent-region): Declare function.
(org-bibtex-import-from-file): Remove unused variable.
* lisp/ol.el (org-link--decode-compound): Use `ash' instead of
obsolete `lsh'.
* lisp/org-macs.el: Do no use obsolete generalized variable
`buffer-string'.
* lisp/org-plot.el (org-plot/redisplay-img-in-buffer):
* lisp/org.el (image-flush):
(org-display-inline-images): Use `image-flush' instead of obsolete
`image-refresh'.
* lisp/ox.el (org-export-to-file): Quote ' in the docstring.

All other changes are changing obsolete `point-at-bol' and
`point-at-eol' to `line-beginning-position' and `line-end-position'.
2022-09-06 20:50:59 +08:00
Ihor Radchenko e81a094383
Assert all the Org files to load the same Org version
* lisp/org-compat.el (org-assert-version): New macro comparing Org
version at compile time and laod time.

Add `org-assert-version' call to all files:

* lisp/org-macs.el:
* lisp/org-crypt.el:
* lisp/org-ctags.el:
* lisp/org-cycle.el:
* lisp/org-datetree.el:
* lisp/org-duration.el:
* lisp/org-element.el (avl-tree):
* lisp/org-entities.el:
* lisp/org-faces.el:
* lisp/org-feed.el:
* lisp/org-fold-core.el:
* lisp/org-fold.el:
* lisp/org-footnote.el:
* lisp/org-goto.el:
* lisp/org-habit.el:
* lisp/org-id.el:
* lisp/org-indent.el:
* lisp/org-inlinetask.el:
* lisp/org-keys.el:
* lisp/org-lint.el:
* lisp/org-list.el:
* lisp/org-macro.el:
* lisp/org-mobile.el:
* lisp/org-mouse.el:
* lisp/org-num.el:
* lisp/org-pcomplete.el:
* lisp/org-persist.el:
* lisp/org-plot.el:
* lisp/org-protocol.el:
* lisp/org-refile.el:
* lisp/org-src.el:
* lisp/org-table.el:
* lisp/org-tempo.el:
* lisp/org-timer.el:
* lisp/org.el:
* lisp/ox-ascii.el:
* lisp/ox-beamer.el:
* lisp/ox-html.el:
* lisp/ox-icalendar.el:
* lisp/ox-koma-letter.el:
* lisp/ox-latex.el:
* lisp/ox-man.el:
* lisp/ox-md.el:
* lisp/ox-odt.el:
* lisp/ox-org.el:
* lisp/ox-publish.el:
* lisp/ox-texinfo.el:
* lisp/ox.el:
2022-09-04 12:24:55 +08:00
Kyle Meyer 5a64429b27 Merge branch 'bugfix'
As mentioned in 2e36ac2ac (Merge single quote fixes from Emacs's
master, 2022-07-24), this merge is keeping Org main's side of
org-babel-lua-read-string and org-agenda-sorting-strategy rather than
the variant introduced in the Emacs repo that's now in bugfix.

Note that for org-agenda-sorting-strategy docstring I think it'd
probably be preferable to change main's

    \\='(time-up category-keep priority-down)

to a bare

    (time-up category-keep priority-down)

but, at least for this merge, I'm sticking to choosing between the
variables that are in one of the sides.
2022-07-24 16:53:32 -04:00
Lars Ingebrigtsen cea0263784 Backport commit bbf389ea6 from Emacs
* lisp/ox-publish.el (org-publish-find-property):
* lisp/ox-html.el (org-html--unlabel-latex-environment):
* lisp/org-table.el (org-table-collapse-header):
* lisp/org-plot.el (org--plot/prime-factors):
* lisp/org-agenda.el (org-agenda--mark-blocked-entry):
(org-agenda-set-restriction-lock):
* lisp/ob-lua.el (org-babel-lua-read-string):
* lisp/ob-julia.el (org-babel-julia-evaluate-external-process):
(org-babel-julia-evaluate-session):
* lisp/ob-core.el (org-babel-default-header-args): Fix
quoting in doc strings.  In code examples, the ' character is
quoted with \\=, and regularize 'foo to `foo', and quote strings
like "foo" instead of 'foo'.

Audit quoting the quote character in doc strings
bbf389ea6deab229ba18dc519fe712ec982609d1
Lars Ingebrigtsen
Fri Apr 22 16:17:22 2022 +0200

[km] Org's bugfix branch is currently receiving commits from emacs-28,
     but this commit comes from Emacs's master branch.  I'm porting it
     because it has conflicts with bugfix's 01b0fb14b (Backport from
     main: Escape single left quotes in docstrings, 2022-07-24) and
     only touches docstrings.
2022-07-24 15:58:18 -04:00
Paul Eggert a4105d0942
Use higher level helpers instead of `encode-time'
* lisp/org-clock.el (org-clock-sum)
(org-clock-update-time-maybe):
Prefer org-time-string-to-seconds to doing it by hand.
* lisp/org-macs.el (org-2ft):
Prefer org-time-string-to-seconds to doing it by hand.
* lisp/org-table.el (org-table-eval-formula):
Prefer org-time-string-to-time to doing it by hand.

Max Nikulin:
A larger patch "Improve Org usage of timestamps" was suggested in
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=54764#10

Only cosmetic changes are selected for this patch.
2022-07-17 16:38:51 +08:00
Stefan Kangas 0ed0dea229
Delete some Emacs 24 compat code
Org mode supports Emacs 26 or newer:
https://orgmode.org/worg/org-maintenance.html#emacs-compatibility

* lisp/org-compat.el (org-set-transient-map)
(org-font-lock-ensure): Delete compat aliases.  Update callers.
(org-define-error): Redefine as obsolete function alias for
`define-error'.  Update callers.
(string-suffix-p): Delete compatibility definition.

* lisp/org-fold-core.el (org-fold-core--seq-partition): Delete private
function and update callers to use `seq-partition'.

* lisp/org-macs.el (org-without-partial-completion): Move from here...
* lisp/org-compat.el (org-without-partial-completion): ...to here.
Redefine as obsolete function alias for `progn'.
2022-07-02 12:10:00 +08:00
Stefan Kangas 13d97ee18c
Prefer "website" to "homepage"
Emacs now advises using "website" (instead of "homepage") and
consequently to use the "URL" comment header instead of "Homepage".

* README:
* README_ELPA:
* doc/org-guide.org (Creating Footnotes):
* doc/org-manual.org (Creating Footnotes):
* etc/styles/README (URL): Prefer "website" to "homepage".

* lisp/*.el:
* mk/org-fixup.el: Replace the "Homepage" header comment with "URL".
2022-06-26 10:10:48 +08:00
Stefan Kangas 45174d62b9
Remove XEmacs and ancient Emacs compat code
* lisp/org-colview.el (org-columns-remove-overlays):
* lisp/org-ctags.el (org-ctags-find-tag-interactive):
* lisp/org-macs.el (org-fit-window-to-buffer):
* lisp/org-mouse.el (org-mouse-show-context-menu):
* lisp/org-table.el (org-table-fedit-lisp-indent):
* lisp/org.el (org-version, org-reload):
* lisp/ox-html.el (org-html-template, org-html--build-meta-info):
Remove Emacs 21 and 22 compat code.

* lisp/ol-eww.el (org-eww-copy-for-org-mode):
* lisp/ol-w3m.el (org-w3m-copy-for-org-mode):
* lisp/org-clock.el (org-clock-select-task):
* lisp/org-macs.el (org-fit-window-to-buffer):
* lisp/org-refile.el (org-refile):
* lisp/org.el (org-change-tag-in-region): Remove XEmacs compat code.

* lisp/org-goto.el (org-goto--set-map):
* lisp/org-macs.el (org-fit-window-to-buffer):
* lisp/org-table.el (orgtbl-mode):
* lisp/org.el (org-setup-filling): Remove XEmacs or Emacs 19 or 20
compat code.  (It is one of these; not clear which.)
2022-06-18 15:43:30 +08:00
Ihor Radchenko 65e19a0812
org-table.el: Fix orgtbl-mode not remapping delete key
* lisp/org-table.el (orgtbl-setup): Remap `delete-forward-char' in
addition to `delete-char'.  The former is called in Emacs >26.

Partially fixes
https://orgmode.org/list/1AD1B9B7-5A15-4F86-9274-B04B83694C85@misasa.okayama-u.ac.jp
2022-06-18 14:18:00 +08:00
Robert Pluim e9da29b6fa
Escape single left quotes in docstrings
* lisp/ob-core.el (org-babel-default-header-args):
* lisp/ob-julia.el (org-babel-julia-evaluate-external-process):
(org-babel-julia-evaluate-session):
* lisp/ob-lua.el (org-babel-lua-read-string):
* lisp/ob-table.el (org-sbe):
* lisp/oc-basic.el (org-cite-basic--shorten-names):
* lisp/org-agenda.el (org-agenda-sorting-strategy):
(org-agenda--mark-blocked-entry):
(org-agenda-set-restriction-lock):
* lisp/org-fold-core.el (org-fold-core--specs):
(org-fold-core-remove-folding-spec):
(org-fold-core-get-folding-spec):
(org-fold-core--isearch-overlays):
* lisp/org-plot.el (org--plot/prime-factors):
* lisp/org-table.el (org-table-collapse-header):
* lisp/org.el (org-special-ctrl-o):
(org-latex-to-html-convert-command):
* lisp/ox-html.el (org-html--unlabel-latex-environment):
* lisp/ox-publish.el (org-publish-find-property):
Use \\=' when there's a need for a single left quote in a docstring.

The emacs-29 byte compiler complains about such usage.
2022-06-16 20:51:02 +08:00
Ihor Radchenko 0b07b30dea
orgtbl-toggle-comment: Fix when table is at `point-min' or `point-max'
* lisp/org-table.el (orgtbl-toggle-comment): Avoid infinite loop when
begin/end line of the table is at `point-min' or `point-max'.

Fixes https://orgmode.org/list/874k20v7sj.fsf@gmail.com
2022-05-09 21:31:54 +08:00
Bastien d7cae14953 Merge branch 'bugfix' 2022-03-31 17:47:54 +02:00
Bastien 64ee5c2c47 lisp/org-table.el: Fix bug in `org-table-row-get-visible-string'
* lisp/org-table.el (org-table-row-get-visible-string): Don't use
`backward-char' in a function called in a post-command hook.
2022-03-31 17:31:50 +02:00
Mark A. Hershberger 1537bb4029
Fix signature for org-element-at-point 2022-01-12 22:26:10 +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 4b1def3c5c
org-table.el: Do not create new field when at EOL after table line
* lisp/org-table.el (org-table-justify-field-maybe): Do not treat "|$"
as unclosed table field.

Fixes https://orgmode.org/list/trinity-2561db57-1561-470b-982f-0d91ddf4f145-1629900012884@3c-app-mailcom-lxa06
2021-11-23 21:40:58 +08:00
Ihor Radchenko b5f992b678
org-table.el: Do not create new field when at EOL after table line
* lisp/org-table.el (org-table-justify-field-maybe): Do not treat "|$"
as unclosed table field.

Fixes https://orgmode.org/list/trinity-2561db57-1561-470b-982f-0d91ddf4f145-1629900012884@3c-app-mailcom-lxa06
2021-11-23 21:14:44 +08:00
Ihor Radchenko abe7222ed8
Add declares to suppress compiler warnings 2021-10-17 00:01:56 +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
Kyle Meyer cc2490a706 Prune Emacs 25.1 compatibility kludges
* lisp/oc-basic.el (org-cite-basic--field-less-p):
* lisp/ol-eww.el (org-eww-store-link):
* lisp/org-agenda.el (org-agenda-check-clock-gap):
* lisp/org-clock.el (org-clock-get-clocked-time)
(org-clock-resolve-clock, org-clock-resolve)
(org-resolve-clocks, (org-resolve-clocks-if-idle)
(org-clock-in, org-clock-sum): Drop now unnecessary use of
compatibility functions.

* lisp/org-compat.el (org-string-collate-lessp, org-decode-time)
(org-format-time-string, org-link-escape-browser, org-time-add)
(org-time-subtract, org-time-since, org-time-less-p): Mark as
obsolete.

The 9.5 release declared Emacs 25.1 as the minimum version.
2021-10-04 23:43:14 -04:00
Ihor Radchenko 60365a1641
orgtbl-to-generic: Mention that :fmt is ignored for empty cells
* lisp/org-table.el (orgtbl-to-generic): Amend docstring mentioning
that :fmt is ignored for empty table cells.
2021-10-01 11:56:30 +08:00
Bastien 806ac1b7f6 *el: Fix indentation 2021-09-29 09:22:47 +02:00
Kyle Meyer 1292d89c37 Clean up spacing to pass Emacs's pre-commit check
* lisp/org-agenda.el (org-agenda-highlight-todo):
(org-agenda-set-mode-name):
* lisp/org-table.el (org-table-eval-formula): Avoid space before tab in
indent.

This is in preparation for syncing with the Emacs repo.
2021-09-29 00:37:30 -04:00
Bastien 72c9f1bf42 Merge branch 'bugfix' 2021-09-26 08:54:40 +02:00
Bastien dbbb93dfdf lisp/org-table.el: Fix positioning of "#+TBLFM:
* lisp/org-table.el (org-table-store-formulas): Fix positioning of
"#+TBLFM:".

Reported-by: tbanelwebmin <tbanelwebmin@free.fr>
<http://list.orgmode.org/43910853-03cb-c226-f46d-4736d0e6cca6@free.fr>
2021-09-26 08:53:36 +02:00
Nicholas Vollmer 74a5af619c Fix byte-comp function warnings
* (org.el, org-table.el org-keys.el) Declare functions for byte compiler.
2021-09-25 21:31:25 +02:00
Nicholas Vollmer d8b9bd05ba Fix byte-comp function warnings
* (org.el, org-table.el org-keys.el) Declare functions for byte compiler.
2021-09-25 21:30:32 +02:00
Utkarsh Singh e626185081 org-table.el: Fix usage of user-error
* lisp/org-table.el (org-table-convert-region): Don't use `if' because
  Elisp has no concept of continuable errors.
2021-09-25 16:23:54 +02:00
Stefan Kangas 51cdd6e30f Various minor docfixes found by checkdoc 2021-09-16 21:24:59 +02:00
Bastien 0f2ece647b Update Carsten's email address in some files 2021-05-07 16:50:57 +02:00
Bastien c7824f9cf8 Merge branch 'maint' 2021-05-02 05:46:57 +02:00
Bastien eedbe286ef lisp/org-table.el: Fix bug with `org-table-wrap-region'
* lisp/org-table.el (org-table-copy-region): Only display a
message when called interactively.
(org-table-wrap-region): Prevent `org-table-cut-region' from
losing track of the region beginning.

Reported-by: Marko Schuetz-Schmuck <marko.schutz@upr.edu>
Link: https://orgmode.org/list/875z84fnwv.fsf@tpad-m.i-did-not-set--mail-host-address--so-tickle-me/
2021-05-02 05:44:46 +02:00
Utkarsh Singh 7c99d15557 org-table.el: Allow to import files with no .txt, .tsv or .csv
* lisp/org-table.el (org-table-import): Allow to import files
with no .txt, .tsv or .csv extension.

TINYCHANGE
2021-05-01 10:48:07 +02:00
Bastien Guerry 29d4cc1802 Merge branch 'maint' 2021-04-26 21:52:25 +02:00
Bastien Guerry 058339d6e6 org-table.el: Fix a bug when displaying a table header
* lisp/org-table.el (org-table-row-get-visible-string): Fix wrong
beginning of the header string.
(org-table-header-set-header): Get the real beginning of the line.

Reported-by: "Oorja Sandhu" <oorja.sandhu@inoutbox.com>
Link: https://orgmode.org/list/7beea3b5-6fe5-4ba6-831e-19a88d87de6b@www.fastmail.com/
2021-04-26 21:51:12 +02:00
Kyle Meyer 664b653448 Merge branch 'km/from-emacs-master' 2021-04-18 02:12:44 -04:00
Stefan Monnier 8c29cbdef7 Backport commit c45bfd3c4 from Emacs
* lisp/ox-beamer.el (org-beamer-mode-map): Move initialization
into declaration.
(org-beamer-mode):
* lisp/org.el (org-cdlatex-mode):
* lisp/org-table.el (org-table-header-line-mode)
(org-table-follow-field-mode, orgtbl-mode):
* lisp/org-src.el (org-src-mode):
* lisp/org-list.el (org-list-checkbox-radio-mode):
* lisp/org-indent.el (org-indent-mode):
* lisp/org-capture.el (org-capture-mode):
Avoid old-style positional args to `define-minor-mode`.

* lisp/**/*.el: Avoid positional args to `define-minor-mode`
c45bfd3c4abbfa585c9199f4866b6b8046945117
Stefan Monnier
Sun Apr 11 23:47:14 2021 -0400
2021-04-18 02:11:35 -04:00
Kyle Meyer a02a3bd6ac Merge branch 'maint' 2021-04-17 15:19:41 -04:00
Kyle Meyer f12ca1a562 table: Restore temporary-goal-column after displaying header
* lisp/org-table.el (org-table-header-set-header): Restore
temporary-goal-column to prevent disrupting the expected next-line and
previous-line movement.

org-table-header-set-header, which org-table-header-line-mode adds to
post-command-hook, changes the value of temporary-goal-column to zero,
interfering with the logic in line-move-1.

Reported-by: Oorja Sandhu <oorja.sandhu@inoutbox.com>
Ref: https://orgmode.org/list/1b8b1a96-149e-4409-9738-fc45fad3a604@www.fastmail.com
2021-04-17 15:06:11 -04:00
Stefan Kangas 2e1c984153 Prefer HTTPS to HTTP in most links 2021-03-21 15:21:22 -04:00
Kyle Meyer e0fb2339f4 Merge branch 'km/from-emacs-master'
Porting from Emacs's master to Org's maint branch has been on hold
leading up to the Emacs 27.2 release to avoid any required fixup syncs
carrying those commits into the emacs-27 branch.  This merge brings
those changes into master.  The km/from-emacs-master branch should be
merged to maint when Emacs 27.2 has been released (assuming Org 9.5
hasn't been released, in which case maint will be tracking 9.5.x and
already include these changes).
2021-02-14 18:06:23 -05:00
Stefan Kangas 4aa4ae8cf0 Backport commit bbe88cd82 from Emacs
* lisp/org-table.el (org-table-edit-field):
* lisp/org.el (org-restart-font-lock): Assume font-lock-mode variable
is not void; it is preloaded.

Assume font-lock-mode variable is not void
bbe88cd82e4bbfd76df06223614ab74d1022c119
Stefan Kangas
Fri Feb 5 01:15:02 2021 +0100
2021-02-14 17:38:07 -05:00
Kyle Meyer 291993888d Merge branch 'maint' 2021-01-01 15:02:10 -05:00
Kyle Meyer 99eafe3787 Update copyright year to 2021 2021-01-01 14:59:01 -05:00
Kyle Meyer f845305c31 Merge branch 'maint' 2020-12-13 14:56:59 -05:00
Kyle Meyer d7d714c7d5 Silence byte-compiler in Emacs repo
These show up in the Emacs repo (before and after the latest sync in
f22856a5c5), but for an unknown reason do not show up with `make
compile' or `make single' in the Org repo.

All of these functions are autoloaded.
2020-12-13 13:56:29 -05:00
Kyle Meyer b3b29e1d59 Merge branch 'maint' 2020-11-27 01:35:31 -05:00
Stefan Kangas 00bc3097cd Backport commit affe9b225 from Emacs
* lisp/org-agenda.el (org-agenda-mode):
* lisp/org-table.el (org-table-edit-formulas, orgtbl-mode):
* lisp/org.el: Don't call easy-menu-add, an obsolete XEmacs compat
alias.

Make XEmacs compat aliases easy-menu-{add,remove} obsolete
affe9b225de711429248a73f920dc9f38b15c932
Stefan Kangas
Tue Nov 24 18:06:05 2020 +0100
2020-11-26 19:31:48 -05:00
Daniele Nicolodi 15469774dd org-table: Add mode flag to enable Calc units simplification mode
* org-table.el (org-table-eval-formula): Add the `u` mode flag to
enable Calc's units simplification mode.

* test-org-table.el (test-org-table/mode-string-u): Add Unit test for
the new mode flag.

* org-manual.org: Document new mode flag.
2020-11-24 20:59:39 -05:00
Daniele Nicolodi abd9949431 org-table: Simplify mode string parsing
* org-table.el (org-table-eval-formula): Simplify mode string parsing
and reduce scope of local variables.
2020-11-24 20:58:27 -05:00
Daniele Nicolodi bd7e16ca21 org-table: Remove unused org-tbl-calc-modes variable declaration
* org-table.el (org-tbl-calc-modes): Remove variable declaration as
the varialble is used only within `org-table-eval-formula'.

* org-table.el (org-table-eval-formula): Rename `org-tbl-calc-modes`
local variable without the `org-tbl-` prefix and use the gained screen
real estate to avoid indirection through covenience macro. This
requires moving the mode lookup table from `org-table--set-calc-mode`
to here.

* org-table.el (org-table--set-calc-mode): Drop convenience macro.
Note that the macro was not working as intended when the caller tried
to add a new entry in the plist as in this case the macro would create
a new plist with the added entry but return the old one.
2020-11-24 20:58:27 -05:00
Stefan Kangas 9a6689f9ce Backport commit c6fa0ad31 from Emacs
; Prefer https to http in many URLs
c6fa0ad315e38167cb81a4d8c143cc53ad783cc3
Stefan Kangas
Thu Oct 1 15:28:15 2020 +0200
2020-10-04 15:06:39 -04:00
Nicolas Goaziou 10ed4994f5 table: Fix regexp
* lisp/org-table.el (org-table-import): Fix missing leading
backslash.  Switch to Rx notation for clarity.
2020-09-15 09:50:29 +02:00
Bastien Guerry 9c31cba002 org-table.el: Throw an error when importing a non-csv/tsv/txt file
* lisp/org-table.el (org-table-import): Throw an error when
interactively trying to import a non-csv/tsv/txt file.

Reported-by: swedebugia <swedebugia@riseup.net>
See https://orgmode.org/list/20200912135043.0354bac4@parabola/
2020-09-13 19:13:05 +02:00
Bastien b2f54f9f8e Merge branch 'maint' 2020-09-05 15:20:06 +02:00
Bastien 114d509829 org-table.el: Prevent an error from occurring
* lisp/org-table.el (org-table-justify-field-maybe): Fix bug.

Reported-by: Lester Longley <lester@ieee.org>
https://orgmode.org/list/CAA3095_oH2sH_a=nNeYEa=agZp7L2K8Vp2s-c7fN4M4Sro=stQ@mail.gmail.com
2020-09-05 15:18:51 +02:00
mfrasca 73e367fca4 table: Allow collapsing header into single line
* lisp/org-table.el (org-table-collapse-header): New function.

* lisp/org-plot.el (org-plot/gnuplot): Use org-table-collapse-header
and trust there will be no more leading `hline' symbols in lisp table.

* testing/lisp/test-org-table.el (test-org-table/to-lisp):
Adding tests to already existing to-lisp function.
(test-org-table/collapse-header): Adding tests to new
collapse-header function.

* testing/lisp/test-ox.el (test-org-export/has-header-p): Testing
exporting table with multi-line header.
2020-06-28 23:02:26 +02:00
Nicolas Goaziou e3a7247b68 table: Gracefully align hrule-only tables
* lisp/org-table.el (org-table-align): Try to align the table even
when it only consists of horizontal rules.
* testing/lisp/test-org-table.el (test-org-table/align): Add test.
2020-06-15 21:34:00 +02:00
Nicolas Goaziou e39365e32f table: Avoid unnecessary consing
* lisp/org-table.el (org-table-align): Avoid unnecessary consing.
2020-05-09 10:44:43 +02:00
Nicolas Goaziou ba7bf12b44 table: Small refactoring of `org-table-align'
* lisp/org-table.el (org-table-align): Remove dead code.  Slightly
simplify code.
2020-05-08 23:40:57 +02:00
Nicolas Goaziou 984c7af21f table: `org-table-to-lisp' preserves text properties.
* lisp/org-table.el (org-table-to-lisp): Preserve text properties.
Otherwise, it breaks `org-table-align', which needs to know about
invisible characters.
2020-05-08 16:14:50 +02:00
Nicolas Goaziou 13195a4a5f table: Speed-up for `org-table-align'
* lisp/org-table.el (org-table-align): Use `org-table-to-lisp'.

Suggested-by: Thierry Banel <tbanelwebmin@free.fr>
2020-05-08 15:42:43 +02:00
Nicolas Goaziou 7d35d46494 Fix :package-version values
* lisp/ol.el (org-link-email-description-format):
* lisp/org-src.el (org-src-tab-acts-natively):
* lisp/org-table.el (org-table-header-line-p):
* lisp/org.el (org-loop-over-headlines-in-active-region):
(org-fontify-done-headline): Use correct (PACKAGE . VERSION-STRING)
value.  Remove :version keyword since :package-version overrides it.
2020-05-06 02:12:23 +02:00
Nicolas Goaziou e5eda0beeb table: Tiny clean-up
* lisp/org-table.el (org-table-export): Remove unnecessary calls to
`buffer-substring-no-properties'.
2020-05-02 11:32:17 +02:00
Marco Wahl 90185c98f4 table: Remove the last row (LR) feature
The feature was undocumented and broken according to Carsten.

* lisp/org-table.el (org-table-insert-column):
(org-table-delete-column):
(org-table-move-column):
(org-table-get-formula):
(org-table-fix-formulas):
(org-table-analyze): Remove the parts refering to LR.
2020-05-02 00:04:30 +02:00
Nicolas Goaziou ce10179cc2 table: `org-table-to-lisp' does not check if point is at a table
* lisp/org-table.el (org-table-to-lisp): Do not check if point is at
a table.  Leave it to the caller.

See <http://lists.gnu.org/r/emacs-orgmode/2020-05/msg00000.html>.
2020-05-01 15:00:47 +02:00
Nicolas Goaziou e955976983 table: Small fix
* lisp/org-table.el (org-table-to-lisp): Make sure to stop at the end
of the table.
2020-05-01 12:29:11 +02:00
tbanelwebmin 20f2cd8416 table: Rewrite `org-table-to-lisp'
* lisp/org-table.el (org-table-to-lisp): Rewrite function.

The new implementation can be more than 100 times faster.  This enhances
responsiveness of Babel or Gnuplot blocks handling very large tables.
2020-05-01 00:26:46 +02:00
Mattias Engdegård e69937ddac Backport commit 6a60701bb from Emacs
* lisp/org-table.el (org-table-finish-edit-field):
Further improvement of regexp, as suggested by Paul Eggert.

Improve regexp in org-table-finish-edit-field
6a60701bba3d87f5d9a1730e18b6da827f41a062
Mattias Engdegård
Thu Apr 16 19:53:10 2020 +0200
2020-04-20 00:42:44 -04:00
Mattias Engdegård 37c916d90c Backport commit 905c0a13f from Emacs
* lisp/org-table.el (org-table-finish-edit-field):
Avoid wrapped subsumption in repeated sequences.

Fix bugs, inefficiencies and bad style in regexps
905c0a13f7929298cb36151f46dbef03f7bdcbe4
Mattias Engdegård
Thu Apr 16 12:14:38 2020 +0200
2020-04-20 00:42:44 -04:00
Nicolas Goaziou e515a7cec8 Merge branch 'maint' 2020-04-18 18:34:24 +02:00
Nicolas Goaziou 756ddff9e3 table: Small fix to column deletion
* lisp/org-table.el (org-table-delete-column): Do not assume row ends
right after the last vertical line.  Do not use `looking-back'.
* testing/lisp/test-org-table.el (test-org-table/delete-column): Add
test.
2020-04-18 18:33:07 +02:00
Marco Wahl 6f38fe24a3 Merge branch 'maint' 2020-04-18 16:17:12 +02:00
Marco Wahl bb9dfdafeb org-table: Make column delete consistent with row delete
* lisp/org-table.el (org-table-delete-column): Stay in the column at
delete.  Exceptionally allow column delete when point is at eol
immediately to the right of a cell seperator.

A hint by Eric S Fraga led to this commit.
https://lists.gnu.org/archive/html/emacs-orgmode/2020-04/msg00283.html
2020-04-18 16:16:02 +02:00
Marco Wahl c990d43a64 org-table: Small refactoring
* lisp/org-table.el (org-table-fix-formulas): Eliminate a local
variable.
2020-04-18 01:20:49 +02:00
Marco Wahl 5dcf6d4af3 org-table: Decrease the amount of redundant messages
* lisp/org-table.el (org-table-fix-formulas): Only one message per
tblfm instead of an update message for every line.
2020-04-18 01:03:15 +02:00
Marco Wahl 0e5be8a656 Merge branch 'maint' 2020-04-18 00:21:39 +02:00
Marco Wahl 22d2b0ac84 org-table: Insert column at point
* lisp/org-table.el (org-table-insert-column): Adjust the function to
insert the column at point (and not to the right.)

Org-manual, ORG-NEWS and testing are changed accordingly.
2020-04-18 00:13:24 +02:00
Marco Wahl 31d1bf86a3 Merge branch 'maint' 2020-03-30 23:23:33 +02:00
Marco Wahl fe34a408f2 org-table: Fix formula at column insert
* lisp/org-table.el (org-table-insert-column): Fix the index.

Report and fix by Yu Han Quek.  https://lists.gnu.org/archive/html/emacs-orgmode/2020-03/msg00290.html

TINYCHANGE
2020-03-30 23:21:22 +02:00
Mattias Engdegård b78583a1c1 Backport commit 770f76f05 from Emacs
Make regexps smaller and faster by removing terms that are superfluous
by virtue of standing next to another term that matches more.  See
https://lists.gnu.org/archive/html/emacs-devel/2020-01/msg00949.html
for details.

* lisp/ob-core.el (org-babel-remove-result):
* lisp/ob-fortran.el (org-babel-fortran-ensure-main-wrap):
* lisp/org-capture.el (org-capture-set-target-location):
* lisp/org-compat.el (org-maybe-keyword-time-regexp):
* lisp/org-table.el (org-table-expand-lhs-ranges):
Remove subsumed repetitions.

Remove subsumed repetitions in regexps
770f76f050376bbd77a3cc8cf44db57cf855a27c
Mattias Engdegård
Thu Feb 20 16:05:18 2020 +0100
2020-03-15 22:51:31 -04:00
Mattias Engdegård 7265f2864e Backport commit af085ef40 from Emacs
* lisp/org-agenda.el (org-agenda-hide-tags-regexp)
(org-agenda-category-icon-alist):
* lisp/org-protocol.el (org-protocol-data-separator):
* lisp/org-table.el (org-table-number-regexp):
* lisp/ox-latex.el (org-latex-known-warnings):
Use 'regexp' instead of 'string' as type for values that are regexps
in defcustom declarations.

Use regexp type for regexps in defcustom declarations
af085ef40b961ca3466e8b2dfb7f722573e5a4cc
Mattias Engdegård
Thu Dec 26 16:50:58 2019 +0100
2020-03-15 22:51:31 -04:00