Commit Graph

592 Commits

Author SHA1 Message Date
Ihor Radchenko 051e7b9d7c
Reduce repetitive calls to `find-buffer-visiting' + `find-file-noselect'
* lisp/org-macs.el (org-with-file-buffer): New macro switching to a
file buffer temporarily and killing it if a buffer visiting file did
not exist previously.
(org-file-buffer-created): New variable set when buffer visiting file
has been created.
* lisp/ob-tangle.el (org-babel-tangle-file):
* lisp/org-archive.el (org-archive-subtree):
* lisp/org-refile.el (org-refile):
(org-refile-check-position):
(org-refile-new-child):
* lisp/ox-org.el (org-org-publish-to-org):
* lisp/ox-publish.el (org-publish-org-to):
(org-publish-find-property): Avoid calling `find-buffer-visiting' +
`find-file-noselect'.  The latter calls the former.  Instead, either
just call `find-file-noselect' or use `org-with-file-buffer'.

This commit addresses O(N_buffers) complexity in
`find-buffer-visiting', reducing the number of calls to it.

See Emacs bug#66117.
2024-03-16 11:21:30 +03:00
Psionik K b6f8078ab4
org-do-remove-indentation: Ignore invisible text
* lisp/org-macs.el (org-do-remove-indentation): Set
`buffer-invisibility-spec' to nil before detecting the column or
moving to a column.

This fixes src_block indentation removal for org-modern-mode but will
also correct other cases of hidden indentation.

TINYCHANGE
2024-03-12 15:19:50 +03:00
Ihor Radchenko a1b8554f6f
org-mks: Do not leave window around
* lisp/org-macs.el (org-mks): Make sure that selection window is
closed upon exiting.  See also fef873b1c.

Reported-by: Björn Bidar <bjorn.bidar@thaodan.de>
Link: https://orgmode.org/list/874jdg2ipo.fsf@
2024-03-12 15:12:42 +03:00
Ihor Radchenko 755fef38f5
Merge branch 'bugfix' 2024-02-28 10:54:50 +03:00
Ihor Radchenko 80dff08ed1
Fix unescaped \ in docstrings
* lisp/org-macs.el (org-split-string):
* lisp/ox-latex.el (org-latex-guess-babel-language): Fix docstrings,
as revealed by compiler warnings.
2024-02-28 10:52:58 +03:00
Ihor Radchenko a250fc745f
org-compile-file: Retain all the logs when PROCESS is a list
* lisp/org-macs.el (org-compile-file): When PROCESS is a list of shell
commands, do not erase logs of all but last commands.
2024-02-13 12:59:38 +01:00
Ihor Radchenko 78dc58508d
Obsolete org-switch-to-buffer-other-window and org-no-popups
* lisp/org-compat.el (org-switch-to-buffer-other-window):
(org-no-popups): Move from org-macs.el and mark obsolete.
* lisp/ob-lilypond.el (org-babel-lilypond-execute-tangled-ly):
(org-babel-lilypond-mark-error-line):
* lisp/ol.el (org-insert-link):
* lisp/org-agenda.el (org-agenda-get-restriction-and-command):
(org-agenda-prepare-window):
(org-agenda-goto):
(org-agenda-open-link):
(org-agenda-clock-goto):
(org-agenda-diary-entry-in-org-file):
(org-agenda-add-entry-to-org-agenda-diary-file):
(org-agenda-show-the-flagging-note):
* lisp/org-attach.el (org-attach):
* lisp/org-capture.el (org-capture-place-template):
(org-capture-fill-template):
* lisp/org-clock.el (org-clock-select-task):
* lisp/org-macs.el (org-mks):
* lisp/org-src.el (org-src-switch-to-buffer):
* lisp/org-table.el (org-table-edit-field):
(org-table-edit-formulas):
(org-table-show-reference):
* lisp/org.el (org-fast-todo-selection):
(org-add-log-note):
(org-fast-tag-selection):
* lisp/ox.el (org-export-stack-view):
(org-export--dispatch-ui): Use `switch-to-buffer-other-window'.
* etc/ORG-NEWS (Org mode no longer disallows configuring
~display-buffer-alist~ to open Org popups in other frame): Document
the breaking change.

Reported-by: Jan Seeger
Link: https://orgmode.org/list/87pmr3mfq3.fsf@localhost
2024-01-24 15:00:26 +01:00
Kyle Meyer 6e17ddd334 Merge branch 'bugfix' 2024-01-20 21:33:37 -05:00
Stefan Kangas 50183ada86 Backport commit 725a3f32f from Emacs
; Fix typos in symbol names
725a3f32f8ba78ac5fffcd03be5b82cbc2c1b275
Stefan Kangas
Sun Jan 14 15:16:54 2024 +0100
2024-01-20 21:25:59 -05:00
Kyle Meyer 72a2db86d9 Merge branch 'bugfix' 2024-01-06 16:02:02 -05:00
Po Lu 9f1d6dfd73 Backport commit 8e1c56ae4 from Emacs
; Add 2024 to copyright years
8e1c56ae46754dd7baedff49a464f078f0e9912d
Po Lu
Tue Jan 2 09:47:10 2024 +0800
2024-01-06 15:48:23 -05:00
Ihor Radchenko 80ce6152ba
lisp/org-table.el: Improve cell alignment accuracy
* lisp/org-macs.el (org-string-width): Add new optional argument
providing reference face to be used for relative width calculation.
Use `ceiling' when the total string width is a fraction of "a" width.
* lisp/org-table.el (org-table-blank-field):
(org-table-clean-line):
(org-table--shrink-field):
(org-table--align-field):
(org-table-align):
(org-table-justify-field-maybe): Use org-table face as reference for
width calculation.

When org-table face is not default, `org-string-width' may not return
correct width as " " and "-" in the table may not have the same width
as "a" with default face used as reference in `org-string-width'.
With this patch, the width calculation becomes more accurate, although
may still be off if the table faces are customized to be more
piece-mill.

Reported-by: ltmsyvag
Link: https://emacs-china.org/t/org-9-6-5-org/24484
2023-12-28 16:17:03 +01:00
Ihor Radchenko bd9dc32178
org-assert-version: Disable version check in .elc files for built-in Org mode
* lisp/org-macs.el (org-assert-version): Record
`org--inhibit-version-check' during compile time inside
`org-assert-version'.  This way, .elc files generated when compiling
built-in Org mode in Emacs git tree never trigger version mismatch
warning.

Link: https://yhetil.org/emacs-devel/87zfxzdbna.fsf@yahoo.com
2023-12-25 15:50:08 +01:00
Ihor Radchenko eadeaa8533
org-assert-version: Disable version check in .elc files for built-in Org mode
* lisp/org-macs.el (org-assert-version): Record
`org--inhibit-version-check' during compile time inside
`org-assert-version'.  This way, .elc files generated when compiling
built-in Org mode in Emacs git tree never trigger version mismatch
warning.

Link: https://yhetil.org/emacs-devel/87zfxzdbna.fsf@yahoo.com
2023-12-24 13:47:04 +01:00
Ihor Radchenko 7440911e49
Merge branch 'bugfix' 2023-12-24 11:58:52 +01:00
Ihor Radchenko af18216738
org-assert-version: Convert to warning. Add info when building Emacs git
* lisp/org-macs.el (org-assert-version): Do not throw an error - it is
preventing Org loading and creating more breakage than the problem it
is trying to solve (the version mismatch is problematic occasionally,
while the error was thrown every single time).  Document what to do
when version mismatch is encountered for Org mode built inside Emacs
git repository.

Link: https://yhetil.org/emacs-devel/83frzsccuy.fsf@gnu.org/T/#t
2023-12-24 11:53:39 +01:00
Ihor Radchenko 571186631a
lisp/org-macs.el (org-current-text-column): Improve error message
The previous version is apparently not clear enough for some people.

Link: https://list.orgmode.org/412FBC9A-3DA2-48A7-A57F-AA90A40B5BEA@gmail.com/T/#t
2023-12-19 12:51:04 +01:00
Ihor Radchenko d6924212bd
lisp/org-macs.el: Fix some checkdoc warnings
* lisp/org-macs.el (org-with-remote-undo): Avoid using Elisp symbol
without quotes.
(org-with-wide-buffer): Mark the argument in docstring.
2023-12-15 12:21:10 +01:00
Ihor Radchenko 1fe051fa19
fixup! org-string-width: Fix measuring lines beyond window width 2023-12-05 20:38:32 +01:00
Ihor Radchenko 4a7a1f2fe7
org-string-width: Fix measuring lines beyond window width
* lisp/org-macs.el (org-string-width): Pass non-nil X-LIMIT argument
to `window-text-pixel-size' to not limit the maximum width to window
pixel width.

Reported-by: Raffael Stocker <r.stocker@mnet-mail.de>
Link: https://orgmode.org/list/yplmr0k4bv9d.fsf@mnet-mail.de
2023-12-05 16:40:37 +01:00
Ihor Radchenko 315417582f
lisp/org.el (org-mode): Force `tab-width' to be 8
* lisp/org-macs.el (org-current-text-column): Assert `tab-width' to be
8 to ensure consistency of the parser across user configurations.
* etc/ORG-NEWS (~tab-width~ value is now assumed to be 8): Document
the breaking change.

This breaking change is made to standardize Org mode format for list
items.  With variable `tab-width', indentation in lists may depend on
user settings leading to inconsistent Org documents when open by
different users.

Link: https://orgmode.org/list/2c9a6cbd-21c0-45bf-8fbb-4f7eccac4ae7@app.fastmail.com
2023-12-05 14:11:23 +01:00
Ihor Radchenko b1c507c0ee
org-find-base-buffer-visiting: Document function argument
* lisp/org-macs.el (org-find-base-buffer-visiting): Fix the docstring.
2023-09-20 11:02:32 +03:00
Ihor Radchenko dcd2ba4a02
* lisp/org-macs.el: Declare `org-buffer-text-pixel-width' 2023-08-15 13:49:02 +03:00
Max Nikulin 2f79c63c2c
org-macs.el: Fix Emacs-26 compatibility
lisp/org-macs.el (org-string-width): Avoid multiple variables in
`setq-local' since it is not supported by Emacs-26.

The code caused the issue was added in 0c29f53ab8723.
2023-08-11 19:24:36 +03:00
Ihor Radchenko 6c40983e86
org-with-remote-undo: Update docstring
* lisp/org-macs.el (org-with-remote-undo): Mention all the arguments.
Document that function is not useful outside agenda.
2023-08-09 11:47:07 +03:00
Roshan Shariff 4ea9a98f85
org-macs: Fix incorrect use of relative paths in org-compile-file
* org-macs.el (org-compile-file, org-compile-file-commands): Resolve
symlinks in default-directory before computing relative source path

Commit 5a8a1d4ff [1] changed org-compile-file to use
`file-relative-name` for the SOURCE argument.  This was intended to
fix bug [2] by expanding ~ directories, like a shell.  Unfortunately,
this breaks when DEFAULT-DIRECTORY is a symlink and SOURCE has an
absolute path.

For example, on macOS Ventura, ~/Dropbox is a symlink to
~/Library/CloudStorage/Dropbox.  Suppose DEFAULT-DIRECTORY is
/Users/username/Dropbox and SOURCE is /var/tmp/test.org, so its
relative path is ../../../var/tmp/test.org.  But the working directory
of a compilation process is actually ~/Library/CloudStorage/Dropbox,
relative to which the source path resolves to
/Users/username/var/tmp/test.org.  The process thus cannot find the
source file.

This commit changes `org-compile-file` and its helper function
`org-compile-file-commands` to resolve symlinks in DEFAULT-DIRECTORY
before computing the relative path of SOURCE.  If SOURCE is already
relative, it is used as-is.  The absolute path is processed by
`expand-file-name`, avoiding bug [1].

[1] https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=5a8a1d4ff
[2] https://orgmode.org/list/25528.42190.53674.62381@gargle.gargle.HOWL

TINYCHANGE
2023-08-06 09:44:13 +03:00
Ihor Radchenko 11ce194dcf
org-string-width: Fix Emacs <29 compatibility
* lisp/org-compat.el (org-buffer-text-pixel-width): New function using
`buffer-text-pixel-size' in Emacs >=29 and falling back to
`window-text-pixel-size' in older Emacs.
* lisp/org-macs.el (org-string-width): Use the new function.
2023-08-04 10:53:17 +03:00
Ihor Radchenko 323a669921
org-string-width: Remove unnecessary dedicated window check
* lisp/org-macs.el (org-string-width): Do not handle dedicated
selected window specially.  The bug fixed by 946abeb49 is no
longer reproducible using the release version of Emacs 29 and other
Emacs versions.  Apparently, it was caused by now-fixed Emacs bug
specific to Emacs 29.

Also, use `buffer-text-pixel-size' as in `string-pixel-width' from
Emacs master.  Using `window-text-pixel-size' requires setting buffer
to window, which is tricky when selected window is dedicated (see
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=64986).
2023-08-02 08:04:56 +03:00
Ihor Radchenko 884b84f7ad
org-string-width: Adapt Emacs commit 0c29f53ab8723
* lisp/org-macs.el (org-string-width): Make sure that default values
of `line-prefix' and `wrap-prefix' do not affect width calculation.

Link: https://git.savannah.gnu.org/cgit/emacs.git/commit/?h=emacs-29&id=0c29f53ab8723dd5a9f31ce8a6e913cc08132e56
2023-08-01 10:06:01 +03:00
Ihor Radchenko dd586c5f42
* lisp/org-macs.el (org-time-convert-to-list): Provide declaration
Update obsolete declaration using the function that is used now.
This fixes native-comp warning.
2023-07-30 12:27:21 +03:00
Ihor Radchenko d5006e195a
Merge branch 'bugfix' 2023-07-30 12:22:09 +03:00
Ihor Radchenko da1bc002f2
Backport Emacs commit 670174a6d5f
* lisp/org-macs.el (org-replace-escapes): Suppress byte-compiler
warning about modifying constant string.

Unlike, 39786a8dbf, this commit does not
create merge conflicts.
2023-07-30 12:21:37 +03:00
Ihor Radchenko 3007511f3f
org-string-width: Reuse buffer when calculating string width
* lisp/org-macs.el (org-string-width): Use dedicated buffer instead of
creating a new one every time.  The idea is from `string-pixel-width'.
2023-07-17 12:33:03 +03:00
Sébastien Miquel 2e2ed40553
org-src.el: Use native value of `indent-tabs-mode' for indentation
* lisp/org.el (org-indent-line): Simplify native indentation inside
src block.  Ensure we add the org indentation if the line is empty.
* lisp/org-macs.el (org-do-remove-indentation): Preserve
indentation (spaces vs tabs) past the common indentation to remove.
Do not empty blank lines.
* lisp/org-src.el (org-src--contents-for-write-back): Preserve the
native indentation (spaces vs tabs).  If necessary, add a common org
indentation to the block according to org's `indent-tabs-mode'.
(org-src-font-lock-fontify-block): Display the native indentation tab
characters with a fixed width, according to the native tab width
value, to preserve vertical alignement in the org buffer.
* testing/lisp/test-org-src.el (test-org-src/indented-blocks): Update
tests.  Indentation no longer obeys `indent-tabs-mode' from the org
buffer, but is separated in an eventual org part, and the native part.

Link: https://list.orgmode.org/87a5wcez7e.fsf@localhost/T/#t
2023-07-07 11:58:43 +03:00
Justin Vallon f18fad60b6
org-id-uuid: Use compat org-time-convert-to-list for emacs <27.1
* lisp/org-macs.el (org-id-uuid): Use `org-time-convert-to-list'
instead of `time-convert', which is not yet available in Emacs 26.
2023-07-05 13:28:38 +03:00
Ihor Radchenko a04e16bd11
lisp/org-macs.el: Restructure file outline, fixing compiler warning
Add new section "Misc", moving all the functions that do not belong to
other sections below.  This also fixes defun order for
`org-compile-file' that needs `org-trim' to be defined.
2023-07-01 14:36:18 +03:00
Ihor Radchenko f93d855c51
Prefer `forward-line' over `beginning-of-line'
The latter is much slower.

Link: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=63225#98
2023-07-01 14:36:14 +03:00
Ihor Radchenko e1a2ea65ef
Allow syntax nodes to be supplied in place of POM in API functions
* lisp/org-agenda.el (org-agenda-entry-get-agenda-timestamp):
* lisp/org-element.el (org-element-context):
* lisp/org-habit.el (org-is-habit-p):
* lisp/org-id.el (org-id-get):
* lisp/org-macs.el (org-with-point-at):
* lisp/org.el (org-fast-tag-selection):
(org-get-tags):
(org-entry-properties):
(org--property-local-values):
(org-entry-get):
(org-entry-delete):
(org-entry-remove-from-multivalued-property):
(org-entry-member-in-multivalued-property):
(org-entry-put-multivalued-property):
(org-entry-get-with-inheritance):
(org-entry-put):
(org-read-property-value):
(org-read-property-value):
(org-property-get-allowed-values): Allow POM to be a cached Org syntax
node.
2023-07-01 14:36:04 +03:00
Ihor Radchenko 607c230d74
org-with-point-at: Accept syntax node as POM 2023-07-01 14:35:46 +03:00
Ihor Radchenko 7da765e459
Revert "org-replace-escapes: Fix compiler warning"
This reverts commit 39786a8dbf.

In favor of an equivalent upstream Emacs commit 670174a6d5f.
2023-06-26 13:43:44 +03:00
Ihor Radchenko 39786a8dbf
org-replace-escapes: Fix compiler warning
* lisp/org-macs.el (org-replace-escapes): Do not modify constant
string.
2023-06-25 14:05:36 +03:00
Ihor Radchenko 1cb5de6211
org-eval: Use `condition-case-unless-debug' for better backtraces 2023-06-02 10:52:12 +03:00
Ihor Radchenko 93492b8619
org-compile-file: Ensure whitespace before ERR-MSG
* lisp/org-macs.el (org-compile-file): Make sure that ERR-MSG has
lading whitespace and no trailing whitepace when displaying error.

Reported-by: Niall Dooley <dooleyn@gmail.com>
Link:
https://orgmode.org/list/CADS3Lq5Uv4gK0U93H2EX9r=g43BbhzHT33oXbWVg7bAURmFvFw@mail.gmail.com
2023-05-25 13:56:32 +02:00
Ihor Radchenko 6d9f3af774
org-element--parse-to: Micro optimizations
* lisp/org-element.el (org-element-headline-parser): Store :true-level
property.
(org-element--parse-to): Call `org-get-limited-outline-regexp'
directly rather than via `org-with-limited-levels'.  Avoid moving
point unnecessarily.  Prefer `org-headline-re' to generate regexps.
* lisp/org-macs.el (org-headline-re):
(org-skip-whitespace): Inline.
2023-05-18 15:22:49 +02:00
Ihor Radchenko bc4ee1c72a
org-element--current-element: Micro optimizations
* lisp/org-element.el (org-element--current-element): Try hard
spending minimal amount of time in testing which parser to call.
Prefer `look-at-p' that does not modify match data and thus save us
significant amount of time.  Do not call `org-with-limited-levels' and
instead use the simplest possible tests with all unnecessary branches
removed.  Add commentary explaining the importance of writing fast
core when adding new elements.
(org-inlinetask-min-level): Declare variable.

* lisp/org-list.el (org--item-re-cache):
(org-item-re): Cache results rather than calculating regexp every time
the parser is invoked.
* lisp/org-macs.el:
(org--headline-re-cache):
(org--headline-re-cache-no-bol):
(org--headline-re-cache-bol):
(org-headline-re): Prefer plists to store headline regexp cache - the
number of items tends to be within 10-20 and hence hash table is an
overkill and will be slower.
2023-05-18 15:22:44 +02:00
Ihor Radchenko 3a4f9604f1
Cache <N>-level headline regexps instead of calculating dynamically
* lisp/org-macs.el (org-headline-re): New function to retrieve cached
or get a new regexp for headline of level TRUE-LEVEL.
(org-get-limited-outline-regexp): Use `org-headline-re'.  Add new
optional argument WITH-BOL.
2023-05-18 15:07:24 +02:00
Kyle Meyer e5ae9c0ce7 Merge branch 'bugfix' 2023-04-30 19:55:54 -04:00
Stefan Monnier 2993f482c1 Backport commit 2bcf11d0e from Emacs
* lisp/org-macs.el (org--inhibit-version-check): Fix docstring.

2bcf11d0efecd18a1be8bcf0ac1a1dadb14d971a
Stefan Monnier
Sun Apr 30 09:41:13 2023 -0400
2023-04-30 19:34:05 -04:00
Ihor Radchenko 310a668917
org-compile-file-commands: Fix return value when PROCESS is a function
* lisp/org-macs.el (org-compile-file-commands): Make sure that we
always return a list, as expected by `org-compile-file'.  Document the
return value in the docstring.  Also, document ERR-MSG argument.

Reported-by: John Kitchin <jkitchin@andrew.cmu.edu>
Link: https://orgmode.org/list/CALEYq0_DsD2Ofw1XG4=EbEbJ9nr5_jWoU1+7-kUkmZF=ELhd5Q@mail.gmail.com
2023-04-30 18:42:02 +02:00
Ihor Radchenko 989cc51499
Prefer "timestamp" over "time-stamp"
* lisp/org.el (org-time-stamp-formats):
(org-timestamp-formats):
(org-time-stamp-rounding-minutes):
(org-timestamp-rounding-minutes):
(org-time-stamp-custom-formats):
(org-timestamp-custom-formats):
(org-time-stamp):
(org-timestamp):
(org-time-stamp-inactive):
(org-timestamp-inactive):
(org-insert-time-stamp):
(org-insert-timestamp):
(org-toggle-time-stamp-overlays):
(org-toggle-timestamp-overlays):
(org-time-stamp-to-now):
(org-timestamp-to-now):
* lisp/ox.el (org-export-time-stamp-file):
(org-export-timestamp-file): Rename using "timestamp" term, keeping
the old name as alias.
* doc/org-manual.org: Update all the uses, adding #+findex and
 #+vindex entries.  Keep the alias names for searchability.

Adjust all the callers.

The following "time-stamp" uses are unchanged:
1. `org-time-stamp-format' where obsolete and _different_ function
   `org-timestamp-format' still exists.
2. :time-stamp-file property in export INFO plist.  Changing this
   would be breaking.
3. ORG-NEWS remains unchanged.
2023-04-30 13:48:52 +02:00