Compare commits

...

1619 Commits

Author SHA1 Message Date
TEC 8f1d75ae1b
---END PERSONAL NOPUSH DIVIDER---
--
2.42.0
2024-04-16 20:07:28 +08:00
TEC 2a78c11a96
NOPUSH org: Don't fill displayed equations in text
* list/org.el (org-fill-element): If a displayed equation (\[ ... \])
starts on its own line, it should not be filled into the rest of the
text. I.e.,

some nice text
\[
  1+1=2
\]
more text.

should not become,

some nice text \[ 1+1=3 \] more text.

While the above example may not look bad, with non-trivial equations
this can become quite messy.
2024-04-16 20:07:28 +08:00
TEC 8d3909de66
NOPUSH org-src: Prettify inline results
* lisp/org.el (org-inline-src-prettify-results):

* lisp/org-src.el (org-fontify-inline-src-blocks-1):
2024-04-16 20:07:28 +08:00
TEC 9183d8e6ff
---NOPUSH PERSONAL DIVIDER---
--
2.42.0
2024-04-16 20:07:28 +08:00
Karthik Chikmagalur f8c1678317
org-latex-preview: Fix live previews org-src setup
* lisp/org-latex-preview.el (org-latex-preview-live--src-buffer-setup):
Ensure that live LaTeX previews of org-src buffer contents are created
in the src buffer.  Since this runs on a timer, the active buffer can be
different from the org-src LaTeX buffer when the preview run fires.
Ensure that `org-element-context' is not called from the org-src buffer
by setting the element type persistently when it is set up.
2024-04-16 20:07:08 +08:00
Karthik Chikmagalur b3ed738b26
ox-odt: Update to use org-latex-preview
* lisp/ox-odt.el (org-odt-latex-image-options,
org-odt-link--inline-image, org-odt--translate-latex-fragments):
Use the org-latex-preview library to generate LaTeX preview images
for ODT exports when exporting with an appropriate method (dvipng,
dvisvgm or imagemagick).  The new user option
`org-odt-latex-image-options' adds LaTeX preview image processing
options for ODT exports similar to
`org-latex-preview-appearance-options' for in-buffer previews.
Add support for svg images in ODT exports, as well as LaTeX images
scaled to match the surrounding text.  Baseline alignment for
images is not implemented.
2024-04-16 19:58:50 +08:00
Karthik Chikmagalur 2143cf5f09
ox-html: Use org-latex-preview for LaTeX preview images
* lisp/ox-html.el (org-html-latex-image-options,
org-html-prepare-latex-images, org-html-latex-image,
org-html-latex-image--data, org-html-close-tag): Delegate LaTeX
preview image creation to `org-latex-preview-cache-images'.
Require both 'svg and 'svg-embed in the :inline condition of
`org-html-latex-image-options' to embed svg tags.  Handle LaTeX
preview image generation errors gracefully when exporting to html,
and highlight missing images in the html output.
2024-04-16 19:58:50 +08:00
Karthik Chikmagalur bfad8754d7
org-latex-preview: Add export-helper function
* lisp/org-latex-preview.el (org-latex-preview-cache-images,
org-latex-preview--colors-around): Add
`org-latex-preview-cache-images', which produces preview images
synchronously for all applicable LaTeX fragments in a parse-tree
and provides a hash table containing this information.  This is
intended for use with export backends (html, odt) that can display
LaTeX using svg/png LaTeX preview images.  The function can also
be used for general scripting purposes, to obtain a list of image
files and metadata for LaTeX fragments in an Org buffer.
2024-04-16 19:58:50 +08:00
TEC e7b49a4686
ox-latex: Fix interning of engraved theme keyword
* lisp/ox-latex.el (org-latex-src-block--engraved,
org-latex-inline-src-block--engraved): The engrave-faces backend expects
themes to be named using symbols, as does the default theme used by org
`org-latex-engraved-theme'. However, when set using #+attr_latex or the
use of #+latex_engraved_theme the value in the info plist is a string.
Thus, the code path needs to handle both string and symbol values,
interning string values to symbols.
2024-04-16 19:58:50 +08:00
TEC 68f255213c
ox-latex: Introduce \codefont command
* lisp/ox-latex.el (org-latex-engraved-preamble): Make it easier to
customise the font used in engraved Code environments with a \codefont
command (defaulting to \footnotesize).
2024-04-16 19:58:50 +08:00
TEC 7f60422b2f
ox-latex: Use more robust engraved theme grouping
* lisp/ox-latex.el (org-latex-src--engrave-code): Use of curly brackets
for grouping has a few edge-cases which \begingroup-\endgroup should not
suffer from.
2024-04-16 19:58:50 +08:00
TEC 5efff6ebd4
ox-latex: Better handle multiple engraved themes
* lisp/ox-latex.el (org-latex-generate-engraved-preamble): Improve the
generated LaTeX code in the multiple-themes case. Using "\long\def"
instead of "\newcommand" mixed with "\renewcommand" is needed without
without duplicating the default theme.  The "\efstrut" command also
needs to be extracted out of the theme-generated commands, which was
previously overlooked.
2024-04-16 19:58:50 +08:00
TEC a8b35e4fc1
ox-latex: Fix engraved-theme propagation
* lisp/ox-latex.el (org-latex-src-block--engraved,
org-latex-src--engrave-code, org-latex-inline-src-block--engraved):
Actually propagate the ":latex-engraved-theme" property through to the
`org-latex-src--engrave-code` call.  To account for whether the theme is
the default theme, or whether it will need to be explicitly switched to,
a new indicator argument ("explicit-theme-p") has been added to
`org-latex-src--engrave-code`.
2024-04-16 19:58:50 +08:00
TEC 159cb401bf
ol: more versatile #+link replacement forms (WIP)
* lisp/ol.el (org-link-expand-abbrev, org-link--abbrev-functions): Allow
link abbreviations to use %s and %h as format-specs, as well as allowing
an anonymous function form with %(sexpr using tag).
2024-04-16 19:58:50 +08:00
TEC 4f0592b21b
org: Introduce semantic seperator fontification
* lisp/org.el (org-fontify-semantic-seperator,
org-set-font-lock-defaults): TODO
2024-04-16 19:58:50 +08:00
TEC 2fde128b19
ox-html: Fix C++ label CSS
* lisp/ox-html.el (org-html-style-default): The "C++" pre-label works if
the "+" characters are backslash-escaped.
2024-04-16 19:58:50 +08:00
TEC 39975f281b
---PATCH SET DIVIDER---
--
2.42.0
2024-04-16 19:58:50 +08:00
TEC e03c702bc4
org-latex-preview: Add authors header
* lisp/org-latex-preview.el: Mention that Karthik and I authored this
file.
2024-04-16 19:58:50 +08:00
Karthik Chikmagalur f6c7309e4d
org-latex-preview: Fix bug when checking previews
*
lisp/org-latex-preview.el (org-latex-preview--check-all-fragments-produced):
When the first fragment in a preview run silently fails to render,
this function tries to cache a nil value as a fragment.  Fix by
checking that the fragment that fails to render is valid as a
fragment.
2024-04-16 19:58:50 +08:00
TEC 157784392c
org-latex-preview: Take advantage of dvisvgm3.2
* lisp/org-latex-preview.el (org-latex-preview--tex-styled,
org-latex-preview--dvisvgm-filter,
org-latex-preview--dvisvgm-version>=3.1,
org-latex-preview-process-alist,
org-latex-preview--dvisvgm3-minor-version): Take advantage of the new
--message flag of dvisvgm 3.2 to produce a more concise output.
2024-04-16 19:58:50 +08:00
TEC 3019d930d6
ox-html: Allow inlining svg tex as <svg> elements
* lisp/ox-html.el (org-html-latex-image--data, org-html-latex-image):
Add support for inlining dvisvgm-exported svgs as <svg> elements,
preserving the effect of the currentColor attribute.  While making this
change, we improve a few other aspects of the html LaTeX fragment export
system, namely refactoring/code style improvements and the recognition
of \[...\] and $$...$$ fragments as blocks not inline fragments.
2024-04-16 19:58:50 +08:00
TEC fdaeb38609
org-latex-preview: Skip blank fragments
* lisp/org-latex-preview.el (org-latex-preview--construct-entries,
org-latex-preview-auto--regenerate-overlay): Blank fragments produce
invisible previews, which is at best silly and at worst confusing.  It's
much better to simply not produce a preview image of blank fragments.
We also now avoid exessive re-numbering calculations when repeatadly
generating live previews.
2024-04-16 19:58:50 +08:00
TEC de4fb9de11
org-latex-preview: Accommodate a flaky cache
* lisp/org-latex-preview.el (org-latex-preview--get-cached): When using
persist, occasionally we need to be more careful about assuming that
cache entries exist.
2024-04-16 19:58:50 +08:00
Karthik Chikmagalur 59f4ba2111
org-latex-preview: Handle html export preview fail
* lisp/org-latex-preview.el (org-latex-preview--check-all-fragments-produced):
This function assumes that previews are being generated for placement in
the buffer.  Handle the case of preview generation for HTML exports.
2024-04-16 19:58:50 +08:00
TEC d4c97fee06
org-latex-preview: Fix face selection Emacs 28 bug
* lisp/org-latex-preview.el (org-latex-preview--face-around): On Emacs
28 (and presumably below), should a face with :extend set be identified
as appropriate, the overlay may cast a pall (background colour) over the
rest of the line.  This can be addressed by replacing the use of the
default face to normalise display with an anonymous face that inherits
from default and has the :extend attribute set.

Reported-by: Roshan Shariff <roshan.shariff@gmail.com>
Link: https://list.orgmode.org/CAG8iPGxoAD7qmKzDXQ_SRFbmxD7jdM96piCa-dCSCpzae4rCsw@mail.gmail.com
2024-04-16 19:58:50 +08:00
TEC bc2ef6c91d
ox-html: Support for customised latex image dir
* lisp/ox-html.el (org-html-latex-image, org-html-prepare-latex-images,
org-html-latex-image-options): Allow for customising the LaTex image
directory in `org-html-latex-image-options'.
2024-04-16 19:58:50 +08:00
TEC a7b576a567
org-latex-preview: Rework general cache variable
* lisp/org-latex-preview.el (org-latex-preview--get-cached,
org-latex-preview--table, org-latex-preview-persist,
org-latex-preview-cache): Rename and tweak `org-latex-preview-persist'
to also allow for caching to a custom directory, and (in the near
future) unify behaviour with HTML export.

* testing/lisp/test-org-latex-preview.el: Accommodate for the cache variable
change.

* etc/ORG-NEWS: Accommodate for the cache variable change.
2024-04-16 19:58:50 +08:00
TEC 988e24b254
org-latex-preview: Add ignored auto environments
* lisp/org-latex-preview.el (org-latex-preview-live--src-buffer-setup,
org-latex-preview-auto--maybe-track-element-here,
org-latex-preview-auto-ignored-environments): Introduce a new
customisation variable `org-latex-preview-auto-ignored-environments',
for specifying environments that should not be automatically previewed.
2024-04-16 19:58:50 +08:00
Karthik Chikmagalur 2ca8200554
org-latex-preview: Dynamic throttle for live previews
* lisp/org-latex-preview.el (org-latex-preview-live--throttle,
org-latex-preview-live-throttle,
org-latex-preview-live--preview-times,
org-latex-preview-live--update-times,
org-latex-preview-live--record-hook,
org-latex-preview-live--regenerate,
org-latex-preview-live--update-props,
org-latex-preview-live--src-buffer-setup,
org-latex-preview-live--setup, org-latex-preview-live--teardown,
org-latex-preview--create-image-async): Find the optimal throttle
time for live preview updates dynamically.  The variable
`org-latex-preview-live--preview-times' records the last three
process run times, and `org-latex-preview-live-throttle' is set to
the average of these.  This ensures that there are never more than
two concurrent processes live-previewing a single fragment.  Start
another preview run process the end of the throttle period if the
preview image is out of date to ensure that the state of the
preview is eventually consistent with the contents of the
fragment.
2024-04-16 19:58:50 +08:00
TEC 36178651d4
org-latex-preview: Adjust customisation scheme
* lisp/org-latex-preview.el (org-latex-preview-live--teardown,
org-latex-preview-live--setup, org-latex-preview-live--src-buffer-setup,
org-latex-preview-live--ensure-overlay, org-latex-preview-throttle,
org-latex-preview-debounce, org-latex-preview-live-preview-inline,
org-latex-preview-auto--open-this-overlay,
org-latex-preview-auto--detect-fragments-in-change,
org-latex-preview-auto--handle-post-cursor,
org-latex-preview--face-around, org-latex-preview-auto-generate,
org-latex-preview-auto-blacklist, org-latex-preview-clear-cache,
org-latex-preview--latex-preview-filter,
org-latex-preview--create-tex-file,
org-latex-preview--create-image-async, org-latex-preview--hash,
org-latex-preview--auto-aware-toggle, org-latex-preview--preview-region,
org-latex-preview-live--teardown, org-latex-preview-live--setup,
org-latex-preview-live--src-buffer-setup,
org-latex-preview-live--ensure-overlay,
org-latex-preview-auto--regenerate-overlay,
org-latex-preview-auto--close-previous-overlay,
org-latex-preview-auto--open-this-overlay,
org-latex-preview-auto--detect-fragments-in-change,
org-latex-preview--update-overlay,
org-latex-preview--indicate-processing, org-latex-preview-precompile,
org-latex-preview-open-functions, org-latex-preview-close-functions,
org-latex-preview-update-overlay-functions,
org-latex-preview-auto-command-blacklist,
org-latex-preview-processing-indicator,
org-latex-preview-default-process): Change the customisation naming
scheme to be more consistent.

* testing/lisp/test-org-latex-preview.el: Change the LaTeX preview
customisation naming scheme to be more consistent.

* lisp/org-compat.el: Change the LaTeX preview customisation naming
scheme to be more consistent.

* etc/ORG-NEWS: Change the LaTeX preview customisation naming scheme to
be more consistent.

* doc/org-manual.org (Footnotes, Previewing LaTeX fragments): Change the
LaTeX preview customisation naming scheme to be more consistent.
2024-04-16 19:58:50 +08:00
TEC 443239a12a
org-latex-preview: Formatting and spacing tweaks
* lisp/org-latex-preview.el (org-latex-preview--dvipng-filter,
org-latex-preview--latex-preview-filter,
org-latex-preview--create-tex-file,
org-latex-preview--create-image-async,
org-latex-preview--get-numbered-environments,
org-latex-preview-live--setup,
org-latex-preview-live--update-overlay-run,
org-latex-preview-auto--detect-fragments-in-change,
org-latex-preview--update-overlay): Adjust formatting/spacing.
2024-04-16 19:58:50 +08:00
Karthik Chikmagalur 8f2a647bc2
org-latex-preview: Live previews in org-src bufs
* lisp/org-latex-preview.el (org-latex-preview-live--src-buffer-setup):
When live previews are enabled in an Org buffer and using org-src
buffers to edit LaTeX fragments (via `org-edit-special'), show
continuously updated previews in the source Org buffer if it is
visible.  If it is not visible, show continuously updated previews
in the org-src buffer.
2024-04-16 19:58:50 +08:00
Karthik Chikmagalur dcf2982e99
org-latex-preview: Eldoc support for live previews
* lisp/org-latex-preview.el (org-latex-preview-live-display-type,
org-latex-preview-live--display-in-eldoc,
org-latex-preview-live--update-eldoc,
org-latex-preview-live--setup, org-latex-preview-live--teardown):
Add Eldoc support for live previews.  The user option
`org-latex-preview-live-display-type' now accepts the symbols
buffer and eldoc as values.  When it is set to eldoc and live
previews are enabled, display of the continuously updated previews is
handled by Eldoc.  Note that previewing larger images with Eldoc may
require `eldoc-echo-area-use-multiline-p' and `max-mini-window-height'
to be set appropriately.
2024-04-16 19:58:50 +08:00
Karthik Chikmagalur e7e7ec0cb1
org-latex-preview: Add support for live previews
* lisp/org-latex-preview.el (org-latex-preview-auto-generate,
org-latex-preview-live-preview-inline, org-latex-preview-throttle,
org-latex-preview-debounce, org-latex-preview-live-display-type,
org-latex-preview-live--debounce,
org-latex-preview-live--throttle,
org-latex-preview-live--clearout,
org-latex-preview-live--regenerate,
org-latex-preview-live--update-props,
org-latex-preview-live--ensure-overlay,
org-latex-preview-live--update-overlay,
org-latex-preview-live--setup, org-latex-preview-live--teardown,
org-latex-preview-live--docstring,
org-latex-preview-live--element-type,
org-latex-preview-live--generator,
org-latex-preview--ensure-overlay,
org-latex-preview--failure-callback,
org-latex-preview--svg-make-fg-currentColor): Add support for
live-previewing LaTeX fragments.  When
`org-latex-preview-auto-generate' is set to the symbol live and
`org-latex-preview-auto-mode' is turned on, LaTeX previews are
continuously updated when editing a LaTeX fragment.  These
previews are shown to the right of or below the fragment.  The
preview generation timing can be controlled using the options
`org-latex-preview-debounce' and `org-latex-preview-throttle'.
2024-04-16 19:58:50 +08:00
TEC a93808588f
org-latex-preview: Update copyright years 2024-04-16 19:58:50 +08:00
TEC 4280eb3869
org-latex-preview: Put :page-width in opt plist
* lisp/org-latex-preview.el (org-latex-preview-options,
org-latex-preview-appearance-options): Rename
`org-latex-preview-options' to `org-latex-preview-appearance-options',
as it better reflects the purpose of the variable.

(org-latex-preview--tex-styled, org-latex-preview--image-extract-async,
org-latex-preview--create-tex-file,
org-latex-preview--create-image-async, org-latex-preview--hash,
org-latex-preview-place, org-latex-preview--update-overlay): Put the
page width specification in `org-latex-preview-appearance-options', and
adjust existing code to handle this new structuring.

* lisp/ox-html.el (org-html-prepare-latex-images,
org-html-latex-image-options): Adjust for the
`org-latex-preview-appearance-options' rename, and put :page-width in
the options plist, just with a raised value of 1.0 as the HTML default.

* lisp/org.el (org-do-latex-and-related, org-latex-preview-options),
org-compute-latex-and-related-regexp): Adjust for the
`org-latex-preview-appearance-options' rename.

* lisp/org-compat.el: Adjust for the
`org-latex-preview-appearance-options' rename.

* lisp/ob-latex.el (org-babel-execute:latex, org-latex-preview-header)):
Adjust for the `org-latex-preview-appearance-options' rename.

* etc/ORG-NEWS: Adjust for the `org-latex-preview-appearance-options'
rename.

* doc/org-manual.org (Previewing LaTeX fragments): Adjust for the
`org-latex-preview-appearance-options' rename.
2024-04-16 19:58:50 +08:00
Karthik Chikmagalur b2adb517f4
org-latex-preview: Fix preview help-echo property
* lisp/org-latex-preview.el (org-latex-preview--update-overlay):
Add LaTeX compilation errors to the help-echo property when the
cursor is inside the fragment that is being previewed.  This
primarily affects the use of `org-latex-preview-auto-mode`.
2024-04-16 19:58:50 +08:00
TEC 79336cef3d
org-latex-preview: Improved face heuristics
* lisp/org-latex-preview.el (org-latex-preview--face-around): To work
around issues where syntax highlighting of the underlying LaTeX fragment
interferers with the foreground colour of the preview, we append default
to the face list regardless.

(org-latex-preview--ignored-faces): While we're improving face
heuristics, it's also come to my attention that whitespace-mode can
interferer with face selection, and whitespace-mode should also be
ignored.  Perhaps this should become part of the API?
2024-04-16 19:58:50 +08:00
TEC 5dbe159407
org-latex-preview: Support symbol entrypoint args
* lisp/org-latex-preview.el (org-latex-preview): Refactor to support a
symbol-value "mode" argument as well as prefix arguments.  This stops
forcing programmatic invocations from having to use uninformative
values, and actually makes the implementation slightly nicer to read I
think.

* lisp/org.el: Change the argument in the preview startup invocation to 'buffer.
2024-04-16 19:58:50 +08:00
TEC 5e7af27352
org-latex-preview: Robustify DPI calculation
* lisp/org-latex-preview.el (org-latex-preview--get-display-dpi): It was
reported that on a WSLg system using pgtk that
`org-latex-preview--get-display-dpi' produced an arithmetic overflow
error.  Inspecting the calculation performed and docstrings of functions
involved, it seems we need to be more careful of the `display-mm-height'
output.  We now guard against it being zero or nil, which should make
the DPI calculation more robust.

Simply falling back to a guessed DPI of 140 is non-ideal, but probably
the best we can reasonably do here.
2024-04-16 19:58:50 +08:00
TEC c20bf88205
org-latex-preview: Guard against deleted buf/ov
* lisp/org-latex-preview.el (org-latex-preview--place-images): Since the
image generation and placement is asynchronous, it is possible that in
the meantime the target overlay or even buffer could be deleted.  To
avoid errors, we simple check that this is not the case before
attempting to place preview images.
2024-04-16 19:58:50 +08:00
TEC 557275af54
org-latex-preview: Still show errs with no tooltip
* lisp/org-latex-preview.el (org-latex-preview--update-overlay): When
`tooltip-mode' is not active, still show the error, just remove multiple
spaces to be economic with the horizontal room available.  This isn't
good as showing the tooltip, but it's better than not showing anything.
2024-04-16 19:58:50 +08:00
TEC 90e7813dd7
org-macs: Set some process variables in org-async
* lisp/org-macs.el (org-async-call): When eking out maximum performance
from external commands, there are a few potentially important process
variables. `org-async-call' is extended to support setting these, with
default values that differ from Emacs' defaults but should enable better
performance in general.
2024-04-16 19:58:50 +08:00
TEC f52b7b4c89
org-latex-preview: Mention latex buffer if no dvi
* lisp/org-latex-preview.el (org-latex-preview--failure-callback,
org-latex-preview--create-image-async): When the image conversion step
fails due to a missing input file, point the user to the LaTeX output
buffer instead of the image conversion output buffer.
2024-04-16 19:58:50 +08:00
TEC 7834e6a850
org-latex-preview: Include running command in bufs
* lisp/org-latex-preview.el (org-latex-preview--image-extract-async,
org-latex-preview--tex-compile-async): Add a comment at the start of the
process output buffers mentioning what the command being run is.
2024-04-16 19:58:50 +08:00
TEC 40d8b3acea
org-latex-preview: Simplify color formatting
* lisp/org-latex-preview.el (org-latex-preview--format-color,
org-latex-preview--normalize-color): Use three decimal places, and
remove the now-obsolete `org-latex-preview--normalize-color'.

* lisp/org-compat.el (org-normalize-color): With the removal of the
`org-latex-preview--normalize-color' alias, mark `org-normalize-color'
as obsolete.
2024-04-16 19:58:50 +08:00
TEC b37062d4a8
org-latex-preview: Use dvisvgm 3.1+ currentcolor
* lisp/org-latex-preview.el (org-latex-preview--tex-styled,
org-latex-preview--svg-make-fg-currentColor,
org-latex-preview--dvisvgm-filter,
org-latex-preview--dvisvgm-version>=3.1): With dvisvgm 3.1+, it can
replace the foreground color with "currentColor" itself, and so we can
skip `org-latex-preview--svg-make-fg-currentColor' when we are using a
new enough dvisvgm.

(org-latex-preview--await-fragment-existance): Just in case the
asyncronicity in file writing causes issues, we keep the file existence
check (for now).
2024-04-16 19:58:50 +08:00
TEC 0090e25460
org-latex-preview: Improve env numbering calc
* lisp/org-latex-preview.el (org-latex-preview--get-numbered-environments,
org-latex-preview--environment-numbering-table): Make numbering
calculations more accurate, at the expense of a ~10x increase in the
time to calculate numbering in a document, mitigated by the use of
caching — resulting in a ~2x improvement compared to the simpler method
in subsequent runs.

(org-latex-preview--numbered-environments,
org-latex-preview--numbered-environments-single,
org-latex-preview--numbered-environments-multi,
org-latex-preview--numbered-environments-all): Split
`org-latex-preview--numbered-environments' into
`org-latex-preview--numbered-environments-single' and
`org-latex-preview--numbered-environments-multi', then rename
`org-latex-preview--numbered-environments' to
`org-latex-preview--numbered-environments-all' for the sake of clarity.

Determining the count of numbered equations in a LaTeX environment is
non-trivial.  Previously, a simple heuristic was used that counted the
number of lines ending with "\\" in particular environments, then
subtracted the number of "\nonumber" and "\tag{...}" instances.

However, lines can end with "\\" without contributing to the number of
equations in the environment, consider the "cases" and "bmatrix"
environments.  To improve the heuristic, we (with some care) remove
/all/ inner environments from the LaTeX maths environment before
processing.  Since this takes more effort, we split the numbered
environments into those we know will contain exactly one numbered
equation where we can avoid the extra processing, and those that require
the more sophisticated heuristics.

The new org-element caching API is very helpful for recovering the
performance cost of this extra computation in the long run.
2024-04-16 19:58:50 +08:00
Karthik Chikmagalur 2ff67428fa
org-latex-preview: Fix process filter timing errs
* lisp/org-latex-preview.el (org-latex-preview--create-image-async,
org-latex-preview--latex-preview-filter,
org-latex-preview--dvipng-filter, org-latex-preview--dvisvgm-filter,
org-latex-preview--place-images): The dvipng and latex-preview filters
run concurrently (interleaved), and both contribute image metadata.
So caching/placing images cannot be associated with the dvipng filter,
this leads to non-deterministic errors where preview images can have
incomplete metadata.  To fix this, check if we are using dvipng when
running the LaTeX filter, and place images from whichever of the two
filters processes each fragment second.

Refactor: Move the image placement/caching logic fully to
`org-latex-preview--place-images' instead of duplicating code in all
three (latex-filter, dvipng and dvisvgm) previews.
2024-04-16 19:58:50 +08:00
Karthik Chikmagalur 5210d52d20
org-latex-preview: Fix LaTeX header on fails + reruns
*
lisp/org-latex-preview.el (org-latex-preview--check-all-fragments-produced):
When rerunning a preview run (because of catastrophic failures), pass
the LaTeX header used to the new process.  The current behavior passes
an empty header, which causes the process to fail again.
2024-04-16 19:58:50 +08:00
Karthik Chikmagalur f206164ef4
org-latex-preview: Fix xelatex preview image sizes
*
lisp/org-latex-preview.el (org-latex-preview--include-preview-string,
org-latex-preview--latex-preview-filter):  when xetex is used,
preview.sty assumes PDF output by default and does not write any
postscript data to the output XDV file.  This makes dvisvgm unable to
correctly determine the preview geometry.  Fix by specifying the
`dvips' option to preview, which adds (apparently as a side effect)
this geometry information to the XDV file.

Remove a conditional in `org-latex-preview--latex-preview-filter' that
was previously used to attempt to work around this issue.
2024-04-16 19:58:50 +08:00
Karthik Chikmagalur 3b7c6faf9f
ox-latex: Disable precompile for xelatex/lualatex
* lisp/ox-latex.el (org-latex-make-preamble): If xelatex or
lualatex are used for LaTeX export, disable LaTeX header
precompilation (via the CTAN package mylatexformat) locally in the
buffer and issue a warning.  Xelatex does not support
precompilation, and while Lualatex supports it in some cases, it
is best left unsupported by the Org LaTeX export process until
precompilation support for them improves upstream.

* lisp/org-latex-preview.el (org-latex-preview--create-tex-file):
Make the same changes as above when precompiling LaTeX headers
for LaTeX preview purposes.
2024-04-16 19:58:50 +08:00
Karthik Chikmagalur a9fbf9d7cf
org-latex-preview: Rename precompilation vars
* lisp/org-latex-preview.el (org-latex-preview-precompile,
org-latex-preview--latex-preview-filter,
org-latex-preview--create-tex-file,
org-latex-preview-use-precompilation, org-latex-preview--precompile):
Rename (i) the user option that controls precompilation for LaTeX
previews, and (ii) the function that precompiles headres for LaTeX
previews.  This makes the names shorter and consistent with their
corresponding equivalents in `ox-latex'.

Rename
`org-latex-preview-use-precompilation' -> `org-latex-preview-precompile'
`org-latex-preview-precompile' -> `org-latex-preview--precompile'

The new names have equivalents `org-latex-precompile' and
`org-latex--precompile' in `ox-latex'.

* testing/lisp/test-org-latex-preview.el: Update tests that set this
user option.

* etc/ORG-NEWS: Update the NEWS file.
2024-04-16 19:58:50 +08:00
Karthik Chikmagalur 99f8c7b7fd
org-latex-preview: Fix bug clearing precompile cache
* lisp/org-latex-preview.el (org-latex-preview-clear-cache,
org-latex-preview--create-tex-file,
org-latex-preview--include-preview-string): LaTeX headers that are
precompiled include additional strings that set the
textwidth (according to `org-latex-preview-width') and include
preview.sty.  These strings are not appended to the header when
trying to clear the precompile cache for the present buffer.  Fix
by (i) removing the textwidth declaration from the precompiled
text, and (ii) including the preview.sty inclusion string with the
header we look for when trying to remove the corresponding fmt
file in the org-persist cache.

org-latex-preview--include-preview-string: Introduce string that
holds the text to include preview.sty in the document header.
2024-04-16 19:58:50 +08:00
Karthik Chikmagalur 8f64d73bbd
org-latex-preview: Reduce delay when re-rendering
*
lisp/org-latex-preview.el (org-latex-preview-auto--close-previous-overlay):
Reduce the delay when re-rendering fragments (with `org-latex-preview-auto-mode' turned
on) from 50 ms to 10 ms. This delay is a heuristic number for
perceived smoothness, and this change represents a tuning effort.
2024-04-16 19:58:50 +08:00
Karthik Chikmagalur 513b4a1b12
org-latex-preview: Change preview hashing parameters
* lisp/org-latex-preview.el (org-latex-preview--hash): Use only the
`:scale' parameter from `org-latex-preview-options' when hashing
fragments.  Other parameters like `:zoom' do not affect the content of
the image, so this helps avoid building up garbage in the org-persist
cache.  `org-latex-preview' is also faster since re-rendering images
is required less often.
2024-04-16 19:58:50 +08:00
Karthik Chikmagalur b7a789dbd8
org-latex-preview: Change hooks to abnormal hooks
*
lisp/org-latex-preview.el (org-latex-preview-auto--close-previous-overlay,
org-latex-preview-auto--open-this-overlay,
org-latex-preview-close-hook, org-latex-preview-open-hook): Change
`org-latex-preview-open-hook' and `org-latex-preview-close-hook' to
abnormal hooks that accept an overlay as the argument.  This makes it
easier to apply overlay-specific changes -- which is what these hooks
are primarily for -- without having to find the overlay by probing the
buffer first.

Rename:
`org-latex-preview-open-hook' to `org-latex-preview-open-functions'
`org-latex-preview-close-hook' to `org-latex-preview-close-functions'
2024-04-16 19:58:50 +08:00
Karthik Chikmagalur 0549f0f55f
org-latex-preview: Fix clear-cache command
* lisp/org-latex-preview.el (org-latex-preview-clear-cache): When
clearing the preview cache, clear the cached preamble after clearing
the image cache, since the preamble is used to compute the image
hashes.
2024-04-16 19:58:50 +08:00
Karthik Chikmagalur b536e6506d
test-org-latex-preview: Add preliminary tests
* testing/lisp/test-org-latex-preview.el: Tests for
org-latex-preview.el.

* testing/examples/org-latex-preview-test.org: Short but
full-featured document with LaTeX fragments to run tests on.
2024-04-16 19:58:50 +08:00
Karthik Chikmagalur efb6371315
org-latex-preview: Don't fully reset overlay state
* lisp/org-latex-preview.el (org-latex-preview--ensure-overlay,
org-latex-preview--update-overlay): When ensuring a preview overlay
exists, do not fully reset the state of the overlay, such as the
stored image spec, the flag that checks if the preview is open, etc.
Persisting prior state is required for the "live" preview
feature (introduced in the following commits) to function.  Similarly,
if "live" previewing a LaTeX element that has an overlay attached, do
not set the overlay face or error display indicator(s).
2024-04-16 19:58:50 +08:00
Karthik Chikmagalur 6fc221b439
org-latex-preview: Add hooks for customization
* lisp/org-latex-preview.el (org-latex-preview-process-finish-functions,
org-latex-preview-update-overlay-hook, org-latex-preview-close-hook,
org-latex-preview-open-hook, org-latex-preview--create-image-async,
org-latex-preview-auto--handle-post-cursor,
org-latex-preview--run-finish-functions): Add four hooks for better
control of the LaTeX preview process.

`org-latex-preview-process-finish-functions': Runs after the image
conversion process. This is an abnormal hook: each hook function
accepts the same arguments as other `org-async' callbacks for this
process.

`org-latex-preview-close-hook' and `org-latex-preview-open-hook':
Run after a preview is closed (text hidden to reveal image) or
opened (image hidden to reveal text) respectively.

`org-latex-preview-update-overlay-functions': Run after a LaTeX
preview overlay is updated with a new image.  This is an abnormal
hook: each hook function accepts one argument, the overlay that was
updated.

The "live" preview system introduced in the following commits uses
these hooks, along with the facilities provided by
`org-latex-preview-auto-mode'.  In addition, these hooks will
prove useful when writing code that reuse the API afforded by
`org-latex-preview-place' to provide LaTeX previews for other
major modes.
2024-04-16 19:58:50 +08:00
TEC 6a40115563
org-latex-preview: Ignored cmds list for auto mode
* lisp/org-latex-preview.el (org-latex-preview-auto-blacklist): Add a
blacklist for commands that should not cause LaTeX preview overlays to
be "opened", i.e. for preview images to be hidden and text revealed when
using `org-latex-preview-auto-mode'.  A common use case would be cursor
navigation commands like `next-line' or `scroll-up-command' that are
often intended to move the view of the buffer, where opening preview
overlays can be distracting.
2024-04-16 19:58:50 +08:00
Karthik Chikmagalur 9914b251af
org-latex-preview: Fix overlay boundary deletion bug
*
lisp/org-latex-preview.el (org-latex-preview-auto--regenerate-overlay):
When `org-latex-preview-auto-mode' is active and a LaTeX fragment
or environment boundary is deleted,
`org-latex-preview-auto--regenerate-overlay' generates a new
preview for the new org-element at point, which is no longer a
LaTeX fragment or environment.  This results in paragraph text or
other syntax being captured into the preview.  Fix by adding a
check to ensure that the element post-change is still a LaTeX
fragment or environment.
2024-04-16 19:58:50 +08:00
Karthik Chikmagalur e509cf6adc
org-latex-preview: non-buffer-local auto-marker bug
* lisp/org-latex-preview.el (org-latex-preview-auto--marker,
org-latex-preview-auto-mode): `org-latex-preview-auto--marker' is
initialized to a marker, which can cause it to not be
buffer-local.  Instead, initialize it to nil and explicitly set it
to a marker when running `org-latex-preview-auto-mode'.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur 2835c96dcf
org-latex-preview: Fix startup preamble generation
* lisp/org-latex-preview.el (org-latex-preview--get-preamble):
When `org-startup-with-latex-preview' (or the `#+startup:
latexpreview') option is set, preamble generation and
precompilation fail as latex previews are generated in the clone
of the current buffer created by `org-export-with-buffer-copy'.
This is because org-mode is turned on in the cloned buffer, which
requires creating LaTeX previews there.  Not only is this
unnecessary, it causes a flurry of errors since the cloned buffer
is killed before the previews can be placed.  Explicitly avoid
org-startup-* tasks in the cloned buffer when generating the LaTeX
preamble for our main Org buffer.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur 33c79f8e0e
org-latex-preview: Ensure fmt file cache is cleared
* lisp/org-latex-preview.el (org-latex-preview-clear-cache): When
running `org-latex-preview-clear-cache', the precompiled format
file is only removed from the `org-persist' cache if the preamble
has been cached in the current buffer.  We require the format file
to always be unregistered from the cache, so generate the preamble
if necessary so it can be hashed and used as the key to find the
corresponding format file in the cache.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur 7bd5973233
org-latex-preview: Optimize overlay-modify hook
*
lisp/org-latex-preview.el (org-latex-preview-auto--mark-overlay-modified):
Reduce slightly the number of checks needed to run each time text
inside a LaTeX fragment overlay is modified.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur 3ab374790d
Update ORG-NEWS
* etc/ORG-NEWS: Add summary of `org-latex-preview' changes.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur c0e314cb52
org-manual: Update LaTeX preview section
* doc/org-manual.org (Previewing LaTeX fragments): Mention newly
added user options and `org-latex-preview-auto-mode'.
2024-04-16 19:58:49 +08:00
TEC ea44c61cf1
ox-html: Allow inlining of LaTeX images
* lisp/ox-html.el (org-html-latex-image, org-html-latex-image-options):
Add a new `org-html-latex-image-options' keyword, ":inline", which
controls image inlining in `org-html-latex-image'.
2024-04-16 19:58:49 +08:00
TEC 1b1373f3c9
org-latex-preview: Emit warning when hyperref seen
* lisp/org-latex-preview.el (org-latex-preview--latex-preview-filter):
If during LaTeX compilation hyperref seems to be present, emit a warning
mentioning the sizing issue it is known to cause.
2024-04-16 19:58:49 +08:00
TEC f90b633f9a
org-latex-preview: Add preview-order eqn numbering
* lisp/org-latex-preview.el (org-latex-preview--tex-styled,
org-latex-preview-numbered): Allow for preview-order based equation
numbering, by setting `org-latex-preview-numbered' to the symbol
"preview".
2024-04-16 19:58:49 +08:00
TEC 7340c4fae7
org-latex-preview: Use icon for non-numbered eqns
* lisp/org-latex-preview.el (org-latex-preview--get-preamble,
org-latex-preview--single-eqn-format): When numbering is turned off (via
`org-latex-preview-numbered'), instead of always showing "(1)" as the
equation number, use a diamond symbol, and in multiline environments
show +offset.  The LaTeX setup for this is stored in the new const
`org-latex-preview--single-eqn-format'.
2024-04-16 19:58:49 +08:00
TEC fed2ebc16a
org-latex-preview: Fix snippet preamble hash
* lisp/org-latex-preview.el (org-latex-preview--create-tex-file,
org-latex-preview--hash, org-latex-preview-place,
org-latex-preview-clear-cache): The only the default preamble was being
hashed, which led to incorrect results across documents.  To correctly
hash the preamble, it is now determined at the start of
`org-latex-preview-place', and used in `org-latex-preview--hash',
`org-latex-preview--create-tex-file', and
`org-latex-preview-clear-cache'.
2024-04-16 19:58:49 +08:00
TEC 4ec83eb21e
org-latex-preview: Set overlay priority to -80
* lisp/org-latex-preview.el (org-latex-preview--ensure-overlay): Setting
the overlay priority to -80 ensures that the background colour of
hl-line-mode's overlays takes priority, improving the visual consistency
of previews in the buffer.
2024-04-16 19:58:49 +08:00
TEC 39e0faebd1
ox-html: Update LaTeX export for images and mathml
* lisp/ox-html.el (org-html-latex-environment, org-html-format-latex,
org-latex-to-html-convert-command, org-format-latex-as-html,
org-html-latex-image-options): Introduce new functions and variables to
work directly with the new org-latex-preview and ox-mathml API.

* lisp/org-latex-preview.el (org-format-latex-as-html,
org-latex-preview--tex-styled, org-latex-preview-replace-fragments,
org-latex-to-html-convert-command, org-latex-preview-options,
org-latex-preview-place-image-link): Move all of the HTML-specific
processing out of org-latex-preview.el, and into ox-html.el, and remove
now-obsolete code.

* lisp/org-compat.el (org-place-formula-image, org-html-format-latex):
Relocate a copy of `org-place-formula-image' and `org-html-format-latex'
here, and mark them as obsolete.
2024-04-16 19:58:49 +08:00
TEC 7ce7e39650
ox-mathml: Refactor mathml export
* lisp/ox-mathml.el: Introduce a new library for managing mathml conversion.

* lisp/org-latex-preview.el (org-create-math-formula,
org-format-latex-mathml-available-p, org-latex-to-mathml-jar-file): Move
the various mathml functions into ox-mathml.

* lisp/org-compat.el: Add compat entries for the various mathml
conversion functions that have now been brought under ox-mathml.

* lisp/ox-odt.el (org-odt-export-as-odf,
org-odt--translate-latex-fragments): Use the new org-mathml functions.
2024-04-16 19:58:49 +08:00
TEC 0d28e6ef72
org: Update LaTeX overlay during fontification
* lisp/org.el (org-do-latex-and-related, org-latex-preview-options): To
ensure that LaTeX preview overlays update as the face changes (for
instance, when in a heading that changes level), the face used is
updated during fontification when applicable.  This also ensures that
the correct face is used when JIT fontification is active.
2024-04-16 19:58:49 +08:00
TEC febabadb99
org-latex-preview: Improved face adaptation
* lisp/org-latex-preview.el (org-latex-preview--face-around): Instead of
only examining the face immediately before the LaTeX snippet, also look
at the face immediately after before determining the appropriate face to
use.  This is relevant when the prior face is
uninformative (e.g. org-indent) but the latter face contains the
applicable face (e.g. org-list-dt).  Determination of the applicable
face is now performed in the new function
`org-latex-preview--face-around'.
(org-latex-preview--colors-at, org-latex-preview--update-overlay):
Rename `org-latex-preview--colors-at' to
`org-latex-preview--colors-around', and use
`org-latex-preview--face-around' for better face determination.
(org-latex-preview-place, org-latex-preview-clear-cache): Update to
provide an "end" value to `org-latex-preview--colors-around'.
2024-04-16 19:58:49 +08:00
TEC ec8662aa82
org-latex-preview: Better handle temp/remote files
* lisp/org-latex-preview.el (org-latex-preview-precompile,
org-latex-preview--create-tex-file): Before obtaining the (compiled)
preamble, check for the temp-ness and remote-ness of the file, and act
accordingly.  Non-temp remote files are not currently supported, and an
error will now be thrown in such cases.  The temporary file status is
now passed on to `org-latex-preview-precompile' and through to
`org-latex--precompile'.
2024-04-16 19:58:49 +08:00
TEC 96dc874f91
ox-latex: Handle preamble temp-ness explicitly
* lisp/ox-latex.el (org-latex--precompile, org-latex-make-preamble):
Instead of detecting relative file includes within
`org-latex--precompile', have an optional argument to signal a file can
be safely compile in the tempdir.  Move the check to
`org-latex-make-preamble' when calling `org-latex--precompile'.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur 52fd5cabea
org-latex-preview: Clean up tex file on failure
*
lisp/org-latex-preview.el (org-latex-preview--create-image-async):
Ensure that the latex-preview cleanup callback runs when the
preview image extraction process fails.  This is to avoid
littering the default-directory with temporary tex files.
2024-04-16 19:58:49 +08:00
TEC ce260ed2c9
org-latex-preview: Work around XeTeX misbehaviour
* lisp/org-latex-preview.el (org-latex-preview--latex-preview-filter):
Since XeLaTeX seems to misbehave with tightpage, we special-case the
tightpage processing to account for it.
2024-04-16 19:58:49 +08:00
TEC 178fd49021
org-latex-preview: Improved error messages
* lisp/org-latex-preview.el (org-latex-preview--image-extract-async,
org-latex-preview--tex-compile-async,
org-latex-preview--create-image-async): Edit the error messages for
LaTeX compilation and image generation failure to be slightly more informative.
2024-04-16 19:58:49 +08:00
TEC 3d46db577d
org-latex-preview: Disable buf precompile on error
* lisp/org-latex-preview.el (org-latex-preview--create-tex-file): When
an error occurs during LaTeX precompilation, disable it using
`setq-local' and emit an informative warning message.
2024-04-16 19:58:49 +08:00
TEC 8ccc93eae1
org-latex-preview: Use stand-in color for SVG fg
* lisp/org-latex-preview.el (org-latex-preview--svg-make-fg-currentColor,
org-latex-preview-place): Instead of guessing the SVG foreground to be
the first color seen, set a static stand-in color that is unlikely to
occur organically.
2024-04-16 19:58:49 +08:00
TEC 13888aeeb3
org-latex-preview: Guard against caching nil-files
* lisp/org-latex-preview.el (org-latex-preview--cache-image): When
caching an image with `org-latex-preview--cache-image', check that the
image path is non-nil.  Should this not be true, a warning message is
emitted suggesting this is a bug that should be reported to the Org
mailing list.
2024-04-16 19:58:49 +08:00
TEC c769032876
org-latex-preview: Get a list of all started tasks
* lisp/org-latex-preview.el (org-latex-preview--create-image-async):
Instead of just returning the main tex-compile task, return a list of
all async tasks created (i.e. the dvipng task, when used).  This will
allow for `org-async-wait-for' to be used on the list to wait until all
processing has completed.
2024-04-16 19:58:49 +08:00
TEC f592d7b3cc
org-latex-preview: Split out entry construction
* lisp/org-latex-preview.el (org-latex-preview--place-from-elements,
org-latex-preview--construct-entries): Split the entry construction code
into its own function `org-latex-preview--construct-entries'.

This change will make it easier to generate previews during export.
2024-04-16 19:58:49 +08:00
TEC 5d319e4339
org-latex-preview: Construct numbering from tree
* lisp/org-latex-preview.el (org-latex-preview--get-numbered-environments,
org-latex-preview--environment-numbering-table): Extend
`org-latex-preview--get-numbered-environments' and
`org-latex-preview--environment-numbering-table' to accept a parse tree
to operate on as an optional argument.

This will be useful when trying to integrate numbering with exports.
2024-04-16 19:58:49 +08:00
TEC e1fd05fda5
org-latex-preview: Wait for SVGs more robustly
* lisp/org-latex-preview.el (org-latex-preview--svg-make-fg-currentColor,
org-latex-preview--dvisvgm-filter): Instead of waiting 0.01s and hoping
that an SVG exists by that point, we can wait and check for the
existance of an SVG within
`org-latex-preview--svg-make-fg-currentColor', and that should reduce
the chance of edge cases where the delay is insufficient.
(org-latex-preview--svg-make-fg-currentColor): Adjust the
`buffer-substring' call to not error when the buffer is empty.
2024-04-16 19:58:49 +08:00
TEC 73df97486f
org-latex-preview: Move org-format-latex to compat
* lisp/org-latex-preview.el (org-latex-preview-create-image,
org-format-latex): It has become apparent that it is not reasonably
possible to maintain the behaviour of `org-format-latex' and
`org-create-formula-image' using the new image, so instead put the
original implementations in org-compat.
(org-preview-latex-image-directory): Move and mark as obsolete in
org-compat as it has not be used.

* lisp/org-compat.el: Introduce the original `org-format-latex' and
`org-create-formula-image' definitions.  Also move
`org-preview-latex-image-directory' here and mark as obsolete, since it
has ended up being completely unused.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur 5a20575b6f
org-latex-preview: Get geometry from preview.sty
* lisp/org-latex-preview.el (org-latex-preview--latex-preview-filter,
org-latex-preview--tex-scale-divisor,
org-latex-preview--dvipng-dpi-pt-factor): Fetch image geometry and
alignment information from the LaTeX compilation output instead of
dvisvgm or dvipng.  This calculation is simpler and should work for all
image converters (including imagemagick) and with all latex
processors (including xelatex and lualatex).

(org-latex-preview--shameful-magic-tex-scaling-factor): New
variable to match image geometry reported by preview.sty and that
computed by dvisvgm.

(org-latex-preview--dvipng-filter, org-latex-preview--dvisvgm-filter,
org-latex-preview--latex-preview-filter,
org-latex-preview--display-info): Adjust to no longer use the old sizing
information.

* lisp/org-latex-preview.el (org-latex-preview-process-alist,
org-latex-preview-create-image, org-latex-preview--display-info,
org-latex-preview--image-extract-async): Remove the :image-size-adjust
keyword, as with the new geometry detection system it is redundant.

We tried also switching dvisgm from "--bbox=preview" to "--exact-bbox",
as it should no longer be needed, but testing found "--exact-bbox" to
cause sizing issues in practice.
2024-04-16 19:58:49 +08:00
TEC e6a76e7ce5
org-latex-preview: Introduce a place-preview arg
* lisp/org-latex-preview.el (org-latex-preview--dvipng-filter,
org-latex-preview--dvisvgm-filter,
org-latex-preview--check-all-fragments-produced,
org-latex-preview--generic-callback,
org-latex-preview--create-image-async, org-latex-preview-place):
Refactor the preview pipeline to use a "place-preview" argument to
indicate that LaTeX previews should be placed after generation.

This change will pave the way for use with export, where the LaTeX
preview should be generated but not previewed.
2024-04-16 19:58:49 +08:00
TEC 3376423921
ox-latex: Precompile preamble for export
* lisp/ox-latex.el (org-latex-precompile, org-latex-make-preamble): Make
use of "mylatexformat" to precompile the LaTeX preamble, for faster
exports.
(org-latex--remove-cached-preamble): Add a function to clear a cached
preamble.

* lisp/org-latex-preview.el (org-latex-preview-precompile,
org-latex-preview--get-preamble): Relocate the precompilation
functionality to ox-latex.el, and use the new ox-latex preamble
precompilation API.
(org-latex-preview-clear-cache): Use the new preamble cache clearing
functionality in ox-latex.
2024-04-16 19:58:49 +08:00
TEC 688427138d
org-latex-preview: Use org-persist for .fmt cache
* lisp/org-latex-preview.el (org-latex-preview-precompile,
org-latex-preview--create-tex-file): Cache compiled ".fmt" format dump
files with org-persist, instead of using predictably named tempfiles.
`org-latex-preview--precompile-preamble' is introduced to seperate out
the compilation process from the org-persist interaction.  As a result
of the new changes, the ".fmt" extension is also returned now, and so it
must be stripped in `org-latex-preview--create-tex-file'.
2024-04-16 19:58:49 +08:00
TEC 4e623d4593
org-latex-preview: Rework auto toggle behaviour
* lisp/org-latex-preview.el (org-latex-preview--auto-aware-toggle):
Adjust the toggle behaviour to hopefully behave more intuitively.
2024-04-16 19:58:49 +08:00
TEC 58b2400e00
org-latex-preview: org-latex-conditional-features
* lisp/org-latex-preview.el (org-latex-preview--get-preamble):
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur 9724e205e7
org-latex-preview: Reduce verbosity of messaging
* lisp/org-latex-preview.el (org-latex-preview--cleanup-callback,
org-latex-preview--create-image-async, org-latex-preview-place,
org-latex-preview--auto-aware-toggle, org-latex-preview,
org-latex-preview-auto--regenerate-overlay): Do not emit a message
when previewing is successful.  This reduces how "busy" the echo area
is, especially when `org-latex-preview-auto-mode' is on.  When
previewing fails, display a message as before (behaviour unchanged).
2024-04-16 19:58:49 +08:00
TEC ba4e542fc1
org-latex-preview: Lazy-load, with autoloads
* lisp/org.el: No longer require org-latex-preview.

* lisp/org-latex-preview.el: Require the relevant files, and add
autoload tokens to `org-latex-preview-options',
`org-latex-preview-process-alist' (for backwards compatibility),
`org-latex-preview-auto-mode', `org-latex-preview' (the major likely
entry points), and `org-latex-preview-place` (potential external entry
point).
2024-04-16 19:58:49 +08:00
TEC 444583f0e6
org-latex-preview: Use the conditional preamble
* lisp/org-latex-preview.el (org-latex-preview--create-tex-file,
org-latex-preview--clear-preamble-cache): Instead using a minimal info
export plist, populate it with buffer-specific values so that the
conditional preamble can be appropriately generated, and cache the
result.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur b9f937bb2d
org-latex-preview: Speed up texfile creation time
* lisp/org-latex-preview.el (org-latex-preview--create-tex-file):
Speed up texfile creation time by inhibiting fsync and setting the
`coding-system-for-write' explicitly.  Times are reduced by about
40-50%.
2024-04-16 19:58:49 +08:00
TEC 0f1d2f0ca0
org-latex-preview: Fix spacing before LaTeX envs
* lisp/org-latex-preview.el (org-latex-preview--create-tex-file): Set
the \abovedisplayskip length to zero to remove the default padding.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur 716e32492b
org-latex-preview: Fix element start positions
* lisp/org-latex-preview.el (org-latex-preview--place-from-elements,
org-latex-preview-auto--maybe-track-element-here): The org-element
property `:begin' includes any Org keyword text associated with the
element, such as "#+RESULTS:" or "#+ATTR_LATEX:" and these are swallowed
up in the created preview overlays.  Fix by using the `:post-affiliated'
property over `:begin' when it is available.  Note that some
calculations, such as equation numbering, still use the `:begin'
keyword.  These calculations don't involve creating overlays and thus
this is not (expected to be) an issue.
2024-04-16 19:58:49 +08:00
TEC 36d1b5d3b2
org-macs: Support blocking on async tasks
* lisp/org-macs.el (org-async--blocking-tasks, org-async-wait-for,
org-async--cleanup-process, org-async--execute-callback): Add support
for waiting for a set of async tasks to complete via the new function
`org-async-wait-for'.
2024-04-16 19:58:49 +08:00
TEC 37c95a6026
org-latex-preview: Redesign preview creation API
* lisp/org-latex-preview.el (org-latex-preview--check-all-fragments-produced,
org-latex-preview--create, org-latex-preview-fragments,
org-latex-preview-auto--regenerate-overlay,
org-latex-preview-auto--detect-fragments-in-change): Split the
org-element processing and the preview creation components of
`org-latex-preview--create` into two new functions, `
org-latex-preview--place-from-elements' and `org-latex-preview-place'.
The latter of these can serve as a convenient public API for creating
fragments.
(org-latex-preview-place, org-latex-preview-create-image-async): To make
`org-latex-preview-place' this easier to use, we also allow the LaTeX
preamble to be provided as an optional argument, and adjust
`org-latex-preview-create-image-async' to add this as the :latex-header
to the processing-info plist.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur 62dbb79288
org-latex-preview: Better imagemagick cleanup
* lisp/org-latex-preview.el (org-latex-preview--generic-callback,
org-latex-preview-create-image-async,
org-latex-preview-process-alist): Reuse
`org-latex-preview--cleanup-callback' for imagemagick-based previews.
Additionally, check produced fragments and regenerate them if
necessary.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur 3028030013
org-latex-preview: Fix auto-gen at end of overlay
* lisp/org-latex-preview.el (org-latex-preview-auto--maybe-track-element-here):
`overlays-at' does not include overlays that end at the position it is
called on.  This caused auto-generation to not trigger immediately
when manually typing the closing delimiters of a LaTeX fragment. Fix
this by recording the position just before the end of a newly created overlay.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur 1323115972
org-latex-preview: Respect auto-generate option
* lisp/org-latex-preview.el (org-latex-preview-auto--detect-fragments-in-change):
Respect the user option `org-latex-preview-auto-generate' when
`org-latex-preview-auto-mode' is active.  (This was lost when the
auto-generation code was rewritten.)
2024-04-16 19:58:49 +08:00
TEC 5ca232e8ea
org-latex-preview: Use appropriate TeX compiler
* lisp/org-latex-preview.el (org-latex-preview--tex-compile-async,
org-latex-preview-process-alist): Introduce %l and %L placeholders for
the LaTeX compiler.
(org-latex-preview-precompile): Record the LaTeX compiler in the
preamble hash, and add %l/%L to the `org-compile-file' format spec.
(org-latex-preview-compiler-command-map): Introduce a new variable to
map each LaTeX compiler name to the command and arguments needed.

Note that due to idiosyncrasies in how the various TeX compilers behave,
pdfLaTeX will likely continue to provide a smoother experience.  In the
future, some work can be done to improve this situation.
2024-04-16 19:58:49 +08:00
TEC c19eadcf20
org-latex-preview: Allow setting persist expiry
* lisp/org-latex-preview.el (org-latex-preview--cache-image,
org-latex-preview-persist-expiry): Introduce a new variable
`org-latex-preview-persist-expiry' which is used within
`org-latex-preview--cache-image' as the expiry value when calling
`org-persist-register' on preview data.
2024-04-16 19:58:49 +08:00
TEC 3a585e28a1
org-latex-preview: Customisable preview width
* lisp/org-latex-preview.el (org-latex-preview--create-tex-file,
org-latex-preview-width ): Introduce a new variable
`org-latex-preview-width' for convenient setting of the preview width,
and use it in the preamble generation.
(org-latex-preview-header): Remove now-redundant content (thanks to the
use of preview.sty).
2024-04-16 19:58:49 +08:00
TEC 35f97f07c9
org-latex-preview: Wait for complete SVG file
* lisp/org-latex-preview.el (org-latex-preview--svg-make-fg-currentColor):
Wait until the SVG file is complete before processing it.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur 482bada781
org-latex-preview: Custom processing indicator
* lisp/org-latex-preview.el (org-latex-preview-create-image-async,
org-latex-preview--update-overlay, org-latex-preview--ensure-overlay):
These functions are modified to incorporate customizable visual
indication of preview processing.
(org-latex-preview-processing-indicator): User option to customize how
preview processing is indicated visually.  The current options are:
no indication, show a fringe marker, or apply the
face `org-latex-preview-processing-face'.  The fringe marker is
currently set as the default.
(org-latex-preview--indicate-processing): Add function to handle
applying the appropriate processing indicator.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur 7b6f8f4562
org-latex-preview: Compile previews in default-dir
* lisp/org-latex-preview.el (org-latex-preview--generic-callback,
org-latex-preview--tex-compile-async,
org-latex-preview--create-tex-file): Compile latex fragments in
`default-directory', with output placed in `temporary-file-directory'.
This is to ensure that relative paths in fragments (such as paths to
figures) are parsed correctly.  Note that relative paths in the header
are handled during precompilation instead.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur 2b6b8605f7
org-latex-preview: Rename filename parts uniformly
* lisp/org-latex-preview.el (org-latex-preview-create-image,
org-latex-preview--dvipng-filter, org-latex-preview--generic-callback,
org-latex-preview--do-cleanup,
org-latex-preview--image-extract-async): Adopt the following
convention for parts of file names used in the latex and image
processing: For file with path 'foo', foo-base refers to its base
name (no directory, no extension) and foo-no-ext refers to its full
path but without a file extension.  The third option (no directory
component but with file extension) is not used in org-latex-preview.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur ad2fe7b48e
org-latex-preview: Precompile with relative paths
* lisp/org-latex-preview.el (org-latex-preview-precompile,
org-latex-preview-process-alist): Change the precompilation parameters
so the created format file includes all files included/input in the
header with paths relative to the original Org buffer.  The
precompilation is carried out by calling latex from the
`default-directory', with the source tex file and destination format
dump file both placed in `temporary-file-directory'.  Additionally the
source tex file for precompilation is deleted if the precompilation is
successful.
2024-04-16 19:58:49 +08:00
TEC a7a464af21
org-persist: Add situational write inhibition
* lisp/org-persist.el (org-persist-write, org-persist--inhibit-write): TODO
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur 21a71b7d5e
org-latex-preview: Compile latex in default-dir
* lisp/org-latex-preview.el (org-latex-preview-precompile,
org-latex-preview--do-cleanup, org-latex-preview--image-extract-async,
org-latex-preview--tex-compile-async,
org-latex-preview--create-tex-file): Format dump-files can be referred
to by their full paths in latex file preambles by adding a space after the "%&"
token.  Using this, we can compile the tex file containing the
previews in the same directory as the org file and handle relative
file references.  The above functions now do the following:
- format dump-file: Compiled and placed in
temporary-file-directory (no change)
- preview tex file: Refers to the format dump file in
temporary-file-directory. Compiled in default-directory, with output to
default-directory.
- image processors: Input (from tex output) in and output to
temporary-file-directory.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur 9405d8f6b4
org-latex-preview: Indicate errors when using pngs
* lisp/org-latex-preview.el (org-latex-preview--update-overlay,
org-latex-preview--ensure-overlay): When using dvipng, latex errors
cannot be indicated using an error face, and if a preview is generated
it is indistinguishable from a correct one.  Fall back to a fringe
marker in this situation.
2024-04-16 19:58:49 +08:00
TEC 12f22bd572
org-latex-preview: Introduce auto-aware toggling
* lisp/org-latex-preview.el (org-latex-preview--auto-aware-toggle,
org-latex-preview): Toggling of fragments with auto-mode active needs a
bit of work to function as most people would likely expect.  To provide
this more nuanced behaviour a new function
`org-latex-preview--auto-aware-toggle' is created and replaces the prior
"toggle this element" implementation in `org-latex-preview'.
2024-04-16 19:58:49 +08:00
TEC a931da50cf
org-latex-preview: Document async image logic
* lisp/org-latex-preview.el (org-latex-preview-create-image-async):
Explain the async call structure/logic with a large code comment.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur c40c287d07
org-latex-preview: Add error reporting via tooltip
* lisp/org-latex-preview.el (org-latex-preview--update-overlay): Add a
rudimentary interface for viewing compile errors (via tooltip).
2024-04-16 19:58:49 +08:00
TEC 90cb3e9507
org-persist: Fallback to associated files in write
* lisp/org-persist.el (org-persist-write:file): If the path given in a
file container does not exist, instead of returning nothing return the
associated path if possible.  This fixes an issue where should the
original file be deleted and `org-persist-write-all' be run, then the
file container's association will be set to nil and so when
`org-persist-gc' is run the nil path will cause
org-persist-associated-files:file to produce an error.
2024-04-16 19:58:49 +08:00
TEC eb7e65bcaf
org-latex-preview: Fix face checking
* lisp/org-latex-preview.el (org-latex-preview--resolved-faces-attr,
org-latex-preview--update-overlay): Handle more of the complexity of the
forms of face specifications, and avoid inheriting information from the
`org-indent' face, which is never useful.
2024-04-16 19:58:49 +08:00
TEC 93799947c8
org-latex-preview: Wait for dvisvgm to write
* lisp/org-latex-preview.el (org-latex-preview--dvisvgm-filter): As
mentioned in the code comment, dvisvgm seems to sometimes lie about when
file content has been written, so we need to work around that by waiting
a little bit.
(org-latex-preview--cleanup-callback): Now that the svg processing is on
a timer, we must be careful not to run the callback to soon.  This isn't
desperately urgent, so we can use a relatively generous timer for this.
2024-04-16 19:58:49 +08:00
TEC 8aabc04b08
org-latex-preview: Adjust defaults
* lisp/org-latex-preview.el (org-latex-preview,
org-latex-to-html-convert-command, org-latex-preview-process-alist):
Adjust the default LaTeX preview parameters to better suit the reworked
preview system.
2024-04-16 19:58:49 +08:00
TEC 6bebfc89a6
org-latex-preview: Equation numbering
* lisp/org-latex-preview.el (org-latex-preview-numbered): Introduce a
new variable to signal whether equations numbering should be calculated
to be correct throughout the document, or not.
(org-latex-preview--numbered-environments): Create a list of known
numbered environments.
(org-latex-preview--environment-numbering-table,
org-latex-preview--get-numbered-environments): Introduce functions which
create a numbering hash table from the buffer.
(org-latex-preview--tex-styled): When an initial equation number is
provided, add LaTeX code to set the counter to apply the numbering.
(org-latex-preview--create,
org-latex-preview-auto--detect-fragments-in-change,
org-latex-preview--create): Make use of the new equation numbering
facilities.
(org-latex-preview--hash): Include first equation number (if applicable)
in the hash.
(org-latex-preview-clear-cache): Use numbering information.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur 72d3f815b0
org-latex-preview: Simplify overlay regeneration
* lisp/org-latex-preview.el (org-latex-preview--close-previous-overlay,
org-latex-preview--regenerate-overlay): Overlays carry information
about the buffer they belong to, so it is unnecessary to pass this
information explicitly when passing an overlay argument to a function.
2024-04-16 19:58:49 +08:00
TEC 1eda17bfb8
org-latex-preview: Reuse overlays more
* lisp/org-latex-preview.el (org-latex-preview--create,
org-latex-preview--maybe-track-element-here,
org-latex-preview--make-overlay): Instead of always deleting and
re-creating overlays in a region when wanting to ensure a suitable
overlay exists, we can look at the scanned overlays, check if a suitable
overlay already exists, and re-use it.  To indicate the change in
behaviour, as well as documentation updates
`org-latex-preview--make-overlay' is renamed to
`org-latex-preview--ensure-overlay'.  While we're at it, the
"front-advance" argument is now set when calling `make-overlay', to make
sure that text typed at the beginning of the fragment is not absorbed
into the overlay.
(org-latex-preview--failure-callback): It's possible the overlay
provided could be nil when something goes wrong, in which case do
nothing.
(org-latex-preview--mark-overlay-modified): Move to a separate function
for neatness.
2024-04-16 19:58:49 +08:00
TEC 922e17d98b
org-latex-preview: Better fragment insertion check
* lisp/org-latex-preview.el (org-latex-preview--handle-insert,
org-latex-preview--detect-fragments-in-change, ): Replace the old
checker `org-latex-preview--handle-insert' that was called as a
`post-insert-hook' with a new method of checking for newly created
fragments based on buffer modifications as a `after-change-functions'
hook.  This has a number of benefits, including generally improved
robustness, and the removal of a reliance on font-lock information.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur 14558a6df6
org-latex-preview: Previews stored in /tmp
* lisp/org-latex-preview.el (org-latex-preview--get-cached,
org-latex-preview--remove-cached, org-latex-preview--cache-image):
These functions are modified to search in, remove from or add to a
session cache instead of org-persist's cache.
(org-latex-preview-persist-p): User option to turn off or on
persistent caching.
(org-latex-preview--table): Hash table used to hold preview image
metadata when using a session cache instead of org-persist.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur 7b0679a262
org-latex-preview: Fix precomp when backend switch
* lisp/org-latex-preview: (org-latex-preview-process-alist,
org-latex-preview-precompile): Update programs required for
imagemagick conversion to include pdflatex.  Precompilation now
generates a new format file when switching
`org-latex-preview-default-process' to or from imagemagick.
2024-04-16 19:58:49 +08:00
TEC cfed7bbc79
org-macs: Ensure that filter run before callbacks
* lisp/org-macs.el (org-async--cleanup-process): Run
`accept-process-output` until no further output is fetched on process
exit, so we can assume that the callbacks are run after all filter
invocations.
2024-04-16 19:58:49 +08:00
TEC 2b36e6f5d3
org-macs: Add :coding kwarg to org-async-call
* lisp/org-macs.el (org-async-call): It is recommended in
(info "(elisp) Decoding Output") that the process coding system be set.
To allow for this we add a new keyword argument, :coding, and set the
default value to utf-8.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur 030ad6c9e3
org-latex-preview: Improve preview creation msg
* lisp/org-latex-preview.el: (org-latex-preview,
org-latex-preview-create-image-async): `org-latex-preview' starts an
async process, and so it can only inform the user of the start of the
process. Information about the completion (to success or failure) is
provided by the relevant process sentinels instead.
(org-latex-preview--latex-log, org-latex-preview--image-log,
org-latex-preview--precompile-log): Log buffer names for preview latex
processing.
(org-latex-preview--tex-compile-async,
org-latex-preview--image-extract-async, org-latex-preview-precompile,
org-latex-preview-create-image): Use the newly created log buffer name
variables.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur 1194febb98
org-latex-preview: Clear failed preview overlays
* lisp/org-latex-preview.el: (org-latex-preview-create-image-async): If
preview images fail to generate for some or all LaTeX fragments, the
overlays placed on the fragments during processing need to be cleared.
This is done by adding a (failure) callback function to the image
generation process.
(org-latex-preview--failure-callback): Add callback that clears overlays
for previews that fail to generate.  Other behaviours are possible here
but not implemented yet.  This includes signalling failure by changing
how the overlays are displayed, such as by adding a face or fringe
marker.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur daaa034cd0
org-latex-preview: Make clear-cache user-friendly
* lisp/org-latex-preview.el (org-latex-preview-clear-cache): Ask for
confirmation before wiping the entire LaTeX preview cache, and confirm
cache clearing at the end when clearing the buffer cache.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur b8e2f65cee
org-latex-preview: Add cache clearing function
* lisp/org-latex-preview.el (org-latex-preview-clear-cache): Clears the
latex preview cache for LaTeX fragments in a region.  This can be called
as a command by itself, but is primarily required when previewing
fragments by force-regenerating their preview images.  This might be
necessary when the output image corresponding to a fragment is malformed
in some way, for instance.
2024-04-16 19:58:49 +08:00
TEC 330d5a49ab
org-latex-preview: More robust face resolving
* lisp/org-latex-preview.el (org-latex-preview--colors-at,
org-latex-preview--resolved-faces-attr): Just using `face-attribute' on
the first face spec given when the face text property is a list is too
naive.  To do this correctly, a new function
`org-latex-preview--resolved-faces-attr' is introduced which takes care
of the annoying semantics, and used in `org-latex-preview--colors-at' to
better resolve the face attribute.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur 3e54ddd45c
org-latex-preview: Split org-latex-preview--create
* lisp/org-latex-preview.el (org-latex-preview--create): This function
does many tasks, including computing face colors and hashes for
fragments.  Split this function into three to reuse the parts for other
planned purposes, such as clearing cached images.
(org-latex-preview--colors-at): Finds appropriate foreground and
background colors at a position for the preview image of a LaTeX
fragment.  Also improve the code to handle multiple faces.
(org-latex-preview--hash): Computes the hash key for a LaTeX fragment
combined with relevant processing metadata.  This key is used to
identify the fragment when caching and placing images.
2024-04-16 19:58:49 +08:00
TEC ab107da60e
org-latex-preview: Graceful precompile failure
* lisp/org-latex-preview.el (org-latex-preview-precompile,
org-latex-preview--create-tex-file): Fall back to compiling without
using a preamble format file if the preamble could not be precompiled
without error.  In such an event, alert the user that preamble
precompilation failed, and in particular let them know if mylatexformat
could not be found.
2024-04-16 19:58:49 +08:00
TEC b9e0db41ce
org-latex-preview: Check all fragments produced
* lisp/org-latex-preview.el (org-latex-preview--check-all-fragments-produced):
Create a new callback that checks that each fragment has indeed been
produced not, and if not guesses the last produced fragment caused a
problem.  The last produced fragment is then marked as erroneous,
its cache entry updated (replaced and re-inserted), and the remaining
fragments are regenerated.
(org-latex-preview-create-image-async): Run
`org-latex-preview--check-all-fragments-produced' after successfully
extracting images.
(org-latex-preview--cache-name, org-latex-preview--cache-image,
org-latex-preview--get-cached): Use a defconst instead of hardcoding the
cache container string in `org-latex-preview--cache-image' and
`org-latex-preview--get-cached'.
(org-latex-preview--remove-cached): Easy removal of an item from the
org-persist cache, as a counterpart to `org-latex-preview--cache-image'.
2024-04-16 19:58:49 +08:00
TEC b77f8b6e12
org-latex-preview: Strip redundant color switching
* lisp/org-latex-preview.el (org-latex-preview--create,
org-latex-preview--create-tex-file): Keep track of the last fragment's
foreground/background color, and only include LaTeX color specifications
as needed.
(org-latex-preview-create-image-async): Provide the processing type so
`org-latex-preview--create-tex-file' can change the style of color
setting as appropriate.  This allows the dvipng route to use postscript
special statements instead of regular color declarations.
2024-04-16 19:58:49 +08:00
TEC a3087aba81
org-latex-preview: Do not show empty SVG fragments
* lisp/org-latex-preview.el (org-latex-preview--svg-make-fg-currentColor):
When an SVG is empty, delete it.  This will cause
`org-latex-preview--cache-image' to give nil as the path.  When the
provided path is nil, do nothing.
(org-latex-preview--update-overlay): If the image path is nil, do
attempt to place an image.  If an error is recorded and there is no
image this causes the text to be shown with the error face.
(org-latex-preview--cleanup-callback): If the image path is nil, do not
try to delete it.
2024-04-16 19:58:49 +08:00
TEC 1931fc2131
org-persist: Allow inhibiting of normalisation
* lisp/org-persist.el (org-persist-register,
org-persist--normalize-container,
org-persist--inhibit-container-normalization): Since container
normalisation is applied frequently (via
`org-persist--normalize-container'), when registering many new
containers the cost can quickly add up.  To avoid redundant overhead,
after normalising the container initially in `org-persist-register' we
bind a new variable `org-persist--inhibit-container-normalization' to t
and adjust `org-persist--normalize-container' to do nothing when this
new variable is non-nil.
2024-04-16 19:58:49 +08:00
TEC a27cc761ff
org-latex-preview: Cache formatted color strings
* lisp/org-latex-preview.el (org-latex-preview--format-color,
org-latex-preview--format-color-cache): Introduce a color cache alist, and use
it.
2024-04-16 19:58:49 +08:00
TEC 7a4925cac6
org-latex-preview: Reduce overhead in SVG editing
* lisp/org-latex-preview.el (org-latex-preview--svg-make-fg-currentColor):
By setting the coding system and avoiding triggering any file
handlers (such as the `image-file-handler'), memory usage is nearly
halved, reducing GC pressure.
2024-04-16 19:58:49 +08:00
TEC 9884886692
org-latex-preview: Tweak baseline alignment
* lisp/org-latex-preview.el (org-latex-preview--update-overlay): After
doing quite a bit of testing, tweak the ascent formula to introduce a
slight correction to visually improve the final result.
2024-04-16 19:58:49 +08:00
TEC 85b284d7f6
org-latex-preview: Introduce dvipng filter
* lisp/org-latex-preview.el (org-latex-preview--dvipng-filter,
org-latex-preview-create-image-async): Introduce a dvipng filter
function to capture information from the dvipng stdout, and place images
as they are generated.
(org-latex-preview-process-alist): Update default dvipng process to emit
depth and height information.
2024-04-16 19:58:49 +08:00
TEC a1ea4c705d
org-latex-preview: Eagerly make fragment overlays
* lisp/org-latex-preview.el (org-create-latex-export,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--create-tex-file,
org-latex-preview-create-image-async, org-latex-preview--create,
org-latex-preview--close-previous-overlay,
org-latex-preview--make-overlay, org-latex-preview--update-overlay,
org-latex-preview-processing-face): Instead of saving buffer locations
and creating an overlay after the fragment image has been generated,
create an overlay initially and then update it when the image has been
created.  This is done by splitting the image-related code of
`org-latex-preview--make-overlay' into a new function,
`org-latex-preview--update-overlay'.  This provides a number of
advantages, primarily robustness to buffer edits during image
generation.  It also allows us to create a face to indicate
in-progress (`org-latex-preview-processing-face'), which is a nice
visual indicator.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur faccbc04e9
org-latex-preview: Avoid duplicating cached images
* lisp/org-latex-preview.el (org-latex-preview--cache-image): When
caching an image, check if there is already an entry in the
`org-persist--index' with the same hash as this one.  This avoids
missing preview images for fragments with duplicates in a buffer, or
across org-persist's cache.  Without this measure, when we try to
register two fragments identified by the same hash,
`org-persist-register' returns a structure with the correct metadata
for both, but with the cached image path field missing for the second
fragment.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur 18095e6578
org-latex-preview: Prioritise near latex previews
* lisp/org-latex-preview.el (org-latex-preview-fragments): Reorder
gathered latex fragments so that they are processed starting at the
window start position.  When previewing a large file, this makes a
significant difference to the perceived speed of the processing.
Remove references to `org-preview-latex-image-directory' from this
function, as it is no longer used to cache images.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur f02c40835b
org-latex-preview: Avoid duplicate latex fragments
* lisp/org-latex-preview.el (org-latex-preview-collect-fragments): This
function was collecting duplicate org-elements when handling nested
latex environments (For instance, a matrix env inside an equation env).
Fix by comparing the current element with the previously collected one.
2024-04-16 19:58:49 +08:00
TEC a1f2f6806d
org-latex-preview: Inhibit fsync when editing SVGs
* lisp/org-latex-preview.el (org-latex-preview--svg-make-fg-currentColor):
The value of fsync appears questionable at best on modern hardware, and
makes little sense for small files where the performance overhead is
significant.  Thus, it makes sense to inhibit fsync when editing the
generated SVGs.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur b014c81a3f
org-latex-preview: Add org-preview-latex-auto-mode
* lisp/org-latex-preview.el (org-latex-preview--make-overlay): Add
overlay hooks that correct for any edits made inside the overlay, and
store a copy of the image specification in the "preview-image" slot.
Also return the created overlay, so it can be used in other functions.
(org-latex-preview--from-overlay-p, org-latex-preview--marker,
org-latex-preview--inhibit): New variables to keep track of overlay
state when using auto-mode.
(org-latex-preview--handle-pre-cursor,
org-latex-preview--handle-post-cursor, org-latex-preview--move-into):
Detect when the cursor is entering or leaving a preview overlay, and
trigger the appropriate action.
(org-latex-preview--open-this-overlay,
org-latex-preview--close-previous-overlay): When cursor has entered/left
a preview overlay, show the text/image as appropriate.
(org-latex-preview--handle-insert): Create a dummy preview overlay when
a new LaTeX fragment is created.
(org-latex-preview--insert-front-handler,
org-preview--insert-behind-handler): Extend preview overlay boundaries
when their content changes.
(org-latex-preview-auto-mode): A new minor mode for automatic
opening/closing of preview overlays, and regeneration.
(org-latex-preview-auto-generate-p): Variable which affects the
regeneration behaviour of `org-latex-preview-auto-mode'.
2024-04-16 19:58:49 +08:00
TEC 239f3bab04
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.

* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.

* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.

* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables.  Use the org-latex-preview group instead of
org-latex for preview-related variables.

* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.

* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.

* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.

org-latex-preview: clear overlays name

* lisp/org-latex-preview.el (org-clear-latex-preview):
2024-04-16 19:58:49 +08:00
TEC 0b16419f21
org-latex-preview: Basic error indication
* lisp/org-latex-preview.el (org-latex-preview--tex-compile-async,
org-latex-preview--latex-preview-filter): Search the latex compilation
stdout for fragment error messages via a process filter, and record any
found.
(org-latex-preview--display-info): Save the :error field of fragments.
(org--make-preview-overlay): When showing an SVG that has an error, use
the error face.
(org-preview-latex--tex-styled): Make any generated styling directives
take up exactly one line in all situations, so the fragment-relative
line numbers can easily be worked out in
`org-latex-preview--latex-preview-filter'.
2024-04-16 19:58:49 +08:00
TEC d528301806
org-latex-preview: Filter dvisvgm process for info
* lisp/org-latex-preview.el (org-latex-preview--display-info,
org-latex-preview--cleanup-callback, org-create-formula-image-async,
org--make-preview-overlay): Apply a filter to the dvisvgm process in
order to place overlays as images are produced, and along the way
extract size and baseline information that is used to more accurately
position the overlay image.  Because `org-latex-preview--place-images'
is now run within a filter and hence the stdout buffer, we need to
record the org buffer and switch to it before placing overlays.
(org-latex-preview--image-extract-async): Record the DPI-based scaling
factor so it can be accounted for when calculating the pt-scale fragment
height/width/depth.
(org-latex-format-options): Introduce a new parameter :zoom for
affecting the display scaling of images with associated height
resolution, but unlike :scale not the resolution/size of the images
files themselves.  This is then used in `org--make-preview-overlay'.
2024-04-16 19:58:49 +08:00
TEC cb225ab2f2
org-latex-preview: Use a fragment info plists
* lisp/org-latex-preview.el (org-latex-preview--cleanup-callback,
org-create-formula-image-async, org-create-latex-preview): Instead of
using lists of the same length for fragment information, use a single
list of fragment information plists.  This allows for more information
to be stored/used without ending up with half a dozen disparate lists
that we rely on lining up.
2024-04-16 19:58:49 +08:00
TEC 9ecfa904a2
org-latex-preview: Use org-persist for caching
* lisp/org-latex-preview.el
(org-latex-preview--cache-image, org-latex-preview--get-cached):
Implement image data save/retrieve functions using org-persist.
(org-place-latex-image, org-create-latex-export,
org-latex-preview--cleanup-callback, org-create-formula-image-async,
org-create-latex-preview, org--make-preview-overlay): Use the new model
of image data caching relying on org-persist.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur 8af5751ff2
org-latex-preview: Make image optional in overlay
* lisp/org-latex-preview.el (org-make--preview-overlay): Supplying an
image file when creating a latex preview overlay is now optional.
This change is in preparation for fully-automatic preview generation,
which requires "dummy" overlays to be placed on latex fragments that
have not yet been fully inserted or previewed.
2024-04-16 19:58:49 +08:00
Karthik Chikmagalur 69265adff0
org-latex-preview: Add imagemagick support
* lisp/org-latex-preview.el (org-preview-latex-process-alist,
org-preview-latex--create-tex-file, org-preview-precompile):
Add a new entry `:latex-precompiler' to
`org-preview-latex-process-alist', and tweak imagemagick-specific
`:image-converter' entries.  The function `org-preview-precompile' now
accepts two arguments.  Extra processing info is used to find the
right precompilation command.
2024-04-16 19:58:48 +08:00
TEC 7bc9de054a
org-macs: Rework async filter
* lisp/org-macs.el (org-async--filter, org-async-call): Expose :info to
the async filter function, and make the obvious modifications to the
process buffer content.
2024-04-16 19:58:48 +08:00
TEC fe5712eac8
org-macs: Accept nested org-async callbacks
* lisp/org-macs.el (org-async--execute-callback, org-async-call): Change
the org-async call arguments callback form to start with the symbol
org-async-task.  This allows for a list of callbacks to be
differentiated from a single callback.  `org-async-call' is also
extended to accept a a callback of this form as its sole argument.

* lisp/org-latex-preview.el (org-latex-preview--image-extract-async,
org-latex-preview--tex-compile-async, org-create-formula-image-async):
Use the new async callback form.
2024-04-16 19:58:48 +08:00
TEC 1223971314
org-latex-preview: use currentColor in SVGs
* lisp/org-latex-preview.el (org-place-latex-image,
org-create-formula-image-async, org--make-preview-overlay,
org-latex-preview--dvisvgm-callback): Edit the dvisvgm generated SVGs to
use "currentColor" instead of a hardcoded foreground color.  To then set
the color of the displayed images, set the overlay face as appropriate.
(org-create-latex-preview): Now that the foreground is generalised, when
producing the sha1 hash for an SVG image, the current foreground value
should not affect it.
2024-04-16 19:58:48 +08:00
TEC c230fef02b
org-latex-preview: Run dvipng concurrently
* lisp/org-latex-preview.el (org-create-formula-image-async): When using
dvipng with the "--follow" flag, image processing can occur
concurrently, so we may as well check for this case and start it
concurrently when this occurs.
2024-04-16 19:58:48 +08:00
TEC 82ac33c1d7
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async.  Along the way a few other minor tweaks have crept in.
2024-04-16 19:58:48 +08:00
Karthik Chikmagalur af24131046
org-latex-preview: Add preamble precompilation
* lisp/org-latex-preview.el (org-create-formula-image-async): Change
how the latex header is computed to account for precompiled headers.
(org-preview-use-precompilation): Boolean to control if
header/preamble precompilation is enabled when generating latex
previews.  If enabled, previewing will be much faster at the expense
of a slower first run.
(org-preview-precompile): This function creates precompiled dumps of
latex preambles/headers, and is intended for use with
`org-create-formula-image-async'.
2024-04-16 19:58:48 +08:00
Karthik Chikmagalur b47f2b23a8
org-latex-preview: Change default latex command
* lisp/org-latex-preview.el (org-preview-latex-process-alist,
org-create-formula-image-async): Change the default latex command to
include the input file name.  Previously the input file was introduced
via process input for compatibility with preview.sty directives.  But
it appears that it's possible to simply set \RequirePackage{preview}
in the latex header without issues.
2024-04-16 19:58:48 +08:00
TEC a8f433c31b
org-latex-preview: Get face from char before latex
* lisp/org-latex-preview.el (org-create-latex-preview): Instead of
getting the face using `face-at-point' use `get-text-property' on the
position one before the start of the LaTeX fragment.  This ensures that
the face is that of the parent element rather than the LaTeX fragment.
2024-04-16 19:58:48 +08:00
Karthik Chikmagalur 3f9cfd7849
org-latex-preview: Add async image previews
* lisp/org-latex-preview.el (org-latex-preview-fragments): Collect and
send all fragments to be processed in a single pass.

(org-create-latex-preview): Apply cached previews and send the
other fragments to be generated asynchronously.

(org-create-formula-image-async): Generate latex preview
images asynchronously and apply them to the buffer.

(org-create-preview-string): Helper function that accepts a math
fragment and returns a latex snippet suitable for use with
preview.sty. Respects color preferences.
2024-04-16 19:58:48 +08:00
TEC e827bb8a24
org-latex-preview: Collect math fragments in fun
* lisp/org-latex-preview.el (org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-collect-fragments): Introduce a
new function to collect all LaTeX math fragments in a
region (`org-latex-collect-fragments') and use it in
`org-latex-preview-fragments' and `org-latex-replace-fragments'.
2024-04-16 19:58:48 +08:00
TEC 712f97aaaf
org-latex-preview: Split org-create-latex-preview
* lisp/org-latex-preview.el (org-create-latex-preview,
org-create-latex-export): Split the export and preview functionality of
`org-create-latex-preview' into two functions: a rewritten
`org-create-latex-preview' that now /only/ deals with previews, and
`org-create-latex-export' for exports.
(org-latex-preview-fragments): Use the new `org-create-latex-preview`.
(org-latex-replace-fragments): Use the new `org-create-latex-export`.
2024-04-16 19:58:48 +08:00
TEC 9edfc99fda
org-latex-preview: Split org-format-latex into two
* lisp/org-latex-preview.el (org-format-latex, org-create-latex-preview,
org-latex-replace-fragments): The rather large `org-format-latex'
function mixed the preview and export code paths together in rather
confusing way.  This has now been split into
`org-latex-replace-fragments' for export, and
`org-latex-preview-fragments' for in-buffer previews.
(org--latex-preview-region): Replace `org-format-latex' with the more
specific `org-latex-preview-fragments'.
(org-latex-tentative-math-re): Instead of let-binding the math regexp,
use a const and explain its usage.

* lisp/ox-odt.el (org-odt--translate-latex-fragments): Replace
`org-format-latex' with the more specific `org-latex-replace-fragments`.

* lisp/ox-html.el (org-html-format-latex): Replace `org-format-latex'
with the more specific `org-latex-replace-fragments`.
2024-04-16 19:58:48 +08:00
TEC 3b9b87548b
org-latex-preview: Split org-place-formula-image
* lisp/org-latex-preview.el (org-create-latex-preview,
org-place-formula-image, org-place-latex-image,
org-place-latex-image-link): Replace `org-place-formula-image' with two
functions, one for overlays (`org-place-latex-image') and another for
links (`org-place-latex-image-link').
2024-04-16 19:58:48 +08:00
TEC ae09ab8ebe
org-latex-preview: Split org-format-latex into two
* lisp/org-latex-preview.el (org-create-latex-preview,
org-format-latex): Split `org-format-latex' into two, creating a new
function for the `cond' branch that deals with
`org-preview-latex-process-alist'.
2024-04-16 19:58:48 +08:00
TEC c591dda62a
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.

* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2024-04-16 19:58:48 +08:00
TEC 72ba4116eb
ox-latex: Call compilation commands asynchronously
* lisp/ox-latex.el (org-latex-compile): Make use of the new
`org-async-call' to call compilation commands asynchronously.

When running ox-export via the command line, the expectation is the
Emacs process will not exit until the export has completed.  This
assumption is violated with async export, so when the current Emacs
session is `noninteractive' we go back to the previous (synchronously)
method of compiling.
2024-04-16 19:58:48 +08:00
TEC 6b6aff2ef2
org-macs: Add an async command execution system
* lisp/org-macs.el (org-async--stack, org-async--wait-queue,
org-async-process-limit, org-async-timeout,
org-async-check-timeout-interval, org-async--counter, org-async-call,
org-async--sentinel, org-async--cleanup-process,
org-async--execute-callback, org-async--monitor-scheduled,
org-async--monitor): Introduce an asynchronous command execution system.
2024-04-16 19:58:48 +08:00
TEC 2917fe4e35
---PATCH SET DIVIDER--- 2024-04-16 19:58:48 +08:00
TEC b458757f0f
org-manual: Document export features
* doc/org-manual.org (+*** Export features): Initial manual entry on
export features.
2024-04-16 19:58:48 +08:00
TEC 3f0a84aced
test-ox: Add tests for export feature resolution
* testing/lisp/test-ox.el: Add a set of tests for
`org-export-resolve-feature-implementations'.
2024-04-16 19:58:48 +08:00
TEC 8bc2742d29
oc-*: Make use of conditional preamble for export
* lisp/oc-natbib.el (org-cite-natbib-use-package): Refactor to make use
of the conditional/generated preamble.

* lisp/oc-csl.el (org-cite-csl-finalizer): Refactor to make use of
the conditional/generated preamble.

* lisp/oc-biblatex.el (org-cite-biblatex-prepare-preamble): Refactor to
make use of the conditional/generated preamble.
2024-04-16 19:58:48 +08:00
TEC 64d0d115af
ox: Introduce conditional/generated preamble
* lisp/ox.el (org-export-detect-features, org-export-expand-features,
org-export-generate-features-preamble): New functions for detecting
features and generating content based on them.
(org-export-conditional-features): Customisation for feature detection.
(org-export-as): Add detected to features to info in the slot :features.
(org-export-update-features): Add a convenience function for users to
edit the feature condition/implementation lists.
(org-export--annotate-info, org-export-detect-features,
org-export-define-derived-backend, org-export-define-backend,
org-export-conditional-features): Refactor backend feature
conditions/implementations into a struct field.  This allows for parent
inheritance to be properly managed, and leads into future work making
features more widely used in the export process.
(org-export-expand-features, org-export-resolve-feature-implementations,
org-export-generate-features-preamble,
org-export-expand-feature-snippets): The main functions for working with
export features.
(org-export-process-features, org-export-update-features): Introduce
`org-export-process-features' to simplify the application of features to
INFO.
2024-04-16 19:58:48 +08:00
TEC c737d6ed77
org-compat: Add ensure-list as org-ensure-list
* lisp/org-compat.el (org-ensure-list): Add `ensure-list' from Emacs 28,
as `org-ensure-list'.
2024-04-16 19:58:48 +08:00
Ihor Radchenko 1ae978f940
Merge branch 'bugfix' 2024-04-15 14:19:50 +03:00
Ihor Radchenko 4ae5cc0182
org-self-insert-command: Prevent deleting selection for speed commands
* lisp/org.el (org--speed-command-p): New helper function checking
whether current command is a speed command.
(org-self-insert-command): Use the new helper.
* lisp/org.el: In `delete-selection' property of
`org-self-insert-command' symbol, signal that selection must not be
deleted when current command is a speed command.

Reported-by: Joe Gilder <joe@homestudiocorner.com>
Link: https://orgmode.org/list/87il0voeok.fsf@localhost
2024-04-15 14:17:17 +03:00
Ihor Radchenko b03ece433b
org-fold: Optimize fontification of link folds
* lisp/org-fold-core.el (org-fold-core--specs): Add new folding spec -
:font-lock.  When non-nil, enable re-fontification of the folds.
(org-fold-core-region): Only trigger re-fontification when the folding
spec has :font-lock property.
* lisp/org-fold.el (org-fold-initialize): Only enable re-fontification
of folded outlines, drawers, and blocks.
2024-04-15 11:53:59 +03:00
Ihor Radchenko 17072a4690
Allow clock elements without timestamp, like CLOCK: => 12:00
This syntax has been introduced in Org 4.78, but not supported later,
when Org element parser have been created.  Fix this omission to not
remove an existing (and announced!) feature.

This kind of clock is of limited use though - all the customizations
relying upon knowing _when_ clocking time was recorded, like ranges in
clock tables or limits on the displayed clocked-in time, will include
such clocks unconditionally.  So, not adding this to the manual, as it
is not very clear how to use it in actual workflow.

* lisp/org-element.el (org-element-clock-line-re): Update the regexp.
(org-element-clock-parser): Do not assume that timestamp always
follows CLOCK: line.
* testing/lisp/test-org-element.el (test-org-element/clock-parser):
(test-org-element/clock-interpreter): Add tests checking parser and
interpreter output of clocks without timestamps.

Link: https://orgmode.org/list/87frvpyzrf.fsf@localhost
2024-04-14 15:46:15 +03:00
Ihor Radchenko b42867b5a1
org-html-toc: Fix duplicate ids when there are multiples TOCs
* lisp/ox-html.el (org-html-toc): When multiple TOCs are generated
inside the exported document, make sure that they do not have
duplicate IDs.

Reported-by: Michel Damiens <michel.damiens@gmail.com>
Link: https://orgmode.org/list/87sfj6av4t.fsf@localhost
2024-04-14 13:34:13 +03:00
Ihor Radchenko 4d3b216b83
Merge branch 'bugfix' 2024-04-13 15:50:01 +03:00
Ihor Radchenko 6cb088972f
org-link-open-as-file: Do not try dired wildcard expansion when file exists
* lisp/ol.el (org-link-open-as-file): When PATH points to an existing
file and contains wildcard chars, do not try to list all the files in
`dired'.

Reported-by: Edgar Lux <edgarlux@mailfence.com>
Link: https://orgmode.org/list/1294251072.453751.1712943418634@ichabod.co-bxl
2024-04-13 15:47:18 +03:00
Ihor Radchenko 08c047a507
Merge branch 'bugfix' 2024-04-12 21:03:36 +03:00
Lei Zhe 5128460f94
org-table-header-line-mode: Fix when cursor is outside table
* lisp/org-table.el (org-table-header-set-header): Display table
header even when the point is below the table, as long as the table is
visible at the top of the window.
2024-04-12 21:01:49 +03:00
Ihor Radchenko c274128997
org-table-eval-formula: Keep empty result in duration (;TtU) mode
* lisp/org-table.el (org-table-eval-formula): When using T, t, or
U (duration) mode, do not convert empty results into duration.  This
is to keep things consistent with default mode.

Reported-by: Jeff Trull <edaskel@att.net>
Link: https://list.orgmode.org/orgmode/CAF_DUeEFpNU5UXjE80yB1MB9xj5oVLqG=XadnkqCdzWtakWdPg@mail.gmail.com/
2024-04-12 15:07:02 +03:00
Ihor Radchenko 096ecc9e24
Update version number for the 9.6.26 release 2024-04-12 09:53:47 +03:00
Morgan Smith 66e307b411
lisp/org-element.el: Add repeater-deadline support to org-element
* lisp/org-element.el (org-element-timestamp-parser,
org-element-timestamp-interpreter): Add support for repeater
deadlines.  Adds two new properties: ':repeater-deadline-value' and
':repeater-deadline-unit'.

* testing/lisp/test-org-element.el (test-org-element/timestamp-parser,
test-org-element/timestamp-interpreter): Test support for repeater
deadlines.

* etc/ORG-NEWS: Add relevant news.
2024-04-11 16:17:40 +03:00
Ihor Radchenko ead3f99901
Fix regression after 72b0e9ff0
* lisp/ox-html.el (org-html-link): Fix code branches assuming that
PATH variable strips link type.

Reported-by: Daniel Clemente <n142857@gmail.com>
Link: https://orgmode.org/list/CAJKAhPD=eMR2Tw3rsufPw_T6eEexpcHP=6PXKw3fLDtB2Z7qNg@mail.gmail.com
2024-04-10 17:02:01 +03:00
Ihor Radchenko 093b21c8c3
org-latex--caption/label-string: Add comment 2024-04-10 16:36:10 +03:00
Ihor Radchenko 78e9dd0c42
Fix when user customization makes Org dialogues pop up in new frames
* lisp/ol.el (org-insert-link):
* lisp/org-agenda.el (org-agenda-get-restriction-and-command):
* lisp/org-attach.el (org-attach):
* lisp/org-clock.el (org-clock-select-task):
* lisp/org-goto.el (org-goto-location):
* lisp/org-macs.el (org-mks):
* lisp/org-table.el (org-table-fedit-finish):
* lisp/org.el (org-offer-links-in-entry):
* lisp/ox.el (org-export-dispatch): Arrange the dialogue window to be
killed when it is displayed in a new frame.
`save-window-configuration' is not enough in such scenarios.  Use
`quit-window' instead.
* lisp/org-table.el (org-table-edit-formulas): Prohibit popping up
table editor in a new frame.  This is because the major mode for
formula editing makes assumptions about where the editor window is
located and does not work reliably in a separate frame.

Reported-by: Björn Bidar <bjorn.bidar@thaodan.de>
Link: https://orgmode.org/list/87jzlcoxuq.fsf@
2024-04-10 15:42:52 +03:00
Ihor Radchenko 129a18abf3
org-timer-set-timer: Fix when called from agenda buffer
* lisp/org-timer.el (org-timer-set-timer): Get effort minutes from
agenda entry line when in agenda buffer.

Reported-by: Bhavin Gandhi <bhavin7392@gmail.com>
Link: https://orgmode.org/list/CAOn=hbez7-4wFG2M1-MSHqAwvV0mysvLAUYP9_GK6mrSbtz3CQ@mail.gmail.com
2024-04-10 11:49:55 +03:00
Ihor Radchenko 85389da8cf
Merge branch 'bugfix' 2024-04-10 11:18:25 +03:00
Ihor Radchenko 42cdf2a90e
org-emphasis-alist: Clarify that emphasis markers cannot be changed
* lisp/org.el (org-emphasis-alist): Update the docstring, clarifying
that emphasis markers cannot be changed to arbitrary markers.

Link: https://orgmode.org/list/m3il0pac42.fsf@sina.com
2024-04-10 11:17:03 +03:00
Ihor Radchenko 9d636473be
fixup! lisp/ob-emacs-lisp.el: Throw an error when session is requested 2024-04-09 16:35:44 +03:00
Ihor Radchenko d1c6f91ced
lisp/ob-emacs-lisp.el: Throw an error when session is requested
* lisp/ob-emacs-lisp.el (org-babel-execute:emacs-lisp): When :session
is provided, signal error - sessions are not supported.
(org-babel-prep-session:emacs-lisp): Signal error when trying to
switch to session.

Reported-by: Adam Sneller <adam@earth2adam.com>
Link: https://orgmode.org/list/871qoe8k9e.fsf@localhost
2024-04-09 16:22:00 +03:00
Ihor Radchenko 029d85dcca
Merge branch 'bugfix' 2024-04-09 14:07:28 +03:00
Ihor Radchenko 67ec699769
org-dblock-write:columnview: Fix when :id file:foo.org is not open
* lisp/org-colview.el (org-dblock-write:columnview): Fix generating
columnview when :id point to a file that is not yet open in Emacs.
Just open it as needed.

Reported-by: Vlastimil Vondra <vlastimil.vondra@gmail.com>
Link: https://orgmode.org/list/CACjq+cwjyi-d_jFY9oVe_kviMfLqm4t3+DVtr_Qk_kZaZt7ncA@mail.gmail.com
2024-04-09 14:04:02 +03:00
Ihor Radchenko 6d864526b7
org-offer-links-in-entry: Kill *Select Link* buffer on C-g
* lisp/org.el (org-offer-links-in-entry): When selection is aborted
via C-g, kill *Select Link* buffer.  This is useful when the location
of the buffer is customized via `display-buffer-alist' to be not in
the same frame - then, `save-window-configuration' is not enough get
rid of the temporary window.
2024-04-07 16:03:10 +03:00
Ihor Radchenko be80f4319f
fixup! Honor `display-buffer-alist' when creating dialogues
Fix Emacs <29 compatibility.
2024-04-07 16:02:35 +03:00
Ihor Radchenko 18fbb9985f
Honor `display-buffer-alist' when creating dialogues
* lisp/org-macs.el (org-display-buffer-split): New function to display
just the new buffer and current buffer visible in the frame.  To be
used as `display-buffer' ACTION parameter.
* lisp/org-agenda.el (org-agenda-get-restriction-and-command):
(org-agenda-fit-window-to-buffer):
(org-agenda-prepare-window):
(org-agenda-switch-to):
* lisp/org-capture.el (org-capture-place-template):
* lisp/org-goto.el (org-goto-location):
* lisp/org-src.el (org-src-switch-to-buffer):
* lisp/org.el (org-tree-to-indirect-buffer):
(org-fast-todo-selection):
(org-add-log-note):
(org-fast-tag-selection):
(org-submit-bug-report):
* lisp/ox.el (org-export--dispatch-ui): Get rid of calling
`delete-other-windows' manually.  Instead, make use of
`org-display-buffer-slip' + `pop-to-buffer'/`display-buffer'.  This
way, user overrides in `display-buffer-alist' are honored.
* lisp/org-plot.el (org-plot/gnuplot):
* lisp/org.el (org-offer-links-in-entry): When `delete-other-windows'
cannot be avoided, make it ignore errors in the frames where
displaying a lone window is forbidden.
2024-04-07 13:34:13 +03:00
Sławomir Grochowski cc3a13c1fe
lisp/org-colview.el: Add defcustom `org-columns-checkbox-allowed-values'
* lisp/org-colview.el Add defcustom
`org-columns-checkbox-allowed-values'.
(org-columns-next-allowed-value): Introduce variable
`org-columns-checkbox-allowed-values'.

This would allow to use more than two states ("[ ]", "[X]") in columns
with SUMMARY-TYPE that use checkbox ("X", "X/", "X%").  For example
you can add an intermediate state ("[-]").  Or empty state ("") to
remove checkbox.

* etc/ORG-NEWS: New option ~org-columns-checkbox-states~.
2024-04-06 15:54:35 +03:00
Ihor Radchenko ea6296a4d9
Consistently label fold types when `org-fold-core-style' is 'overlays
* lisp/org-clock.el (org-clock-find-position):
* lisp/org-compat.el (org-flag-drawer):
* lisp/org-src.el (org-edit-src-exit):
* lisp/org.el (org-log-beginning): Do not force 'outline folds when
`org-fold-core-style' is 'overlays.  The erroneous logic dates back to
the time when all the folding was done via 'outline folds to save up
on the number of overlays in buffer.  This is not longer the case -
newer Emacs no longer struggle with number of overlays and we fall
back to using text properties in older Emacs.

Reported-by: Bruno Cardoso <cardoso.bc@gmail.com>
Link: https://orgmode.org/list/87sezzmd1m.fsf@gmail.com
2024-04-06 15:21:10 +03:00
Ihor Radchenko b45b393265
lisp/ox.el (org-export-table-row-is-special-p): Fix docstring
Special rows may not be ignored depending on :with-special-rows option.
2024-04-05 17:03:41 +03:00
Ihor Radchenko d72feeb09b
lisp/ox.el (org-export-table-row-number): Clarify docstring 2024-04-05 17:03:40 +03:00
Ihor Radchenko eceb2fac4c
Merge branch 'bugfix' 2024-04-05 14:33:25 +03:00
Ihor Radchenko 22306682ff
doc/org-manual.org (Plain Lists): Add example of forced list numbering
Reported-by: Sharon Kimble <boudiccas@skimble09.plus.com>
Link: https://orgmode.org/list/87pmbwkqb2.fsf@localhost
2024-04-05 14:32:15 +03:00
Ihor Radchenko b2827aed98
org-dblock-write:columnview: Write width specifications
* lisp/org-colview.el (org-dblock-write:columnview): When writing
table, write width specifications as well and apply them.
* testing/lisp/test-org-colview.el (test-org-colview/dblock): Add
test.
* etc/ORG-NEWS (=colview= dynamic block now writes column width
specifications): Document the change.

Link: https://orgmode.org/list/87r1015w30.fsf@localhost
2024-04-05 14:14:04 +03:00
Ihor Radchenko d491a74fd9
fixup! lisp/ox-odt.el (org-odt-table): Add FIXME comment 2024-04-05 13:19:58 +03:00
Ihor Radchenko 95b494a862
lisp/ox-odt.el (org-odt-table): Add FIXME comment 2024-04-05 13:17:27 +03:00
Ihor Radchenko ef43642874
lisp/ox-odt.el (org-odt-item): Fix table hack inside nested list
* lisp/ox-odt.el (org-odt-item): When exporting table inside a list,
fix scenario when the table is located inside a sub-list of another
list.

Reported-by: Christian Moe <mail@christianmoe.com>
Link: https://orgmode.org/list/87edxn9z7n.fsf@localhost
2024-04-05 13:17:23 +03:00
Ihor Radchenko 9bff93f19a
Update version number for the 9.6.25 release 2024-04-05 10:29:48 +03:00
Stefan Monnier 90045c45e2
org-element--cache-after-change: Remove redundant setq
* lisp/org-element.el (org-element--cache-after-change):
`org-element--cache-after-change' already changes
`org-element--cache-change-warning' by side effect.  No need to assign
it.
2024-04-04 20:11:04 +03:00
Ihor Radchenko e965d26edb
Merge branch 'bugfix' 2024-04-04 19:17:22 +03:00
Lee Thompson 9895ed3968
doc/org-manual.org (Header and sectioning structure): Corrected info mixup
TINYCHANGE
2024-04-04 19:14:49 +03:00
Ihor Radchenko c8d1338365
org-html-htmlize-generate-css: Do not omit faces without :inherit property
* lisp/ox-html.el (org-html-htmlize-generate-css): Fix not adding
faces without :inherit property to the generated css.  Update the
docstring, detailing that the css class names are the face names with
`org-html-htmlize-font-prefix' prepended.
2024-04-04 14:18:37 +03:00
Ihor Radchenko 0f11d21cb6
Merge branch 'bugfix' 2024-04-03 15:07:08 +03:00
Morgan Smith 3e61311c71
org-manual: Document Org Plot option "timeind"
* doc/org-manual.org (Plot options): Document "timeind".  Also fix the
formatting for a couple other entries.
2024-04-03 15:06:24 +03:00
Ihor Radchenko f6876d73b3
etc/ORG-NEWS: Fix typos
* etc/ORG-NEWS (=.avif= images are now recognized in ~org-html-inline-image-rules~):
(Blank lines after removed objects are now retained during export):
"are not" -> "are now".
2024-04-03 15:01:14 +03:00
Ihor Radchenko ce5e8ecbb8
Prioritize underline over subscript inside parenthesis
* lisp/org-element.el (org-element--object-lex): Prioritise underline
parser over subscript.  `org-element-underline-parser' is more strict
compared to `org-element-subscript-parser'.
* testing/lisp/test-org-element.el (test-org-element/underline-parser):
Add test.
* etc/ORG-NEWS (Underline syntax now takes priority over subscript
when both are applicable): Announce the breaking change.

Reported-by: Juan Manuel Macías <maciaschain@posteo.net>
Link: https://list.orgmode.org/87v8z52eom.fsf@posteo.net/T/#t
2024-04-01 15:32:14 +03:00
Max Nikulin a3bcb55365
test-org.el: Add new LaTeX to MathML tests for shell escaping
* testing/lisp/test-org.el (test-org/format-latex-as-html)
(test-org/create-math-formula): New tests for escaping of shell specials
in commands executed by `org-format-latex-as-html'
and `org-create-math-formula'.

These tests do not require applications for conversion of LaTeX
snippets and use simple shell commands instead.
2024-04-01 14:21:49 +03:00
Ihor Radchenko a698d073a1
org-latex-to-mathml/html-convert-command: Prevent shell expansion
* lisp/org.el (org-create-math-formula):
(org-format-latex-as-html): Shell-quote LaTeX fragment text when
replacing %i placeholder.  This prevents shell expansion of
$... and similar constructs inside the code.
(org-latex-to-mathml-convert-command):
(org-latex-to-html-convert-command): Update the docstring.
* etc/ORG-NEWS (~org-latex-to-mathml-convert-command~ and
~org-latex-to-html-convert-command~ shell-escape LaTeX code): Announce
the breaking change.
* doc/org-manual.org (LaTeX math snippets): Update example.

Reported-by: Max Nikulin <manikulin@gmail.com>
Link: https://orgmode.org/list/735645dd-1ddf-4579-a6dd-2700f3e83c94@gmail.com
2024-04-01 14:13:15 +03:00
Ihor Radchenko 1d86651bef
org--collect-keywords-1: Ignore #+SETUPFILE when its file handler errs
* lisp/org.el (org--collect-keywords-1): When `expand-file-name'
handler errs on #+SETUPFILE, ignore it.  An error may be thrown when
by custom file handler (for example, by TRAMP handler on GVFS path
when `tramp-gvfs-enabled' is nil; which is the default).

Reported-by: Max Nikulin <manikulin@gmail.com>
Link: https://orgmode.org/list/uue18j$j42$1@ciao.gmane.io
2024-04-01 14:04:50 +03:00
Ihor Radchenko 4c902d4771
doc/org-manual.org: Do not abbreviate links when editing the manual
Filling paragraphs depends on the hidden parts of the links, making
contributor edits dependent on the `org-link-descriptive'
customization.  Make filling consistent by not hiding link paths in
the org-manual.org specifically.
2024-04-01 12:55:52 +03:00
Ihor Radchenko 462bbb213a
Make sure that commented headings appear commented
* lisp/org.el (org-set-font-lock-defaults): Apply 'org-special-keyword
face to commented headings last, so that every markup inside look dim,
as per 'org-special-keyword face.
2024-03-31 14:50:49 +03:00
Ihor Radchenko d3878cb6fe
Consistently combine markup and the containing element faces during fontification
* lisp/org-src.el (org-fontify-inline-src-blocks-1):
* lisp/org.el (org-fontify-macros):
* lisp/org.el (org-activate-footnote-links):
(org-set-font-lock-defaults):  Prepend faces during
activation instead of overriding.  Add a comment explaining the
general rule how we combine faces.
* etc/ORG-NEWS (Org mode faces are now consistently combined, with
markup faces taking precedence over the containing element faces):
Document the breaking change.

Reported-by: StrawberryTea <look@strawberrytea.xyz>
Link: https://orgmode.org/list/875xy21e49.fsf@localhost
2024-03-31 14:41:07 +03:00
Ihor Radchenko c0e732266b
org-file-contents: Improve comment
* lisp/org.el (org-file-contents): Link to an example when
`file-remote-p' may throw an error.
2024-03-30 13:01:17 +03:00
Matthew Trzcinski e9c288dfac lisp/ob-comint.el: Fix prompt appearing in async shell results
* lisp/ob-comint.el (org-babel-comint-async-filter): Call prompt
`org-babel-comint--prompt-filter'

Reported-by: "Matthew Trzcinski" <matt@excalamus.com>
Link: https://list.orgmode.org/18d753c1e8a.cfb3e1921191837.5665565128507976741@excalamus.com/
2024-03-29 12:11:18 +01:00
Matthew Trzcinski 0102988afb testing/lisp/test-ob-shell.el: Test async prompt removal
* testing/lisp/test-ob-shell.el (test-ob-shell/session-async-results):
Create test verifying bug report that shell prompt appears in async
results.
2024-03-29 12:11:18 +01:00
Matthew Trzcinski 574e04d119 lisp/ob-comint.el: Refactor `org-babel-comint-with-output'
* lisp/ob-comint.el (org-babel-comint-with-output): Replace logic for
prompt and echo filtering with `org-babel-comint--prompt-filter' and
`org-babel-comint--echo-filter'.  Delete
`org-babel-comint-prompt-separator' variable and move related comment
to `org-babel-comint--prompt-filter'.
2024-03-29 12:11:18 +01:00
Matthew Trzcinski 3776eba2f7 lisp/ob-comint.el: Create comint echo filter
* lisp/ob-comint.el (org-babel-comint--echo-filter): Extract echo
filtering logic from `org-babel-comint-with-output' into a new
function.
2024-03-29 12:11:18 +01:00
Matthew Trzcinski c2b763dd14 testing/lisp/test-ob-comint.el: Make test for echo filter
* test-ob-comint.el:
(test-org-babel-comint/echo-filter-removes-echo): Test that echoed
input is removed from process buffer output.
2024-03-29 12:11:18 +01:00
Matthew Trzcinski 227cbb5359 lisp/ob-comint.el: Create comint prompt filter
* lisp/ob-comint.el (org-babel-comint--prompt-filter): Extract prompt
filtering logic from `org-babel-comint-with-output' into a new
function.
2024-03-29 12:11:18 +01:00
Matthew Trzcinski 820a99b171 testing/lisp/test-ob-comint.el: Make test for prompt filter
* test-ob-comint.el:  Make new file for comint tests.
(test-org-babel-comint/prompt-filter-removes-prompt): Test that the
prompt is removed from process buffer output.
2024-03-29 12:11:18 +01:00
Ross Timson 1be2f96931
lisp/ox-html.el: Add avif support for html export inline images
* lisp/ox-html.el (org-html-inline-image-rules): Add AVIF image
support for inline images on HTML export.

AVIF is well supported by browsers these days and offers similar
features and much better compression than the other image formats
commonly used for the web.

TINYCHANGE
2024-03-27 15:11:40 +03:00
Ihor Radchenko 3f20e32f8e
org-element-clock-parser: Do not be case-sensitive
* lisp/org-element.el (org-element-clock-parser): Fix demanding
upcased "CLOCK:" string.  As per general Org mode syntax principle,
keywords in Org mode are case-insensitive.
* testing/lisp/test-org-element.el (test-org-element/clock-parser):
Add test.

Reported-by: Gregor Zattler <telegraph@gmx.net>
Link: https://orgmode.org/list/875xx8mvvn.fsf@no.lan
2024-03-27 14:57:17 +03:00
Ihor Radchenko 5bdfc02c6f
Update version number for the 9.6.24 release 2024-03-26 22:45:33 +03:00
Laurence Warne 990b89d324
Create commands for `org-read-date-minibuffer-local-map'
Create commands for `org-read-date-minibuffer-local-map' for use in
place of the inline lambda commands in order to aid user discoverability.

* org.el (org-calendar-goto-today-or-insert-dot)
(org-calendar-goto-today, org-calendar-backward-month)
(org-calendar-forward-month, org-calendar-backward-year)
(org-calendar-forward-year, org-calendar-backward-week)
(org-calendar-forward-week, org-calendar-backward-day)
(org-calendar-forward-day, org-calendar-view-entries)
(org-calendar-scroll-month-left, org-calendar-scroll-month-right)
(org-calendar-scroll-three-months-left)
(org-calendar-scroll-three-months-right): New functions.
* org-keys.el (org-read-date-minibuffer-local-map): Use the new
functions for keybindings instead of inline functions.

TINYCHANGE
2024-03-26 18:04:23 +03:00
Ihor Radchenko a3bd978e15
Merge branch 'bugfix' 2024-03-26 14:44:52 +03:00
Ihor Radchenko 6223f20a64
org-map-entries: Fix when buffer is not a file buffer and SCOPE is nil
* lisp/org.el (org-map-entries): Avoid triggering check for existence
of file on FS when SCOPE is nil.

Link: https://old.reddit.com/r/emacs/comments/1bnhz24/bug_nonexistent_agenda_file_s/
2024-03-26 14:36:53 +03:00
Ihor Radchenko f0a92b1eb9
org-resource-download-policy: Emphasize that the value of t is dangerous
* lisp/org.el (org-resource-download-policy): Mark value t in the
docstring dangerous.
2024-03-26 14:10:52 +03:00
Ihor Radchenko 9450468e5c
Merge branch 'bugfix' 2024-03-25 14:32:57 +03:00
Ihor Radchenko d7f7b63a77
lisp/org.el (untrusted-content): Fix for Emacs <29.3
* lisp/org.el (untrusted-content): Define the variable ourselves when
not defined by Emacs.
2024-03-25 14:32:09 +03:00
Ihor Radchenko 16f7021c75
Merge branch 'bugfix' 2024-03-25 13:56:53 +03:00
Ihor Radchenko 656531edbe
org-html-style-default: Fix XHTML validation failing
* lisp/ox-html.el (org-html-style-default): Provide mandatory
attribute type for style tag.

Reported-by: c.buhtz@posteo.jp
2024-03-25 13:54:58 +03:00
Ihor Radchenko 6652ee7be9
Merge branch 'bugfix' 2024-03-24 19:18:11 +03:00
Ihor Radchenko 5ff4d54c6f
Update version number for the 9.6.23 release 2024-03-24 19:16:02 +03:00
Ihor Radchenko 01f10031b1
org--confirm-resource-safe: Fix prompt when prompting in non-file Org buffers
* lisp/org.el (org--confirm-resource-safe): When called from
non-file buffer, do not put stray "f" in the prompt.
2024-03-24 17:11:36 +03:00
Ihor Radchenko 4255d5dcc0
org-file-contents: Consider all remote files unsafe
* lisp/org.el (org-file-contents): When loading files, consider all
remote files (like TRAMP-fetched files) unsafe, in addition to URLs.
2024-03-24 17:11:28 +03:00
Ihor Radchenko 03635a3355
org-latex-preview: Add protection when `untrusted-content' is non-nil
* lisp/org.el (org--latex-preview-when-risky): New variable
controlling how to handle LaTeX previews in Org files from untrusted
origin.
(org-latex-preview): Consult `org--latex-preview-when-risky' before
generating previews.

This patch adds a layer of protection when LaTeX preview is requested
for an email attachment, where `untrusted-content' is set to non-nil.
2024-03-24 17:11:17 +03:00
Ihor Radchenko 003ddacf1c
org-macro--set-templates: Prevent code evaluation
* lisp/org-macro.el (org-macro--set-templates): Get rid of any
risk to evaluate code when `org-macro--set-templates' is called as a
part of major mode initialization.  This way, no code evaluation is
ever triggered when user merely opens the file or when
`mm-display-org-inline' invokes Org major mode to fontify mime part
preview in email messages.
2024-03-24 17:11:05 +03:00
Ihor Radchenko 33503445e6
org-export: Do not treat unpaired ' and " as smart quotes
* lisp/ox.el (org-export--smart-quote-status): When quotes are not
balanced, treat " literally and ' as apostrophes.
* testing/lisp/test-ox.el (test-org-export/activate-smart-quotes): Fix
test with unbalanced " and add new tests for unbalanced quotes.

Reported-by: Juan Manuel Macías <maciaschain@posteo.net>
Link: https://list.orgmode.org/orgmode/875xxfqdpt.fsf@posteo.net/
2024-03-24 12:53:11 +03:00
Ihor Radchenko 8507efa848
Merge branch 'bugfix' 2024-03-23 17:22:39 +03:00
Nick Dokos 01b540e21f
org-manual: Add footnote on how to enable described functionality
* doc/manual.org (Literal Examples): The functionality of having
`ref:' links remote-highlighted in HTML is disabled by default (since
version 9.5).  Add a footnote to explain how to enable it.

Link: https://emacs.stackexchange.com/questions/80783/org-mode-export-to-html-onmouseover-highlighting-of-referenced-code-lines
2024-03-23 17:21:12 +03:00
Aaron L. Zeng 5808155084 lisp/ob-shell.el: Initialize explicit-shell-file-name
* lisp/ob-shell.el (org-babel-shell-initialize): force blocks to
always use the specified shell language

Sessions are initialized using `shell'.  The `shell' command checks
`explicit-shell-file-name' for file to use before checking other
variables, like `shell-file-name'.  Previously, only `shell-file-name'
was set.  So, if the user had set the `explicit-shell-file-name',
session blocks would use that whereas non-session blocks would use
`shell-file-name', resulting in inconsistent behavior.  This change
sets both variables so that even if the user changes the
`explicit-shell-file-name' or `shell-file-name', blocks will only use
the shell language specified by the block.

TINYCHANGE
2024-03-23 08:57:18 +01:00
Matthew Trzcinski 34c844ab33 Revert "lisp/ob-shell.el: Initialize explicit-shell-file-name"
This reverts commit 37cd00bb12.

Commit 37cd00bb accidentally added check.sh, nohup.out, and setup.sh.
2024-03-23 08:54:51 +01:00
Ihor Radchenko 13af0fd543
fixup! Support completion boundaries when completing olp, tags, and agenda filter
Copy-paste typos.
2024-03-23 08:58:20 +03:00
Ihor Radchenko 5fa0f0c6fe
Support completion boundaries when completing olp, tags, and agenda filter
* lisp/org-agenda.el (org-agenda-filter-completion-function):
* lisp/org-refile.el (org-olpath-completing-read):
* lisp/org-tags.el (org-tags-completion-function): Add support for
orderless/flex completion styles that require boundaries operation.
2024-03-22 13:50:45 +03:00
Ihor Radchenko 50c51b9ad1
Update version number for the 9.6.22 release 2024-03-22 10:30:04 +03:00
Ihor Radchenko 01cc01fc13
doc/org-manual.org (Using the Property API): Fix typo 2024-03-21 17:12:58 +03:00
Ihor Radchenko 1b99cccbe9
Merge branch 'bugfix' 2024-03-21 15:56:36 +03:00
Ihor Radchenko 5dbf930c2d
org-agenda-clock-cancel: Unmark clocking tasks in the agenda buffer
* lisp/org-agenda.el (org-agenda-clock-cancel): When canceling clock,
remove clocking overlays from current agenda buffer.
2024-03-21 15:55:21 +03:00
Ihor Radchenko 81dcc6350f
Merge branch 'bugfix' 2024-03-21 12:13:38 +03:00
Ihor Radchenko fe83afc300
org-persist: Do not demand write access to existing directories
* lisp/org-persist.el (org-persist--check-write-access): New function
checking write access to creating a directory and all the necessary
parents.  The function is a refactoring of duplicated code that
previously checked one parent beyond what needs to be created.
(org-persist-write:index): Use the new function.  Create
`org-persist-directory' together with all its parents.  Gracefully
handle failure.
* lisp/org-persist.el: Use the new function when adding hooks to
`kill-emacs-hook'.

Reported-by: Al Oomens <aloomens@outlook.com>
Link: https://list.orgmode.org/MW4PR19MB6888F37194BA260AE5631770C4332@MW4PR19MB6888.namprd19.prod.outlook.com
2024-03-21 12:13:13 +03:00
Ihor Radchenko ad02825337
org-persist: Do not demand write access to existing directories
* lisp/org-persist.el (org-persist--check-write-access): New function
checking write access to creating a directory and all the necessary
parents.  The function is a refactoring of duplicated code that
previously checked one parent beyond what needs to be created.
(org-persist-write:index): Use the new function.  Create
`org-persist-directory' together with all its parents.  Gracefully
handle failure.
* lisp/org-persist.el: Use the new function when adding hooks to
`kill-emacs-hook'.

Reported-by: Al Oomens <aloomens@outlook.com>
Link: https://list.orgmode.org/MW4PR19MB6888F37194BA260AE5631770C4332@MW4PR19MB6888.namprd19.prod.outlook.com
2024-03-21 12:04:53 +03:00
Ihor Radchenko 224254e7f0
fixup! Fix org-fontify-quote-and-verse-blocks when org-src-fontify-natively is t 2024-03-19 23:35:30 +03:00
Ihor Radchenko df4a48bc4f
Fix org-fontify-quote-and-verse-blocks when org-src-fontify-natively is t
* lisp/org.el (org-fontify-meta-lines-and-blocks-1): Do not attempt
native fontification in quote and verse blocks when
`org-src-fontify-natively' is non-nil.  Limit native fontification to
src and example blocks only.

Reported-by: William Denton <william@williamdenton.org>
Link: https://orgmode.org/list/Ml33lIeToTUsXIzeVEIolD5SsK-HJ0yrdPgOMr2N9WrldhU72LtjnGjehgViKAjMOgN5IAwM5Tx5TfCJlRBrTfnGnxqpuhy3-lEbUNycPMY=@williamdenton.org
2024-03-19 22:22:57 +03:00
Ihor Radchenko 4f548f9482
fixup! org-create-math-formula: Do not run file-related hooks when checking output 2024-03-19 19:26:46 +03:00
Ihor Radchenko b338a90698
org-create-math-formula: Do not run file-related hooks when checking output
* lisp/org.el (org-create-math-formula): Avoid using
`find-file-noselect' to check contents of the generated mathml
formula.  `find-file-noselect' runs a number of hooks, which are not
necessary and may sometimes throw errors.

Link: https://orgmode.org/list/ut96a7$i6d$1@ciao.gmane.io
2024-03-19 17:44:00 +03:00
Damien Cassou 2381c7b882
ox-odt: Avoid warning when everything is fine
* lisp/ox-odt.el (org-odt--translate-latex-fragments): When
processing-type is already 'verbatim, no need to print any warning.
2024-03-19 17:22:52 +03:00
Ihor Radchenko 63b10621a0
org-sparse-tree: Fix matching property names containing "-"
* lisp/org.el (org-sparse-tree): Escape "-" in property names.

Reported-by: Fabian Kurmann <fabian.kurmann@uni-duesseldorf.de>
Link: https://orgmode.org/list/87v87qprwq.fsf@localhost
2024-03-19 17:02:02 +03:00
Leo Butler 46909a54e1
testing/lisp/test-ox-beamer.el: New regression tests for ox-beamer.
* testing/lisp/test-ox-beamer.el (ox-beamer/orgframe,
ox-beamer/orgframe-in-example, ox-beamer/orgframe-in-one-example): New
file.  Regression tests for ox-beamer.  Test that the
`org-beamer-frame-environment' is defined only when used.
2024-03-17 17:35:38 +03:00
Leo Butler 80615195c4
lisp/ox-beamer.el: constrain use of org-beamer-frame-environment
* lisp/ox-beamer.el (org-beamer--format-frame, org-beamer-template):
Only use `org-beamer-frame-environment' when a frame is marked as
fragile and the frame's contents include either \begin{frame} or
\end{frame}.  When `org-beamer-frame-environment' is used and not
equal to "frame", add the property :beamer-define-frame to INFO and
set it to t.  When that property is t, `org-beamer-template' emits a
definition of the alternative frame environment.

Refs: https://list.orgmode.org/orgmode/87bk7jeik8.fsf@localhost/
https://list.orgmode.org/87a5nux3zr.fsf@t14.reltub.ca/T/
2024-03-17 17:35:37 +03:00
Ihor Radchenko aa241ffd0b
Makefile: List make native in make help output 2024-03-17 17:35:37 +03:00
Aaron L. Zeng 37cd00bb12 lisp/ob-shell.el: Initialize explicit-shell-file-name
* lisp/ob-shell.el (org-babel-shell-initialize): force blocks to
always use the specified shell language

Sessions are initialized using `shell'.  The `shell' command checks
`explicit-shell-file-name' for file to use before checking other
variables, like `shell-file-name'.  Previously, only `shell-file-name'
was set.  So, if the user had set the `explicit-shell-file-name',
session blocks would use that whereas non-session blocks would use
`shell-file-name', resulting in inconsistent behavior.  This change
sets both variables so that even if the user changes the
`explicit-shell-file-name' or `shell-file-name', blocks will only use
the shell language specified by the block.

TINYCHANGE
2024-03-17 13:42:39 +01:00
Matthew Trzcinski cb80019c28 Revert "lisp/ob-shell.el: Initialize explicit-shell-file-name"
This reverts commit 0e2a9524dc.
2024-03-17 13:40:57 +01:00
Ihor Radchenko d545ad6068
lisp/ol.el: Make `org-link-get-parameter' a valid PLACE for `setf'
* lisp/ol.el (org-link-get-parameter): Define setter.  This allows
modifying link parameters with `setf' and altering them via
`add-function'.

Link: https://orgmode.org/list/a123389c-8f86-4836-a4fe-1e3f4281d33b@app.fastmail.com
2024-03-17 13:06:11 +03:00
Ihor Radchenko ae50b94e0e
Merge branch 'bugfix' 2024-03-16 16:03:00 +03:00
Jan Zavitski c5ede53210
org-export-dictionary: Improve Estonian translation
* lisp/ox.el (org-export-dictionary): Add missing and improve
existing Estonian translation entries.
2024-03-16 16:02:14 +03:00
Visuwesh 89b0773c3f
ob-calc.el: Add support for tables in Calc source block :var
A table with MxN dimensions is converted to a MxN matrix when given in
:var to a Calc source block.  A table with a single row is converted
to a vector (i.e., row vector).

* lisp/ob-calc.el (org-babel-execute-src-block:calc): Construct the
right data structure to pass tables as matrices to Calc.
* testing/lisp/test-ob-calc.el: Add tests for ob-calc, and this new
feature.
* etc/ORG-NEWS: Announce the feature.
* mk/default.mk (BTEST_OB_LANGUAGES): Enable ob-calc tests by default.
2024-03-16 15:15:40 +03:00
Ihor Radchenko a862ef6906
etc/ORG-NEWS: Fix typo 2024-03-16 14:31:14 +03:00
Ihor Radchenko caafed42e5
Merge branch 'bugfix' 2024-03-16 12:26:27 +03:00
Ihor Radchenko 712ef988c3
org-fold-core-region: Fix removing non-fold overlays
* lisp/org-fold-core.el (org-fold-core-region): Do not clear all the
overlays in region when unfolding and when SPEC-OR-ALIAS is nil.

Reported-by: Bruno Barbier <brubar.cs@gmail.com>
Link: https://orgmode.org/list/65f4a408.df0a0220.5debf.2c65@mx.google.com
2024-03-16 12:26:00 +03:00
Ihor Radchenko 8b73c8b98f
org-fold-core-region: Fix removing non-fold overlays
* lisp/org-fold-core.el (org-fold-core-region): Do not clear all the
overlays in region when unfolding and when SPEC-OR-ALIAS is nil.

Reported-by: Bruno Barbier <brubar.cs@gmail.com>
Link: https://orgmode.org/list/65f4a408.df0a0220.5debf.2c65@mx.google.com
2024-03-16 12:23:08 +03:00
Ihor Radchenko 9f4064e68e
org-capture-templates: Document %^{prompt}X %-escape syntax
* lisp/org-capture.el (org-capture-templates):
* doc/org-manual.org (Template expansion): Document the supported
custom prompt syntax.

Link: https://old.reddit.com/r/orgmode/comments/1bfgzsz/format_timestamp_after_capture_by_prompt/
2024-03-16 12:18:17 +03:00
Ihor Radchenko acf6fa6209
org-fold-core--property-symbol-get-create: Improve performance
* lisp/org-fold-core.el (org-fold-core--property-symbol-get-create):
Cache values of global property symbols.
2024-03-16 12:17:49 +03:00
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
Matthew Trzcinski 0e2a9524dc lisp/ob-shell.el: Initialize explicit-shell-file-name
* lisp/ob-shell.el (org-babel-shell-initialize): force blocks to
always use the specified shell language

Sessions are initialized using `shell'.  The `shell' command checks
`explicit-shell-file-name' for file to use before checking other
variables, like `shell-file-name'.  Previously, only `shell-file-name'
was set.  So, if the user had set the `explicit-shell-file-name',
session blocks would use that whereas non-session blocks would use
`shell-file-name', resulting in inconsistent behavior.  This change
sets both variables so that even if the user changes the
`explicit-shell-file-name' or `shell-file-name', blocks will only use
the shell language specified by the block.

Submitted by: "Aaron L. Zeng" me@bcc32.com

TINYCHANGE
2024-03-15 22:27:04 +01:00
Ihor Radchenko fb61e83f2a
org-insert-property-drawer: Fix incorrect fold type
* lisp/org.el (org-insert-property-drawer): When folding style is
overlays, do not use outline folds to fold the property drawer.

Reported-by: Bruno Cardoso <cardoso.bc@gmail.com>
Link: https://orgmode.org/list/87wmq5btzn.fsf@gmail.com
2024-03-15 00:20:02 +03:00
Ihor Radchenko 7653e58f6d
org-table-next-row: Improve docstring
* lisp/org-table.el (org-table-next-row): Explain what happens when
the next row is outside table or when it is an hline.

Link: https://orgmode.org/list/B35D543F-6A6C-4F7D-913F-E8CBB6B9BC1B@gmail.com
2024-03-13 17:14:04 +03:00
Stefan Monnier 2773904cfb
org-src-font-lock-fontify-block: Clarify offset computation
* lisp/org-src.el (org-src-font-lock-fontify-block): Improve the translation
of local positions into org-buffer positions, and get rid of
assumption about the value of `point-min' while we're at it.
2024-03-13 16:31:56 +03:00
Ihor Radchenko cd0568ab1b
org-submit-bug-report: Submit Org-related warnings
* lisp/org.el (org--warnings): New variable storing Org mode warnings
to be submitted together with bug reports.
(org-submit-bug-report): Add `org--warnings' to bug report template.
* lisp/org-element.el (org-element--cache-warn): Store cache warnings
for submission.
2024-03-13 16:07:06 +03:00
Max Nikulin ca29290948
testing: Add missing lexical-binding modeline
* testing/lisp/test-ox-html.el:
* testing/lisp/test-ox-texinfo.el: Add modeline with `lexical-binding'.
2024-03-13 15:35:32 +03:00
Max Nikulin ff5fc2563f
testing: Fix misleading file headers
* testing/lisp/test-org-tempo.el:
* testing/lisp/test-property-inheritance.el: Do not refer to
non-existing file names in the file header.
2024-03-13 15:35:31 +03:00
Max Nikulin 37a98d7de4
testing: Fix file names in file headers
* testing/lisp/test-ob-julia.el:
* testing/lisp/test-ol-bbdb.el:
* testing/lisp/test-org-fold.el:
* testing/lisp/test-ox-ascii.el: Fix names in file headers.

Inconsistency was likely caused by copy-paste.
2024-03-13 15:35:30 +03:00
Ihor Radchenko 505db97a8c
org-update-parent-todo-statistics: Fix infinite loop after 4254a54f8
* lisp/org.el (org-update-parent-todo-statistics): Make sure that we
move to the end of updated cookie at the end of search loop, even when
the cookie has not been updated.

Reported-by: No Wayman <iarchivedmywholelife@gmail.com>
Link: https://orgmode.org/list/87le6pucnv.fsf@gmail.com
2024-03-13 13:26:00 +03:00
Gerard Vermeulen e2caccfdf6
lisp/oc-basic.el: add missing function declarations 2024-03-12 16:17:09 +03:00
Ihor Radchenko f08174a459
org-export: Display a warning when the value of :exports header arg is invalid
* lisp/ob-exp.el (org-babel-exp-do-export): Display warning when
:exports value is not known.  Document nil return value.
(org-babel-exp-process-buffer): Do not remove code block when
`org-babel-exp-do-export' returns nil.

Reported-by: Max Nikulin <manikulin@gmail.com>
Link: https://orgmode.org/list/usc9jn$g2r$1@ciao.gmane.io
2024-03-12 16:07:13 +03:00
Ihor Radchenko c9b655f273
org-activate-folds: Skip over folded newlines faster
* lisp/org.el (org-activate-folds): When searching next unfolded
newline skip over folded newlines faster, using org-fold-core API.
2024-03-12 15:40:37 +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 72b0e9ff04
org-export: Do not strip link type by default during export
* lisp/ox-html.el (org-html-link):
* lisp/ox-latex.el (org-latex-link):
* lisp/ox-man.el (org-man-link):
* lisp/ox-md.el (org-md-link):
* lisp/ox-odt.el (org-odt-link--inline-image):
* lisp/ox-texinfo.el (org-texinfo-link): Preserve link type during
export for all the links, not just for a hard-coded subset.
* etc/ORG-NEWS (Built-in HTML, LaTeX, Man, Markdown, ODT, and Texinfo
exporters preserve the link protocol during export): Document the
breaking change.

Link: https://list.orgmode.org/orgmode/878r9nofpw.fsf@localhost/
2024-03-12 13:57:47 +03:00
Stefan Monnier b0c3c90574
ox-texinfo:: Always provide a @direntry
Until now @dircategory/@direntry entries were added only if
both TEXINFO_DIR_CATEGORY and TEXINFO_DIR_TITLE were set.
And the setting of TEXINFO_DIR_TITLE had to be careful to
provide exactly the right syntax.

This patch changes various things in this regard:
- Always generate a @dircategory/@direntry.
- Default TEXINFO_DIR_CATEGORY to "Misc".
- Use the document title by default if TEXINFO_DIR_DESC is missing.
- Rename TEXINFO_DIR_TITLE to TEXINFO_DIR_NAME.
- Use the filename by default when TEXINFO_DIR_NAME is missing.
- Try and make it harder to provide a direntry that does not
  have the right format or refers to a different filename than
  the one we're outputting to.

* lisp/ox-texinfo.el (texinfo): Add entry for TEXINFO_DIR_NAME.
(org-texinfo-template): Use sane defaults for `@direntry` and `@dircategory`.

* doc/org-manual.org (Texinfo specific export settings): Adjust accordingly.
(Info directory file, A Texinfo example, Export Setup): Update examples
to use the new syntax.
* etc/ORG-NEWS (Version 9.7 / New features): Add entry.
2024-03-08 13:45:26 +03:00
Stefan Monnier 4fd8691941
lisp/ox-texinfo.el: Remove redundant `:group`s 2024-03-08 13:45:25 +03:00
Ihor Radchenko 28dc5dd1ac
Update version number for the 9.6.21 release 2024-03-08 11:34:42 +03:00
Bastien Guerry 57ec015ab3 Merge branch 'bugfix' 2024-03-08 07:14:20 +01:00
Bastien Guerry 4ee6e88b2f doc/org-manual.org: Small fix
* doc/org-manual.org (Include Files): Add missing quotes.
2024-03-08 07:14:07 +01:00
Bastien Guerry 044dc80a77 doc/org-manual.org: Small fix
* doc/org-manual.org (Include Files): Add missing quotes.
2024-03-08 07:12:32 +01:00
Ihor Radchenko cab81f2428
org-babel: Improve parsing of colnames in tables with horizontal lines
* lisp/ob-core.el (org-babel-get-colnames): When table starts with
horizontal lines, consider column names to be the first non-hline row.
(org-babel-disassemble-tables): When detecting automatic column names,
do not assign colnames when the first row is an hline.
* doc/org-manual.org (Passing arguments): Update the manual, detailing
that leading hline rows are skipped for :colnames yes.

Link: https://orgmode.org/list/87wmqexjoj.fsf@localhost
2024-03-07 22:02:21 +03:00
Ihor Radchenko 0a6c881174
org-babel: Fix smart `replace-regexp-in-string' behavior during variable assignment
* lisp/ob-latex.el (org-babel-expand-body:latex):
* lisp/ob-lilypond.el (org-babel-expand-body:lilypond):
* lisp/ob-org.el (org-babel-expand-body:org):
* lisp/ob-sql.el (org-babel-sql-expand-vars): Pass FIXEDCASE and
LITERAL arguments to `replace-regexp-in-string'.  This avoids changing
case and special handling of \N constructs in the replacement string.
2024-03-07 15:49:07 +03:00
Ihor Radchenko 0608ae1062
Merge branch 'bugfix' 2024-03-07 15:43:53 +03:00
Ihor Radchenko 01a0f15b6b
org-babel-expand-body:gnuplot: Fix altering variable data case
* lisp/ob-gnuplot.el (org-babel-expand-body:gnuplot): Pass FIXEDCASE
and LITERAL arguments to `replace-regexp-in-string'.  This prevents it
from "smartly" altering the replacement text case when the variable
name is upcased like $C or $FOO; and from interpreting \N constructs.

Reported-by: Paul Stansell <paulstansell@gmail.com>
Link: https://orgmode.org/list/CAMJKaZyH0ZwaitHxCTdd2ZGMKOZtVCvwVf_OEuRe9crPbqG9jA@mail.gmail.com
2024-03-07 15:43:00 +03:00
Ihor Radchenko 8eb78048f0
org-mobile-create-index-file: Fix typo
* lisp/org-mobile.el (org-mobile-create-index-file): Fix argument
order in the call to `expand-file-name'.

Reported-by: Fabian Brosda <f.brosda@gmx.de>
Link: https://orgmode.org/list/87a5ngxzcr.fsf@gmx.de
2024-03-06 13:36:56 +03:00
Ihor Radchenko 1151c614b3
org-fold-core-region: Fix another edge case with newline fontification
* lisp/org-fold-core.el (org-fold-core-region): Do not just update
folds before/after.  Refresh newlines created by splicing a fold by
unfolding in the middle of an existing fold.  Then, fold list between
from/to will not cover the folds right before from and right after to.

Reported-by: StrawberryTea <look@strawberrytea.xyz>
Link: https://orgmode.org/list/878r2xfk60.fsf@strawberrytea.xyz
2024-03-05 11:02:21 +03:00
Gerard Vermeulen c2ea553be8
org-babel-demarcate-block: split using element API
* lisp/ob-babel.el (org-babel-demarcate-block): Modify a copy
of (org-element-at-point) to replace the old source block with 2 or 3
new modified copies by means of `org-element-interpret-data'.  The 1st
source block contains the text from the body of the old block before
point or region, the 2nd block contains the body text after point or
body text within region, and in case of region, the 3rd block contains
the text after region.  The caption and the name are deleted from the
1 or 2 blocks below the upper source block.  Indent all blocks
immediately after insertion.  Use :post-blank to control white lines
between inserted blocks.  Leave point at the last inserted block.
Trying to split when point or region is not within the body of the old
source block raises an user-error.
* lisp/ob-babel (org-get-src-block-info): add the "within blank lines
after a source block" condition to the doc-string to match it with the
doc-string of and a comment in `org-babel-demarcate-block'.
* testing/lisp/test-ob.el (test-ob/demarcate-block-split-duplication)
(test-ob/demarcate-block-split-prefix-point)
(test-ob/demarcate-block-split-prefix-region)
(test-ob/demarcate-block-split-user-errors)
(test-ob/demarcate-block-wrap-point)
(test-ob/demarcate-block-wrap-region): New tests to check test cases
that broke earlier versions of this patch.

Link: https://list.orgmode.org/7e41f9b6e9026a404e256f33371e974c@posteo.net/
2024-03-04 14:48:59 +03:00
Ihor Radchenko 5f5db3d353
org-babel-do-in-edit-buffer: Fix when opening src edit buffer fails
* lisp/ob-core.el (org-babel-do-in-edit-buffer): When opening src edit
buffer fails, do not leave point inside that buffer.

Reported-by: gerard.vermeulen@posteo.net
Link: https://orgmode.org/list/5bf6832d2485f0aa6be2e5ea2eba37d2@posteo.net
2024-03-04 13:11:21 +03:00
Anand Deopurkar 8ac99c33f0
org-agenda.el: Fix org-agenda-write to avoid duplicates
* lisp/org-agenda.el (org-agenda-write): Make sure headlines are not
duplicated when writing to an `org' file, even if they are repeated in
the agenda view.

For example, a headline may appear multiple times in the agenda
view (for example, if it has multiple time stamps).  But
org-agenda-write should write it only once to the output `org' file.

TINYCHANGE
2024-03-03 16:44:54 +03:00
Ihor Radchenko 2da622cad7
org-fold-core-region: Fix re-fontification when unfolding everything
* lisp/org-fold-core.el (org-fold-core-region): Make sure that we
refresh fontification of newlines after folds when unfolding is
requested across multiple non-intersecting folds.

Reported-by: StrawberryTea <look@strawberrytea.xyz>
Link: https://orgmode.org/list/87y1b0m0ij.fsf@strawberrytea.xyz
2024-03-03 16:42:03 +03:00
Anand Deopurkar 902dacb9ca
org-archive.el: Fix org-add-archive-files to correctly de-duplicate
* org-archive.el (org-add-archive-files): Use `seq-uniq' with TESTFN
`file-equal-p' to de-duplicate the list of gathered files.

Previously, `org-uniquify' was used.  This de-duplicates the
file-names, but not necessarily the files.  The problem occurs if the
list of file-names includes distinct file-names that reference the
same file (symbolic links, for example).

TINYCHANGE
2024-03-02 15:26:16 +03:00
Ihor Radchenko ca061cfacb
org-beamer-template: Fix when `org-beamer-frame-environement' is "frame"
* lisp/ox-beamer.el (org-beamer-template): Do not try to define
`org-beamer-frame-environement' when it is set to "frame" - the same
as the existing frame environment.

Reported-by: Pedro Andres Aranda Gutierrez <paaguti@gmail.com>
Link: https://orgmode.org/list/87a5nh1r9h.fsf@t14.reltub.ca
2024-03-02 15:19:31 +03:00
Leo Butler 60ddec4827
lisp/ox-beamer.el: fix orgframe environment definition
* (org-beamer-template):  pass the frame overlay specification to the
frame in the definition of the orgframe environment.

Bug reported by Pedro Andres Aranda Gutierrez.

Ref: https://list.orgmode.org/orgmode/CF58E7A4-233D-4F9D-BBE2-FC1A67E315BD@gmail.com/T/
2024-03-02 15:16:40 +03:00
Ihor Radchenko b127d7257e
lisp/ol.el (org--re-list-looking-at): Fix Emacs <29 compatibility 2024-02-29 16:00:06 +03:00
Ihor Radchenko c88da815ed
Revert "lisp/ob-sql.el: Prevent from getting stuck with an error"
This reverts commit 45ca597f96.

Another commit handles the problem more universally: a3ebd8c66.
2024-02-29 15:05:19 +03:00
Ihor Radchenko a3ebd8c669
org-babel-do-in-edit-buffer: When editing fails, do not throw an error
* lisp/ob-core.el (org-babel-do-in-edit-buffer): Avoid throwing an
error when something is not right with the code block.  We already
ignore errors when major mode fails to load and we generally don't
want this macro to fail as it is used during indentation.

Link: https://list.orgmode.org/orgmode/87wmqo3it5.fsf@localhost/
2024-02-29 15:01:00 +03:00
Ihor Radchenko ac49228040
Merge branch 'bugfix' 2024-02-29 14:49:10 +03:00
Ihor Radchenko 8648576573
org-up-heading-safe: Return true level, ignoring org-odd-levels-only
* lisp/org.el (org-up-heading-safe): Fix return value, making sure
that the returned level is not reduced.

Reported-by: E.L.K. <some.any.key@gmail.com>
Link: https://orgmode.org/list/CAF+cOoPuh8rzVRoV9-pGSP3SVRm-M8ZQrM=xGB+o4TqJat_O-A@mail.gmail.com
2024-02-29 14:47:31 +03:00
Ihor Radchenko 6ef0154576
org-up-heading-safe: Return true level, ignoring org-odd-levels-only
* lisp/org.el (org-up-heading-safe): Fix return value, making sure
that the returned level is not reduced.  This is what other code
expects and what used to be the case before refactoring, in previous
version of the function.
* testing/lisp/test-org.el (test-org/up-heading-safe): Add test.

Reported-by: E.L.K. <some.any.key@gmail.com>
Link: https://orgmode.org/list/CAF+cOoPuh8rzVRoV9-pGSP3SVRm-M8ZQrM=xGB+o4TqJat_O-A@mail.gmail.com
2024-02-29 14:36:26 +03:00
Ihor Radchenko 731d16f9e9
org-table-to-lisp: Preserve text properties
* lisp/org-table.el (org-table-to-lisp): When parsing table, keep text
properties.  These text properties are required to calculate table
alignment with invisible text.
* testing/lisp/test-org-table.el (test-org-table/align): Add new test.

Reported-by: Kostadin Ninev <dinkonin@gmail.com>
Link: https://orgmode.org/list/1709041784097.2987395179.620232376@gmail.com
2024-02-29 14:23:37 +03:00
Ihor Radchenko c841be9656
lisp/ol.el (org-target-link-regexp-limit): Bump value 2024-02-29 14:07:15 +03:00
Ihor Radchenko 341a01a07d
Work around regexp size limitation for large number of link targets
* lisp/ol.el (org-target-link-regexp-limit): New constant defining
maximum regexp limit where `org-target-link-regexp' is still safe to
use without triggering "Regexp too long" error.
(org-target-link-regexps): New variable holding a series of shorter
regexps to be used instead of too long single
`org-target-link-regexp'.
(org--re-list-search-forward): New function like `re-search-forward',
but accepting a list of regexps.
(org--re-list-looking-at): New function like `looking-at', but
accepting a list of regexps.
(org-update-radio-target-regexp): When `org-target-link-regexp' is too
long, set `org-target-link-regexps', partitioning the link target list
into smaller regexps.
* lisp/org-element.el (org-element-link-parser):
(org-element--object-lex):
* lisp/org.el (org-activate-target-links): Use
`org--re-list-search-forward' and `org--re-list-looking-at' when
`org-target-link-regexps' is non-nil.
* testing/lisp/test-org-element.el (test-org-element/link-parser): Add
tests.

Reported-by: Rudolf Adamkovič <salutis@me.com>
Link: https://list.orgmode.org/orgmode/m2lenax5m6.fsf@me.com/
2024-02-29 13:54:41 +03:00
Olivier Lischer dd4d05a159
ob-tangle: Add flag to optionally remove files before writing
* lisp/ob-tangle.el: Add new custom option
`org-babel-tangle-remove-file-before-write'.
(org-babel-tangle): Remove file before writing according to the value
of `org-babel-tangle-remove-file-before-write'.

The variable `org-babel-tangle-remove-file-before-write' adds support
for the current and old behaviour of `org-babel-tangle'.

Link: https://list.orgmode.org/orgmode/877cjzhjtg.fsf@liolin.ch/
Co-authored-by: Ihor Radchenko <yantar92@posteo.net>

TINYCHANGE
2024-02-29 13:41:34 +03:00
Ihor Radchenko 9029470eb9
fixup! oc-basic.el: Drop {...} when rendering Bibtex entries 2024-02-29 13:02:48 +03:00
Ihor Radchenko ac1ed2bf85
lisp/org-colview.el: Fix computing summary with low-level first child
* lisp/org-colview.el (org-columns--compute-spec): Do not assume that
all the children of an entry have the same LAST-LEVEL.  Handle
situation when the first child has lower level:

* Heading
****** Child 1
** Child 2
** Child 3

Reported-by: Uwe Brauer <oub@mat.ucm.es>
Link: https://orgmode.org/list/87wn8yj2i5.fsf@localhost
2024-02-29 12:57:24 +03:00
Ihor Radchenko d2df9624ce
oc-basic.el: Drop {...} when rendering Bibtex entries
* lisp/oc-basic.el (org-cite-basic--print-bibtex-string): New function
approximately parsing Bibtex strings and dropping {...}.
(org-cite-basic--print-entry): Use the new function.
* testing/examples/Basic.bib:
*
testing/lisp/test-oc-basic.el (test-org-cite-basic/export-bibliography):
Add test.

Reported-by: Dominik Schrempf <dominik.schrempf@gmail.com>
Link: https://orgmode.org/list/CAF+0kSg8O3RQBG1wXoHjMEHwnGFz0gaDkTTSGv+ZaOt4d4myCA@mail.gmail.com
2024-02-29 12:21:08 +03:00
Ihor Radchenko 286a8fb798
org-element-insert-before: Fix return value when setting plain-text
* lisp/org-element-ast.el (org-element-set-element): When setting
plain-text node, return the new node instead of immutable old one.
* testing/lisp/test-org-element.el (test-org-element/set): Add test.
2024-02-29 11:43:52 +03:00
Ihor Radchenko 755fef38f5
Merge branch 'bugfix' 2024-02-28 10:54:50 +03:00
Ihor Radchenko fe9bc9efd1
Update version number for the 9.6.20 release 2024-02-28 10:53:28 +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
Tim Ruffing 356072c1d6
org-agenda: Make sure skipping warning/delay days never increases their number
* lisp/org-agenda.el (org-agenda-get-deadlines, org-agenda-get-scheduled):
Use minimum of warning/delay days specified in timestamp cookie and the
limit specified by `org-agenda-skip-deadline-prewarning-if-scheduled' or
`org-agenda-skip-scheduled-delay-if-deadline`, respectively.
* testing/lisp/test-org-agenda.el (test-org-agenda/skip-deadline-prewarning-if-scheduled):
New test.

Link: https://orgmode.org/list/59e48dfe744dc9409ff47183255bc64e92d26d88.camel@timruffing.de

TINYCHANGE
2024-02-27 15:40:18 +03:00
Ihor Radchenko 8651c83991
Address Emacs 27 warnings
* lisp/org-entities.el (seq): Require seq.el - it is not preloaded in
Emacs <28.
* lisp/org.el (org--image-yank-media-handler): Suppress warning and
throw an error about `file-name-with-extension'.  This function is not
supposed to be called in older Emacs.
2024-02-27 13:34:07 +03:00
Ihor Radchenko 25a51bad2c
Address Emacs 28 warnings
* lisp/oc-basic.el (org-cite-basic--shorten-names): Provide third
argument for `mapconcat'.  It is mandatory in Emacs <29.
* lisp/org.el (org--image-yank-media-handler): Suppress warning and
throw and error in Emacs <29.
(org--dnd-rmc): Do not try to call `use-dialog-box-p' in Emacs <29.
2024-02-27 13:29:00 +03:00
Ihor Radchenko 87c9f9b5db
org-export: Fix exporting visible when org-fold-core-style is 'text-properties
* lisp/org-fold-core.el (org-fold-core--update-buffer-folds): New
function updating buffer folds in copied text for current buffer.
(org-fold-core-decouple-indirect-buffer-folds): Use the new function.
* lisp/org-element.el (org-element--generate-copy-script): Synchronize
folds.
2024-02-27 13:21:36 +03:00
Ihor Radchenko fef873b1cf
org-agenda-get-restriction-and-command: Do not leave window around
* lisp/org-agenda.el (org-agenda-get-restriction-and-command): When
agenda selection is aborted or completed by any means, quit agenda
command selection window.

Reported-by: Björn Bidar <bjorn.bidar@thaodan.de>
Link: https://list.orgmode.org/orgmode/87il2ai916.fsf@/
2024-02-27 12:18:34 +03:00
Ihor Radchenko 9f6894c106
org-activate-folds: Do not fontify newline after abbreviated links
* lisp/org.el (org-activate-folds): When a fold is created by link
abbreviation, and a link ends at eol, do not force the newline after
the ]] to have the same face as the link.

Reported-by: Rohit Patnaik <quanticle@quanticle.net>
Link: https://orgmode.org/list/6d440976-6747-4ce6-8913-b63931dd017f@app.fastmail.com
2024-02-26 15:52:25 +03:00
Ihor Radchenko 8bac4d386a
org-fold-core-get-folding-spec: Fix edge case
* lisp/org-fold-core.el (org-fold-core-get-folding-spec): When SPEC is
nil, do not rely upon 'invisible property value to determine the fold.
Examine unique property set by `org-fold-region' instead.
2024-02-26 15:51:31 +03:00
Ihor Radchenko 655e97208c
org-element--generate-copy-script: Copy all the overlay properties
* lisp/org-element.el (org-element--generate-copy-script): In buffer
copy, copy over all the overlay properties, not just 'invisible.  This
is needed to copy folding overlays correctly - they use more than just
'invisible property.
2024-02-26 15:51:04 +03:00
Thierry Banel 407a55c1c0
org-table.el: Enhanced table parsing
* lisp/org-table.el (org-table-to-lisp): Refactored.
* etc/ORG-NEWS: Document changes.

`org-table-to-lisp' is significantly faster.
It no longer uses regexps, nor clobbers the global regexp state.
2024-02-25 14:30:38 +03:00
Ihor Radchenko af9100382c
Never pass error message verbatim as the first argument for `message'/`error'
* lisp/org-capture.el (org-capture-store-last-position):
* lisp/org-crypt.el (org-encrypt-entry):
* lisp/org.el (org-open-file): Avoid (error string) code pattern.
Instead use (error "%s" string).  (error string) is erroneous when
STRING contains %-specs.

Reported-by: Corwin Kerr <corwin@corwinkerr.com>
Link: https://orgmode.org/list/beceaf05-ae15-487b-864b-2e23a33a3884@app.fastmail.com
2024-02-25 13:15:04 +03:00
Ihor Radchenko 9daad41ccf
Re-introduce undocumented fontification of example blocks
* lisp/org.el (org-fontify-meta-lines-and-blocks-1): Do not assert
that `org-src-fontify-natively' only applies to code blocks.  Allow
other blocks with language specifier to be fontified, but keep this
behavior undocumented.

Reported-by: Rudi C <rudiwillalwaysloveyou@gmail.com>
Link: https://orgmode.org/list/CAE9z9A3ko27NeN0oYFs_aBWV_cUbNm5YQTLrRux16dHsixsMBA@mail.gmail.com
2024-02-25 13:00:12 +03:00
Martin Kampas 37e468cf16
org-bibtex-yank: Allow to populate existing item
Align with `org-bibtex-create'.

* lisp/ol-bibtex.el (org-bibtex-write):
* lisp/ol-bibtex.el (org-bibtex-yank): New optional argument
UPDATE-HEADING to update heading at point instead of creating a new
heading.
(org-bibtex-create): Rename NONEW argument to UPDATE-HEADING.
* etc/ORG-NEWS (~org-bibtex-yank~ accepts a prefix argument):
(New optional argument =UPDATE-HEADING= for ~org-bibtex-yank~):
Announce the change.

Link: https://list.orgmode.org/orgmode/4868155.GXAFRqVoOG@gt1/
2024-02-25 11:50:38 +03:00
Ihor Radchenko 5d186b499d
org-fold: Refactor fontifying newlines after folds
* lisp/org.el (org-activate-folds): New fontification function to
arrange faces at newlines after folds to be the same as face before
the fold.
(org-set-font-lock-defaults): Add the new fontification function.
* lisp/org-fold-core.el (org-fold-core-region): Refresh fontification
of newlines after folds when folding/unfolding.

Reported-by: StrawberryTea <look@strawberrytea.xyz>
Link: https://orgmode.org/list/87plwoqrfv.fsf@strawberrytea.xyz
2024-02-25 11:42:44 +03:00
Rick Lupton 95554543b9
org-id.el: Add search strings, inherit parent IDs
* lisp/ol.el (org-store-link): Refactor org-id links to use standard
`org-store-link-functions'.
(org-link-search): Create new headings at appropriate level.
(org-link-precise-link-target): New function extracting logic to
identify a precise link target, e.g. a heading, named object, or text
search.
(org-link-try-link-store-functions): Extract logic to call external
link store functions. Pass them a new `interactive?' argument.
* lisp/ol-bbdb.el (org-bbdb-store-link):
* lisp/ol-bibtex.el (org-bibtex-store-link):
* lisp/ol-docview.el (org-docview-store-link):
* lisp/ol-eshell.el (org-eshell-store-link):
* lisp/ol-eww.el (org-eww-store-link):
* lisp/ol-gnus.el (org-gnus-store-link):
* lisp/ol-info.el (org-info-store-link):
* lisp/ol-irc.el (org-irc-store-link):
* lisp/ol-man.el (org-man-store-link):
* lisp/ol-mhe.el (org-mhe-store-link):
* lisp/ol-rmail.el (org-rmail-store-link): Accept optional arg.
* lisp/org-id.el (org-id-link-consider-parent-id): New option to allow
a parent heading with an id to be considered as a link target.
(org-id-link-use-context): New option to add context to org-id links.
(org-id-get): Add optional `inherit' argument which considers parents'
IDs if the current entry does not have one.
(org-id-store-link): Consider IDs of parent headings as link targets
when current heading has no ID and `org-id-link-consider-parent-id' is
set.  Add a search string to the link when enabled.
(org-id-store-link-maybe): Function set as :store option for custom id
link property. Move logic from `org-store-link' here to determine when
an org-id link should be stored using `org-id-store-link'.
(org-id-open): Recognise search strings after "::" in org-id links.
* lisp/org-lint.el: Add checker for "::" in ID properties.
* testing/lisp/test-ol.el: Add tests for
`org-link-precise-link-target' and `org-id-store-link' functions,
testing new options.
* doc/org-manual.org: Update documentation about links.
* etc/ORG-NEWS: Document changes and new options.

These feature allows for more precise links when using org-id to link to
org headings, without requiring every single headline to have an id.

Link: https://list.orgmode.org/118435e8-0b20-46fd-af6a-88de8e19fac6@app.fastmail.com/
2024-02-24 15:56:44 +03:00
Rick Lupton 6e7e0b2cd3
lisp/org.el (org-insert-heading): Allow specifying heading level
* lisp/org.el (org-insert-heading): Change optional argument TOP to
LEVEL, accepting a number to force a specific heading level.
* testing/lisp/test-org.el (test-org/insert-heading): Add tests.
* etc/ORG-NEWS: Document changes.
2024-02-24 15:56:43 +03:00
Ihor Radchenko f90322377c
ox: Fix exporting code blocks with missing language specifier
* lisp/ox-latex.el (org-latex-inline-src-block): Export code blocks
without language as verbatim.
* lisp/ox-man.el (org-man-inline-src-block):
(org-man-src-block): Do not try to call source-highlight executable
when code block language is missing.
* lisp/ox-odt.el (org-odt-do-format-code):
* lisp/ox-texinfo.el (org-texinfo-src-block): Do not throw error when
code block language is missing.

Reproducer (not available on the list):

  To reproduce my problem you can write create an org-mode buffer (C-x b
  1.org M-x org-mode) with the following content:

  #+begin_src lua :tangle yes  :noweb yes
    aaa
    <<second>>
  #+end_src

  #+name: second
  #+begin_src
   bbb
  #+end_src

  Then enable exporting to texinfo and export the buffer:
    M-: (require 'ox-texinfo)
    C-c C-e i t

  The folllowing backtrace appears (providing you already enabled
  debugging on errors):

  Debugger entered--Lisp error: (wrong-type-argument stringp nil)
    apply(debug error (wrong-type-argument stringp nil))
    edebug(error (wrong-type-argument stringp nil))
    signal(wrong-type-argument (stringp nil))
    edebug-signal(wrong-type-argument (stringp nil))
    string-match("lisp" nil nil t)
    string-match-p("lisp" nil)
    (edebug-after (edebug-before 1) 5 (string-match-p "lisp" (edebug-after (edebug-before 2) 4
  (org-element-property :language (edebug-after 0 3 src-block)))))

Reported-by: pva-outdoor@yandex.ru
Link: https://list.orgmode.org/orgmode/87jzn7oz1u.fsf@yandex.ru/
2024-02-24 12:52:51 +03:00
Ihor Radchenko 505778950a
org-persist: Disable reporting read/write time by default
* lisp/org-persist.el (org-persist--report-time): This information
might be interesting, but not really necessary for users.  At least
one user also asked to disable the time reporting.
2024-02-24 12:39:59 +03:00
Ihor Radchenko 19db45f2cc
org-agenda-filter-by-category: Fix using truncated category as a filter
* lisp/org-agenda.el (org-agenda-format-item): Do not store truncated
category in 'org-category property when `org-agenda-prefix-format'
causes truncation.  This leads to agenda filters assuming truncated
version of the category as the true value, which is incorrect.

Reported-by: John Mathena <jmmathena@gmail.com>
Link: https://orgmode.org/list/CADywB5Lonxw-t1H7cvK+Au3oWq=EsB=Bthj13pt03MRP-Fn-4w@mail.gmail.com
2024-02-24 12:33:27 +03:00
Ihor Radchenko 4b1399fb21
org-goto-map: Do not treat 0-9 as digital arguments by default
* lisp/org-goto.el (org-goto--set-map): Fix 0-9 being interpreted as
digital arguments when `org-goto-auto-isearch' is non-nil.

Reported-by: Pan Xie <xiepan@skyguard.com.cn>
Link: https://orgmode.org/list/5f491471-af08-49d5-a840-6b2f96be54cf@skyguard.com.cn
2024-02-24 12:07:55 +03:00
Ihor Radchenko e52a480f9f
Merge branch 'bugfix' 2024-02-23 16:24:45 +03:00
Ihor Radchenko bfe253f7eb
org-cycle: Fix "Overwriting value of ... by aliasing" warning
* lisp/org-cycle.el:
* lisp/org.el (org-cycle): Move variable aliases right before new
variable name definitions in org-cycle.el.  Otherwise, if users set
the aliased variable values before loading Org-mode, they might get
overwritten by the default value.

Reported-by: Ruiyang Wu <ywwry66@gmail.com>
Link: https://orgmode.org/list/F3A95086-B4BF-4C08-AF7A-8D7DE6FE30CF@gmail.com
2024-02-23 16:24:19 +03:00
Ihor Radchenko 256caa0823
org-cycle: Fix "Overwriting value of ... by aliasing" warning
* lisp/org-cycle.el:
* lisp/org.el (org-cycle): Move variable aliases right before new
variable name definitions in org-cycle.el.  Otherwise, if users set
the aliased variable values before loading Org-mode, they might get
overwritten by the default value.

Reported-by: Ruiyang Wu <ywwry66@gmail.com>
Link: https://orgmode.org/list/F3A95086-B4BF-4C08-AF7A-8D7DE6FE30CF@gmail.com
2024-02-23 16:21:13 +03:00
Ihor Radchenko 24ce9abce7
org-capture-set-target-location: Fix `pcase' conditions
* lisp/org-capture.el (org-capture-set-target-location): Do not demand
file path to be a string in capture targets.  Other non-string values
are also allowed and checked in `org-capture-expand-file' that is
called later.

This commit fixes the changes introduced in 0a58a53ed.

Reported-by: Derek Chen-Becker <derek@chen-becker.org>
Link: https://orgmode.org/list/CAMbmz5nnXY1V1cPObfdw9wyM_GbiuYQ5_rksJ6gcO3Af+HOmSQ@mail.gmail.com
2024-02-23 15:51:11 +03:00
Ihor Radchenko 67d9372487
org-read-date-display: Fix random overlay priority when selection is at today
* lisp/org.el (org-read-date-display): Assign `org-read-date-overlay'
non-default priority.  This makes sure that the overlay is displayed
over the overlay that calendar.el puts to indicate "today".

Reported-by: John Kitchin <jkitchin@andrew.cmu.edu>
Link: https://orgmode.org/list/CALEYq0-xbCc6ayEK3v7tKnuGU7=Npgh3raEjuB13qOTN6Eu07Q@mail.gmail.com
2024-02-21 14:15:24 +03:00
Leo Butler b3b35b03ff
lisp/ox-beamer.el: customize the beamer frame environment name
* lisp/ox-beamer.el (org-beamer-frame-environment): A new customize
variable.  It contains the name of an environment that serves as an
alias for the beamer frame environment.

(org-beamer-template): Insert the `org-beamer-frame-environment'
environment definition into the beamer document.

* lisp/org-lint.el (org-lint-beamer-frame): Check the body of each
frame for an occurrence of \begin{orgframe} or \end{orgframe}, or
whatever environment name is in `org-beamer-frame-environment' [4].
The warning includes advice to see `org-beamer-frame-environment'.

* etc/ORG-NEWS (New option ~org-beamer-frame-environment~): Announce
the new option.

Rationale: Code with \begin{frame} or \end{frame} cannot be embedded
in a verbatim environment inside a beamer frame due to a design
decision made by the beamer developers [1].  As suggested in that
report, defining an alias for the beamer frame environment will allow
such verbatim examples to compile correctly [2].

This solution also works with instances of \againframe.

Refs:
[1] https://github.com/josephwright/beamer/issues/360
[2] https://github.com/josephwright/beamer/issues/360#issuecomment-708705250
[3] https://list.orgmode.org/orgmode/87le8eg1hs.fsf@localhost/T/
[4] https://list.orgmode.org/orgmode/87il38i5tb.fsf@localhost/T/
2024-02-21 13:46:32 +03:00
Ihor Radchenko 0dd2c5ea39
Merge branch 'bugfix' 2024-02-19 13:20:47 +03:00
Ihor Radchenko d5b98bcfb5
org-dynamic-block-define: Clarify that FUNC must accept zero arguments
* lisp/org.el (org-dynamic-block-define): Update the docstring.

Reported-by: chris <inkbottle007@gmail.com>
Link: https://orgmode.org/list/5790810.DvuYhMxLoT@nixos
2024-02-19 13:19:11 +03:00
Ihor Radchenko d6c3ab08b4
org-dynamic-block-insert-dblock: Do not call non-commands interactively
* lisp/org.el (org-dynamic-block-insert-dblock): When insert command
for a dynamic block is not interactive, do not try to call it
interactively.

Reported-by: chris <inkbottle007@gmail.com>
Link: https://orgmode.org/list/5790810.DvuYhMxLoT@nixos
2024-02-19 13:18:10 +03:00
Martin Edström a8443f2c79
org-latex-to-html-convert-command: Enhance the docstring
* org.el (org-latex-to-html-convert-command): Add a note in the
docstring about proper shell-quoting.

It can trip you up because wrongly quoted input still works with some
math snippets, so the command may work during testing but not later
when you have different math snippets in play.

TINYCHANGE
2024-02-19 11:28:06 +03:00
Ihor Radchenko d314882301
org-narrow-to-subtree: Fix when current narrowing intersects subtree
* lisp/org.el (org-narrow-to-subtree): Fix error when current
narrowing intersects the current subtree.  When intersection happens,
behave historically, like the previous version of the command (that
did not use org-element).
2024-02-18 17:47:18 +01:00
Ihor Radchenko 7360c6b427
Merge branch 'bugfix' 2024-02-18 17:29:35 +01:00
Ihor Radchenko 85aafac417
ox-md.el: Fix adding blank lines between table rows in derived exporters
* lisp/ox-md.el (org-md-separate-elements): Do not add blank lines
between table cells.  Even though table-cell elements are not exported
by ox-md itself, derived backends do not expect blank lines appearing
there.

Reported-by: Rohit Patnaik <quanticle@quanticle.net>
Link: https://orgmode.org/list/d84d5df0-108f-4a75-b7d2-299392613052@app.fastmail.com
2024-02-18 17:25:27 +01:00
Ihor Radchenko ea487bffb5
org-fold-hide-drawer-all: Do not use point and mark when no region is active
* lisp/org-fold.el (org-fold-hide-drawer-all): Do not unconditionally
use point and mark.  Only use region boundaries when the region is
active.
2024-02-18 11:48:50 +01:00
Ihor Radchenko 388ba5b5c4
org-insert-link: Do not expand path arg when `org-link-file-path-type' is a function
* lisp/ol.el (org-insert-link): Drop `expand-file-name'.
(org-link-file-path-type): Update docstring.
* etc/ORG-NEWS (When ~org-link-file-path-type~ is a function, its
argument is now a filename as it  in the link; not an absolute
path): Announce the change.

Link: https://orgmode.org/list/871qahl0un.fsf@localhost
2024-02-17 16:25:19 +01:00
Ihor Radchenko c9fc4c03e8
org-manual: Fix inaccuracy about TOC placement
* doc/org-manual.org (Table of Contents): Clarify that TOC is placed
at the beginning of the file, not "before first heading".  If there is
a text before first heading, TOC will be placed before that text.

Reported-by: Kodi Arfer <kodi@arfer.net>
Link: https://orgmode.org/list/dd0ae51d-7d56-0ff6-5eb1-3786464adfe3@arfer.net
2024-02-17 14:34:48 +01:00
Ihor Radchenko 1cca1967e9
fixup! ox-org: Do not process citations by default
* lisp/ox.el (org-export-process-citations): Add missing defcustom keywords.
2024-02-14 15:36:51 +01:00
Ihor Radchenko 0e1f0e1605
ox-latex: Make errors/warnings during PDF generation more obvious
* lisp/ox-latex.el (org-latex-compile--postprocess): Display a
warning, not message when there are problems with PDF generation.
2024-02-14 15:34:19 +01:00
Juan Manuel Macias 9eec4af620
lisp/ox-latex.el: Add missing character warnings
* (org-latex-known-warnings): Two missing character warnings are
added: one for LuaLaTeX/XelaTeX and another for pdfLaTeX.
2024-02-14 15:29:30 +01:00
Ihor Radchenko 97cc71b594
lisp/org-element.el, lisp/ox.el: Add Ihor Radchenko as a maintainer
* lisp/org-element.el:
* lisp/ox.el:
2024-02-14 13:41:21 +01:00
Ihor Radchenko fd45bfa648
Acknowledge that Nicolas Goaziou is no longer maintaining Org libraries
* lisp/ox-ascii.el:
* lisp/ox-beamer.el:
* lisp/ox-icalendar.el:
* lisp/ox-md.el:
* lisp/ox-org.el:
* lisp/ox-publish.el:
* lisp/ox-texinfo.el:
* lisp/ox.el: Remove "Maintainer" line.
2024-02-14 13:41:21 +01:00
Ihor Radchenko b8ee1315a1
ox-org: Do not process citations by default
* lisp/ox.el (org-export-options-alist): Add new export option
:with-cite-processors that allows disabling citation processors.
(org-export-process-citations): New customization (t by default)
defining the default value of :with-cite-processors export option.
(org-export-as):
(org-export--annotate-info): Disable citation processors when
:with-cite-processors is nil.
* lisp/ox-org.el (org-org-with-cite-processors): New custom
option (nil by default) controlling whether to use citation processors
when exporting to Org.
(org): Set :with-cite-processors according to the new option.  Declare
transcoders for citation and citation-reference objects.
* doc/org-manual.org (Summary of the export process): Update the
export flow description.
* etc/ORG-NEWS (Org export backends can now disable citation processors):
(=ox-org= disables citation processors by default):
(New option ~org-export-process-citations~):
(New option ~org-org-with-cite-processors~): Document the changes.

The change in ox-org behavior also fixes citation objects being
removed unconditionally from table src block results.

Reported-by: Stanislav Vlasov <S.Vlasov@tilburguniversity.edu>
Link: https://orgmode.org/list/87edrin6jw.fsf@localhost
2024-02-14 13:16:57 +01:00
Ihor Radchenko 666bd90497
fixup! ox-org: Export special table rows by default
* lisp/ox-org.el (org-org-with-special-rows): Add missing keywords for defcustom.
2024-02-14 12:50:17 +01: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 61c235b778
org-element-paragraph-parser: Fix edge case; fix tests
* lisp/org-element.el (org-element-paragraph-parser): Fix edge case
when 🔚 is in the middle of a paragraph.
*
testing/lisp/test-org-element.el (test-org-element/paragraph-parser):
Fix point position in the tests.  Add test case for ending lines of
incomplete blocks/drawers.  Remove test for incomplete dynamic blocks
- they are keywords.

Reported-by: Tom Alexander <tom@fizz.buzz>
Link: https://orgmode.org/list/87o7hiwzma.fsf@localhost
2024-02-13 12:46:58 +01:00
Martin Marshall 38dd882685
org-ctags: Fix regexp to not break radio-target links
* org-ctags.el (org-ctags-tag-regexp): Add left angle-bracket to
excluded characters for tag text.

Link: https://orgmode.org/list/87frxylw33.fsf@martinmarshall.com

TINYCHANGE
2024-02-12 15:04:41 +01:00
Ihor Radchenko 5cbaa87473
doc/org-manual.org (Include Files): Add link to export flow
Add reference to export flow where the exact export sequence is
explained in details.

Reported-by: Tim Landscheidt <tim@tim-landscheidt.de>
Link: https://orgmode.org/list/87fs9axxcm.fsf@localhost
2024-02-12 14:56:42 +01:00
Ihor Radchenko a70f216e3f
doc/org-manual.org (Summary of the export process): Reference `org-export-as' 2024-02-12 14:23:52 +01:00
Ihor Radchenko f9fc9d95c7
org-export-as: Add reference to export flow in the manual
* lisp/ox.el (org-export-as): Update docstring.
2024-02-12 14:23:51 +01:00
Ihor Radchenko 1087a7b4af
doc/org-manual.org: Add link to WORG export reference page
* doc/org-manual.org (Extending an existing backend): Link to WORG
page describing more details about writing export backends.
2024-02-12 14:23:51 +01:00
Ihor Radchenko 46cf76259c
doc/org-manual.org: Describe export flow
* doc/org-manual.org (Summary of the export process): Explain how the
export process is handled in Org mode.
2024-02-12 14:23:50 +01:00
Ihor Radchenko 1ff72e0918
doc/org-manual.org: Fix some obsolete variable names
* doc/org-manual.org (Export hooks): Use the new
`org-export-before-processing-functions' and
`org-export-before-parsing-functions' instead of their obsolete
aliases.
2024-02-12 14:23:49 +01:00
Ihor Radchenko cf7ef80a13
org-manual: Undocument `org-fast-tag-selection-include-todo'
* doc/org-manual.org (Fast access to TODO states): Remove references
to `org-fast-tag-selection-include-todo' to honour its docstring that
discourages using this option.  Renumber the footnotes.

Link: https://orgmode.org/list/87ttnmw818.fsf@localhost
2024-02-12 14:01:13 +01:00
Ihor Radchenko 6ff0de5c3e
ox-org: Export special table rows by default
* lisp/ox.el (org-export-options-alist): New internal plist option -
:with-special-rows.  Defaults to nil.
(org-export--skip-p): Do not skip special table rows when
:with-special-rows is non-nil.
* lisp/ox-org.el (org-org-with-special-rows): New custom option
controlling whether to export special table rows.  t by default.
(org): Use `org-org-with-special-rows' as the value of
:with-special-rows option.
* etc/ORG-NEWS (=ox-org= now exports special table rows by default):
(New option ~org-org-with-special-rows~): Announce the change.
2024-02-12 12:55:37 +01:00
Ihor Radchenko f4f0fc8bda
lisp/org-colview.el (org-columns--compute-spec): Fix columns in inlinetasks
* lisp/org-colview.el (org-columns--compute-spec): When summarizing
columns, limit the length of LVALS vector to maximum (not minimal!)
possible inlinetask depth.
2024-02-11 16:39:11 +01:00
Ihor Radchenko 807bf95c49
lisp/org-colview.el (org-columns): Avoid calling expensive `move-marker'
Just rely on garbage collector to do the right thing.  `move-marker'
significantly slows down column creation.   More than GC.
2024-02-11 16:34:44 +01:00
Ihor Radchenko 7e547fd3b6
org-columns--display-here: Cache result of `substitute-command-keys'
* lisp/org-colview.el (org-columns--read-only-string):
(org-columns--display-here): Cache return value of
`substitede-command-keys' in a variable.  It is otherwise slow to call
it every time a row is displayed.
2024-02-11 16:25:37 +01:00
Ihor Radchenko 2a999b298f
org-columns--display-here: Avoid calling `face-remap-add-relative' when possible
* lisp/org-colview.el (org-columns--display-here): Do not call
`face-remap-add-relative' multiple times in the same buffer.
2024-02-11 16:24:56 +01:00
Ihor Radchenko 01a074d0b5
fixup! Obsolete `org-icompleting-read' and `org-completing-read-no-i'
* lisp/ol.el (org-insert-link):
* lisp/org-ctags.el (org-ctags-find-tag-interactive):
* lisp/ox-odt.el (org-odt-convert-read-params): Remove the remaining
uses and references to ido-mode.  Rely upon built-in Emacs completion
system using the necessary completion backend rather than directly
calling ido functions.

This commit removes leftovers after
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=fdbf441560

Reported-by: Martin Marshall <law@martinmarshall.com>
2024-02-11 15:57:27 +01:00
Ihor Radchenko 5be39ff798
Reapply "lisp/org-element-ast.el (org-element-property-raw): Simplify implementation"
This reverts commit 942b4d97c1.

The cause was not this commit, but missing (require 'subr-x).
2024-02-11 15:11:39 +01:00
Ihor Radchenko 130382779b
testing/lisp/test-duplicates-detector.el: Fix Emacs 27 compatibility
*
testing/lisp/test-duplicates-detector.el (test-duplicates-detector--find-duplicates):
Do not use `while-let' that is not yet available in Emacs 27.
2024-02-11 15:11:11 +01:00
Ihor Radchenko 112f1c5fcd
lisp/org-element-ast.el: Fix compilation for Emacs 27 2024-02-11 15:10:55 +01:00
Ihor Radchenko ce1da4d201
fixup! org-startup-folded: Make values consistent with #+STARTUP keyword 2024-02-11 15:10:48 +01:00
Ihor Radchenko c2a58bbd53
org-startup-folded: Make values consistent with #+STARTUP keyword
* lisp/org.el (org-startup-folded): Document all the allowed values in
the docstring.  Allow symbols named the same as #+STARTUP option.
(org-startup-options): Allow `org-startup-folded' to have values
corresponding to the corresponding #+STARTUP options.
2024-02-11 13:40:17 +01:00
Ihor Radchenko bc0e14a1ab
Update version number for the 9.6.19 release 2024-02-11 12:50:12 +01:00
Ihor Radchenko d3a1394270
fixup! org-ctags.el: Fix use of "ctags" executable
* lisp/org-ctags.el (org-ctags-create-tags): Quote spaces and other
special characters in path.
2024-02-10 22:18:20 +01:00
Ihor Radchenko 8c7313d397
org-babel: New babel backend API function org-babel-session-buffer:<lang>
* lisp/ob-core.el (org-babel-session-buffer): New API function that
return session buffer, if such buffer exists and is live.
(org-babel-execute-src-block): Use `org-babel-session-buffer'.
* lisp/ob-lua.el (org-babel-session-buffer:lua):
* lisp/ob-python.el (org-babel-session-buffer:python): Provide API to
retrieve session buffer name.
(org-babel-python-initiate-session-by-key): Use
`org-babel-session-buffer:python'.
* etc/ORG-NEWS (Org babel backends are now expected to define an
additional API function ~org-babel-session-buffer:<lang>~): Declare
the API addition.

Link: https://orgmode.org/list/87r0hr9f3b.fsf@localhost
2024-02-10 21:57:52 +01:00
Jack Kamm 644bf846d6
ob-comint: Make file results from async sessions respect :dir header
* lisp/ob-comint.el (org-babel-comint-async-filter): Set
default-directory before calling `org-babel-insert-result'

https://list.orgmode.org/875xz9o4nj.fsf@localhost/T/#t
2024-02-10 21:57:13 +01:00
Ihor Radchenko 13d0f8bf8e
org-babel-execute-src-block: Force :dir according to live session
* lisp/ob-core.el (org-babel-execute-src-block): Force eval directory
to follow live session buffer, if any.  This is consistent with what
we promise in the manual section "16.4 Environment of a Code
Block">Choosing a working directory.

Link: https://orgmode.org/list/87mssi8ht2.fsf@gmail.com
2024-02-10 21:57:08 +01:00
Ihor Radchenko cbfe1354b3
org-insert-subheading: Never insert sub-heading above current
* lisp/org.el (org-insert-subheading): When at bol, do not insert
heading above (default behavior of `org-insert-heading').  Instead,
force `org-insert-heading' to insert below.  Improve docstring,
explaining how the prefix arguments are used and the new different
with `org-insert-heading'.
* etc/ORG-NEWS (~org-insert-subheading~ no longer inserts a
sub-heading above current when point is at the beginning of line):
Document the breaking change.

Reported-by: Michael Dauer <mick.dauer@gmail.com>
Link: https://list.orgmode.org/CAP7OBx+whiB8Jo_hEcfL6MajDU1EH=E5j0ZOvHB3dPRK+Aj4mQ@mail.gmail.com/
2024-02-10 16:57:59 +01:00
Ihor Radchenko 9ddfb66996
lisp/org.el (org-insert-subheading): Improve docstring 2024-02-10 16:57:42 +01:00
Ihor Radchenko 942b4d97c1
Revert "lisp/org-element-ast.el (org-element-property-raw): Simplify implementation"
This reverts commit cfb48624f3.

The commit is not compatible with Emacs 27, which is still supported.
2024-02-10 16:39:13 +01:00
Gerard Vermeulen 80e7c9f80f
ox-latex: String variables are not file local safe
* lisp/ox-latex.el (org-latex-default-figure-position):
(org-latex-default-quote-environment, org-latex-image-default-scale):
(org-latex-reference-command): File local safe string variables allow
to write Org files allowing to inject any command.

Link: https://list.orgmode.org/ffa77c01d47b15dfc0ae687cab95fb01@posteo.net/
2024-02-10 15:55:44 +01:00
Martin Marshall 981402a93d
org-ctags.el: Fix use of "ctags" executable
* lisp/org-ctags.el (org-ctags-create-tags): Allow file globbing in
`shell-command' invocation of "ctags".

TINYCHANGE
2024-02-10 15:25:08 +01:00
Ihor Radchenko cfb48624f3
lisp/org-element-ast.el (org-element-property-raw): Simplify implementation 2024-02-10 14:07:52 +01:00
Ihor Radchenko 7319136420
org-element-cache-map: Fix when :next-re is provided
* lisp/org-element.el (org-element-cache-map): Fix searching next-re
in move-start-to-next-match.  The if confition was erroneously always
true due to the last `cl-incf'.  Do not map over failing entry when
next-re did not match and continue-flag is set.  Do not move point to
next entry before calling FUNC.
* testing/lisp/test-org.el (test-org/map-entries): Add new test case.
2024-02-09 21:32:54 +01:00
Ihor Radchenko df1f9be7f8
fixup! Add testing/lisp/test-duplicates-detector.el
*
testing/lisp/test-duplicates-detector.el (test-duplicates-detector--find-duplicates):
Provide third argument to `mapconcat' for Emacs <29.
2024-02-09 19:55:01 +01:00
Ihor Radchenko aa3724dbde
org-capture: Obsolete `org-capture-bookmark' in favor of `org-bookmark-names-plist'
* lisp/org-capture.el (org-capture-bookmark):
* lisp/org-compat.el (org-capture-bookmark): Mark obsolete.
* lisp/org-capture.el (org-capture-store-last-position): Add comment
about obsoletion.
* doc/org-manual.org (Using capture): Mention
`org-bookmark-names-plist' instead of `org-capture-bookmark'.

Reported-by: Tim Wichmann <schwurg@arcor.de>
Link: https://orgmode.org/list/87bk8r2ig1.fsf@localhost
2024-02-09 17:47:57 +01:00
Ihor Radchenko 0d77cf8421
org-latex-headline: Prevent footnotes in TOC/footers
* lisp/ox-latex.el (org-latex-headline): When headline contains
footnotes and does not have ALT_TITLE, arrange alternative title that
will appear in TOC and footers to not have any footnotes.

Reported-by: Eric Anderson <kluwak@gmail.com>
Link: https://orgmode.org/list/691643eb-49d0-45c3-ab7f-a1edbd093bef@gmail.com
2024-02-09 17:38:43 +01:00
Ihor Radchenko 27d6f8305c
lisp/ob-comint.el: Introduce a fallback prompt regexp
* lisp/ob-comint.el (org-babel-comint-prompt-regexp-old): New variable
storing the default value of `comint-prompt-regexp' to be used when
the prompt set by Org mode changes for some reason.
(org-babel-comint-fallback-regexp-threshold): New customization to set
the time Org babel waits for comint command to finish until trying
fallback prompt regexp.
(org-babel-comint--set-fallback-prompt): New internal function that
sets the fallback prompt regexp, if there is any available.
(org-babel-comint-with-output):
(org-babel-comint-wait-for-output): Try fallback prompt regexp when we
cannot find comint command end for too long.
* lisp/ob-haskell.el (org-babel-interpret-haskell):
* lisp/ob-ruby.el (org-babel-ruby-initiate-session):
* lisp/ob-shell.el (org-babel-sh-initiate-session):
* lisp/ob-clojure.el (ob-clojure-eval-with-inf-clojure): Set
`org-babel-comint-prompt-regexp-old' when initializing the inferior
shell.
* etc/ORG-NEWS (New option
~org-babel-comint-fallback-regexp-threshold~): Document the new
customization.

Reported-by: Jack Kamm <jackkamm@tatersworld.org>
Link: https://orgmode.org/list/87sf2q9ubd.fsf@gmail.com
2024-02-09 17:35:58 +01:00
Ihor Radchenko c76d498f44
mk/default.mk: Use make single by default
This is compatible with parallel execution and can also help to catch
native compilation errors (native compilation compiles .elc files
separately), like the one discussed in bug#68851.
2024-02-09 17:17:12 +01:00
Ihor Radchenko 71fbe92c2e
mk: Allow parallel execution
* lisp/Makefile (.NOTPARALLEL): Do not suppress parallel execution.
(all compile compile-dirty):
(compile-single):
(compile-native):
(compile-source):
(compile-slint1):
(compile-slint2): Explicitly declare prerequisites that must be run
sequentially.
* mk/targets.mk (.NOTPARALLEL): Do not suppress parallel execution.
(uncompiled):
(update update2):
(repro): Explicitly declare prerequisites that must be run
sequentially.
2024-02-09 17:15:53 +01:00
Stefan Monnier ecb5b605d7
lisp/org-element-ast.el: Fix compile-time inline expansion
* lisp/org-element-ast.el (org-element--property-idx): Define inline
expansion within `eval-and-compile' to make sure that the expanded is
available at compile time.

See Emacs bug#68851.
2024-02-09 16:31:10 +01:00
Ihor Radchenko 8e2ed45bb1
test-org/file-contents: Refactor duplicate test
* testing/lisp/test-org.el (test-org/file-contents): Avoid safety
prompt when testing.  Fix duplicate test testing optional argument for
`org-file-contents' (the argument were not passed previously).
2024-02-09 15:07:35 +01:00
Ihor Radchenko e3f327d1e6
ob-haskell/session-named-none-means-one-shot-sessions: Remove duplicate
*
testing/lisp/test-ob-haskell-ghci.el (ob-haskell/session-named-none-means-one-shot-sessions):
Remove duplicate from the test.
2024-02-09 14:57:57 +01:00
Ilya Chernyshov 8d2fcfea99
Add testing/lisp/test-duplicates-detector.el
* testing/lisp/test-duplicates-detector.el: Add test unit that checks
for duplicate ert-deftests and forms inside of them.
2024-02-09 14:57:54 +01:00
Ihor Radchenko 4797ebf834
lisp/org-crypt.el (org-current-level): Fix compiler warning 2024-02-09 13:44:33 +01:00
Ihor Radchenko adf841219d
mk: Use ` quotes instead of complex '"'"'
* mk/default.mk (req-ob-lang):
(req-extra):
(BTEST_LOAD):
(BATCHO):
(BATCHL):

Reported-by: Stefan Monnier <monnier@iro.umontreal.ca>
Link: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=68851#50
2024-02-09 12:55:43 +01:00
Ihor Radchenko ee395b9b8e
Add new make target for native compilation
* lisp/Makefile (LISPN): New variable listing all the valid .eln
targets.
(_ORGCM_):
(compile-native):
(native): New compile target.
(%.eln): Rule how to compile .eln files from .el files.
* mk/default.mk (ELN): Command to perform native compilation of a
single .eln file.
* mk/targets.mk (.PHONY):
(CONF_CALL): List the new targets and variables.
(native): Add target.
2024-02-08 20:16:51 +01:00
Ihor Radchenko bfc0cb3723
lisp/org-num.el: Autoload safe variables
* lisp/org-num.el (org-num-face):
(org-num-max-level):
(org-num-skip-commented):
(org-num-skip-footnotes):
(org-num-skip-tags):
(org-num-skip-unnumbered): Autoload variables with :safe
specification.  Without autoloading, if org-num is not loaded,
unexpected warning may be displayed when opening an Org file.

Reported-by: Chang Xiaoduan <drcxd@sina.com>
Link: https://list.orgmode.org/orgmode/87jznf7gqo.fsf@PWRD-20230207OU./
2024-02-08 16:17:34 +01:00
Ihor Radchenko 62956196d0
org-agenda: Fix entries with timestamps without day name
* lisp/org-agenda.el (org-agenda-get-timestamps):
(org-agenda-get-progress): When matching specific date in timestamp,
do not demand that timestamp to contain day name.

Reported-by: Stephen J. Eglen <sje30@cam.ac.uk>
Link: https://orgmode.org/list/874jejrij6.fsf@localhost
2024-02-08 16:01:29 +01:00
Rick Lupton f016545aa1
org-link-search-must-match-exact-headline: Improve docstring
* lisp/ol.el (org-link-search-must-match-exact-headline): Make the
docstring more accurately describe behaviour.

Link: https://list.orgmode.org/87cytdithi.fsf@localhost/
2024-02-08 15:51:10 +01:00
Ihor Radchenko b26745b985
org-agenda: Fix meaning of 'repeated-after-deadline value of `org-agenda-skip-scheduled-if-deadline-is-shown'
* lisp/org-agenda.el (org-agenda-skip-scheduled-if-deadline-is-shown):
Move 'repeated-after-deadline value into a new custom option.
(org-agenda-skip-scheduled-repeats-after-deadline): Create a new
custom option to make agenda hide scheduled entries repeated past
deadline.
* lisp/org-agenda.el (org-agenda-get-scheduled): Use the new custom
option.  Do not demand deadline to be actually shown when deciding
whether to skip scheduled repeats past deadline.  This fixes a bug
when repeats continue to be displayed if past deadline is not
displayed within agenda span.
* doc/org-manual.org (Repeated tasks): Adjust manual entry, mentioning
the new custom option.
* etc/ORG-NEWS (~repeated-after-deadline~ value of
~org-agenda-skip-scheduled-repeats-after-deadline~ is moved to a new
customization): Announce the change.
*
testing/lisp/test-org-agenda.el (test-org-agenda/skip-scheduled-repeats-after-deadline):
Add new test.

Reported-by: Morgan Smith <Morgan.J.Smith@outlook.com>
Link: https://orgmode.org/list/874jft6vpj.fsf@localhost
2024-02-07 13:21:34 +01:00
Sławomir Grochowski 18d98ee655
org-colview: Extract functions `org-columns-move-up' & `org-columns-move-down'
* lisp/org-colview.el (org-defkey): Do not use anonymous function as a
binding.
2024-02-06 20:31:01 +01:00
Ihor Radchenko 8ccda1737b
fixup! org-capture-set-target-location: Improve error reporting for malformed target
Reported-by: Zhitao <zhitaao.gong@gmail.com>
Link: https://orgmode.org/list/CACcmFoCvtyGBKR7mTjdQOd-w82wz-xcavnpEVT=6mFOWpo1T1w@mail.gmail.com
2024-02-06 20:02:40 +01:00
Ihor Radchenko 4254a54f88
org-update-parent-todo-statistics: Do not modify buffer unnecessarily
* lisp/org.el (org-update-parent-todo-statistics): When the updated
statistics cookie is unchanged, do not modify buffer.  This prevents
unnecessary queries to element cache.
2024-02-05 22:12:03 +01:00
Pedro A. Aranda Gutiérrez 10d2868c58
org-footnote-new: Add an option to create new anonymous labels
* lisp/org-footnote.el (org-footnote-new, org-footnote-auto-label):
Add symbol `anonymous' to `org-footnote-auto-label'.  With this,
anonymous footnotes will be created.  This is sometimes useful in long
texts.  Mimics \footnote{} in LaTeX.  Modify `org-footnote-new' to
generate anonymous footnotes directly.

* lisp/org.el (org-startup-options): Add `fnanon' to startup options.

* testing/lisp/test-org-footnote.el (test-org-footnote/new-anon): Add
a test for creation of anonymous footnotes.

* etc/ORG-NEWS:
(~org-footnote-new~ can be configured to create anonymous footnotes):
Announce new anonymous footnote support.

* doc/org-manual.org (Summary of In-Buffer Settings): Document
"fnanon" startup option.
2024-02-05 15:38:48 +01:00
Ihor Radchenko 7f5e085cad
org-decrypt-entry: Adjust headline levels in decrypted subtree
* lisp/org-crypt.el (org-decrypt-entry): When decrypted subtree
contains headings with levels below the containing heading, demote
that subtree, so that originally encrypted text remains under the same
parent heading.  This is useful when encrypted heading is promoted.
2024-02-05 14:04:52 +01:00
Ihor Radchenko f4414f5dbb
ox-latex: Fix references to src block results without #+name
* lisp/ox-latex.el (org-latex--label): Consider :results property in
addition to :name property of the datum.  For datums that are results
of evaluation, the label may not only come from #+name keyword, but
can also be duplicated from the generating src block.
(org-latex--wrap-label): Do not limit label to elements with #+name.
Rely on `org-latex--label' to return appropriate label (or nil).

Reported-by: gerard.vermeulen@posteo.net
Link: https://orgmode.org/list/6d9db4be5d42236391d5c4e530250ee1@posteo.net
2024-02-05 13:29:05 +01:00
Sławomir Grochowski 0938795fd7
org-colview: Replace anonymous function with `forward-char'
* lisp/org-colview.el (org-defkey): Do not use anonymous function as a
binding.
2024-02-04 17:48:04 +01:00
Ihor Radchenko 0a58a53eda
org-capture-set-target-location: Improve error reporting for malformed target
* lisp/org-capture.el (org-capture-set-target-location): Tighten
matching the template target location when the location value is not
properly formatted.
2024-02-04 14:47:23 +01:00
Ihor Radchenko b2ee10545e
Merge branch 'bugfix' 2024-02-04 14:31:31 +01:00
Ihor Radchenko 1abff38597
org-fontify-extend-region: Fix edge case
* lisp/org.el (org-fontify-extend-region): Extend region for an extra
character, just as `font-lock-extend-jit-lock-region-after-change'
does.  This fixes a reported edge case.

Also, see https://debbugs.gnu.org/cgi/bugreport.cgi?bug=68849

Reported-by: Kostas Papadakis <papadakis.k@yandex.com>
Link: https://orgmode.org/list/c5fb9f63-185c-4e36-b13f-e887a4a29aae@yandex.com
2024-02-04 14:29:23 +01:00
Ihor Radchenko 97f4ae0c2d
Update version number for the 9.6.18 release 2024-02-04 13:53:02 +01:00
Ihor Radchenko 7a6bb0904d
org-table-justify-field-maybe: Do not leak alignment data from other tables
* lisp/org-table.el (org-table-justify-field-maybe): Make sure that
`org-table-last-alignment' and `org-table-last-column-widths' do not
lea from another table that was re-aligned recently.

Link: https://old.reddit.com/r/emacs/comments/10gegwa/recalculating_an_orgmode_table_causes/
2024-02-03 15:58:41 +01:00
Ihor Radchenko 09ced6d2c2
org-link-plain-re: Improve regexp heuristics
* lisp/ol.el (org-link-make-regexps): Match <...> and <...> balanced
brackets.

This change detects plain links like
http://dx.doi.org/10.1002/(SICI)1521-396X(199901)171:1<239::AID-PSSA239>3.0.CO;2-M
2024-02-03 15:15:46 +01:00
Ihor Radchenko 5cb52f379b
org-html-example-block: Combine :class attributes using space
* lisp/ox-html.el (org-html-example-block): Avoid creating duplicate
class= attributes when example block has #+ATTR_HTML: :class foo.

Multiple class attributes must be combined with space, as per
https://www.w3schools.com/html/html_classes.asp

Reported-by: Joshua Honeycutt <joshua.honeycutt@gmail.com>
Link: https://orgmode.org/list/87fsfxfzex.fsf@localhost
2024-02-03 15:09:11 +01:00
Ihor Radchenko 3f4bdf80cb
Merge branch 'bugfix' 2024-02-02 21:01:30 +01:00
Ihor Radchenko 56748ea4e2
org: Fix security prompt for downloading remote resource
* lisp/org.el (org--confirm-resource-safe): Do not assume that
resource is safe when user replies "n" (do not download).

Reported-by: Max Nikulin <manikulin@gmail.com>
Link: https://orgmode.org/list/upj6uk$b7o$1@ciao.gmane.io
2024-02-02 20:59:41 +01:00
Ihor Radchenko 57f1c02556
doc/org-manual.org: Clarify the default export language for LaTeX export
* doc/org-manual.org (LaTeX specific export settings): Link to
`org-export-default-language' customization and mention its default
value.
2024-02-02 17:22:28 +01:00
Ihor Radchenko c67af5c24a
test-org-fold/org-fold-display-inline-images: Fix skip condition in older Emacs
*
testing/lisp/test-org-fold.el (test-org-fold/org-fold-display-inline-images):
Use skip-unless available in older Emacs rather than skip-when.
2024-02-02 17:03:35 +01:00
Ihor Radchenko 1156554aaf
test-org-fold/org-fold-display-inline-images: Fix test, disable when non-interactive
* testing/lisp/test-org-fold.el (test-org-fold/org-fold-display-inline-images):
2024-02-02 16:24:32 +01:00
Ihor Radchenko 844bd9f1f1
lisp/org.el (org-copy-visible): Fix when using overlays for folding 2024-02-02 16:24:16 +01:00
Ihor Radchenko 83bc81b750
lisp/org-list.el (org-list-swap-items): Fix re-folding after swap 2024-02-02 16:23:50 +01:00
Ihor Radchenko 96944e8d43
org-fold-core--process-delayed: Fix delayed folding in killed buffers
* lisp/org-fold-core.el (org-fold-core--process-delayed): Do not fold
when markers point to killed buffers.
2024-02-02 16:23:05 +01:00
Gerard Vermeulen 71fa0014db
lisp/ox-latex.el: make org-latex-prefer-user-labels safe file local
* lisp/ox-latex.el (org-latex-prefer-user-labels): make it a safe file
local variable for consistency with `org-latex-reference-command' and
`org-html-prefer-user-labels' being also safe file local variables.
2024-02-02 14:50:33 +01:00
Ihor Radchenko 344d4624e1
lisp/org-compat.el: Fix compiler warning when make single
* lisp/org-compat.el (org-switch-to-buffer-other-window): Do not use
obsolete macro.  Even with `with-no-warnings', a warning is emitted.
2024-02-02 14:33:01 +01:00
Ihor Radchenko 62c6d5668d
org-fold-core-style: Use 'overlays in Emacs >=29
* lisp/org-fold-core.el (org-fold-core-style): Set default value to
'overlays in newer Emacs versions.  Newer Emacs does not have
performance issues with overlays and using text-properties there is
not beneficial due to numerous issues with most of Emacs code and
third-party packages that assume overlay-based folding.
2024-02-02 14:21:31 +01:00
Sławomir Grochowski 614d534a9d
fixup! doc/org-manual.org: Checkboxes, add checkbox states examples
Description of example of a checkbox list ("The ‘[2/4]’ and ‘[1/3]’...")
should be right below the example.
2024-02-01 16:49:22 +01:00
Tommy Kelly 055ed4a2f6
doc/org-manual.org: Clarify what TIMESTAMP and TIMESTAMP_IA refer to
* doc/org-manual.org (Special Properties): Improve description of the
special properties.

Re-number footnotes.

Link: https://orgmode.org/list/CAMg28OtQTFsk8SRSvN6B83M_Rf1AaTskgtYGcND_XnaazDnRww@mail.gmail.com

TINYCHANGE
2024-02-01 16:35:01 +01:00
Ihor Radchenko 40d1352b29
org-babel: Declare :async header argument in the backends that support it
* lisp/ob-R.el (org-babel-header-args:R):
* lisp/ob-python.el (org-babel-header-args:python): Declare async
header argument.
* lisp/ob-shell.el (org-babel-header-args:shell): Add variable.
(org-babel-shell-initialize): Propagate base
`org-babel-header-args:shell' to `org-babel-header-args:<shell-name>'.

Without declaration, org-lint would not recognize :async argument.
2024-02-01 16:15:50 +01:00
Ihor Radchenko 14acf626fe
org: Fontify whole table rows with `org-table-row' face
* lisp/org-faces.el (org-table-row): New face.
* lisp/org.el (org-set-font-lock-defaults): Use ~org-table-row~ face
to fontify the whole table rows, including indentation and newlines.
* etc/ORG-NEWS (Org mode now fontifies whole table lines (including
newline) according to ~org-table~ face): Announce the change.
2024-02-01 15:30:18 +01:00
Ihor Radchenko 788af56753
doc/org-manual.org (Summary): Clarify the Org markup is human-readable
Readability of raw Org text is one of the core principles we maintain
when designing Org markup language.  Let's state it explicitly in the
manual.
2024-02-01 13:16:11 +01:00
Ihor Radchenko 402643f194
Merge branch 'bugfix' 2024-02-01 12:45:32 +01:00
Gerard Vermeulen 84f56c47f2
lisp/ox-latex.el: improve org-latex-toc-command docstring
* lisp/ox-latex.el (org-latex-toc-command): specify clearer which
option settings use `org-latex-toc-command'.  This shows also how
to specify a table of contents depth.
2024-02-01 12:44:41 +01:00
Ihor Radchenko 5f22a1be40
org-table-header-set-header: Fix header calculation
* lisp/org-table.el (org-table-header-set-header): Make sure that
Emacs finishes any queued redisplay before calculating window
boundaries.  Do not make assumptions about the same character width of
table lines.
(org-table-row-get-visible-string): Refactor calculation of the visual
text representation.  Inherit all the text properties - in particular,
composition.  Collect non-intersecting overlays into text properties.

Reported-by: Ypo <ypuntot@gmail.com>
Link: https://orgmode.org/list/87a605oyht.fsf@localhost
2024-01-31 15:56:26 +01:00
Eric S Fraga c9ed0388e7
lisp/ox-beamer.el: Add BEAMER_ACT to column definition
* ox-beamer.el (org-beamer--format-block): Process BEAMER_ACT if given
for column block.
2024-01-31 15:26:48 +01:00
Ihor Radchenko 13a8a74a99
Merge branch 'bugfix' 2024-01-31 14:07:50 +01:00
Ihor Radchenko d4eaf8fe5f
org-publish-sitemap-file-entry-format: Do not refer to non-existing symbol
* lisp/org-compat.el (org-publish-sitemap-file-entry-format): Update
the docstring.

Reported-by: Stefan Kangas <stefankangas@gmail.com>
Link: https://orgmode.org/list/CADwFkmnsjEg+d7ty0bjT5RGQiS-SdKcvRUy+KHDh+maa92bp1w@mail.gmail.com
2024-01-31 14:07:18 +01:00
Ihor Radchenko 28e38a47aa
doc/org-manual.org (Generating a sitemap): Fix property list
* doc/org-manual.org (Generating a sitemap): Add missing
:sitemap-style property description.  Remove deprecated
:sitemap-file-entry-format and :sitemap-date-format.

Reported-by: Stefan Kangas <stefankangas@gmail.com>
Link: https://orgmode.org/list/CADwFkmnsjEg+d7ty0bjT5RGQiS-SdKcvRUy+KHDh+maa92bp1w@mail.gmail.com
2024-01-31 14:07:12 +01:00
Ihor Radchenko ee0196e6af
doc/org-manual.org (Generating a sitemap): Link to `org-publish-project-alist' 2024-01-31 14:07:08 +01:00
Ihor Radchenko f1978ede29
org-odt-get-table-cell-styles: Fix reference to obsolete text property
* lisp/ox-odt.el (org-odt-get-table-cell-styles): Remove reference to
long-obsolete text property used to store table alignment info.
Instead, refer to table alignment cookies described in the manual.

Reported-by: Stefan Kangas <stefankangas@gmail.com>
Link: https://orgmode.org/list/CADwFkmnsjEg+d7ty0bjT5RGQiS-SdKcvRUy+KHDh+maa92bp1w@mail.gmail.com
2024-01-31 14:06:50 +01:00
Ihor Radchenko ad90ff7cb2
lisp/org-table.el: Fix reference to non-existing function
* lisp/org-table.el (org-table--read-column-selection): Fix the
docstring, pointing to the right function that explains the format of
SELECT argument.

Reported-by: Stefan Kangas <stefankangas@gmail.com>
Link: https://orgmode.org/list/CADwFkmnsjEg+d7ty0bjT5RGQiS-SdKcvRUy+KHDh+maa92bp1w@mail.gmail.com
2024-01-31 14:06:30 +01:00
Ihor Radchenko 75b6f2712a
lisp/org-table.el (org-table-copy-down): Fix typo 2024-01-31 14:06:16 +01:00
Ihor Radchenko a5e84c2fb8
org-link-translation-function: Remove reference to removed function
* lisp/ol.el (org-link-translation-function): Remove reference to
no-longer-available `org-translate-link-from-planner' from the
docstring.

Reported-by: Stefan Kangas <stefankangas@gmail.com>
Link: https://orgmode.org/list/CADwFkmnsjEg+d7ty0bjT5RGQiS-SdKcvRUy+KHDh+maa92bp1w@mail.gmail.com
2024-01-31 14:06:03 +01:00
Ihor Radchenko 4aced687b8
lisp/org-tempo.el: Do not refer to removed function in the commentary
Reported-by: Stefan Kangas <stefankangas@gmail.com>
Link: https://orgmode.org/list/CADwFkmnsjEg+d7ty0bjT5RGQiS-SdKcvRUy+KHDh+maa92bp1w@mail.gmail.com
2024-01-31 14:05:46 +01:00
Ihor Radchenko ede8294cf7
lisp/ox.el: Fix removed variable in the commentary
Reported-by: Stefan Kangas <stefankangas@gmail.com>
Link: https://orgmode.org/list/CADwFkmnsjEg+d7ty0bjT5RGQiS-SdKcvRUy+KHDh+maa92bp1w@mail.gmail.com
2024-01-31 14:05:30 +01:00
Ihor Radchenko fe663b6c80
lisp/org-element-ast.el (org-element--property-idx): Simplify implementation
Reported-by: Stefan Monnier <monnier@iro.umontreal.ca>
Link: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=68818#11
2024-01-31 14:01:33 +01:00
Ihor Radchenko 03b383df8b
ox-latex: Remove org-latex-line-break-safe
This reverts commit 3f60acff77 and
subsequent relevant comments.

* lisp/ox-latex.el (org-latex-line-break-safe): Remove constant.  The
\\[0pt] is actually not safe to use in some scenarios. We use a
different approach to avoid plain text [...] being interpreted as
LaTeX optional argument - we escape [ like {[}; that's what pandoc
does.
(org-latex-clock):
(org-latex-line-break):
(org-latex-plain-text):
(org-latex-planning):
(org-latex--org-table):
(org-latex--math-table):
(org-latex-table-row):
(org-latex-verse-block):
* testing/lisp/test-org-table.el (test-org-table/to-latex):
* testing/lisp/test-ox-latex.el (test-ox-latex/verse):
(test-ox-latex/longtable): Remove references to
`org-latex-line-break-safe'.
* etc/ORG-NEWS (=ox-latex=: ~org-latex-line-break-safe~ is removed):
Announce removal.
* lisp/org-compat.el (org-latex-line-break-safe): Make obsolete.

Link: https://orgmode.org/list/878r4jg37s.fsf@posteo.net
2024-01-31 12:35:29 +01:00
Ihor Radchenko bd305ecdf6
ox-latex: Make sure that [text] is not misinterpreted as LaTeX argument
* lisp/ox-latex.el (org-latex-plain-text): Protect plain text starting
from [.  It might be misinterpreted as optional command argument if
previous exported fragment ends with a command accepting such.
*
testing/lisp/test-ox-latex.el (text-ox-latex/protect-square-brackets):
Add new test.

Link: https://orgmode.org/list/87o7dju9vn.fsf@posteo.net
2024-01-31 12:34:21 +01:00
Ihor Radchenko 15e51d7083
lisp/org-persist.el (and): Fix typo
Use `unless' instead of erroneous `when' in the test whether to run
lockfile timer.

Reported-by: Karthik Chikmagalur
2024-01-31 12:18:54 +01:00
Ihor Radchenko afc529b4a0
lisp/org-element-ast.el (org-element-type-p): Simplify implementation
Reported-by: Stefan Monnier <monnier@iro.umontreal.ca>
Link: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=68818#11
2024-01-30 17:19:05 +01:00
Hunter Jozwiak 86c4038da6
ob-scheme: Allow ob-scheme to accept a remote connection
* lisp/org/ob-scheme.el (org-babel-scheme-get-repl): Introduce two
optional arguments: host and port.  If these are not given, just run
Geiser as before.  In the case when both are given, connect to the
remotely running Scheme process.
* lisp/org/ob-scheme (org-babel-scheme-execute-with-geiser,
org-babel-execute:scheme): Take these  optional arguments into account.
* lisp/org/ob-scheme.el (org-babel-header-args:scheme): Define host
and port header arguments for completion.

TINYCHANGE
2024-01-30 16:42:23 +01:00
Ihor Radchenko da9ac6da1d
Merge branch 'bugfix' 2024-01-30 15:28:02 +01:00
Ihor Radchenko 7de8b3917c
org-todo: Fix tag alignment when title contains a folded link
* lisp/org.el (org-todo): When title contains link, we cannot use
`org-fold-region' to unfold everything - this may cause unexpected tag
alignment when the link is revealed and font-locking is not yet
triggered.  Instead of unfolding everything, just remove outline folds.

Reported-by: Peter Solodov <solodov@gmail.com>
Link: https://orgmode.org/list/413C89C3-25DB-425B-A367-FA683E7ADD05@gmail.com
2024-01-30 15:25:00 +01:00
Ihor Radchenko a5c977b43e
org-cycle-set-visibility-according-to-property: Honor inner VISIBILITY settings
* lisp/org-cycle.el (org-cycle-set-visibility-according-to-property):
Do not ignore :VISIBILITY: properties when parent also has
:VISIBILITY:.
*
testing/lisp/test-org-fold.el (test-org-fold/set-visibility-according-to-property):
Add new test.

Similar to how :VISIBILITY: overrides #+STARTUP folding settings,
child :VISIBILITY: should override parent :VISIBILITY:.

The previous version of the code was skipping child VISIBILITY
property to address
https://lists.gnu.org/r/emacs-orgmode/2019-01/msg00402.html
However, that problem in that bug report was not with child VISIBILITY
property, but rather with previous implementation detail that
`org-reveal' was called prior to setting VISIBILITY. That affected
parent headings as well and no longer a problem.

Reported-by: John Mathena <jmmathena@gmail.com>
Link: https://orgmode.org/list/87tucu99od.fsf@localhost
2024-01-30 14:43:08 +01:00
Ihor Radchenko e2144f5f32
org-publish-sitemap-file-entry-format: Do not refer to non-existing symbol
* lisp/org-compat.el (org-publish-sitemap-file-entry-format): Update
the docstring.

Reported-by: Stefan Kangas <stefankangas@gmail.com>
Link: https://orgmode.org/list/CADwFkmnsjEg+d7ty0bjT5RGQiS-SdKcvRUy+KHDh+maa92bp1w@mail.gmail.com
2024-01-30 13:41:42 +01:00
Ihor Radchenko cfef7f85f1
doc/org-manual.org (Generating a sitemap): Fix property list
* doc/org-manual.org (Generating a sitemap): Add missing
:sitemap-style property description.  Remove deprecated
:sitemap-file-entry-format and :sitemap-date-format.

Reported-by: Stefan Kangas <stefankangas@gmail.com>
Link: https://orgmode.org/list/CADwFkmnsjEg+d7ty0bjT5RGQiS-SdKcvRUy+KHDh+maa92bp1w@mail.gmail.com
2024-01-30 13:40:11 +01:00
Ihor Radchenko 6533eedc41
doc/org-manual.org (Generating a sitemap): Link to `org-publish-project-alist' 2024-01-30 13:39:57 +01:00
Andrew Hyatt f490c1548a
org-agenda: New customization `org-agenda-start-with-archives-mode'
* lisp/org-agenda.el: Add `org-agenda-start-with-archives-mode'.
(org-agenda-mode): Set value of `org-agenda-archive-mode' according to
value of new variable `org-agenda-start-with-archives-mode'.

* doc/org-manual.org: Note new variable in the documentation of
`org-agenda-archives-mode'.

* etc/ORG-NEWS: Note change to add
`org-agenda-start-with-archives-mode'.
2024-01-29 17:56:42 +01:00
Gerard Vermeulen 813614cff4
lisp/org-src.el: complete `org-src-preserve-indentation' docstring
* lisp/org-src.el (org-src-preserve-indentation): Add that this
option is also honored by `org-indent-block'. Remove \\<org-mode-map>
since such forms serve for major mode documentation strings.
2024-01-29 16:50:53 +01:00
Ihor Radchenko 22050243b8
org-update-parent-todo-statistics: Use parser to match statistics cookie
* lisp/org.el (org-update-parent-todo-statistics): Ignore text
matching statistics cookie that is inside verbatim environments or
otherwise not detected by parser.  Leave a single exception for
headline properties for backwards compatibility.
2024-01-29 16:38:07 +01:00
Ihor Radchenko 522d7d0afe
org-odt-get-table-cell-styles: Fix reference to obsolete text property
* lisp/ox-odt.el (org-odt-get-table-cell-styles): Remove reference to
long-obsolete text property used to store table alignment info.
Instead, refer to table alignment cookies described in the manual.

Reported-by: Stefan Kangas <stefankangas@gmail.com>
Link: https://orgmode.org/list/CADwFkmnsjEg+d7ty0bjT5RGQiS-SdKcvRUy+KHDh+maa92bp1w@mail.gmail.com
2024-01-29 14:38:01 +01:00
Ihor Radchenko 107cbc74a9
ob-python: Set Python shell in Org edit buffer
* lisp/ob-python.el (org-babel-python-associate-session): New function
setting `python-shell-buffer-name' in *Org Src* buffer according to
source block's :session parameter.  This function will be triggered by
`org-src-associate-babel-session'.
* etc/ORG-NEWS (ob-python now sets ~python-shell-buffer-name~ in Org
edit buffers): Announce the change.

Co-authored-by: Liu Hui <liuhui1610@gmail.com>

Link: https://orgmode.org/list/CAOQTW-MdC=jiGf+3bEVtfww+izSZix7csBJ+mZ4eZ2BQHDR42w@mail.gmail.com
2024-01-29 14:29:45 +01:00
Pedro A. Aranda Gutierrez a4a880d1f9
org-latex-default-packages-alist: Refine packages for font management
* lisp/org.el (org-latex-default-packages-alist): Change to refine
font management depending on the latex compiler.

Differentiate between pdflatex and lualatex/xetex
packages for font management.  lualatex/xetex should use
fontspec instead of fontenc/inputenc.  When using
fontspec, you need to load amsmath before fontspec
and you don't need amssymb.
2024-01-29 14:26:30 +01:00
Detlef Steuer da2b61b09e lisp/ox-icalendar.el: Add time-to-live functionality to ox-icalendar
This commit adds functionality for ox-icalendar to set X-PUBLISHED-TTL
in the exported ICS, which advises a subscriber to the exported ICS
file to reload after the given time interval.

* lisp/ox-icalendar.el (org-icalendar-ttl): New option to set
X-PUBLISHED-TTL in exported ICS
(icalendar): Add ICAL-TTL export keyword
(org-icalendar--vcalendar): Add argument for TTL
(org-icalendar-template, org-icalendar-export-current-agenda,
org-icalendar--combine-files): Pass TTL to `org-icalendar--vcalendar'

Co-authored-by: Ihor Radchenko <yantar92@posteo.net>
Co-authored-by: Jack Kamm <jackkamm@gmail.com>
2024-01-28 13:45:41 -08:00
Ihor Radchenko e24ca9fa05
org-switch-to-buffer-other-window: Suppress compiler warning
* lisp/org-compat.el (org-switch-to-buffer-other-window): Suppress
compiler warning - we are using obsolete macro instead obsolete
function.  They will be removed together.
2024-01-28 20:08:53 +01:00
Ihor Radchenko 319563cef7
ob-R, ob-julia: Do not force-start session in Org Src buffers
* lisp/ob-R.el (org-babel-R-associate-session): Set
`ess-gen-proc-buffer-name-function' to associate the right session
buffer if user requests session interaction from inside Org Src edit
buffer.
(org-babel-edit-prep:R): Remove in favor of
`org-babel-R-associate-session'.
* lisp/ob-julia.el (org-babel-julia-associate-session): Implement
analogous functionality.
(org-babel-edit-prep:julia): Remove in favor of
`org-babel-julia-associate-session'.
* etc/ORG-NEWS (~org-edit-special~ no longer force-starts session in R
and Julia source blocks): Document the change.
* lisp/org-src.el (org-src-associate-babel-session): Run
org-babel-<lang>-associate-session even when session is not yet
initiated.

Link: https://orgmode.org/list/87r0ir2ln8.fsf@gmail.com
2024-01-28 20:04:31 +01:00
Ihor Radchenko 5e98599f50
lisp/org-table.el: Fix reference to non-existing function
* lisp/org-table.el (org-table--read-column-selection): Fix the
docstring, pointing to the right function that explains the format of
SELECT argument.

Reported-by: Stefan Kangas <stefankangas@gmail.com>
Link: https://orgmode.org/list/CADwFkmnsjEg+d7ty0bjT5RGQiS-SdKcvRUy+KHDh+maa92bp1w@mail.gmail.com
2024-01-28 14:50:30 +01:00
Matthew Trzcinski eacc9aa3ca doc/org-manual.org: Minor language fixes
* doc/org-manual.org (Property Syntax): Give article for "buffer
level" and "headline".  Fix plural confusion on "needs".  Change
"allowing" language; authors should only allow comments above buffer
level property blocks because Org requires it.
2024-01-28 12:31:54 +01:00
Ihor Radchenko ef23b4706b
org-babel-tangle: Do not allow tangling into self
* lisp/ob-tangle.el (org-babel-tangle): Throw an error when trying to
tangle into the org file we tangle from.
* etc/ORG-NEWS (It is no longer allowed to tangle into the same file
as Org source): Document the breaking change.
* testing/lisp/test-ob-tangle.el (ob-tangle/tangle-to-self): New test.
2024-01-26 16:54:04 +01:00
Ihor Radchenko 13bbe6743d
lisp/org-table.el (org-table-copy-down): Fix typo 2024-01-26 15:04:19 +01:00
Jack Kamm 44385f5bc4 lisp/ox-icalendar.el: Add Jack Kamm as maintainer
Link: https://list.orgmode.org/87fryllemw.fsf@localhost/T/#m1d51f9256be03ba0e77256c8442e0ce6776aff1e
2024-01-25 21:01:02 -08:00
Ihor Radchenko 19c90dd947
org-link-translation-function: Remove reference to removed function
* lisp/ol.el (org-link-translation-function): Remove reference to
no-longer-available `org-translate-link-from-planner' from the
docstring.

Reported-by: Stefan Kangas <stefankangas@gmail.com>
Link: https://orgmode.org/list/CADwFkmnsjEg+d7ty0bjT5RGQiS-SdKcvRUy+KHDh+maa92bp1w@mail.gmail.com
2024-01-25 15:22:22 +01:00
Ihor Radchenko 8ec89c53ca
ox-icalendar: Add support for multi-line SUMMARY, LOCATION, and DESCRIPTION
* lisp/ox-icalendar.el (org-icalendar-entry): Use `org-entry-get' to
account for both PROP and PROP+ in SUMMARY, LOCATION, and DESCRIPTION
properties.  Use newline as accumulated value separator.
* etc/ORG-NEWS (iCalendar export now supports multiline =SUMMARY=,
=LOCATION=, and =DESCRIPTION= properties): Announce the breaking
change.
* doc/org-manual.org (iCalendar Export): Add an example in the manual.

Reported-by: Hanno Perrey <hanno@hoowl.se>
Link: https://orgmode.org/list/87o821dv7o.fsf@localhost
2024-01-25 14:20:22 +01:00
Ihor Radchenko 46b9769a02
org-attach-store-link-p: Change default value to 'attached
* lisp/org-attach.el (org-attach-store-link-p): Change the default
value.
* etc/ORG-NEWS (The default value of ~org-attach-store-link-p~ is now
~attached~): Announce the change.
2024-01-25 13:59:58 +01:00
Ihor Radchenko ea529007d7
ox-html: Fix links to targets that do not have a number
* lisp/ox.el (org-export-get-ordinal): Return nil when ELEMENT does
not match PREDICATE.  `ox-html-link' expects this behavior when a link
refers to target that does not have a caption.
* testing/lisp/test-ox.el (test-org-export/get-ordinal): Fix tests.

Reported-by: gerard.vermeulen@posteo.net
Link: https://orgmode.org/list/7bf1f79071a714750634e76130fe5963@posteo.net
2024-01-25 13:30:35 +01:00
Ihor Radchenko d2986be076
lisp/org-lint.el (org-lint-named-result): Improve accuracy and message
Reported-by: gerard.vermeulen@posteo.net
Link: https://orgmode.org/list/b3dc0bd4368f3db0c7afe136d9f9ca97@posteo.net
2024-01-24 16:47:20 +01:00
Ihor Radchenko 228d6ccfcf
doc/org-manual.org (Repeated tasks): Clarify that all the timestamps are shifted
* doc/org-manual.org (Repeated tasks): Add a paragraph explaining that
marking task with repeaters DONE shifts all the timestamps with
repeater inside.
2024-01-24 15:13:55 +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
Ihor Radchenko b980f7abb8
lisp/org-tempo.el: Do not refer to removed function in the commentary
Reported-by: Stefan Kangas <stefankangas@gmail.com>
Link: https://orgmode.org/list/CADwFkmnsjEg+d7ty0bjT5RGQiS-SdKcvRUy+KHDh+maa92bp1w@mail.gmail.com
2024-01-24 13:24:14 +01:00
Ihor Radchenko 9ef18956bd
org-element: Allow more objects inside citations
* lisp/org-element.el (org-element-object-restrictions): Allow all but
citation, citation-reference, line-break, table-cell, link and
footnote-reference objects inside citations.

Reported-by: M. ‘quintus’ Gülker <post+orgmodeml@guelker.eu>
Link: https://orgmode.org/list/87tu425pla.fsf@guelker.eu
2024-01-24 12:27:15 +01:00
Ihor Radchenko 793cdbea68
fixup! org-fold: Honor :extend face property in folded headings/blocks/drawers 2024-01-22 16:27:06 +01:00
Ihor Radchenko 2ade16bbc2
org-fold: Honor :extend face property in folded headings/blocks/drawers
* lisp/org-fold-core.el (org-fold-core-region): When folding, when the
fold ends at a newline, copy 'face property from the beginning of the
fold, so that the trailing newline after ellipsis does not appear
with different face.  This fixes :extend t in headlines, blocks, and
drawers not being honored when the headlines are folded.

* etc/ORG-NEWS (Folded lines can now extend their face beyond
ellipsis): Announce the change.

Link: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=65896
2024-01-22 15:43:29 +01:00
Ihor Radchenko dd4fd02995
Allow per-buffer setting of org-link-descriptive via #+STARTUP options
* lisp/org.el (org-startup-options): Add new startup options to set
`org-link-descriptive'.
(org-mode): Move #+startup keyword parsing before setting up link
visibility.
* doc/org-manual.org (Link Format):
(Summary of In-Buffer Settings): Document the new startup option.
* etc/ORG-NEWS (~org-link-descriptive~ can now be set per-buffer via
=#+STARTUP= options): Announce the new feature.

Link: https://orgmode.org/list/87bkst1nfl.fsf@ucl.ac.uk
2024-01-22 13:58:30 +01:00
Ihor Radchenko 6dab5c317d
lisp/ox.el: Fix removed variable in the commentary
Reported-by: Stefan Kangas <stefankangas@gmail.com>
Link: https://orgmode.org/list/CADwFkmnsjEg+d7ty0bjT5RGQiS-SdKcvRUy+KHDh+maa92bp1w@mail.gmail.com
2024-01-22 12:25:04 +01:00
Ihor Radchenko 83696bf21f
org-export-activate-smart-quotes: Fix edge case with multiple secondary strings
* lisp/ox.el (org-export--smart-quote-status): Do not hash quote
status by parent syntax node - it will create clashes when parent has
multiple secondary strings.  Instead, hash by parent + secondary
string property.
* testing/lisp/test-ox.el (test-org-export/activate-smart-quotes): Add
new test case.

Reported-by: William Denton <william@williamdenton.org>
Link: https://orgmode.org/list/TarY7-tR4TEmIu8jawOtTyyi03K93WIg7DsS1eXNylelCy2Hv-6OFNKOMQMukf70Tzf3uO_2F1Qe7xwrzb43SpJc4jxJZLN3W0MioKYbgzI=@williamdenton.org
2024-01-21 13:44:50 +01:00
Ihor Radchenko ac1c72376c
org-open-at-point-global: Match multiline links
* lisp/org.el (org-open-at-point-global): Match multiline links
spanning up to a paragraph.

Reported-by: Omar Antolín Camarena <omar@matem.unam.mx>
Link: https://orgmode.org/list/87o7df7psx.fsf@localhost
2024-01-21 13:17:12 +01:00
Kyle Meyer 6e17ddd334 Merge branch 'bugfix' 2024-01-20 21:33:37 -05:00
Kyle Meyer de060c36d4 Merge branch 'km/from-emacs-29' into bugfix 2024-01-20 21:27:59 -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
Stefan Kangas 6e0fdd1714 Backport commit 6653ee66c from Emacs
* lisp/ox-latex.el (org-latex-src-block-backend)
(org-latex-engraved-theme): Improve docstring; mention that
engrave-faces is a GNU ELPA package.

Improve two docstrings in ox-latex
6653ee66ca5ebd42322613a09d4c0d2e35af924b
Stefan Kangas
Sun Jan 14 14:52:17 2024 +0100
2024-01-20 21:24:44 -05:00
Ihor Radchenko 037e3b3eb7
lisp/ob-tangle.el (org-babel-detangle): Improve docstring 2024-01-20 19:35:34 +01:00
Ihor Radchenko 4edb7d43ba
doc/org-manual.org (The Agenda Dispatcher): Remove obsolete convention
We should not advertise obsolete conventions in the manual.
2024-01-20 16:04:42 +01:00
Ihor Radchenko 92c53f23d3
org-get-outline-path: Drop COMMENT keywords from the outline path
* lisp/org.el (org--get-outline-path-1): Remove comment keyword from
title when current heading is commented.
* testing/lisp/test-org.el (test-org/get-outline-path): Add test.
2024-01-18 15:13:04 +01:00
Ihor Radchenko a19a72f7d3
org-agenda: Fix grid lines when `org-agenda-default-appointment-duration' is non-nil
* lisp/org-agenda.el (org-agenda-add-time-grid-maybe): Let-bind
`org-agenda-default-appointment-duration' to nil when formatting the
grid lines.  Otherwise, `org-agenda-format-item' logic fails to
produce the expected result.
* testing/lisp/test-org-agenda.el (test-org-agenda/time-grid): Add new
test set covering the bug and several simpler cases.
* testing/examples/agenda-file2.org (two): New test file example.

Reported-by: Detlef Steuer <steuer@hsu-hh.de>
Link: https://orgmode.org/list/87edv5fv1w.fsf@localhost
2024-01-17 15:40:24 +01:00
Ihor Radchenko 4ce2ad4eb1
lisp/org.el (org-agenda-files): Avoid duplicates
Duplicate entries in agenda files cause scanning the same file
twice, producing duplicates in the agenda.

Reported-by: Christopher M. Miles <numbchild@gmail.com>
Link: https://orgmode.org/list/65a75fd3.170a0220.be4f3.67c9@mx.google.com
2024-01-17 12:52:37 +01:00
José Miguel García Urrutia 490260ceb8
orgcard.tex: Allow correct rendering in PDF format and US letter page size
* doc/orgcard.tex: orgcard now can be printed as a triptych.  Shorten
titles to prevent overflows.

Link: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=64578

TINYCHANGE
2024-01-17 12:42:37 +01:00
Ihor Radchenko 2da9253e7d
doc/org-manual.org: Clarify context of evaluation code block references
* doc/org-manual.org (Noweb Reference Syntax):
(Passing arguments): Explain that referenced code block evaluation
happens with point at the referenced block.
2024-01-16 16:33:50 +01:00
Joseph Turner 0254854eea
lisp/ol.el (org-link-open): Use let-bound :follow function
TINYCHANGE
2024-01-16 14:38:43 +01:00
Ihor Radchenko 87da1ff15b
org-cite-basic-export-citation: Fix prefix/suffix being ignored
* lisp/oc-basic.el (org-cite-basic-export-citation): Honour prefix and
suffix in citation references and citations.
* testing/examples/Basic.bib: New example bibliography used by tests.
* testing/lisp/test-oc-basic.el:
(test-org-cite-basic/parse-bibliography):
(test-org-cite-basic/export-citation): New file, adding tests for
oc-basic processor.

Reported-by: William Denton <william@williamdenton.org>
Link: https://orgmode.org/list/FMaPNvYf_8jqVxcU2L5kgiMuejm0NqK3e9D7CzhSzG-fmESTZKgtAJy1LG_zNDLS6o_oQ-gF_G-6DXlXA2iQ_yAjNjLgeB86JTU46Sv8Wec=@williamdenton.org
2024-01-16 13:38:27 +01:00
Ihor Radchenko e6e8f0933a
org-cite-basic-export-citation: Fix suffix inside brackets (year suffix)
* lisp/oc-basic.el (org-cite-basic-export-citation): Fix formatting
citation reference with brackets.  When year is placed inside
brackets, put the reference suffix outside.
2024-01-16 13:36:18 +01:00
Ihor Radchenko d51723102a
lisp/ox-latex.el: Honor non-list value of `org-latex-caption-above'
* lisp/ox-latex.el (org-latex-generate-engraved-preamble):
(org-latex-latex-environment):  Use
`org-latex--caption-above-p' to query whether an element should have
its caption above.

Reported-by: Mads Bach Villadsen <mbvilladsen@pm.me>
Link: https://orgmode.org/list/m2zfx69uhb.fsf@pm.me
2024-01-16 12:33:01 +01:00
Matthew Trzcinski b79d9dd604 lisp/ob-shell.el: Remove unnecessary prompt template
(org-babel-shell-set-prompt-commands): "posh" is POSIX complaint and
uses PS1 and PS2 to define the shell prompt.  A separate template is
not needed.

Link: https://list.orgmode.org/18cfa388d12.f0069ffe919377.6846036599039377431@excalamus.com/
2024-01-15 20:57:20 +01:00
Ihor Radchenko 78754cdcff
doc/org-manual.org: Do not indent example python blocks
* doc/org-manual.org (Passing arguments):
(Type):
(Noweb Reference Syntax): Do not indent python block examples.  No
indentation should work across different user settings for
`org-src-preserve-indentation', not just for its default value.

Reported-by: Uwe Brauer
Link: https://orgmode.org/list/87o7dn9euy.fsf@mat.ucm.es
2024-01-15 14:17:06 +01:00
Ihor Radchenko 38c6eb2b72
ox-latex: Do not use float for inline images inside links
* lisp/ox.el (org-export-insert-image-links): Fix call to
`org-element-set-contents' - setting "nil" literally would put an
actual nil element into contents.
* lisp/ox-latex.el (org-latex--inline-image): Do not use float
environment unless the inline image is a single image inside
paragraph.  The code is adapted with simplifications from
`org-html-standalone-image-p'.
* testing/lisp/test-ox-latex.el (test-ox-latex/inline-image): New
test.

Reported-by: Dr. Arne Babenhauserheide <arne_bab@web.de>
Link: https://orgmode.org/list/878rest3qv.fsf@localhost
2024-01-15 13:52:43 +01:00
Ihor Radchenko 59238cfa82
doc/org-manual.org (Bibliography options...): Clarify biblatex vs. csl options
Make it more clear which options are accepted by biblatex processors
and which by csl.
2024-01-14 15:21:02 +01:00
Ihor Radchenko 25c786f0fb
Update version number for the 9.6.17 release 2024-01-14 12:50:34 +01:00
Ihor Radchenko 83f17091e6
doc/org-manual.org (Citations): Add clarification about default style 2024-01-13 20:04:14 +01:00
Ihor Radchenko 56f6d8d1ab
doc/org-manual.org: Fix description and example for #+CITE_EXPORT
* doc/org-manual.org (Citation export processors): Reword explanation
about #+CITE_EXPORT keyword.  Fix example.  Add template.
2024-01-13 20:04:06 +01:00
Ihor Radchenko c41a89676e
org-next-visible-heading: Fix when moving over non-descriptive link
* lisp/org.el (org-next-visible-heading): Really test for visibility;
not folding.  Some folds may not be invisible - when
`org-link-descriptive' is nil, links are folded yet visible.
* testing/lisp/test-org.el (test-org/next-visible-heading): Add new
test case.

Reported-by: Rudolf Adamkovič <salutis@me.com>
Link: https://orgmode.org/list/m2bk9q7adw.fsf@me.com
2024-01-13 13:35:52 +01:00
Ihor Radchenko 1aa4552e5c
org-indent-drawer, org-indent-block: Update docstring
* lisp/org.el (org-indent-drawer):
(org-indent-block): Document that an error is signaled when not at a
drawer/block.

Reported-by: gerard.vermeulen@posteo.net
Link: https://list.orgmode.org/orgmode/abc9e25cebcba21d941435e5f39e72d9@posteo.net/
2024-01-12 20:17:12 +01:00
Ihor Radchenko 77a1ddd39f
lisp/org-element-ast.el: Fix typos in top comment 2024-01-12 16:23:23 +01:00
Ihor Radchenko dda435773f
doc/org-manual.org (Citations): Add more examples 2024-01-12 15:32:34 +01:00
stardiviner dea7780d6d
org-fast-tag-selection: Limit the number of displayed tags
* lisp/org.el (org-fast-tag-selection): Do not print tags without
explicit bindings and tags outside groups when the number of displayed
tags exceeds new customization.
* lisp/org.el (org-fast-tag-selection-maximum-tags): Add new custom
option to set maximum tags number for fast tag selection.
(org--fast-tag-selection-keys): New internal variable holding keys
available for auto-assigning tag bindings.
* doc/org-manual.org (org-fast-tag-selection-maximum-tags): Add new
custom option documentation.
* etc/ORG-NEWS: Declare this new custom option.

Co-Authored-by: Ihor Radchenko <yantar92@posteo.net>
Link: https://list.orgmode.org/orgmode/CAL1eYuK7GUx_=47e8+N5Jh+ZJnDexY+CDMUjPjJHNmcMiVVRrQ@mail.gmail.com/
2024-01-12 12:58:46 +01:00
Ihor Radchenko 2708a63714
Merge branch 'bugfix' 2024-01-11 16:34:59 +01:00
Ihor Radchenko 4145ee4211
fixup! org-man-open: Fix shell expansion vulnerability (Emacs bug#66390)
The escaped string is not necessary "\\;id" on Windows/DOS.
2024-01-11 16:34:17 +01:00
Ihor Radchenko fad90df535
Revert "org-table-make-reference: Disable compiler warning"
This reverts commit bdc60fb936.

Apparently, the branch of if used sometimes and that sometimes is
covered by tests.  Strange.  Leave it be for now.
2024-01-11 15:45:09 +01:00
Ihor Radchenko bdc60fb936
org-table-make-reference: Disable compiler warning
* lisp/org-table.el (org-table-make-reference): Comment out the code
that always returns nil, replacing it with explicit nil.  This line is
certainly a fault in logic, but we do not know of any associated bugs.
So, just leave a FIXME to potential future refactoring and avoid the
compiler complaining about this code every time.
2024-01-11 14:18:35 +01:00
Ihor Radchenko d8b0c23d5c
Merge branch 'bugfix' 2024-01-11 14:15:48 +01:00
Ihor Radchenko 6b60b5ac12
fixup! org-man-open: Fix shell expansion vulnerability (Emacs bug#66390) 2024-01-11 14:15:19 +01:00
Ihor Radchenko 6592c766d2
org-agenda-bulk-mark: Fix mark not being visible when column view is active
* lisp/org-agenda.el (org-agenda-bulk-mark): Use 'before-string in the
mark overlay to make sure that higher-priority Org agenda columns
overlay is not making the mark completely invisible.

Link: https://old.reddit.com/r/orgmode/comments/13jbjep/is_it_possible_to_show_a_selection_mark_in/
2024-01-11 14:12:32 +01:00
Ihor Radchenko 78c1a0f383
doc/org-manual.org (Citation handling): Add index entries
* doc/org-manual.org (Citation handling):
(Citations):
(Citation export processors):
(Bibliography printing): Add variables and keywords to variable index
and concept index.
2024-01-11 13:21:08 +01:00
Ihor Radchenko 8f7efd9d7d
Merge branch 'bugfix' 2024-01-11 13:06:31 +01:00
Ihor Radchenko bc3caa8f90
org-man-open: Fix shell expansion vulnerability (Emacs bug#66390)
* lisp/ol-man.el (org-man-open): Work around Emacs bug#66390.
Implement fix on org side before Emacs commit that fixes the bug.

Link: https://yhetil.org/emacs-bugs/CADwFkmnTMsOM+z0x8FGPGguMtoD9hLrNt9YfbaJ08KPNKW3EbQ@mail.gmail.com/
2024-01-11 13:04:23 +01:00
Ihor Radchenko f6e3b1a805
doc/org-manual.org (Org Syntax): Update reference to syntax document
Also, update information about the maintainer.  The latest version has
been rewritten by Tecosaur.
2024-01-10 16:22:05 +01:00
Ihor Radchenko f22be2878f
org-agenda: Fix hard-coded day lengths when calculating timestamp regexp
* lisp/org-agenda.el (org-agenda-get-timestamps):
(org-agenda-get-progress): Do not assume that all the timestamps have
length of exactly 12 (English).  Use options argument for
`org-time-stamp-format' instead to drop brackets from the timestamp.
2024-01-10 16:07:11 +01:00
Ihor Radchenko d0a917ab23
org-agenda-get-progress: Fix detecting time when todo keyword contains ]
* lisp/org-agenda.el (org-agenda-get-progress): Improve accuracy
matching time inside state note.

The old code failed to match time in
- State "[X]"        from "[ ]"        [2022-10-25 Tue 10:00]

Link: https://old.reddit.com/r/orgmode/comments/ycshlg/orgagendalogmode_does_not_display_time_for/
2024-01-10 16:07:06 +01:00
Ihor Radchenko f9702a09e7
org-fold: Fix edge case when revealing fragile folds breaks some Emacs commands
* lisp/org-fold-core.el (org-fold-core--fix-folded-region): Delay
revealing fragile regions to until the current command is executed.
(org-fold-core--region-delayed): New function to postpone folding to
the time when `post-command-hook' is executed.
(org-fold-core--region-delayed-list): New internal variable holding
delayed fold requests.
(org-fold-core--process-delayed): New function to be used to process
the delayed folds and cleanup `post-command-hook'.
*
testing/lisp/test-org-fold.el (test-org-fold/org-fold-reveal-broken-structure):
Update tests to account for the delayed unfolding.

Reported-by: Sebastian Miele <iota@whxvd.name>
Link: https://orgmode.org/list/875y04yq9s.fsf@localhost
2024-01-09 16:42:42 +01:00
Ihor Radchenko c9e5270bf1
lisp/org.el (org-self-insert-command): Do not skip fragility checks
* lisp/org-fold-core.el (org-fold-core--suppress-folding-fix):
(org-fold-core-suppress-folding-fix): New macro suppressing re-folding
checks.
(org-fold-core--fix-folded-region): Skip re-folding checks when
`org-fold-core--suppress-folding-fix' is non-nil.
* lisp/org.el (org-self-insert-command): Use
`org-fold-core-suppress-folding-fix' to bypass re-folding checks, but
not fragility checks.
*
testing/lisp/test-org-fold.el (test-org-fold/org-fold-reveal-broken-structure):
New test.
2024-01-09 16:40:22 +01:00
Ihor Radchenko 0773f4980c
org-cycle: Throw an error when `org-cycle-max-level' is not positive
* lisp/org-cycle.el (org-cycle): Avoid cryptic regexp error when
`org-cycle-max-level' is not set to positive integer.

Reported-by: Alain.Cochard@unistra.fr
Link: https://orgmode.org/list/25496.14797.512207.593382@gargle.gargle.HOWL
2024-01-09 15:25:50 +01:00
Ihor Radchenko 97951352bb
Fix [[* completion when there is text after point
* lisp/org-pcomplete.el (org-parse-arguments): Parse text between [[*
and point as a single "argument" for pcomplete.  This avoid weird
breakage when treating every space-separated text in the line as an
argument.
(pcomplete/org-mode/searchhead): Do not alter `pcomplete-stub' - it is
no longer necessary as `org-parse-arguments' now takes care about not
including * and ] into the stub.

Warning! pcomplete code is rather tricky and it is not always clear if
Org's approach is not overusing internals of pcomplete.

Reported-by: Ignacio Casso <ignaciocasso@hotmail.com>
Link: https://orgmode.org/list/87ils0lut8.fsf@localhost
2024-01-07 16:50:40 +01:00
Ihor Radchenko 804d032685
Update version number for the 9.6.16 release 2024-01-07 12:25:20 +01:00
Kyle Meyer aab2c94531 Update copyright years for main-only files 2024-01-06 16:06:47 -05:00
Kyle Meyer 72a2db86d9 Merge branch 'bugfix' 2024-01-06 16:02:02 -05:00
Kyle Meyer 1666eeef55 Update remaining copyright years
Most copyright years were updated with the port of Emacs's 8e1c56ae4
in 9f1d6dfd7.  Update the remaining copyright years for files that
have Free Software Foundation as the copyright holder but aren't
included in the Emacs repo.
2024-01-06 15:55:18 -05:00
Kyle Meyer 54acceb971 Merge branch 'km/from-emacs-29' into bugfix 2024-01-06 15:52:07 -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 fa198cbbe4
org-agenda-search-headline-for-time: Ignore all the timestamps in headings
* lisp/org-agenda.el (org-agenda-format-item): When
`org-agenda-search-headline-for-time' is non-nil, exclude timestamps
in headings from searching the time.
(org-agenda-search-headline-for-time): Remove warning about timestamps
in headings from the docstring.
* etc/ORG-NEWS (~org-agenda-search-headline-for-time~ now ignores all
the timestamp in headings): Announce the change.

Reported-by: rameiko87@posteo.net
Link: https://orgmode.org/list/dc5c0aa3748f5d7ad8b79bea674266e7@posteo.net
2024-01-06 13:29:43 +01:00
Ihor Radchenko b6643884cb
ob-R, ob-julia: Use `ess-gen-proc-buffer-name-function' to control session buffer name
* lisp/ob-R.el (org-babel-R-initiate-session):
* lisp/ob-julia.el (org-babel-julia-initiate-session): Do not use the
hack with renaming ESS buffer and instead indicate the session buffer
name to ESS appropriately through `ess-gen-proc-buffer-name-function'.

Link: https://orgmode.org/list/871qb21bp7.fsf@gmail.com
2024-01-05 14:56:21 +01:00
Ihor Radchenko c10a079a2c
org-edit-src-code: Setup Org Src buffer context before running `org-src-mode-hook'
* lisp/org-src.el (org-edit-src-code): Make sure that
`org-coderef-label-format' and `org-src--babel-info' are set before
`org-src-mode-hook' is executed.  Earlier,
`org-src-babel-configure-edit-buffer' that is by default present in
the hook would do nothing as it relies upon `org-src--babel-info'
being set.
2024-01-05 14:33:42 +01:00
Ihor Radchenko b4687fcd69
Revert "lisp/org-src.el: Suppress compiler warnings for obsolete code"
This reverts commit 3b71939903.
2024-01-05 14:31:31 +01:00
Ihor Radchenko 99c9cae25c
Revert "Obsolete `org-src-associate-babel-session' and related functionality"
This reverts commit 7926045ff5.

`org-src-associate-babel-session' is still useful because:

1. It indicates the need to implement session association to babel
   backend (although we still need to make it more clear for backend
   authors in future).

2. It provides infrastructure for more granular control over session
   association for third-party packages.  For example, we might want
   to disabled session association when it can cause unwanted side
   effects, like starting comint process unconditionally (looking at
   ob-R and other ess-based backends).
2024-01-05 14:20:14 +01:00
Ihor Radchenko aeebac3780
lisp/org-id.el: Fix inaccuracy in the commentary
Reported-by: Stephen J. Eglen <sje30@cam.ac.uk>
Link: https://orgmode.org/list/m234vceq40.fsf@cam.ac.uk
2024-01-05 13:31:27 +01:00
Ihor Radchenko d8586fb601
Remove mentions of semi-obsolete `org-tags-match-list-sublevels' from manuals
* doc/org-guide.org (Tag searches):
* doc/org-manual.org (Tag Inheritance):
(Tag Searches):
(Property Searches):
(Matching tags and properties): Do not link
`org-tags-match-list-sublevels' customization.  We declare it
semi-obsolete, so the manual and the guide should not encourage using
it.
2024-01-04 16:50:49 +01:00
Nafiz Islam a27a1b87b5
lisp/org-agenda.el (org-todo-list): Rename variables and format
* lisp/org/org-agenda.el
(org-todo-list): Use `org-today' directly for `calendar-gregorian-from-absolute'.
(org-todo-list): Replace `date' with `today' (`date' is no longer used).
(org-todo-list): Replace `kwds' with `todo-keywords'.
(org-todo-list): Replace `rtn' with `todo-entries'.
(org-todo-list): Replace `rtnall' with `all-todo-entries'.
(org-todo-list): Replace some `and' with `when' and `cond'.
(org-todo-list): Some whitespace changes.

TINYCHANGE
2024-01-04 16:00:07 +01:00
Ihor Radchenko 6d1c1721e3
Merge branch 'bugfix' 2024-01-04 15:15:18 +01:00
Ihor Radchenko 4279b84a1f
org-lint-invalid-cite-export-declaration: Do not warn about not-yet-loaded processors
* lisp/org-lint.el (org-lint-invalid-cite-export-declaration): Fix
false-positive warning when cite processor is not yet loaded.

Reported-by: gerard.vermeulen@posteo.net
Link: https://orgmode.org/list/a142147a781384402547d49859fa3287@posteo.net
2024-01-04 15:14:19 +01:00
Ihor Radchenko d6117f895c
org-element-cache: Provide Elisp API to store user data inside the cache
* lisp/org-element.el (org-element-cache-store-key):
(org-element-cache-get-key): New functions to store and retrieve data
associated with cached nodes.  The data is stored inside
:fragile-cache and :robust-cache node properties.
(org-element--cache-shift-positions): Clear :fragile-cache when the
contents boundaries are changed.  Optimize when OFFSET is 0.
* lisp/org-element.el (org-element--cache-process-request): Call
`org-element--cache-shift-positions' even for 0 offset to account for
:fragile-cache.
* etc/ORG-NEWS (New API functions to store data within
~org-element-cache~): Announce the new API.
* testing/lisp/test-org-element.el (test-org-element/cache-get-key):
New test.
2024-01-04 14:23:08 +01:00
Alexandre Avanian 3aac00e45d
lisp/org-indent.el: Add hook to run after it initializes a buffer
* lisp/org-indent.el (org-indent-initialize-buffer): Define and call
hook after it initializes a buffer.
* etc/ORG-NEWS: Announce new custom option.

This will allow to enrich org-indent properties without requiring
hacks to detect initialization.
See https://list.orgmode.org/orgmode/5f4cdb77-8f43-4f2d-91a7-bc4ce57df8ad@app.fastmail.com/#r

TINYCHANGE
2024-01-03 16:34:59 +01:00
Ihor Radchenko dfeff03c5a
lisp/org-element-ast.el (org-element-copy): Fix altering source element
* testing/lisp/test-org-element.el (test-org-element/copy): Add new
test case.

Reported-by: gerard.vermeulen@posteo.net
Link: https://orgmode.org/list/e0252d664af25728243734d67432ad64@posteo.net
2024-01-03 15:57:01 +01:00
Jack Kamm d57d3bd9bb ob-python: Remove :version from variables with :package-version 2023-12-31 10:32:55 -08:00
Jack Kamm 9239b0e8d1 ob-python: Changed options for default Python command
ob-python will now use the same settings as `run-python' when starting
interactive sessions, by default.

* lisp/ob-python.el (org-babel-python-command): Changed to have
additional `auto' option, which is the new default value.
(org-babel-python-command-session): New option to control default
session Python command.
(org-babel-python-command-nonsession): New option to control default
nonsession Python command.
(org-babel-python--command): New function to determine the command to
run Python.
(org-babel-python-initiate-session-by-key): Call `run-python' without
CMD arg.  Instead, set `python-shell-interpreter' and
`python-shell-interpreter-args' from `org-babel-python--command' when
needed.
(org-babel-python-evaluate-external-process): Use
`org-babel-python--command' to start Python.
2023-12-31 08:29:20 -08:00
Ihor Radchenko 478b40d99e
Update version number for the 9.6.15 release 2023-12-31 12:59:12 +01:00
Kyle Meyer f348adce0d Merge branch 'km/from-emacs-29' into bugfix 2023-12-30 22:34:57 -05:00
Stefan Kangas 38ccb77196 Backport commit 55555a6a0 from Emacs
* lisp/org-protocol.el: Minor copy-edits to Commentary.

org-protocol: Minor copy-edits to Commentary
55555a6a0d1d76468f8327972b3cb067b9e35f24
Stefan Kangas
Sat Dec 30 17:53:53 2023 +0100
2023-12-30 22:33:14 -05:00
Jack Kamm d526ab5388 fixup! ob-python: Test and improve robustness for externally started python
*
lisp/ob-python.el (org-babel-python--python-util-comint-end-of-output-p):
Backport python-util-comint-end-of-output-p for emacs28.
(org-babel-python-initiate-session-by-key): Use backported version of
python-util-comint-end-of-output-p.
2023-12-29 08:44:17 -08:00
Jack Kamm d0d838b02e ob-python: Test and improve robustness for externally started python
* lisp/ob-python.el (org-babel-python-initiate-session-by-key): Wait
for first prompt for pre-existing python processes.  Document behavior
for pre-existing python processes.
(org-babel-python-initiate-session): Document behavior for
pre-existing python processes.
*
testing/lisp/test-ob-python.el (test-ob-python/session-with-existing-inferior-python):
New test for working with existing python processes.
2023-12-29 07:46:49 -08:00
Ihor Radchenko 996441fd56
lisp/ox-odt.el: Do not alter `auto-mode-alist'
Reported-by: Peter Prevos <peter@prevos.net>
Link: https://orgmode.org/list/87wmtoosru.fsf@prevos.net
2023-12-29 16:33:54 +01:00
Ihor Radchenko 69e746c1e4
lisp/ox-odt.el: Do not open the generated exported file in the background
* lisp/ox-odt.el (org-odt--export-wrap): Do not open the exported file
in the background.  Such behavior is not consistent with the other
export backends and is not documented (users don't know about it).
* etc/ORG-NEWS (ODT export no longer opens the exported file in the
background): Document the breaking change.
2023-12-29 16:33:54 +01:00
Ihor Radchenko d15e52fef4
org-element: Distinguish between [[/path/to]] and [[file:/path/to]] links
* lisp/org-element.el (org-element-link-parser): Record information
whether link type: is implicit or explicitly provided in the input
text.  The information is saved into new link object property
`:type-explicit-p'.
(org-element-link-interpreter): Take into account `:type-explicit-p'
when interpreting link object.
(org-element-cache-version): Bump AST version.
* testing/lisp/test-org-element.el (test-org-element/link-interpreter):
Add new test.

Reported-by: Joseph Turner <joseph@ushin.org>
Link: https://orgmode.org/list/87o7e9ei3p.fsf@ushin.org
2023-12-29 15:44:10 +01:00
Justin Vallon 684aff8eeb
org-persist--gc-orphan-p: Fix Emacs 26.1 compatibility
* lisp/org-compat: Add org-assoc-delete-all from compat/compat-27.el.
* lisp/org-persist.el (org-persist--gc-orphan-p): Use
org-assoc-delete-all.

TINYCHANGE
2023-12-28 23:57:02 +01: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
Pedro A. Aranda 5092ecd46a
Reword biblatex documentation 2023-12-27 14:49:05 +01:00
Ihor Radchenko 60f357e8bf
doc/org-manual.org: Clarify that inline code blocks cannot be named
* doc/org-manual.org (Structure of Code Blocks):
2023-12-26 16:36:51 +01:00
Ihor Radchenko 5185339fe6
Merge branch 'bugfix' 2023-12-25 19:57:41 +01:00
Ihor Radchenko 4ad7ae2520
lisp/org-element-ast.el: Add a comment why no `org-element-properties' 2023-12-25 15:56: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 3afae6690f
org-element-with-buffer-copy, org-export-with-buffer-copy: Fix expansion
* lisp/org-element.el (org-element-with-buffer-copy):
* lisp/ox.el (org-export-with-buffer-copy): Make sure that keyword
arguments in the macro are not duplicated into BODY, which happens for
&rest body + &allow-other-keys in `cl-defmacro'.

Reported-by: João Távora <joaotavora@gmail.com>
Link: https://yhetil.org/emacs-devel/CALDnm53p7nXdnbA2PuH-VHL7EeGQUXYy3x_87hp3oj2pkyWS9Q@mail.gmail.com/
2023-12-25 15:50:04 +01:00
Ihor Radchenko f59ac10257
lisp/org-clock.el: Improve some docstrings
* lisp/org-clock.el (org-clock-save-markers-for-cut-and-paste):
(org-clock-select-task):
2023-12-25 10:42:33 +01:00
Pedro A. Aranda a2b09e4aa6
org-manual.org: Add comment on the biblatex bibliography exporter
* doc/org-manual.org (Citation export processors): Provide an example
for enabling biblatex processor with biber backend.
2023-12-24 18:46:07 +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 e9ae9dbc54
org-lint.el: Add linter checking for independent keywords prior affiliated
* lisp/org-lint.el (org-lint-regular-keyword-before-affiliated):
(combining-keywords-with-affiliated):

Link: https://orgmode.org/list/87ilpj9lv1.fsf@localhost
2023-12-24 12:43:26 +01:00
Ihor Radchenko b8b02e3da3
org-lint: New linter for named results of evaluation
* lisp/org-lint.el (org-lint-named-result):
(named-result):

Link: https://orgmode.org/list/87ilpj9lv1.fsf@localhost
2023-12-24 12:35:34 +01:00
Ihor Radchenko 52a836b40d
lisp/oc-basic.el (org-element-contents): Add missing declare 2023-12-24 12:24:06 +01:00
Ihor Radchenko cee9b6abc6
Revert "lisp/oc.el (org-cite-parse-elements): Use org-mode buffer for parsing"
This reverts commit 36f61a9c8b.

Because of complex dependencies, it is not easy to properly "require"
`org-element-with-buffer-copy' in oc.el.  So, reverting for now.
2023-12-24 12:18:52 +01:00
Ihor Radchenko a64b779cbe
Merge branch 'bugfix' 2023-12-24 12:16:31 +01:00
Morgan Smith 086752fb33
doc/org-manual.org: Fix typo
doc/org-manual.org: 'org-hierarchical-checkbox-statistics' ->
'org-checkbox-hierarchical-statistics'
2023-12-24 12:16:03 +01:00
Morgan Smith 11e16e5f9e
lisp/org-agenda.el: Check agenda type earlier
lisp/org-agenda.el (org-agenda-goto-date): Check agenda type earlier.
Also remove redundant error.

When this function is run on a todo agenda the user is given the
undescriptive error "(wrong-type-argument listp "todo")" because we
attempt to parse the 'org-last-args text-property prematurely.  With
this change users will get the much better error "Not allowed in
'todo'-type agenda buffer or component".
2023-12-24 12:11:16 +01:00
Ihor Radchenko 7440911e49
Merge branch 'bugfix' 2023-12-24 11:58:52 +01:00
Sébastien Miquel f280b2178c lisp/ob-python.el (org-babel-python-table-or-string): Small fix
Check for empty results.
2023-12-23 21:19:54 +01:00
Ihor Radchenko 539728840f
ox-latex: Fix exporting longtable with multiline header
* lisp/ox-latex.el (org-latex-table-row): Use all the rows when
constructing header definition.
* testing/lisp/test-ox-latex.el (test-ox-latex/longtable): Add new
test.

Reported-by: Brett Presnell <presnell@member.fsf.org>
Link: https://orgmode.org/list/87mt9zywco.fsf@localhost
2023-12-23 12:03:36 +01:00
Ihor Radchenko 872c1b99fb
Merge branch 'bugfix' 2023-12-22 12:22:41 +01:00
Karthik Chikmagalur 6011e7a489
org: Add image alignment
* lisp/org.el (org-image--align, org-image-align,
org-toggle-inline-images): Add the ability to left-align, center
or right-align inline image previews in the Emacs window. This is
controlled globally using the new user option `org-image-align'.
Alignment can be specified per image using the `#+ATTR.*'
affiliated keywords.  The function `org-image--align' determines
the kind of alignment for its argument link.

* lisp/org-lint.el (org-lint-invalid-image-alignment): Add an
org-lint checker to catch invalid ":align" and ":center"
attributes in `#+attr_org' keywords.

* doc/org-manual.org: Document the new feature under the Images
section.
2023-12-21 14:38:06 +01:00
Ihor Radchenko e6bfe3caa8
lisp/org-persist.el: Honor org-persist--disable-when-emacs-Q for gc-lock
Do not run `org-persist--refresh-gc-lock-timer' for emacs -Q.
2023-12-21 11:40:00 +01:00
Ihor Radchenko e469636a6d
org-element-plain-list-interpreter: Do not run mode hooks
* lisp/org-element.el (org-element-plain-list-interpreter): Use
`org-element-with-buffer-copy' and make sure that we do not run user
hooks.  User hooks are often not designed to work in temporary
buffers.  The changed approach also follows similar code elsewhere in
Org code.
2023-12-21 11:39:59 +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 e3abcdbf01
lisp/oc-csl.el: Fix some checkdoc warnings
* lisp/oc-csl.el (org-cite-csl-latex-label-separator): Make first line
of the docstring full sentence.  Fix double space between sentences.
(org-cite-csl--create-structure-params): re-fill.
(org-cite-csl--no-citelinks-p): Document the function arguments.
2023-12-19 12:03:16 +01:00
Ihor Radchenko 41726d408b
lisp/oc-basic.el (org-cite-basic--shorten-names): Fix typo
Use normalized NAMES-STRING to shorten names.

Reported-by: William Denton <wtd@pobox.com>
Link: https://orgmode.org/list/alpine.DEB.2.22.394.2312181114040.123851@shell3.miskatonic.org
2023-12-18 18:13:15 +01:00
Ihor Radchenko 1d72973efa
org-clock-history-push: Improve docstring. Raise error for illegal args
* lisp/org-clock.el (org-clock-history-push): Document all the
function arguments.  Throw an error when BUFFER is provided, but POS
is not.
2023-12-18 11:37:35 +01:00
Ihor Radchenko 5a5ec1b320
lisp/org-persist.el: Do not GC orphan files when another Emacs is running
* lisp/org-persist.el (org-persist-gc-lock-file): New constant naming
the lock file to store active sessions in.
(org-persist-gc-lock-interval): New variable defining session lock
refresh frequency.
(org-persist-gc-lock-expiry): New variable defining which sessions are
considered expired.
(org-persist--refresh-gc-lock): New function refreshing session
timestamp in `org-persist-gc-lock-file'.
(org-persist--gc-orphan-p): New function checking whether orphan files
should be garbage collected.
(org-persist-gc): Use `org-persist--gc-orphan-p'.
(org-persist--refresh-gc-lock-timer): New variable holding timer
refreshing GC lock file.  Run the timer every
`org-persist-gc-lock-interval'.

This patch prevents files created in the other running Emacs sessions
from being garbage-collected.
2023-12-18 11:32:54 +01:00
Ihor Radchenko 2df9642f1d
lisp/ob-maxima.el (org-babel-header-args:maxima): Fix value
The value should be a lists, as in
`org-babel-common-header-args-w-values'.

Reported-by: gerard.vermeulen@posteo.net
Link: https://orgmode.org/list/3e1e1479365794e2cb3b6d1979e6c98c@posteo.net
2023-12-17 21:03:25 +01:00
Ihor Radchenko 92fec81e2e
lisp/org.el (org-sort-entries): Fix sorting partially selected subtree
* lisp/org.el (org-sort-entries): Make sure that we extend sorted
region to the full subtree if it spans beyond end of region.
* testing/lisp/test-org.el (test-org/sort-entries): Add test.
2023-12-17 14:58:44 +01:00
Ihor Radchenko 67ce9386ad
lisp/org.el (org-sort-entries): Fix when end of region is not a bol
* lisp/org.el (org-sort-entries): Avoid putting a heading not at bol
when end of selected region is not at bol.

Reported-by: Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>
Link: https://orgmode.org/list/8d637a8a-6cbc-4158-bded-f9182716a1fc@posteo.de
2023-12-17 14:57:11 +01:00
Ihor Radchenko bf1d45f9ba
org-lint: Remove checker for #+name with colon
* lisp/org-lint.el (org-lint-colon-in-name):
(colon-in-name): Remove the checker.  It is no longer a problem after
b5cfc311d that allows referring to named elements with name containing
colon.
* testing/lisp/test-org-lint.el (test-org-lint/colon-in-name): Remove
test.
2023-12-17 14:57:03 +01:00
Ihor Radchenko de9f1169d2
lisp/org-element.el (org-src-preserve-indentation-p): Fix declare form 2023-12-16 18:42:23 +01:00
Ihor Radchenko d2ce1c6ec1
lisp/ox-texinfo.el: Fix @menu in headlines without contents
* lisp/ox-texinfo.el (org-texinfo--normalize-headlines): Do not rely
upon undocumented implementation side-effects in `org-element-create'
that have been changed.

*
testing/lisp/test-ox-texinfo.el (test-ox-texinfo/normalize-headlines):
New test.

Reported-by: Jonas Bernoulli <jonas@bernoul.li>
Link: https://orgmode.org/list/87zfybnqwf.fsf@bernoul.li
2023-12-16 15:10:29 +01:00
Ihor Radchenko 8fd21d04ce
lisp/ob-sqlite.el (org-babel-sqlite-table-or-scalar): Improve docstring 2023-12-16 12:47:54 +01:00
Ihor Radchenko 31caf84bb7
lisp/oc-basic.el (org-cite-basic--shorten-names): Fix NAMES being raw pseudo-object
NAMES-STRING should be a string, while `org-element-contents' returns
a list.

Reported-by: William Denton <wtd@pobox.com>
Link: https://orgmode.org/list/alpine.DEB.2.22.394.2312150948490.84946@shell3.miskatonic.org
2023-12-15 16:06:43 +01:00
Ihor Radchenko 15cf8c3fcd
Merge branch 'bugfix' 2023-12-15 15:02:45 +01:00
Ihor Radchenko 63ef7b9242
org-lint-wrong-include-link-parameter: Ignore narrowing when verifying
It is implied that we ignore narrowing when searching for included
part .  But `org-link-search' does not.  Widen the included before
around its call.
2023-12-15 13:52:59 +01:00
Ihor Radchenko cb71bde7cb
lisp/org-macro.el (org-macro--get-property): Ignore narrowing
It is implied that we ignore narrowing when searching for property
value.  But `org-link-search' does not.  Widen around its call.
2023-12-15 13:52:07 +01:00
Ihor Radchenko 5c543cd9d9
lisp/ol.el (org-link-search): Clarify that narrowing is respected 2023-12-15 13:46:42 +01:00
Ihor Radchenko 89164e6054
lisp/ol.el (org-store-link): Use non-obsolete variable name in docstring 2023-12-15 13:45:48 +01:00
Ihor Radchenko 23291840b2
org-clock-auto-clockout: Honor system idle time. Do not spawn multiple timers
* lisp/org-clock.el (org-clock--auto-clockout-timer-obj): New internal
variable holding the auto-clockout timer.
(org-clock--auto-clockout-maybe): New function to be used in timer.
Use `org-user-idle-seconds' to check for idleness.  Make sure that we
correctly handle system idle time, which may be lesser than Emacs idle
time.
(org-clock-auto-clockout): Do not create duplicate timers.  Use the
new internal helper function.

Reported-by: Vladimir Nikishkin <lockywolf@gmail.com>
Link: https://orgmode.org/list/87ttqv6l2g.fsf@laptop.lockywolf.net
2023-12-15 12:26:44 +01:00
Ihor Radchenko 3be87f15d5
lisp/ol-man.el (Man-completion-cache): Declare variable 2023-12-15 12:25:35 +01:00
Ihor Radchenko fbcd71e856
org-babel-tangle: Do note erase the existing tangle target before overwriting
* lisp/ob-tangle.el (org-babel-tangle): Do not remove the existing
tangle target file, if any.  `write-region' later will overwrite it
anyway, while removing may be unexpected if the existing target is a
symlink.

Reported-by: Cletip Cletip <clement020302@gmail.com>
Link: https://list.orgmode.org/orgmode/CAPHku6O9NfVMAfmE3_ahmpJea_2Qm0mJMFX6qPpT8uiQ94KMZA@mail.gmail.com/
2023-12-15 12:23:22 +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
Max Nikulin b8d27bb4ec
ol-man.el: Mark WoMan link handler as obsolete
lisp/ol-man.el (org-man-command): Add label suggesting against
the WoMan package as a viewer for man pages.  It has enough bugs.

Eli Zaretskii to emacs-orgmode. Re: Completion of links to man pages.
Thu, 05 Oct 2023 19:33:26 +0300.
<https://list.orgmode.org/orgmode/83sf6p2fgu.fsf@gnu.org>
2023-12-14 16:02:25 +01:00
Max Nikulin 7c9a5216bb
ol-man.el: Enable completion
* lisp/ol-man.el (org-man-complete): New function implementing
completion for man pages using `Man-completion-table'.  Set this
function as the `:complete' property of "man" links.

Ihor Radchenko. Re: Completion of links to man pages.
Sat, 09 Dec 2023 11:32:39 +0000.
<https://list.orgmode.org/877clnsjag.fsf@localhost>
2023-12-14 16:02:24 +01:00
Ihor Radchenko d6c392b020
lisp/org-refile.el (org-refile-marker): Update docstring
Document the header argument and what "caching" means.
2023-12-14 14:11:50 +01:00
Ihor Radchenko 7c4a02f868
lisp/ox-ascii.el (org-ascii-format-inlinetask-default): Fix checkdoc warning 2023-12-13 15:47:11 +01:00
Ihor Radchenko b9778ed5ad
Merge branch 'bugfix' 2023-12-12 16:15:08 +01:00
Kenny Ballou ac8b925407
lisp/org-capture.el: use `org-store-link' for %K values
* org-capture.el (org-capture-fill-template): fill %K values using link
value from `org-store-link', which respects `org-id-link-to-use-id'.
* doc/ORG-NEWS: (Template variable expansion %K) Document new behavior.

Reported-by: Nathaniel W Griswold <nate@manicmind.earth>
Signed-off-by: Kenny Ballou <kb@devnulllabs.io>
Link: https://list.orgmode.org/EF459D47-FCA4-4A18-AFC7-3E62159F186C@manicmind.earth/

TINYCHANGE
2023-12-12 13:43:03 +01:00
Ihor Radchenko 676f46b7e2
lisp/ox-beamer.el (org-beamer-bold): Fix typo in the docstring 2023-12-12 13:01:39 +01:00
Ihor Radchenko 7505055f58
org-agenda-to-appt: Do not hard-code not-done todo keywords
* lisp/org-agenda.el (org-agenda-to-appt): Use org-todo-regexp and
org-not-done-regexp to determine whether an even is already done.

Reported-by: Raffael Stocker <r.stocker@mnet-mail.de>
Link: https://orgmode.org/list/yplmsf4ac6va.fsf@mnet-mail.de
2023-12-12 12:55:11 +01:00
Ihor Radchenko 420ed4e033
lisp/org.el (org-skip-over-state-notes): Improve docstring 2023-12-11 14:47:02 +01:00
Ihor Radchenko 0c4358b4ac
lisp/ox-html.el: Fix some checkdoc warnings
* lisp/ox-html.el (org-html-format-list-item): Document some function
arguments.
(org-html--latex-environment-numbered-p): Suppress checkdoc heuristics.
(org-html-image-link-filter): Add docstring.
(org-html-table--table.el-table):
(org-html-final-function):  Document the function arguments.
2023-12-11 12:59:27 +01:00
Rudolf Adamkovič 664ffde149
org-link: Improve UX of 'org-insert-link'
* lisp/ol.el (org-insert-link): Shorten the text in the *Org Links*
buffer to avoid unnecessary line breaks, reword it to better align
with the rest of Emacs, and propertize its key bindings to improve
readability.  Further, move the default link to the minibuffer, as
seen elsewhere in Emacs, and make the *Org Links* buffer read-only.
2023-12-11 12:28:32 +01:00
Visuwesh b77f991c02
Add support for yank-media and DND
* lisp/org.el (org-mode): Call the setup function for yank-media and
DND.
(org-setup-yank-dnd-handlers): Register yank-media-handler and DND
handler.
(org-yank-image-save-method, org-yank-image-file-name-function)
(org-yank-dnd-method, org-yank-dnd-default-attach-method): New
defcustoms.
(org--image-yank-media-handler, org--copied-files-yank-media-handler)
(org--dnd-rmc, org--dnd-multi-local-file-handler)
(org--dnd-local-file-handler, org--dnd-attach-file, org--dnd-xds-method)
(org--dnd-xds-function): Add yank-media and DND handlers.

* doc/org-manual.org: (Drag and Drop & ~yank-media~): Describe the new
feature in the manual.

* etc/ORG-NEWS: Advertise the new features.
2023-12-10 16:04:02 +01:00
Ihor Radchenko b1cb3b724a
Revert "org-element: Simplify drawer and property drawer regexps"
This reverts commit 2b96501070.

The regexp was actually incorrect and correcting it is not trivial.
2023-12-10 16:03:53 +01:00
Ihor Radchenko 1e8081aeec
Revert "lisp/org.el (org-property-drawer-re): Fix regexp"
This reverts commit 6003637a4d.

The new accurate regexp is making the parser horribly slow.  The
regexp should be fix some other way.
2023-12-10 15:59:23 +01:00
Ihor Radchenko 5e809903d5
lisp/ol.el (org-store-link): Clarify the return value when INTERACTIVE? is nil 2023-12-10 13:18:28 +01:00
Ihor Radchenko 4f92738774
lisp/ox-html.el: Fix some checkdoc warnings
* lisp/ox-html.el (org-html-mathjax-options): Use two spaces between
sentences and remove trailing newline in the docstring.
(org-html--container):
(org-html-xhtml-p):
(org-html-html5-p): Add docstring.
(org-html--anchor):
(org-html--todo):
(org-html-format-headline-default-function):
(org-html-format-inlinetask-default-function): Document all the
function arguments.
2023-12-10 12:52:16 +01:00
Ihor Radchenko 282c0fb6d1
lisp/ox-icalendar.el (org-icalendar--vtodo): Document CLASS argument 2023-12-09 12:14:24 +01:00
Ihor Radchenko 73617ff586
lisp/ox-icalendar.el (org-icalendar--vevent): Escape ( in the docstring 2023-12-09 12:14:11 +01:00
Ihor Radchenko 3c714d7b32
lisp/ox-icalendar.el (org-icalendar--rrule): Add docstring 2023-12-09 12:14:00 +01:00
Antero Mejr 478576749d
Move files when using `org-babel-tangle-publish'
* lisp/ob-tangle.el (org-babel-tangle-publish): Use `rename-file'
instead of `copy-file' on tangled files.

Fixes `copy-file' error when publishing to the current directory.
Don't leave behind the old tangled files when publishing.

Link: https://orgmode.org/list/87v898mgx4.fsf@mailbox.org
2023-12-09 11:26:03 +01:00
Ihor Radchenko 3280f2f8bd
lisp/ox-koma-letter.el: Fix checkdoc warnings
* lisp/ox-koma-letter.el (org-koma-letter-use-foldmarks): Do not quote
t.
(org-koma-letter--special-contents-inline): Document INFO argument.
(org-koma-letter--add-latex-newlines): Mention STRING argument.
Clarify that the return value is a new string.
2023-12-08 14:15:20 +01:00
Ihor Radchenko 3b71939903
lisp/org-src.el: Suppress compiler warnings for obsolete code
* lisp/org-src.el (org-src-babel-configure-edit-buffer):
(add-hook): Suppress obsolete call warning - this code is also
obsolete and is to be removed in future.
2023-12-07 15:15:44 +01:00
Ihor Radchenko a8a0a45d24
lisp/org-lint.el (misplaced-heading): New linter
* lisp/org-lint.el (org-lint-misplaced-heading): Add new linter
function to detect heading lines accidentally merged with the line
above.
2023-12-07 15:13:49 +01:00
Ihor Radchenko 6003637a4d
lisp/org.el (org-property-drawer-re): Fix regexp
`org-property-re' demands whitespace after property name when the
value is present.  Do the same for property drawer detection.
2023-12-07 15:11:41 +01:00
Ihor Radchenko ac9acb2113
lisp/ox-latex.el (org-latex--format-spec): Fix checkdoc warning 2023-12-07 11:52:25 +01:00
Ihor Radchenko a59193e47d
fixup! lisp/oc-basic.el: Consider that author/title fields may be raw string objects
* lisp/oc.el (org-cite-capitalize): Should use `capitalize', not `upcase'.
2023-12-07 11:31:07 +01:00
Ihor Radchenko fdd9b6d330
org-cite-capitalize: Fix when STR is a raw string pseudo-object
* lisp/oc.el (org-cite-capitalize): Assure that `upcase' is passed a
string.

Link: https://orgmode.org/list/alpine.DEB.2.22.394.2311290957360.107158@shell3.miskatonic.org
2023-12-06 15:52:34 +01:00
Ihor Radchenko 29d5b2573b
lisp/ox-latex.el (org-latex--make-option-string): Document all the arguments 2023-12-06 15:18:46 +01:00
Ihor Radchenko 7926045ff5
Obsolete `org-src-associate-babel-session' and related functionality
* etc/ORG-NEWS (~org-src-associate-babel-session~ and
~org-babel-<lang>-associate-session~ are now obsolete): Announce the
change.
* lisp/org-compat.el (org-src-associate-babel-session):
(org-src-babel-configure-edit-buffer): Mark obsolete.
* lisp/org-src.el: Add comment to remove "Babel related functions"
block in the next release.

Link: https://orgmode.org/list/CAOQTW-OMeyWYcLq8hDJ4MB10_4dOkvoNjKnFedLYP2z+-M6BAg@mail.gmail.com
2023-12-06 14:21:01 +01:00
Ihor Radchenko e3dec7fe6a
fixup! org-buffer-text-pixel-width: Fix measuring lines beyond window width 2023-12-05 20:40:28 +01:00
Ihor Radchenko 88e8b207fd
Merge branch 'bugfix' 2023-12-05 20:39:00 +01:00
Ihor Radchenko f2cb64579b
org-buffer-text-pixel-width: Fix measuring lines beyond window width
* lisp/org-compat.el (org-buffer-text-pixel-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:42:17 +01:00
Ihor Radchenko 8c2f7635c5
Merge branch 'bugfix' 2023-12-05 16:41:12 +01:00
Ihor Radchenko 5e946d3673
org-print-speed-command: Rename and mark for internal use
* etc/ORG-NEWS (~org-print-speed-command~ is now an internal
function): Announce the change.
* lisp/org-compat.el (org-print-speed-command): Mark obsolete.
* lisp/org-keys.el (org--print-speed-command): Rename as internal
function.  Add docstring.  Rename the argument to be more clear.
(org-speed-command-help): Use the new function name.
2023-12-05 14:30:55 +01:00
Ihor Radchenko a0ee5d4c33
lisp/org-keys.el (org-mouse-1-follows-link): Fix checkdoc warning
This change is just suppressing it, following what
`mouse-1-click-follows-link' docstring does.
2023-12-05 14:28:05 +01:00
Ihor Radchenko f4b9f3f7b9
lisp/org-keys.el: Document all the function arguments
* lisp/org-keys.el (org-key):
(org-defkey):
(org-babel-speed-command-activate):
(org-speed-command-activate):
2023-12-05 14:27:44 +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 23378177c2
lisp/oc-basic.el: Consider that author/title fields may be raw string objects
* lisp/oc-basic.el (org-cite-basic--get-field): Clarify that raw
string object may be returned.
(org-cite-basic--shorten-names): Clarify NAMES type.  Allow NAMES to
be a raw string object.
(org-cite-basic--get-year):
(org-cite-basic--key-completion-table): Use a more clear RAW argument
value in the call to make it explicit that we request raw return value.
(org-cite-basic-export-citation): Allow AUTHOR to be raw string object.
* lisp/oc.el (org-cite-capitalize): New function to capitalize string
or raw string object.

Reported-by: William Denton <wtd@pobox.com>
Link: https://orgmode.org/list/alpine.DEB.2.22.394.2311230124110.19367@shell3.miskatonic.org
2023-12-05 12:08:14 +01:00
Ihor Radchenko 36f61a9c8b
lisp/oc.el (org-cite-parse-elements): Use org-mode buffer for parsing 2023-12-05 12:08:13 +01:00
Kyle Meyer 1e353648ef Merge branch 'bugfix' 2023-12-04 23:33:47 -05:00
Ihor Radchenko 08c9664a42
Merge branch 'bugfix' 2023-12-04 15:52:16 +01:00
Bastien Guerry 4d72f3a0d2 Merge branch 'bugfix' 2023-12-02 10:03:02 +01:00
Ihor Radchenko 57b94f3447
lisp/org.el (org-in-src-block-p): Fix when post-blank has spaces
Reported-by: Jens Schmidt <jschmidt4gnu@vodafonemail.de>
Link: https://orgmode.org/list/c286709d-5981-41ba-ac3f-f628f2b0ce34@vodafonemail.de
2023-11-29 11:05:41 +01:00
Ihor Radchenko 6d7c7917a0
lisp/org.el (org-in-src-block-p): Fix when on affiliated or post-blank
* lisp/org.el (org-in-src-block-p): When INSIDE is non-nil, do not
return t for affiliated keywords and post-blank.

Reported-by: No Wayman <iarchivedmywholelife@gmail.com>
Link: https://orgmode.org/list/87msuzdkcu.fsf@gmail.com
2023-11-27 21:26:28 +01:00
Ihor Radchenko bd7fab2129
lisp/org.el (org-in-src-block-p): Improve docstring
* lisp/org.el (org-in-src-block-p):

Reported-by: No Wayman <iarchivedmywholelife@gmail.com>
Link: https://orgmode.org/list/87il5n9owq.fsf@gmail.com
2023-11-27 21:25:56 +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 6a417d5798
doc/org-guide.org: Convert references to manual into info:org links
Reported-by: @inktvis_75:matrix.org
2023-11-23 12:43:29 +02:00
Ihor Radchenko bfa4f9d5aa
* lisp/ox-latex.el: Document some undocumented function arguments
(org-latex-generate-engraved-preamble):
(org-latex--remove-packages): Document INFO argument.
2023-11-18 13:18:53 +02:00
Ihor Radchenko ad1aff1722
lisp/ox-latex.el (org-latex-src-block-backend): Fix double space in docstring 2023-11-18 13:18:37 +02:00
Ihor Radchenko a1fa521975
org-agenda-format-item: Do not call `org-get-outline-path' in non-Org buffer
* lisp/org-agenda.el (org-agenda-format-item): Avoid invoking Org
parser when we are not actually in Org buffer.  Add commentary
explaining when it can happen.

Reported-by: Will O'Brien <will.08rien@gmail.com>
Link: https://orgmode.org/list/m2leawo9zo.fsf@hazy.com
2023-11-17 15:04:28 +02:00
Ihor Radchenko 0740e62df8
lisp/ox-ascii.el: Fix justification of special blocks
* lisp/ox-ascii.el (org-ascii--current-justification): Fix typos in
the code.
* testing/lisp/test-ox-ascii.el (test-ox-ascii/justify): Add test.

Reported-by: Gregor Zattler <telegraph@gmx.net>
Link: https://orgmode.org/list/87o7ft8gxo.fsf@no.lan
2023-11-17 10:28:32 +02:00
Ihor Radchenko 819cd73cb4
lisp/ox-publish.el (org-publish-timestamp-filename): Document function arguments 2023-11-15 11:20:33 +02:00
Ihor Radchenko 4758255035
lisp/ox-texinfo.el (org-element-ast): Fix checkdoc warnings
Require org-element-ast explicitly to avoid checkdoc warnings for its
functions.  org-element-ast is indirectly loaded by ox->org-element,
but requiring it directly is indeed more clear.
2023-11-14 20:07:47 +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 d285f72f9d
* lisp/org-persist.el (org-persist-write:url): Do not end error with "." 2023-11-13 11:28:40 +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 6af71d6f2f
Merge branch 'bugfix' 2023-11-11 13:05:03 +02:00
Ihor Radchenko b5cfc311db
org-babel-ref-resolve: Search current buffer when FILE in FILE:REF does not exist
* lisp/ob-ref.el (org-babel-ref-resolve): Only search in other file
when FILE in FILE:REF exists.
* doc/org-manual.org (Passing arguments):
* etc/ORG-NEWS (Babel references =FILE:REFERENCE= now search current
buffer when =FILE= does not exist): Document the change.

Reported-by: Stefano Ghirlanda <dr.ghirlanda@gmail.com>
Link: https://orgmode.org/list/CAK_gY-Q4f82dbDQgyS+FfyeQaHAMXHqygq3e6ZsWnEj-+eoG9A@mail.gmail.com
2023-11-10 12:31:14 +02:00
Ihor Radchenko 08bbdc7c8b
Merge branch 'bugfix' 2023-11-10 12:08:57 +02:00
Ihor Radchenko 2e8262b893
lisp/org-timer.el (org-timer-start-time): Fix checkdoc warning
Start docstring with capital letter.
2023-11-08 11:55:50 +02:00
Ihor Radchenko c80f320269
lisp/org-timer.el: Document all the function arguments
* lisp/org-timer.el (org-timer):
(org-timer-change-times-in-region):
(org-timer-item):
(org-timer-fix-incomplete):
(org-timer-hms-to-secs):
(org-timer-set-timer):
2023-11-08 11:55:50 +02:00
Sławomir Grochowski 0ad14d7b0e doc/org-manual.org: Checkboxes, add checkbox states examples
* org-manual.org: Checkboxes, add checkbox states examples
2023-11-08 00:35:32 +01:00
Ihor Radchenko 6feef2a279
Merge branch 'bugfix' 2023-11-07 12:52:46 +02:00
Ihor Radchenko 154a80f864
lisp/org-crypt.el (org-crypt-check-auto-save): Fix checkdoc warning 2023-11-07 11:43:53 +02:00
Ihor Radchenko 7056752f33
* lisp/org-cycle.el: Document all the function arguments
(org-cycle-content):
(org-cycle-optimize-window-after-visibility-change):
(org-cycle-display-inline-images):
2023-11-06 11:46:30 +02:00
Ihor Radchenko 1014296344
* lisp/org.el (org-comment-dwim): Rely on `org-comment-or-uncomment-region'
Remove special case for src block and instead use the Org's
`org-comment-or-uncomment-region' used as `comment-region-function'.
`org-comment-or-uncomment-region' already supports commenting inside
src blocks.

Fixes https://orgmode.org/list/d8dc0cca-00d9-4349-a123-6ea6776b00cc@vodafonemail.de
2023-11-06 11:14:29 +02:00
Ihor Radchenko 089fda1219
Merge branch 'bugfix' 2023-11-05 17:51:55 +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 459a10979d
* lisp/ox-man.el (org-man-table-cell): Fix checkdoc warning 2023-11-05 11:31:39 +02:00
Ihor Radchenko 054bdb6ce3
* lisp/ox-md.el (org-md--convert-to-html): Fix the docstring
Clarify that CONTENTS argument is ignored and document INFO argument.
2023-11-04 09:48:39 +02:00
Ihor Radchenko 38723463db
org-publish-project-alist: Fix checkdoc warning
Clarify that `user-full-name' refers to a variable.
2023-11-03 09:21:37 +02:00
Ihor Radchenko 91ce96d04a
org-html-link-org-files-as-html: Fix checkdoc warning
Escape ( at bol.
2023-11-02 10:22:23 +02:00
Ihor Radchenko 9ecee6f2e2
* lisp/ox.el (org-export-async-debug): Fix checkdoc warning 2023-11-01 12:48:43 +02:00
Ihor Radchenko ab0d0a6402
fixup! * lisp/org-table.el (org-table-make-reference): Add a FIXME comment 2023-11-01 11:24:49 +02:00
Ihor Radchenko 1ef9e144aa
* lisp/org-table.el (org-table-make-reference): Add a FIXME comment 2023-11-01 11:23:58 +02:00
Bastien Guerry 0ab6ab00c1 Revert "lisp/org-table.el: fix warning about `eq' usage"
This reverts commit ee0961ba31.
2023-11-01 10:14:30 +01:00
Karl Fogel ee0961ba31 lisp/org-table.el: fix warning about `eq' usage
* lisp/org-table.el (org-table-make-reference): Use `equal' instead of
`eq' to compare strings.

This change makes the following warning go away:

  Warning (comp): org-table.el:2867:23: \
  Warning: `eq' called with literal string that may never match (arg 2)

This change does not affect the behavior of `org-table-make-reference'
because `eq' treats all instances of the empty string as the same
object anyway, e.g., `(eq (string-trim "aaabbb" "a+" "b+") "")' ==> t.
The only effect of this change is to eliminate the warning.
2023-10-31 21:38:23 +01:00
Ihor Radchenko d68d0f5f49
* lisp/org-pcomplete.el: Add commentary section 2023-10-30 12:05:09 +02:00
Ihor Radchenko ffcdaa1e22
* lisp/org-mouse.el (org-mouse-re-search-line): Document function argument 2023-10-28 13:53:22 +03:00
Ihor Radchenko 9183e3c723
* lisp/org-crypt.el: Fix checkdoc warnings
(org-crypt-disable-auto-save):
(org-crypt-check-auto-save): Add missing quoting in the docstrings.
2023-10-27 12:19:44 +03:00
Ihor Radchenko 41ff569f2d
* lisp/org-ctags.el: Fix sentence spacing in the top comment 2023-10-26 12:48:21 +03:00
Ihor Radchenko 55db64e9d0
org-element--properties-mapc: Fix typo
* lisp/org-element-ast.el (org-element--properties-mapc): Fix missing
parenthesis.

Reported-by: Max Nikulin <manikulin@gmail.com>
Link: https://orgmode.org/list/uhb60m$10d5$1@ciao.gmane.io
2023-10-25 16:47:53 +03:00
Ihor Radchenko 2b15e789ae
org-clock-out-removed-last-clock: New variable to be used by `org-clock-hook'
* lisp/org-clock.el (org-clock-out-removed-last-clock): Add new global
variable.
(org-clock-out): Set the variable to non-nil when the CLOCK line has
been removed before running `org-clock-out-hook'.
(org-clock-out-hook): Add reference to the new variable.
* etc/ORG-NEWS (New variable ~org-clock-out-removed-last-clock~):
Announce the change.
2023-10-25 16:14:23 +03:00
Ihor Radchenko 9512bf250a
org-clock-out-hook: Clarify point location when hook is executed
* lisp/org-clock.el (org-clock-out-hook): Clarify that the point is at
the clock line when the hook is executed.
2023-10-25 14:52:22 +03:00
Ihor Radchenko b06995e998
* lisp/ol-man.el: Add file commentary and Code: header 2023-10-25 13:46:00 +03:00
PolishEmacsUser 0b0bf03e4b
org-clock-clocktable-language-setup: Reformat and add Polish translation
* lisp/org-clock.el (org-clock-clocktable-language-setup): Add Polish.
Reorder the translation aplhabetically with English on top.  Unify
spaces in lists.

TINYCHANGE
2023-10-25 13:35:43 +03:00
Max Nikulin 9cbaf8e49c
ox-ascii.el: Consistently add brackets around links
* lisp/ox-ascii.el (org-ascii-link): Add square brackets around
description of fuzzy links when they are exported inline.
* lisp/ol-docview.el (org-docview-export):
* lisp/ox-ascii.el (org-ascii-link): Export links with square brackets
around description and angle brackets around path.

This make export of links inline (when `org-ascii-links-to-notes' is
nil) consistent with "http:" links: "[DESC] (<URI>)".

I would drop brackets for "http:" and similar links instead
("DESC (<URI>)" or even "DESC <URI>"), but any case I prefer
consistency.

Ihor Radchenko to emacs-orgmode. Re: [RFC][PATCH] Allow to export to
ascii custom link types as notes. Tue, 24 Oct 2023 10:40:41 +0000.
<https://list.orgmode.org/87edhk717a.fsf@localhost>
2023-10-25 13:30:40 +03:00
Ihor Radchenko f632def07c
* doc/org-manual.org: Improve documentation for #+SELECT_TAGS and #+EXCLUDE_TAGS
(Export Settings): Clarify how to define multiple tags per-document.  Reword.

Link: https://orgmode.org/list/87y1ftilf3.fsf@mat.ucm.es
2023-10-25 11:26:43 +03:00
Ihor Radchenko 96286321c5
Merge branch 'bugfix' 2023-10-25 11:03:15 +03: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 c7db1c0981
* lisp/org-clock.el (org-clock-menu): Add docstring 2023-10-24 13:44:28 +03:00
Ihor Radchenko e03402b931
Merge branch 'bugfix' 2023-10-24 12:28:20 +03:00
Ihor Radchenko 098f081591
org-open-at-point: Preserve point unless opening link moves the point
* lisp/org.el (org-open-at-point): Preserve point when opening links.
When a link opened moves point in current buffer, do move the point
as needed by the link.  When multiple links that are opened move point
in current buffer, move point to the last such link.  Fix searching
for the links when opening _multiple_ the links is requested.

Reported-by: Gustavo Barros <gusbrs.2016@gmail.com>
Link: https://orgmode.org/list/87r0mp2srd.fsf@localhost
2023-10-23 14:28:04 +03:00
Ihor Radchenko 20ab29117c
* lisp/ol.el (org-link-open-as-file): Document function arguments 2023-10-23 12:33:29 +03:00
Ihor Radchenko 154ef34107
* lisp/ol-eww.el (org-eww-extend-eww-keymap): Add docstring 2023-10-22 12:18:53 +03:00
Ihor Radchenko 693a3c558f
org-icalendar-entry: Fix when the value is a list of keywords
* lisp/ox-icalendar.el (org-icalendar-entry): Add condition when the
value of :icalendar-include-todo is a list of keywords.
(org-icalendar-include-todo): Document that the value can be a list of
keywords, as per :type spec.

Reported-by: Björn Bidar <bjorn.bidar@thaodan.de>
Link: https://list.orgmode.org/orgmode/87ttqjirrv.fsf@/
2023-10-22 11:45:34 +03:00
Gerard Vermeulen 1494445116
Fix obsolete `sleep-for' usage
* lisp/ob-lua.el (org-babel-lua-evaluate-session):
* lisp/ob-python.el (org-babel-python-initiate-session-by-key):
(org-babel-python-evaluate-session):
* testing/lisp/test-ob-R.el (ob-session-async-R-simple-session-async-value):
(ob-session-async-R-simple-session-async-output):
(ob-session-async-R-named-output):
(ob-session-async-R-named-value):
(ob-session-async-R-output-drawer):
(ob-session-async-R-value-drawer):
(ob-session-R-result-output):
* testing/lisp/test-ob-julia.el (test-ob-julia/async-simple-session-output):
(test-ob-julia/async-named-output):
(test-ob-julia/async-output-drawer):
* testing/lisp/test-ob-python.el (test-ob-python/async-simple-session-output):
(test-ob-python/async-named-output):
(test-ob-python/async-output-drawer): Replace deprecated two integer
argument `sleep-for' calls with one float `sleep-for' calls.
2023-10-21 16:08:25 +03:00
Ihor Radchenko edff094b5f
* lisp/ol-eshell.el: Fix docstrings
(org-eshell-open): Document the function argument.
(org-eshell-store-link): Make the first docstring line into a single
sentence.
2023-10-21 14:49:52 +03:00
Nan JunJie 7ceefaf2d5
* lisp/ob-plantuml.el: Support tikz output
(org-babel-execute:plantuml): Generate tikz code without preamble when
requested :file has .tikz extension.
* etc/ORG-NEWS (=ob-plantuml.el=: Support tikz file format output):
Document the change.

TINYCHANGE
2023-10-20 14:52:25 +03:00
Ihor Radchenko 595a32d532
* lisp/ol.el: Document some of the function arguments
(org-link-store-props):
(org-link-add-props):
(org-link-open-from-string):
2023-10-20 13:29:03 +03:00
Ihor Radchenko 0e9485c90b
* lisp/ol.el (org-link--set-link-display): Fix compiler warning 2023-10-20 13:28:42 +03:00
Ihor Radchenko aef5cf5e0b
* lisp/ol.el (org-link-descriptive): Provide :set function
(org-link--set-link-display): New internal function used to apply
`org-link-descriptive' value across open Org buffers.
2023-10-20 12:38:18 +03:00
Ihor Radchenko 46a52a5708
* lisp/ob-sqlite.el: Document all the function arguments
(org-babel-execute:sqlite):
(org-babel-sqlite-offset-colnames):
2023-10-19 12:58:21 +03:00
Ihor Radchenko 13353f1fa3
org-fold-hide-drawer-all: Make interactive
* lisp/org-fold.el (org-fold-hide-drawer-all): Convert into
interactive command.  Accept two optional arguments - region
boundaries.
* etc/ORG-NEWS (~org-fold-hide-drawer-all~ is now interactive):
Document the change.

Link: https://orgmode.org/list/CAFmwT7WEMvGVyQhP8NcZY5vZMzz4NcvBjchd4jBqgHCPwjOgFA@mail.gmail.com
2023-10-19 12:32:49 +03:00
Ihor Radchenko c77e7f9c8a
* etc/ORG-NEWS (=UNNUMBERED= property ...): Add reference to the manual
Reported-by: Pedro Andres Aranda Gutierrez <paaguti@gmail.com>
Link: https://orgmode.org/list/CAO48Bk_7TMEzCt4GCQwjhmK5Q-MSVL6BkyV98o4SyfpA0qiv7Q@mail.gmail.com
2023-10-19 12:08:19 +03:00
Ihor Radchenko 733cb9614c
* lisp/ob-sqlite.el: Add support for :prologue/:epilogue parameters
(org-babel-expand-body:sqlite):
2023-10-19 12:01:10 +03:00
Ihor Radchenko ab4ec726e5
* lisp/ob-org.el: Add support for :prologue/:epilogue parameters
(org-babel-expand-body:org):
2023-10-19 12:01:09 +03:00
Ihor Radchenko 320b0e5b1f
* lisp/ob-lisp.el: Add support for :prologue/:epilogue parameters
(org-babel-expand-body:lisp):
2023-10-19 12:01:09 +03:00
Ihor Radchenko 6887851401
* lisp/ob-lilypond.el: Add support for :prologue/:epilogue parameters
(org-babel-expand-body:lilypond):
2023-10-19 12:01:08 +03:00
Ihor Radchenko f0a2531bb4
* lisp/ob-latex.el: Add support for :prologue/:epilogue parameters
(org-babel-expand-body:latex):
2023-10-19 12:01:06 +03:00
Ihor Radchenko 92b69d4331
* lisp/ob-java.el: Add support for :prologue/:epilogue parameters
(org-babel-expand-body:java):
2023-10-19 12:01:03 +03:00
Ihor Radchenko 67bd4b0a36
* lisp/ob-fortran.el: Add support for :prologue/:epilogue parameters
(org-babel-expand-body:fortran):
2023-10-19 12:01:00 +03:00
Ihor Radchenko 936290fe18
* lisp/ob-emacs-lisp.el: Add support for :prologue/:epilogue parameters
(org-babel-expand-body:emacs-lisp):
2023-10-19 12:00:55 +03:00
Ihor Radchenko 3bffa96448
* lisp/ob-dot.el: Add support for :prologue/:epilogue parameters
(org-babel-expand-body:dot):
2023-10-19 12:00:46 +03:00
Ihor Radchenko be59f11435
* lisp/ob-calc.el: Add support for :prologue/:epilogue parameters
(org-babel-expand-body:calc):
2023-10-19 12:00:37 +03:00
Ihor Radchenko 1f0eaefa52
* lisp/ob-awk.el: Add support for :prologue/:epilogue parameters
(org-babel-expand-body:awk):
2023-10-19 12:00:28 +03:00
Ihor Radchenko 312deaa13a
* lisp/ob-C.el: Add support for :prologue/:epilogue parameters
(org-babel-C-expand-C):
2023-10-19 12:00:18 +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 627097c7d3
* lisp/ol.el (org-link-complete-file): Document the function argument 2023-10-18 13:47:49 +03:00
Ihor Radchenko 8320e4794e
org-entry-get-with-inheritance: Fix inherited explicit nil value
* lisp/org.el (org-entry-get-with-inheritance): Do not ignore when
property has explicit "nil" value.
* testing/lisp/test-org.el (test-org/entry-get): Add test.
2023-10-18 11:37:13 +03:00
Ihor Radchenko 4f8c9f5ac5
* lisp/ol-man.el (org-man-export): Document all the function arguments
Rename FORMAT to more accurate BACKEND.
2023-10-17 14:00:01 +03:00
Ihor Radchenko b223a3cc75
org-num: Allow property inheritance for UNNUMBERED property
* lisp/org-num.el (org-num--skip-value): Honour property inheritance.
* etc/ORG-NEWS (=UNNUMBERED= property inheritance is now honored by
~org-num-mode~): Document the change.

Link: https://orgmode.org/list/249cd3af-c173-5ff2-df27-c32af3886329@gmail.com
2023-10-17 13:01:25 +03:00
Ihor Radchenko 24a0e7f8df
* lisp/ob-python.el: Fix misspelled constant name
(org-babel-default-header-args:python):
(org-babel-header-args:python): Rename.
`org-babel-header-args:python' is the correct name for extra
language-specific allowed header arguments.
2023-10-17 11:13:59 +03:00
Ihor Radchenko 9bbc21df84
Merge branch 'bugfix' 2023-10-16 16:05:05 +03:00
Ihor Radchenko 678af9d502
test-org/auto-repeat-maybe: Fix Emacs <28 compatibility
* testing/lisp/test-org.el (test-org/auto-repeat-maybe): Do not use
`string-search', which is not yet available in Emacs <28.
2023-10-16 13:24:24 +03:00
Ihor Radchenko 16548593eb
* lisp/org-clock.el (org-clock-clocked-in-display): Fix docstring format
Make sure that the docstring has a single sentence as its first line.
2023-10-16 12:18:43 +03:00
Valentin Herrmann 23f751910e
org.el: Respect org-extend-today-until in timestamps with ++
* org.el (org-auto-repeat-maybe): Changed org-auto-repeat-maybe, so that
switching a repeating todo with a timestamp of the form <… ++…> respects
`org-extend-today-until'.
* test-org.el (test-org/auto-repeat-maybe, org-test-with-time-locale):
Tests for interaction of `org-extend-today-until' and
`org-auto-repeat-maybe'. Added `org-test-with-time-locale' to make test
results independent of running machine. Explicitly avoid matching log
note with old timestamp in all the tests to avoid confusion.

Co-authored-by: Ihor Radchenko <yantar92@posteo.net>

TINYCHANGE
2023-10-16 11:35:36 +03:00
bzg 201625f7e2 lisp/org-agenda.el: Display commands in a more consistent order
* lisp/org-agenda.el (org-agenda-get-restriction-and-command):
Display commands in a more consistent order.
2023-10-16 10:30:03 +02: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 fa7542d74c
* lisp/org-agenda.el (org-agenda-get-progress): Fix clock log entries
Do not alter match data when calling `org-get-category'.  The
subsequent code assumes that match data is not altered.
2023-10-16 10:34:14 +03:00
bzg 0becd1d6f7 Merge branch 'bugfix' 2023-10-16 07:43:04 +02:00
Jack Kamm 1eb5987589 ob-python: Check for end of output in org-babel-python-send-string
This is an attempt to mitigate occasional leaky prompts in CI. My
current hypothesis is that this could happen if the comint-output ends
between `org-babel-python-eoe-indicator' and the new prompt. Then the
new prompt could be injected into the output of the next unit test. To
avoid this, check we are at an ending prompt before exiting
`org-babel-python-send-string'.

https://list.orgmode.org/873506j7ky.fsf@localhost/

* lisp/ob-python.el (org-babel-python-send-string): Add check for
`python-shell-comint-end-of-output-p' to stop while loop accepting
process output.
2023-10-15 16:25:14 -07:00
Ihor Radchenko 061988c024
* lisp/org-tempo.el: Fix checkdoc warnings
(org-tempo-add-block):
(org-tempo-add-keyword): Fix arglist format in the docstring.
2023-10-15 11:53:05 +03:00
Ihor Radchenko 1a1f45d236
Merge branch 'bugfix' 2023-10-15 11:32:55 +03:00
Ihor Radchenko 7d90507420
Merge branch 'bugfix' 2023-10-15 11:12:34 +03:00
Ihor Radchenko 9fcbd19b3b
* lisp/org-protocol.el (org--protocol-detect-protocol-server): Fix docstring 2023-10-14 12:09:34 +03:00
Ihor Radchenko ec23993301
lisp/ox.el: Ignore case when matching headings and targets
* lisp/ox.el (org-export-search-cells):
(org-export-string-to-search-cell): Ignore case in headline titles and
radio targets.
* testing/lisp/test-ox.el (test-org-export/fuzzy-link): Add new test.

ox.el implements an independent link resolution mechanism that is not
fully consistent with ol.el.  In particular, radio links, when
resolved via `org-export-resolve-link' (unlike
`org-export-resolve-radio-link'), were previously case-sensitive, in
contrast with ol.el, which is case-insensitive.  Similarly, headline
matching by fuzzy links had inconsistency between `org-link-search'
and what ox.el does.

Link: https://orgmode.org/list/m2cyxl3qd0.fsf@me.com
2023-10-14 11:45:57 +03:00
Ihor Radchenko ed42dc34a8
* lisp/ol.el (org-link-search): Ignore case when matching headings
As per the docstring.
2023-10-14 11:44:10 +03:00
Ihor Radchenko abf5156096
* lisp/org-attach.el (org-attach-attach): Do not end error message with period 2023-10-13 15:34:39 +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 f3de4c3e04
org-babel-tangle-collect-blocks: Ignore src blocks without language
* lisp/ob-tangle.el (org-babel-tangle-collect-blocks): Skip src blocks
that do not specify lang rather than erring.

Reported-by: Andrea <andrea-dev@hotmail.com>
Link: https://orgmode.org/list/AS8P193MB241369D9F0701F57E293429288D3A@AS8P193MB2413.EURP193.PROD.OUTLOOK.COM
2023-10-12 17:34:54 +03:00
Ihor Radchenko a2dd30d3a1
* lisp/ol-doi.el (org-link-doi-open): Document all the function arguments 2023-10-12 14:44:02 +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 e1569918cc
org-agenda: Handle inactive ranges when displaying inactive timestamps
* lisp/org-agenda.el (org-agenda-get-timestamps): Skip inactive
ranges.  Previously, inactive ranges were treated as two individual
timestamps.
(org-agenda-get-blocks): Handle inactive ranges when
`org-agenda-include-inactive-timestamps' is non-nil.  Append
`org-agenda-inactive-leader' when formatting inactive ranges.

Reported-by: Cletip Cletip <clement020302@gmail.com>
Link: https://orgmode.org/list/87jzru8mjt.fsf@localhost
2023-10-11 12:02:18 +03:00
Ihor Radchenko f32f5982a7
* lisp/ol-info.el (org-info-map-html-url): Prioritize custom URLs
When deriving info page URL, prioritizeable
`org-info-other-documents'.
2023-10-10 19:27:09 +03:00
Ihor Radchenko 7e7ce81136
* lisp/ol-info.el (org-info-other-documents): Convert to `defcustom'
* etc/ORG-NEWS (~org-info-other-documents~ is now a custom option):
Announce the change.

Link: https://orgmode.org/list/871qe44cec.fsf@breatheoutbreathe.in
2023-10-10 19:23:37 +03:00
Ihor Radchenko ce47fdf382
Merge branch 'bugfix' 2023-10-10 19:09:00 +03:00
Ihor Radchenko ad7406fc14
Merge branch 'bugfix' 2023-10-10 18:45:33 +03:00
Ihor Radchenko c952ff10fb
* lisp/ob-ruby.el: Document all the function arguments
(org-babel-execute:ruby):
(org-babel-variable-assignments:ruby):
(org-babel-ruby-initiate-session):
2023-10-10 15:30:35 +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 ad07b2982f
fixup! org-element-parse-secondary-string: Prevent altering current buffer cache 2023-10-10 15:05:25 +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 ac108a3ac1
* lisp/ol-docview.el (org-docview-export): Update docstring and arglist
Document all the arguments. Add fourth argument as require by the
latest :export link property spec.  Rename FORMAT to BACKEND for more
clarity.
2023-10-09 16:33:28 +03:00
Ihor Radchenko 681f3fc8f9
* lisp/ol-docview.el (org-docview-open): Add docstring 2023-10-09 16:33:18 +03:00
Ihor Radchenko 54b9c845a7
* lisp/org-crypt.el: Fix outdated declare forms
(org-end-of-subtree):
(org-make-tags-matcher): Update the arglists.
2023-10-08 13:01:12 +03:00
Ihor Radchenko fe19ebe4af
* lisp/org-archive.el: Fix flycheck warnings
(org-add-archive-files):
(org-toggle-archive-tag): Document all the function arguments.
(org-timestamp-to-now): Add missing declare.
2023-10-08 12:58:29 +03:00
Ihor Radchenko 1003790d1d
* lisp/org-pcomplete.el (org-element-property): Fix malformed declare 2023-10-07 16:25:08 +03:00
Ihor Radchenko 1225f62576
org-babel-python-read-string: Upcase function argument in the docstring
* lisp/ob-python.el (org-babel-python-read-string):
2023-10-07 13:34:42 +03:00
Ihor Radchenko 26f1cb77a9
org-ascii-item: Fix for alphabetical bullets
* lisp/ox-ascii.el (org-ascii-item): Fix setting [@X] counter for
alphabetical lists.
* testing/lisp/test-ox-ascii.el:
(test-ox-ascii/list):  Add new test.
* testing/lisp/test-ox-latex.el (org-test-with-exported-text):
* testing/org-test.el (org-test-with-exported-text): Move macro to be
available across multiple test files.

Reported-by: Tom Alexander <tom@fizz.buzz>
Link: https://orgmode.org/list/36a62fbf-6484-456f-9537-a7aa40530068@app.fastmail.com
2023-10-07 13:22:09 +03:00
Ihor Radchenko 69c830f361
* lisp/ob-processing.el: Document all the function arguments
(org-babel-execute:processing):
(org-babel-variable-assignments:processing): Fix the docstrings.
2023-10-06 20:04:30 +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 e6690c5b79
* lisp/ob-screen.el (org-babel-execute:screen): Document the function args 2023-10-05 15:04:14 +03:00
Ihor Radchenko 88ff6c2fbc
org-reset-checkbox-state-subtree: Do not reset outside the subtree
* lisp/org-list.el (org-update-checkbox-count): Allow ALL argument to
have a value `narrow', meaning "update in accessible portion of the
buffer".  Update the docstring accordingly.
(org-update-checkbox-count-maybe): Document the special value of ALL
argument passed to `org-update-checkbox-count'.
(org-reset-checkbox-state-subtree): Update checkbox count within
subtree only.

Reported-by: J. G. <jerzor@pacbell.net>
Link: https://orgmode.org/list/1700336757.1605468.1695739462846@mail.yahoo.com
2023-10-05 12:34:42 +03:00
Ihor Radchenko 6d85f851b3
* lisp/ob-shell.el (org-babel-execute:shell): Document the function args 2023-10-04 12:28:10 +03:00
Ihor Radchenko 460c1a3524
Merge branch 'bugfix' 2023-10-04 11:42:16 +03:00
Leo Butler 2ba45fcb78
* lisp/ob-maxima.el: enable use of `batch' loader and `draw'
* (org-babel-header-args:maxima): Document the two new header
arguments (batch and graphics-pkg) that are specific to ob-maxima.
* (org-babel-maxima--command-arguments-default): A new variable
storing the default command-line argument(s).  This value was
hard-coded in `org-babel-maxima:execute'.
* (org-babel-maxima--graphic-package-options): A new variable that
stores an alist of Maxima graphics packages and the Maxima code to set
up that package.
* (org-babel-maxima--default-epilogue): A new variable that stores an
alist of the clean-up code that is run at end of a `graphical-output'
or `non-graphical-output' source block.
* (org-babel-maxima--output-filter-regexps): A new variable that
stores a list of regexps to identify "bad" output lines to be removed
from Maxima's output.  Source-code comments document each regexp's
purpose.  Two additional regexps have been added: one filters
un-wanted output from `batch' and the other removes empty input lines
that `batch'-ed output may spuriously produce (actual empty input
lines are syntax errors, see the new tests below).
* (org-babel-maxima--output-filter): A new function that takes a
single line of Maxima output.  It returns nil if the line has zero
length or matches a regexp in
`org-babel-maxima--output-filter-regexps'; otherwise, it returns the
line.  This function and regexp replace the hard-coded filter in
`org-babel-execute:maxima'.
* (org-babel-maxima-expand): Prepare the source block for execution,
depending on whether it is producing graphical output or not.  In case
of graphical output, use the `graphics-pkg' header to set the graphics
package and use `org-babel-maxima--graphic-package-options' to set-up
the package.  Grovel the graphics terminal from the output filename.
* (org-babel-execute:maxima): Use the :batch header argument and
`org-babel-maxima--command-arguments-default' to execute the source
block.  Replace the existing, in-line output filter and its regexps
with `org-babel-maxima--output-filter' and
`org-babel-maxima--output-filter-regexps'.

* testing/examples/ob-maxima-test.org: Add test examples.

Include examples of the batch-related tests from
testing/lisp/test-ob-maxima.el.  Provide an example of the
`:graphics-pkg' header argument with the `draw' package.

* testing/lisp/test-ob-maxima.el: Introduce six new, batch-related
test functions.  Each test exercises the :batch header argument.  The
response to unusual inputs is tested (empty strings, strings with just
whitespace, input with the `:lisp' reader, and two syntax-related
errors).

link: https://list.orgmode.org/87cyz1ivzw.fsf@t14.reltub.ca/
2023-10-04 11:27:46 +03:00
Ihor Radchenko 3fcf3d2e24
* lisp/ob-R.el (org-babel-edit-prep:R): Add docstring 2023-10-02 16:29:10 +03:00
Ihor Radchenko 3c29e77b51
* lisp/org-capture.el: Fix malformed declare form 2023-10-02 14:19:43 +03:00
Ihor Radchenko 0ed8bf794f
* lisp/ob-python.el: Document some missing function arguments
(org-babel-execute:python):
(org-babel-variable-assignments:python):
(org-babel-python-format-session-value): Document all the function
arguments in the docstrings.
(org-babel-python-with-earmuffs):
(org-babel-python-without-earmuffs): Add docstring.
2023-10-01 13:41:59 +03:00
Ihor Radchenko 85ebb6d422
* lisp/ob-org.el: Document all the function arguments
(org-babel-expand-body:org): Add docstring.
(org-babel-execute:org): Explain all the arguments and describe what
execution of Org body means.
2023-09-29 16:27:11 +03:00
Ihor Radchenko aa9177e1a8
* lisp/ob-octave.el: Document all the function arguments
(org-babel-execute:matlab):
(org-babel-execute:octave):
(org-babel-variable-assignments:octave):
(org-babel-octave-var-to-octave):
(org-babel-matlab-initiate-session):
(org-babel-octave-initiate-session):
(org-babel-octave-evaluate-external-process): Update docstrings and
argument names.
2023-09-26 14:14:11 +03:00
Ihor Radchenko 224d455d60
* lisp/ob-ocaml.el: Document all the function arguments
(org-babel-execute:ocaml):
(org-babel-variable-assignments:ocaml): Fix docstrings.
2023-09-23 14:23:59 +03:00
Ihor Radchenko 4d0f89672a
* lisp/ob-maxima.el: Document all the function arguments
(org-babel-maxima-expand):
(org-babel-execute:maxima):
(org-babel-maxima-var-to-maxima): Document all the arguments.
(org-babel-prep-session:maxima): Add docstring.
2023-09-22 14:09:36 +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 d73d85b05e
* lisp/ob-makefile.el (org-babel-execute:makefile): Document function args 2023-09-21 13:59:23 +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 8b18fc5817
org-attach-dir-from-id: Detect attachments under default `org-attach-id-dir'
* lisp/org-attach.el (org-attach-dir-from-id): When searching for an
existing attachment directory, consider the default value of of
`org-attach-id-dir', if it is changed.  This way, if user used the
default value in the past (or accidentally via emacs -Q), we can still
find the existing attachment dir.
2023-09-20 13:39:20 +03:00
Ihor Radchenko 39314eab11
* lisp/ob-lisp.el (org-babel-lisp-vector-to-list): Add docstring 2023-09-20 13:20:34 +03: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 e42b7a6fdd
* lisp/ob-latex.el: Document all the function arguments
(org-babel-execute:latex):
(org-babel-latex-convert-pdf):
2023-09-19 15:49:09 +03:00
Ihor Radchenko 6c917e8904
org-timestamp-change: Fix increasing range with prefix arg
* lisp/org.el (org-modify-ts-extra): Treat INCREMENT-STEP argument as
multiplier for minutes.
(org-timestamp-change): Add commentary.  Make sure that minutes are
incremented by prefix argument when incrementing time range without
rounding.

Reported-by: Jorge P. de Morais Neto <jorge+list@disroot.org>
Link: https://orgmode.org/list/87wnoezd15.fsf@disroot.org
2023-09-19 15:31:43 +03:00
Ihor Radchenko a098c07973
* lisp/org.el (org-modify-ts-extra): Refactor the code
Rename arguments and variables to be more readable.  Add commentary
explaining the code.  Update the docstring, documenting the important
details and describing all the function arguments.
2023-09-19 14:57:20 +03:00
Ihor Radchenko edcb8eca5f
(org-fast-tag-selection): Honour tag groups when using <TAB> input
* lisp/org.el (org--add-or-remove-tag): New helper function to toggle
tags taking into account tag groups.
(org-fast-tag-selection): Factor out the tag toggling code into a new
function and re-use it in both key selection branch and in the <TAB>
completion interface.

Reported-by: sreenivas sumadithya <sumadithya@gmail.com>
Link: https://orgmode.org/list/CAHVqzFVP9KhrC5ZG_GUHbXZRBVg+PU+tR91vSfrnirLo7_T5Ug@mail.gmail.com
2023-09-19 12:43:00 +03:00
Ihor Radchenko 769c1dc64e
Merge branch 'bugfix' 2023-09-19 11:27:27 +03:00
Ihor Radchenko 6307a774a7
org-agenda-get-scheduled: Fix call to `org-time-string-to-time'
* lisp/org-agenda.el (org-agenda-get-scheduled): Do not pass timestamp
object to `org-time-string-to-time'.  Convert it to string first.

Reported-by: Carlo Tambuatco <oraclmaster@gmail.com>
Link: https://orgmode.org/list/CAJb92EzRWO6v3MRVbU0XwQomx-A1eYvFaOaBsJemB85Y4nJ1eg@mail.gmail.com
2023-09-19 11:22:00 +03:00
Ihor Radchenko 0d9efae43f
org-odt--translate-latex-fragments: Make sure that we use org-mode buffer
* lisp/ox-odt.el (org-odt--translate-latex-fragments): When exporting
Latex fragments, use Org mode buffer to setup parser properly.
2023-09-18 13:08:42 +03:00
Ihor Radchenko 5da44c7ba1
* lisp/ob-js.el: Document all the function arguments
(org-babel-execute:js):
(org-babel-variable-assignments:js):
2023-09-18 11:55:04 +03:00
Ihor Radchenko 72bbf89282
* lisp/ob-haskell.el (org-babel-haskell-execute): Document function arguments 2023-09-17 13:23:00 +03:00
Ihor Radchenko 14bde5aba5
ox-icalendar: Ensure that entries in icalendar end with a newline
* lisp/ox-icalendar.el (org-icalendar--vevent):
(org-icalendar--vtodo): Make sure that there is a newline after the
exported VEVENT and VTODO.

Reported-by: Henrik Frisk <frisk.h@gmail.com>
Link: https://orgmode.org/list/CAO0LSb4aQhUMny4xr=1LB3t5F-K-WnjK1zc+qR7Jy+69vr2wpw@mail.gmail.com
2023-09-17 12:49:46 +03:00
Ilya Chernyshov e203b5a659
testing: Delete useless ert tests
* testing/lisp/test-ob-C.el: Delete useless test.

* testing/lisp/test-ob-fortran.el: Delete useless test.

* testing/lisp/test-ob-lilypond.el: Delete useless test.

* testing/lisp/test-ob-maxima.el: Delete useless test.
2023-09-17 12:48:36 +03:00
Ihor Radchenko 88f2dde0fc
* lisp/ob-python.el: Declare non-standard header args
(org-babel-default-header-args:python): New constant declaring
python-specific header arguments.
2023-09-17 12:39:40 +03:00
Ihor Radchenko c703541ffc
* lisp/ob-groovy.el: Fix checkdoc warnings
(org-babel-execute:groovy):
(org-babel-groovy-evaluate): Document all the function arguments.
(org-babel-groovy-initiate-session): Fix the docstring, explaining
that function does nothing.
2023-09-16 12:23:52 +03:00
Rudolf Adamkovič 2c7018f72e
org-manual: Fix a preposition and capitalization
* doc/org-manual.org (Capturing column view): Replace "in the
... line" with "on the ... line" and capitalize the containing
sentence as well.
2023-09-16 11:55:09 +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 aee3f2227f
* lisp/org.el (org-mode): Initialize cache before parsing buffer keywords
If we load cache after `org-set-regexp-and-options', we may do double
job as `org-set-regexp-and-options' by itself queries cache.
2023-09-16 11:40:56 +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 fd1418dadd
* lisp/ob-gnuplot.el: Document all the function arguments
(org-babel-execute:gnuplot):
(org-babel-variable-assignments:gnuplot):
2023-09-15 12:58:25 +03:00
Gerard Vermeulen d70c1200f7
ob-fortran.el: Fix name of caller in documentation
* lisp/ob-fortran.el (org-babel-execute:fortran): Fix name of caller
in documentation and conform to "rules" in sibling ob-XXX.el files.
2023-09-15 12:22:50 +03:00
Ihor Radchenko 1d35ebd93c
test-org-clok/org-clock-update-time-maybe: Fix test for non-English LANG
* testing/lisp/test-org-clock.el (test-org-clok/org-clock-update-time-maybe):
Do not assert English day names.

Reported-by: emacs@supporter.mailer.me
2023-09-15 12:00:06 +03:00
Ihor Radchenko 9eaca51c51
* lisp/org-clock.el (org-clock--translate): Clarify "L" and "ALL" terms
Explain in a comment what "L" And "ALL" terms mean in the context of
clock table.

Reproted-by: emacs@supporter.mailer.me
2023-09-15 11:55:33 +03:00
Ihor Radchenko 765a84ea25
* lisp/ob-fortran.el: Document all the function arguments
(org-babel-execute:fortran):
(org-babel-expand-body:fortran):
(org-babel-fortran-ensure-main-wrap):
(org-babel-prep-session:fortran):
(org-babel-load-session:fortran):
(org-babel-fortran-var-to-fortran):
(org-babel-fortran-transform-list): Document function arguments and
make sure that the first line of the docstring is a short single
sentence.
2023-09-14 16:06:13 +03:00
Ihor Radchenko df0539d678
* lisp/org.el (org-cdlatex-mode): Try to load texmathp
Attempt to load texmathp before setting advice.  `texmathp' is
optional and must be loaded before `cdlatex'.
2023-09-14 12:37:12 +03:00
Ihor Radchenko 6fbeac84e6
* lisp/ob-lua.el: Fix checkdoc warnings
(org-babel-execute:lua):
(org-babel-variable-assignments:lua):
(org-babel-lua-with-earmuffs):
(org-babel-lua-without-earmuffs):
(org-babel-lua-evaluate):
(org-babel-lua-evaluate-external-process):
(org-babel-lua-read-string): Add or modify docstrings, documenting all
the function arguments.
2023-09-13 11:23:55 +03:00
Ihor Radchenko d96982f375
* lisp/ob-forth.el: Document all the function arguments.
(org-babel-execute:forth): Document the arguments.
(org-babel-forth-session-execute): Add docstring.
2023-09-12 12:30:51 +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
Ihor Radchenko 1d585a1b38
* doc/org-manual.org (HTML doctypes): Remove time reference for a feature
Remove "now" as the manual should not refer to relative time when new
features are introduced - this creates confusion as the time passes.
2023-09-11 12:12:00 +03:00
Ihor Radchenko 4c0cde5783
org-babel-variable-assignments:eshell: Document PARAMS argument
* lisp/ob-eshell.el (org-babel-variable-assignments:eshell):
2023-09-11 11:51:59 +03:00
Juan Manuel Macias 893c5d0851
ox-latex.el: Fixes and improvements in `org-latex-language-alist'.
* (org-latex-language-alist): Fix a language code (`de-de') removed
when `org-latex-babel-language-alist' and
`org-latex-polyglossia-language-alist' were merged.  New admitted
properties: `:babel-ini-alt', `:script' and `:script-tag'.  Add
language code for ancient Greek.  Fix Afrikaans (was previously
removed).  New languages: Chinese Simplified and Traditional.
Correction of some typos, errors and inaccuracies.  `let' bindings
suggested by Ihor Radchenko.

* (org-latex-guess-babel-language): Some necessary modifications.

Link: https://orgmode.org/list/8734zoxzd0.fsf_-_@posteo.net
2023-09-10 16:32:29 +03:00
Ihor Radchenko 08f8c06b14
* lisp/ob-exp.el: Document all the function arguments
(org-babel-exp-do-export):
(org-babel-exp-code):
(org-babel-exp-results):
2023-09-10 11:45:02 +03:00
Ihor Radchenko c2594e7456
fixup! * lisp/ox.el (org-export-dictionary): Add Polish translation 2023-09-10 11:26:06 +03:00
Emacs User 7de89d0a42
* lisp/ox.el (org-export-dictionary): Add Polish translation
TINYCHANGE
2023-09-10 11:01:32 +03:00
Ihor Radchenko 515e4ed49b
* lisp/org.el (org--get-expected-indentation): Remove redundant cond clause
Reported-by: No Wayman <iarchivedmywholelife@gmail.com>
Link: https://orgmode.org/list/87wmwzdwx8.fsf@gmail.com
2023-09-10 10:38:19 +03:00
Ihor Radchenko 2030c111eb
* lisp/ob-emacs-lisp.el: Document all the function arguments
(org-babel-execute:emacs-lisp):
(org-babel-edit-prep:emacs-lisp): Document all the function arguments
in the docstrings.
2023-09-09 13:57:02 +03:00
Ihor Radchenko 163bafb43d
* lisp/ob-dot.el (org-babel-execute:dot): Document all the function arguments 2023-09-08 12:23:31 +03:00
Ihor Radchenko eed3ac9f78
* lisp/ob-haskell.el (inferior-haskell-root-dir): Declare external variable 2023-09-08 11:11:06 +03:00
Bruno BARBIER 3674e40247
* testing/lisp/test-ob-haskell-ghci.el: Test output without EOL
(ob-haskell/output-without-eol-1):
(ob-haskell/output-without-eol-2):
(ob-haskell/output-without-eol-3): New tests.
2023-09-08 10:59:46 +03:00
Bruno BARBIER 36a786f7f9
ob-haskell: Implement sessions
* lisp/ob-haskell.el (org-babel-haskell-initiate-session): Implement
sessions.
(org-babel-haskell-with-session): New macro to manage sessions.
(org-babel-interpret-haskell): Refactor code.  Use
`org-babel-haskell-with-session` to manage sessions.

* testing/lisp/test-ob-haskell-ghci.el: Update tests related to
sessions.
2023-09-08 10:59:45 +03:00
Bruno BARBIER 924c2dd836
lisp/ob-haskell: Request the last value from GHCi
* lisp/ob-haskell.el (org-babel-interpret-haskell): When the result
type is 'value, use the last value as defined by GHCi.
(org-babel-haskell-eoe): New default value.
(org-babel-interpret-haskell): Update for the new value of `org-babel-haskell-eoe'.

* testing/lisp/test-ob-haskell-ghci.el: Update tests related to output/value.
2023-09-08 10:59:44 +03:00
Ihor Radchenko b852172170
* testing/lisp/test-ob-haskell-ghci.el: Enable fixed tests
(ob-haskell/hello-world-output-multilines):
(ob-haskell/let-multilines-1):
(ob-haskell/let-multilines-2):
(ob-haskell/primes):
(ob-haskell/not-defined-then-defined-1-fixed): Re-enable tests.
2023-09-08 10:59:43 +03:00
Ihor Radchenko d6dd92d442
* testing/lisp/test-ob-haskell-ghci.el: Fix some tests
(ob-haskell/2D-lists-multilines):
(ob-haskell/ghci-info): Fix incorrect test assertions.
2023-09-08 10:59:43 +03:00
Ihor Radchenko 5bffb9a1e3
org-babel-haskell-initiate-session: Remove secondary prompt
* lisp/ob-haskell.el (org-babel-haskell-initiate-session): Set
secondary prompt to "".  If we do not do this, org-comint may treat
secondary prompts as a part of output.
2023-09-08 10:59:42 +03:00
Bruno BARBIER 91c52e2ab6
ob-haskell: Add tests for GHCi
testing/lisp/test-ob-haskell-ghci.el: New file.
2023-09-08 10:59:41 +03:00
Ihor Radchenko 1f88acd013
* lisp/ob-core.el (org-babel-result-cond): Document all the arguments 2023-09-07 15:05:40 +03:00
Nicholas Vollmer 4fe52fc8ac
lisp/ob-lilypond.el: refactor org-babel-lilypond-compile-lilyfile
* ob-lilypond.el (org-babel-lilypond-compile-lilyfile):
Correct compilation message.
Remove superfluous local variables.
Remove unused ad-hoc debugging TEST parameter.

* test-ob-lilypond.el (ob-lilypond/ly-compile-lilyfile):
Locally bind variables which may generate output files.
Refactor to account for removed TEST parameter.
2023-09-06 12:33:35 +03:00
Ihor Radchenko 13e4ee7371
org-babel-comint-with-output: Fix for edge case of `comint-prompt-regexp'
* lisp/ob-comint.el (org-babel-comint-with-output): Implement more
universal algorithm catching agglomerated prompts.  The new approach
works for regexps that match ^, but not as the first char in the
regexp string.
* testing/lisp/test-ob-octave.el (ob-octave/session-multiline): Add
new test.

Reported-by: Paul Stansell <paulstansell@gmail.com>
Link: https://orgmode.org/list/CAMJKaZwuTV-06pPz5nv87CNcoVcqCwFjEodubXTzXs15Q=OFug@mail.gmail.com
2023-09-06 12:19:14 +03:00
Nicholas Vollmer f6fc385ed0
ob-lilypond.el: Fix docstring typos 2023-09-04 10:47:28 +03:00
Jens Schmidt 234650af2e
org-make-tags-matcher: Re-add quoting of property names
* lisp/org.el (org-make-tags-matcher):
* testing/lisp/test-org.el (test-org/map-entries): Move special cased
handling of LEVEL properties.  Add tests for other special cased
properties TODO and CATEGORY.

* lisp/org.el (org-make-tags-matcher):
* doc/org-manual.org (Matching tags and properties):
* testing/lisp/test-org.el (test-org/map-entries): Re-add and extend
quoting of property names in search strings.

Link: https://orgmode.org/list/87h6oq2nu1.fsf@gmail.com
2023-09-03 09:48:41 +03:00
Ihor Radchenko dbf415b840
Revert "org-texinfo--match-definition: Drop redundant `save-match-data'"
This reverts commit e32bd5f7c7.

This is `pcase-let*', not `pcase', so the arguments are _all_
evaluated and match data must be preserved in the ARGS binding.

Link: https://yhetil.org/emacs-devel/877cp8bkpa.fsf@bernoul.li
2023-09-02 20:07:07 +03:00
Ihor Radchenko 21654e9a44
* lisp/ob-core.el (org-babel-examplify-region): Document all the arguments 2023-09-02 12:53:08 +03:00
Ihor Radchenko af9c063edf
* lisp/ob-core.el (org-babel-remove-result): Document function arguments 2023-09-01 14:03:39 +03:00
Ihor Radchenko f97877a069
ox-latex: Prefer :latex-src-block-backend INFO property over variable
* lisp/ox-beamer.el (org-beamer-template):
* lisp/ox-latex.el (org-latex-template): Reuse INFO plist to retrieve
src backend.  Direct usage can break user settings where INFO channel
is expected to be modified and have effect.
2023-09-01 13:42:27 +03:00
Ihor Radchenko 91a532b40e
org-babel-expand-noweb-references: Document all the function arguments
* lisp/ob-core.el (org-babel-expand-noweb-references): Fix the
docstring, documenting every argument.
2023-08-31 14:27:36 +03:00
Ihor Radchenko deb5ea0fc0
ob-ruby: Work around long line input
* lisp/ob-ruby.el (org-babel-ruby-var-to-ruby): Some comint buffers
are not able to process more than 4096 characters in one line - the
rest of the line can be silently ignored.  Work around this by
splitting list vars to multiple lines.

Link: https://orgmode.org/list/87pm3ut3zi.fsf@localhost
2023-08-31 12:47:01 +03:00
Ihor Radchenko db679cff98
* lisp/ob-ruby.el (org-babel-ruby-initiate-session): Fix multiline
Without a newline at the end, repl sometimes does not interpret the
prompt settings correctly.
2023-08-31 12:46:21 +03:00
Ihor Radchenko 83411c0d3e
* lisp/ob-ruby.el (org-babel-ruby-evaluate): Fix eoe indicator 2023-08-31 12:46:09 +03:00
Ihor Radchenko ff53846f31
org-babel-comint-with-output: Fix another edge case with REPL prompts
* lisp/ob-comint.el (org-babel-comint-with-output): Sometimes, REPL
can split whitespace between sequence of prompt prompt prompt.

In particular, inf-ruby did this on multiline input.
2023-08-31 12:42:21 +03:00
Jack Kamm 8000b11209 test-ob-python: Unit test for restarting session
See: https://list.orgmode.org/87ttsnh5bx.fsf@localhost/T/#t

* testing/lisp/test-ob-python.el (test-ob-python/session-restart): New
test for restarting ob-python session process.
2023-08-30 21:48:36 -07:00
Jack Kamm b49275acbe Merge branch 'bugfix' 2023-08-30 21:48:18 -07:00
Ihor Radchenko d8af9c40e0
org-babel-remove-result-one-or-many: Document the prefix argument
* lisp/ob-core.el (org-babel-remove-result-one-or-many): Rename prefix
argument to the conventional ARG and document it in the docstring.
2023-08-30 08:24:11 +03:00
Ihor Radchenko cd0e225e34
* lisp/ob-core.el (org-babel-import-elisp-from-file): Document all function arguments 2023-08-29 12:47:12 +03:00
Ihor Radchenko 3f6c33b7b6
* lisp/ob-core.el (org-babel-temp-stable-file): Document all function arguments 2023-08-29 12:46:58 +03:00
Ihor Radchenko e32bd5f7c7
org-texinfo--match-definition: Drop redundant `save-match-data'
* lisp/ox-texinfo.el (org-texinfo--match-definition): It is safe to
drop `save-match-data' as the function modifies the match data anyway,
and `save-match-data' does not affect anything else.
2023-08-29 12:38:04 +03:00
Ihor Radchenko f02b4c8b4d
org-refile-get-targets: Improve malformed target handling
* lisp/org-refile.el (org-refile-get-targets): Throw better errors
when `org-refile-targets' value is malformed.  Allow common mistake
with not using a cons cell in the target description.
2023-08-27 15:18:12 +03:00
Ihor Radchenko 320c29c021
* lisp/ob-core.el (org-babel-remove-inline-result): Document DATUM argument 2023-08-27 14:04:25 +03:00
Ihor Radchenko 9f12a1b9e4
org-babel-map-executables: Avoid using `save-match-data'
* lisp/ob-core.el (org-babel-map-executables): Drop
`save-match-data' as it may be costly.
2023-08-27 13:10:44 +03:00
Ihor Radchenko 05064052ad
org-babel-map-call-lines: Avoid using `save-match-data'
* lisp/ob-core.el (org-babel-map-call-lines): Drop
`save-match-data' as it may be costly.
2023-08-27 13:10:26 +03:00
Ihor Radchenko 99b65bb212
org-babel-map-inline-src-blocks: Avoid using `save-match-data'
* lisp/ob-core.el (org-babel-map-inline-src-blocks): Drop
`save-match-data' as it may be costly.
2023-08-27 13:09:51 +03:00
Ihor Radchenko b22ebf8c78
Merge branch 'bugfix' 2023-08-27 11:21:25 +03:00
Ihor Radchenko 1dcde9889b
Merge branch 'bugfix' 2023-08-26 19:13:33 +03:00
Ihor Radchenko b3c7ebecac
* lisp/ob-core.el (org-babel-format-result): Document SEP argument 2023-08-26 15:06:20 +03:00
Ihor Radchenko f299fbbbb0
org-export--prepare-file-contents: Drop redundant `save-match-data'
`save-match-data' is costly.  We should not use it unless necessary.
2023-08-26 14:29:17 +03:00
Ihor Radchenko 99c40177ad
org-babel-demarcate-block: Document prefix argument in the docstring 2023-08-25 14:26:44 +03:00
Ihor Radchenko 5ff5ac03b6
* lisp/ox.el (org-export-parse-include-value): Remove `save-match-data'
Avoid using GC-expensive `save-match-data'.
2023-08-25 14:13:23 +03:00
Ihor Radchenko 0ceb562b33
org-fold-core--specs: Remove wrong ":alias" alias
* lisp/org-fold-core.el (org-fold-core-get-folding-spec-from-alias):
Do not put ":alias" as an actual alias.  The code did not account that
`assq' returns the whole cons cell, not just value of the alist item.
2023-08-25 11:33:29 +03:00
Nicholas Vollmer 538ddecb30
* lisp/ob-lilypond.el: Satisfy checkdoc
(org-babel-lilypond-compile-post-tangle):
(org-babel-lilypond-display-pdf-post-tangle):
(org-babel-lilypond-play-midi-post-tangle):
(org-babel-execute:lilypond):
(org-babel-lilypond-tangle):
(org-babel-lilypond-process-basic):
(org-babel-lilypond-parse-line-num):
(org-babel-lilypond-set-header-args):
Fix docstring
2023-08-25 10:56:50 +03:00
Ihor Radchenko fcca762741
* testing/lisp/test-ob-clojure.el: Remove incorrect tests (all the tests)
("cider"): Remove assertions for cider.  Clojure supports more than cider.
(ob-clojure/simple-session):
(ob-clojure/initiate-session):
(ob-clojure/initiate-session-with-var): Remove session tests -
ob-clojure has no session support.
(ob-clojure/tangle-without-ns): Remove tangle test - it has no
relation to ob-clojure.

Add FIXME to implement some tests, as we end up with 0 ob-clojure
tests after this commit.

Link: https://orgmode.org/list/87v8d4ivqh.fsf@localhost
2023-08-25 10:46:36 +03:00
Ihor Radchenko 7bdec435ff
org-export-expand-include-keyword: Drop unnecessary call to `save-match-data'
* lisp/ox.el (org-export-expand-include-keyword): Do not wrap
`org-element-at-point' into `save-match-data'.  The search data from
`re-search-forward' is unused in the code and `save-match-data' call
is costly.
2023-08-24 15:10:32 +03:00
Ihor Radchenko d5ee33fed8
lisp/ob-core: List all the arguments in some docstrings
* lisp/ob-core.el (org-babel-parse-multiple-vars):
(org-babel-goto-named-src-block):
(org-babel-goto-named-result): Describe all the function arguments in
the docstring.
2023-08-24 13:27:58 +03:00
Ihor Radchenko 85c94ecfc2
ox-latex: Improve warning for unexpected org-latex-src-block-backend
* lisp/ox-latex.el (org-latex-inline-src-block):
(org-latex-src-block): Update the warning text, explicitly mentioning
the variable name to be adjusted.

Reported-by: Guillaume MULLER <guillaume.muller@emse.fr>
Link: https://orgmode.org/list/b5c056cb-3258-4a11-2d9b-33c97b112d62@emse.fr
2023-08-24 10:37:52 +03:00
Ihor Radchenko 3c3db7b337
oc-basic: Fix detecting changes in symlinked bibliography
* lisp/oc-basic.el (org-cite-basic--parse-bibliography): Use
`file-truename' to follow symlinks first before checking bibliography
file change times.

Reported-by: Leo Butler <Leo.Butler@umanitoba.ca>
Link: https://orgmode.org/list/877cpmkds1.fsf@t14.reltub.ca
2023-08-24 10:21:21 +03:00
Ihor Radchenko 1665283f25
Merge branch 'bugfix' 2023-08-24 10:18:02 +03:00
Ihor Radchenko 5e7427c6d1
* lisp/ob-core.el (org-babel-hide-result-toggle): Document FORCE argument 2023-08-23 14:24:53 +03:00
Ihor Radchenko 430c72924c
ob-ruby: Fix ruby tests
* lisp/ob-ruby.el (org-babel-ruby-prompt):
(org-babel-ruby-define-prompt): New variables used to set appropriate
unique prompt and disable echo in session.
(org-babel-ruby-initiate-session): Setup prompt and echo during
session initialization.
(org-babel-ruby-evaluate): Rely on `org-babel-ruby-initiate-session'
to setup prompt and echo.  Re-setting the prompt back after every
evaluation can be tricky because of async nature of the prompt, so it
is now dropped.
2023-08-23 14:19:52 +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
Jack Kamm 579e8c5723 ob-python: Results handling for dicts, dataframes, arrays, plots
Thanks to Ihor Radchenko and Liu Hui for valuable feedback on this
patch.

* lisp/ob-python.el (org-babel-execute:python): Parse graphics-file
from params, and pass it to `org-babel-python-evaluate'.
(org-babel-python--output-graphics-wrapper): New constant.  Python
code to save graphical output.
(org-babel-python--def-format-value): New constant.  Python function
to format and save value results to file.  Includes handling for
graphics, dataframes, and arrays.
(org-babel-python-table-or-string): Prevent `org-babel-script-escape'
from mangling dict results.
(org-babel-python--setup-session): New function to
run setup code within Python session.
(org-babel-python-initiate-session-by-key): Replace lambda with
`org-babel-python--setup-session' in `python-shell-first-prompt-hook',
or run it directly if the session was started outside Org.
(org-babel-python-wrapper-method): Removed.  Instead use part of the
string directly in `org-babel-python-evaluate-external-process'.
(org-babel-python-pp-wrapper-method): Removed.  Pretty printing is now
handled by `org-babel-python--def-format-value'.
(org-babel-python--exec-tmpfile): Removed.  Instead use the raw string
directly in `org-babel-python-evaluate-session'.
(org-babel-python-format-session-value): Updated to use
`org-babel-python--def-format-value' for formatting value result.
(org-babel-python-evaluate): New parameter graphics-file.  Pass
graphics-file onto downstream helper functions.
(org-babel-python-evaluate-external-process): New parameter
graphics-file.  Use `org-babel-python--output-graphics-wrapper' for
graphical output.  For value result, use
`org-babel-python--def-format-value'.  Don't call `org-trim' on
results, to prevent misalignment of pandas DataFrames.
(org-babel-python-evaluate-session): New parameter graphics-file.  Use
`org-babel-python--output-graphics-wrapper' for graphical output.
Replace the removed constant `org-babel-python--exec-tmpfile' with the
string directly.  Rename local variable tmp-results-file to
results-file, which may take the value of graphics-file when provided.
(org-babel-python-async-evaluate-session): New parameter
graphics-file.  Use `org-babel-python--output-graphics-wrapper' for
graphical output.  Rename local variable tmp-results-file to
results-file, which may take the value of graphics-file when provided.
2023-08-22 16:22:17 -07: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 80ae8462a6
org-element--standard-properties: Re-order, putting boundaries in order
* lisp/org-element-ast.el (org-element--standard-properties): Re-order
the properties, making the element boundaries in order as they will
appear in buffer.  Re-group other properties.
2023-08-22 11:23:16 +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 168b99ba94
org-babel-join-splits-near-ch: Fix the docstring
* lisp/ob-core.el (org-babel-join-splits-near-ch): Explain all the
arguments and what the function does.
2023-08-21 13:01:54 +03:00
Ihor Radchenko 680138d7ff
fixup! test-org-colview/...: Fix Emacs 28 compatibility 2023-08-21 12:58:44 +03:00
Ihor Radchenko 8b35734b49
test-org-colview/...: Fix Emacs 28 compatibility
*
testing/lisp/test-org-colview.el (test-org-colview/columns--move-row-stay-at-the-same-column):
Skip the test in Emacs <29 where it is not possible to determine
visual column.
2023-08-21 10:21:33 +03:00
Ihor Radchenko 299193bf09
org-display-remote-inline-images: Add new allowed value t
* lisp/org.el (org-display-remote-inline-images): Allow value t as
alias to cache.
(org--create-inline-image): Handle t value.
2023-08-20 14:15:49 +03:00
Ihor Radchenko e08d878314
org-columns-redo: Fix when `org-columns' is called with prefix arg
* lisp/org-colview.el (org-columns-global): New buffer-local variable
holding GLOBAL argument to `org-columns'.
(org-columns): Record the GLOBAL arg.
(org-columns-redo): Fix `org-columns' call, using
`funcall-interactively' and passing GLOBAL arg as well.  The previous
usage of `call-interactively' made no sense because
`org-column-current-fmt' would not be passed as an argument -
`call-interactively' does not allow passing arguments.

Link: https://orgmode.org/list/877culo1pb.fsf@localhost
2023-08-20 13:39:50 +03:00
Sławomir Grochowski 650e42996e
lisp/org-colview.el: Add new commands to move column view table row
* doc/org-manual.org (org-columns-move-row-up,
org-columns-move-row-down, org-columns-move-left,
org-columns-move-right): Document two new and two old commands.
* etc/ORG-NEWS (New commands to move rows up & down): Document the new
feature.
* lisp/org-colview.el (org-columns--move-row, org-columns-move-row-up,
org-columns-move-row-down): New functions.
* testing/lisp/test-org-colview.el (test-org-colview/columns-move-row-down,
test-org-colview/columns-move-row-up,
test-org-colview/columns--move-row-stay-at-the-same-column,
test-org-colview/columns-move-row-down-with-subheading): New tests.
2023-08-20 13:39:47 +03:00
Ihor Radchenko 58c5c5882c
org-columns: Fix when adding spaces to headings
* lisp/org-colview.el (org-columns): Use markers to store collected
column headline value positions.  This is necessary because
`org-columns--display-here' may modify buffer, invalidating headline
positions returned by `org-scan-tags'.

Reported-by: Jakob Schöttl <jschoett@gmail.com>
Link: https://orgmode.org/list/831f07e0-d86a-a0dc-c967-e48906f520a1@gmail.com
2023-08-20 11:54:20 +03:00
Ihor Radchenko 06714dea79
org-babel-current-result-hash: Mark unused argument
* lisp/ob-core.el (org-babel-current-result-hash): Mark INFO argument
as unused.  `org-babel-where-is-src-block-results' does not use INFO
argument even when passed.
2023-08-20 11:45:04 +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 dd2f05f592
fixup! fixup! org-insert-heading: Fix when folded text is kept right at the new heading 2023-08-20 09:43:25 +03:00
Ihor Radchenko 7a4784b122
org-fast-tag-selection: Fix when C-g is pressed
* lisp/org.el (org-fast-tag-selection): Fix "no catch" error.  But do
not directly set `quit-flag' as it was done in the earlier versions.
Instead, call `keyboard-quit', allowing it to perform the necessary
cleanups.
2023-08-20 09:36:40 +03:00
Ihor Radchenko e17ca87994
Merge branch 'bugfix' 2023-08-20 09:30:59 +03:00
Ihor Radchenko 35960e1614
org-babel-execute-subtree: Document the argument in the docstring
* lisp/ob-core.el (org-babel-execute-subtree): Clarify the meaning of
command argument in the docstring.
2023-08-19 12:47:53 +03:00
Ihor Radchenko bbdf9781c2
test-org/insert-todo-heading-respect-content: Fix tests
*
testing/lisp/test-org.el (test-org/insert-todo-heading-respect-content):
Do not assert newline after newly added heading.  See 52bc95676.
2023-08-19 12:16:36 +03:00
Ihor Radchenko 54f8b0bfd0
Merge branch 'bugfix' 2023-08-19 10:55:08 +03:00
Ihor Radchenko 928f2d7fb0
Revert "org-return: Do not insert inside folded region"
This reverts commit a25d00d5df.

Direct call to `org-fold-check-before-invisible-edit' is no longer
necessary on main.  We use `org-fold-catch-invisible-edits-commands'.
2023-08-19 10:27:09 +03:00
Ihor Radchenko 73e332a307
Merge branch 'bugfix' 2023-08-19 10:27:00 +03:00
Ihor Radchenko 3cbd9f4233
org-lint: New checker for SCHEDULED/DEADLINE with inactive timestamp
* lisp/org-lint.el (org-lint-inactive-planning): Add new checker.

Link: https://orgmode.org/list/875y5tlouo.fsf@localhost
2023-08-18 15:21:10 +03:00
Ihor Radchenko 7cc208af91
org-agenda: Do not err on SCHEDULED/DEADLINE with inactive timestamp
* lisp/org-agenda.el (org-agenda-get-deadlines):
(org-agenda-get-scheduled): Ignore SCHEDULED/DEADLINE set to inactive
timestamps.  Previously, an error would be thrown.

Reported-by: Christian Barthel <bch@online.de>
Link: https://orgmode.org/list/875y5tlouo.fsf@localhost
2023-08-18 15:19:25 +03:00
Ihor Radchenko d560a2d739
org-lint-invalid-id-link: Only update ID locations if there are ID links
* lisp/org-lint.el (org-lint-invalid-id-link): Avoid running
`org-id-update-id-locations' when there are no ID links in the linted
file.
2023-08-18 15:18:50 +03:00
Ihor Radchenko 83fd03fb6d
org-attach: Fix when called from agenda
* lisp/org-attach.el (org-attach): Do not try to call `org-attach-dir'
from non-Org buffer.  This requires parser, which cannot run in agenda
buffer.
2023-08-18 13:24:13 +03:00
Ihor Radchenko 79aa149143
org-babel-map-executable: Describe header arg in the docstring
* lisp/ob-core.el (org-babel-execute-buffer): Mention in the docstring
how prefix argument is handled.
2023-08-18 13:15:10 +03:00
Ihor Radchenko b3660cf135
* testing/lisp/test-org-attach-git.el: Avoid using global git config
(test-org-attach-git/with-annex): Disable global git config during
testing.
2023-08-18 12:03:58 +03:00
Juan Manuel Macias 2eb4fd8900
lisp/ox-latex.el: Add the `:literal' attribute to verse block.
* (org-latex-verse-block): Now the treatment of blank lines is
consistent with the syntax of the LaTeX `verse' environment, and the
one provided by the `verse' package.  If the `:literal' attribute is
used, all blank lines are preserved and exported as
`\vspace*{\baselineskip}', including the blank lines before or after
contents.  The rx code has been suggested by Ihor Radchenko, to
improve readability.

* doc/org-manual.org (Verse blocks in LaTeX export): The new feature
is documented.

* testing/lisp/test-ox-latex.el (test-ox-latex/verse): Updated.
2023-08-18 11:41:24 +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 3ec0933122
Fix Emacs 27 test failure
* lisp/org-id.el (org-id-find-id-in-file): Work around change
functions not always firing up in Emacs 27 when using
`insert-file-contents'.
2023-08-18 11:10:12 +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 9e40208547
test-org-agenda/todo-selector: Remove stray `message' call
* testing/lisp/test-org-agenda.el: Remove leftover message call.
2023-08-18 11:08:12 +03:00
Ihor Radchenko 3b49db8755
Revert "Prefer `string-search' when matching exact strings"
This reverts commit e9110a8dd7.

`string-search' is not available in Emacs<28 and also always
case-sensitive.
2023-08-18 11:00:13 +03:00
Ihor Radchenko d0c7cd48eb
org-babel-do-key-sequence-in-edit-buffer: Mention argument in docstring
* lisp/ob-core.el (org-babel-do-key-sequence-in-edit-buffer): Mention
argument KEY in the docstring.
2023-08-17 15:54:20 +03:00
Ihor Radchenko 1ae611c7e3
fixup! org-id-find-id-in-file: Prefer using temporary buffer
* lisp/org-id.el (org-id-find-id-in-file): Fix Emacs 27 compatibility.
Avoid modifications not captured by element cache.
2023-08-17 15:45:13 +03:00
Ihor Radchenko d1e4b93519
org-copy-subtree: Do not consider inlinetask to be a subtree of its own
* lisp/org.el (org-copy-subtree): Go up to parent heading when we are
at or inside inlinetask.
2023-08-17 14:25:43 +03:00
Ihor Radchenko f285ae37b3
org-agenda-get-todos: Fix for todo keywords that can be interpreted as regexp
* lisp/org-agenda.el (org-agenda-get-todos): Use `regexp-quote' to
match keywords.
(org-select-this-todo-keyword): Add docstring, clarifying the allowed
values.
* testing/lisp/test-org-agenda.el (test-org-agenda/todo-selector): Add
new test.

Reported-by: spookygostee@gmail.com
Link: https://orgmode.org/list/87jztuzzpl.fsf@gmail.com
2023-08-17 14:15:14 +03:00
Jonathan Gregory f78a3c2bdc
lisp/ob-lilypond.el: Prevent full page results in basic-mode
* ob-lilypond.el (org-babel-lilypond-paper-settings): New variable.
* lisp/ob-lilypond.el (org-babel-lilypond-process-basic): Pass the new
variable value to correctly set paper size on the generated transcript.

Link: https://list.orgmode.org/87a5w15jur.fsf@localhost/

TINYCHANGE
2023-08-17 13:20:08 +03:00
Ihor Radchenko b2e34474f5
org-lint: Allow jumping outside narrowing when jumping to source
* lisp/org-lint.el (org-lint--jump-to-source): When buffer is
narrowed and the location to jump is outside the narrowing, widen.
2023-08-17 12:50:52 +03:00
Ihor Radchenko 2cf245810b
org-lint-invalid-id-link: Improve performance
* lisp/org-lint.el (org-lint-invalid-id-link): Do not try to search
for exact position of every ID.  Instead, sync all the ID locations
once and then make use of the up-to-date locations state to query if
an ID is present.
2023-08-17 12:49:59 +03:00
Ihor Radchenko 4cf0b0433d
org-id-find-id-in-file: Prefer using temporary buffer
* lisp/org-id.el (org-id-find-id-in-file): Use a temporary throwaway
Org buffer to lookup IDs when we do not need to keep the buffer.  This
speeds up updating IDs.
2023-08-17 12:48:52 +03:00
Ihor Radchenko cc435cba71
lisp/ob-core.el: Fix some docstrings that do not detail all the arguments
* lisp/ob-core.el (org-babel-initiate-session):
(org-babel-switch-to-session):
(org-babel-switch-to-session-with-code): Explain all the arguments in
the docstring.
2023-08-16 13:32:06 +03:00
Ihor Radchenko e4504853b5
Merge branch 'bugfix' 2023-08-16 11:43:12 +03:00
Ihor Radchenko 9fd547dd3a
org-babel-where-is-src-block-result: Fix inside affiliated parsed keyword
* lisp/ob-core.el (org-babel-where-is-src-block-result): Do not assume
that parent has contents-end and that we are inside contents, but not
inside secondary object/affiliated keyword.
*
testing/lisp/test-ob.el (test-ob/inline-src_blk-default-results-replace-line-1):
Add tests.

Reported-by: Tom Gillespie <tgbugs@gmail.com>
Link: https://orgmode.org/list/CA+G3_PNt7WqkCzChV+dx1FeSPgTEVkNSE41a3qC5wv3g+jTwrQ@mail.gmail.com
2023-08-16 11:07:20 +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 99c8425bc7
org-babel-insert-result: Remove duplicate let-binding
* lisp/ob-core.el (org-babel-insert-result): Remove duplicate
computation of the INLINE value.
2023-08-16 11:05:31 +03:00
Ihor Radchenko 487f39efa6
org-babel-insert-result: Err on :results drawer inline src block
* lisp/ob-core.el (org-babel-insert-result): Throw an error when
trying to insert :results drawer in inline src blocks.
2023-08-16 11:04:14 +03:00
Ihor Radchenko 5496f5277f
org-babel-load-in-session: Document argument INFO
* lisp/ob-core.el (org-babel-load-in-session): Update the docstring,
describing what INFO argument does.
2023-08-15 14:50:58 +03:00
Ihor Radchenko 570cdacdbf
org-export-smart-quotes-alist: Turn into a custom option
* lisp/ox.el (org-export-smart-quotes-alist): Change to `defcustom'.
Fix typo in the value.  Add :type/:package-version/:group definitions.
* etc/ORG-NEWS (~org-export-smart-quotes-alist~ is now a custom
option): Announce the change.

Link: https://orgmode.org/list/871qg5bnfh.fsf@bzg.fr
2023-08-15 14:16:41 +03:00
Ihor Radchenko 1d04af59b6
org-refile-get-targets: Barf when target is not an Org buffer
* lisp/org-refile.el (org-refile-get-targets): Display error when
target buffer is not in Org mode.  If we do not manually throw an
error, local variables like `org-complex-heading-regexp' will not be
defined, and the user would see a lot more cryptic error.
2023-08-15 13:54:00 +03:00
Ihor Radchenko dcd2ba4a02
* lisp/org-macs.el: Declare `org-buffer-text-pixel-width' 2023-08-15 13:49:02 +03:00
Ihor Radchenko 6954fe93ed
org-store-link: Never allow link duplicates in `org-stored-links'
* lisp/ol.el (org-link-store-existing): Remove the previously added
custom option.
(org-store-link): Do not use `org-link-store-existing' removing all
the code branches for values other than 'move-to-front.
* etc/ORG-NEWS (~org-store-link~ now moves an already stored link to
front of the ~org-stored-links~): Remove reference to the removed
custom option.

Link: https://orgmode.org/list/87leeffd1z.fsf@localhost
2023-08-15 13:48:55 +03:00
Ihor Radchenko 1c00632f11
org-latex-compile--postprocess: Fix when OUTFILE has no directory
* lisp/ox-latex.el: Make sure that we do not pass nil to
`directory-files'.  Use `default-directory' when OUTFILE is like
"file.foo" without any directory component.
2023-08-15 13:13:44 +03:00
Ihor Radchenko 572d01ab7e
Merge branch 'bugfix' 2023-08-15 12:59:18 +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 b89bc55867
org-babel-insert-header-arg: Describe arguments in the docstring
* lisp/ob-core.el (org-babel-insert-header-arg): Fix the docstring,
describing when the arguments do.
2023-08-14 14:59:11 +03:00
Ihor Radchenko 34ee6f1a21
Merge branch 'bugfix' 2023-08-13 19:24:50 +03:00
Ihor Radchenko 36dcb2a23c
org-babel-combine-header-arg-lists: Describe arguments in the docstring
* lisp/ob-core.el (org-babel-combine-header-arg-lists): Describe all
the header arguments in the docstring.
2023-08-13 13:35:53 +03:00
Ihor Radchenko a0830f94ea
* testing/org-test.el: Avoid looking into .emacs.d when ran non-interactively
(org-test-load):
(org-test-update-id-locations): Set `org-id-locations-file' inside
test dir, but only when running in batch mode.

Reported-by: Morgan Smith <Morgan.J.Smith@outlook.com>
Link: https://orgmode.org/list/ub84qp$6pu$1@ciao.gmane.io
2023-08-13 11:28:32 +03:00
Ihor Radchenko 70a082c9fb
org-babel-expand-src-block: Mention all the header arguments in the docstring
* lisp/ob-core.el (org-babel-expand-src-block): Explain all the header
arguments in the docstring.
2023-08-12 12:06:12 +03:00
Ihor Radchenko 051c929d65
* mk/default.mk: Enable ob-sqlite and ob-eshell tests by default
(BTEST_OB_LANGUAGES): Add more tests to be executed by default.
2023-08-12 11:20:48 +03:00
Ihor Radchenko b5aaefb551
org-babel-variable-assignments:eshell: Prevent leaking values into results
* lisp/ob-eshell.el (org-babel-variable-assignments:eshell): Wrap
`setq' eshell call into `ignore' to prevent the variable assignment
values leaking into block output.  Fixes
`ob-eshell/variables-assignment'.
2023-08-12 11:17:15 +03:00
Rudolf Adamkovič 68aa438857
ob-sqlite: Use a transient in-memory database by default
* etc/ORG-NEWS (New features): Add a news entry.
* lisp/ob-sqlite.el (org-babel-execute:sqlite): Default ':db' to
":memory:" instead of throwing an error.
* testing/lisp/test-ob-sqlite.el (ob-sqlite/in-file): Test the old behavior.
* testing/lisp/test-ob-sqlite.el (ob-sqlite/in-memory): Test the new behavior.
2023-08-12 11:00:48 +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 cfea24dc15
org-babel-expand-body:generic: Document all the arguments in the docstring
* lisp/ob-core.el (org-babel-expand-body:generic): Document VAR-LINES
in the docstring.
2023-08-11 14:22:28 +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 85b74750eb
etc/ORG-NEWS: Fix typo
* etc/ORG-NEWS (New property accessors and setters): Fix property names.
2023-08-11 12:07:29 +03:00
Ihor Radchenko 695fbc9086
fixup! test-ox-html: Add new tests for checkboxes: ascii, html & unicode
* testing/lisp/test-ox-html.el (ox-html/checkbox-ascii):
(ox-html/checkbox-html):
(ox-html/checkbox-unicode): Pass BEG and END arguments to
`libxml-parse-xml-region'.  They are mandatory in Emacs <29.
2023-08-10 15:47:30 +03:00
Ihor Radchenko 0eb9aa798c
* lisp/ob-R.el: Fix some checkdoc warnings
(org-babel-execute:R):
(org-babel-variable-assignments:R):
(org-babel-R-initiate-session): Mention all the argument in the
docstring.
2023-08-10 13:58:14 +03:00
Hraban Luyat 39ae2eda5b
test-ox-html: Add new tests for postamble format
* testing/lisp/test-ox-html.el (ox-html/postamble-default):
(ox-html/postamble-custom):
(ox-html/postamble-custom-format):
(ox-html/postamble-none):
(ox-html/postamble-format-wrong-config):
(ox-html/postamble-format-proper-config):
(ox-html/postamble-format-conflict):
(ox-html/postamble-format-author): New tests.
2023-08-10 12:41:35 +03:00
Hraban Luyat 003927a594
test-ox-html: Add new tests for checkboxes: ascii, html & unicode
* testing/lisp/test-ox-html.el (ox-html/checkbox-ascii):
(ox-html/checkbox-html):
(ox-html/checkbox-unicode): New tests.
2023-08-10 12:35:34 +03:00
Ihor Radchenko f80c824040
* doc/org-manual.org: Clarify that org-emphasis-alist does not affect parser
(Emphasis and Monospace): Clarify that modifying `org-emphasis-alist'
does not affect parser; just the fontification.
2023-08-09 12:52:53 +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
Ihor Radchenko 8ed3887821
etc/ORG-NEWS: Clarify that `org-element-property' can be used with deferred
* etc/ORG-NEWS (Internal structure of Org parse tree has been
changed): Clarify when one needs to adjust for the breaking change
introducing deferred properties.
2023-08-09 10:26:35 +03:00
Ihor Radchenko f159adc269
org-element-property: Improve docstring
* lisp/org-element-ast.el (org-element-property): Clarify the meaning
of FORCE-UNDEFER argument.
2023-08-09 10:26:11 +03:00
Ihor Radchenko a18ebc7893
Revert "Avoid creating ID property during tangling"
This reverts commit 0b4e357d62.

The original bug report actually does not need special handling
because (1) some people actually want the "fixed" behavior with IDs
being created; (2) people who don't can set org-id-link-to-org-use-id
to 'create-if-interactive.

See https://orgmode.org/list/87v8e3p5fv.fsf@localhost
2023-08-08 15:54:56 +03:00
Ihor Radchenko 173b5de0ec
testing: Re-introduce more useful new tests instead of deleted dupllicates
* testing/lisp/test-ol.el (test-org-link/store-link):
* testing/lisp/test-org-table.el (test-org-table/get-field):
* testing/lisp/test-org.el (test-org/auto-fill-function): Add modified
version of the removed test duplicates, according to their likely
original intention.

Link: https://orgmode.org/list/87cz0wyw9m.fsf@localhost
2023-08-08 15:40:59 +03:00
Ilya Chernyshov fe85d61a92
testing: Delete duplicate tests
* testing/lisp/test-ol.el (test-org-link/store-link): Delete a duplicate test.

* testing/lisp/test-org-clock.el (test-org-clock/clocktable/properties): Delete a duplicate test.

* testing/lisp/test-org-element.el (test-org-element/link-parser,
test-org-element/timestamp-parser): Delete duplicate tests.

* testing/lisp/test-org-table.el (test-org-table/get-field): Delete a duplicate test.

* testing/lisp/test-org.el (test-org/auto-fill-function): Delete a duplicate test.
2023-08-08 15:33:06 +03:00
Ihor Radchenko 3780948905
lisp/ob-ditaa.el: Fix checkdoc warnings
* lisp/ob-ditaa.el (org-babel-execute:ditaa): Mention all the
arguments in the docstring.  Start error message from capital letter.
2023-08-08 12:38:14 +03:00
Jens Schmidt f689eb44f1
org-make-tags-matcher: Add starred property operators, fix quoting
* lisp/org.el (org-make-tags-matcher): Add starred property operators.
Recognize additional operators "==", "!=", "/=".  Clean up and
document match term parsing.  Remove needless and buggy unquoting of
minus characters in property and tag names.
(org-op-to-function): Recognize additional inequality operator "/=".

* doc/org-manual.org (Matching tags and properties): Add documentation
on starred and additional operators.  Document allowed characters in
property names and handling of minus characters in property names.

* testing/lisp/test-org.el (test-org/map-entries): Add tests for
starred and additional operators.  Add tests for property names
containing minus characters.

* etc/ORG-NEWS: (~org-tags-view~ supports more property operators):
Add announcement on starred and additional operators.

Link: https://orgmode.org/list/9132e58f-d89e-f7df-bbe4-43d53a2367d2@vodafonemail.de
2023-08-08 10:01:00 +03:00
Ihor Radchenko f9e083086f
Merge branch 'bugfix' 2023-08-07 14:59:17 +03:00
Ihor Radchenko 30b747b86d
org-babel-execute:css: Mention arguments in the docstring
* lisp/ob-css.el (org-babel-execute:css): Fix docstring.
2023-08-06 12:10:21 +03:00
Ihor Radchenko f4fecc244c
doc/org-manual.org: Refer to LaTeX docs for general terminology
* doc/org-manual.org (LaTeX Export): Add links to online and offline
LaTeX docs.
(Quoting LaTeX code): Clarify that direct LaTeX can be used for
fine-tuning.

Link: https://orgmode.org/list/SJ0PR03MB5455B2712FA85BA945DFF441A20BA@SJ0PR03MB5455.namprd03.prod.outlook.com
2023-08-06 11:03:10 +03:00
Ihor Radchenko da8fabf464
org-delete-indentation: Fix Emacs 26 compatibility
* lisp/org.el (org-delete-indentation): `delete-indentation' in Emacs
26 does not yet accept region boundaries.  Provide compatibility
fallback.
2023-08-06 10:22:18 +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 c7e1f78326
Merge branch 'bugfix' 2023-08-05 16:17:35 +03:00
Ihor Radchenko 8dfd8c987c
org-format-latex: Add FIXME
* lisp/org.el (org-format-latex): Mark `overlay-recenter' call for
removal after Emacs 28 support is dropped.
2023-08-05 16:14:25 +03:00
Ihor Radchenko 0a5dd8cf68
org-babel--file-desc: Update docstring
* lisp/ob-core.el (org-babel--file-desc): Describe all the argument in
the docstring and clarify what the function returns.
2023-08-05 15:09:59 +03:00
Ihor Radchenko 222fdf9c57
Merge branch 'bugfix' 2023-08-05 14:00:18 +03:00
Ihor Radchenko 764a306cae
Merge branch 'bugfix' 2023-08-05 11:16:01 +03:00
Ihor Radchenko 5e378a6e13
org-capture-template-contexts: Improve docstring
* lisp/org-capture.el (org-capture-templates-contexts): Clarify that
function context definition is not a cons cell using example.
2023-08-05 09:53:13 +03:00
Ihor Radchenko 8d6ec48b84
org-end-of-subtree: Fix when inside inlinetask
* lisp/org.el (org-end-of-subtree): Do not consider inlinetasks as
dedicated subtrees.
* testing/lisp/test-org.el (test-org/end-of-subtree): New test.
2023-08-05 09:48:10 +03:00
Bastien 73cb528c24 Merge branch 'bugfix' 2023-08-04 13:08:25 +02:00
Ihor Radchenko 8dc71d915e
lisp/ob-core.el: Fix some checkdoc warnings
* lisp/ob-core.el (org-babel-where-is-src-block-head): Quote
`match-data'.
(org-babel-insert-result): Ensure two spaces between sentences.
(org-babel-temp-file): Clarify that `temporary-file-directory' refers
to a function.
2023-08-04 11:33:33 +03:00
Ihor Radchenko 6eb117da06
* lisp/ob-core.el (org-babel--expand-body): Document all the arguments 2023-08-04 11:33:18 +03:00
Ihor Radchenko 4fb8ad9990
lisp/ob-core.el: Add some missing docstrings
* lisp/ob-core.el (org-babel-execute-safely-maybe):
(org-babel-execute-maybe):
(org-babel-active-location-p): Add docstrings.
2023-08-04 11:33:01 +03:00
Ihor Radchenko 47b04383e7
fixup! org-id-update-id-locations: Optimize performance
Avoid modifying FILES by side effect.
2023-08-04 10:54:19 +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 f5467b53ec
lisp/ob-shell.el: Fix sessions for generic "shell" blocks
* lisp/ob-shell.el (org-babel-prompt-command): Remove variable.
(org-babel-sh-initiate-session): Set prompt according to
`shell-file-name' - either the value set in let-binding provided by
`org-babel-shell-initialize' or using the default Emacs value of
`shell-file-name'.
(org-babel-shell-initialize): Do not set `org-babel-prompt-command'.
Only let-bind `shell-file-name' according to shell variant in src
block.
2023-08-04 09:30:47 +03:00
Ihor Radchenko 5ed2763b15
org-id-update-id-locations: Optimize performance
* lisp/org-id.el (org-id--locations-checksum): New internal variable
holding list of files and their modification times for the last known
ID list.
(org-id-update-id-locations): Do nothing when the ID locations
correspond to the same ID file list and modification times.  Convert
SEEN-IDS to hash table for faster lookup of the duplicates.  Re-enable
element cache.  Avoid queries to heading properties that would force
full parsing.
2023-08-03 16:52:04 +03:00
Ihor Radchenko b11894aa55
org-lint: Use markers instead of line number to track report positions
* lisp/org-lint.el (org-lint--generate-reports): Store marker to
reports as text property in the Line field.
(org-lint--current-marker): New function retrieving marker
corresponding to current report.
(org-lint--jump-to-source): Jump using marker, not line number.

This fixes *Org Lint* report jumping to wrong location when the Org
buffer is edited while going through the report.
2023-08-03 16:03:56 +03:00
Ihor Radchenko 8b9e3be9a9
* lisp/ob-comint.el (org-babel-comint-async-dangling): Fix docstring
Make first line a complete sentence.
2023-08-03 11:45:15 +03:00
Ihor Radchenko 2c4c5fdd8b
Merge branch 'bugfix' 2023-08-03 08:29:54 +03:00
Ihor Radchenko 63e8cac2ca
org-goto-sibling: Fix when called from inlinetask
* lisp/org.el (org-goto-sibling): Do not try to find inlinetask
siblings.  Clarify the docstring.
* testing/lisp/test-org.el (test-org/goto-sibling): New test.
2023-08-02 16:06:02 +03:00
Ihor Radchenko 345d4e09b5
org-insert-drawer: Make sure that point is left inside drawer
* lisp/org.el (org-insert-drawer): Leave and reveal point inside
drawer even when we insert property drawer or drawer around region, as
advertised by the docstring.
2023-08-02 15:42:53 +03:00
Ihor Radchenko 83575624ab
Ensure that clocking drawer is inserted before point
* lisp/org-clock.el (org-clock-find-position): Insert before point
when creating drawers.  This makes sure that newly inserted drawer do
not interfere with user typing.  See f993ecd67.
* lisp/org-clock.el (org-clock-in): Add commentary.
2023-08-02 15:23:06 +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 8e2f6d94e9
ob-C: Fix docstrings
* lisp/ob-C.el (org-babel-execute:cpp):
(org-babel-expand-body:cpp):
(org-babel-execute:C++):
(org-babel-expand-body:C++):
(org-babel-execute:D):
(org-babel-expand-body:D):
(org-babel-execute:C):
(org-babel-expand-body:C):
(org-babel-C-execute):
(org-babel-C-expand-C++):
(org-babel-C-expand-C):
(org-babel-C-expand-D):
(org-babel-C-val-to-base-type):
(org-babel-C-var-to-C): Mention all the arguments.
(org-babel-prep-session:C):
(org-babel-load-session:C): Make first line a proper short description
consisting of a single sentence.
2023-08-02 10:42:39 +03:00
Ihor Radchenko 7b80334fda
org-lint-timestamp-syntax: Improve lint message
* lisp/org-lint.el (org-lint-timestamp-syntax): Mention the original
timestamp in the link message.

Reported-by: Fraga, Eric <e.fraga@ucl.ac.uk>
Link: https://orgmode.org/list/87y1iuyb3m.fsf@ucl.ac.uk
2023-08-02 09:31:44 +03:00
Ihor Radchenko 20d90b9790
org-lint-export-option-keywords: Improve message and ignore `org-default-properties'
* lisp/org-lint.el (org-lint-export-option-keywords): Mention which
backends the suspicious properties may belong to.  Avoid triggering on
`org-default-properties'.

Reported-by: Fraga, Eric <e.fraga@ucl.ac.uk>
Link: https://orgmode.org/list/87y1iuyb3m.fsf@ucl.ac.uk
2023-08-02 09:31:21 +03:00
Ihor Radchenko f9d2d92f42
Merge branch 'bugfix' 2023-08-02 08:18:15 +03:00
Ihor Radchenko 8aa6e8125d
lisp/ob-cal.el: Fix docstrings
* lisp/ob-calc.el (org-babel-execute:calc): Mention all the args.
(org-babel-calc-maybe-resolve-var): Add docstring.
2023-08-02 08:05:29 +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 f03b839530
lisp/ob-awk.el: Fix docstrings
* lisp/ob-awk.el (org-babel-execute:awk):
* lisp/ob-awk.el (org-babel-awk-var-to-awk): Detail all the argument
in the docstring.
2023-07-31 14:17:22 +03:00
Ihor Radchenko f409cb4e52
ox: New option `org-export-expand-links'
* lisp/ox.el (org-export-options-alist): New export option toggling
environment variable expansion in link paths.
(org-export-expand-links): New customization.
(org-export--expand-links): New function expanding environment
variables all the link paths in AST.
(org-export-expand-include-keyword):
(org-export--blindly-expand-include): Add new optional arguments to
expand environment variables in INCLUDE file paths.  Update
docstrings.
(org-export--annotate-info): Call `org-export--expand-links' during
export and pass :expand-links parameter to
`org-export-expand-include-keyword'.
* doc/org-manual.org (Export Settings): Document the new option.
* etc/ORG-NEWS (New export option ~org-export-expand-links~): Announce
new option.

Link: https://list.orgmode.org/orgmode/87pm6fbnlo.fsf@localhost/
2023-07-31 11:24:40 +03:00
Ihor Radchenko 7151481313
org-manual: Automatically generate export option list
* mk/org-fixup.el (org-make-manual):
(org-make-guide):
(org-make-manuals): Allow code evaluation when exporting manuals.
* doc/org-manual.org (Generic properties):
(ASCII specific properties):
(Beamer specific properties):
(HTML specific properties):
(LaTeX specific properties):
(Markdown specific properties):
(ODT specific properties):
(Texinfo specific properties): Build property tables programatically,
from a code block.
2023-07-31 11:23:33 +03:00
Ihor Radchenko 68ba286fee
org-lint-link-to-local-file: Expand environment variables in path
* lisp/org-lint.el (org-lint-link-to-local-file): Try to expand
environment variables in file paths before testing if the linked file
exists.
2023-07-31 11:20:26 +03:00
Kyle Meyer d3f587fadf org-find-open-clocks: Fix recent bug in handling of match data
* lisp/org-clock.el (org-find-open-clocks): Prevent clock match data
from being clobbered by downstream org-element-at-point call.
2023-07-30 17:56:54 -04:00
Jens Schmidt eabc9bfecf
ol-gnus.el: Fix issue when storing links from Gnus article buffers
* lisp/ol-gnus.el (org-gnus-store-link): Switch to
`gnus-summary-buffer' when calling functions that are intended to be
called only there.

Link: https://list.orgmode.org/orgmode/2fa5914d-2cbf-f41f-8be6-e79e77794140@vodafonemail.de
2023-07-30 19:31:58 +03:00
Ihor Radchenko a6f3b24a67
Merge branch 'bugfix' 2023-07-30 12:30:40 +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 01bf57488c
lisp/org.el: Define `org-rear-nonsticky-at' defsubst before its first usage
This fixes compiler warning.
2023-07-30 12:26:49 +03:00
Ihor Radchenko d5006e195a
Merge branch 'bugfix' 2023-07-30 12:22:09 +03:00
Ihor Radchenko d38ca59230
ob-gnuplot: Fix links and verbatim when converting tables
* lisp/ob-gnuplot.el (org-babel-gnuplot-table-to-data): Use custom
backend to export table data.  The backend will export links verbatim,
without trying to resolve them and drop verbatim markers from data
fields.

Reported-by: Paul Stansell <paulstansell@gmail.com>
Link: https://orgmode.org/list/CAMJKaZzHuLxPoTg6FWUgt-U8QSHmuB3Kdqmk_E_0GH+jUZMSag@mail.gmail.com
2023-07-29 11:26:39 +03:00
Ihor Radchenko 2452f5de6d
org-export-get-all-transcoders: Fix when :parent is not symbol
* lisp/ox.el (org-export-get-all-transcoders): Handle :parent backend
not being symbol.
2023-07-29 11:26:03 +03:00
Ihor Radchenko de9f89e4be
org-babel-execute-src-block: Fix with :cache yes :results append/prepend
* lisp/ob-core.el (org-babel-execute-src-block): Do not remove
previous result when :cache is yes, but :results requests
appending/prepending the new result.
2023-07-28 12:11:31 +03:00
Ihor Radchenko 410cecc0e7
ob-tangle/collect-blocks: Small refactoring and extra commentary
* testing/lisp/test-ob-tangle.el (ob-tangle/collect-blocks): Use
`format-spec' instead of `format' for better readability.  Add extra
comments explaining the logic of testing.  Add "." at the end of
`lambda' docstrings.
2023-07-28 10:27:27 +03:00
Evgenii Klimov 3ee10d57f1
ob-tangle.el: Avoid relative file names when grouping blocks to tangle
* lisp/ob-tangle.el (org-babel-tangle-single-block,
org-babel-tangle-collect-blocks): Make target file name attribute,
used internally to group blocks with identical language, to be
absolute.
(org-babel-effective-tangled-filename): Avoid using relative file
names that could cause one block to overwrite the others in
`org-babel-tangle-collect-blocks' if they have the same target file
but in different formats.
2023-07-28 10:16:36 +03:00
Evgenii Klimov fcac0039aa
testing/lisp/test-ob-tangle.el: Test block collection into groups for tangling
* testing/lisp/test-ob-tangle.el (ob-tangle/collect-blocks): Test
block collection into groups for tangling.
2023-07-28 10:16:35 +03:00
Ihor Radchenko dc78f09465
org-up-heading-safe: Fix when parent is not a heading
* lisp/org.el (org-up-heading-safe): Do not assume that
`org-element-parent' is always a heading.  Use `org-element-lineage'
to get parent heading specifically.  Move point to current heading
even when no parent heading is available, as expected by some of the
other Org routines.  Document moving point when no parent.
* testing/lisp/test-org.el (test-org/up-heading-safe): Add tests.

Reported-by: Daniel Liden <djliden91@gmail.com>
Link: https://orgmode.org/list/CAG=u__pAT9k_AsRG6cpyPPUt0__5S7o=3a8WWkAijuPPuGc7Cg@mail.gmail.com
2023-07-26 11:01:34 +03:00
Ihor Radchenko 5f7cfdfd1d
* doc/org-manual.org: Refactor, explain diary sexp export in ox-icalendar
(iCalendar Export): Explain what is exported by default.  Mention
`icalendar-export-sexp-enumeration-days' that limits how far into
future generic diary sexps are exported.  Split large paragraph
explaining about handling entries with scheduled and deadline set.

Link: https://orgmode.org/list/87v8e93hor.fsf@localhost
2023-07-25 14:19:58 +03:00
Ihor Radchenko ac0042184e
org-bibtex-headline-format-function: Factor out lambda default value
* lisp/ol-bibtex.el (org-bibtex-headline-format-default): New function
to be used as the default value of
`org-bibtex-headline-format-function'.
(org-bibtex-headline-format-function): Update the default value.

Link: https://orgmode.org/list/87edl71tyu.fsf@localhost
2023-07-25 13:50:09 +03:00
Ihor Radchenko 39de4a1848
org-babel-sh-evaluate: Fix edge case when :shebang is set and :dir is remote
* lisp/ob-shell.el (org-babel-sh-evaluate): Pass remote local file
name as command when executing script with :shebang.  `org-babel-eval'
will fail when SCRIPT-FILE is TRAMP file name.

Link: https://www.reddit.com/r/orgmode/comments/14zh2yi/orgbabel_shebang_not_working_on_with_tramp_dir/
2023-07-23 17:38:09 +03:00
Ihor Radchenko ef391c882c
org-babel--shell-command-on-region: Remove obsolete workaround
* lisp/ob-eval.el (org-babel--shell-command-on-region): Remove
workaround for ancient Emacs version < minimal supported Emacs 26.
2023-07-23 17:35:44 +03:00
Evgenii Klimov d6f3aed7b1
testing/lisp/test-ob-tangle.el: Avoid interaction in test
* testing/lisp/test-ob-tangle.el (ob-tangle/detangle-false-positive):
Unset modification flag from buffer to kill
(testing/examples/babel.org) in tear down step of test to avoid Emacs
asking for confirmation during interactive testing from within Emacs.
2023-07-21 19:58:43 +03:00
Ihor Radchenko 36c254ae30
org-lint: Add checkers for square brackets inside link description
* lisp/org-lint.el (org-lint-confusing-brackets):
(org-lint-brackets-inside-description):
(trailing-bracket-after-link):
(unclosed-brackets-in-link-description): New checkers testing for
trailing extra "]" after links and for unmatched opening "[" inside
link description.
2023-07-21 12:36:47 +03:00
Ihor Radchenko 5cf6769747
* doc/org-manual.org (Activation): Add link to Emacs init file docs
Make it clear to the new users where to add the Elisp code.
2023-07-21 10:14:39 +03:00
Ihor Radchenko 6a2d84e501
ob-lilypond: Resolve FIXME
* lisp/ob-lilypond.el: Use `org-src-lang-modes' to inform Org babel
about non-standard mode name instead of using `defalias'.
* testing/lisp/test-ob-lilypond.el (ob-lilypond/check-lilypond-alias):
Remove test.
2023-07-20 10:02:07 +03:00
Yuval Langer dbb3912229
doc/org-guide.org: Add command names to listed keybindings
For every key binding listed, list the corresponding command name.
Useful for users of non-vanilla Emacs distributions with customized
key bindings.

Co-authored-by: Ihor Radchenko <yantar92@posteo.net>
Link: https://list.orgmode.org/orgmode/CAK0OjG2hOJry4L4TfefkdKQp3ALX7zML_NwS=gqhD79UE7O42g@mail.gmail.com/

TINYCHANGE
2023-07-19 12:47:28 +03:00
Morgan Smith 27b5de4d02
Testing: Test ignoring todo items in 'org-agenda' based on timestamp
* testing/lisp/test-org-agenda.el
(test-org-agenda/timestamp-ignore-todo-item): New test.
2023-07-19 10:48:52 +03:00
Ihor Radchenko 724135ddaf
fixup! org-do-emphasis-faces: Make sure that 'invisible property is not sticky 2023-07-19 10:05:30 +03:00
Ihor Radchenko 3e3b873d3f
org-do-emphasis-faces: Make sure that 'invisible property is not sticky
* lisp/org.el (org-do-emphasis-faces): Mark invisible text property in
emphasis markers non-sticky.  This is usually not a problem as we
manage invisible text property via font-lock.  However subtle bugs may
exist with non-interactive calls to Elisp primitives that inherit text
properties (like `indent-to').

Reported-by: Jens Schmidt <jschmidt4gnu@vodafonemail.de>
Link: https://orgmode.org/list/8b691a7f-6b62-d573-e5a8-80fac3dc9bc6@vodafonemail.de
2023-07-18 11:10:46 +03:00
Ihor Radchenko 5b6268c29e
org-columns--truncate-below-width: Fix Emacs 27 compatibility
* lisp/org-colview.el (org-columns--truncate-below-width): Do not use
extra optional arguments that are only available since Emacs 28.
2023-07-17 12:57:35 +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
Ihor Radchenko c730caf512
org-babel-result-to-file: Fix when in indirect buffer
* lisp/ob-core.el (org-babel-result-to-file): Consider file name in
base buffer when calculating base directory.

Reported-by: 赵一宇 <zhyznd@163.com>
Link: https://list.orgmode.org/orgmode/3d69c850.69db.18953ae45da.Coremail.zhyznd@163.com/
2023-07-17 12:04:05 +03:00
Ihor Radchenko 26440689aa
org-test-without-dow: Make name consistent with what the macro does
* testing/lisp/test-org.el (org-test-without-dow): Do not implicitly
call `org-test-with-result'.

Update all the callers.
2023-07-17 11:35:04 +03:00
Ihor Radchenko 9730f408c2
testing/org-test.el: New helper function `org-test-get-day-name'
* testing/org-test.el (org-test-get-day-name): New function to convert
English day name to current locale.
* testing/lisp/test-org-clock.el (test-org-clock/org-clock-timestamps-change):
(test-org-clock/clock-drawer-dwim): Use the new function instead of
direct `aref'.
2023-07-17 11:34:19 +03:00
Ruijie Yu 8739a95782
Let org-columns correctly detect string-widths in code
TODO: maybe I should also make a test directly on
`org-columns-add-ellipses'.  Will do in next iteration unless
objections.

* lisp/org-colview.el (org-columns--truncate-below-width): add a
helper function that will trim off just enough data from string to
fit into expected width.
(org-columns-add-ellipses): make sure to do truncation correctly
even in CJK locales (where an ellipsis character takes two
spaces).

* testing/lisp/test-org-colview.el
(test-org-colview/substring-below-width): add test to make sure
helper function is correct.
(test-org-colview/columns-width): fix incorrect expectations for
CJK locales about ellipses.
2023-07-17 11:06:32 +03:00
Ruijie Yu ab9c9732ea
Fix dependence on locale in org testing facilities
* testing/org-test.el org-test-day-of-weeks-seconds: add values of
seconds that yield different days of week (by trial-and-error).
org-test-day-of-weeks-abbrev: add a vector of abbreviated DoW
names for testing.
org-test-day-of-weeks-full: add a vector of full DoW names for
testing.

* testing/lisp/test-org-clock.el
(test-org-clock/clock-drawer-dwim): make use of the pre-generated
DoW names in the testing to remove assumptions on LANG=C.
(test-org-clock/org-clock-timestamps-change): renamed from
test-org-clok/org-clock-timestamps-change; used DoW pre-generated
names.

* testing/lisp/test-org.el (org-test-with-result):
(org-test-without-dow): add two macros to combat the 40-time
repetition of "do not add day-of-week, do something, and return
buffer string".
(test-org/clone-with-time-shift): (test-org/add-planning-info):
(test-org/deadline): (test-org/schedule): rewrite the
day-of-week-removal portion to avoid generating day-of-week names
altogether, using the new macro `org-test-without-dow'.
2023-07-17 11:04:23 +03:00
Morgan Smith a1ef64f3d1
Testing: Add tests for 'org-agenda-skip-if'
* testing/lisp/test-org-agenda.el (test-org-agenda/skip-if): New test.
(test-org-agenda/non-scheduled-re-matces): Fix typo by changing name
to 'test-org-agenda/non-scheduled-re-matches'.
2023-07-16 13:02:21 +03:00
Ihor Radchenko c0dbcf361e
org-store-link: Move already stored link to front by default
* lisp/ol.el (org-link-store-existing): New customization controlling
how to deal with already stored links.
(org-store-link): Respect the new customization, allowing duplicates
to (1) be added anyway; (2) be ignored; (3) be moved to front of
`org-stored-links'.  The default is (3).
* etc/ORG-NEWS (~org-store-link~ now moves an already stored link to
front of the ~org-stored-links~): Document the breaking change.

Reported-by: Samuel Wales <samologist@gmail.com>
Link: https://list.orgmode.org/orgmode/CAJcAo8sjD3_FX5pFQ4git9wRDNM3bMqTgP-R5mM8zcf1B3mjPg@mail.gmail.com/
2023-07-15 15:31:41 +03:00
Liu Hui 5e31dcdd9a ob-python: Fix async evaluation
* lisp/ob-python.el (org-babel-python-async-evaluate-session): Bind
`python-shell-buffer-name' inside the temp buffer.
* testing/lisp/test-ob-python.el (test-ob-python/async-local-python-shell):
Add test.
2023-07-13 17:24:41 -07:00
Ihor Radchenko c9b80f06d4
org-fold-core-next-folding-state-change: Optimize performance
* lisp/org-fold-core.el (org-fold-core-next-folding-state-change):
Avoid repetitive searches all to way to LIMIT.  Instead, limit the
next searches by the limit computer by previous.
2023-07-13 19:32:49 +03:00
Ihor Radchenko 17096b3f4c
Refactor `org-src--contents-for-write-back'
* lisp/org-src.el (org-src--contents-for-write-back-1): New function
that is passed indentation parameters and contents explicitly, without
relying on buffer-local variables in current buffer.  The function
extracts variable-independent code and removes unused MARKER.
(org-src--contents-for-write-back): Use the new function, passing the
parameters according to buffer-local values in src edit buffer.
2023-07-13 12:28:13 +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
Sébastien Miquel 67e819d6ee
test-org-src.el: Work around `current-column' bug in older emacs
* testing/lisp/test-org-src.el (test-org-src/indented-blocks): Work
around `current-column' not working in the presence of display strings
in older emacs.
2023-07-10 11:19:31 +03:00
Akira Kyle 8fa7f0279e
org-html-link: Fix relative links with :html-link-use-abs-url
* lisp/ox-html.el (org-html-link): When publishing relative links with
both :html-link-use-abs-url and :html-link-home, ensure the correct
link is constructed.  Never append `home' to absolute paths.

TINYCHANGE
2023-07-10 11:16:32 +03:00
Max Nikulin 879ba22ef6
org-compat.el: `org--flatten-tree' for Emacs-26 compatibility
* lisp/org-compat.el (org--flatten-tree): New internal compatibility
alias or function based on `flatten-tree' added to Emacs-27.1.
* lisp/org-protocol.el (org-protocol-flatten): Convert to an obsolete
function alias.
(org-protocol-flatten-greedy): Use the `org--flatten-tree' new
compatibility alias or function instead of `org-protocol-flatten'.
* lisp/org-src.el (org-src--get-known-shells): Make the function
compatible with Emacs-26 by using `org--flatten-tree' instead of
`flatten-tree'.

Reported as: Justin to emacs-orgmode. [PATCH] org-src: flatten-tree is
Emacs 27.1; require compat. Tue, 4 Jul 2023 19:21:05 -0400.
https://list.orgmode.org/0288575b-fde8-0e7d-ac74-1f0ac93ce56f@vallon.homeip.net
2023-07-08 12:09:25 +03:00
Max Nikulin caa27be102
org-element.el: Fix Emacs-26 compatibility
* org-element.el (org-element--current-element-re): Use `rx-to-string'
instead of `rx' to expand variables.
(org-element--cache-setup-change-functions): Avoid multiple variables in
`setq-local'.

Reported as: Justin to emacs-orgmode. [BUG] org-element loading fails
with "regexp" argument not "stringp" Tue, 4 Jul 2023 19:51:44 -0400.
https://list.orgmode.org/2ff109c7-b3ec-27ac-e75d-ae5ddac14746@vallon.homeip.net
2023-07-08 12:09:24 +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
Shynur 501be358bb
Several typo fixes
* CONTRIBUTE.org: Use the article 'an' for Org.
* org-manual.org: Use the article 'an' for Org.
Delete unnecessary whitespace at beginning of line.
Move LaTeX comment to the LaTeX code block.

TINYCHANGE
2023-07-06 20:38:13 +03:00
Ihor Radchenko 7c6302e203
org-agenda-show-new-time: Fix when window is very narrow
* lisp/org-agenda.el (org-agenda-show-new-time): When window is
narrower than timestamp, do not try to display timestamps starting at
negative column.

Reported-by: Nick Römer <nick.romer@skynet.be>
Link: https://orgmode.org/list/4196e86e.19136.1891ceef131.Webtop.154@skynet.be
2023-07-05 16:12:19 +03:00
Evgenii Klimov 402f72ad4f
lisp/org.el: Add final hooks to S-/M-/S-M-cursor commands
* lisp/org.el (org-metaleft-final-hook, org-metaright-final-hook,
org-metaup-final-hook, org-metadown-final-hook): Define final hooks
for S-cursor commands.
(org-metaleft, org-metaright, org-metaup, org-metadown): Add final
hooks to M-commands and document them in the docstring.

* lisp/org.el (org-shiftup, org-shiftdown, org-shiftright,
org-shiftleft): Document hooks for S-cursor commands in the docstring.

* lisp/org.el (org-shiftmetaleft-final-hook,
org-shiftmetaright-final-hook, org-shiftmetaup-final-hook,
org-shiftmetadown-final-hook): Define final hooks for the S-M-cursor
commands.
(org-shiftmetaleft, org-shiftmetaright, org-shiftmetaup,
org-shiftmetadown): Add final hooks to the S-M-cursor commands and
document hooks in the docstring.

* etc/ORG-NEWS (New final hooks for Modifier-Cursor keys): Document
new hooks.

TINYCHANGE
2023-07-05 13:40:19 +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
Evgenii Klimov 48fffa5dac
org-insert-link: Keep the link in `org-stored-links' if it was not inserted
* lisp/ol.el (org-insert-link): Keep the link in `org-stored-links' if
the command was interrupted by the user during the reading of a
description from the minibuffer.

TINYCHANGE
2023-07-04 13:43:21 +03:00
Ihor Radchenko e34b72eec6
org-make-tags-matcher: Do not try collecting tags from non-Org buffers
* lisp/org.el (org-make-tags-matcher): When building tag completion
table, do not attempt to call `org-get-buffer-tags' when current
buffer is not an Org buffer.

Reported-by: Colin Baxter <m43cap@yandex.com>
Link: https://orgmode.org/list/87ilb1fakk.fsf@yandex.com
2023-07-03 15:28:08 +03:00
Ihor Radchenko 38f87aa30a
Update Ihor Radchenko's email address
* lisp/ob-gnuplot.el:
* lisp/org-cycle.el:
* lisp/org-element-ast.el:
* lisp/org-fold-core.el:
* lisp/org-fold.el:
* lisp/org-persist.el: Update contact email of the maintainer/author.
2023-07-03 11:08:49 +03:00
Ihor Radchenko 02ad2a114f
lisp/org-element-ast.el: Fix copyright notice
Make copyright consistent with the rest of Org.
2023-07-03 11:06:55 +03:00
Ihor Radchenko 948c896448
Rename `org-element-property-1' to `org-element-property-raw'
The new name is more readable.

Link: https://orgmode.org/list/87sfail69e.fsf@localhost
2023-07-01 14:36:32 +03:00
Ihor Radchenko 66c8e94732
lisp/org-element-ast.el: Fix typo in commentary 2023-07-01 14:36:31 +03:00
Ihor Radchenko f97aeaa243
org-fold-core--isearch-setup: Use `add-function'
* lisp/org-fold-core.el (org-fold-core--isearch-setup): Use
add-function, respecting the value of `isearch-filter-predicate'.
(org-fold-core--isearch-filter-predicate-overlays): Remove.

Link: https://yhetil.org/emacs-devel/87o7lxpip9.fsf@web.de
2023-07-01 14:36:31 +03:00
Ihor Radchenko 7f337a2b95
org-fold-core: Fix isearch with `org-fold-core-isearch-open-function'
* lisp/org-fold-core.el (org-fold-core--with-isearch-active): New
macro, signaling `org-fold-core-region' to store newly created folds
in `org-fold-core--isearch-overlays'.
(org-fold-core-region): Respect the new macro.  Respect fold priority
for overlays.
(org-fold-core--isearch-setup): Do not run
`org-fold-core--clear-isearch-overlays' twice.
(org-fold-core--isearch-show): Fix when point is not on the match.
(org-fold-core--isearch-show-temporary): Rewrite, limiting to overlays
only and simplifying the code.
(org-fold-core--create-isearch-overlays): Extend link folds to full
link.
(org-fold-core--clear-isearch-overlay): Do not expect to be called in `isearch-mode-end-hook'.
* lisp/org-fold.el (org-fold--isearch-reveal): Respect argument.
2023-07-01 14:36:30 +03:00
Ihor Radchenko afbbebff3f
org-fold-core-get-folding-spec: Respect `org-fold-core-style'
* lisp/org-fold-core.el (org-fold-core-get-folding-spec): Only
consider folding using a single (currently selected) folding style.

Multiple fold styles may be present during isearch - we do not want to
mix them.
2023-07-01 14:36:29 +03:00
Ihor Radchenko 383d5dacb7
org-fold-show-set-visibility: Fix lineage visibility
* lisp/org-fold.el (org-fold-show-set-visibility): Do not reveal
everything, including drawers under heading when point is outside
drawers.  Reveal individual folding specs one by one, within their
folding bounds.
2023-07-01 14:36:28 +03:00
Ihor Radchenko 52c63f5cce
org-lint-export-option-keywords: Small refactoring
* lisp/org-lint.el (org-lint-export-option-keywords): Use
`org-element-post-affiliated'.
2023-07-01 14:36:28 +03:00
Ihor Radchenko 37a58cc6ee
org-agenda-skip: Do not alter match data
* lisp/org-agenda.el (org-agenda-skip): Never alter match-data.  The
callers often use `re-search-forward' and do not expect the match data
to be altered.
2023-07-01 14:36:27 +03:00
Ihor Radchenko f2dd1eea41
org-find-open-clocks: Fix false positives
* lisp/org-clock.el (org-find-open-clocks): Ensure that we only match
actual clock elements, not everything matching `org-clock-re',
including clocks inside verbatim environments.
2023-07-01 14:36:26 +03:00
Ihor Radchenko 759676b308
org-fold-core--isearch-show: Do not fully rely on `point'
* lisp/org-fold-core.el (org-fold-core--isearch-show): Make use of the
passed argument.  Do not just rely on `point' being at the isearch
match.

This partially fixes edge case with point being moved to the end of
the folded region during isearch.
2023-07-01 14:36:25 +03:00
Ihor Radchenko e18263fceb
org-element--substring: Fix when buffer is narrowed
* lisp/org-element.el (org-element--substring): Ignore narrowing.
2023-07-01 14:36:25 +03:00
Ihor Radchenko fcde1f779d
test-org-element/at-point: Add new test
* testing/lisp/test-org-element.el (test-org-element/at-point): Test
when point is not in current buffer.
2023-07-01 14:36:24 +03:00
Ihor Radchenko 9249275738
fixup! etc/ORG-NEWS: Document Org API changes 2023-07-01 14:36:23 +03:00
Ihor Radchenko 81e85bda2b
Fix Emacs 27 compatibility
* lisp/org-element-ast.el (org-element-create): Do not use `length='
that is not yet available.
(org-element-property-inherited): Do not use `ensure-list' that is not
yet available.
2023-07-01 14:36:22 +03:00
Ihor Radchenko 21d3b888c6
org-element-create: Fix Emacs 28 compatibility
* lisp/org-element-ast.el (org-element-create): Do not use `plistp'
that is not yet available in older Emacs.
2023-07-01 14:36:22 +03:00
Ihor Radchenko f895be1ad9
org-element--properties-mapc: Small refactoring
* lisp/org-element-ast.el (org-element--properties-mapc): Do not use
`pcase' - we are not testing for complex patterns here.
2023-07-01 14:36:21 +03:00
Ihor Radchenko 5a3224a325
etc/ORG-NEWS: Document Org API changes
* etc/ORG-NEWS (Major changes and additions to Org API):
(New functions and changes in function arguments): Document the
changes and additions to Org API.
2023-07-01 14:36:20 +03:00
Ihor Radchenko ea401fb1f4
org-agenda-ignore-properties: Bump :package-version
* lisp/org.el (org-agenda-ignore-properties): Remove :version keyword
and bump :package-version after changing the allowed values.
2023-07-01 14:36:19 +03:00
Ihor Radchenko 96b754c105
org-get-category, org-get-tags: Clarify that match data is modified
* lisp/org.el (org-get-category):
(org-get-tags): Update docstrings, documenting that these functions
may modify match data.
2023-07-01 14:36:19 +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 5ed3e1dfc3
org-refresh-category-properties: Do not check element cache
* lisp/org.el (org-refresh-category-properties): Do not check if
org-element-cache is active.  This function is now obsolete and can
only be called on purpose by third-party code that probably expects
the text properties to be assigned regardless whether the cache is
active.

This commit also fixes compiler warning as
`org-element--cache-active-p' is not declared anymore in lisp/org.el.
2023-07-01 14:36:17 +03:00
Ihor Radchenko 9ed7956afd
org-element: Use constant values for fixed deferred properties
* lisp/org-element.el (org-element--headline-archivedp):
(org-element--headline-footnote-section-p):
(org-element--headline-raw-value):
(org-element--headline-parse-title-raw):
(org-element--headline-parse-title-parse):
(org-element--headline-deferred):
(org-element--get-global-node-properties):
(org-element--headline-parent-deferred): New internal constants
holding deferred values used by parser.  These values are not a
subject of modification and thus can be re-used instead of
re-allocating a new instance for every new parsed element.
(org-element--headline-parse-title):
(org-element-headline-parser):
(org-element-org-data-parser):
(org-element-inlinetask-parser):
(org-element--parse-to): Use the new constants.

This patch aims for smaller memory footprint of Org AST and cache.
2023-07-01 14:36:16 +03:00
Ihor Radchenko 48e4a76b99
org-element: Avoid computing static regexps dynamically
* lisp/org-element.el (org-element--headline-comment-re):
(org-element--timestamp-raw-value-regexp): New internal regexp
constants.
(org-element--headline-parse-title):
(org-element-timestamp-parser): Use the new constants.
2023-07-01 14:36:15 +03:00
Ihor Radchenko 5a1dd94309
org-element: Avoid slow `end-of-line'
Link: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=63225#98
2023-07-01 14:36:15 +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 1c7c67b3c6
org-indent-drawer, org-indent-block: Remove unnecessary checks
* lisp/org.el:
(org-indent-block):
(org-indent-drawer): Do not try to check drawer/block twice.
2023-07-01 14:36:13 +03:00
Ihor Radchenko f63000cca8
org-element--current-element: Use "nogroup" versions of regexps
* lisp/org-element.el (org-element-dynamic-block-open-re-nogroup):
(org-element--latex-begin-environment-nogroup): New constants for
internal regexps.
(org-element-comment-parser):
(org-element--current-element-re):
(org-element--current-element): Prefer string constants instead of
repeated plain strings that may be considered different by Emacs
regexp compiler.  Also, avoid groups in these regexps as creating
groups makes Emacs regexp matches allocate extra memory.  Finally,
avoid using \{N\} constructs in regexps as they are slightly more
costly for regexp engine.
2023-07-01 14:36:12 +03:00
Ihor Radchenko 110601ce74
org-element--current-element: Add FIXME 2023-07-01 14:36:12 +03:00
Ihor Radchenko b0a2deaec6
org-element--current-element: Faster property drawer check
* lisp/org-element.el (org-element--current-element): Slight
optimization of checking for property drawer at point.  `forward-line'
is significantly faster compared to `beginning-of-line'.
`skip-chars-forward' also provides a bit of improvement compared to
`looking-at-p'.

Reported-by: Mattias Engdegård <mattias.engdegard@gmail.com>
Link: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=63225#80
2023-07-01 14:36:11 +03:00
Ihor Radchenko a80efaf460
org-element-node-property-parser: Remove unnecessary regexp search
* lisp/org-element.el (org-element-node-property-parser): Remove
unnecessary `re-search-forward'.  It always triggers as long as
`org-property-drawer-re' only allow node properties inside property
drawer.  Also, remove unnecessary `case-fold-search' setting that has
no meaning since we do not match against specific letters.
2023-07-01 14:36:10 +03:00
Ihor Radchenko 3ce57e17a0
org-item-re: Convert into defsubst
* lisp/org-list.el (org-item-re): Use faster `defsubst'.  This
function is called very frequently when parsing Org buffers by
`org-element--current-element'.
2023-07-01 14:36:09 +03:00
Ihor Radchenko b2482d9cc4
* testing/lisp/test-org-element.el: Add new tests
(test-org-element/type):
(test-org-element/type-p):
(test-org-element/org-element-property-1):
(test-org-element/property):
(test-org-element/properties-resolve):
(test-org-element/secondary-p):
(test-org-element/class):
(test-org-element/ast-map):
(test-org-element/properties-mapc):
(test-org-element/properties-map):
(test-org-element/org-element-create):
(test-org-element/put-property):
(test-org-element/set):
(test-org-element/lineage-map): add new and extend tests according to
the new API.
2023-07-01 14:36:09 +03:00
Ihor Radchenko 5c05ac198a
testing: Test with and without cache in more cases 2023-07-01 14:36:08 +03:00
Ihor Radchenko 16d7cdcf52
org-manual: Remove unused drawer properties to disable 2023-07-01 14:36:07 +03:00
Ihor Radchenko 01351f3eab
Restructure file organization 2023-07-01 14:36:06 +03:00
Ihor Radchenko 2b96501070
org-element: Simplify drawer and property drawer regexps
* lisp/org-element.el (org-element-drawer-re-nogroup): New constant
regexp matching drawer line without creating regexp groups.
(org-element--current-element): Use the new constant.
* lisp/org.el (org-drawer-regexp): Ensure that it is the same with
org-element version and mark for removal/alias.
(org-property-drawer-re): Simplify, removing unnecessary matching of
node property structures.

Link: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=63225#62
2023-07-01 14:36:05 +03:00
Ihor Radchenko 39466ecf47
org-element-cache: Do not check for deferred :parent unnecessarily
* lisp/org-element.el (org-element--cache-remove):
(org-element--cache-interrupt-p):
(org-element--cache-sync):
(org-element--cache-process-request):
(org-element--parse-to):
(org-element--cache-submit-request):
(org-element--cache-for-removal): use `org-element-property-1' to
retrieve parent without checking if it is deferred.  All the cached
elements have proper parent.
2023-07-01 14:36:05 +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 7dee228569
org-element-at-point-no-context: Update docstring 2023-07-01 14:36:03 +03:00
Ihor Radchenko 598d7bbcf2
Remove APPT_WARNTIME text property cache
* lisp/org.el (org-agenda-ignore-properties):
(org-agenda-prepare-buffers): Remove APPT_WARNTIME cache.
* lisp/org-agenda.el (org-agenda-get-timestamps):
(org-agenda-get-sexps):
(org-agenda-get-deadlines):
(org-agenda-get-scheduled): Use `org-entry-get' to retrieve
APPT_WARNTIME.
2023-07-01 14:36:02 +03:00
Ihor Radchenko 5898fcf269
Remove unused declares 2023-07-01 14:36:01 +03:00
Ihor Radchenko 7c549f4841
org-babel-tangle-collect-blocks: Switch to org-element API 2023-07-01 14:36:01 +03:00
Ihor Radchenko ebbdd67a2a
Remove effort property cache
* lisp/org-compat.el (org-refresh-effort-properties): Obsolete.
* lisp/org-clock.el (org-clock-in):
* lisp/org.el (org-default-properties):
(org-edit-agenda-file-list)
(org-set-property-and-value): Remove unnecessary calls to
`org-refresh-effort-properties'.
(org-agenda-ignore-properties): Update the allowed values.
2023-07-01 14:36:00 +03:00
Ihor Radchenko 2efc7fcfdc
org-agenda-get-scheduled: Switch to org-element API 2023-07-01 14:35:59 +03:00
Ihor Radchenko 06aba04f75
org-agenda-get-deadlines: Switch to org-element API 2023-07-01 14:35:58 +03:00
Ihor Radchenko 31d53cb015
org-end-of-subtree: Use org-element API
* lisp/org.el (org-end-of-subtree): Skip all the blank lines before,
not just the last empty.  Update the docstring.
2023-07-01 14:35:58 +03:00
Ihor Radchenko def4bfa9c1
org-scan-tag: Switch to pure use of `org-element-cache-map' 2023-07-01 14:35:57 +03:00
Ihor Radchenko e3d690edf8
org-element-cache-map: Allow when cache is disabled
* lisp/org-element.el (org-element--cache-variables): New constant
holding variables involved in cache state.
(org-element-cache-reset): Fix modification hooks when cache is reset
and buffer already have indirect child buffers.
(org-element-with-enabled-cache): New macro, to enable cache around
body.
(org-element-cache-map): Enable cache when executing.
2023-07-01 14:35:56 +03:00
Ihor Radchenko 3024e933c0
org-get-buffer-tags: Switch to org-element API 2023-07-01 14:35:55 +03:00
Ihor Radchenko 6938857369
org-goto-first-child: Switch to org-element API 2023-07-01 14:35:54 +03:00
Ihor Radchenko 6266197bbd
org-at-item-p: Use org-element API 2023-07-01 14:35:54 +03:00
Ihor Radchenko fefaadc2d5
org-element: Optimize working with match data and Emacs regexps
* lisp/org-element.el: Add commentary explaining some regexp-related
optimizations useful for the parser.

Link: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=63225
(org-element--headline-deferred):
(org-element-item-parser):
(org-element-item-interpreter):
(org-element--list-struct):
(org-element-plain-list-parser):
(org-element-example-block-parser):
(org-element-fixed-width-interpreter):
(org-element-paragraph-parser):
(org-element-src-block-parser):
(org-element-table-parser):
(org-element--parse-generic-emphasis):
(org-element-export-snippet-interpreter):
(org-element-link-parser):
(org-element--current-element):
(org-element--collect-affiliated-keywords):
(org-element-parse-buffer):
(org-element-normalize-string):
(org-element-normalize-contents):
(org-element--parse-to):
(org-element--cache-before-change):
(org-element--cache-for-removal):
(org-element-context): Avoid storing match data unless strictly
necessary.  Explain the necessity in places where we have to use
`save-match-data'.  Prefer `looking-at-p' (does not alter match data)
to `looking-at'.  Simplify regexps.  Update docstrings clearly
indicating when match data might be modified.
* lisp/org.el:
(org-offer-links-in-entry):
* lisp/ob-exp.el (org-babel-exp-process-buffer):
* lisp/org-agenda.el: Fix places where we need to protect match data.
2023-07-01 14:35:53 +03:00
Ihor Radchenko dfd36d1969
org-up-heading-safe: Use element API 2023-07-01 14:35:52 +03:00
Ihor Radchenko eb0a293a02
Remove 'org-category text property cache
* lisp/org.el (org-get-category): Update useing
`org-entry-get-with-inheritance'.
(org-agenda-ignore-properties): Update docstring.
(org-refresh-category-properties):
(org-check-agenda-file): Do not call
`org-refresh-category-properties'.
* lisp/org-compat.el (org-refresh-category-properties): Obsolete.
* doc/org-manual.org (Speeding Up Your Agendas): Update the manual.
* testing/lisp/test-org.el (test-org/get-category): Update tests, not
calling the obsolete function.
2023-07-01 14:35:51 +03:00
Ihor Radchenko 771074ba5e
org-in-archived-heading-p: Use org-element API 2023-07-01 14:35:50 +03:00
Ihor Radchenko ec8f359bd6
org-in-commented-heading-p: Use org-element API 2023-07-01 14:35:50 +03:00
Ihor Radchenko 13ae9b95f8
org-narrow-to-subtree: Use org-element API 2023-07-01 14:35:49 +03:00
Ihor Radchenko 7cbc441915
org-entry-get-with-inheritance: Use org-element API
* lisp/org.el (org--property-local-values):
(org-entry-get-with-inheritance): Switch to pure org-element API.
2023-07-01 14:35:48 +03:00
Ihor Radchenko 3b1693c461
org-back-to-heading: Use org-element API 2023-07-01 14:35:47 +03:00
Ihor Radchenko 4d63e571e0
org-get-tags: Use org-element API
* lisp/org.el (org--get-local-tags):
(org-get-tags): Switch to pure org-element API instead of regexp
matching.
2023-07-01 14:35:47 +03:00
Ihor Radchenko 607c230d74
org-with-point-at: Accept syntax node as POM 2023-07-01 14:35:46 +03:00
Ihor Radchenko f225e24869
org-element--current-element: Make defsubst 2023-07-01 14:35:45 +03:00
Ihor Radchenko b00c2d0e1d
org-element--parse-to: Provide deferred :parent when cache is inactive
* lisp/org-element.el (org-element--headline-parent-deferred): New
function to calculate :parent of a heading on demand.
(org-element--parse-to): Assign deferred :parent when cache is
inactive.
2023-07-01 14:35:44 +03:00
Ihor Radchenko bc29f5de41
org-element: New `org-element-*property*' functions
* lisp/org-element.el (org-element-begin):
(org-element-end):
(org-element-contents-begin):
(org-element-contents-end):
(org-element-post-affiliated):
(org-element-post-blank): New functions for fast access to frequently
used element properties.  The functions are `setf'-able.

Update all the relevant code in Org to use the new functions instead
of genetic property queries.
2023-07-01 14:35:43 +03:00
Ihor Radchenko 81a7e8c836
org-element-lineage: Allow TYPES to be a symbol
* lisp/org-element-ast.el (org-element-lineage): Allow TYPES argument
to be a symbol.
* lisp/ox-ascii.el (org-ascii--current-text-width):
(org-ascii-format-inlinetask-default):
(org-ascii-section):
* lisp/ox-beamer.el (org-beamer--format-block):
* lisp/ox-html.el (org-html-section):
(org-html-table-cell):
(org-html-table-row):
* lisp/ox-latex.el (org-latex-table-cell):
(org-latex-table-row):
* lisp/ox-odt.el (org-odt-headline):
(org-odt-table-style-spec):
(org-odt-get-table-cell-styles):
(org-odt-table-cell):
(org-odt-table-row):
* lisp/ox-org.el (org-org-section):
* lisp/ox-publish.el (org-publish-collect-index):
* lisp/ox-texinfo.el (org-texinfo--get-node):
(org-texinfo-section):
(org-texinfo-table-row):
* lisp/ox.el (org-export--skip-p):
(org-export-get-node-property):
(org-export-table-cell-borders):
(org-export-table-row-in-header-p):
(org-export-table-row-number):
(org-export-collect-headlines): Update all the callers.
2023-07-01 14:35:43 +03:00
Ihor Radchenko 2d22d7f515
ox.el: Rename `org-element-get-parent-element' and move to org-element
* lisp/org-element.el: Rename `org-element-get-parent-element' to
`org-element-parent-element'.
* lisp/org-compat.el (org-export-get-parent-element):
* lisp/ox.el (org-export-get-parent-element): Remove, adding obsolete
alias.
(org-export--skip-p):
* lisp/org-table.el:
* lisp/ox-beamer.el (org-beamer-link):
* lisp/ox-html.el (org-html-link):
* lisp/ox-latex.el (org-latex-footnote-reference):
* lisp/ox-md.el (org-md-link):
* lisp/ox-odt.el (org-odt-format-label):
(org-odt-link--inline-image):
(org-odt-link--inline-formula):
* lisp/ox-texinfo.el (org-texinfo--inline-image): Update all the
callers.
2023-07-01 14:35:42 +03:00
Ihor Radchenko ea4f4fdf58
Rename `org-export-get-parent' to `org-element-parent' 2023-07-01 14:35:41 +03:00
Ihor Radchenko 6a7aee2c35
org-texinfo--normalize-headlines: Use `org-element-create' 2023-07-01 14:35:40 +03:00
Ihor Radchenko a43cc8c9aa
org-export-get-node-property: Use `org-element-property-inherited' 2023-07-01 14:35:40 +03:00
Ihor Radchenko a2730b47fa
org-odt--paragraph-style: Use `org-element-lineage' 2023-07-01 14:35:39 +03:00
Ihor Radchenko 69383dfc24
org-ascii--current-justification: Use `org-element-lineage-map' 2023-07-01 14:35:38 +03:00
Ihor Radchenko 44baf8f2b8
org-element-parse-buffer: New optional argument to not force undefer
* lisp/org-element.el (org-element-parse-buffer): Do not force-undefer
when new optional argument is provided.
* lisp/org-lint.el (org-lint--generate-reports):
* lisp/org.el (org-unindent-buffer):
* lisp/ox.el (org-export--missing-definitions):
(org-export--annotate-info): Do not undefer when unnecessary.

Adjust all the declare forms.
2023-07-01 14:35:37 +03:00
Ihor Radchenko 244cc7d560
org-element-org-data-parser: Defer parsing
* lisp/org-element.el (org-element--get-category): New function
calculating buffer category, excluding top-level property drawer.
(org-element--get-global-node-properties): Set category as well,
calling `org-element--get-category'.
(org-element-org-data-parser): Defer category and top-level drawer
property parsing.
2023-07-01 14:35:37 +03:00
Ihor Radchenko a06dc07cc0
org-element: Defer more when parsing headings and inlinetasks
* lisp/org-element.el (org-element-headline-parser--deferred):
(org-element--headline-deferred): Rename.
(org-element--headline-archivedp):
(org-element--headline-footnote-section-p):
(org-element--headline-parse-title): New internal helpers.
(org-element-headline-parser):
(org-element-inlinetask-parser): Defer parsing headline components.
*
testing/lisp/test-org-attach.el (test-org-attach/dired-attach-to-next-best-subtree/1):
Use property API instead of relying upon internal syntax node representation.
2023-07-01 14:35:36 +03:00
Ihor Radchenko a7d1dfa171
Use `org-element-type-p'
Use `org-element-type-p' across Org source, except some tests, where `eq' can
produce more meaningful failure explanations.
2023-07-01 14:35:35 +03:00
Ihor Radchenko 5e94d5cef6
org-element-map: Allow FUN to be a lisp form
* lisp/org-element-ast.el (org-element-ast-map):
* lisp/org-element.el (org-element-map): Allow FUN to be a lisp form,
wrapping it into lambda.
2023-07-01 14:35:34 +03:00
Ihor Radchenko 71e2ea5698
org-element: Update docstrings using new syntax node terminology 2023-07-01 14:35:34 +03:00
Ihor Radchenko 23f9347d1a
org-element-map: Allow TYPES t and add new arg NO-UNDEFER
* lisp/org-element-ast.el (org-element-ast-map):
* lisp/org-element.el (org-element-map): Treat TYPES t as all possible
types.  Add new optional parameter to no resolve deferred while
traversing the AST.
2023-07-01 14:35:33 +03:00
Ihor Radchenko c22697f472
Use new function names `org-element-extract' and `org-element-set' 2023-07-01 14:35:32 +03:00
Ihor Radchenko 29cb0b370b
org-element-headline-parser: Defer property drawer values
* lisp/org-element.el (org-element--get-node-properties): Defer the
property values.
2023-07-01 14:35:31 +03:00
Ihor Radchenko 4fcdcb456d
org-element: Defer large buffer substrings when parsing
* lisp/org-element.el (org-element--substring):
(org-element--unescape-substring): New functions to be used for
deferred buffer substring calculation.
(org-element--headline-raw-value):
(org-element-comment-block-parser):
(org-element-example-block-parser):
(org-element-export-block-parser):
(org-element-latex-environment-parser):
(org-element-src-block-parser):
(org-element-table-parser):
(org-element--parse-generic-emphasis):
(org-element-inline-babel-call-parser):
(org-element-latex-fragment-parser):
(org-element-export-snippet-parser): Defer large buffer substrings.
2023-07-01 14:35:30 +03:00
Ihor Radchenko daebeb6446
org-element-inlinetask-parser: Use deferred properties 2023-07-01 14:35:30 +03:00
Ihor Radchenko 932c49c7bb
org-element-headline-parser: Use deferred properties
* lisp/org-element.el (org-element--headline-raw-value): New function
calculating :raw-value property dynamically.
(org-element-headline-parser): Use the new function, deferring
:raw-value to reduce memory footprint of the cache.
2023-07-01 14:35:29 +03:00
Ihor Radchenko 55ba9f05a7
org-element-map: Refactor using `org-element-ast-map'
* lisp/org-element.el (org-element-map): Use `org-element-ast-map' to
traverse the AST.  Update the docstring adding new features from
`org-element-ast-map' - FUN can now throw `:org-element-skip' signal
to skip current node and its child nodes.  Clarify the structure of
INFO argument.  Reverse the traverse order for dual keywords -
secondary value is now traversed after the main value.
* testing/lisp/test-org-element.el (test-org-element/map): Update the test
reflecting the change in dual keyword traversal order.
2023-07-01 14:35:28 +03:00
Ihor Radchenko 5f37f77fc6
org-element--cache-shift-positions: Make use of inliner
* lisp/org-element.el: Allow `org-element-property' inliner to expand
into `aref'.
2023-07-01 14:35:27 +03:00
Ihor Radchenko ad75fd2bae
org-element: Use `org-element-create' when parsing 2023-07-01 14:35:27 +03:00
Ihor Radchenko a8286a5a9e
org-element: Record origin buffer when parsing
* lisp/org-element.el (org-element-parse-buffer): Resolve all the
deferred values in the string.  If not, we might leave pointers to
killed buffer.
(org-element--parse-elements): Resolve deferred in objects.
(org-element--object-lex): Store :buffer property.
* lisp/org-macro.el (org-macro--find-date): Do not try to print
:buffer property.
* lisp/org-element.el (org-element--cache-persist-before-write):
(org-element--cache-persist-after-read): Clear and restore
non-printable buffer objects in :buffer property.
2023-07-01 14:35:26 +03:00
Ihor Radchenko f4aa3747e1
org-element: Preserve order of multiple affiliated keywords
* lisp/org-element.el: Do not reverse affiliated keyword order.
(org-element-map): Remove special arrangement to restore keyword
ordering.
(org-element--interpret-affiliated-keywords): Obey the new keyword order.
* lisp/ox.el (org-export-get-caption):
* testing/lisp/test-org-element.el (test-org-element/affiliated-keywords-parser):
* testing/lisp/test-org-element.el (test-org-element/interpret-data):
Do not assume reverse order.

This is one of the undocumented conventions that is inconsistent with
other aspects of the parser.
2023-07-01 14:35:25 +03:00
Ihor Radchenko 924a64da39
org-element: Use the new org-element-ast library
* lisp/org-element.el (org-element-class):
(org-element-interpret-data): Explicitly consider anonymous syntax
node type.
* lisp/org-element.el (org-element-put-property):
(org-element-set-contents):
(org-element-secondary-p):
(org-element-adopt-elements):
(org-element-extract-element):
(org-element-insert-before):
(org-element-set-element):
(org-element-create):
(org-element-copy):
(org-element-lineage): Remove from org-element.el, using
org-element-ast function versions.
* lisp/org-element.el (org-element-headline-parser):
(org-element-inlinetask-parser):
(org-element-item-parser):
(org-element-citation-parser):
(org-element-citation-reference-parser): Assign :secondary property.
(org-element-parse-buffer):
(org-element-parse-secondary-string): Resolve deferred properties.
(org-element--cache-shift-positions): Use the new AST API.
(org-element--cache-for-removal): Use optional argument for
`org-element-set-element' to keep the needed property values.
(org-element--cache-gapless): Bump element cache version when persisting.
* testing/lisp/test-org-element.el (test-org-element/class): Update
test using the new :secondary property convention.
* lisp/ox-man.el (org-man-paragraph): Use the new AST API.
2023-07-01 14:35:24 +03:00
Ihor Radchenko ea9d5b45db
org-element-create: Allow single &rest argument as a list
* lisp/org-element-ast.el (org-element-create): Add special case when
CHILDREN contains a single list of Org notes:

  (let ((children (list a b c ...)))
    (org-element-create 'type nil children))

This will simplify creating new elements when children are stored in a
list.
2023-07-01 14:35:24 +03:00
Ihor Radchenko 6333a20aa5
org-element-ast: New function `org-element-lineage-map' 2023-07-01 14:35:23 +03:00
Ihor Radchenko 6b20a23065
org-element-ast: New function `org-element-type-p' 2023-07-01 14:35:22 +03:00
Ihor Radchenko ae49451364
org-element-ast: New function `org-element-put-property-2'
* lisp/org-element-ast.el (org-element-put-property-2): New function
allowing to pass NODE as the last argument.
2023-07-01 14:35:21 +03:00
Ihor Radchenko 80122a1204
org-element-ast: New function `org-element-property-2' 2023-07-01 14:35:21 +03:00
Ihor Radchenko f611f131ee
org-element-ast: New function `org-element-ast-map'
* lisp/org-element-ast.el (org-element-ast-map): New function
equivalent to `org-element-map', but more low-level.  Unlike
`org-element-map', `org-element-ast' does not consider the details of
Org syntax - just syntax tree structure.
2023-07-01 14:35:20 +03:00
Ihor Radchenko 669e8d8824
org-element-ast: New function `org-element-property-inherited' 2023-07-01 14:35:19 +03:00
Ihor Radchenko 4a8849340d
org-element-ast: New functions to map and resolve property values
* lisp/org-element-ast.el (org-element--properties-mapc): New internal
helper.
(org-element-properties-resolve): New function used to resolve
deferred property values by side effect.
(org-element-properties-mapc):
(org-element-properties-map): New function to map over properties and
their values.
(org-element-resolve-deferred): New alias to resolve all the deferred
values in syntax nodes.
2023-07-01 14:35:18 +03:00
Ihor Radchenko 2d2656f6a7
org-element-ast: Add setters for `org-element-property' and `org-element-property-1' 2023-07-01 14:35:18 +03:00
Ihor Radchenko 1260f61830
Refactor org-element API for abstract syntax tree
Major changes:
1. Property values can now deferred and computed next time when the
   value is requested.
2. Some properties are stored in an array instead of plist.  The
   functions are inlined to turn the propery queries into direct
   `aref' and `aset' calls to the plist, when applicable.
3. Secondary strings are now considered of `anonymous' type, in
   backwards-compatible way.
4. New functions to map over and/or resolve deferred values of element
   properties.
5. Docstrings and code consistently use "node" for generic syntax tree
   elements, to not confuse the element/object terminology we use in
   the parser.

* lisp/org-element-ast.el (org-element-deferred): New type user to
store deferred values.
(org-element--deferred-resolve-once):
(org-element--deferred-resolve):
(org-element--deferred-resolve-force):
(org-element--deferred-resolve-list): Helper functions used to resolve
the deferred values.
(org-element--standard-properties):
(org-element--standard-properties-idxs):
(org-element--property-idx):
(org-element--parray):
(org-element--plist-property): Store most commonly used properties in
vector for faster access.  Implement inliner helpers to transform
property keywords into array indices.
(org-element-property-1): New function to retrieve property without
resolving deferred value.
(org-element--put-parray):
(org-element-put-property): Refactor, using the new property vector
when applicable.
(org-element--property): New helper function.
(org-element-property): Refactor, using the new property vector and
deferred value resolution.  Add new optional arguments DFLT and
FORCE-UNDEFER.  Define setters.
(org-element-set-contents): Handle anonymous nodes.
(org-element-set):
(org-element-adopt):
(org-element-extract): Rename from `org-element-set-elements',
`org-element-adopt-elements', and `org-element-extract-elements' and
keep backward-compatible alias.  This is to reduce the confusion about
"node" vs. "element" vs. "object".
(org-element-create): Initialize property array correctly.
(org-element-copy): Allow copying secondary strings.  Add new optional
argument KEEP-CONTENTS.
(org-element-lineage): Clarify the limitation when cache is disabled.
(org-element-type): New optional argument to identify anonymous nodes
instead of returning nil for both anonymous nodes and everything not
matching other element types.
2023-07-01 14:35:17 +03:00
Ihor Radchenko d5198e39fb
org-element-ast: Add commentary describing the basics of AST structure
Clarify some of the undocumented concept assumptions about Org syntax
tree that are used in Org code base.  In particular, clarify that
syntax nodes are not necessarily limited by the specific Org syntax -
exporters can define new "pseudo" elements and objects.

Introduce a new concept of deferred values.

Add a new convention to keep secondary property names in a special
:secondary property.

Introduce `anonymous' element type, which was previously
indistinguishable from values that are not Org syntax elements.
2023-07-01 14:35:16 +03:00
Ihor Radchenko f750f46c9d
Factor out pure syntax tree API to org-element-ast.el (copy old functions)
The functions to be modified are copied here for better diffs with
subsequent commits.
2023-07-01 14:35:15 +03:00
Ihor Radchenko 184b735323
Merge branch 'bugfix' 2023-07-01 13:26:08 +03:00
Ihor Radchenko 64a0a624d2
org-insert-structure-template: Err on empty TYPE
* lisp/org.el (org-insert-structure-template): Throw a user error on
empty TYPE input.  Throw an error when TYPE is not a string or an
empty string.

Reported-by: pva-outdoor@yandex.ru
Link: https://orgmode.org/list/87a5wij05o.fsf@yandex.ru
2023-07-01 13:22:46 +03:00
Ihor Radchenko 85aa3c1850
org-narrow-to-block: Use element API and handle all the block types
* lisp/org.el (org-narrow-to-block): Narrow to any block type,
including dynamic blocks.  Use org-element API.

Reported-by: pva-outdoor@yandex.ru
Link: https://orgmode.org/list/87a5wij05o.fsf@yandex.ru
2023-07-01 13:18:38 +03:00
Ihor Radchenko dc70878fc0
org-lint: Add new linter for ambiguous literal $
* lisp/org-lint.el (org-lint-LaTeX-$-ambiguous): New linter that
matches "$.12" and similar that match right LaTeX fragment boundary,
but are likely indented for literal use.

Reported-by: Paul Rubin <paulr@hackyon.net>
Link: https://orgmode.org/list/49c5dcf6-26fa-5fe1-1778-c932d056eadb@hackyon.net
2023-07-01 13:03:11 +03:00
Ihor Radchenko cf2349d14b
org-manual: Explain how to deal with literal $ parsed as LaTeX fragments
* doc/org-manual.org (LaTeX fragments): Mention entities and
zero-width space as workarounds when literal "$" is needed, but Org
matches it as LaTeX fragment.

Reported-by: Paul Rubin <paulr@hackyon.net>
Link: https://orgmode.org/list/49c5dcf6-26fa-5fe1-1778-c932d056eadb@hackyon.net
2023-07-01 13:00:30 +03:00
Ihor Radchenko c33ea8f9e2
org-refile: Fix typo in 94c2c8d92
* lisp/org-refile.el (org-refile): Fix typo in variable name.
2023-06-30 15:49:57 +03:00
Ihor Radchenko a19654583c
Refactor `org-fast-tag-selection'
* lisp/org.el (org-fast-tag-selection): Refactor the function, adding
commentary and renaming variables to more readable names.
2023-06-30 15:46:51 +03:00
Ihor Radchenko f5001c0da6
Refactor `org-fast-todo-selection'
* lisp/org.el (org-fast-todo-selection): Refactor the function, adding
commentary and renaming variables to more readable names.
2023-06-30 15:46:51 +03:00
Matthew Trzcinski 88c572de25 Create aliases for export region functions
lisp/ox-ascii.el: Create alias `org-export-region-to-ascii` for
`org-ascii-convert-region-to-ascii`.
lisp/ox-html.el: Create alias `org-export-region-to-html` for
`org-html-convert-region-to-html`.
lisp/ox-latex.el: Create alias `org-export-region-to-latex` for
`org-latex-convert-region-to-latex`.
lisp/ox-md.el: Create alias `org-export-region-to-md` for
`org-md-convert-region-to-md`.
lisp/ox-texinfo.el: Create alias `org-export-region-to-texinfo` for
`org-texinfo-convert-region-to-texinfo`.
doc/org-manual.org: Change commands from "*-convert-region-*" form to
the "org-export-region-to-*" aliases.  Add function index for aliases.
2023-06-29 21:18:01 +02:00
Matthew Trzcinski 9da248ccd2 doc/org-manual.org: Remove term "foreign buffer"
doc/org-manual.org: Change "Export in Foreign Buffers" to "Export
Region", replace phrase "foreign buffers" with"non-Org buffers",
clarify explanation of the export region functions.
2023-06-29 21:12:53 +02:00
Matthew Trzcinski 1b5451a105 doc/org-manual.org: Reorder sections
org-manual.org: Move the "Exporting to minimal HTML" node from its
current section under "Export in Foreign Buffers" (13.18.1) to within
"HTML Export" (13.9.5).

Link: https://lists.gnu.org/archive/html/emacs-orgmode/2023-06/msg00395.html
2023-06-29 20:44:50 +02:00
Ihor Radchenko 5df1ee36ae
org-refile: Fix typo in 94c2c8d92
* lisp/org-refile.el (org-refile): Fix typo in variable name.
2023-06-28 12:34:53 +03:00
Sébastien Miquel 73134cfbf1 test-org-src.el: Add two tests
* testing/lisp/test-org-src.el (test-org-src/preserve-empty-lines):
Test that empty lines are not indented.
(test-org-src/indented-latex-fragments): Test special edit of
multiline indented LaTeX fragment.
2023-06-26 12:10:26 +02:00
Ihor Radchenko f8b0b2babf
org-edit-special: Fix docstring
* lisp/org.el (org-edit-special): Document missing contexts in the docstring.
2023-06-25 13:45:18 +03:00
Ihor Radchenko 18f003a164
Merge branch 'bugfix' 2023-06-24 15:36:34 +03:00
Ihor Radchenko 94c2c8d929
Inhibit error when saving bookmarks with `debug-on-error' set to non-nil
* lisp/org-capture.el (org-capture-store-last-position):
* lisp/org-refile.el (org-refile): Use `condition-case' instead of
`with-demoted-errors' when saving bookmarks.  We intent to suppress
errors completely here (116c09053), even when `debug-on-error' is set.
`with-demoted-errors' does trigger error in such scenario, unlike
explicit `condition-case' clause.

Reported-by: No Wayman <iarchivedmywholelife@gmail.com>
Link: https://orgmode.org/list/875y7d7jlr.fsf@gmail.com
2023-06-24 15:05:12 +03:00
Dmitry Logvinenko 5b3a1a634c
lisp/org-habit.el: Inherit habit style property
* lisp/org-habit.el (org-is-habit-p):  Use `org-entry-get' with
'selective option to optionally find habit subheadings.
* etc/ORG-NEWS: Describe a breaking change.

TINYCHANGE
2023-06-23 13:47:51 +03:00
Tim Visher bea9fca183
org-capture.el: Allow `(here)' as a template target
* lisp/org-capture.el (org-capture-set-target-location): Allow
`(here)' as a template target in addition to `here'.
(org-capture-templates): Update the docstring, describing the new
target.
* doc/org-manual.org (Template elements): Add `(here)' target
documentation
* etc/ORG-NEWS (Capture templates now support ~(here)~ as a target):
Document the new feature.

Templates had no user accessible way to target the current location
directly from a capture template. Attempting to directly utilize the
behavior accessible through a 0 prefix arg exposed the inconsistent
treatment of the `:target` property in
`org-capture`. `org-capture-set-target-location` understood that it
could be both a symbol and a list, while `org-capture` itself required
it to be a list through its use of `car`.

This change opts to make `org-capture-set-target-location` more
liberal in what it accepts rather than making `org-capture` agree that
targets can be lists. This is because the manual implies, especially
in the `(clock)' entry, that targets are expected to be lists even if
they are meant as specific points.

TINYCHANGE
2023-06-22 13:14:12 +03:00
Ihor Radchenko 200d168275
Merge branch 'bugfix' 2023-06-22 12:54:51 +03:00
Ihor Radchenko c8c8e3326d
org-priority-show: Fix the docstring after changes in "priority" for agenda
* lisp/org.el (org-priority-show): Do not wrongly assert that the
priority is affected by scheduled and deadline values.  This was not
true in the past for Org mode buffers, and it is no longer true after
8fab6eeef renamed composite agenda rank from priority to urgency.

* etc/ORG-NEWS (~org-priority=show~ command no longer adjusts for
scheduled/deadline): Document the change, right before the NEWS item
describing changes in the agenda.
2023-06-21 20:22:43 +03:00
libreville eab92e8f77
org-manual.org: Delete ref to non-existent examples of hook usage
* doc/org-manual.org (Hooks): Delete ref to non-existent examples of
hook usage in A.1 Hooks.

TINYCHANGE
2023-06-21 14:53:37 +03:00
Jack Kamm 294a4d2fe2 ox-icalendar: Add support for unscheduled and repeating TODOs
* lisp/ox-icalendar.el (org-icalendar-todo-unscheduled-start): New
customization to control the exported start time of unscheduled tasks.
(org-icalendar--rrule): Helper function for RRULE export.
(org-icalendar--vevent): Use the new helper function for RRULE.
(org-icalendar--repeater-type): Helper function to get the repeater
type, and display warning if not supported.
(org-icalendar--vtodo): Change how unscheduled TODOs are handled using
the new customization option.  Export SCHEDULED and DEADLINE
repeaters.  In case of SCHEDULED repeater and a DEADLINE without
repeater, treat DEADLINE as RRULE UNTIL.  Emit a warning for tricky
edge cases that are not yet implemented.
* testing/lisp/test-ox-icalendar.el
(test-ox-icalendar/todo-repeater-shared): Test for exporting shared
SCHEDULED/DEADLINE repeater.
(test-ox-icalendar/todo-repeating-deadline-warndays): Test using
warning days as DTSTART of repeating deadline.
(test-ox-icalendar/todo-repeater-until): Test using DEADLINE as RRULE
UNTIL.
(test-ox-icalendar/todo-repeater-until-utc): Test RRULE UNTIL is in
UTC format when DTSTART is not in local time format.
(test-ox-icalendar/warn-unsupported-repeater): Unit test to warn for
unsupported repeater types.
* lisp/org-lint.el (org-lint-mismatched-planning-repeaters): Add lint
for mismatched SCHEDULED and DEADLINE repeaters.
* testing/lisp/test-org-lint.el
(test-org-lint/mismatched-planning-repeaters): Add test for linting of
mismatched SCHEDULED and DEADLINE repeaters.
* doc/org-manual.org (iCalendar Export): Add link to new variable
`org-icalendar-todo-unscheduled-start'.
2023-06-18 06:51:47 -07:00
David Masterson d50956e480
org-manual, org-guide: Improve timestamp documentation
* doc/org-manual.org (Dates and Times): Explain the purpose of
timestamps in the opening paragraphs.
(Timestamps): Mention that time range.  Clarify that an entry may
contain multiple timestamps, providing an example.  Explain formal
time range meaning, with example.  Add cindex entry "time range".  Add
date range example.
* doc/org-guide.org: Syncronoize changes with org-manual, adding some
missing pieces.
(Timestamps): Remove useless cindex entries (org-guide does not
produce index).

Co-authored-by: Ihor Radchenko <yantar92@posteo.net>
Link: https://orgmode.org/list/SJ0PR03MB5455693CA8266256D46BA594A259A@SJ0PR03MB5455.namprd03.prod.outlook.com

TINYCHANGE
2023-06-18 13:23:36 +03:00
Ihor Radchenko 1ec3a43c58
org-lint: Add checker for misspelled export options in properties
* lisp/org-lint.el (org-lint-export-option-keywords): New linter
checking export properties without EXPORT_.

Link: https://orgmode.org/list/87ttv7kp2j.fsf@k-7.ch
2023-06-17 15:09:03 +03:00
Ihor Radchenko 739c8989a7
Merge branch 'bugfix' 2023-06-15 12:39:12 +03:00
Ihor Radchenko a072608567
org-set-font-lock-defaults: Fix checkbox fontification
* lisp/org.el (org-set-font-lock-defaults): Use full
`org-list-full-item-re' that accounts for alphabetical bullets as
well.

Reported-by: pondersson <pondersson@gmail.com>
Link: https://orgmode.org/list/CAHewz5N5vNMiWFuG3t=bZoyVmsYswyerZ6VsLC88DGTXR+AhOA@mail.gmail.com
2023-06-14 13:49:09 +03:00
Ihor Radchenko 2f7b35ac89
org-element-cache: Reduce memory footprint in indirect buffers
* lisp/org-element.el (org-element--cache-setup-change-functions): Set
buffer-local cache values to nil in indirect buffers.

Reported-by: Sebastian Wålinder <s.walinder@gmail.com>
Link: https://orgmode.org/list/87v8funovi.fsf@localhost
2023-06-13 13:08:48 +03:00
Ihor Radchenko 34082ff184
org-indent-line: Fix with line is within blank lines after heading
* lisp/org.el (org-indent-line): Fix when we are within blank lines
after heading.  ELEMENT is then `heading' and looking at :begin - 1
does not make sense.
* testing/lisp/test-org.el (test-org/indent-region): Add test.

Reported-by: Jens Schmidt <jschmidt4gnu@vodafonemail.de>
Link: https://orgmode.org/list/d7129804-1f42-ea2b-85e8-18ea1ee32d73@vodafonemail.de
2023-06-11 13:16:31 +03:00
Ihor Radchenko b29edcaf82
Merge branch 'bugfix' 2023-06-11 12:25:27 +03:00
Ihor Radchenko 9082fa8892
Merge branch 'bugfix' 2023-06-08 16:14:13 +03:00
Ihor Radchenko c9f3de6e8f
Merge branch 'bugfix' 2023-06-07 20:34:23 +03:00
Ihor Radchenko 16f15f9665
* doc/org-manual.org (Export hooks): Fix example hook
Set `org-map-continue-from' in the hook as otherwise the example won't
work if user try the example on buffer with headings not separated by
contents or empty lines.

Reported-by: Victor A. Stoichita <victor@svictor.net>
Link: https://orgmode.org/list/877csf6yva.fsf@svictor.net
2023-06-07 20:28:31 +03:00
Ihor Radchenko ba8c468634
org-insert-todo-heading-respect-content: Fix regression in b4e41b
* lisp/org.el (org-insert-todo-heading-respect-content): Do not force
first TODO keyword in the inserted heading.  Instead, accept prefix
arguments and pass them directly to `org-insert-todo-heading'.
* etc/ORG-NEWS (~org-insert-todo-heading-respect-content~ now accepts
prefix arguments): Document the change.
*
testing/lisp/test-org.el (test-org/insert-todo-heading-respect-content):
Add tests.

Reported-by: Xuan Wang <xuan.public@gmail.com>
Link: https://orgmode.org/list/CALjN2yehOVYZuU+tURes+mJ5XyTrRY1O0UG1ijH-6TjJ=W0ibw@mail.gmail.com
2023-06-07 15:18:16 +03:00
Ihor Radchenko 661a98f891
org-insert-todo-heading: Update docstring
* lisp/org.el (org-insert-todo-heading): Use docstring construct when
talking about prefix argument.
2023-06-07 15:12:04 +03:00
Ihor Radchenko a144b23550
doc/org-manual.org: Document `org-latex-src-block-backend'
* doc/org-manual.org (Source blocks in LaTeX export): Explain possible
LaTeX export options for source blocks.
2023-06-03 11:27:45 +03:00
Ihor Radchenko e83d4e94d8
fixup! org-fold-core: Fix folding for `isearch-filter-prediacate' outside isearch
* lisp/org-fold-core.el (org-fold-core--isearch-show-temporary): Fix
edge case when `org-fold-core--isearch-local-regions' contains empty
region.
2023-06-03 11:09:52 +03:00
Ihor Radchenko dbb451dc9d
org-manual.org: Explain that noweb expansion does not carry over :var
* doc/org-manual.org (Noweb Reference Syntax): Provide an example
explaining that :var header arguments are not in effect when expanding
noweb reference.

Reported-by: Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>
Link: https://orgmode.org/list/46e6f579-9eca-e1da-06ea-f2478a603c5a@posteo.de
2023-06-02 16:08:53 +03:00
Ihor Radchenko 07521331c3
org-image-max-width: Allow floating point value as fraction of window width
* lisp/org.el (org--create-inline-image): Allow `org-image-max-width'
to be a floating point value - fraction of window width.
(org-image-max-width): Update the docstring and type specification.
2023-06-02 14:55:36 +03:00
Ihor Radchenko 1cb5de6211
org-eval: Use `condition-case-unless-debug' for better backtraces 2023-06-02 10:52:12 +03:00
Basil L. Contovounesios a00889997b
doc/org-manual.org: Mark up nil as ~nil~
* doc/org-manual.org (Images, Plain lists in Texinfo export)
(Results of Evaluation): Mark up plain nil as ~nil~.
(Org Crypt): Ditto.  Clarify wording.
2023-06-02 10:30:32 +03:00
Leo Butler d55a112149
lisp/ob-C.el: replace %f with %s to prevent unneeded rounding
* lisp/ob-C.el (org-babel-C-val-to-C-type): Floats should be printed
as string literals to prevent rounding introduced by %f format.

* testing/lisp/test-ob-C.el (ob-C/float-var): Test that floats are not
rounded when passed as an org :var.
2023-06-02 10:23:58 +03:00
Ihor Radchenko 2c77551a68
org-texinfo-export-to-info: Fix docstring
* lisp/ox-texinfo.el (org-texinfo-export-to-info): Remove description
of a removed argument from the docstring.  The PUB-DIR argument has
been removed in 496ed832d.

Reported-by: Niall Dooley <dooleyn@gmail.com>
Link: https://list.orgmode.org/orgmode/CADS3Lq7W=LZYd3F3aA0p1RaDWdHSmwahvs8oyJfx_Hw0WF9K9Q@mail.gmail.com/
2023-06-02 10:23:57 +03:00
Ihor Radchenko 5b4eebfabd
Prefer `condition-case-unless-debug' where possible
* lisp/org-clock.el (org-clock-play-sound):
* lisp/org-element.el (org-element-at-point):
* lisp/org-src.el (org-src--edit-element):
(org-fontify-inline-src-blocks):
* lisp/org.el (ox):
(org-fontify-meta-lines-and-blocks):
(org-map-dblocks):
* lisp/ox-odt.el (org-odt--export-wrap): Use
`condition-case-unless-debug' to allow more descriptive backtraces
when `debug-on-error' is non-nil.

Link: https://orgmode.org/list/878rdnq1iy.fsf@web.de
2023-06-01 15:05:22 +03:00
Ihor Radchenko 7dee2c07f4
org-fold-core: Fix folding for `isearch-filter-prediacate' outside isearch
* lisp/org-fold-core.el (org-fold-core--keep-overlays): New internal
macro, signaling `org-fold-core-region' to keep overlays in place and
store new overlays for later use in isearch.
(org-fold-core-region): Never remove overlays and store newly created
ones in `org-fold-core--isearch-overlays' when
`org-fold-core--keep-overlays' is non-nil.  Remove resolved FIXME.
(org-fold-core--isearch-setup): Advice `isearch-clean-overlays' as
more reliable way to clear all the temporary overlays created for
isearch.  `query-replace' and EVIL packages use
`isearch-filter-predicate' separately as thus `isearch-mode-end-hook'
is not sufficient to ensure that isearch overlays are converted back
to text properties.
(org-fold-core--isearch-show-temporary): Do not alter match data, as
isearch expects the match data to stay unchanged.  Arrange the
overlays to be kept for isearch consumption (otherwise, isearch will
signal an error; see
https://list.orgmode.org/orgmode/87pmc4smdg.fsf@fastmail.fm/).
(org-fold-core--create-isearch-overlays): Call `org-fold-core-region'
with let-bound `org-fold-core-style' instead of repeating the code
from `org-fold-core-region'.

Reported-by: Michael Dauer <mick.dauer@gmail.com>
Link:
https://list.orgmode.org/orgmode/CAP7OBx+L11ck3Ni6rv94HGU3otdj6C4rG-rMDzkwR1LTj=BWiw@mail.gmail.com/
Link+: https://list.orgmode.org/orgmode/87pmc4smdg.fsf@fastmail.fm/
Link+: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=60399
Link+: https://yhetil.org/emacs-devel/87fs7c10cq.fsf@web.de/
2023-06-01 14:24:33 +03:00
Ihor Radchenko 873b0d22fd
org-fold-core--isearch-reveal: Fix typo
* lisp/org-fold-core.el (org-fold-core--isearch-setup): Fix arguments
in the `org-fold-core-get-region-at-point' call.
2023-06-01 14:22:59 +03:00
Ihor Radchenko 74198ac49c
org-lint: Add linter for unknown babel language
* lisp/org-lint.el (org-lint-suspicious-language-in-src-block): New
linter checking for unknown src block languages.
2023-05-31 11:40:47 +03:00
Ihor Radchenko 3123caa8e9
org-display-inline-images: Expand environment variables in image path
* lisp/org.el (org-display-inline-images): Expand environment
variables in the link path, just like `org-open-file' does.

Reported-by: Pan Xie <xiepan@skyguard.com.cn>
Link: https://orgmode.org/list/7a012430-6084-e693-1a86-f14d0512bebc@skyguard.com.cn
2023-05-31 11:20:02 +03:00
Ihor Radchenko 24ed8b204e
org-mode-tags-syntax-table: Make the value available outside Org buffers
* lisp/org.el (org-mode-syntax-table): New explicitly defined variable
for Org mode syntax table.
(org-mode-tags-syntax-table): Define value in advance, available even
before Org mode is loaded.
(org-mode): Use the new `org-mode-syntax-table' variable.

Reported-by: Daniel Clemente <n142857@gmail.com>
Link: https://orgmode.org/list/CAJKAhPCcMwZS6aYK9MRKsjds9uTivOdfC9nzMok70Df8vR3tPA@mail.gmail.com
2023-05-29 11:30:58 +03:00
Ihor Radchenko aa3980dd7f
test-org/return: Add test clauses for `org-return' at citations
* testing/lisp/test-org.el (test-org/return): Add new tests checking
new functionality of `org-return' at citations and citation
references.
2023-05-25 14:21:25 +02:00
Ihor Radchenko 513534f2a7
lisp/org.el: allow org-return to call org-open-at-point on citations
* lisp/org.el (org-return): When `org-return-follows-link' is non-nil
and point is over an org-cite citation or citation reference, call `org-open-at-point'.

TINYCHANGE
2023-05-25 14:21:20 +02: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
Kyle Meyer fa058f6d97 mk/org-fixup.el: Adjust for Emacs 29 autoload.el deprecation
* mk/org-fixup.el (org-make-org-loaddefs): Generate org-loaddefs.el
with loaddefs-generate if available.

Link: https://list.orgmode.org/87lenabrcv.fsf@kyleam.com
2023-05-21 17:06:59 -04: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 64e15ea0b0
Optimize org-element--cache-compare
* lisp/org-element.el (org-element--cache-key): Reduce property and
type queries.
(org-element--cache-compare): Convert into `defsubst'.
2023-05-18 15:22:49 +02:00
Ihor Radchenko 534045979d
org-element--current-element: Do not try to query cache
* lisp/org-element.el (org-element--current-element): Do not try to
search cache.  This is rarely useful and forces an awkward
`org-element-copy' workaround what parsing buffer.
(org-element--parse-elements): Do not use `org-element-copy' for
element at point - it is now safe to assume that
`org-element--current-element' does not return cached.
(org-element--parse-to): Do not force disabled cache when calling
`org-element--current-element'.  It is no longer needed.
2023-05-18 15:22:48 +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
Ihor Radchenko bfa362c47d
org-element-section-parser: Optimize performance
* lisp/org-element.el (org-element-section-parser): Call
`re-search-forward' directly instead of using `outline-next-heading'.
2023-05-18 14:15:02 +02:00
Ihor Radchenko 9d304d371e
org-indent-line: Remove unnecessary call to `org-element-at-point'
* lisp/org.el (org-indent-line): Do not re-calculate already known
element.
2023-05-18 14:14:58 +02:00
Ihor Radchenko fe74a3ed2d
org-crypt-decrypt-entry: Apply initial visibility upon decryption
* lisp/org-crypt.el: Call `org-cycle-set-startup-visibility' on the
decrypted entries.  Still re-fold if the decrypted entry has been
inside an existing fold.
* lisp/org-cycle.el (org-cycle-set-visibility-according-to-property):
Respect narrowing.
* etc/ORG-NEWS (=org-crypt.el= now applies initial visibility settings
to decrypted entries): Announce the change.

This patch solves a slight annoyance when the freshly decrypted entry
is fully unfolded, including all the property drawers.  It will make
more sense to make the folding state follow initial visibility
settings, including VISIBILITY properties.
2023-05-15 15:35:56 +02:00
Jim Wisniewski 9d06e7bf80
ox.el: Add more customizable `org-export-dispatch' options
* lisp/ox.el (org-export-dispatch): Add customizable variables
`org-export-body-only', `org-export-visible-only', and
`org-export-force-publishing', and use them in `org-export-dispatch'.
* doc/org-manual.org (The Export Dispatcher): Document the new export
variables.
* etc/ORG-NEWS (New customization options for ~org-export-dispatch~):
Announce the new customization options.

Currently when calling `org-export-dispatch', two of the export
options can have their defaults specified with customizable variables:
"Export scope" (via `org-export-initial-scope') and "Async export"
(via `org-export-in-background').  This change adds customizable
variables for the "Body only", "Visible only", and "Force publishing"
options as well.
2023-05-14 16:16:01 +02:00
Sławomir Grochowski 03afd25582
testing/lisp/test-org-colview.el: Add tests
* test-org-colview.el (test-org-colview/uncompile-format,
test-org-colview/compile-format): Add tests for functions:
`org-columns-uncompile-format' & `org-columns-compile-format'.
2023-05-14 16:06:41 +02:00
Ihor Radchenko cfb2ddab11
org-update-checkbox-count: Disable fold modification check 2023-05-14 14:11:26 +02:00
Ihor Radchenko ea3d06e57e
org-element--cache-active-p: Fix when cache is not initialized 2023-05-14 14:09:03 +02:00
Ihor Radchenko c0cdc5f77c
* lisp/org.el (org-at-heading-p): Do not call redundant `bolp' 2023-05-14 14:08:18 +02:00
Ihor Radchenko 546f2d86d1
org-add-prop-inherited: Avoid modifying S
* lisp/org.el (org-add-prop-inherited): Do not modify argument by side
effect.  Modifying strings may cause unexpected issues when working
with constant strings.

Link: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=62847
2023-05-14 14:05:27 +02:00
Ihor Radchenko c8e8f4e3c2
org-fold--reveal-headline-at-point: Fix edge case with invisible subtree 2023-05-14 14:04:41 +02:00
Ihor Radchenko 6fd6b94cd5
org-element-parse-buffer: Use "property" term consistently 2023-05-14 14:01:18 +02:00
Ihor Radchenko aafa0c2828
org-element: Cache commonly used property value strings in obarray
* lisp/org-element.el (org-element--string-cache): New obarray holding
common strings in Org AST.
(org-element--get-cached-string): New function retrieving interned
string object.
(org-element-drawer-parser):
(org-element-dynamic-block-parser):
(org-element-footnote-definition-parser):
(org-element-headline-parser):
(org-element-inlinetask-parser):
(org-element-item-parser):
(org-element-special-block-parser):
(org-element-keyword-parser):
(org-element-node-property-parser):
(org-element-src-block-parser):
(org-element-citation-parser):
(org-element-citation-reference-parser):
(org-element-export-snippet-parser):
(org-element-footnote-reference-parser):
(org-element-inline-babel-call-parser):
(org-element-inline-src-block-parser):
(org-element-link-parser):
(org-element-macro-parser): Reuse string objects that are likely to
occur in parsed elements.
2023-05-14 14:00:44 +02:00
Ihor Radchenko ec694f00de
org-element-inlinetask-parser: Store boolean instead of larger integer 2023-05-14 13:56:05 +02:00
Ihor Radchenko b70ef01ff2
org-element: Prefer property values that occupy less memory
* lisp/org-element.el (org-element-subscript-parser):
(org-element-superscript-parser): Use boolean values where it is
sufficient.
2023-05-14 13:55:35 +02:00
Ihor Radchenko 57eb97fa35
org-element: Consistently drop text properties when parsing
* lisp/org-element.el (org-element-headline-parser):
(org-element-inlinetask-parser):
(org-element-item-parser):
(org-element-example-block-parser):
(org-element-src-block-parser):
(org-element-link-parser):
(org-element-timestamp-parser): Do not preserve text properties in the
element property values that are strings.
2023-05-14 13:52:57 +02:00
Ihor Radchenko ef4d8adcaa
fixup! org-lint: Lint malformed timestamps 2023-05-13 12:42:05 +02:00
Ihor Radchenko ab542a6532
org-lint: Lint malformed timestamps
* lisp/org-lint.el (org-lint-timestamp-syntax): New linter checking
timestamp syntax.

Link: https://list.orgmode.org/orgmode/87a6c3urkv.fsf@localhost/
2023-05-13 12:39:25 +02:00
Ihor Radchenko 30b790f42b
org-refile: Fix heading being removed when refiling into itself
* lisp/org-refile.el (org-refile): Throw an error when attempting to
refile heading into itself and the point is not at bol.
* testing/lisp/test-org.el (test-org/refile): Add tests.

Reported-by: Oliver Epper <oliver.epper@gmail.com>
Link: https://list.orgmode.org/orgmode/CAP8tsuSEScO+Q7=g7kL=9Dk-95reJvUmLoyqmJjd2-ZM6iycfA@mail.gmail.com/
2023-05-11 12:07:27 +02:00
Ihor Radchenko 6e6354c074
org-tags-expand: Do no modify buffer's syntax table by side effect
* lisp/org.el (org-mode-tags-syntax-table): New variable holding
syntax table for tags.
(org-mode): Initialize tag syntax table.
(org-make-tags-matcher): Match tags using appropriate syntax table.
(org-tags-expand): Do no modify syntax table by side effect.

Reported-by: Mattias Engdegård <mattias.engdegard@gmail.com>
Link: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=63225#68
2023-05-08 13:23:15 +02:00
Ihor Radchenko fdea20084d
org-element-cache-map: Fix edge case
* lisp/org-element.el (org-element-cache-map): Fix when we use
NEXT-RE/FAIL-RE, the initial cached guess is not right, and the
NEXT-RE hits not-yet-cached element.
2023-05-07 14:56:54 +02:00
Max Nikulin ed0cfbd7b5
org-clock.el: Fix week start != 1
* lisp/org-clock.el (org-clock-special-range): Prevent returning
previous week for `thisweek' KEY when WSTART is 0.  Treat both 0 and 7
as Sunday.
* testing/lisp/test-org-clock.el (test-org-clock/special-range): New
test for `thisweek' and various WSTART arguments.

It seems only the case of weeks starting on Monday was tested.
Other variants caused shifted intervals.

Bug report: Marcin Borkowski. What is a week?
Mon, 10 Apr 2023 05:35:44 +0200.
<https://list.orgmode.org/87h6to1ka7.fsf@mbork.pl>
2023-05-07 10:03:52 +02:00
Ihor Radchenko 8944124edf
Revert "org-persist-gc: GC collections without persist file"
`org-persist-gc' is ran before `org-persist-write-all' and we may not
yet have all the persist files written.  Absence of a persist files is
thus not a sign that collection is expired.

This reverts commit e11073d17d.
2023-05-06 17:50:18 +02:00
Ihor Radchenko 080710797a
fixup! org-babel-common-header-args-w-values: Add docstring 2023-05-03 19:51:33 +02:00
Ihor Radchenko f268819d19
org-babel-common-header-args-w-values: Add docstring
* lisp/ob-core.el (org-babel-common-header-args-w-values): Add missing
docstring.
2023-05-03 19:19:28 +02:00
Ihor Radchenko e11073d17d
org-persist-gc: GC collections without persist file
* lisp/org-persist.el (org-persist-gc): Do not store collections that
lack persist file.  Such collection may emerge, for example, when
writing fails or gets blocked for some reason (in
`org-persist-before-write-hook' or when associated with encrypted
file).

Reported-by: Gustavo Barros <gusbrs.2016@gmail.com>
Link: https://orgmode.org/list/CAM9ALR_F4gjWxOVh_Eq14NOC9nF6g0Cv1jAKb=p4FjPvjqSkWQ@mail.gmail.com
2023-05-03 12:55:26 +02:00
Ihor Radchenko 5ec364a1ae
org-cite-list-bibliography-files: Preserve relative bibliography paths
* lisp/oc.el (org-cite-list-bibliography-files): When the bibliography
path is relative to the exported file location, keep the path
relative.  Resolve relative paths for bibliographies from SETUPFILE as
well.

* testing/lisp/test-oc.el (test-org-cite/list-bibliography-files):
* testing/examples/sub-bib/include-relative-bib.org:
* testing/examples/sub-bib/include-global-bib.org: New test.

Link: https://orgmode.org/list/CAO48Bk_upR4h-xd0YL+FxeKtWvDoqH+Eju6F_Vzds_m6oxBKcg@mail.gmail.com
2023-05-02 14:47:56 +02:00
Gerard Vermeulen e58bbded5c
lisp/ob-lisp: fix `org-babel-execute:lisp' for use with Sly
* lisp/ob-lisp (org-babel-execute:lisp): by default, Sly and Slime
talk with different RPC server programs with different names.
Specialize the prefix of eval-and-grab-output to Slime (prefix swank:)
or to Sly (prefix slynk:).
2023-05-02 14:09:37 +02:00
Ihor Radchenko 9ea50ca211
Use `calendar-buffer' constant to refer to calendar buffers
* lisp/org-agenda.el (org-agenda-diary-entry-in-org-file):
* lisp/org.el (org-read-date):
(org-eval-in-calendar):
(org-timestamp-change):
(org-recenter-calendar):
(org-get-date-from-calendar): Use `calendar-buffer' instead of
hard-coded "*Calendar*".

Reported-by: Thuna <thuna.cing@gmail.com>
Link: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=61546
2023-05-02 13:35:12 +02:00
Ihor Radchenko 05c3e59de1
org-manual: Document how to profile performance
* doc/org-manual.org (Feedback): Document how to deal with performance
degradation, add new index entries.
2023-05-01 14:41:17 +02:00
Ihor Radchenko 7ddc86a2ca
Merge branch 'bugfix' 2023-05-01 12:16:48 +02:00
Kyle Meyer e5ae9c0ce7 Merge branch 'bugfix' 2023-04-30 19:55:54 -04:00
Ihor Radchenko 128742418b
Merge branch 'bugfix' 2023-04-30 19:18:58 +02:00
Ihor Radchenko a686c7b609
ox-odt: Throw actual error when export fails
* lisp/ox-odt.el (org-odt--export-wrap): Throw an error rather than a
warning when export fails.
2023-04-30 19:18:21 +02:00
Ihor Radchenko c265d964f9
ox-odt: Improve some warning messages
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Reference
`org-odt-with-latex' variable in the warning to direct users what to
do.  Only display the warning when there are LaTeX fragments to
convert.
2023-04-30 19:07:26 +02: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 09cf89f712
org-delete-indentation: Support region selection
* lisp/org.el (org-delete-indentation): Support active region when the
first line in region is a heading.  Clarify in the docstring that
region is ignored with prefix argument.

Reported-by: Spencer Baugh <sbaugh@janestreet.com>
Link: https://orgmode.org/list/ier3552edfr.fsf@janestreet.com
2023-04-30 17:02:58 +02:00
Ihor Radchenko 76c3340557
* doc/org-manual.org: Fix obsolete variables
(Summary of In-Buffer Settings): Fix description of custom timestamp
overlay format.
2023-04-30 13:48:59 +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
Ihor Radchenko eb6cabdee5
mk: Expand shell commands once only
* mk/targets.mk (GITVERSION):
(GITSTATUS):
(DATE):
(YEAR): Only expand the variables once, not in every make sub-process.
Previous code ran pwd/date/git in every make sub-process, slowing
things down significantly and unnecessarily.
2023-04-30 11:38:23 +02:00
Ihor Radchenko 42e95938ed
org-latex-compile: Fix erasing PDF output buffer late
* lisp/ox-latex.el (org-latex-compile): Clear the PDF output log
buffer before running compile command.

Fixes regression introduced in 0dfbf0c3.

Reported-by: John Kitchin <jkitchin@andrew.cmu.edu>
Link: https://orgmode.org/list/CALEYq0_t38_gsmjE-qgPCX07-V0P8FYwYEt9R4AT0dZ_SnXRuA@mail.gmail.com
2023-04-30 10:17:09 +02:00
Ihor Radchenko 52d9961f50
org-set-tags-command: Provide more useful error when before first heading
* lisp/org.el (org-set-tags-command): Produce more useful error
message when point is before first heading.
2023-04-28 12:59:19 +02:00
Ihor Radchenko f067a4bd43
org-attach-tag: Work around error when before first heading
* lisp/org-attach.el (org-attach-tag): Avoid error thrown when trying
to set tags before first heading.  This is not a proper fix, but it
will at least allow attaching files to Org file.  The tagging will be
skipped for now, until setting FILETAGS is supported by Org API.
2023-04-28 12:52:09 +02:00
Ihor Radchenko 7e75571f02
Handle more compiler warnings from Emacs master
* lisp/org-macs.el (org-id-uuid): Use built-in `time-convert' instead
of function defined in org-compat.  `time-convert' can already be used
as it is available in Emacs 26.
2023-04-27 22:45:47 +02:00
Ihor Radchenko a8dbe8eb38
Merge branch 'bugfix' 2023-04-27 22:42:58 +02:00
Ihor Radchenko ef800e3bec
org--collect-keywords-1: Handle FIXME
* lisp/org.el (org--collect-keywords-1): Do not inhibit SETUPFILE in
read-only buffers.

It is unclear what kind of edge case the FIXME is trying to solve.
Yet, there is no reason to inhibit SETUPFILE processing in all the
read-only buffers (which may happen, for example, when refreshing Org
setup with C-c C-c).  Finally, if there is some bug in Gnus (if any)
we should better report it instead of using unexplained workaround.
2023-04-27 22:18:35 +02:00
Ihor Radchenko 2bc510217a
org-element--cache-find: Remove statistics gathering code
* lisp/org-element.el (org-element--cache-find): Do not collect
hashing statistics.  According to
https://orgmode.org/list/87sfffawfe.fsf@localhost, it is quite useful
for a fraction of users, yielding up to 30% recent cache queries being
memoized.  Add additional commentary.  Also, slight refactoring.
(org-element--cache-hash-nocache):
(org-element--cache-hash-statistics):
(org-element-cache-hash-show-statistics): Remove.
2023-04-27 15:26:56 +02:00
Ihor Radchenko 9e42842a82
org-persist: Fix :last-access being set on every write
* lisp/org-persist.el (org-persist-write:generic): Do not set
:last-access on write, unless writing first time.  Otherwise,
:last-access may never trigger expiration.
2023-04-26 23:39:49 +02:00
Ihor Radchenko eaf274909f
Consistently allow null character in block and drawer bodies
Also, do not use [^\000] as a poor-man's replacement for
(rx (or any newline)).

* lisp/ob-core.el (org-babel-src-block-regexp):
* lisp/ob-haskell.el (org-babel-haskell-export-to-lhs):
* lisp/org-compat.el (org-hide-block-toggle-all):
* lisp/org-element.el:
* lisp/org-feed.el (org-feed-read-previous-status):
(org-feed-parse-rss-feed):
(org-feed-parse-rss-entry):
* lisp/ox-org.el (org-org-publish-to-org):
* testing/lisp/test-ob-tangle.el:
* lisp/org.el (org-block-regexp):
(org-clock-drawer-re): Use \(.\|\n\) regexp instead of [^\000].
(org-latex-regexps): Do not try to match \000 inside latex fragments -
we now use parser for this purpose.

Reported-by: Tommy Kelly <tommy.kelly@verilab.com>
Link: https://orgmode.org/list/875yfk9vlv.fsf@localhost
2023-04-25 21:06:50 +02:00
Zelphir Kaltstahl d97ba5ba52
org-babel-expand-body:scheme: define header arg vars using define
* ob-scheme.el (org-babel-expand-body:scheme,
org-babel-expand-header-arg-vars:scheme): Change the way header
argument :var variables are expanded for for Scheme source blocks.  Use
`define' instead of wrapping using `let'.

Wrapping binding definitions using `let' can lead to issues with GNU
Guile and potentially other Scheme dialects.  GNU Guile will only get
to the body of the let at evaluation time, not at macro expansion
time.  If the let form wraps any imports of libraries that define
macros, then those imported macros are seen too late and their
corresponding forms inside the body of the let are not
expanded.  Using `define' to define bindings avoids this problem, at
least in GNU Guile.

For more context see the mailing list discussion at: https://lists.gnu.org/archive/html/emacs-orgmode/2023-03/msg00087.html

TINYCHANGE
2023-04-25 14:25:30 +02:00
Ihor Radchenko e065b53a4a
Merge branch 'bugfix' 2023-04-24 14:27:42 +02:00
Ihor Radchenko 56f651e961
org-lint: Add new linter for empty header arguments
* lisp/org-lint.el (org-lint-empty-header-argument):
(empty-header-argument): New linter.
2023-04-24 14:01:12 +02:00
Ihor Radchenko 6376237779
org-babel-parse-multiple-vars: Do no err on empty :var
* lisp/ob-core.el (org-babel-parse-multiple-vars): Parse empty :var
header argument into (:var) alist element.
2023-04-24 14:00:49 +02:00
Ihor Radchenko 9030cc394d
Merge branch 'bugfix' 2023-04-23 16:48:52 +02:00
Ihor Radchenko 466a37d089
Merge branch 'bugfix' 2023-04-22 15:29:08 +02:00
Ihor Radchenko f81ba451a7
Prefer "backend" over "back-end"
* doc/org-manual.org (Exporting): Add cindex entry for both "backend"
and "back-end" for better searchability.

All other changes are trivial.

Note that `org-element-export-snippet-parser' will still use :back-end
property.  So will ox.el in INFO channel.
2023-04-20 14:11:19 +02:00
Ihor Radchenko 9440a29828
Merge branch 'bugfix' 2023-04-20 11:05:12 +02:00
Ihor Radchenko 264d555e4b
org-org-publish-to-org: Handle fixme
* lisp/ox-org.el (org-org-publish-to-org): Remove setting buffer
modification status.

There is no clear reason why it should be done and none of the tests
are failing without this statement.  Can be re-added if a real problem
is encountered, with appropriate explanation in the comment.
2023-04-20 10:45:05 +02:00
Ihor Radchenko 3c449cc438
* testing/lisp/test-ob-R.el (ob-session-R-result-value): New test 2023-04-18 15:04:57 +02:00
Ihor Radchenko 83e446ea86
* testing/lisp/test-ob-R.el: Fix test failures with the newest ESS
(ob-session-async-R-simple-session-async-output):
(ob-session-async-R-named-output):
(ob-session-async-R-output-drawer): Force no truncation of output
lines in ESS.  Otherwise, the expected output may be split into
multiple lines.

Note that we do not want to override the output splitting outside
tests - this is what users may prefer for :results output.  And
:results value is not affected.

Link: https://orgmode.org/list/87ilduqrem.fsf@localhost
2023-04-18 15:04:47 +02:00
Ihor Radchenko 4929f0c55f
* lisp/ob-R.el: Fix ESS compatibility
(org-babel-R-initiate-session): Fix `require'.  Do not use obsolete
`R' function.
2023-04-17 20:20:58 +02:00
Matthew Trzcinski 26ef5e3e5b org-src: Use `sh-mode' for all the shells it can handle
* lisp/org-src.el (org-src--get-known-shells): New helper function
extracting known shells from `sh-ancestor-alist'
(org-src-lang-modes): Update the value

Link: https://orgmode.org/list/CAMbmz5ntkOHMiZG4EbNAks9ob-0ahnciCfHQ9LQmJoci0+i7fg@mail.gmail.com
2023-04-17 10:57:35 -04:00
Ihor Radchenko cfe5e01e14
org-lint: Add checker for $...$ LaTeX fragments
* lisp/org-lint.el (org-lint-LaTeX-$): New checker warning about
semi-obsolete $...$ LaTeX fragment syntax.

Link: https://orgmode.org/list/86ileukojk.fsf@lan
2023-04-17 16:00:41 +02:00
Ihor Radchenko ab85c1b958
org-fold: Allow customizing commands where invisible edits are checked
* lisp/org-fold.el (org-fold-catch-invisible-edits-commands): New
custom option.
(org-fold-catch-invisible-edits): Mention the new custom option in the
docstring.
(org-fold-check-before-invisible-edit-maybe): New function checking
if edits are safe for `this-command'.
(org-fold--advice-edit-commands): New function advising the functions
with `org-fold-check-before-invisible-edit-maybe'.
* lisp/org.el (org-mode): Advice functions on Org startup.
(org-self-insert-command):
(org-delete-backward-char):
(org-delete-char):
(org-meta-return): Do not call `org-fold-check-before-invisible-edit'
and rely on the new advise mechanism instead.
* etc/ORG-NEWS (Commands affected by ~org-fold-catch-invisible-edits~
can now be customized): Announce the change.
* doc/org-manual.org (Catching invisible edits): Mention new
customization.
2023-04-17 15:32:20 +02:00
Ihor Radchenko d4b66e99fd
Merge branch 'bugfix' 2023-04-17 13:12:22 +02:00
Ihor Radchenko 425f379458
Merge branch 'bugfix' 2023-04-17 12:48:10 +02:00
Ihor Radchenko 62996300ef
org-manual.org: Clarify the ox-md uses the original markdown spec
* doc/org-manual.org (Markdown Export): Make it more clear that we are
using the original Markdown spec.  Link to Wikipedia article
describing different Markdown favours.
2023-04-16 17:35:15 +02:00
Ihor Radchenko d57d90964f
Merge branch 'bugfix' 2023-04-16 13:55:39 +02:00
Ihor Radchenko 81acba727a
Merge branch 'bugfix' 2023-04-16 13:21:07 +02:00
Jack Kamm f4446ce795 ox-icalendar: Apply folding to whole VCALENDAR
Moves the calls to `org-icalendar-fold-string' out of
`org-icalendar--vevent' and `org-icalendar--vtodo', instead calling it
from `org-icalendar--vcalendar'.  This way, the string folding applies
to the entire VCALENDAR rather than just the VEVENT or VTODO, as
required by the iCalendar spec.

See also:
https://list.orgmode.org/m2pm85jyw1.fsf@eglen.org.uk/T/#md08cfd0209f6332a1a0c6a54f08544006ff93aed

* lisp/ox-icalendar.el (org-icalendar--vevent, org-icalendar--vtodo):
Remove call to `org-icalendar-fold-string'.
(org-icalendar--vcalendar): Add call to `org-icalendar-fold-string'.
2023-04-15 21:47:58 -07:00
Ihor Radchenko 7c8623be96
fixup! * doc/org-manual.org: Clarify "++" explanation for habits 2023-04-14 15:48:52 +02:00
Ihor Radchenko 8f058060ce
* doc/org-manual.org: Clarify "++" explanation for habits
(Tracking your habits): Do not create a confusion that one can use
"++" to make a habit repeat on weekdays/weekends.  Instead, make it
explicit that "++" can only keep certain day of week.  Also, link to
the repeater intervals section.
2023-04-14 15:46:37 +02:00
Ihor Radchenko 9607226610
org-export--prune-tree: Ensure spaces when removing objects
* lisp/ox.el (org-export--prune-tree): If the removed object has
trailing spaces and previous object does not have, keep the trailing
spaces.
* etc/ORG-NEWS (Blank lines after removed objects are not retained
during export): Document the change.

Reported-by: Andrea Lazzarini <andrea.lazzarini1@gmail.com>
Link: https://orgmode.org/list/87o7p7z9k3.fsf@localhost
2023-04-14 13:46:22 +02:00
TEC 5b300edf2e
etc/ORG-NEWS: Mention the new \P entity 2023-04-13 09:09:05 +02:00
TEC 00abdca361
oc-csl: Recognise ¶/§ entity locators
* lisp/oc-csl.el: Recognise org-entity based paragraph and section
locators "\P" and "\S".
2023-04-13 09:02:58 +02:00
TEC 0f62e9771b
org-entities: Treat ¶ similarly to §
* lisp/org-entities.el: Treat pilcrows / paragraph symbols similarly to
section symbols (§), move them next to each other and add a \P entity.
2023-04-13 09:02:58 +02:00
TEC cd53816c3a
org-entities: § is a section sign, not paragraph
* lisp/org-entities.el: Correct the ASCII version of § to be "section",
not "paragraph".
2023-04-13 09:02:57 +02:00
Ihor Radchenko 00fb0a0b33
Merge branch 'bugfix' 2023-04-13 09:02:47 +02:00
Ihor Radchenko 5d32058bf9
Merge branch 'bugfix' 2023-04-12 10:58:44 +02:00
Ihor Radchenko cd10999e7d
Merge branch 'bugfix' 2023-04-11 12:26:15 +02:00
Ihor Radchenko 8dd1cc04d0
Merge branch 'bugfix' 2023-04-09 13:16:38 +02:00
Ihor Radchenko ddd8281e62
lisp/org.el: Allow limiting inline image width
* lisp/org.el (org-image-max-width): New custom variable controlling
max inline image width.
(org--create-inline-image): Use the new variable.
* doc/org-manual.org (Images):
* etc/ORG-NEWS (New customization ~org-image-max-width~ limiting the
displayed inline image width): Document the new variable.
2023-04-09 10:55:50 +02:00
Ihor Radchenko 2ad8a45f00
test-ob-fortran: Enable and fix commented tests
* testing/lisp/test-ob-fortran.el (ob-fortran/wrong-list):
(ob-fortran/compiler-flags): Uncomment the tests, making sure that
error buffer is displayed.
2023-04-08 14:56:08 +02:00
Ihor Radchenko 28d41e69d7
Merge branch 'bugfix' 2023-04-07 12:37:40 +02:00
Nathaniel Nicandro 616e80a9f1
Handle block-type when checking `org-src-fontify-natively`
* lisp/org.el (org-fontify-meta-lines-and-blocks-1): Only fontify
  natively for blocks of src type.
2023-04-07 12:12:10 +02:00
Ihor Radchenko 8fab6eeef2
org-agenda: Rename sorting "priority" to "urgency"
* lisp/org-habit.el (org-habit-get-priority): Rename to
`org-habit-get-urgency'.
* lisp/org-compat.el (org-habit-get-priority): Obsolete the old name.
* lisp/org-agenda.el (org-agenda-sorting-strategy):
* lisp/org-agenda.el (org-search-view):
(org-agenda-get-todos):
(org-agenda-get-timestamps):
(org-agenda-get-progress):
(org-agenda-get-deadlines):
(org-agenda-get-scheduled):
(org-agenda-get-blocks):
(org-entries-lessp): Alter priority-up and priority-down sorting
strategies to only sort by actual priority.  Rename the previous
composite sorting rank to urgency, corresponding to the new urgency-up
and urgency-down sorting strategies.  Store the new rank in 'urgency
text property.  Update the docstrings accordingly.  Use `urgency-down'
in place of `priority-down' in the default sorting strategy.
(org-set-sorting-strategy): Use `urgency-down' in place of
`priority-down'.
* etc/ORG-NEWS ("Priority" used to sort items in agenda is renamed to
"urgency"): Document the change.
* doc/org-manual.org (Sorting of agenda items): Update manual using
"urgency" term in place of confusing "priority".

Thanks to Samuel Wales for the idea how to fix the inconsistency.

Reported-by: Jonas Olofsson <jonas.olofsson@apple.com>
Link: https://orgmode.org/list/26396316-1201-4D88-9D81-C87DDDA8885A@apple.com
2023-04-06 11:40:30 +02:00
Feraidoon Mehri 5e9953fa0e
ox.el: Refactor ID prefixes
* lisp/ox-html.el (org-html--id-attr-prefix):
* lisp/ox-odt.el (org-odt--id-attr-prefix): Refactor hardcoded "ID-"
as a new private variable.

* org/ox-html.el (org-html--reference): Add support for the ID
property (previously only supported CUSTOM_ID).

These changes make crossfile ID links work in the exported HTML when
`org-html-prefer-user-labels' is not-nil.
2023-04-05 11:22:32 +02:00
Ihor Radchenko 614b96f910
org-lint: Add checker for numbered list item numbers
* lisp/org-lint.el (org-lint-item-number): New checker to ensure
consistency between item bullet text and the counter Org will use when
exporting.
2023-04-04 12:05:03 +02:00
Jack Kamm e10b4054e6 ox-icalendar: Use consistent CRLF line endings
Fixes issue where the ox-icalendar export uses an inconsistent mix of
dos and unix style line endings.

* lisp/ox-icalendar.el (org-icalendar-fold-string): No longer converts
to CRLF, instead delegating that to `org-icalendar--post-process-file'.
(org-icalendar--post-process-file): New function to handle exported
file post-processing.  Converts EOL to CRLF, and then runs
`org-icalendar-after-save-hook'.
(org-icalendar-export-to-ics, org-icalendar-export-current-agenda,
org-icalendar--combine-files): Call `org-icalendar--post-process-file'
instead of running `org-icalendar-after-save-hook' directly.
* testing/lisp/test-ox-icalendar.el: New file for unit tests of
ox-icalendar.  Add an initial test for CRLF line endings.

See also:

https://list.orgmode.org/87o7oetneo.fsf@localhost/T/#m3e3eb80f9fc51ba75854b33ebfe9ecdefa2ded24

https://list.orgmode.org/orgmode/87ilgljv6i.fsf@localhost/
2023-04-02 13:20:56 -07:00
Ihor Radchenko 9ca271c406
org-export: Display warning when code block results cannot be computed
* lisp/ob-exp.el (org-babel-exp-results): Display warning when babel
does not know how to execute exported code block and :results
demands results to be exported.
2023-04-02 17:04:43 +02:00
Ihor Radchenko c316476ee9
org-export: Be less aggressive with window configuration in export dispatch
* lisp/ob-exp.el (org-babel-exp-process-buffer): Do not use
`save-window-excursion'.
* lisp/ox.el (org-export-dispatch):
(org-export--dispatch-ui): Use `save-window-excursion' only when
displaying the dispatch interface.
2023-04-02 17:00:06 +02:00
Ihor Radchenko c2ffc6b602
org-fontify-meta-lines-and-blocks-1: Fontify src blocks without lang
* lisp/org.el (org-fontify-meta-lines-and-blocks-1): Allow fontifying
src blocks with language specification missing.
* lisp/org-src.el (org-src-block-faces): Clarify in the docstring that
"" language name referes to src blocks with no language.  Remove
redundant :version tag.
* etc/ORG-NEWS (~org-src-block-faces~ now accepts empty string ~""~ as
language name): Announce the change.

Link: https://orgmode.org/list/99388ff3711696091f0312a5c3f0bcbd@kragelund.me
2023-04-02 16:32:00 +02:00
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 6f742685d7
org-metaup: Fix edge case when the upper subtree is moved further below
* lisp/org.el (org-metaup): Work around `org-move-subtree-down'
inserting before end marker.

Reported-by: Philipp Kiefer <phil.kiefer@gmail.com>
Link: https://orgmode.org/list/2248cb94-e400-08c7-b76b-bbae2d877ca7@gmail.com
2023-04-02 16:16:06 +02:00
Ihor Radchenko 15e70240e9
org-manual.org: Clarify what SETUPFILE does
* doc/org-manual.org (Summary of In-Buffer Settings): Clarify that
only in-buffer settings are considered in SETUPFILE.  Other contents
is ignored.  Split the explanation into multiple paragraphs.

Reported-by: Bruno BEAUFILS <bruno.beaufils@univ-lille.fr>
Link: https://orgmode.org/list/20230216235224.7g5xdlkcnw2z4k3n@settat
2023-04-02 15:58:04 +02:00
Jack Kamm e46811c5e1 ob-python: Allow working with externally started sessions again
* lisp/ob-python.el (python-shell-buffer-name): Remove unneeded
defvar.
(org-babel-python-initiate-session-by-key): Check if session already
existed before run-python.  Only wait for initialization if it's a
newly started session.  Also simplify the code a bit by combining
multiple setq and let statements into a single let statement.  Also
add a comment about why adding to `python-shell-first-prompt-hook'
after `run-python' should be safe from race conditions.
2023-03-31 09:11:42 -07:00
Ihor Radchenko 1a6d5f11d0
Merge branch 'bugfix' 2023-03-29 16:59:01 +02:00
Ihor Radchenko f53205a443
org-export-data: Clarify that filters are not applied
* lisp/ox.el (org-export-data): Clarify the docstring.
2023-03-29 16:34:11 +02:00
Ihor Radchenko c1bb68ab9d
ox: Make export errors more prominent
* lisp/ox-html.el (org-html-fontify-code):
* lisp/ox-latex.el (org-latex-generate-engraved-preamble):
(org-latex-inline-src-block):
(org-latex-src-block):
(org-latex-src--engrave-code):
* lisp/ox-odt.el:
(org-odt--table):
(org-odt--translate-latex-fragments):
(org-odt--export-wrap): Use `warn' instead of `message' when external
dependency/tool is missing/fails.
2023-03-29 16:30:41 +02:00
Ihor Radchenko e9110a8dd7
Prefer `string-search' when matching exact strings
* lisp/ob-core.el (org-babel-inline-result-wrap):
(org-babel-demarcate-block):
* lisp/org-agenda.el (org-agenda-get-represented-categories):
* lisp/org-persist.el (org-persist--read-elisp-file):
* lisp/ox-beamer.el (org-beamer--format-frame):
* lisp/ox-latex.el (org-latex--environment-type):
(org-latex--inline-image): Use a simple and faster `string-search'
when searching for non-regexps.
2023-03-29 15:54:24 +02:00
Ihor Radchenko 88f7bea169
org-babel-temp-stable-file: Avoid `sxhash' collisions
* lisp/org-macs.el (org-sxhash-safe): New function to calculate object
hashes.  Unlike `sxhash', the new function ensures that
if (= (org-sxhash-safe A) (org-sxhash-safe b)) then (equal A B)
Not just the opposite.
* lisp/ob-core.el (org-babel-temp-stable-file): Use the new function.

Reported-by: Thomas Worthington <thomas.worthington@cosector.com>
Link: https://orgmode.org/list/877cwrcdh2.fsf@localhost
2023-03-29 15:10:19 +02:00
Ihor Radchenko 05ae268973
org-fold-show-children: Only display direct children by default
* lisp/org-fold.el (org-fold-show-children): Clarify the docstring
emphasizing that direct children are always displayed.  Fix
grandchildren being displayed when the first child has deeper level
than the next children.
2023-03-29 14:58:28 +02:00
Ihor Radchenko e80ba42d62
Merge branch 'bugfix' 2023-03-27 13:14:02 +02:00
Stephen J. Eglen 1e38519b02
doc/org-manual.org: Document `org-hide-emphasis-markers'
* doc/org-manual.org (Emphasis and Monospace): Document
`org-hide-emphasis-markers'.
2023-03-27 13:12:59 +02:00
Ihor Radchenko 44e1cbb094
org-compile-file: Fix when `org-batch-test' is not defined
* lisp/org-macs.el (org-compile-file): Avoid error when
`org-batch-test' is not defined.
2023-03-24 14:59:36 +01:00
Ihor Radchenko 866ed1a3c5
org-babel-comint-with-output: Fix edge case for partial prompts
* lisp/ob-comint.el (org-babel-comint-with-output): Do not try to
filter out prompts in `comint-output-filter-functions'.  The prompts
may arrive there arbitrarily - multiple prompts together, partial
prompts, full prompts, etc.  For example "ghci> " prompt may arrive as
"gh" + "ci> " with second part still matching `comint-prompt-regexp'.
As a result, if we keep using `comint-output-filter-functions', the
split prompts may sometimes retain their initial part, littering the
results.  Now, we postpone filtering to after receiving the output,
still making sure that agglomerated prompts gets filtered using a
custom regexp derived from `comint-prompt-regexp'.
2023-03-24 11:15:58 +01:00
Ihor Radchenko a8a516ba33
org-babel-comint-with-output: Handle agglomerated prompts better
* lisp/ob-comint.el (org-babel-comint-with-output): Consider that
comint can sometimes agglomerate multiple prompts together even within
a single output increment as passed to
`comint-output-filter-functions'.

Example in GHC comint buffer:

GHCi, version 9.0.2: https://www.haskell.org/ghc/  :? for help
ghci> ghci> :{
main :: IO ()
main = putStrLn "Hello World!"
:}

main
"org-babel-haskell-eoe"
ghci| ghci| ghci| ghci> ghci> Hello World!
ghci> "org-babel-haskell-eoe"
ghci>
2023-03-24 10:46:05 +01:00
Matthew Trzcinski 6c9104f59c etc/ORG-NEWS: Announce :async header in ob-shell.el 2023-03-23 15:30:31 -04:00
Ihor Radchenko 03d15dd724
org-logind-dbus-session-path: Fix CI tests failure
* lisp/org-clock.el (org-logind-dbus-session-path): Do not try to use
dbus when `dbus-call-method' errs.

`dbus-call-method' may throw
Debugger entered--Lisp error: (dbus-error "org.freedesktop.login1.NoSessionForPID" "PID 7361 does not belong to any known session")
Do not try to use dbus method in such scenario.

Link: https://builds.sr.ht/~bzg/job/961763
2023-03-23 13:47:38 +01:00
Daniel Kraus 880782660a
ob-clojure.el: Reword docstring for ob-clojure-eval-with-cider
* lisp/ob-clojure.el (ob-clojure-eval-with-cider): Mention in the
docstring that the Babel params argument is not used anymore.
2023-03-23 13:25:15 +01:00
Aaron L. Zeng 04087be6b3
lisp/org.el: Make predicates non-interactive
* lisp/org.el (org-at-date-range-p):
(org--math-p):
(org-first-sibling-p): Remove interactive spec.

Predicates like `org-first-sibling-p' are no use when called
interactively, and should not appear in the M-x prompt.

TINYCHANGE
2023-03-23 12:59:27 +01:00
Nathaniel Nicandro 693df6fd90
lisp/org-clock.el: Add support for logind
* lisp/org-timer.el (org-logind-dbus-session-path): New variable.
(org-logind-user-idle-seconds): New function.
(org-user-idle-seconds): Use them.
* etc/ORG-NEWS (Add support for ~logind~ idle time in
~org-user-idle-seconds~): Document the new feature.
2023-03-23 12:43:30 +01:00
Matthew Trzcinski f7aa8c19f5 ob-shell.el: Add async evaluation
* ob-shell.el (org-babel-sh-evaluate): Add condition for async within
session.  Allow :async header argument to be either t or blank.

* test-ob-shell.el:
(test-ob-shell/session-async-valid-header-arg-values): Check that
:async header works for both t and blank values.
(test-ob-shell/session-async-inserts-uuid-before-results-are-returned):
Check that UUID is used as placeholder until results return.
(test-ob-shell/session-async-evaluation): Check that asynchronously
evaluated results are eventually placed in the buffer.

Link: https://list.orgmode.org/186283d230a.129f5feb61660123.3289004102603503414@excalamus.com/
2023-03-22 14:55:11 -04:00
Matthew Trzcinski 180c1c37a9 ob-comint.el: Fix off-by-one error in async result
* ob-comint.el (org-babel-comint-async-filter): Fix region returned
after async calculation completes so that the trailing prompt ends in
a space.

Link: https://list.orgmode.org/18705dca9b8.f4f7e70c165671.6021704484862511260@excalamus.com/
2023-03-22 14:25:51 -04:00
Matthew Trzcinski cb95d88936 ob-R.el/ob-python: Update `md5' calls to `org-id-uuid'
* ob-R.el (ob-session-async-org-babel-R-evaluate-session): Use
`org-id-uuid' instead of `md5' as results placeholder.

* ob-python.el (org-babel-python-async-evaluate-session): Use
`org-id-uuid' instead of `md5' as results placeholder.
2023-03-22 14:20:47 -04:00
Matthew Trzcinski 5a52ee57d4 org-macs.el: Move UUID related code
* org-id.el (org-id-uuid): Move to org-macs.el.

* org.el (org-uuidgen-p): Move to org-macs.el.  Expose regexp used to
match UUID.

* org-macs.el (org-uuid-regexp): Refactor `org-uuidgen-p' to expose
regexp used to match UUID.
2023-03-22 14:08:08 -04:00
Ihor Radchenko 20b33106cd
org-element-headline-parser: Fix empty headings with tags
* lisp/org-element.el (org-element-headline-parser): Allow empty title
with tags.  Do not consider space after COMMENT to be a part of title.
*
testing/lisp/test-org-element.el (test-org-element/headline-todo-keyword):
Add tests.

Reported-by: Leo Butler <Leo.Butler@umanitoba.ca>
Link: https://orgmode.org/list/87zg8t4zgo.fsf@localhost
2023-03-22 16:08:32 +01:00
Ihor Radchenko 93bf820384
org-element-headline-parser: Treat "* TODO" as empty title + TODO keyword
* lisp/org-element.el (org-element-headline-parser): Allow end of line
instead of space after todo keyword.
*
testing/lisp/test-org-element.el (test-org-element/headline-todo-keyword):
Add new test.
2023-03-22 15:52:24 +01:00
Daniel Kraus cd2355a204
ob-clojure.el: Fix compiler warning
* lisp/ob-clojure.el (ob-clojure-eval-with-cider): Silence compiler
warning about unused argument 'params'.
2023-03-19 21:39:07 +01:00
Ihor Radchenko a645a6d679
Merge branch 'bugfix' 2023-03-19 14:06:34 +01:00
Ihor Radchenko 533a83a989
org-compile-file: Expose logs when running Org tests
* lisp/org-macs.el (org-compile-file): Output logs on failure when
running Org test suite.  This is useful to expose more information in
CI tests.
2023-03-19 11:10:04 +01:00
Max Nikulin 07ea7fc443
org-manual.org: $n$-th is not math
* doc/org-manual.org (LaTeX fragments): Do not state that dash is
allowed after single "$" math delimiter and recommend "\(...\)".

Detection of "$-" as closing math delimiters has been broken since 2015
as a side effect of using punctuation class in regular expressions while
dash is considered as a word constituent.  See commits
6779f8f424 and c0369a7984.  Bring the manual in accordance to the code
instead of allowing "($-2 change)" false positives.  Users who do not
like "\(...\)" constructs may use a helper for typing it and may change
how it is displayed to minimize visual noise by fontification, see

- Eric S Fraga to emacs-orgmode. Re: Depreciating TeX-style LaTeX
  fragments. Sun, 16 Jan 2022 12:10:30 +0000.
  <https://list.orgmode.org/87k0ezdgp5.fsf@ucl.ac.uk>
- Ihor Radchenko to emacs-orgmode. Re: [PATCH] Add support for $…$ latex
  fragments followed by a dash. Thu, 27 Jan 2022 16:28:10 +0800.
  <https://list.orgmode.org/87r18t7fc5.fsf@localhost>
2023-03-18 13:19:40 +01:00
Ihor Radchenko 6bf8e44d3f
Merge branch 'bugfix' 2023-03-18 13:03:31 +01:00
Ihor Radchenko 3b9ffc6868
org-latex-export-to-latex: Use nil arg for `write-region'
* lisp/ox.el: Use BEG=nil instead of explicit arguments to
`write-region'.  This simplifies the code.
2023-03-18 12:33:15 +01:00
Ihor Radchenko 4cad6c8eaf
* lisp/Makefile: Remove references to org-contrib
Since org-contrib is now a separate package, the parts of Makefile
that are referring to it are no longer needed.
2023-03-16 13:34:34 +01:00
Daniel Kraus 6efb073463
ob-clojure.el: Fix results output, support clojure-cli
* lisp/ob-clojure.el (org-babel-clojure-backend): Add support for
clojure-cli.
* lisp/ob-clojure.el (org-babel-clojurescript-backend): Move nbb to
clojurescript.
* lisp/ob-clojure.el (org-babel-expand-body:clojure)
* lisp/ob-clojure.el (ob-clojure-eval-with-cider): Return only the
last expression when :results is not set or value, and return only
stdout when :results is set to output.
* lisp/ob-clojure.el (ob-clojure-eval-with-cmd): Rename function as
it is not only for babashka.
* lisp/ob-clojure.el (org-babel-execute:clojure): Differentiate
between Clojure and ClojureScript source blocks.

The problem was that the ob-clojure results where not correctly
taking the results parameter into account.
E.g. with the cider backend, you would get all printed or returned
values for each line in your block:

(def small-map {:a 2 :b 4 :c 8})
{:some :map}
(prn :xx)
(:b small-map)

| #'user/small-map |
| {:some :map}     |
| 4                |

or for babashka you would only get the printed values but not the
last return value:
(def small-map {:a 2 :b 4 :c 8})
{:some :map}
(prn :xx)
(:b small-map)

: :xx

Now when you specify :results value, the result is only the last
returned value, and with :results output you get all values
printed to stdout.
So the examples above would all result in the same:
(def small-map {:a 2 :b 4 :c 8})
{:some :map}
(prn :xx)
(:b small-map)

: 4
2023-03-16 11:25:41 +01:00
Ihor Radchenko 635a601dd5
org-self-insert-command: Do not trigger folding checks
* lisp/org.el (org-self-insert-command): Do not trigger folding checks
for interactive edits.
2023-03-15 15:18:23 +01:00
Ihor Radchenko 0e7b5626ef
Merge branch 'bugfix' 2023-03-14 14:51:57 +01:00
Ihor Radchenko d2e8a118f6
Merge branch 'bugfix' 2023-03-14 13:21:28 +01:00
Ihor Radchenko 3d04af3826
org-latex-paragraph: Ensure that paragraphs are not split by empty lines
* lisp/ox-latex.el (org-latex-paragraph): If export creates single
paragraph contents with empty lines, remove the empty lines to ensure
that we retain a single paragraph.

Reported-by: Max Nikulin <manikulin@gmail.com>
Link: https://orgmode.org/list/tufdb6$11h2$1@ciao.gmane.io
2023-03-14 13:11:37 +01:00
Ihor Radchenko 5f817f21fc
Merge branch 'bugfix' 2023-03-12 12:25:39 +01:00
Tim Ruffing f5987b37d4
Don't reset `org-todo-keywords-for-agenda' when org-agenda-multi
* org-agenda.el (org-prepare-agenda): Don't reset
`org-todo-keywords-for-agenda' when org-agenda-multi.

Fixes a bug with TODO keywords that came to light in org-modern,
see https://github.com/minad/org-modern/issues/26.

This is very similar to cd2d138883,
which fixed the same for `org-done-keywords-for-agenda` (to fix
a similar styling issue).

TINYCHANGE
2023-03-11 11:18:52 +01:00
Ihor Radchenko d6e75d0eeb
org-read-date: Do not consider `org-extend-today-until' with default time
* lisp/org.el (org-read-date): When DEFAULT-TIME time provided, prefer
it even when `org-extend-today-until' dictates -1 day shift.  We
should only consider `org-extend-today-until' for actual today times,
not for future dates, where is becomes confusing.

Reported-by: Tim Ruffing <crypto@timruffing.de>
Link: https://orgmode.org/list/3489c1917ad4be0625ea5f0b2c1b0f2b72ea39e9.camel@timruffing.de
2023-03-11 10:30:15 +01:00
Ihor Radchenko 6ab611720d
Merge branch 'bugfix' 2023-03-10 12:10:47 +01:00
Ihor Radchenko 8589de94d8
Merge branch 'bugfix' 2023-03-07 14:09:48 +01:00
Ihor Radchenko c0a9c9edea
test-org-clock/mode-line: Update the docstring
* testing/lisp/test-org-clock.el (test-org-clock/mode-line): Link to
the info node explicitly.

Link: https://orgmode.org/list/m28rgbq8wo.fsf@me.com
2023-03-07 14:03:37 +01:00
Ihor Radchenko 12883765d2
org-babel-import-elisp-from-file: Fix the docstring
* lisp/ob-core.el (org-babel-import-elisp-from-file): Document all the
arguments.
2023-03-07 14:03:02 +01:00
Ihor Radchenko 077c4adabf
Merge branch 'bugfix' 2023-03-07 13:33:18 +01:00
Ihor Radchenko e52c531e17
Merge branch 'bugfix' 2023-03-05 13:22:02 +01:00
Ihor Radchenko 913e40a5bb
Merge branch 'bugfix' 2023-03-05 13:08:55 +01:00
Ihor Radchenko 1b1d314ada
* lisp/org.el: Bump Org version on development branch 2023-03-05 12:56:02 +01:00
Ihor Radchenko f93cc661c6
org-element-set-contents: Do alter the anonymous parents
* lisp/org-element.el (org-element-set-contents): Do alter anonymous
elements (el1 el2 ...).  Such elements are used, for example, when
parsing keyword values during export, like :title.
* testing/lisp/test-org-element.el (test-org-element/set-contents):
Add test.

The patch fixed bug during export when exporting a subtree with
option stat:nil.  The :title during subtree export is taken from the
heading title and parsed.  However, the parsed value is stored outside
the parse tree, in :title property of the INFO channel.  The parsed
value does get filtered through `org-export--prune-tree', but before
this commit, `org-element-set-contents' did not actually alter the
out-of-AST-tree parent lists of elements.

Reported-by: Leo Butler <Leo.Butler@umanitoba.ca>
Link: https://orgmode.org/list/87mt4w8epo.fsf@t14.reltub.ca
2023-03-03 16:31:37 +01:00
Ihor Radchenko 973669389b
Merge branch 'bugfix' 2023-03-03 15:57:17 +01:00
Ihor Radchenko aa22497876
Merge branch 'bugfix' 2023-02-26 14:43:54 +03:00
Ihor Radchenko 351279ffae
org-diary-to-ical-string: Make sure that temporary file/buffer is cleaned
* lisp/org.el (org-diary-to-ical-string): Clean temporary file buffer
on error.

Reported-by: Alexei Gilev <gerardomoro37@gmail.com>
Link: https://orgmode.org/list/CAF4Fj9gUBj4Ap4noTLP3aSG4owXJ2nydxaqwT4cF5x9DcdhQmg@mail.gmail.com
2023-02-23 12:41:38 +03:00
Ihor Radchenko 2e883b21a7
org-sbe: Allow quoting string values
* lisp/ob-table.el (org-sbe): Allow quoting string values of variables
with "$".  Update the docstring.
* testing/lisp/test-ob-table.el (test-ob-table/sbe): Add test.  Do not
use `org-test-at-id' in favor of more illustrative
`org-test-with-temp-text'.  The latter does not force users to search
the ID in reference Org file.
* testing/examples/babel.org (calling code blocks from inside table):
Remove unused example.

Reported-by: 赵一宇 <zhyznd@163.com>
Link: https://orgmode.org/list/40651be0.3e3b.1867971e644.Coremail.zhyznd@163.com
2023-02-23 12:29:18 +03:00
Ihor Radchenko cbab9ebf55
org-manual.org: Clarify that Imenu support is activated in future Org buffers
* doc/org-manual.org (Packages that Org cooperates with): Clarify that
imenu should be loaded before Org mode is loaded in current buffer.

Reported-by: Kuba Orlik <kontakt@kuba-orlik.name>
Link: Emacs bug#61685
2023-02-22 14:11:11 +03:00
Ihor Radchenko 236bd45849
Merge branch 'bugfix' 2023-02-22 13:20:47 +03:00
Ihor Radchenko d94f4066e0
oc-natbib: Provide a fallback bibliography style
* lisp/oc-natbib.el (org-cite-natbib-bibliography-style): New custom
option for default bibliography style.
(org-cite-natbib-export-bibliography): Use the new custom option.
* etc/ORG-NEWS (New ~org-cite-natbib-export-bibliography~ option
defining fallback bibliography style): Document the new option.

If we do not specify a bibliography style, LaTeX export will fail.
After the patch, the following simple-minded Org document will export
without errors:

 #+title: Testing org-cite \LaTeX export
 #+latex_header: \usepackage{natbib}
 #+bibliography: bibliography.bib
 #+options: toc:nil
 #+cite_export: natbib

 Hello World! This is a citation: [cite:@citationkey2023]

 #+print_bibliography:
2023-02-20 16:48:48 +03:00
Matthew Trzcinski aa158da69b test-ob-shell: Fix test buffers not being removed on success
* test-ob-shell.el (test-ob-shell/remote-with-stdin-or-cmdline): Kill
test related buffers when test is successful.  See ce4f7db3c.
2023-02-19 18:19:45 -05:00
Ihor Radchenko 747e60629f
org-cycle: Allow intuitively used values of of `org-startup-folded'
* lisp/org-cycle.el (org-cycle-set-startup-visibility): Recognize
`org-startup-folded' set to symbols `fold', `nofold', and `showall'.
They are used as #+STARTUP: option and often tried blindly by users.
2023-02-18 15:31:14 +03:00
Ihor Radchenko fe92a3cedb
Provide a uniform way to inform users about missing third-party packages
* lisp/org-macs.el (org-require-package): New macro trying to load a
library and displaying custom error message or warning on failure.
The actual package (not library) name can be provided as optional
argument.

* lisp/ob-R.el (org-babel-R-initiate-session):
* lisp/ob-clojure.el (ob-clojure-eval-with-inf-clojure):
(ob-clojure-eval-with-cider):
(ob-clojure-eval-with-slime):
* lisp/ob-forth.el (org-babel-forth-session-execute):
* lisp/ob-gnuplot.el (org-babel-execute:gnuplot):
(org-babel-gnuplot-initiate-session):
* lisp/ob-haskell.el (org-babel-interpret-haskell):
(org-babel-haskell-initiate-session):
* lisp/ob-js.el (org-babel-execute:js):
(org-babel-js-initiate-session):
* lisp/ob-julia.el (org-babel-julia-initiate-session):
* lisp/ob-lisp.el (org-babel-execute:lisp):
* lisp/ob-ocaml.el (org-babel-prep-session:ocaml):
* lisp/ob-octave.el (org-babel-octave-initiate-session):
* lisp/ob-processing.el (org-babel-processing-view-sketch):
* lisp/ob-ruby.el (org-babel-execute:ruby):
(org-babel-ruby-initiate-session):
* lisp/ol-bbdb.el (org-bbdb-open):
(org-bbdb-complete-link):
(org-bbdb-anniv-export-ical):
* lisp/org-agenda.el:
* lisp/org-plot.el (org-plot/gnuplot):
* lisp/org.el:
* lisp/ox-ascii.el (org-ascii-table):
* lisp/ox-html.el (org-html-htmlize-generate-css):
* lisp/ox-org.el: Use the new macro.

* lisp/oc-csl.el: Add FIXME. oc-csl uses a custom function doing
similar job.

* lisp/ob-js.el (org-babel-js-initiate-session): Add FIXME noting that
the third-party package is outdated.
2023-02-17 17:09:23 +03:00
Ihor Radchenko 18a146a9d5
org-fold-core-previous-visibility-change: Fix edge case
* lisp/org-fold-core.el (org-fold-core-next-visibility-change): Take
into account that `previous-single-char-property-change' move the
point to the first position where the property is still unchanged.
* lisp/org-cycle.el (org-cycle-set-visibility-according-to-property):
Ignore invisibility when skipping subtree.

Reported-by: Philipp Kiefer <phil.kiefer@gmail.com>
Link: https://orgmode.org/list/96becf12-9a5a-2fc2-0105-a41528be1f66@gmail.com
2023-02-17 14:58:32 +03:00
Ilya Chernyshov 715f74db36
org-manual.org: Update timestamp and timerange definitions
* doc/org-manual.org (Timestamps): Document that time specification of the
form <2023-02-17 Fri 10:00-12:00> is not a timestamp, but a timerange.
2023-02-17 14:08:37 +03:00
Ihor Radchenko fff9239dc1
Merge branch 'bugfix' 2023-02-17 13:41:18 +03:00
Ihor Radchenko 74eb0f8bc9
Merge branch 'bugfix' 2023-02-15 18:31:04 +03:00
Ihor Radchenko 6b0c2775f0
org-persist-associated-files:file: Fix when container has been deleted
* lisp/org-persist.el (org-persist-associated-files:file): Do not err
when `org-persist-read' returns nil (failed to read).
2023-02-14 23:08:58 +03:00
Jack Kamm e6353d5b9c ob-python: Remove debugging print statement
* lisp/ob-python.el (org-babel-python-initiate-session-by-key): Remove
old print statement that was added for debugging.
2023-02-11 13:18:09 -08:00
Ihor Radchenko 1f332d6c5c
* lisp/org-clock.el: Remove completed FIXME 2023-02-11 14:55:28 +03:00
Kevin Brubeck Unhammer d2952e14d9
org-clock-clocktable-language-setup: Add a Norwegian translation
* lisp/org-clock.el (org-clock-clocktable-language-setup): Add
Norwegian Nynorsk translation.

Link: https://orgmode.org/list/87k00z1090.fsf@fsfe.org
2023-02-11 14:55:05 +03:00
Kevin Brubeck Unhammer bd34cb3f95
org-export-dictionary: Add Norwegian translations
* lisp/ox.el (org-export-dictionary): Add some translations.

Link: https://orgmode.org/list/87ilgj2jza.fsf@fsfe.org
2023-02-11 14:50:18 +03:00
TEC 02ae908b03
oc: Add org-cite-processor function
* lisp/oc.el (org-cite-processor): As a counterpart to the other cite
information accessor functions, add `org-cite-processor`.
2023-02-11 01:38:41 +08:00
TEC 663e200f54
ox: Document the setting of :parse-tree
* lisp/ox.el (org-export--annotate-info,
org-export--collect-tree-properties): Mention in comments the setting of
:parse-tree.
2023-02-11 01:38:41 +08:00
TEC 4fbd302df6
ox: Split up the org-export-as function
* lisp/ox.el (org-export--annotate-info, org-export-as): Separate out
the info-collection phase of `org-export-as' into a new function,
`org-export--annotate-info'.
2023-02-11 01:32:33 +08:00
Ihor Radchenko 6d37d2a8e7
* mk/targets.mk(GITVERSION): Provide commit number for shallow clones
Fall back to using git describe --always when git describe fails in
Org repo.

See https://orgmode.org/list/87bkmve8qv.fsf@gmail.com
2023-02-10 16:18:51 +03:00
Ihor Radchenko 9e9669a271
Merge branch 'bugfix' 2023-02-10 14:43:41 +03:00
Alan Schmitt 666a61bcc8
lisp/ox-beamer.el: add labels to latex export
* ox-beamer.el (org-beamer-environments-default): add label escape to
some environments
(org-beamer--format-block): generate label string for label escape
(org-beamer-environments-extra): document label escape

A new escape %l is available to be used in `org-beamer-environments-*'
to insert the label of the current block, obtained using
`org-babel--get-label'
2023-02-10 13:55:18 +03:00
Aaron L. Zeng 739ccf6cbf
org--batch-store-agenda-views: Fix treatment of lambda functions
* org-agenda.el (org--batch-store-agenda-views): Fix treatment of
lambda functions used as custom agenda commands.
`org-agenda-custom-commands' entries may specify a custom function
instead of a symbol like `tags-todo'.  `org--batch-store-agenda-views'
behaved differently from `org-agenda' when that custom function was
defined as a lambda rather than a symbol, incorrectly treating the
lambda form as a list of agenda commands.  Instead, use the same test
as `org-agenda' does to determine whether the command is a series.

TINYCHANGE
2023-02-09 12:59:24 +03:00
Ihor Radchenko 5d548c34fa
org-manual.org: Clarify what `org-timestamp-up'/`org-timestamp-down' does
* doc/org-manual.org (Clocking commands): Fix and add missing findex
entries.  Explain that only clocks recorded during current Emacs
session are considered when adjusting neighboring timestamps.

Reported-by: Robert Nikander <robert.nikander@icloud.com>
Link: https://orgmode.org/list/830BAEAD-AA4C-4226-A93E-1329B41194D7@icloud.com
2023-02-09 12:55:50 +03:00
Ihor Radchenko 6cbbf4cdbf
org-link-abbrev-alist: Fix :safe predicate
* lisp/ol.el (org-link-abbrev-alist): Check every element in the
alist when considering :safe values.

Reported-by: Qiantan Hong <qthong@stanford.edu>
Link: https://orgmode.org/list/950326F5-F72D-4F51-A946-F37E96971B08@stanford.edu
2023-02-08 16:44:34 +03:00
Ihor Radchenko c8a5fef910
Preserve active region after structure edits
* lisp/org-list.el (org-list-indent-item-generic):
* lisp/org.el (org-do-promote):
(org-do-demote): Do not deactivate mark after edits.
(org-metadown):
(org-metaup): Do not deactivate mark and do not exchange point and
mark in region.
* etc/ORG-NEWS (Datetree structure headlines can now be complex):
Announce the change.
2023-02-04 16:49:54 +03:00
Ihor Radchenko b665f8de31
org-metaup, org-metadown: Move subtrees in active region
* lisp/org.el (org-metaup):
(org-metadown): When active region contains headings, move the
containing subtrees according to the selection.  Do not deactive
region.
* testing/lisp/test-org.el (test-org/move-subtree): Add test.
* etc/ORG-NEWS (~org-metaup~ and ~org-metadown~ now act on headings in
region): Announce the new features.
2023-02-04 16:49:30 +03:00
Ihor Radchenko 581df107b0
org-clock-sum: Fix Emacs 26 compatibility after 2e901ed23
* lisp/org-clock.el (org-clock-sum): Use backwards-compatible
`org-encode-time'.
2023-02-04 13:46:23 +03:00
Ihor Radchenko ec5d76bce1
Merge branch 'bugfix' 2023-02-03 18:01:47 +03:00
Ihor Radchenko 2e901ed236
org-clock-sum: Optimize performance
* lisp/org-clock.el (org-clock-sum): Do not re-parse the timestamps,
reusing already-parser element.
2023-02-03 15:10:45 +03:00
Ihor Radchenko 0522c1850b
org-read-property-value: Fix DEFAULT arg when values are not restricted
* lisp/org.el (org-read-property-value): Honor DEFAULT argument when
property can have arbitrary value.

Reported-by: Janek F <xerusx@pm.me>
Link: https://orgmode.org/list/hh0ohv2LgPq86aW2Kp4AFV1VZ3yLuZafFLFqWN_NCciQcy86rxDkcZryr7gyPXrNzjFdP8lhdC0GS4c_XQtVXjOKDD-lqkJjlswSGX7OWvo=@pm.me
2023-02-03 14:42:35 +03:00
Ihor Radchenko 562cba7aab
Merge branch 'bugfix' 2023-02-03 14:29:32 +03:00
Ihor Radchenko a411192c11
Merge branch 'bugfix' 2023-02-03 14:21:11 +03:00
Ihor Radchenko e455df4a07
org-persist: Improve commentary
* lisp/org-persist.el: Update top comment.
(org-persist--index-hash):
(org-persist--report-time): Update docstrings.
2023-02-02 23:32:00 +03:00
Pedro Andres Aranda Gutierrez 8ae8a8462f
org-clock-clocktable-language-setup: Fix Spanish translation
* lisp/org-clock.el (org-clock-clocktable-language-setup): Translate
leftover English string and use more accurate translation for clocked
time.
2023-02-02 14:01:53 +03:00
Ihor Radchenko c8d20d023f
Merge branch 'bugfix' 2023-02-01 15:04:38 +03:00
Ihor Radchenko b4a1133a18
org-babel-eval: Clarify the purpose of 4a751709b in code
* lisp/ob-eval.el (org-babel-eval): Add comment.
2023-02-01 15:03:50 +03:00
Ihor Radchenko 9a00f6cd78
org-cite: Clarify how multiple bibliography sources are combined
* doc/org-manual.org (Citations): Clarify that all the global and
local bibliographies are used to search citation keys.

Link: https://orgmode.org/list/87fsc0gimd.fsf@uwaterloo.ca
2023-02-01 14:08:35 +03:00
Ihor Radchenko b363ec04a2
Merge branch 'bugfix' 2023-02-01 00:21:06 +03:00
Marco Wahl 0d01a198bc org-attach: Show Org Attach UI starting from top
* org-attach.el (org-attach): Move cursor to the top of the
UI-description buffer.

This matters when the buffer does not fit completely in the window for
display.  Without the change the user would see the bottom part.
2023-01-30 23:01:17 +01:00
Matthew Trzcinski 4a751709b5 lisp/ob-eval.el: Append newline to source block query
* lisp/ob-eval.el (org-babel-eval): Newline facilitates working with
Windows cmdproxy.exe.

Reported-by: "Osher Jacob" <osherz5@gmail.com>
Link: https://list.orgmode.org/orgmode/CAGsxwFZ88cybALCVGgma=5gENMhUa0Rk6xNkBNS_HdsmBgYe6w@mail.gmail.com/
2023-01-30 12:05:22 -05:00
Andreas Gerler 1f86003a5d
lisp/ob-sql.el: allow string in sql-connection-alist
* ob-sql.el (org-babel-find-db-connection-param): read
sql-connection-alist like sql.el/sql-connect and allow strings.

Signed-off-by: Andreas Gerler <baron@bundesbrandschatzamt.de>
2023-01-30 17:57:04 +01:00
Ihor Radchenko 0509a84786
Merge branch 'bugfix' 2023-01-30 12:06:49 +03:00
Jack Kamm aa48c80fe1 ob-python: Remove python-mode.el support
* lisp/ob-python.el (org-babel-python-mode): Moved to ob-compat.el,
and changed to a constant.
(org-babel-python-initiate-session-by-key): Remove code to support
python-mode.el.
(org-babel-python-send-string): Renamed from
`org-babel-python--send-string', turning it into a public function to
accommodate ob-python-mode-mode which advises this function. Also,
remove some code for python-mode.el.
(org-babel-python-evaluate-session): Update calls to renamed function
`org-babel-python-send-string'.
* lisp/ob-compat.el (org-babel-python-mode): Moved from ob-python.el,
and changed to a constant.
2023-01-27 11:30:51 -08:00
Ihor Radchenko 265e4a5747
Merge branch 'bugfix' 2023-01-27 13:35:28 +03:00
Ihor Radchenko 0c00590606
lisp/ob-scheme: Silence compiler
* lisp/ob-scheme.el (geiser-eval--error-msg): Declare external
function.
2023-01-27 13:19:12 +03:00
Ihor Radchenko 1810c625df
org-clock-x11idle-program-name: Prefer "xprintidle", when available
* lisp/org-clock.el (org-clock-x11idle-program-name): Change the
default value to "xprintidle" when its executable is available.
Fallback to previous default otherwise.  Update :package-version and
remove :version tags.
* etc/ORG-NEWS (New and changed options):
(~org-clock-x11idle-program-name~ now defaults to =xprintidle=, when available):
Document the change.

Link: https://orgmode.org/list/874jvkn1po.fsf@localhost
2023-01-27 13:16:14 +03:00
Ihor Radchenko 6001313b8f
Merge branch 'bugfix' 2023-01-26 12:21:17 +03:00
TEC 3e23682d37
ox: Fix non-renamed variable (f to file)
* lisp/ox.el (org-export-expand-include-keyword): In 2fecd96200 "f"
was renamed to "file", but one usage was missed, which is corrected
here.
2023-01-25 21:30:11 +08:00
Marc Nieper-Wißkirchen f35fb8ac2a
lisp/ob-scheme.el: Do not hide Scheme evaluation errors
* lisp/ob-eval.el (org-babel-eval-error-notify): Handle an exit code of nil.

* lisp/ob-scheme.el (org-babel-expand-body:scheme)
(org-babel-scheme-get-repl, org-babel-scheme-make-session-name)
(org-babel-scheme-execute-with-geiser)
(org-babel-scheme--table-or-string, org-babel-execute:scheme):
Display Scheme evaluation errors in an error buffer using
`org-babel-eval-error-notify'.

TINYCHANGE
2023-01-25 16:04:06 +03:00
Ihor Radchenko a6c882949e
Merge branch 'bugfix' 2023-01-24 21:20:30 +03:00
Ihor Radchenko 7ad7796546
org-update-dblock: Add comment
* lisp/org.el (org-update-dblock): Clarify that `org-update-dblock' is
called for side effects.

Reported-by: Marcin Borkowski <mbork@mbork.pl>
Link: https://orgmode.org/list/87sfg1nfii.fsf@mbork.pl
2023-01-24 12:49:02 +03:00
Ihor Radchenko 1f9249eb6e
Merge branch 'bugfix' 2023-01-24 12:21:05 +03:00
TEC 6b15897a56
ox: Remove unused let binding
* lisp/ox.el (org-export-parse-include-value): The current indentation
is used for expansion in `org-export--blindly-expand-include' (and
handled there).  It is not used during #+include keyword parsing.
2023-01-23 23:11:30 +08:00
TEC 2fecd96200
ox: Regain Emacs <28 compatibility with #+include
* lisp/ox.el (org-export-expand-include-keyword): Replace the (pred (not
FUN)) `pcase' form introduced in Emacs 28 with a simple `cond' statement.
2023-01-23 23:11:30 +08:00
Ihor Radchenko 77a1cfb9a4
org-html-src-block: Treat code blocks without LANG equally
* lisp/ox-html.el (org-html-src-block): Do not treat src blocks
without LANG as example blocks.  Instead, export them using "nil"
language.  This way, such src blocks will get captions, unlike example
blocks.

The new behavior is consistent with ox-latex and ox-ascii.

Reported-by: Johan Bolmsjö <org-mode@johan.bitmaster.se>
Link: https://orgmode.org/list/87zgb90win.fsf@localhost
2023-01-23 16:29:13 +03:00
Ihor Radchenko d98ca046cc
org-manual.org: Clarify that LANGUAGE may be omitted in code blocks
* doc/org-manual.org (Structure of Code Blocks):
(Editing Source Code): Clarify that <language> is optional.  Link to
possible consequences of <language> being omitted.
2023-01-23 16:29:13 +03:00
Ihor Radchenko 59fa35a0b7
Merge branch 'bugfix' 2023-01-23 15:48:58 +03:00
Ihor Radchenko 4166f55da1
Merge branch 'bugfix' 2023-01-23 13:28:46 +03:00
Kyle Meyer e84077ded3 Merge branch 'bugfix' 2023-01-22 21:46:52 -05:00
TEC a9ee43a124
ox: Fix parsing of example #+includes
* lisp/ox.el (org-export-parse-include-value): Since the example
environment regexp does not contain a capture group, we can not assume
we can call `replace-match' on the first capture group.  Before doing
so, check that the capture group indeed exists.
2023-01-22 20:14:23 +03:00
Ihor Radchenko ce4f7db3c1
test-ob-shell: Fix test failures on Emacs 26
* testing/lisp/test-ob-shell.el (test-ob-shell/remote-with-stdin-or-cmdline):
Work around non-local exit when running tests on Emacs 26.  Do no call
`kill-matching-buffers' unless Emacs in newer.
2023-01-22 19:21:25 +03:00
TEC f0dfbf0c39
ox-latex: Erase compile buffer at the start
* lisp/ox-latex.el (org-latex-compile): Before running the compile
command, erase the log buffer to ensure that stale/old logging is
cleared.
2023-01-22 18:18:43 +03:00
TEC b84018633e
ox-latex: Split org-latex-compile into two funs
* lisp/ox-latex.el (org-latex-compile): Split off the postprocessing in
`org-latex-compile' into a new function,
`org-latex-compile--postprocess'.
2023-01-22 18:18:43 +03:00
TEC 18d2f871c2
org: Split org-format-latex into two functions
* lisp/org.el (org-place-formula-image, org-format-latex): Extract the
overlay placement component of `org-format-latex' into a new function
`org-place-formula-image`.
2023-01-22 18:18:42 +03:00
TEC d0c87c762a
ox-latex: Do not hardcode fallback compiler
* lisp/ox-latex.el (org-latex-compile): Instead of hardcoding "pdflatex"
as the fallback compiler, use `org-latex-compiler'.
2023-01-22 18:18:41 +03:00
TEC b29f772416
org-macs: Split org-compile-file into two funs
* lisp/org-macs.el (org-compile-file, org-compile-file-commands):
Pull out the logic transforming process descriptions to commands to be
executed into a new function, `org-compile-file-commands'.
`org-compile-file' is now solely concerned with running the commands and
reporting the result.
2023-01-22 18:18:40 +03:00
TEC c8f88589cb
org-persist: Set utf-8 coding when reading/writing
* lisp/org-persist.el (org-persist--write-elisp-file,
org-persist--read-elisp-file): Instead of letting `find-auto-coding' be
invoked to determine the coding for org-persist cache files (which can
be surprisingly expensive), we simply set utf-8 coding when
reading/writing.
2023-01-22 18:18:40 +03:00
TEC e9c0696f79
org-persist: Inhibit fsync when writing cachefiles
* lisp/org-persist.el (org-persist--write-elisp-file): For the reasons
mentioned in the large code comment, it simply does not make much sense
to use fsync when writing cache files.

The value of fsync in general on modern hardware seems questionable,
particularly with CoW filesystems which take care of the problem better
than it seems fsync ever could.
2023-01-22 18:18:39 +03:00
TEC 506989bed5
ox: Improve #+include parsing docstring
* lisp/ox.el (org-export-parse-include-value): Actually describe the
parsing behaviour of the function in the docstring.
2023-01-22 18:18:38 +03:00
TEC ffd832d5d6
org-manual: Update #+include block parsing
* doc/org-manual.org (Include Files): Mention that block names starting
with ":" will need to be quoted, and reformat the paragraph for clarity
while editing the mention of block name.
2023-01-22 18:18:37 +03:00
TEC 7e649050c7
ox: Pass through unparsed #+include content
* lisp/ox.el (org-export-parse-include-value): Adjust the block matches
not to match keywords (i.e. ":\S-+"), and both block and env to consume
their matches in value.  Now value only contains the unmatched content,
which is given in as the results plist as :unmatched.
2023-01-22 18:18:37 +03:00
TEC 5cde90e3c8
ox: Refactor org-export-expand-include-keyword
* lisp/ox.el (org-export-expand-include-keyword): Split the parsing and
inclusion logic of the ~150 line `org-export-expand-include-keyword'
into two new functions: `org-export-parse-include-value' and
`org-export--blindly-expand-include'.
2023-01-22 18:18:36 +03:00
TEC 0af74d33a7
org-manual: Fix typos in print_bibliography kwd
* doc/org-manual.org (Bibliography options in the "biblatex" and "csl"
export processors): In some example Org content, the "+" in the keyword
prefix "#+" was missing.
2023-01-22 18:18:30 +03:00
Ihor Radchenko 4b546e04af
org-element--cache-submit-request: Ensure correct cache synchronization
* lisp/org-element.el (org-element--cache-sync): Add new optional
argument FORCE to force cache synchronization even when
`org-element--cache-active-p' returns non-nil.  Update commentary
explaining why `org-element--cache-active-p' needs to be checked.
(org-element--cache-submit-request): Force cache synchronization.  We
are safe to force it as all the callers of
`org-element--cache-submit-request' do check that cache is active.

This fixes an edge case when Org buffer has transient indirect buffers
with `after-change-functions' not being setup.  If a change happens in
the main Org buffer, `org-element--cache-after-change' gets called and
cache request is processed even though (org-element--cache-active-p),
but not (org-element--cache-active-p t), returns nil (due to the
indirect buffer).

Before this commit, `org-element--cache-submit-request' called by
`org-element--cache-after-change' missed cache synchronization, as
`org-element--cache-sync' did nothing.  As a result, if the indirect
buffer would get deleted, we would end up with incorrect cache state.

Reported-by: Gregor Zattler <telegraph@gmx.net>
2023-01-22 15:13:50 +03:00
Ihor Radchenko ddca762329
org-element--cache-verify-element: Format all the elements in warning
* lisp/org-element.el (org-element--cache-verify-element): Use
`org-element--format-element' to print all the elements.
2023-01-22 15:13:49 +03:00
Ihor Radchenko b34bdc8719
org-capture-finalize: Do not save new file with :no-save aborted capture
* lisp/org-capture.el (org-capture-finalize): Do not save the newly
created file buffer when the capture is aborted and org-capture is not
asked to save upon capture.
* testing/lisp/test-org-capture.el (test-org-capture/abort): Add test.
2023-01-22 13:49:07 +03:00
Ilya Chernyshov 005c9ae747
lisp/org-datetree.el: Allow datetrees with TODO, priority, tags
* org-datetree.el (org-datetree--find-create): Add optional argument
MATCH-TITLE that controls whether to match REGEX-TEMPLATE against
heading title inside complex heading or to match REGEX-TEMPLATE
against the whole heading line.

* org-datetree.el (org-datetree--find-create-group,
org-datetree-find-iso-week-create): Allow finding a datetree with TODO
state, priority, tags, statistics cookies, or COMMENT keyword.

* testing/lisp/test-org-datetree.el
(test-org-datetree/find-date-create,
test-org-datetree/find-iso-week-create): Add tests for a datetree with
tags, TODO or priority keywords.

* etc/ORG-NEWS (Datetree structure headlines can now be complex):
Document the change.

* doc/org-manual.org: Update datetree definition.
2023-01-21 12:29:32 +03:00
Ihor Radchenko f2320a2cc1
Revert "org-agenda.el: Fix `org-agenda-get-blocks'"
This reverts commit cb19f5c94e.

The original commit broke timestamp ranges with same starting and
ending hours.

Link: https://orgmode.org/list/87edrpa15m.fsf@gnu.org
2023-01-21 11:27:39 +03:00
Gautier Ponsinet 84ead47d3c
Define the face `org-agenda-calendar-daterange'
* etc/ORG-NEWS: Announce the introduction of the new face
  `org-agenda-calendar-daterange'.
* lisp/org-faces.el: Define the face `org-agenda-calendar-daterange'.
* lisp/org-agenda.el (org-agenda-get-blocks): Apply the face
  `org-agenda-calendar-daterange' to entries with a date range.
2023-01-21 11:27:38 +03:00
Gautier Ponsinet 22dea8557f
org-agenda: Apply the face `org-agenda-calendar-event'
* list/org-agenda.el (org-agenda-get-blocks): Apply the face
  `org-agenda-calendar-event' to entries with a time range within a
  single day.
2023-01-21 11:27:38 +03:00
Marco Wahl 9d58e1c781 org: Make documentation of org-reverse-note-order true
* lisp/org.el (org-notes-order-reversed-p): Return value is
org-reverse-note-order if it is neither nil or a list.

E.g. before nil has been returned when org-reverse-note-order was a
symbol.  And this did not meet the documentation of
org-reverse-note-order.
2023-01-20 13:56:00 +01:00
Ihor Radchenko c92769a505
org-paste-subtree: Do not leave empty line in place of level indicator
* lisp/org.el (org-paste-subtree): Remove the whole line when level
indicator is provided.  Improve check for level indicator.
* testing/lisp/test-org.el (test-org/paste-subtree): Add test.

Reported-by: Philipp Kiefer <phil.kiefer@gmail.com>
Link: https://orgmode.org/list/a2cc49d3-7f65-5f6a-8f05-21e5056335b3@gmail.com
2023-01-20 13:05:08 +03:00
Ihor Radchenko cf1ccc7154
Merge branch 'bugfix' 2023-01-20 12:10:40 +03:00
Ihor Radchenko e553e19ca9
Merge branch 'bugfix' 2023-01-20 11:46:55 +03:00
Ihor Radchenko 52f29d4da3
Merge branch 'bugfix' 2023-01-18 12:19:34 +03:00
Ihor Radchenko f8a601f800
Merge branch 'bugfix' 2023-01-18 11:53:21 +03:00
Ihor Radchenko 0e5de0ff64
org-export-expand-include-keyword: Fix relative links in recursive includes
* lisp/ox.el (org-export-expand-include-keyword): Add new optional
argument INCLUDER-FILE to explicitly pass the includer file path when
expanding inside a temporary buffer.  Pass the INCLUDER-FILE later
during recursive expansion.

Reported-by: Gabriel Petrini da Silveira <gpetrinidasilveira@gmail.com>
Link: https://orgmode.org/list/CAHCA-UvaqnegPYfpPcJCqiY8+dDoj0pfX0vDckUui-MCj3wq5A@mail.gmail.com
2023-01-18 11:41:03 +03:00
Ihor Radchenko 104311c7f8
org-cite-basic--get-field: Throw an error on non-nil field values
* lisp/oc-basic.el (org-cite-basic--get-field): Throw an error when
the field value is not a string.  Document the new behavior.

Link: https://orgmode.org/list/87edsnsocj.fsf@localhost
2023-01-17 15:25:00 +03:00
Ihor Radchenko 15bbb930d5
Merge branch 'bugfix' 2023-01-17 15:05:36 +03:00
Ihor Radchenko 30dfafac34
Merge branch 'bugfix' 2023-01-16 13:41:26 +03:00
Ihor Radchenko 889b8cc2fd
Merge branch 'bugfix' 2023-01-16 12:30:03 +03:00
Ihor Radchenko 25dd206a0e
Merge branch 'bugfix' 2023-01-14 16:30:26 +03:00
Ihor Radchenko d71bb04f78
Merge branch 'bugfix' 2023-01-13 12:08:49 +03:00
Ihor Radchenko 76f9a3c2cb
org-timestamp-change: Add FIXME
* lisp/org.el (org-timestamp-change): Add FIXME comment to
re-implement the logic in future to avoid `save-excursion' markers
being moved to the end of timestamp.
2023-01-13 12:06:16 +03:00
Ihor Radchenko dc29c7d81f
Merge branch 'bugfix' 2023-01-13 11:18:36 +03:00
Stefan Monnier ecb62e2e31
org-babel-shell-initialize: Refactor
* lisp/ob-shell.el (org-babel-shell-initialize): Refactor avoiding
`eval' runtime calls and assigning 'definition-name function symbol
property to assist Emacs help system with finding the definition.

Link: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=60568#71

> One of the discussed features was displaying function source code right
> in *Help* buffers. This feature usefulness have been objected at that
> time, on the grounds that showing function code may be too long and
> cause large *Help* buffers.

FWIW, I find myself regularly jumping to `M-x ielm` to look at the
`symbol-function`, so I would actually appreciate a button in the *Help*
buffer to display the actual value in the `symbol-function` slot.
This would also bring `describe-function` a bit closer to
`describe-variable`, which I think is good.

> 1. emacs -Q
> 2. M-: (require 'ob-shell)
> 3. <F1> f org-babel-execute:sh <RET>
> 4. Click on the source code link in *Help* buffer
> 5. Observe point jumping to (point-min) with no obvious way to find the
>    function definition.

We have `definition-name` for that.
I.e. `org-babel-shell-initialize` should arguably do

    (put 'org-babel-execute:sh 'definition-name 'org-babel-shell-initialize)

so that step 4 above jumps to `org-babel-shell-initialize`.

The patch below does that, along with saving some kittens.

        Stefan
2023-01-12 13:35:09 +03:00
Ihor Radchenko 0d5951a9b0
org-refile: Fix edge case when we refile on top of the same subtree
* lisp/org-refile.el (org-refile): Use dedicated marker (move after
insertion) to store position of the heading being refiled.  Otherwise,
if refiled heading is inserted at the same point, `save-excursion'
would restore point before the inserted heading instead of keeping it
at the original heading.
* testing/lisp/test-org.el (test-org/refile): At test.

Reported-by: /u/madclassix
2023-01-12 13:19:02 +03:00
Ihor Radchenko d0758eabfe
Merge branch 'bugfix' 2023-01-12 12:23:41 +03:00
Matt Trzcinski bcca8819c3 test-ob-shell.el: Organize tests
* testing/lisp/test-ob-shell.el:
  - Give instructions on how to run tests
  - Require `org-test' explicitly
  - Group tests into sections
  - Insert `page-delimiter's between sections
2023-01-11 14:31:16 -05:00
Matt Trzcinski ccd5977f62 ob-shell-test.org: Remove ob-shell-test.org
* testing/examples/ob-shell-test.org: Delete file

File was used by test-ob-shell.el to test ob-shell.el.  Tests have
been updated to use temporary buffers, rendering ob-shell-test.org
unnecessary.
2023-01-11 14:31:10 -05:00
Matt Trzcinski d7ff5b2462 test-ob-shell.el: Refactor test names and kill test buffers
* testing/lisp/test-ob-shell.el:
(ob-shell/generic-uses-no-arrays): Rename test from
`ob-shell/generic-uses-no-arrays' to
`test-ob-shell/generic-uses-no-arrays'.
(ob-shell/generic-uses-no-arrays): Move comments from
testing/examples/ob-shell-test.org to docstring.
(ob-shell/generic-uses-no-arrays): Remove dependency on
testing/examples/ob-shell-test.org.
(ob-shell/bash-uses-arrays): Rename `ob-shell/bash-uses-arrays' to
`test-ob-shell/bash-uses-arrays'.
(ob-shell/bash-uses-arrays): Move comments from
testing/examples/ob-shell-test.org to docstring.
(ob-shell/bash-uses-arrays): Remove dependency on
testing/examples/ob-shell-test.org.
(ob-shell/simple-list): Change test name from `ob-shell/simple-list'
to `test-ob-shell/simple-list'.
(ob-shell/remote-with-stdin-or-cmdline): Change test name from
`ob-shell/remote-with-stdin-or-cmdline' to
`test-ob-shell/remote-with-stdin-or-cmdline'.
(ob-shell/remote-with-stdin-or-cmdline): On pass, kill buffer created
by test.
(ob-shell/results-table): Rename `ob-shell/results-table' to
`test-ob-shell/results-table'.
(ob-shell/results-list): Rename `ob-shell/results-list' to
`test-ob-shell/results-list'.
 (ob-shell/standard-output-after-success): Rename
`ob-shell/standard-output-after-success' to
`test-ob-shell/standard-output-after-success'.
(ob-shell/standard-output-after-failure): Rename
`ob-shell/standard-output-after-failure' to
`test-ob-shell/standard-output-after-failure'.
(ob-shell/standard-output-after-failure): On pass, kill buffer created
during test.
(ob-shell/error-output-after-success): Rename
`ob-shell/error-output-after-success' to
`test-ob-shell/error-output-after-success'.
(ob-shell/error-output-after-success): On pass, kill buffer created by
test.
(ob-shell/error-output-after-failure): Rename
`ob-shell/error-output-after-failure' to
`test-ob-shell/error-output-after-failure'.
(ob-shell/error-output-after-failure): On pass, kill buffer created by
test.
(ob-shell/error-output-after-failure-multiple): Rename
`ob-shell/error-output-after-failure-multiple' to
`test-ob-shell/error-output-after-failure-multiple'.
(ob-shell/error-output-after-failure-multiple): On pass, kill buffer
created by test.
(ob-shell/exit-code): Rename `ob-shell/exit-code' to
`test-ob-shell/exit-code'.
(ob-shell/exit-code): On pass, kill buffer created by test.
(ob-shell/exit-code-multiple): Rename `ob-shell/exit-code-multiple' to
`test-ob-shell/exit-code-multiple'.
(ob-shell/exit-code-multiple): On pass, kill buffer created by test.
2023-01-11 14:31:01 -05:00
Matt Trzcinski 16ea9f84f6 Refactor ob-shell/bash-uses-assoc-arrays
* testing/lisp/test-ob-shell.el (ob-shell/bash-uses-assoc-arrays):
Split test cases into separate tests,
`test-ob-shell/bash-uses-assoc-arrays' and
`test-ob-shell/bash-uses-assoc-arrays-with-lists'.  Rename prefix from
"ob-shell" to "test-ob-shell".
(ob-shell/bash-uses-assoc-arrays): Move comments from
testing/examples/ob-shell-test.org to docstrings.
(ob-shell/bash-uses-assoc-arrays): Remove dependency on
testing/examples/ob-shell-test.org.
2023-01-11 14:30:53 -05:00
Matt Trzcinski c61112c850 test-ob-shell.el: Refactor ob-shell/generic-uses-no-assoc-arrays
* test-ob-shell.el (ob-shell/generic-uses-no-assoc-arrays): Split test
based on simple versus complex mapping cases,
`test-ob-shell/generic-uses-no-assoc-arrays-simple-map' and
`test-ob-shell/generic-uses-no-assoc-arrays-3-columns'.  Rename prefix
from "ob-shell" to "test-ob-shell".
(ob-shell/generic-uses-no-assoc-arrays): Move
headlines and commentary from `testing/examples/ob-shell-test.org' to
docstring.
(ob-shell/generic-uses-no-assoc-arrays): Remove dependency on
testing/examples/ob-shell-test.org.
2023-01-11 14:30:45 -05:00
Matt Trzcinski 2ddbee5e63 test-ob-shell.el: Refactor test-ob-shell/session
* testing/lisp/test-ob-shell.el (ob-shell/session): Split
`ob-shell/session' into
`test-ob-shell/session-single-return-returns-string' and
`test-ob-shell/session-multiple-returns-returns-list'.
(ob-shell/session): Rename comint from to test name. On
pass, kill process and remove process buffer.
2023-01-11 14:30:35 -05:00
Matt Trzcinski 875845de1b test-ob-shell.el: Split test-ob-shell/dont-error-on-empty-results
* testing/lisp/test-ob-shell.el
(test-ob-shell/dont-error-on-empty-results): Explicitly test handling
of empty results.
(test-ob-shell/dont-error-on-babel-error): Explicitly test handling of
Babel errors.  On pass, remove buffers created during test.

Original test conflated empty results (a valid Babel return) and Babel
errors.
2023-01-11 14:30:23 -05:00
Matthew Trzcinski 597ecaa5c1 Revert "Merge branch 'ob-shell-cleanup-tests'"
This reverts commit 4f319088ba, reversing
changes made to 07c63df9c7.
2023-01-11 14:27:45 -05:00
Matthew Trzcinski 4f319088ba Merge branch 'ob-shell-cleanup-tests' 2023-01-11 11:16:53 -05:00
Bastien 07c63df9c7 Merge branch 'bugfix' 2023-01-11 16:01:03 +01:00
Ihor Radchenko dfcf500df5
org-cdlatex-mode: Fix regression from f01390cf05
* lisp/org.el (org--math-always-on): Rename to `org--math-p' and only
override `texmathp' when current command is `cdlatex-math-symbol' or
when we are inside Org LaTeX math fragment.  Only these two scenarios
are the places where `texmathp' may not work properly in Org files.
We must not return t outside latex fragments as initially suggested by
the docstring because it would break, for example, `cdlatex-dollar'
command.
(org-cdlatex-mode): Use the new function name for advice.
* lisp/org-compat.el (org--math-always-on): Declare obsolete.

Reported-by: Daniel Fleischer <danflscr@gmail.com>
Link: https://orgmode.org/list/m2cz7sj5zt.fsf@gmail.com
2023-01-11 13:55:56 +03:00
Ihor Radchenko 2f7052619b
Merge branch 'bugfix' 2023-01-07 15:15:18 +03:00
Ihor Radchenko b58fbaf834
Merge branch 'bugfix' 2023-01-06 18:06:26 +03:00
Ihor Radchenko a08c37603f
Merge branch 'bugfix' 2023-01-06 16:31:43 +03:00
Ihor Radchenko a3815a169a
org-cycle-level: Do nothing at inlinetasks
* lisp/org.el (org-cycle-level): Do not change task level at
inlinetasks.

Reported-by: Alain.Cochard@unistra.fr
Link: https://orgmode.org/list/25524.11082.597138.21839@gargle.gargle.HOWL
2023-01-05 12:08:01 +03:00
Ihor Radchenko 80d1bc63ff
Merge branch 'bugfix' 2023-01-05 11:29:12 +03:00
Bastien 001e114936 Revert "lisp/ob-scheme.el: Add Rudolf Adamkovič as the maintainer"
This reverts commit e5a3a07cac.

See https://list.orgmode.org/orgmode/m2pmbvqjtf.fsf@me.com/
2023-01-04 00:36:38 +01:00
Ihor Radchenko 30314c6038
Merge branch 'bugfix' 2023-01-03 10:58:59 +03:00
Ihor Radchenko 9e5c25ba75
org-persist-unregister: Allow removing related containers
* lisp/org-persist.el (org-persist-unregister): Add new optional key
:remove-related to remove all the containers stored alongside with
CONTAINER in addition to CONTAINER itself.  Update to docstring.
2023-01-03 10:56:49 +03:00
Ihor Radchenko 82cc6f0fe8
Merge branch 'bugfix' 2023-01-02 12:08:23 +03:00
Ihor Radchenko e002168d64
Merge branch 'bugfix' 2023-01-02 10:53:14 +03:00
Ihor Radchenko 4b647e70e6
Merge branch 'bugfix' 2023-01-02 10:27:44 +03:00
Kyle Meyer 96a402780c Merge branch 'bugfix' 2023-01-01 13:15:12 -05:00
Ihor Radchenko d5b8180e72
Merge branch 'bugfix' 2023-01-01 15:58:56 +03:00
Matt Trzcinski 9ed2821053 test-ob-shell.el: Organize tests
* testing/lisp/test-ob-shell.el:
  - Give instructions on how to run tests
  - Require `org-test' explicitly
  - Group tests into sections
  - Insert `page-delimiter's between sections
2022-12-31 13:56:27 -05:00
Matt Trzcinski 9485450222 ob-shell-test.org: Remove ob-shell-test.org
* testing/examples/ob-shell-test.org: Delete file

File was used by test-ob-shell.el to test ob-shell.el.  Tests have
been updated to use temporary buffers, rendering ob-shell-test.org
unnecessary.
2022-12-31 13:56:27 -05:00
Matt Trzcinski 3dbc7849a3 test-ob-shell.el: Refactor test names and kill test buffers
* testing/lisp/test-ob-shell.el:
(ob-shell/generic-uses-no-arrays): Rename test from
`ob-shell/generic-uses-no-arrays' to
`test-ob-shell/generic-uses-no-arrays'.
(ob-shell/generic-uses-no-arrays): Move comments from
testing/examples/ob-shell-test.org to docstring.
(ob-shell/generic-uses-no-arrays): Remove dependency on
testing/examples/ob-shell-test.org.
(ob-shell/bash-uses-arrays): Rename `ob-shell/bash-uses-arrays' to
`test-ob-shell/bash-uses-arrays'.
(ob-shell/bash-uses-arrays): Move comments from
testing/examples/ob-shell-test.org to docstring.
(ob-shell/bash-uses-arrays): Remove dependency on
testing/examples/ob-shell-test.org.
(ob-shell/simple-list): Change test name from `ob-shell/simple-list'
to `test-ob-shell/simple-list'.
(ob-shell/remote-with-stdin-or-cmdline): Change test name from
`ob-shell/remote-with-stdin-or-cmdline' to
`test-ob-shell/remote-with-stdin-or-cmdline'.
(ob-shell/remote-with-stdin-or-cmdline): On pass, kill buffer created
by test.
(ob-shell/results-table): Rename `ob-shell/results-table' to
`test-ob-shell/results-table'.
(ob-shell/results-list): Rename `ob-shell/results-list' to
`test-ob-shell/results-list'.
 (ob-shell/standard-output-after-success): Rename
`ob-shell/standard-output-after-success' to
`test-ob-shell/standard-output-after-success'.
(ob-shell/standard-output-after-failure): Rename
`ob-shell/standard-output-after-failure' to
`test-ob-shell/standard-output-after-failure'.
(ob-shell/standard-output-after-failure): On pass, kill buffer created
during test.
(ob-shell/error-output-after-success): Rename
`ob-shell/error-output-after-success' to
`test-ob-shell/error-output-after-success'.
(ob-shell/error-output-after-success): On pass, kill buffer created by
test.
(ob-shell/error-output-after-failure): Rename
`ob-shell/error-output-after-failure' to
`test-ob-shell/error-output-after-failure'.
(ob-shell/error-output-after-failure): On pass, kill buffer created by
test.
(ob-shell/error-output-after-failure-multiple): Rename
`ob-shell/error-output-after-failure-multiple' to
`test-ob-shell/error-output-after-failure-multiple'.
(ob-shell/error-output-after-failure-multiple): On pass, kill buffer
created by test.
(ob-shell/exit-code): Rename `ob-shell/exit-code' to
`test-ob-shell/exit-code'.
(ob-shell/exit-code): On pass, kill buffer created by test.
(ob-shell/exit-code-multiple): Rename `ob-shell/exit-code-multiple' to
`test-ob-shell/exit-code-multiple'.
(ob-shell/exit-code-multiple): On pass, kill buffer created by test.
2022-12-31 13:56:22 -05:00
Matt Trzcinski 2a0f5a5153 Refactor ob-shell/bash-uses-assoc-arrays
* testing/lisp/test-ob-shell.el (ob-shell/bash-uses-assoc-arrays):
Split test cases into separate tests,
`test-ob-shell/bash-uses-assoc-arrays' and
`test-ob-shell/bash-uses-assoc-arrays-with-lists'.  Rename prefix from
"ob-shell" to "test-ob-shell".
(ob-shell/bash-uses-assoc-arrays): Move comments from
testing/examples/ob-shell-test.org to docstrings.
(ob-shell/bash-uses-assoc-arrays): Remove dependency on
testing/examples/ob-shell-test.org.
2022-12-31 12:56:51 -05:00
Matt Trzcinski 728e7fca81 test-ob-shell.el: Refactor ob-shell/generic-uses-no-assoc-arrays
* test-ob-shell.el (ob-shell/generic-uses-no-assoc-arrays): Split test
based on simple versus complex mapping cases,
`test-ob-shell/generic-uses-no-assoc-arrays-simple-map' and
`test-ob-shell/generic-uses-no-assoc-arrays-3-columns'.  Rename prefix
from "ob-shell" to "test-ob-shell".
(ob-shell/generic-uses-no-assoc-arrays): Move
headlines and commentary from `testing/examples/ob-shell-test.org' to
docstring.
(ob-shell/generic-uses-no-assoc-arrays): Remove dependency on
testing/examples/ob-shell-test.org.
2022-12-31 12:52:43 -05:00
Ihor Radchenko 24740a9e84
Merge branch 'bugfix' 2022-12-31 16:13:46 +03:00
Ihor Radchenko 5804176149
Merge branch 'bugfix'
* lisp/org-persist.el (org-persist--storage-version): Bump further to
distinguish cache layouts on bugfix vs. main.
2022-12-31 12:40:19 +03:00
Matt Trzcinski 6e0012867d test-ob-shell.el: Refactor test-ob-shell/session
* testing/lisp/test-ob-shell.el (ob-shell/session): Split
`ob-shell/session' into
`test-ob-shell/session-single-return-returns-string' and
`test-ob-shell/session-multiple-returns-returns-list'.
(ob-shell/session): Rename comint from to test name. On
pass, kill process and remove process buffer.
2022-12-30 11:35:10 -05:00
Matt Trzcinski e204c3a6cc test-ob-shell.el: Split test-ob-shell/dont-error-on-empty-results
* testing/lisp/test-ob-shell.el
(test-ob-shell/dont-error-on-empty-results): Explicitly test handling
of empty results.
(test-ob-shell/dont-error-on-babel-error): Explicitly test handling of
Babel errors.  On pass, remove buffers created during test.

Original test conflated empty results (a valid Babel return) and Babel
errors.
2022-12-30 11:18:15 -05:00
Bastien dff9565c2c Merge branch 'bugfix' 2022-12-30 09:17:38 +01:00
Bastien 89bf4b431a etc/ORG-NEWS: Minor rewording
Prefer "option" rather than "setting".
An option is a customizable variable.
2022-12-30 09:15:42 +01:00
Bastien e8ceb4a2cb lisp/ob-shell.el: Add Matt <matt@excalamus.com> as maintainer 2022-12-30 09:02:53 +01:00
András Simonyi 29103fc602 oc-csl: Improve LaTeX bibliography formatting
* lisp/oc-csl.el (org-cite-csl--output-format): Use the dedicated
'org-latex' citeproc formatter to export references in LaTeX.
(org-cite-csl-latex-preamble, org-cite-csl--generate-latex-preamble,
org-cite-csl-finalizer): Insert a preamble fragment compatible with
the 'org-latex' citeproc formatter.
(org-cite-csl-latex-label-separator,
org-cite-csl-latex-label-width-per-char): Introduce additional
variables to control bibliography formatting.

* etc/ORG-NEWS: Describe the introduced new options.
2022-12-29 22:36:36 +01:00
Bastien e5a3a07cac lisp/ob-scheme.el: Add Rudolf Adamkovič as the maintainer 2022-12-29 16:33:03 +01:00
Ihor Radchenko 5bc5add326
lisp/org-keys.el: Provide terminal binding for `org-insert-structure-template'
* lisp/org-keys.el (or): Add alternative terminal binding for
`org-insert-structure-template'.  The default binding may not be
available in some terminals.

* doc/org-manual.org (Using Org on a TTY): List the new binding in the
manual.

Reported-by: Anthony Carrico <acarrico@memebeam.org>
Link: https://orgmode.org/list/d9222967-5747-bf54-8041-4a8453fe81fc@memebeam.org
2022-12-29 17:27:37 +03:00
Ihor Radchenko fbd08a0d9b
oc-basic: Display ?? in place of missing citations on export
* lisp/oc-basic.el (org-cite-basic--format-author-year):
(org-cite-basic-export-citation): Display "????" for missing year and
"??"  for missing other fields.

Reported-by: Ihor Radchenko <yantar92@posteo.net>
Link: https://orgmode.org/list/871qr6kiuv.fsf@localhost
2022-12-29 17:24:21 +03:00
Ihor Radchenko b2adb68afa
* doc/org-manual.org: Clarify :results file link with no :file
(Type):
(Format): Document that :results file link is using the source block
result as file path when :file header argument is not present.

Reported-by: dalanicolai <dalanicolai@gmail.com>
Link: https://orgmode.org/list/CACJP=3=HrzaB+b2bTk2=-hrcv0STx41eFjedgtp=qXvGjVJQWA@mail.gmail.com
2022-12-29 16:59:45 +03:00
Ihor Radchenko 21741a4696
* lisp/ob-python.el: Mark python-mode support for removal
Add FIXME record to remove python-mode.el support in the next release.
See the annoucement in https://orgmode.org/Changes.html (Org 9.6)

Link: https://orgmode.org/list/87r0xq8dk9.fsf@gnu.org
2022-12-29 16:37:00 +03:00
Ihor Radchenko a9c0d4cde2
org-occur-in-agenda-files: Respect agenda restriction
* lisp/org.el (org-occur-in-agenda-files): Respect agenda restriction
when searching.

Reported-by: Alain.Cochard@unistra.fr
Link: https://orgmode.org/list/25514.61148.396137.347019@gargle.gargle.HOWL
2022-12-29 12:55:13 +03:00
Ihor Radchenko b86989c8df
Merge branch 'bugfix' 2022-12-29 12:53:32 +03:00
Ihor Radchenko dedf1cc21f
org-persist: Add more normalizations and new `elisp-data' container
* lisp/org-persist.el (org-persist--normalize-container): Recognize
new `elisp-data' container.  Treat raw strings, keywords, and quoted
expressions as `elisp-data' container options.
(org-persist-read:elisp-data):
(org-persist-load:elisp-data):
(org-persist-write:elisp-data):
(org-persist-gc:elisp-data):
(org-persist-associated-files:elisp-data): New functions.
(org-persist-read): Simplify docstring example using `elisp-data'
container.

Also, update examples in top comment.
2022-12-29 12:27:50 +03:00
Ihor Radchenko 13e78df46a
* lisp/org-persist.el: Update commentary
Add more examples and document recent additions.
2022-12-28 15:57:24 +03:00
Ihor Radchenko 14bfe2841c
org-persist: Use `list-data-mode' for stored data
* lisp/org-persist.el (org-persist-version): Bump version.
(org-persist-index-file): Use .eld extension by default.
(org-persist--index): Set mode in buffer-local variable line.
2022-12-28 15:56:07 +03:00
Ihor Radchenko a97b378ee5
org-persist-read: Do not return related containers by default
* lisp/org-persist.el (org-persist-read): Only return the requested
containers.  Add new optional keyword argument :read-related to read
the containers stored together with requested.  Update the docstring
accordingly.
(org-persist-load): Update definition according to `org-persist-read'.
* lisp/org.el (org-mode): Explicitly load all the associated
cache variables.
2022-12-28 15:53:14 +03:00
Ihor Radchenko ffec2db731
org-persist-write:elisp: Allow buffer-local/global elisp container scope
* lisp/org-persist.el (org-persist-read:index): Allow setting where
the elisp container value is taken from: locally, from buffer, or from
a global variable.
2022-12-28 15:51:49 +03:00
Ihor Radchenko f8428d0f3e
org-fold-core--isearch-show: Small refactoring
* lisp/org-fold-core.el (org-fold-core--isearch-show): Do not move
point unnecessarily.
2022-12-28 15:50:35 +03:00
Ihor Radchenko e8cb52bd3e
org-persist-read: Attempt to write newly register data before reading
* lisp/org-persist.el (org-persist-read): If data is not yet written,
try to write it before reading.
2022-12-28 09:21:13 +03:00
Ihor Radchenko 5549357bf2
Merge branch 'bugfix' 2022-12-27 13:14:04 +03:00
Ihor Radchenko af56f52ccb
Merge branch 'bugfix' 2022-12-27 12:50:24 +03:00
Ihor Radchenko fd162eb9be
Merge branch 'bugfix' 2022-12-26 20:09:22 +03:00
Kyle Meyer adb3591436 Merge branch 'bugfix' 2022-12-26 11:01:49 -05:00
Ihor Radchenko 5de86ffaba
Merge branch 'bugfix' 2022-12-26 12:25:28 +03:00
Ihor Radchenko d88c9893ee
Merge branch 'bugfix' 2022-12-26 12:22:31 +03:00
Ihor Radchenko 0f1184a850
Merge branch 'bugfix' 2022-12-25 15:50:55 +03:00
Ihor Radchenko 46dbd59f03
Merge branch 'bugfix' 2022-12-25 14:38:36 +03:00
Ihor Radchenko 3a5b2555df
Merge branch 'bugfix' 2022-12-25 14:00:14 +03:00
Ihor Radchenko d2b49c72b2
Merge branch 'bugfix' 2022-12-25 12:19:46 +03:00
Ihor Radchenko f731d45d28
Merge branch 'bugfix' 2022-12-21 21:44:07 +03:00
Ihor Radchenko 036cc05a6d
Merge branch 'bugfix' 2022-12-21 15:41:55 +03:00
Ihor Radchenko 71b04d9638
Merge branch 'bugfix' 2022-12-21 15:35:14 +03:00
Ihor Radchenko d9e258b55f
Merge branch 'bugfix' 2022-12-21 14:55:21 +03:00
Ihor Radchenko 04d2cc59e5
Merge branch 'bugfix' 2022-12-18 17:43:03 +03:00
Ihor Radchenko a58ab90395
lisp/ox-latex.el: Add export option for `org-latex-listings-src-omit-language'
* lisp/ox-latex.el (latex):
(org-latex-src-block--listings): Use a proper export option, not just
a `defcustom'.
2022-12-18 16:14:14 +03:00
Pedro A. Aranda Gutierrez 322b2fd226
lisp/ox-latex.el: Add `org-latex-listings-src-omit-language'
* lisp/ox-latex.el (org-latex-listings-src-omit-language): New
customization that controls whether language= should be included in
the parameters of the lstlisting environmet generated by a src block.

(org-latex-src-block--listings): Do not add language parameter when
`org-latex-listings-src-omit-language' is non-nil.

* etc/ORG-NEWS (New =org-latex-listings-src-omit-language= variable
for LaTeX export): Document the new defcustom.
2022-12-18 16:10:40 +03:00
Pedro A. Aranda Gutierrez 0c467b6b89
lisp/ox-latex.el: Don't emit empty label=, caption=
* lisp/ox-latex.el (org-latex-src-block--listings): Don't emit label=
when label is empty.  Don't emit caption= and captionpos= when caption
is empty.

This is safe to do as long as we do not set "lstlisting" parameters
globally.  See the discussion in
https://orgmode.org/list/87h6xyqqod.fsf@localhost.
2022-12-18 16:10:39 +03:00
Ihor Radchenko dd4e06ddc3
org-manual: Document third-party package compatibility
* doc/org-manual.org (Installation): Document that we only guarantee
compatibility with the latest stable versions of third-party packages.

Link: https://orgmode.org/list/86iljd3x90.fsf@gmail.com
2022-12-18 15:43:40 +03:00
Ihor Radchenko 18fec7623c
ob-core: Fix :results list when result is a table
* lisp/ob-core.el (org-babel-insert-result): Do not treat table lines
in RESULT verbatim.
* testing/lisp/test-ob-shell.el (ob-shell/results-list): Add new test.

Reported-by: Rudolf Adamkovič <salutis@me.com>
Link: https://orgmode.org/list/m2tu1v8gj8.fsf@me.com
2022-12-18 14:32:50 +03:00
Kyle Meyer d93df21835 Merge branch 'bugfix' 2022-12-17 17:05:23 -05:00
Ihor Radchenko 751de02127
org-agenda-dim-blocked-tasks: Prioritize face over other overlays
* lisp/org-agenda.el (org-agenda-dim-blocked-tasks): Use high overlays
priority when adding dimmed face.  Otherwise, contained overlays, like
created by `org-agenda-fontify-priorities', will take
priority (default Emacs behavior).

Reported-by: Mark Kerr <mkerr23@gmail.com>
Link: https://orgmode.org/list/CAM9qJ5+C3nvbNaJyq6ofRgPsuAMcaBD=2UN-n96Kb68NBbX3Dg@mail.gmail.com
2022-12-17 12:53:12 +03:00
Ihor Radchenko afe5f3f692
org-persist-gc: Fix edge case
* lisp/org-persist.el (org-persist-gc): Do not err when
`org-persist-directory' is absent.
2022-12-17 12:45:46 +03:00
Ihor Radchenko d52a775369
Merge branch 'bugfix'
Note the resolved conflict.
2022-12-17 12:45:14 +03:00
Leo Butler 01c0ebee2f
prevent error in Octave process, add tests, update test docs
* lisp/ob-octave.el (org-babel-execute:octave):

  -Ensure that the special Octave variable `ans' is bound when
  GFX-FILE is non-nil.  The glue code in
  ORG-BABEL-OCTAVE-WRAPPER-METHOD causes Octave to exit with a
  non-zero exit code when `ans' is not bound.

  -Change format control string to %S from %s.  Ensure the graphics
  filename is quoted.  If it is not, Octave may create a mis-named
  file or fail entirely.

* testing/examples/ob-octave-test.org:

  Update the Graphical tests section:
  -put in the correct headers;
  -add a remark about where to find each test.

* testing/lisp/test-ob-octave.el:

  Add the three tests ob-octave/graphics-file,
  ob-octave/graphics-file-session and ob-octave/graphics-file-space.

  -ob-octave/graphics-file: The first test verifies that the first bug
  identified above is fixed; it also verifies that graphics file
  creation works correctly for scripting.

  -ob-octave/graphics-file-session: The second test verifies graphics
  file creation works correctly for sessions.  The Octave command
  `crash_dumps_octave_core(0)' is included to prevent the creation of
  a core file (`octave-workspace').

  -ob-octave/graphics-file-space: The third test verifies that a
  graphics filename with a space in it is created correctly.

Thanks to Ihor Radchenko for helpful feedback.
Ref: https://list.orgmode.org/8735asbtfe.fsf@localhost/T/#u
2022-12-17 11:22:55 +03:00
TEC 555dacfa8b
org-persist: Merge index with index file content
* lisp/org-persist.el (org-persist-write, org-persist-load,
org-persist-write:index, org-persist-load:index): Check if the index
file has been externally updated since loading, and if so try to perform
basic merging of the current index file contents and the loaded index
before performing GC or overwriting the index file.
(org-persist--index-age, org-persist--merge-index-with-disk,
org-persist--merge-index): New variable and functions to keep track of
index age and perform merging.
2022-12-14 23:03:04 +08:00
Ihor Radchenko cea5af5cce
Merge branch 'bugfix'
Merge back cherry-picked important bugfix commits from main.
2022-12-14 12:43:26 +03:00
Ihor Radchenko 794d502da0
org-time-stamp-custom-formats: Document that variable affects export
* lisp/org.el (org-time-stamp-custom-formats): Mention that the value
affect export; not only the display.
2022-12-14 11:35:10 +03:00
Ihor Radchenko edd000f3b6
org-open-at-point: Link to `org-file-apps' in the docstring
* lisp/org.el: Mention how file links are opened.

Reported-by: David Masterson <dsmasterson@gmail.com>
Link: https://orgmode.org/list/SJ0PR03MB54555477E276E6A3CADBA4B8A2E39@SJ0PR03MB5455.namprd03.prod.outlook.com
2022-12-14 11:08:43 +03:00
Ihor Radchenko f49ee9200c
Merge branch 'bugfix' 2022-12-13 14:14:57 +03:00
Ihor Radchenko 71a5f75bbb
Merge branch 'bugfix' 2022-12-13 11:50:50 +03:00
Ihor Radchenko 45dc19516a
org-inlinetask-min-level: Fix confusing sentence in the docstring
* lisp/org-inlinetask.el (org-inlinetask-min-level): Update
confusingly written sentence.

Reported-by: Alain.Cochard@unistra.fr
Link: https://orgmode.org/list/25495.8102.609172.522785@gargle.gargle.HOWL
2022-12-13 10:31:58 +03:00
Ihor Radchenko 7f7fb256c6
org-latex-listings-options: Update docstring
* lisp/ox-latex.el (org-latex-listings-options): \lstset is no longer
used.  Clarify that options are now supplied directly to the
environment.
2022-12-12 15:33:52 +03:00
Rudolf Adamkovič d440b242b3
org-clock-clocktable-language-setup: Add Slovak translation
* lisp/org-clock.el (org-clock-clocktable-language-setup): Add
translation.
2022-12-12 15:33:51 +03:00
Kyle Meyer e42beabb48 Merge branch 'bugfix' 2022-12-11 13:58:06 -05:00
TEC 92ac00051a
org-persist: Fix omitted argument
* lisp/org-persist.el (org-persist-associated-files:file): Add the
"container" argument used but omitted from the function declaration of
`org-persist-associated-files:file' in 534633d508.
2022-12-12 01:13:23 +08:00
Ihor Radchenko a12d15df98
org-display-inline-remove-overlay: Do better job clearing images from cache
* lisp/org.el (org-display-inline-remove-overlay): Force remove
overlay images from Emacs image cache when un-displaying inline image
overlays.  This change should: (1) slightly improve Emacs memory usage
when the number of inline images is large; (2) Clear images from cache
every time Emacs removes the overlay for any
reason.  (`org-display-inline-remove-overlay' is used in
overlay 'modification-hooks.)
2022-12-11 12:18:22 +03:00
Kyle Meyer 8880cca3d6
ob-core: Revert space misalignment from recent commit
cc5427b7e (org-babel-result-to-file: Fix results file inside
attachment dir, 2022-12-07) carried along an unrelated white space
change upstream of the main change.
2022-12-11 12:18:21 +03:00
Kyle Meyer 4c90e0b613
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-11 12:18:21 +03:00
TEC 1a9d0850b6
org-persist: Do not re-download url files on write
* lisp/org-persist.el (org-persist-write:url): Since the url write
function is called as part of `org-persist-write-all', it is worth
adding a check to avoid re-downloading the file if a file already exists
in the expected location.
2022-12-11 15:47:33 +08:00
TEC 534633d508
org-persist: Use associated file functions for GC
* lisp/org-persist.el (org-persist-gc, org-persist--remove-from-index,
org-persist-gc:file, org-persist-gc:url, org-persist-gc:version,
org-persist-gc:url, org-persist-associated-files:generic,
org-persist-associated-files:url, org-persist-associated-files:elisp,
org-persist-associated-files:index,
org-persist-associated-files:version,
org-persist-associated-files:file): Use associated files for GC, and
move the associated files functions into the public
namespace (i.e. remove the double dash).
2022-12-11 15:47:33 +08:00
TEC 8b8a65ed02
org-persist: Introduce "associated files" for GC
* lisp/org-persist.el (org-persist-gc, org-persist--associated-files,
org-persist--associated-files:url): The url container stores downloaded
files separately within `org-persist-directory', which means that
`org-persist-gc' picks them up as "orphan files" and deletes them every
time it is called.  To avoid this collateral damage, a new family of
collection-specific functions is introduced,
"org-persist--associated-files:COLLECTION".  This allows collections to
tell GC about associated files that should be left alone, and is used
for url collections to preserve downloaded files.
2022-12-11 15:47:33 +08:00
TEC c91226354a
org-persist: Fix attempted mapc-ing of macro
* lisp/org-persist.el (org-persist--gc-persist-file): Redefine
`org-persist--gc-persist-file' as a function so it can be mapc'd in
`org-persist-gc'.
2022-12-11 15:47:33 +08:00
TEC 47654f844d
org-persist: Fix number of remote files kept
* lisp/org-persist.el (org-persist-gc): The `org-persist-remote-files'
documentation states that when set to a number (n) it will keep that
many files.  However, since a <= comparison is used with setting the
expired status of the files every remote file from n-th file onwards
/inclusive/ is marked as expired, and so only n-1 files were actually
kept.  With a less-than operator, the behaviour will actually match the
docstring.
2022-12-11 15:47:33 +08:00
TEC e663b90fe5
org-persist: Fix unconditional gc of urls
* lisp/org-persist.el (org-persist-gc): The :file association of URL
containers lead to `file-exists-p' being called on them, which always
returns nil, causing URL containers to always be garbage collected.
Since the :file entry doesn't really represent a filesystem object, we
now check if the container is url and if so prevent the :file
association from being used in gc checks.
2022-12-11 15:47:33 +08:00
TEC 3b1e7af166
org-persist: Ensure index instantiated before read
* lisp/org-persist.el (org-persist-read): If the index is empty at the
start of `org-persist-read', load it before continuing.
2022-12-11 15:47:33 +08:00
TEC 5b076f5057
org-persist: Add missing end quote to docstrings
* lisp/org-persist.el (org-persist--load-index,
org-persist--save-index): Add missing end quote to the docstrings.
2022-12-11 15:47:33 +08:00
TEC 8800d28e84
org: Use buffer-base-buffer in safe resource fns
* lisp/org.el (org--confirm-resource-safe, org--safe-remote-resource-p):
Replace instances of buffer-file-name
with (buffer-file-name (buffer-base-buffer)) so these functions work in
indirect buffers.
2022-12-11 15:47:33 +08:00
TEC a6fc8d3f1f
ox: Handle failure to localize link
* lisp/ox.el (org-export-link-localise): When no local copy of the link
resource could be fetched, produce a warning message and do nothing
instead of setting the link :path to nil.
2022-12-11 15:47:33 +08:00
Ihor Radchenko 42153ea2fe
Merge branch 'bugfix' 2022-12-10 16:55:38 +03:00
Jonathan Gregory a1607a3609
org-clock-clocktable-language-setup: Add Portuguese translation
* lisp/org-clock.el (org-clock-clocktable-language-setup): Do it.

TINYCHANGE
2022-12-10 16:21:38 +03:00
Ihor Radchenko 4cb39ba282
org-persist: Garbage-collect files outside index
* lisp/org-persist.el (org-persist-gc): Remove files from
`org-persist-directory' that are not listed in the index.  Update the
docstring accordingly.
2022-12-10 14:53:25 +03:00
Ihor Radchenko e7eaee6bba
Merge branch 'bugfix' 2022-12-10 13:23:51 +03:00
Ihor Radchenko 705ed74f36
Merge branch 'bugfix' 2022-12-10 13:02:44 +03:00
Ihor Radchenko cac0b1e96c
Merge branch 'bugfix' 2022-12-10 12:51:02 +03:00
Ihor Radchenko 28dc983fff
Merge branch 'bugfix' 2022-12-10 12:45:08 +03:00
Ihor Radchenko f01390cf05
org-inside-LaTeX-fragment-p: Use more accurate org-element API
* lisp/org.el (org-inside-LaTeX-fragment-p): Use `org-element-context'
to analyze context at point instead of ad-hoc regexp matching.  Do not
return undocumented cons cell.  Update docstring dropping all the
previously listed caveats.  Add new optional argument ELEMENT to
provide element at point.
(org--math-always-on): Follow new `org-inside-LaTeX-fragment-p' return
value spec.  Do no rely on previous undocumented convention.

Reported-by: Justin Silverman <jsilve24@gmail.com>
Link: https://orgmode.org/list/87v8mktt38.fsf@gmail.com
2022-12-10 12:22:04 +03:00
Ihor Radchenko 90db6d5b9c
Merge branch 'bugfix' 2022-12-10 12:04:55 +03:00
Ihor Radchenko ca5f852750
Merge branch 'bugfix' 2022-12-10 08:49:30 +03:00
Kyle Meyer bd5a39e60e Merge branch 'bugfix' 2022-12-09 22:55:39 -05:00
Ihor Radchenko 49cf3e3a7c
Merge branch 'bugfix' 2022-12-08 15:45:46 +03:00
Ihor Radchenko 0baa75bb45
Merge branch 'bugfix' 2022-12-08 15:06:59 +03:00
Ihor Radchenko 697aa627ac
Merge branch 'bugfix' 2022-12-08 14:38:47 +03:00
Jeremie Juste 1ad16ffb95 ob-R.el: Restore the handling of org-list in as var
* ob-R.el (org-babel-R-assign-elisp): Use the patch from
ccberry@health.ucsd.edu, to print org-list as a one column table as it
was the case in release_9.5. The break in R is due commit b4e437f96 *
ob-core: Resolve named list references to simple lists.

* test-ob-R.el (ob-R-nested-list): New function to test that org list
with multiple level are handled as expected in R.

see https://list.orgmode.org/87bkofh0ir.fsf@localhost/ for context.
2022-12-07 22:06:40 +01:00
Jeremie Juste 08433d9b0c test-ob-R.el: New function to test for :result output
* test-ob-R.el (ob-session-R-result-output): This test will check if
output is printed to buffer in a session with :results output. This
test is to prevent the bug mentioned in https://list.orgmode.org/877czca7oj.fsf@u-bordeaux.fr/
does not happen again.
2022-12-07 19:55:33 +01:00
Ihor Radchenko c59d6d82e6
Merge branch 'bugfix' 2022-12-07 17:02:51 +03:00
Ihor Radchenko 0ccf1da3dd
Merge branch 'bugfix' 2022-12-07 16:07:00 +03:00
Ihor Radchenko 1f5afbbcfb
Merge branch 'bugfix' 2022-12-07 14:25:17 +03:00
Ihor Radchenko 06648d43e4
Merge branch 'bugfix' 2022-12-07 14:15:31 +03:00
Ihor Radchenko dd499ccab8
Merge branch 'bugfix' 2022-12-07 13:52:17 +03:00
Rudolf Adamkovič 78d283e27d
ob-core: Remove the confusing "result silenced" message
* lisp/ob-core.el (org-babel-execute-src-block): Do not say "result
silenced" after executing the source blocks with `:results none' to
avoid confusion with `:results silent'.
2022-12-05 14:26:46 +03:00
Yuval Langer c4de06ce10
lisp/org.el: Mention how to widen in docstrings of commands that do narrowing
lisp/org.el: (org-narrow-to-subtree, org-toggle-narrow-to-subtree,
org-narrow-to-block, org-narrow-to-element): Mention how to widen in
docstrings of commands that do narrowing.

TINYCHANGE
2022-12-05 14:21:27 +03:00
Stefan Kangas 60de19f910
; Fix two typos 2022-12-04 16:29:00 +03:00
Stefan Kangas 81b083b083
Improve Swedish entry in org-export-dictionary
* lisp/ox.el (org-export-dictionary): Improve Swedish localization.
2022-12-04 16:27:33 +03:00
Ihor Radchenko f41ef345b6
Merge branch 'bugfix' 2022-12-04 16:19:47 +03:00
Gerard Vermeulen 4af243166c
org-clock-clocktable-language-setup: Fix Dutch translation
* lisp/org-clock.el (org-clock-clocktable-language-setup): Use Rubriek
for "heading".  It is more accurate as "Hoofding" refers to newspaper
headline.  Add the missing translation for "Clock summary at".

TINYCHANGE

Link: https://orgmode.org/list/4057b0bb88604e0f1ac4d18e11bf60f5@posteo.net
2022-12-04 14:13:15 +03:00
Ihor Radchenko 53814a8068
Merge branch 'bugfix' 2022-12-02 14:01:25 +08:00
Ihor Radchenko 9e9412919e
org-element: Prefer `org-element-with-disabled-cache' macro
* lisp/org-element.el (org-element--cache-verify-element):
(org-element-at-point-no-context): Use
`org-element-with-disabled-cache' instead of let-binding
`org-element-use-cache' variable.  The former is more reliable.
2022-12-02 13:26:56 +08:00
Kyle Meyer 74df6e55c2 Merge branch 'bugfix' 2022-12-01 17:27:29 -05:00
Kyle Meyer d500b406fc Merge branch 'bugfix' 2022-11-30 08:57:24 -05:00
Kyle Meyer 4bb59b505d Merge branch 'bugfix'
Discard the ORG-NEWS change from 3b7981869.
2022-11-29 21:27:01 -05:00
197 changed files with 33693 additions and 14718 deletions

View File

@ -4,7 +4,7 @@ effectively.
We value a nice tone in our discussions: please check and respect the
[[https://www.gnu.org/philosophy/kind-communication.en.html][GNU Kind Communications Guidelines]].
* Contribute as a Org user
* Contribute as an Org user
You can contribute by helping others in various channels.
@ -16,7 +16,7 @@ You can contribute with bug reports and patches.
See these [[https://orgmode.org/worg/org-contribute.html#org069b83a][directions]].
* As a Org maintainer
* As an Org maintainer
We encourage you to volunteer to maintain one of the Org files.

View File

@ -27,6 +27,7 @@ help helpall::
$(info make all - ditto)
$(info make compile - build Org ELisp files)
$(info make single - build Org ELisp files, single Emacs per source)
$(info make native - build Org natively compiled Elisp files)
$(info make autoloads - create org-loaddefs.el to load Org in-place)
$(info make test - build Org ELisp files and run test suite)
$(info make vanilla - run Emacs with this Org-mode and no personal config)

View File

@ -1,6 +1,6 @@
# SETUPFILE for Org manual
# Copyright (C) 2021-2023 Free Software Foundation, Inc.
# Copyright (C) 2021-2024 Free Software Foundation, Inc.
#
# This file is part of GNU Emacs.
#

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -9,13 +9,17 @@
% Specify how many you want here.
\columnsperpage=3
% Set letterpaper to 0 for A4 paper, 1 for letter (US) paper. Useful
% only when columnsperpage is 2 or 3.
\letterpaper=1
% PDF output layout. 0 for A4, 1 for letter (US), a `l' is added for
% a landscape layout.
\input pdflayout.sty
\pdflayout=(0l)
\pdflayout=(1l)
% Nothing else needs to be changed below this line.
% Copyright (C) 1987, 1993, 1996--1997, 2001--2023 Free Software
% Copyright (C) 1987, 1993, 1996--1997, 2001--2024 Free Software
% Foundation, Inc.
% This document is free software: you can redistribute it and/or modify
@ -108,17 +112,14 @@
\footline{\hss\folio}
\def\makefootline{\baselineskip10pt\hsize6.5in\line{\the\footline}}
\else %2 or 3 columns uses prereduced size
\hsize 3.2in
\if 1\the\letterpaper
\hsize 3.2in
\vsize 7.95in
\hoffset -.75in
\voffset -.745in
\else
\hsize 3.2in
\vsize 7.65in
\hoffset -.25in
\voffset -.745in
\fi
\hoffset -.75in
\voffset -.745in
\font\titlefont=cmbx10 \scaledmag2
\font\headingfont=cmbx10 \scaledmag1
\font\smallfont=cmr6
@ -275,7 +276,7 @@
%**end of header
\title{Org-Mode Reference Card (1/2)}
\title{Org-Mode Reference Card}
\centerline{(for version \orgversionnumber)}
@ -477,7 +478,7 @@ after ``{\tt :}'', and dictionary words elsewhere.
\newcolumn
\title{Org-Mode Reference Card (2/2)}
\title{Org-Mode Reference Card}
\centerline{(for version \orgversionnumber)}

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
The files OrgOdtContentTemplate.xml and OrgOdtStyles.xml have the
following copyright information:
Copyright (C) 2010-2023 Free Software Foundation, Inc.
Copyright (C) 2010-2024 Free Software Foundation, Inc.
These files are part of GNU Emacs.

View File

@ -1,35 +1,25 @@
.NOTPARALLEL: # always run this make serially
.SUFFIXES: # we don't need default suffix rules
ifeq ($(MAKELEVEL), 0)
$(error This make needs to be started as a sub-make from the toplevel directory.)
endif
ifneq ($(ORG_ADD_CONTRIB),)
_ORG_ADD_EL_ := \
$(notdir \
$(wildcard \
$(addsuffix .el, \
$(addprefix ../contrib/lisp/, \
$(basename \
$(notdir $(ORG_ADD_CONTRIB)))))))
endif
LISPV := org-version.el
LISPI := org-loaddefs.el
LISPA := $(LISPV) $(LISPI)
LISPB := $(LISPA:%el=%elc) org-install.elc
LISPF := $(filter-out $(LISPA),$(sort $(wildcard *.el) $(_ORG_ADD_EL_)))
LISPF := $(filter-out $(LISPA),$(sort $(wildcard *.el)))
LISPC := $(filter-out $(LISPB) $(LISPN:%el=%elc),$(LISPF:%el=%elc))
_ORGCM_ := dirall single source slint1 slint2
LISPN := $(filter-out $(LISPB) $(LISPN:%el=%eln),$(LISPF:%el=%eln))
_ORGCM_ := dirall single native source slint1 slint2
-include local.mk
.PHONY: all compile compile-dirty \
$(_ORGCM_) $(_ORGCM_:%=compile-%) \
autoloads addcontrib \
autoloads \
install clean cleanauto cleanall cleanelc clean-install
# do not clean here, done in toplevel make
all compile compile-dirty:: autoloads
all compile compile-dirty:: | autoloads
ifeq ($(filter-out $(_ORGCM_),$(ORGCM)),)
$(MAKE) compile-$(ORGCM)
else
@ -37,10 +27,11 @@ else
endif
compile-dirall: dirall
compile-single: single $(LISPC)
compile-source: source dirall
compile-slint1: dirall slint1
compile-slint2: source dirall slint1
compile-single: $(LISPC) | single
compile-native: $(LISPN) | native
compile-source: | source dirall
compile-slint1: | dirall slint1
compile-slint2: | source dirall slint1
# internal
dirall:
@ -48,6 +39,8 @@ dirall:
@$(ELCDIR)
single:
@$(info ==================== $@ ====================)
native:
@$(info ==================== $@ ====================)
source: cleanelc
@$(info ==================== $@ ====================)
@$(foreach elc,$(LISPC),$(MAKE) $(elc) && $(RM) $(elc);)
@ -59,12 +52,11 @@ slint1:
@$(info Compiling single $(abspath $<)...)
-@$(ELC) $<
addcontrib:
ifneq ($(ORG_ADD_CONTRIB),)
$(CP) $(addprefix ../contrib/lisp/,$(_ORG_ADD_EL_)) .
endif
%.eln: %.el
@$(info Native compiling single $(abspath $<)...)
-@$(ELN) $<
autoloads: cleanauto addcontrib $(LISPI) $(LISPV)
autoloads: cleanauto $(LISPI) $(LISPV)
$(LISPV): $(LISPF)
@echo "org-version: $(ORGVERSION) ($(GITVERSION))"

View File

@ -1,6 +1,6 @@
;;; ob-C.el --- Babel Functions for C and Similar Languages -*- lexical-binding: t; -*-
;; Copyright (C) 2010-2023 Free Software Foundation, Inc.
;; Copyright (C) 2010-2024 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Thierry Banel
@ -93,44 +93,45 @@ parameter may be used, like rdmd --chatty"
is currently being evaluated.")
(defun org-babel-execute:cpp (body params)
"Execute BODY according to PARAMS.
"Execute BODY according to its header arguments PARAMS.
This function calls `org-babel-execute:C++'."
(org-babel-execute:C++ body params))
(defun org-babel-expand-body:cpp (body params)
"Expand a block of C++ code with org-babel according to its header arguments."
"Expand C++ BODY with org-babel according to its header arguments PARAMS."
(org-babel-expand-body:C++ body params))
(defun org-babel-execute:C++ (body params)
"Execute a block of C++ code with org-babel.
"Execute C++ BODY with org-babel according to its header arguments PARAMS.
This function is called by `org-babel-execute-src-block'."
(let ((org-babel-c-variant 'cpp)) (org-babel-C-execute body params)))
(defun org-babel-expand-body:C++ (body params)
"Expand a block of C++ code with org-babel according to its header arguments."
"Expand C++ BODY with org-babel according to its header arguments PARAMS."
(let ((org-babel-c-variant 'cpp)) (org-babel-C-expand-C++ body params)))
(defun org-babel-execute:D (body params)
"Execute a block of D code with org-babel.
"Execute D BODY with org-babel according to its header arguments PARAMS.
This function is called by `org-babel-execute-src-block'."
(let ((org-babel-c-variant 'd)) (org-babel-C-execute body params)))
(defun org-babel-expand-body:D (body params)
"Expand a block of D code with org-babel according to its header arguments."
"Expand D BODY with org-babel according to its header arguments PARAMS."
(let ((org-babel-c-variant 'd)) (org-babel-C-expand-D body params)))
(defun org-babel-execute:C (body params)
"Execute a block of C code with org-babel.
"Execute a C BODY according to its header arguments PARAMS.
This function is called by `org-babel-execute-src-block'."
(let ((org-babel-c-variant 'c)) (org-babel-C-execute body params)))
(defun org-babel-expand-body:C (body params)
"Expand a block of C code with org-babel according to its header arguments."
"Expand C BODY according to its header arguments PARAMS."
(let ((org-babel-c-variant 'c)) (org-babel-C-expand-C body params)))
(defun org-babel-C-execute (body params)
"This function should only be called by `org-babel-execute:C'
or `org-babel-execute:C++' or `org-babel-execute:D'."
"Execute C/C++/D BODY according to its header arguments PARAMS.
This function should only be called by `org-babel-execute:C' or
`org-babel-execute:C++' or `org-babel-execute:D'."
(let* ((tmp-src-file (org-babel-temp-file
"C-src-"
(pcase org-babel-c-variant
@ -196,11 +197,11 @@ or `org-babel-execute:C++' or `org-babel-execute:D'."
)))
(defun org-babel-C-expand-C++ (body params)
"Expand a block of C/C++ code with org-babel according to its header arguments."
"Expand C/C++ BODY with according to its header arguments PARAMS."
(org-babel-C-expand-C body params))
(defun org-babel-C-expand-C (body params)
"Expand a block of C/C++ code with org-babel according to its header arguments."
"Expand C/C++ BODY according to its header arguments PARAMS."
(let ((vars (org-babel--get-vars params))
(colnames (cdr (assq :colname-names params)))
(main-p (not (string= (cdr (assq :main params)) "no")))
@ -212,7 +213,9 @@ or `org-babel-execute:C++' or `org-babel-execute:D'."
nil))
(namespaces (org-babel-read
(cdr (assq :namespaces params))
nil)))
nil))
(prologue (cdr (assq :prologue params)))
(epilogue (cdr (assq :epilogue params))))
(when (stringp includes)
(setq includes (split-string includes)))
(when (stringp namespaces)
@ -226,6 +229,11 @@ or `org-babel-execute:C++' or `org-babel-execute:D'."
(nconc result (list (concat y " " x)))
(setq y nil)))
(setq defines (cdr result))))
(setq body
(concat
(and prologue (concat prologue "\n"))
body
(and epilogue (concat "\n" epilogue "\n"))))
(mapconcat 'identity
(list
;; includes
@ -269,7 +277,7 @@ or `org-babel-execute:C++' or `org-babel-execute:D'."
body) "\n") "\n")))
(defun org-babel-C-expand-D (body params)
"Expand a block of D code with org-babel according to its header arguments."
"Expand D BODY according to its header arguments PARAMS."
(let ((vars (org-babel--get-vars params))
(colnames (cdr (assq :colname-names params)))
(main-p (not (string= (cdr (assq :main params)) "no")))
@ -313,13 +321,15 @@ or `org-babel-execute:C++' or `org-babel-execute:D'."
(format "int main() {\n%s\nreturn 0;\n}\n" body)))
(defun org-babel-prep-session:C (_session _params)
"This function does nothing as C is a compiled language with no
support for sessions."
"Throw and error that sessions are not supported.
This function does nothing as C is a compiled language with no support
for sessions."
(error "C is a compiled language -- no support for sessions"))
(defun org-babel-load-session:C (_session _body _params)
"This function does nothing as C is a compiled language with no
support for sessions."
"Throw and error that sessions are not supported.
This function does nothing as C is a compiled language with no support
for sessions."
(error "C is a compiled language -- no support for sessions"))
;; helper functions
@ -379,10 +389,11 @@ FORMAT can be either a format string or a function which is called with VAL."
type))))
(defun org-babel-C-val-to-base-type (val)
"Determine the base type of VAL which may be
`integerp' if all base values are integers
`floatp' if all base values are either floating points or integers
`stringp' otherwise."
"Determine the base type of VAL.
The type is:
- `integerp' if all base values are integers;
- `floatp' if all base values are either floating points or integers;
- `stringp' otherwise."
(cond
((integerp val) 'integerp)
((floatp val) 'floatp)
@ -401,7 +412,7 @@ FORMAT can be either a format string or a function which is called with VAL."
(t 'stringp)))
(defun org-babel-C-var-to-C (pair)
"Convert an elisp val into a string of C code specifying a var of the same value."
"Convert PAIR of (var . val) C variable assignment."
;; TODO list support
(let ((var (car pair))
(val (cdr pair)))

View File

@ -1,6 +1,6 @@
;;; ob-R.el --- Babel Functions for R -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Dan Davison
@ -64,6 +64,7 @@
(colormodel . :any)
(useDingbats . :any)
(horizontal . :any)
(async . ((yes no)))
(results . ((file list vector table scalar verbatim)
(raw html latex org code pp drawer)
(replace silent none append prepend)
@ -91,15 +92,6 @@ this variable.")
:version "24.1"
:type 'string)
(defvar ess-current-process-name) ; dynamically scoped
(defvar ess-local-process-name) ; dynamically scoped
(defun org-babel-edit-prep:R (info)
(let ((session (cdr (assq :session (nth 2 info)))))
(when (and session
(string-prefix-p "*" session)
(string-suffix-p "*" session))
(org-babel-R-initiate-session session nil))))
;; The usage of utils::read.table() ensures that the command
;; read.table() can be found even in circumstances when the utils
;; package is not in the search path from R.
@ -156,7 +148,7 @@ This function is used when the table does not contain a header.")
"\n"))
(defun org-babel-execute:R (body params)
"Execute a block of R code.
"Execute a block of R code BODY according to PARAMS.
This function is called by `org-babel-execute-src-block'."
(save-excursion
(let* ((result-params (cdr (assq :result-params params)))
@ -215,7 +207,8 @@ This function is called by `org-babel-execute-src-block'."
;; helper functions
(defun org-babel-variable-assignments:R (params)
"Return list of R statements assigning the block's variables."
"Return list of R statements assigning the block's variables.
Retrieve variables from PARAMS."
(let ((vars (org-babel--get-vars params)))
(mapcar
(lambda (pair)
@ -261,42 +254,44 @@ This function is called by `org-babel-execute-src-block'."
(t (format "%s <- %S" name (prin1-to-string value))))))
(defvar ess-current-process-name) ; dynamically scoped
(defvar ess-local-process-name) ; dynamically scoped
(defvar ess-ask-for-ess-directory) ; dynamically scoped
(defvar ess-gen-proc-buffer-name-function) ; defined in ess-inf.el
(defun org-babel-R-initiate-session (session params)
"If there is not a current R process then create one."
"Create or return the current R SESSION buffer.
Use PARAMS to set default directory when creating a new session."
(unless (string= session "none")
(let ((session (or session "*R*"))
(ess-ask-for-ess-directory
(and (boundp 'ess-ask-for-ess-directory)
ess-ask-for-ess-directory
(not (cdr (assq :dir params))))))
(let* ((session (or session "*R*"))
(ess-ask-for-ess-directory
(and (boundp 'ess-ask-for-ess-directory)
ess-ask-for-ess-directory
(not (cdr (assq :dir params)))))
;; Make ESS name the process buffer as SESSION.
(ess-gen-proc-buffer-name-function
(lambda (_) session)))
(if (org-babel-comint-buffer-livep session)
session
(save-window-excursion
(when (get-buffer session)
;; Session buffer exists, but with dead process
(set-buffer session))
(require 'ess-r-mode)
(org-require-package 'ess-r-mode "ESS")
(set-buffer (run-ess-r))
(let ((R-proc (get-process (or ess-local-process-name
ess-current-process-name))))
(while (process-get R-proc 'callbacks)
(ess-wait-for-process R-proc)))
(rename-buffer
(if (bufferp session)
(buffer-name session)
(if (stringp session)
session
(buffer-name))))
(current-buffer))))))
(defun org-babel-R-associate-session (session)
"Associate R code buffer with an R session.
Make SESSION be the inferior ESS process associated with the
current code buffer."
(setq ess-local-process-name
(process-name (get-buffer-process session)))
(ess-make-buffer-current))
(when-let ((process (get-buffer-process session)))
(setq ess-local-process-name (process-name process))
(ess-make-buffer-current))
(setq-local ess-gen-proc-buffer-name-function (lambda (_) session)))
(defvar org-babel-R-graphics-devices
'((:bmp "bmp" "filename")
@ -520,7 +515,7 @@ by `org-babel-comint-async-filter'."
(ess-eval-buffer nil)))
tmp-file))
(output
(let ((uuid (md5 (number-to-string (random 100000000))))
(let ((uuid (org-id-uuid))
(ess-local-process-name
(process-name (get-buffer-process session)))
(ess-eval-visibly-p nil))

View File

@ -1,6 +1,6 @@
;;; ob-awk.el --- Babel Functions for Awk -*- lexical-binding: t; -*-
;; Copyright (C) 2011-2023 Free Software Foundation, Inc.
;; Copyright (C) 2011-2024 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Maintainer: Tyler Smith <tyler@plantarum.ca>
@ -48,12 +48,18 @@
(defvar org-babel-awk-command "awk"
"Name of the awk executable command.")
(defun org-babel-expand-body:awk (body _params)
(defun org-babel-expand-body:awk (body params)
"Expand BODY according to PARAMS, return the expanded body."
body)
(let ((prologue (cdr (assq :prologue params)))
(epilogue (cdr (assq :epilogue params))))
(concat
(and prologue (concat prologue "\n"))
body
(and epilogue (concat "\n" epilogue "\n")))))
(defun org-babel-execute:awk (body params)
"Execute a block of Awk code with org-babel.
"Execute a block of Awk code BODY with org-babel.
PARAMS is a plist of src block parameters .
This function is called by `org-babel-execute-src-block'."
(message "Executing Awk source code block")
(let* ((result-params (cdr (assq :result-params params)))
@ -100,7 +106,9 @@ This function is called by `org-babel-execute-src-block'."
(cdr (assq :rowname-names params)) (cdr (assq :rownames params))))))
(defun org-babel-awk-var-to-awk (var &optional sep)
"Return a printed value of VAR suitable for parsing with awk."
"Return a printed value of VAR suitable for parsing with awk.
SEP, when non-nil is a separator used when converting list values to awk
table."
(let ((echo-var (lambda (v) (if (stringp v) v (format "%S" v)))))
(cond
((and (listp var) (listp (car var)))

View File

@ -1,6 +1,6 @@
;;; ob-calc.el --- Babel Functions for Calc -*- lexical-binding: t; -*-
;; Copyright (C) 2010-2023 Free Software Foundation, Inc.
;; Copyright (C) 2010-2024 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Maintainer: Tom Gillespie <tgbugs@gmail.com>
@ -44,13 +44,19 @@
(defvar org-babel-default-header-args:calc nil
"Default arguments for evaluating a calc source block.")
(defun org-babel-expand-body:calc (body _params)
"Expand BODY according to PARAMS, return the expanded body." body)
(defun org-babel-expand-body:calc (body params)
"Expand BODY according to PARAMS, return the expanded body."
(let ((prologue (cdr (assq :prologue params)))
(epilogue (cdr (assq :epilogue params))))
(concat
(and prologue (concat prologue "\n"))
body
(and epilogue (concat "\n" epilogue "\n")))))
(defvar org--var-syms) ; Dynamically scoped from org-babel-execute:calc
(defun org-babel-execute:calc (body params)
"Execute a block of calc code with Babel."
"Execute BODY of calc code with Babel using PARAMS."
(unless (get-buffer "*Calculator*")
(save-window-excursion (calc) (calc-quit)))
(let* ((vars (org-babel--get-vars params))
@ -58,7 +64,19 @@
(var-names (mapcar #'symbol-name org--var-syms)))
(mapc
(lambda (pair)
(calc-push-list (list (cdr pair)))
(let ((val (cdr pair)))
(calc-push-list
;; For a vector, Calc follows the format (vec 1 2 3 ...) so
;; a matrix becomes (vec (vec 1 2 3) (vec 4 5 6) ...). See
;; the comments in "Arithmetic routines." section of
;; calc.el.
(list (if (listp val)
(cons 'vec
(if (null (cdr val))
(car val)
(mapcar (lambda (x) (if (listp x) (cons 'vec x) x))
val)))
val))))
(calc-store-into (car pair)))
vars)
(mapc
@ -99,6 +117,8 @@
(calc-pop 1)))))
(defun org-babel-calc-maybe-resolve-var (el)
"Resolve user variables in EL.
EL is taken from the output of `math-read-exprs'."
(if (consp el)
(if (and (eq 'var (car el)) (member (cadr el) org--var-syms))
(progn

View File

@ -1,6 +1,6 @@
;;; ob-clojure.el --- Babel Functions for Clojure -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Author: Joel Boehland, Eric Schulte, Oleh Krehel, Frederick Giasson
;; Maintainer: Daniel Kraus <daniel@kraus.my>
@ -25,20 +25,21 @@
;;; Commentary:
;; Support for evaluating Clojure code
;; Support for evaluating Clojure / ClojureScript code.
;; Requirements:
;; - Clojure (at least 1.2.0)
;; - clojure-mode
;; - inf-clojure, Cider, SLIME, babashka or nbb
;; - babashka, nbb, Clojure CLI tools, Cider, inf-clojure or SLIME
;; For clojure-mode, see https://github.com/clojure-emacs/clojure-mode
;; For inf-clojure, see https://github.com/clojure-emacs/inf-clojure
;; For Cider, see https://github.com/clojure-emacs/cider
;; For SLIME, see https://slime.common-lisp.dev
;; For babashka, see https://github.com/babashka/babashka
;; For nbb, see https://github.com/babashka/nbb
;; For Clojure CLI tools, see https://clojure.org/guides/deps_and_cli
;; For Cider, see https://github.com/clojure-emacs/cider
;; For inf-clojure, see https://github.com/clojure-emacs/inf-clojure
;; For SLIME, see https://slime.common-lisp.dev
;; For SLIME, the best way to install its components is by following
;; the directions as set out by Phil Hagelberg (Technomancy) on the
@ -78,20 +79,33 @@
(defcustom org-babel-clojure-backend (cond
((executable-find "bb") 'babashka)
((executable-find "nbb") 'nbb)
((executable-find "clojure") 'clojure-cli)
((featurep 'cider) 'cider)
((featurep 'inf-clojure) 'inf-clojure)
((featurep 'slime) 'slime)
(t nil))
"Backend used to evaluate Clojure code blocks."
:group 'org-babel
:package-version '(Org . "9.6")
:package-version '(Org . "9.7")
:type '(choice
(const :tag "inf-clojure" inf-clojure)
(const :tag "cider" cider)
(const :tag "slime" slime)
(const :tag "babashka" babashka)
(const :tag "clojure-cli" clojure-cli)
(const :tag "cider" cider)
(const :tag "inf-clojure" inf-clojure)
(const :tag "slime" slime)
(const :tag "Not configured yet" nil)))
(defcustom org-babel-clojurescript-backend
(cond
((or (executable-find "nbb") (executable-find "npx")) 'nbb)
((featurep 'cider) 'cider)
(t nil))
"Backend used to evaluate ClojureScript code blocks."
:group 'org-babel
:package-version '(Org . "9.7")
:type '(choice
(const :tag "nbb" nbb)
(const :tag "cider" cider)
(const :tag "Not configured yet" nil)))
(defcustom org-babel-clojure-default-ns "user"
@ -100,19 +114,29 @@
:group 'org-babel)
(defcustom ob-clojure-babashka-command (executable-find "bb")
"Path to the babashka executable."
"Babashka command used by the Clojure `babashka' backend."
:type '(choice file (const nil))
:group 'org-babel
:package-version '(Org . "9.6"))
(defcustom ob-clojure-nbb-command (executable-find "nbb")
"Path to the nbb executable."
:type '(choice file (const nil))
(defcustom ob-clojure-nbb-command (or (executable-find "nbb")
(when-let (npx (executable-find "npx"))
(concat npx " nbb")))
"Nbb command used by the ClojureScript `nbb' backend."
:type '(choice string (const nil))
:group 'org-babel
:package-version '(Org . "9.6"))
:package-version '(Org . "9.7"))
(defun org-babel-expand-body:clojure (body params)
"Expand BODY according to PARAMS, return the expanded body."
(defcustom ob-clojure-cli-command (when-let (cmd (executable-find "clojure"))
(concat cmd " -M"))
"Clojure CLI command used by the Clojure `clojure-cli' backend."
:type 'string
:group 'org-babel
:package-version '(Org . "9.7"))
(defun org-babel-expand-body:clojure (body params &optional cljs-p)
"Expand BODY according to PARAMS, return the expanded body.
When CLJS-P is non-nil, expand in a cljs context instead of clj."
(let* ((vars (org-babel--get-vars params))
(backend-override (cdr (assq :backend params)))
(org-babel-clojure-backend
@ -146,10 +170,26 @@ or set the `:backend' header argument"))))
vars
"\n ")
body))))))
(if (or (member "code" result-params)
(member "pp" result-params))
(format "(clojure.pprint/pprint (do %s))" body)
body)))
;; If the result param is set to "output" we don't have to do
;; anything special and just let the backend handle everything
(if (member "output" result-params)
body
;; If the result is not "output" (i.e. it's "value"), disable
;; stdout output and print the last returned value. Use pprint
;; instead of prn when results param is "pp" or "code".
(concat
(if (or (member "code" result-params)
(member "pp" result-params))
(concat (if cljs-p
"(require '[cljs.pprint :refer [pprint]])"
"(require '[clojure.pprint :refer [pprint]])")
" (pprint ")
"(prn ")
(if cljs-p
"(binding [cljs.core/*print-fn* (constantly nil)]"
"(binding [*out* (java.io.StringWriter.)]")
body "))"))))
(defvar ob-clojure-inf-clojure-filter-out)
(defvar ob-clojure-inf-clojure-tmp-output)
@ -186,8 +226,7 @@ or set the `:backend' header argument"))))
(defvar inf-clojure-comint-prompt-regexp)
(defun ob-clojure-eval-with-inf-clojure (expanded params)
"Evaluate EXPANDED code block with PARAMS using inf-clojure."
(condition-case nil (require 'inf-clojure)
(user-error "inf-clojure not available"))
(org-require-package 'inf-clojure)
;; Maybe initiate the inf-clojure session
(unless (and inf-clojure-buffer
(buffer-live-p (get-buffer inf-clojure-buffer)))
@ -198,7 +237,9 @@ or set the `:backend' header argument"))))
"clojure" (format "clojure -A%s" alias)
cmd0)
cmd0)))
(setq comint-prompt-regexp inf-clojure-comint-prompt-regexp)
(setq
org-babel-comint-prompt-regexp-old comint-prompt-regexp
comint-prompt-regexp inf-clojure-comint-prompt-regexp)
(funcall-interactively #'inf-clojure cmd)
(goto-char (point-max))))
(sit-for 1))
@ -226,38 +267,24 @@ or set the `:backend' header argument"))))
s))
(reverse ob-clojure-inf-clojure-tmp-output)))))
(defun ob-clojure-eval-with-cider (expanded params)
"Evaluate EXPANDED code block with PARAMS using cider."
(condition-case nil (require 'cider)
(user-error "cider not available"))
(let ((connection (cider-current-connection (cdr (assq :target params))))
(result-params (cdr (assq :result-params params)))
result0)
(defun ob-clojure-eval-with-cider (expanded _params &optional cljs-p)
"Evaluate EXPANDED code block using cider.
When CLJS-P is non-nil, use a cljs connection instead of clj.
The PARAMS from Babel are not used in this function."
(org-require-package 'cider "Cider")
(let ((connection (cider-current-connection (if cljs-p "cljs" "clj"))))
(unless connection (sesman-start-session 'CIDER))
(if (not connection)
;; Display in the result instead of using `user-error'
(setq result0 "Please reevaluate when nREPL is connected")
(ob-clojure-with-temp-expanded expanded params
(let ((response (nrepl-sync-request:eval exp connection)))
(push (or (nrepl-dict-get response "root-ex")
(nrepl-dict-get response "ex")
(nrepl-dict-get
response (if (or (member "output" result-params)
(member "pp" result-params))
"out"
"value")))
result0)))
(ob-clojure-string-or-list
;; Filter out s-expressions that return nil (string "nil"
;; from nrepl eval) or comment forms (actual nil from nrepl)
(reverse (delete "" (mapcar (lambda (r)
(replace-regexp-in-string "nil" "" (or r "")))
result0)))))))
"Please reevaluate when nREPL is connected"
(let ((response (nrepl-sync-request:eval expanded connection)))
(or (nrepl-dict-get response "root-ex")
(nrepl-dict-get response "ex")
(nrepl-dict-get response "out"))))))
(defun ob-clojure-eval-with-slime (expanded params)
"Evaluate EXPANDED code block with PARAMS using slime."
(condition-case nil (require 'slime)
(user-error "slime not available"))
(org-require-package 'slime "SLIME")
(with-temp-buffer
(insert expanded)
(slime-eval
@ -265,39 +292,54 @@ or set the `:backend' header argument"))))
,(buffer-substring-no-properties (point-min) (point-max)))
(cdr (assq :package params)))))
(defun ob-clojure-eval-with-babashka (bb expanded)
"Evaluate EXPANDED code block using BB (babashka or nbb)."
(let ((script-file (org-babel-temp-file "clojure-bb-script-" ".clj")))
(defun ob-clojure-eval-with-cmd (cmd expanded)
"Evaluate EXPANDED code block using CMD (babashka, clojure or nbb)."
(let ((script-file (org-babel-temp-file "clojure-cmd-script-" ".clj")))
(with-temp-file script-file
(insert expanded))
(org-babel-eval
(format "%s %s" bb (org-babel-process-file-name script-file))
(format "%s %s" cmd (org-babel-process-file-name script-file))
"")))
(defun org-babel-execute:clojure (body params)
"Execute the BODY block of Clojure code with PARAMS using Babel."
(defun org-babel-execute:clojure (body params &optional cljs-p)
"Execute the BODY block of Clojure code with PARAMS using Babel.
When CLJS-P is non-nil, execute with a ClojureScript backend
instead of Clojure."
(let* ((backend-override (cdr (assq :backend params)))
(org-babel-clojure-backend
(cond
(backend-override (intern backend-override))
(org-babel-clojure-backend org-babel-clojure-backend)
(t (user-error "You need to customize `org-babel-clojure-backend'
or set the `:backend' header argument")))))
(let* ((expanded (org-babel-expand-body:clojure body params))
(org-babel-clojure-backend (if cljs-p
org-babel-clojurescript-backend
org-babel-clojure-backend))
(t (user-error "You need to customize `%S'
or set the `:backend' header argument"
(if cljs-p
org-babel-clojurescript-backend
org-babel-clojure-backend)))))
;; We allow a Clojure source block to be evaluated with the
;; nbb backend and therefore have to expand the body with
;; ClojureScript syntax when we either evaluate a
;; ClojureScript source block or use the nbb backend.
(cljs-p (or cljs-p (eq org-babel-clojure-backend 'nbb))))
(let* ((expanded (org-babel-expand-body:clojure body params cljs-p))
(result-params (cdr (assq :result-params params)))
result)
(setq result
(cond
((eq org-babel-clojure-backend 'inf-clojure)
(ob-clojure-eval-with-inf-clojure expanded params))
((eq org-babel-clojure-backend 'clojure-cli)
(ob-clojure-eval-with-cmd ob-clojure-cli-command expanded))
((eq org-babel-clojure-backend 'babashka)
(ob-clojure-eval-with-babashka ob-clojure-babashka-command expanded))
(ob-clojure-eval-with-cmd ob-clojure-babashka-command expanded))
((eq org-babel-clojure-backend 'nbb)
(ob-clojure-eval-with-babashka ob-clojure-nbb-command expanded))
(ob-clojure-eval-with-cmd ob-clojure-nbb-command expanded))
((eq org-babel-clojure-backend 'cider)
(ob-clojure-eval-with-cider expanded params))
(ob-clojure-eval-with-cider expanded params cljs-p))
((eq org-babel-clojure-backend 'slime)
(ob-clojure-eval-with-slime expanded params))))
(ob-clojure-eval-with-slime expanded params))
(t (user-error "Invalid backend"))))
(org-babel-result-cond result-params
result
(condition-case nil (org-babel-script-escape result)
@ -305,7 +347,7 @@ or set the `:backend' header argument")))))
(defun org-babel-execute:clojurescript (body params)
"Evaluate BODY with PARAMS as ClojureScript code."
(org-babel-execute:clojure body (cons '(:target . "cljs") params)))
(org-babel-execute:clojure body params t))
(provide 'ob-clojure)

View File

@ -1,6 +1,6 @@
;;; ob-comint.el --- Babel Functions for Interaction with Comint Buffers -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research, comint
@ -58,6 +58,47 @@ executed inside the protection of `save-excursion' and
(let ((comint-input-filter (lambda (_input) nil)))
,@body))))))
(defvar-local org-babel-comint-prompt-regexp-old nil
"Fallback regexp used to detect prompt.")
(defcustom org-babel-comint-fallback-regexp-threshold 5.0
"Waiting time until trying to use fallback regexp to detect prompt.
This is useful when prompt unexpectedly changes."
:type 'float
:group 'org-babel)
(defun org-babel-comint--set-fallback-prompt ()
"Swap `comint-prompt-regexp' and `org-babel-comint-prompt-regexp-old'."
(when org-babel-comint-prompt-regexp-old
(let ((tmp comint-prompt-regexp))
(setq comint-prompt-regexp org-babel-comint-prompt-regexp-old
org-babel-comint-prompt-regexp-old tmp))))
(defun org-babel-comint--prompt-filter (string &optional prompt-regexp)
"Remove PROMPT-REGEXP from STRING.
PROMPT-REGEXP defaults to `comint-prompt-regexp'."
(let* ((prompt-regexp (or prompt-regexp comint-prompt-regexp))
;; We need newline in case if we do progressive replacement
;; of agglomerated comint prompts with `comint-prompt-regexp'
;; containing ^.
(separator "org-babel-comint--prompt-filter-separator\n"))
(while (string-match-p prompt-regexp string)
(setq string
(replace-regexp-in-string
(format "\\(?:%s\\)?\\(?:%s\\)[ \t]*" separator prompt-regexp)
separator string)))
(delete "" (split-string string separator))))
(defun org-babel-comint--echo-filter (string &optional echo)
"Remove ECHO from STRING."
(and echo string
(string-match
(replace-regexp-in-string "\n" "[\r\n]+" (regexp-quote echo))
string)
(setq string (substring string (match-end 0))))
string)
(defmacro org-babel-comint-with-output (meta &rest body)
"Evaluate BODY in BUFFER and return process output.
Will wait until EOE-INDICATOR appears in the output, then return
@ -74,9 +115,7 @@ or user `keyboard-quit' during execution of body."
(let ((buffer (nth 0 meta))
(eoe-indicator (nth 1 meta))
(remove-echo (nth 2 meta))
(full-body (nth 3 meta))
(org-babel-comint-prompt-separator
"org-babel-comint-prompt-separator"))
(full-body (nth 3 meta)))
`(org-babel-comint-in-buffer ,buffer
(let* ((string-buffer "")
(comint-output-filter-functions
@ -93,43 +132,39 @@ or user `keyboard-quit' during execution of body."
;; pass FULL-BODY to process
,@body
;; wait for end-of-evaluation indicator
(while (progn
(goto-char comint-last-input-end)
(not (save-excursion
(and (re-search-forward
(regexp-quote ,eoe-indicator) nil t)
(re-search-forward
comint-prompt-regexp nil t)))))
(accept-process-output (get-buffer-process (current-buffer))))
(let ((start-time (current-time)))
(while (progn
(goto-char comint-last-input-end)
(not (save-excursion
(and (re-search-forward
(regexp-quote ,eoe-indicator) nil t)
(re-search-forward
comint-prompt-regexp nil t)))))
(accept-process-output
(get-buffer-process (current-buffer))
org-babel-comint-fallback-regexp-threshold)
(when (and org-babel-comint-prompt-regexp-old
(> (float-time (time-since start-time))
org-babel-comint-fallback-regexp-threshold)
(progn
(goto-char comint-last-input-end)
(save-excursion
(and
(re-search-forward
(regexp-quote ,eoe-indicator) nil t)
(re-search-forward
org-babel-comint-prompt-regexp-old nil t)))))
(org-babel-comint--set-fallback-prompt))))
;; replace cut dangling text
(goto-char (process-mark (get-buffer-process (current-buffer))))
(insert dangling-text)
;; remove echo'd FULL-BODY from input
(and ,remove-echo ,full-body
(setq string-buffer (org-babel-comint--echo-filter string-buffer ,full-body)))
;; Filter out prompts.
(setq string-buffer
(replace-regexp-in-string
;; Sometimes, we get multiple agglomerated
;; prompts together in a single output:
;; "prompt prompt prompt output"
;; Remove them progressively, so that
;; possible "^" in the prompt regexp gets to
;; work as we remove the heading prompt
;; instance.
(if (string-prefix-p "^" comint-prompt-regexp)
(format "^\\(%s\\)+" (substring comint-prompt-regexp 1))
comint-prompt-regexp)
,org-babel-comint-prompt-separator
string-buffer))
;; remove echo'd FULL-BODY from input
(when (and ,remove-echo ,full-body
(string-match
(replace-regexp-in-string
"\n" "[\r\n]+" (regexp-quote (or ,full-body "")))
string-buffer))
(setq string-buffer (substring string-buffer (match-end 0))))
(delete "" (split-string
string-buffer
,org-babel-comint-prompt-separator))))))
(org-babel-comint--prompt-filter string-buffer)))))
(defun org-babel-comint-input-command (buffer cmd)
"Pass CMD to BUFFER.
@ -145,11 +180,23 @@ The input will not be echoed."
Note: this is only safe when waiting for the result of a single
statement (not large blocks of code)."
(org-babel-comint-in-buffer buffer
(while (progn
(goto-char comint-last-input-end)
(not (and (re-search-forward comint-prompt-regexp nil t)
(goto-char (match-beginning 0)))))
(accept-process-output (get-buffer-process buffer)))))
(let ((start-time (current-time)))
(while (progn
(goto-char comint-last-input-end)
(not (and (re-search-forward comint-prompt-regexp nil t)
(goto-char (match-beginning 0)))))
(accept-process-output
(get-buffer-process buffer)
org-babel-comint-fallback-regexp-threshold)
(when (and org-babel-comint-prompt-regexp-old
(> (float-time (time-since start-time))
org-babel-comint-fallback-regexp-threshold)
(progn
(goto-char comint-last-input-end)
(save-excursion
(re-search-forward
org-babel-comint-prompt-regexp-old nil t))))
(org-babel-comint--set-fallback-prompt))))))
(defun org-babel-comint-eval-invisibly-and-wait-for-file
(buffer file string &optional period)
@ -192,8 +239,8 @@ comint process. It should return a string that will be passed
to `org-babel-insert-result'.")
(defvar-local org-babel-comint-async-dangling nil
"Dangling piece of the last process output, in case
`org-babel-comint-async-indicator' is spread across multiple
"Dangling piece of the last process output, as a string.
Used when `org-babel-comint-async-indicator' is spread across multiple
comint outputs due to buffering.")
(defun org-babel-comint-use-async (params)
@ -221,6 +268,8 @@ STRING contains the output originally inserted into the comint buffer."
(file-callback org-babel-comint-async-file-callback)
(combined-string (concat org-babel-comint-async-dangling string))
(new-dangling combined-string)
;; Assumes comint filter called with session buffer current
(session-dir default-directory)
;; list of UUID's matched by `org-babel-comint-async-indicator'
uuid-list)
(with-temp-buffer
@ -245,7 +294,8 @@ STRING contains the output originally inserted into the comint buffer."
(let* ((info (org-babel-get-src-block-info))
(params (nth 2 info))
(result-params
(cdr (assq :result-params params))))
(cdr (assq :result-params params)))
(default-directory session-dir))
(org-babel-insert-result
(funcall file-callback
(nth
@ -268,16 +318,17 @@ STRING contains the output originally inserted into the comint buffer."
(res-str-raw
(buffer-substring
;; move point to beginning of indicator
(- (match-beginning 0) 1)
(match-beginning 0)
;; find the matching start indicator
(cl-loop
do (re-search-backward indicator)
until (and (equal (match-string 1) "start")
(equal (match-string 2) uuid))
finally return (+ 1 (match-end 0)))))
;; Apply callback to clean up the result
(res-str (funcall org-babel-comint-async-chunk-callback
res-str-raw)))
;; Remove prompt
(res-promptless (org-trim (string-join (mapcar #'org-trim (org-babel-comint--prompt-filter res-str-raw)) "\n") "\n"))
;; Apply user callback
(res-str (funcall org-babel-comint-async-chunk-callback res-promptless)))
;; Search for uuid in associated org-buffers to insert results
(cl-loop for buf in org-buffers
until (with-current-buffer buf
@ -288,7 +339,8 @@ STRING contains the output originally inserted into the comint buffer."
(let* ((info (org-babel-get-src-block-info))
(params (nth 2 info))
(result-params
(cdr (assq :result-params params))))
(cdr (assq :result-params params)))
(default-directory session-dir))
(org-babel-insert-result
res-str result-params info))
t))))

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
;;; ob-css.el --- Babel Functions for CSS -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
@ -36,7 +36,7 @@
(defvar org-babel-default-header-args:css '())
(defun org-babel-execute:css (body _params)
"Execute a block of CSS code.
"Execute BODY of CSS code.
This function is called by `org-babel-execute-src-block'."
body)

View File

@ -1,6 +1,6 @@
;;; ob-ditaa.el --- Babel Functions for ditaa -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
@ -83,11 +83,11 @@ Do not leave leading or trailing spaces in this string."
:type 'string)
(defun org-babel-execute:ditaa (body params)
"Execute a block of Ditaa code with org-babel.
"Execute BODY of Ditaa code with org-babel according to PARAMS.
This function is called by `org-babel-execute-src-block'."
(let* ((out-file (or (cdr (assq :file params))
(error
"ditaa code block requires :file header argument")))
"Ditaa code block requires :file header argument")))
(cmdline (cdr (assq :cmdline params)))
(java (cdr (assq :java params)))
(in-file (org-babel-temp-file "ditaa-"))

View File

@ -1,6 +1,6 @@
;;; ob-dot.el --- Babel Functions for dot -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Maintainer: Justin Abrahms <justin@abrah.ms>
@ -51,7 +51,9 @@
(defun org-babel-expand-body:dot (body params)
"Expand BODY according to PARAMS, return the expanded body."
(let ((vars (org-babel--get-vars params)))
(let ((vars (org-babel--get-vars params))
(prologue (cdr (assq :prologue params)))
(epilogue (cdr (assq :epilogue params))))
(mapc
(lambda (pair)
(let ((name (symbol-name (car pair)))
@ -64,10 +66,13 @@
t
t))))
vars)
body))
(concat
(and prologue (concat prologue "\n"))
body
(and epilogue (concat "\n" epilogue "\n")))))
(defun org-babel-execute:dot (body params)
"Execute a block of Dot code with org-babel.
"Execute Dot BODY with org-babel according to PARAMS.
This function is called by `org-babel-execute-src-block'."
(let* ((out-file (cdr (or (assq :file params)
(error "You need to specify a :file parameter"))))

View File

@ -1,6 +1,6 @@
;;; ob-emacs-lisp.el --- Babel Functions for Emacs-lisp Code -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
@ -53,18 +53,23 @@ by `org-edit-src-code'.")
"Expand BODY according to PARAMS, return the expanded body."
(let ((vars (org-babel--get-vars params))
(print-level nil)
(print-length nil))
(print-length nil)
(prologue (cdr (assq :prologue params)))
(epilogue (cdr (assq :epilogue params))))
(if (null vars) (concat body "\n")
(format "(let (%s)\n%s\n)"
(format "(let (%s)\n%s%s%s\n)"
(mapconcat
(lambda (var)
(format "%S" `(,(car var) ',(cdr var))))
vars "\n ")
body))))
(if prologue (concat prologue "\n ") "")
body
(if epilogue (concat "\n " epilogue "\n") "")))))
(defun org-babel-execute:emacs-lisp (body params)
"Execute a block of emacs-lisp code with Babel."
"Execute emacs-lisp code BODY according to PARAMS."
(let* ((lexical (cdr (assq :lexical params)))
(session (cdr (assq :session params)))
(result-params (cdr (assq :result-params params)))
(body (format (if (member "output" result-params)
"(with-output-to-string %s\n)"
@ -75,6 +80,8 @@ by `org-edit-src-code'.")
(concat "(pp " body ")")
body))
(org-babel-emacs-lisp-lexical lexical))))
(when (and session (not (equal session "none")))
(error "ob-emacs-lisp backend does not support sessions"))
(org-babel-result-cond result-params
(let ((print-level nil)
(print-length nil))
@ -100,12 +107,17 @@ and the LEXICAL argument to `eval'."
(defun org-babel-edit-prep:emacs-lisp (info)
"Set `lexical-binding' in Org edit buffer.
Set `lexical-binding' in Org edit buffer according to the
corresponding :lexical source block argument."
corresponding :lexical source block argument provide in the INFO
channel, as returned by `org-babel-get-src-block-info'."
(setq lexical-binding
(org-babel-emacs-lisp-lexical
(org-babel-read
(cdr (assq :lexical (nth 2 info)))))))
(defun org-babel-prep-session:emacs-lisp (_session _params)
"Return an error because we do not support sessions."
(error "ob-emacs-lisp backend does not support sessions"))
(org-babel-make-language-alias "elisp" "emacs-lisp")
(provide 'ob-emacs-lisp)

View File

@ -1,6 +1,6 @@
;;; ob-eshell.el --- Babel Functions for Eshell -*- lexical-binding: t; -*-
;; Copyright (C) 2018-2023 Free Software Foundation, Inc.
;; Copyright (C) 2018-2024 Free Software Foundation, Inc.
;; Author: stardiviner <numbchild@gmail.com>
;; Maintainer: stardiviner <numbchild@gmail.com>
@ -94,10 +94,11 @@ The PARAMS are variables assignments."
session))
(defun org-babel-variable-assignments:eshell (params)
"Convert ob-eshell :var specified variables into Eshell variables assignments."
"Convert ob-eshell variables from PARAMS into Eshell variables assignments."
(mapcar
(lambda (pair)
(format "(setq %s %S)" (car pair) (cdr pair)))
;; Use `ignore' to suppress value in the command output.
(format "(ignore (setq %s %S))" (car pair) (cdr pair)))
(org-babel--get-vars params)))
(defun org-babel-load-session:eshell (session body params)

View File

@ -1,6 +1,6 @@
;;; ob-eval.el --- Babel Functions for External Code Evaluation -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research, comint
@ -37,16 +37,21 @@
(declare-function org-babel-temp-file "ob-core" (prefix &optional suffix))
(defun org-babel-eval-error-notify (exit-code stderr)
"Open a buffer to display STDERR and a message with the value of EXIT-CODE."
"Open a buffer to display STDERR and a message with the value of EXIT-CODE.
If EXIT-CODE is nil, display the message without a code."
(let ((buf (get-buffer-create org-babel-error-buffer-name)))
(with-current-buffer buf
(goto-char (point-max))
(save-excursion
(unless (bolp) (insert "\n"))
(insert stderr)
(insert (format "[ Babel evaluation exited with code %S ]" exit-code))))
(if exit-code
(insert (format "[ Babel evaluation exited with code %S ]" exit-code))
(insert "[ Babel evaluation exited abnormally ]"))))
(display-buffer buf))
(message "Babel evaluation exited with code %S" exit-code))
(if exit-code
(message "Babel evaluation exited with code %S" exit-code)
(message "Babel evaluation exited abnormally")))
(defun org-babel-eval (command query)
"Run COMMAND on QUERY.
@ -59,6 +64,7 @@ Writes QUERY into a temp-buffer that is processed with
(let ((error-buffer (get-buffer-create " *Org-Babel Error*")) exit-code)
(with-current-buffer error-buffer (erase-buffer))
(with-temp-buffer
;; Ensure trailing newline. It is required for cmdproxy.exe.
(insert query "\n")
(setq exit-code
(org-babel--shell-command-on-region
@ -100,11 +106,6 @@ returned."
(error-file (if error-buffer (org-babel-temp-file "ob-error-") nil))
(shell-file-name (org-babel--get-shell-file-name))
exit-status)
;; There is an error in `process-file' when `error-file' exists.
;; This is fixed in Emacs trunk as of 2012-12-21; let's use this
;; workaround for now.
(unless (file-remote-p default-directory)
(delete-file error-file))
;; we always call this with 'replace, remove conditional
;; Replace specified region with output from command.
(org-babel--write-temp-buffer-input-file input-file)

View File

@ -1,6 +1,6 @@
;;; ob-exp.el --- Exportation of Babel Source Blocks -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Authors: Eric Schulte
;; Dan Davison
@ -32,8 +32,10 @@
(declare-function org-babel-lob-get-info "ob-lob" (&optional datum no-eval))
(declare-function org-element-at-point "org-element" (&optional pom cached-only))
(declare-function org-element-context "org-element" (&optional element))
(declare-function org-element-property "org-element" (property element))
(declare-function org-element-type "org-element" (element))
(declare-function org-element-property "org-element-ast" (property node))
(declare-function org-element-begin "org-element" (node))
(declare-function org-element-end "org-element" (node))
(declare-function org-element-type "org-element-ast" (node &optional anonymous))
(declare-function org-escape-code-in-string "org-src" (s))
(declare-function org-export-copy-buffer "ox"
(&optional buffer drop-visibility
@ -41,8 +43,7 @@
drop-locals))
(declare-function org-in-commented-heading-p "org" (&optional no-inheritance element))
(declare-function org-in-archived-heading-p "org" (&optional no-inheritance element))
(defvar org-src-preserve-indentation)
(declare-function org-src-preserve-indentation-p "org-src" (node))
(defcustom org-export-use-babel t
"Switch controlling code evaluation and header processing during export.
@ -140,214 +141,230 @@ this template."
"Execute all Babel blocks in current buffer."
(interactive)
(when org-export-use-babel
(save-window-excursion
(let ((case-fold-search t)
(regexp "\\(call\\|src\\)_\\|^[ \t]*#\\+\\(BEGIN_SRC\\|CALL:\\)")
;; Get a pristine copy of current buffer so Babel
;; references are properly resolved and source block
;; context is preserved.
(org-babel-exp-reference-buffer (org-export-copy-buffer))
element)
(unwind-protect
(save-excursion
;; First attach to every source block their original
;; position, so that they can be retrieved within
;; `org-babel-exp-reference-buffer', even after heavy
;; modifications on current buffer.
;;
;; False positives are harmless, so we don't check if
;; we're really at some Babel object. Moreover,
;; `line-end-position' ensures that we propertize
;; a noticeable part of the object, without affecting
;; multiple objects on the same line.
(goto-char (point-min))
(let ((case-fold-search t)
(regexp "\\(call\\|src\\)_\\|^[ \t]*#\\+\\(BEGIN_SRC\\|CALL:\\)")
;; Get a pristine copy of current buffer so Babel
;; references are properly resolved and source block
;; context is preserved.
(org-babel-exp-reference-buffer (org-export-copy-buffer))
element)
(unwind-protect
(save-excursion
;; First attach to every source block their original
;; position, so that they can be retrieved within
;; `org-babel-exp-reference-buffer', even after heavy
;; modifications on current buffer.
;;
;; False positives are harmless, so we don't check if
;; we're really at some Babel object. Moreover,
;; `line-end-position' ensures that we propertize
;; a noticeable part of the object, without affecting
;; multiple objects on the same line.
(goto-char (point-min))
(while (re-search-forward regexp nil t)
(let ((s (match-beginning 0)))
(put-text-property s (line-end-position) 'org-reference s)))
;; Evaluate from top to bottom every Babel block
;; encountered.
(goto-char (point-min))
;; We are about to do a large number of changes in
;; buffer, but we do not care about folding in this
;; buffer.
(org-fold-core-ignore-modifications
(while (re-search-forward regexp nil t)
(let ((s (match-beginning 0)))
(put-text-property s (line-end-position) 'org-reference s)))
;; Evaluate from top to bottom every Babel block
;; encountered.
(goto-char (point-min))
;; We are about to do a large number of changes in
;; buffer, but we do not care about folding in this
;; buffer.
(org-fold-core-ignore-modifications
(while (re-search-forward regexp nil t)
(setq element (org-element-at-point))
(unless (save-match-data
(or (org-in-commented-heading-p nil element)
(org-in-archived-heading-p nil element)))
(let* ((object? (match-end 1))
(element (save-match-data
(if object?
(org-element-context element)
;; No deep inspection if we're
;; just looking for an element.
element)))
(type
(pcase (org-element-type element)
;; Discard block elements if we're looking
;; for inline objects. False results
;; happen when, e.g., "call_" syntax is
;; located within affiliated keywords:
;;
;; #+name: call_src
;; #+begin_src ...
((and (or `babel-call `src-block) (guard object?))
nil)
(type type)))
(begin
(copy-marker (org-element-property :begin element)))
(end
(copy-marker
(save-excursion
(goto-char (org-element-property :end element))
(skip-chars-backward " \r\t\n")
(point)))))
(pcase type
(`inline-src-block
(let* ((info
(org-babel-get-src-block-info nil element))
(params (nth 2 info)))
(setf (nth 1 info)
(if (and (cdr (assq :noweb params))
(string= "yes"
(cdr (assq :noweb params))))
(org-babel-expand-noweb-references
info org-babel-exp-reference-buffer)
(nth 1 info)))
(goto-char begin)
(let ((replacement
(org-babel-exp-do-export info 'inline)))
(if (equal replacement "")
;; Replacement code is empty: remove
;; inline source block, including extra
;; white space that might have been
;; created when inserting results.
(delete-region begin
(progn (goto-char end)
(skip-chars-forward " \t")
(point)))
;; Otherwise: remove inline source block
;; but preserve following white spaces.
;; Then insert value.
(unless (string= replacement
(buffer-substring begin end))
(delete-region begin end)
(insert replacement))))))
((or `babel-call `inline-babel-call)
(org-babel-exp-do-export
(or (org-babel-lob-get-info element)
(user-error "Unknown Babel reference: %s"
(org-element-property :call element)))
'lob)
(let ((rep
(org-fill-template
org-babel-exp-call-line-template
`(("line" .
,(org-element-property :value element))))))
;; If replacement is empty, completely remove
;; the object/element, including any extra
;; white space that might have been created
;; when including results.
(if (equal rep "")
(delete-region
begin
(progn (goto-char end)
(if (not (eq type 'babel-call))
(progn (skip-chars-forward " \t")
(point))
(skip-chars-forward " \r\t\n")
(line-beginning-position))))
;; Otherwise, preserve trailing
;; spaces/newlines and then, insert
;; replacement string.
(goto-char begin)
(setq element (save-match-data (org-element-at-point)))
(unless (save-match-data
(or (org-in-commented-heading-p nil element)
(org-in-archived-heading-p nil element)))
(let* ((object? (match-end 1))
(element (save-match-data
(if object?
(org-element-context element)
;; No deep inspection if we're
;; just looking for an element.
element)))
(type
(pcase (org-element-type element)
;; Discard block elements if we're looking
;; for inline objects. False results
;; happen when, e.g., "call_" syntax is
;; located within affiliated keywords:
;;
;; #+name: call_src
;; #+begin_src ...
((and (or `babel-call `src-block) (guard object?))
nil)
(type type)))
(begin
(copy-marker (org-element-begin element)))
(end
(copy-marker
(save-excursion
(goto-char (org-element-end element))
(skip-chars-backward " \r\t\n")
(point)))))
(pcase type
(`inline-src-block
(let* ((info
(org-babel-get-src-block-info nil element))
(params (nth 2 info)))
(setf (nth 1 info)
(if (and (cdr (assq :noweb params))
(string= "yes"
(cdr (assq :noweb params))))
(org-babel-expand-noweb-references
info org-babel-exp-reference-buffer)
(nth 1 info)))
(goto-char begin)
(let ((replacement
(org-babel-exp-do-export info 'inline)))
(cond
((equal replacement "")
;; Replacement code is empty: remove
;; inline source block, including extra
;; white space that might have been
;; created when inserting results.
(delete-region begin
(progn (goto-char end)
(skip-chars-forward " \t")
(point))))
((not replacement)
;; Replacement code cannot be determined.
;; Leave the code block as is.
(goto-char end))
;; Otherwise: remove inline source block
;; but preserve following white spaces.
;; Then insert value.
((not (string= replacement
(buffer-substring begin end)))
(delete-region begin end)
(insert rep))))
(`src-block
(let ((match-start (copy-marker (match-beginning 0)))
(ind (org-current-text-indentation)))
;; Take care of matched block: compute
;; replacement string. In particular, a nil
;; REPLACEMENT means the block is left as-is
;; while an empty string removes the block.
(let ((replacement
(progn (goto-char match-start)
(org-babel-exp-src-block element))))
(cond ((not replacement) (goto-char end))
((equal replacement "")
(goto-char end)
(skip-chars-forward " \r\t\n")
(beginning-of-line)
(delete-region begin (point)))
(t
(if (or org-src-preserve-indentation
(org-element-property
:preserve-indent element))
;; Indent only code block
;; markers.
(with-temp-buffer
;; Do not use tabs for block
;; indentation.
(when (fboundp 'indent-tabs-mode)
(indent-tabs-mode -1)
;; FIXME: Emacs 26
;; compatibility.
(setq-local indent-tabs-mode nil))
(insert replacement)
(skip-chars-backward " \r\t\n")
(indent-line-to ind)
(goto-char 1)
(indent-line-to ind)
(setq replacement (buffer-string)))
;; Indent everything.
(with-temp-buffer
;; Do not use tabs for block
;; indentation.
(when (fboundp 'indent-tabs-mode)
(indent-tabs-mode -1)
;; FIXME: Emacs 26
;; compatibility.
(setq-local indent-tabs-mode nil))
(insert replacement)
(indent-rigidly
1 (point) ind)
(setq replacement (buffer-string))))
(goto-char match-start)
(let ((rend (save-excursion
(goto-char end)
(line-end-position))))
(if (string-equal replacement
(buffer-substring match-start rend))
(goto-char rend)
(delete-region match-start
(save-excursion
(goto-char end)
(line-end-position)))
(insert replacement))))))
(set-marker match-start nil))))
(set-marker begin nil)
(set-marker end nil))))))
(kill-buffer org-babel-exp-reference-buffer)
(remove-text-properties (point-min) (point-max)
'(org-reference nil)))))))
(insert replacement))))))
((or `babel-call `inline-babel-call)
(org-babel-exp-do-export
(or (org-babel-lob-get-info element)
(user-error "Unknown Babel reference: %s"
(org-element-property :call element)))
'lob)
(let ((rep
(org-fill-template
org-babel-exp-call-line-template
`(("line" .
,(org-element-property :value element))))))
;; If replacement is empty, completely remove
;; the object/element, including any extra
;; white space that might have been created
;; when including results.
(cond
((equal rep "")
(delete-region
begin
(progn (goto-char end)
(if (not (eq type 'babel-call))
(progn (skip-chars-forward " \t")
(point))
(skip-chars-forward " \r\t\n")
(line-beginning-position)))))
((not rep)
;; Replacement code cannot be determined.
;; Leave the code block as is.
(goto-char end))
(t
;; Otherwise, preserve trailing
;; spaces/newlines and then, insert
;; replacement string.
(goto-char begin)
(delete-region begin end)
(insert rep)))))
(`src-block
(let ((match-start (copy-marker (match-beginning 0)))
(ind (org-current-text-indentation)))
;; Take care of matched block: compute
;; replacement string. In particular, a nil
;; REPLACEMENT means the block is left as-is
;; while an empty string removes the block.
(let ((replacement
(progn (goto-char match-start)
(org-babel-exp-src-block element))))
(cond ((not replacement) (goto-char end))
((equal replacement "")
(goto-char end)
(skip-chars-forward " \r\t\n")
(forward-line 0)
(delete-region begin (point)))
(t
(if (org-src-preserve-indentation-p element)
;; Indent only code block
;; markers.
(with-temp-buffer
;; Do not use tabs for block
;; indentation.
(when (fboundp 'indent-tabs-mode)
(indent-tabs-mode -1)
;; FIXME: Emacs 26
;; compatibility.
(setq-local indent-tabs-mode nil))
(insert replacement)
(skip-chars-backward " \r\t\n")
(indent-line-to ind)
(goto-char 1)
(indent-line-to ind)
(setq replacement (buffer-string)))
;; Indent everything.
(with-temp-buffer
;; Do not use tabs for block
;; indentation.
(when (fboundp 'indent-tabs-mode)
(indent-tabs-mode -1)
;; FIXME: Emacs 26
;; compatibility.
(setq-local indent-tabs-mode nil))
(insert replacement)
(indent-rigidly
1 (point) ind)
(setq replacement (buffer-string))))
(goto-char match-start)
(let ((rend (save-excursion
(goto-char end)
(line-end-position))))
(if (string-equal replacement
(buffer-substring match-start rend))
(goto-char rend)
(delete-region match-start
(save-excursion
(goto-char end)
(line-end-position)))
(insert replacement))))))
(set-marker match-start nil))))
(set-marker begin nil)
(set-marker end nil))))))
(kill-buffer org-babel-exp-reference-buffer)
(remove-text-properties (point-min) (point-max)
'(org-reference nil))))))
(defun org-babel-exp-do-export (info type &optional hash)
"Return a string with the exported content of a code block.
"Return a string with the exported content of a code block defined by INFO.
TYPE is the code block type: `block', `inline', or `lob'. HASH is the
result hash.
Return nil when exported content cannot be determined.
The function respects the value of the :exports header argument."
(let ((silently (lambda () (let ((session (cdr (assq :session (nth 2 info)))))
(unless (equal "none" session)
(org-babel-exp-results info type 'silent)))))
(unless (equal "none" session)
(org-babel-exp-results info type 'silent)))))
(clean (lambda () (if (eq type 'inline)
(org-babel-remove-inline-result)
(org-babel-remove-result info)))))
(org-babel-remove-inline-result)
(org-babel-remove-result info)))))
(pcase (or (cdr (assq :exports (nth 2 info))) "code")
("none" (funcall silently) (funcall clean) "")
("code" (funcall silently) (funcall clean) (org-babel-exp-code info type))
("results" (org-babel-exp-results info type nil hash) "")
("both"
(org-babel-exp-results info type nil hash)
(org-babel-exp-code info type)))))
(org-babel-exp-code info type))
(unknown-value
(warn "Unknown value of src block parameter :exports %S" unknown-value)
nil))))
(defcustom org-babel-exp-code-template
"#+begin_src %lang%switches%flags\n%body\n#+end_src"
@ -393,7 +410,7 @@ replaced with its value."
:package-version '(Org . "8.3"))
(defun org-babel-exp-code (info type)
"Return the original code block formatted for export."
"Return the original code block of TYPE defined by INFO, formatted for export."
(setf (nth 1 info)
(if (string= "strip-export" (cdr (assq :noweb (nth 2 info))))
(replace-regexp-in-string
@ -423,6 +440,9 @@ replaced with its value."
(defun org-babel-exp-results (info type &optional silent hash)
"Evaluate and return the results of the current code block for export.
INFO is as returned by `org-babel-get-src-block-info'. TYPE is the
code block type. HASH is the result hash.
Results are prepared in a manner suitable for export by Org mode.
This function is called by `org-babel-exp-do-export'. The code
block will be evaluated. Optional argument SILENT can be used to
@ -436,7 +456,8 @@ inhibit insertion of results into the buffer."
(info (copy-sequence info))
(org-babel-current-src-block-location (point-marker)))
;; Skip code blocks which we can't evaluate.
(when (fboundp (intern (concat "org-babel-execute:" lang)))
(if (not (fboundp (intern (concat "org-babel-execute:" lang))))
(warn "org-export: No org-babel-execute function for %s. Not updating exported results." lang)
(org-babel-eval-wipe-error-buffer)
(setf (nth 1 info) body)
(setf (nth 2 info)

View File

@ -1,6 +1,6 @@
;;; ob-forth.el --- Babel Functions for Forth -*- lexical-binding: t; -*-
;; Copyright (C) 2014-2023 Free Software Foundation, Inc.
;; Copyright (C) 2014-2024 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research, forth
@ -45,7 +45,7 @@
"Default header arguments for forth code blocks.")
(defun org-babel-execute:forth (body params)
"Execute a block of Forth code with org-babel.
"Execute Forth BODY according to PARAMS.
This function is called by `org-babel-execute-src-block'."
(if (string= "none" (cdr (assq :session params)))
(error "Non-session evaluation not supported for Forth code blocks")
@ -55,7 +55,8 @@ This function is called by `org-babel-execute-src-block'."
(car (last all-results))))))
(defun org-babel-forth-session-execute (body params)
(require 'forth-mode)
"Execute Forth BODY in session defined via PARAMS."
(org-require-package 'forth-mode)
(let ((proc (forth-proc))
(rx " \\(\n:\\|compiled\n\\|ok\n\\)")
(result-start))

View File

@ -1,6 +1,6 @@
;;; ob-fortran.el --- Babel Functions for Fortran -*- lexical-binding: t; -*-
;; Copyright (C) 2011-2023 Free Software Foundation, Inc.
;; Copyright (C) 2011-2024 Free Software Foundation, Inc.
;; Authors: Sergey Litvinov
;; Eric Schulte
@ -51,7 +51,8 @@
:type 'string)
(defun org-babel-execute:fortran (body params)
"This function should only be called by `org-babel-execute:fortran'."
"Execute Fortran BODY according to PARAMS.
This function is called by `org-babel-execute-src-block'."
(let* ((tmp-src-file (org-babel-temp-file "fortran-src-" ".F90"))
(tmp-bin-file (org-babel-temp-file "fortran-bin-" org-babel-exeext))
(cmdline (cdr (assq :cmdline params)))
@ -82,9 +83,10 @@
(cdr (assq :rowname-names params)) (cdr (assq :rownames params)))))))
(defun org-babel-expand-body:fortran (body params)
"Expand a block of fortran or fortran code with org-babel according to
its header arguments."
"Expand a fortran BODY according to its header arguments defined in PARAMS."
(let ((vars (org-babel--get-vars params))
(prologue (cdr (assq :prologue params)))
(epilogue (cdr (assq :epilogue params)))
(main-p (not (string= (cdr (assq :main params)) "no")))
(includes (or (cdr (assq :includes params))
(org-babel-read (org-entry-get nil "includes" t))))
@ -107,12 +109,20 @@ its header arguments."
(concat
;; variables
(mapconcat 'org-babel-fortran-var-to-fortran vars "\n")
body)
(and prologue (concat prologue "\n"))
body
(and prologue (concat prologue "\n")))
params)
body) "\n") "\n")))
(concat
(and prologue (concat prologue "\n"))
body
(and epilogue (concat "\n" epilogue "\n"))))
"\n")
"\n")))
(defun org-babel-fortran-ensure-main-wrap (body params)
"Wrap body in a \"program ... end program\" block if none exists."
"Wrap BODY in a \"program ... end program\" block if none exists.
Variable assignments are derived from PARAMS."
(if (string-match "^[ \t]*program\\>" (capitalize body))
(let ((vars (org-babel--get-vars params)))
(when vars (error "Cannot use :vars if `program' statement is present"))
@ -120,20 +130,22 @@ its header arguments."
(format "program main\n%s\nend program main\n" body)))
(defun org-babel-prep-session:fortran (_session _params)
"This function does nothing as fortran is a compiled language with no
"Do nothing.
This function does nothing as fortran is a compiled language with no
support for sessions."
(error "Fortran is a compiled languages -- no support for sessions"))
(defun org-babel-load-session:fortran (_session _body _params)
"This function does nothing as fortran is a compiled language with no
"Do nothing.
This function does nothing as fortran is a compiled language with no
support for sessions."
(error "Fortran is a compiled languages -- no support for sessions"))
;; helper functions
(defun org-babel-fortran-var-to-fortran (pair)
"Convert an elisp val into a string of fortran code specifying a var
of the same value."
"Convert PAIR of (VAR . VAL) into a string of fortran code.
The fortran code will assign VAL to VAR variable."
;; TODO list support
(let ((var (car pair))
(val (cdr pair)))
@ -164,7 +176,7 @@ of the same value."
(error "The type of parameter %s is not supported by ob-fortran" var)))))
(defun org-babel-fortran-transform-list (val)
"Return a fortran representation of enclose syntactic lists."
"Return a fortran representation of enclose syntactic list VAL."
(if (listp val)
(concat "(/" (mapconcat #'org-babel-fortran-transform-list val ", ") "/)")
(format "%S" val)))

View File

@ -1,9 +1,9 @@
;;; ob-gnuplot.el --- Babel Functions for Gnuplot -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Maintainer: Ihor Radchenko <yantar92@gmail.com>
;; Maintainer: Ihor Radchenko <yantar92 at posteo dot net>
;; Keywords: literate programming, reproducible research
;; URL: https://orgmode.org
@ -45,6 +45,7 @@
(require 'ob)
(require 'org-macs)
(require 'ox-ascii)
(declare-function org-time-string-to-time "org" (s))
(declare-function orgtbl-to-generic "org-table" (table params))
@ -186,7 +187,7 @@ code."
;; value of the variable
(mapc (lambda (pair)
(setq body (replace-regexp-in-string
(format "\\$%s" (car pair)) (cdr pair) body)))
(format "\\$%s" (car pair)) (cdr pair) body t t)))
vars)
(when prologue (funcall add-to-body prologue))
(when epilogue (setq body (concat body "\n" epilogue)))
@ -196,9 +197,9 @@ code."
body))
(defun org-babel-execute:gnuplot (body params)
"Execute a block of Gnuplot code.
"Execute Gnuplot BODY according to PARAMS.
This function is called by `org-babel-execute-src-block'."
(require 'gnuplot)
(org-require-package 'gnuplot)
(let ((session (cdr (assq :session params)))
(result-type (cdr (assq :results params)))
(body (org-babel-expand-body:gnuplot body params))
@ -251,7 +252,8 @@ This function is called by `org-babel-execute-src-block'."
buffer)))
(defun org-babel-variable-assignments:gnuplot (params)
"Return list of gnuplot statements assigning the block's variables."
"Return list of gnuplot statements assigning the block's variables.
PARAMS is src block parameters alist defining variable assignments."
(mapcar
(lambda (pair) (format "%s = \"%s\"" (car pair) (cdr pair)))
(org-babel-gnuplot-process-vars params)))
@ -262,7 +264,7 @@ This function is called by `org-babel-execute-src-block'."
If there is not a current inferior-process-buffer in SESSION
then create one. Return the initialized session. The current
`gnuplot-mode' doesn't provide support for multiple sessions."
(require 'gnuplot)
(org-require-package 'gnuplot)
(unless (string= session "none")
(save-window-excursion
(gnuplot-send-string-to-gnuplot "" "line")
@ -295,14 +297,29 @@ Pass PARAMS through to `orgtbl-to-generic' when exporting TABLE."
(require 'ox-org)
(with-temp-file data-file
(insert (let ((org-babel-gnuplot-timestamp-fmt
(or (plist-get params :timefmt) "%Y-%m-%d-%H:%M:%S")))
(or (plist-get params :timefmt) "%Y-%m-%d-%H:%M:%S"))
;; Create custom limited backend that will disable
;; advanced ASCII export features that may alter the
;; original data.
(ob-gnuplot-data
(org-export-create-backend
:parent 'ascii
:transcoders
`(;; Do not try to resolve links. Export them verbatim.
(link . (lambda (link _ _) (org-element-interpret-data link)))
;; Drop emphasis markers from verbatim and code.
;; This way, data can use verbatim when escaping
;; is necessary and yet be readable by Gnuplot,
;; which is not aware about Org's markup.
(verbatim . (lambda (verbatim _ _) (org-element-property :value verbatim)))
(code . (lambda (code _ _) (org-element-property :value code)))))))
(orgtbl-to-generic
table
(org-combine-plists
'( :sep "\t" :fmt org-babel-gnuplot-quote-tsv-field
`( :sep "\t" :fmt org-babel-gnuplot-quote-tsv-field
;; Two setting below are needed to make :fmt work.
:raw t
:backend ascii)
:backend ,ob-gnuplot-data)
params)))))
data-file)

View File

@ -1,6 +1,6 @@
;;; ob-groovy.el --- Babel Functions for Groovy -*- lexical-binding: t; -*-
;; Copyright (C) 2013-2023 Free Software Foundation, Inc.
;; Copyright (C) 2013-2024 Free Software Foundation, Inc.
;; Author: Miro Bezjak <bezjak.miro@gmail.com>
;; Maintainer: Palak Mathur <palakmathur@gmail.com>
@ -50,7 +50,7 @@ parameters may be used, like groovy -v"
:type 'string)
(defun org-babel-execute:groovy (body params)
"Execute a block of Groovy code with org-babel.
"Execute Groovy BODY according to PARAMS.
This function is called by `org-babel-execute-src-block'."
(message "Executing Groovy source code block")
(let* ((processed-params (org-babel-process-params params))
@ -81,6 +81,7 @@ println(new Runner().run())
(defun org-babel-groovy-evaluate
(session body &optional result-type result-params)
"Evaluate BODY in external Groovy process.
SESSION must be nil as sessions are not yet supported.
If RESULT-TYPE equals `output' then return standard output as a string.
If RESULT-TYPE equals `value' then return the value of the last statement
in BODY as elisp."
@ -107,9 +108,8 @@ in BODY as elisp."
(error "Sessions are not (yet) supported for Groovy"))
(defun org-babel-groovy-initiate-session (&optional _session)
"If there is not a current inferior-process-buffer in SESSION
then create. Return the initialized session. Sessions are not
supported in Groovy."
"Do nothing.
Sessions are not supported in Groovy."
nil)
(provide 'ob-groovy)

View File

@ -1,6 +1,6 @@
;;; ob-haskell.el --- Babel Functions for Haskell -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Maintainer: Lawrence Bottorff <borgauf@gmail.com>
@ -61,7 +61,7 @@
(defvar org-babel-haskell-lhs2tex-command "lhs2tex")
(defvar org-babel-haskell-eoe "\"org-babel-haskell-eoe\"")
(defvar org-babel-haskell-eoe "org-babel-haskell-eoe")
(defvar haskell-prompt-regexp)
@ -77,8 +77,35 @@ a parameter, such as \"ghc -v\"."
(defconst org-babel-header-args:haskell '((compile . :any))
"Haskell-specific header arguments.")
(defun org-babel-haskell-with-session--worker (params todo)
"See `org-babel-haskell-with-session'."
(let* ((sn (cdr (assq :session params)))
(session (org-babel-haskell-initiate-session sn params))
(one-shot (equal sn "none")))
(unwind-protect
(funcall todo session)
(when (and one-shot (buffer-live-p session))
;; As we don't control how the session temporary buffer is
;; created, we need to explicitly work around the hooks and
;; query functions.
(with-current-buffer session
(let ((kill-buffer-query-functions nil)
(kill-buffer-hook nil))
(kill-buffer session)))))))
(defmacro org-babel-haskell-with-session (session-symbol params &rest body)
"Get the session identified by PARAMS and run BODY with it.
Get or create a session, as needed to match PARAMS. Assign the session to
SESSION-SYMBOL. Execute BODY. Destroy the session if needed.
Return the value of the last form of BODY."
(declare (indent 2) (debug (symbolp form body)))
`(org-babel-haskell-with-session--worker ,params (lambda (,session-symbol) ,@body)))
(defun org-babel-haskell-execute (body params)
"This function should only be called by `org-babel-execute:haskell'."
"Execute Haskell BODY according to PARAMS.
This function should only be called by `org-babel-execute:haskell'."
(let* ((tmp-src-file (org-babel-temp-file "Haskell-src-" ".hs"))
(tmp-bin-file
(org-babel-process-file-name
@ -122,39 +149,63 @@ a parameter, such as \"ghc -v\"."
(cdr (assq :rowname-names params)) (cdr (assq :rownames params))))))))
(defun org-babel-interpret-haskell (body params)
(require 'inf-haskell)
(org-require-package 'inf-haskell "haskell-mode")
(add-hook 'inferior-haskell-hook
(lambda ()
(setq-local comint-prompt-regexp
(concat haskell-prompt-regexp "\\|^λ?> "))))
(let* ((session (cdr (assq :session params)))
(result-type (cdr (assq :result-type params)))
(full-body (org-babel-expand-body:generic
body params
(org-babel-variable-assignments:haskell params)))
(session (org-babel-haskell-initiate-session session params))
(comint-preoutput-filter-functions
(cons 'ansi-color-filter-apply comint-preoutput-filter-functions))
(raw (org-babel-comint-with-output
(session org-babel-haskell-eoe nil full-body)
(insert (org-trim full-body))
(comint-send-input nil t)
(insert org-babel-haskell-eoe)
(comint-send-input nil t)))
(results (mapcar #'org-strip-quotes
(cdr (member org-babel-haskell-eoe
(reverse (mapcar #'org-trim raw)))))))
(org-babel-reassemble-table
(let ((result
(pcase result-type
(`output (mapconcat #'identity (reverse results) "\n"))
(`value (car results)))))
(org-babel-result-cond (cdr (assq :result-params params))
result (when result (org-babel-script-escape result))))
(org-babel-pick-name (cdr (assq :colname-names params))
(cdr (assq :colname-names params)))
(org-babel-pick-name (cdr (assq :rowname-names params))
(cdr (assq :rowname-names params))))))
(setq-local
org-babel-comint-prompt-regexp-old comint-prompt-regexp
comint-prompt-regexp
(concat haskell-prompt-regexp "\\|^λ?> "))))
(org-babel-haskell-with-session session params
(cl-labels
((send-txt-to-ghci (txt)
(insert txt) (comint-send-input nil t))
(send-eoe ()
(send-txt-to-ghci (concat "putStrLn \"" org-babel-haskell-eoe "\"\n")))
(comint-with-output (todo)
(let ((comint-preoutput-filter-functions
(cons 'ansi-color-filter-apply
comint-preoutput-filter-functions)))
(org-babel-comint-with-output
(session org-babel-haskell-eoe nil nil)
(funcall todo)))))
(let* ((result-type (cdr (assq :result-type params)))
(full-body (org-babel-expand-body:generic
body params
(org-babel-variable-assignments:haskell params)))
(raw (pcase result-type
(`output
(comint-with-output
(lambda () (send-txt-to-ghci (org-trim full-body)) (send-eoe))))
(`value
;; We first compute the value and store it,
;; ignoring any output.
(comint-with-output
(lambda ()
(send-txt-to-ghci "__LAST_VALUE_IMPROBABLE_NAME__=()::()\n")
(send-txt-to-ghci (org-trim full-body))
(send-txt-to-ghci "__LAST_VALUE_IMPROBABLE_NAME__=it\n")
(send-eoe)))
;; We now display and capture the value.
(comint-with-output
(lambda()
(send-txt-to-ghci "__LAST_VALUE_IMPROBABLE_NAME__\n")
(send-eoe))))))
(results (mapcar #'org-strip-quotes
(cdr (member org-babel-haskell-eoe
(reverse (mapcar #'org-trim raw)))))))
(org-babel-reassemble-table
(let ((result
(pcase result-type
(`output (mapconcat #'identity (reverse results) "\n"))
(`value (car results)))))
(org-babel-result-cond (cdr (assq :result-params params))
result (when result (org-babel-script-escape result))))
(org-babel-pick-name (cdr (assq :colname-names params))
(cdr (assq :colname-names params)))
(org-babel-pick-name (cdr (assq :rowname-names params))
(cdr (assq :rowname-names params))))))))
(defun org-babel-execute:haskell (body params)
"Execute a block of Haskell code."
@ -163,13 +214,65 @@ a parameter, such as \"ghc -v\"."
(org-babel-interpret-haskell body params)
(org-babel-haskell-execute body params))))
(defun org-babel-haskell-initiate-session (&optional _session _params)
;; Variable defined in inf-haskell (haskell-mode package).
(defvar inferior-haskell-buffer)
(defvar inferior-haskell-root-dir)
(defun org-babel-haskell-initiate-session (&optional session-name _params)
"Initiate a haskell session.
If there is not a current inferior-process-buffer in SESSION
then create one. Return the initialized session."
(require 'inf-haskell)
(or (get-buffer "*haskell*")
(save-window-excursion (run-haskell) (sleep-for 0.25) (current-buffer))))
Return the initialized session, i.e. the buffer for this session.
When SESSION-NAME is nil, use a global session named
\"*ob-haskell*\". When SESSION-NAME is the string \"none\", use
a temporary buffer. Else, (re)use the session named
SESSION-NAME. The buffer name is the session name. See also
`org-babel-haskell-with-session'."
(org-require-package 'inf-haskell "haskell-mode")
(cond
((equal "none" session-name)
;; Temporary buffer name.
(setq session-name (generate-new-buffer-name " *ob-haskell-tmp*")))
((eq nil session-name)
;; The global default session. As haskell-mode is using the buffer
;; named "*haskell*", we stay away from it.
(setq session-name "*ob-haskell*"))
((not (stringp session-name))
(error "session-name must be a string")))
(let ((session (get-buffer session-name)))
;; NOTE: By construction, as SESSION-NAME is a string, session is
;; either nil or a live buffer.
(save-window-excursion
(or (org-babel-comint-buffer-livep session)
(let ((inferior-haskell-buffer session))
;; As inferior-haskell expects the buffer to be named
;; "*haskell*", we temporarily rename it while executing
;; `run-haskell' (unless the user explicitly requested to
;; use the name "*haskell*").
(when (not (equal "*haskell*" session-name))
(when (bufferp session)
(when (bufferp "*haskell*")
(user-error "Conflicting buffer '*haskell*', rename it or kill it"))
(with-current-buffer session (rename-buffer "*haskell*"))))
(unwind-protect
(let ((inferior-haskell-root-dir default-directory))
(run-haskell)
(sleep-for 0.25)
(setq session inferior-haskell-buffer))
(when (and (not (equal "*haskell*" session-name))
(bufferp session))
(with-current-buffer session (rename-buffer session-name))))
;; Disable secondary prompt: If we do not do this,
;; org-comint may treat secondary prompts as a part of
;; output.
(org-babel-comint-input-command
session
":set prompt-cont \"\"")
session)
))
session))
(defun org-babel-load-session:haskell (session body params)
"Load BODY into SESSION."
@ -226,7 +329,7 @@ constructs (header arguments, no-web syntax etc...) are ignored."
(let* ((contents (buffer-string))
(haskell-regexp
(concat "^\\([ \t]*\\)#\\+begin_src[ \t]haskell*\\(.*\\)[\r\n]"
"\\([^\000]*?\\)[\r\n][ \t]*#\\+end_src.*"))
"\\(\\(?:.\\|\n\\)*?\\)[\r\n][ \t]*#\\+end_src.*"))
(base-name (file-name-sans-extension (buffer-file-name)))
(tmp-file (org-babel-temp-file "haskell-"))
(tmp-org-file (concat tmp-file ".org"))
@ -236,6 +339,7 @@ constructs (header arguments, no-web syntax etc...) are ignored."
(command (concat org-babel-haskell-lhs2tex-command
" " (org-babel-process-file-name lhs-file)
" > " (org-babel-process-file-name tex-file)))
;; FIXME: What if src block has :preserve-indentation flag?
(preserve-indentp org-src-preserve-indentation)
indentation)
;; escape haskell source-code blocks
@ -255,26 +359,27 @@ constructs (header arguments, no-web syntax etc...) are ignored."
t t)
(indent-code-rigidly (match-beginning 0) (match-end 0) indentation)))
(save-excursion
;; export to latex w/org and save as .lhs
(require 'ox-latex)
(find-file tmp-org-file)
;; Ensure we do not clutter kill ring with incomplete results.
(let (org-export-copy-to-kill-ring)
(org-export-to-file 'latex tmp-tex-file))
(kill-buffer nil)
(delete-file tmp-org-file)
(find-file tmp-tex-file)
(goto-char (point-min)) (forward-line 2)
(insert "%include polycode.fmt\n")
;; ensure all \begin/end{code} statements start at the first column
(while (re-search-forward "^[ \t]+\\\\begin{code}[^\000]+\\\\end{code}" nil t)
(replace-match (save-match-data (org-remove-indentation (match-string 0)))
t t))
(setq contents (buffer-string))
(save-buffer) (kill-buffer nil))
(delete-file tmp-tex-file)
;; save org exported latex to a .lhs file
(with-temp-file lhs-file (insert contents))
(unwind-protect
(with-temp-buffer
;; Export to latex w/org and save as .lhs
(require 'ox-latex)
(insert-file-contents tmp-org-file)
;; Ensure we do not clutter kill ring with incomplete results.
(let (org-export-copy-to-kill-ring)
(org-export-to-file 'latex tmp-tex-file)))
(delete-file tmp-org-file))
(unwind-protect
(with-temp-buffer
(insert-file-contents tmp-tex-file)
(goto-char (point-min)) (forward-line 2)
(insert "%include polycode.fmt\n")
;; ensure all \begin/end{code} statements start at the first column
(while (re-search-forward "^[ \t]+\\\\begin{code}\\(?:.\\|\n\\)+\\\\end{code}" nil t)
(replace-match (save-match-data (org-remove-indentation (match-string 0)))
t t))
;; save org exported latex to a .lhs file
(write-region nil nil lhs-file))
(delete-file tmp-tex-file)))
(if (not arg)
(find-file lhs-file)
;; process .lhs file with lhs2tex

View File

@ -1,6 +1,6 @@
;;; ob-java.el --- org-babel functions for java evaluation -*- lexical-binding: t -*-
;; Copyright (C) 2011-2023 Free Software Foundation, Inc.
;; Copyright (C) 2011-2024 Free Software Foundation, Inc.
;; Authors: Eric Schulte
;; Dan Davison
@ -341,9 +341,13 @@ is simplest to expand the code block from the inside out."
(imports-val (assq :imports params))
(imports (if imports-val
(split-string (org-babel-read (cdr imports-val) nil) " ")
nil)))
nil))
(prologue (cdr (assq :prologue params)))
(epilogue (cdr (assq :epilogue params))))
(with-temp-buffer
(when prologue (insert prologue "\n"))
(insert body)
(when epilogue (insert "\n" epilogue))
;; wrap main. If there are methods defined, but no main method
;; and no class, wrap everything in a generic main method.

View File

@ -1,6 +1,6 @@
;;; ob-js.el --- Babel Functions for Javascript -*- lexical-binding: t; -*-
;; Copyright (C) 2010-2023 Free Software Foundation, Inc.
;; Copyright (C) 2010-2024 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research, js
@ -76,7 +76,7 @@
"Javascript code to print value of body.")
(defun org-babel-execute:js (body params)
"Execute a block of Javascript code with org-babel.
"Execute Javascript BODY according to PARAMS.
This function is called by `org-babel-execute-src-block'."
(let* ((org-babel-js-cmd (or (cdr (assq :cmd params)) org-babel-js-cmd))
(session (cdr (assq :session params)))
@ -99,7 +99,7 @@ This function is called by `org-babel-execute-src-block'."
;; Indium Node REPL. Separate case because Indium
;; REPL is not inherited from Comint mode.
((string= session "*JS REPL*")
(require 'indium-repl)
(org-require-package 'indium-repl "indium")
(unless (get-buffer session)
(indium-run-node org-babel-js-cmd))
(indium-eval full-body))
@ -158,7 +158,8 @@ specifying a variable of the same value."
session))
(defun org-babel-variable-assignments:js (params)
"Return list of Javascript statements assigning the block's variables."
"Return list of Javascript statements assigning the block's variables.
The variables are defined in PARAMS."
(mapcar
(lambda (pair) (format "var %s=%s;"
(car pair) (org-babel-js-var-to-js (cdr pair))))
@ -171,7 +172,7 @@ Return the initialized session."
((string= session "none")
(warn "Session evaluation of ob-js is not supported"))
((string= "*skewer-repl*" session)
(require 'skewer-repl)
(org-require-package 'skewer-repl "skewer-mode")
(let ((session-buffer (get-buffer "*skewer-repl*")))
(if (and session-buffer
(org-babel-comint-buffer-livep (get-buffer session-buffer))
@ -183,7 +184,7 @@ Return the initialized session."
(skewer-repl)
session-buffer)))
((string= "*Javascript REPL*" session)
(require 'js-comint)
(org-require-package 'js-comint)
(let ((session-buffer "*Javascript REPL*"))
(if (and (org-babel-comint-buffer-livep (get-buffer session-buffer))
(comint-check-proc session-buffer))
@ -192,7 +193,9 @@ Return the initialized session."
(sit-for .5)
session-buffer)))
((string= "mozrepl" org-babel-js-cmd)
(require 'moz)
;; FIXME: According to https://github.com/bard/mozrepl, this REPL
;; is outdated and does not work for Firefox >54.
(org-require-package 'moz "mozrepl")
(let ((session-buffer (save-window-excursion
(run-mozilla nil)
(rename-buffer session)

View File

@ -1,6 +1,6 @@
;;; ob-julia.el --- org-babel functions for julia code evaluation -*- lexical-binding: t; -*-
;; Copyright (C) 2013-2023 Free Software Foundation, Inc.
;; Copyright (C) 2013-2024 Free Software Foundation, Inc.
;; Authors: G. Jay Kerns
;; Maintainer: Pedro Bruel <pedro.bruel@gmail.com>
;; Keywords: literate programming, reproducible research, scientific computing
@ -70,12 +70,15 @@
(defvar ess-local-process-name) ; dynamically scoped
(defvar ess-eval-visibly-p) ; dynamically scoped
(defvar ess-local-customize-alist); dynamically scoped
(defun org-babel-edit-prep:julia (info)
(let ((session (cdr (assq :session (nth 2 info)))))
(when (and session
(string-prefix-p "*" session)
(string-suffix-p "*" session))
(org-babel-julia-initiate-session session nil))))
(defvar ess-gen-proc-buffer-name-function) ; defined in ess-inf.el
(defun org-babel-julia-associate-session (session)
"Associate R code buffer with an R session.
Make SESSION be the inferior ESS process associated with the
current code buffer."
(when-let ((process (get-buffer-process session)))
(setq ess-local-process-name (process-name process))
(ess-make-buffer-current))
(setq-local ess-gen-proc-buffer-name-function (lambda (_) session)))
(defun org-babel-expand-body:julia (body params &optional _graphics-file)
"Expand BODY according to PARAMS, return the expanded body."
@ -181,10 +184,13 @@ end"
(defun org-babel-julia-initiate-session (session params)
"If there is not a current julia process then create one."
(unless (string= session "none")
(let ((session (or session "*Julia*"))
(ess-ask-for-ess-directory
(and (bound-and-true-p ess-ask-for-ess-directory)
(not (cdr (assq :dir params))))))
(let* ((session (or session "*Julia*"))
(ess-ask-for-ess-directory
(and (bound-and-true-p ess-ask-for-ess-directory)
(not (cdr (assq :dir params)))))
;; Make ESS name the process buffer as SESSION.
(ess-gen-proc-buffer-name-function
(lambda (_) session)))
(if (org-babel-comint-buffer-livep session)
session
;; FIXME: Depending on `display-buffer-alist', (julia) may end up
@ -196,13 +202,8 @@ end"
(when (get-buffer session)
;; Session buffer exists, but with dead process
(set-buffer session))
(require 'ess) (set-buffer (julia))
(rename-buffer
(if (bufferp session)
(buffer-name session)
(if (stringp session)
session
(buffer-name))))
(org-require-package 'ess "ESS")
(set-buffer (julia))
(current-buffer))))))
(defun org-babel-julia-graphical-output-file (params)

View File

@ -1,6 +1,6 @@
;;; ob-latex.el --- Babel Functions for LaTeX -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
@ -37,7 +37,7 @@
(require 'ob)
(require 'org-macs)
(declare-function org-create-formula-image "org" (string tofile options buffer &optional type))
(declare-function org-latex-preview-create-image "org-latex-preview" (string tofile options buffer &optional type))
(declare-function org-latex-compile "ox-latex" (texfile &optional snippet))
(declare-function org-latex-guess-inputenc "ox-latex" (header))
(declare-function org-splice-latex-header "org" (tpl def-pkg pkg snippets-p &optional extra))
@ -48,10 +48,10 @@
(defvar org-babel-tangle-lang-exts)
(add-to-list 'org-babel-tangle-lang-exts '("latex" . "tex"))
(defvar org-format-latex-header) ; From org.el
(defvar org-format-latex-options) ; From org.el
(defvar org-latex-default-packages-alist) ; From org.el
(defvar org-latex-packages-alist) ; From org.el
(defvar org-latex-preview-header) ; From org-latex-preview.el
(defvar org-latex-preview-appearance-options) ; From org-latex-preview.el
(defvar org-latex-default-packages-alist) ; From org-latex-preview.el
(defvar org-latex-packages-alist) ; From org-latex-preview.el
(defvar org-babel-default-header-args:latex
'((:results . "latex") (:exports . "results"))
@ -136,12 +136,18 @@ exporting the literal LaTeX source."
(regexp-quote (format "%S" (car pair)))
(if (stringp (cdr pair))
(cdr pair) (format "%S" (cdr pair)))
body)))
body t t)))
(org-babel--get-vars params))
(org-trim body))
(let ((prologue (cdr (assq :prologue params)))
(epilogue (cdr (assq :epilogue params))))
(org-trim
(concat
(and prologue (concat prologue "\n"))
body
(and epilogue (concat "\n" epilogue "\n"))))))
(defun org-babel-execute:latex (body params)
"Execute a block of LaTeX code with Babel.
"Execute LaTeX BODY according to PARAMS.
This function is called by `org-babel-execute-src-block'."
(setq body (org-babel-expand-body:latex body params))
(if (cdr (assq :file params))
@ -161,11 +167,11 @@ This function is called by `org-babel-execute-src-block'."
(append (cdr (assq :packages params)) org-latex-packages-alist)))
(cond
((and (string-suffix-p ".png" out-file) (not imagemagick))
(let ((org-format-latex-header
(concat org-format-latex-header "\n"
(let ((org-latex-preview-header
(concat org-latex-preview-header "\n"
(mapconcat #'identity headers "\n"))))
(org-create-formula-image
body out-file org-format-latex-options in-buffer)))
(org-latex-preview-create-image
body out-file org-latex-preview-appearance-options in-buffer)))
((string= "svg" extension)
(with-temp-file tex-file
(insert (concat (funcall org-babel-latex-preamble params)
@ -232,7 +238,7 @@ This function is called by `org-babel-execute-src-block'."
(insert
(org-latex-guess-inputenc
(org-splice-latex-header
org-format-latex-header
org-latex-preview-header
(delq
nil
(mapcar
@ -273,7 +279,9 @@ This function is called by `org-babel-execute-src-block'."
body))
(defun org-babel-latex-convert-pdf (pdffile out-file im-in-options im-out-options)
"Generate a file from a pdf file using imagemagick."
"Generate OUT-FILE from PDFFILE using imagemagick.
IM-IN-OPTIONS are command line options for input file, as a string;
and IM-OUT-OPTIONS are the output file options."
(let ((cmd (concat "convert " im-in-options " " pdffile " "
im-out-options " " out-file)))
(message "Converting pdffile file %s..." cmd)

View File

@ -1,6 +1,6 @@
;;; ob-lilypond.el --- Babel Functions for Lilypond -*- lexical-binding: t; -*-
;; Copyright (C) 2010-2023 Free Software Foundation, Inc.
;; Copyright (C) 2010-2024 Free Software Foundation, Inc.
;; Author: Martyn Jago
;; Keywords: babel language, literate programming
@ -40,10 +40,8 @@
(declare-function org-fold-show-all "org-fold" (&optional types))
;; FIXME: Doesn't this rather belong in lilypond-mode.el?
(defalias 'lilypond-mode 'LilyPond-mode)
(add-to-list 'org-babel-tangle-lang-exts '("LilyPond" . "ly"))
(add-to-list 'org-src-lang-modes '("lilypond" . "LilyPond"))
(defvar org-babel-default-header-args:lilypond '()
"Default header arguments for lilypond code blocks.
@ -60,23 +58,13 @@ and stored in `org-babel-default-header-args:lilypond'
See `org-babel-lilypond-set-header-args'.")
(defvar org-babel-lilypond-compile-post-tangle t
"Following the org-babel-tangle (C-c C-v t) command,
org-babel-lilypond-compile-post-tangle determines whether ob-lilypond should
automatically attempt to compile the resultant tangled file.
If the value is nil, no automated compilation takes place.
Default value is t.")
"When non-nil, compile tangled file after `org-babel-tangle'.")
(defvar org-babel-lilypond-display-pdf-post-tangle t
"Following a successful LilyPond compilation
org-babel-lilypond-display-pdf-post-tangle determines whether to automate the
drawing / redrawing of the resultant pdf. If the value is nil,
the pdf is not automatically redrawn. Default value is t.")
"When non-nil, display pdf after successful LilyPond compilation.")
(defvar org-babel-lilypond-play-midi-post-tangle t
"Following a successful LilyPond compilation
org-babel-lilypond-play-midi-post-tangle determines whether to automate the
playing of the resultant midi file. If the value is nil,
the midi file is not automatically played. Default value is t")
"When non-nil, play midi file after successful LilyPond compilation.")
(defvar org-babel-lilypond-ly-command ""
"Command to execute lilypond on your system.
@ -143,7 +131,9 @@ blocks.")
(defun org-babel-expand-body:lilypond (body params)
"Expand BODY according to PARAMS, return the expanded body."
(let ((vars (org-babel--get-vars params)))
(let ((vars (org-babel--get-vars params))
(prologue (cdr (assq :prologue params)))
(epilogue (cdr (assq :epilogue params))))
(mapc
(lambda (pair)
(let ((name (symbol-name (car pair)))
@ -152,54 +142,75 @@ blocks.")
(replace-regexp-in-string
(concat "$" (regexp-quote name))
(if (stringp value) value (format "%S" value))
body))))
body t t))))
vars)
body))
(concat
(and prologue (concat prologue "\n"))
body
(and epilogue (concat "\n" epilogue "\n")))))
(defun org-babel-execute:lilypond (body params)
"This function is called by `org-babel-execute-src-block'.
Depending on whether we are in arrange mode either:
1. Attempt to execute lilypond block according to header settings
(This is the default basic mode)
2. Tangle all lilypond blocks and process the result (arrange mode)"
"Execute LilyPond src block according to arrange mode.
See `org-babel-execute-src-block' for BODY and PARAMS.
When in arrange mode, tangle all blocks and process the result.
Otherwise, execute block according to header settings."
(org-babel-lilypond-set-header-args org-babel-lilypond-arrange-mode)
(if org-babel-lilypond-arrange-mode
(org-babel-lilypond-tangle)
(org-babel-lilypond-process-basic body params)))
(defun org-babel-lilypond-tangle ()
"ob-lilypond specific tangle, attempts to invoke
=ly-execute-tangled-ly= if tangle is successful. Also passes
specific arguments to =org-babel-tangle=."
"Tangle lilypond blocks, then `org-babel-liypond-execute-tangled-ly'."
(interactive)
(if (org-babel-tangle nil "yes" "lilypond")
(org-babel-lilypond-execute-tangled-ly) nil))
;; https://lilypond.org/doc/v2.24/Documentation/usage/other-programs
(defvar org-babel-lilypond-paper-settings
"#(if (ly:get-option 'use-paper-size-for-page)
(begin (ly:set-option 'use-paper-size-for-page #f)
(ly:set-option 'tall-page-formats '%s)))
\\paper {
indent=0\\mm
tagline=\"\"
oddFooterMarkup=##f
oddHeaderMarkup=##f
bookTitleMarkup=##f
scoreTitleMarkup=##f
}\n"
"The paper settings required to generate music fragments.
They are needed for mixing music and text in basic-mode.")
(defun org-babel-lilypond-process-basic (body params)
"Execute a lilypond block in basic mode."
"Execute a lilypond block in basic mode.
See `org-babel-execute-src-block' for BODY and PARAMS."
(let* ((out-file (cdr (assq :file params)))
(file-type (file-name-extension out-file))
(cmdline (or (cdr (assq :cmdline params))
""))
(in-file (org-babel-temp-file "lilypond-")))
(with-temp-file in-file
(insert (org-babel-expand-body:generic body params)))
(insert
(format org-babel-lilypond-paper-settings file-type)
(org-babel-expand-body:generic body params)))
(org-babel-eval
(concat
org-babel-lilypond-ly-command
" -dbackend=eps "
"-dno-gs-load-fonts "
"-dinclude-eps-fonts "
(or (cdr (assoc (file-name-extension out-file)
'(("pdf" . "--pdf ")
("ps" . "--ps ")
("png" . "--png "))))
(or (assoc-default file-type
'(("pdf" . "--pdf ")
("eps" . "--eps ")))
"--png ")
"--output="
(file-name-sans-extension out-file)
" "
cmdline
in-file) "")) nil)
in-file)
""))
nil)
(defun org-babel-prep-session:lilypond (_session _params)
"Return an error because LilyPond exporter does not support sessions."
@ -219,7 +230,7 @@ If error in compilation, attempt to mark the error in lilypond org file."
(delete-file org-babel-lilypond-temp-file))
(rename-file org-babel-lilypond-tangled-file
org-babel-lilypond-temp-file))
(org-switch-to-buffer-other-window "*lilypond*")
(switch-to-buffer-other-window "*lilypond*")
(erase-buffer)
(org-babel-lilypond-compile-lilyfile org-babel-lilypond-temp-file)
(goto-char (point-min))
@ -229,27 +240,20 @@ If error in compilation, attempt to mark the error in lilypond org file."
(org-babel-lilypond-attempt-to-open-pdf org-babel-lilypond-temp-file)
(org-babel-lilypond-attempt-to-play-midi org-babel-lilypond-temp-file)))))
(defun org-babel-lilypond-compile-lilyfile (file-name &optional test)
"Compile lilypond file and check for compile errors.
FILE-NAME is full path to lilypond (.ly) file."
(message "Compiling LilyPond...")
(let ((arg-1 org-babel-lilypond-ly-command) ;program
;; (arg-2 nil) ;infile
(arg-3 "*lilypond*") ;buffer
(arg-4 t) ;display
(arg-5 (if org-babel-lilypond-gen-png "--png" "")) ;&rest...
(arg-6 (if org-babel-lilypond-gen-html "--html" ""))
(arg-7 (if org-babel-lilypond-gen-pdf "--pdf" ""))
(arg-8 (if org-babel-lilypond-use-eps "-dbackend=eps" ""))
(arg-9 (if org-babel-lilypond-gen-svg "-dbackend=svg" ""))
(arg-10 (concat "--output=" (file-name-sans-extension file-name)))
(arg-11 file-name))
(if test
`(,arg-1 ,nil ,arg-3 ,arg-4 ,arg-5 ,arg-6 ;; arg-2
,arg-7 ,arg-8 ,arg-9 ,arg-10 ,arg-11)
(call-process
arg-1 nil arg-3 arg-4 arg-5 arg-6 ;; arg-2
arg-7 arg-8 arg-9 arg-10 arg-11))))
;;Ignoring second arg for pre Org 9.7 compatibility
(defun org-babel-lilypond-compile-lilyfile (filename &optional _)
"Compile Lilypond FILENAME and check for compile errors."
(message "Compiling %s..." filename)
(let ((args (delq nil (list
(and org-babel-lilypond-gen-png "--png")
(and org-babel-lilypond-gen-html "--html")
(and org-babel-lilypond-gen-pdf "--pdf")
(and org-babel-lilypond-use-eps "-dbackend=eps")
(and org-babel-lilypond-gen-svg "-dbackend=svg")
(concat "--output=" (file-name-sans-extension filename))
filename))))
(apply #'call-process org-babel-lilypond-ly-command nil
"*lilypond*" 'display args)))
(defun org-babel-lilypond-check-for-compile-error (file-name &optional test)
"Check for compile error.
@ -276,7 +280,7 @@ FILE-NAME is full path to lilypond file."
"Mark the erroneous lines in the lilypond org buffer.
FILE-NAME is full path to lilypond file.
LINE is the erroneous line."
(org-switch-to-buffer-other-window
(switch-to-buffer-other-window
(concat (file-name-nondirectory
(org-babel-lilypond-switch-extension file-name ".org"))))
(let ((temp (point)))
@ -290,7 +294,7 @@ LINE is the erroneous line."
(goto-char temp))))
(defun org-babel-lilypond-parse-line-num (&optional buffer)
"Extract error line number."
"Extract error line number in BUFFER or `current-buffer'."
(when buffer (set-buffer buffer))
(let ((start
(and (search-backward ":" nil t)
@ -423,8 +427,7 @@ These depend upon whether we are in Arrange mode i.e. MODE is t."
ob-lilypond-header-args)))
(defun org-babel-lilypond-set-header-args (mode)
"Set org-babel-default-header-args:lilypond
dependent on ORG-BABEL-LILYPOND-ARRANGE-MODE."
"Set lilypond babel header according to MODE."
(setq org-babel-default-header-args:lilypond
(org-babel-lilypond-get-header-args mode)))

View File

@ -1,6 +1,6 @@
;;; ob-lisp.el --- Babel Functions for Common Lisp -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Authors: Joel Boehland
;; Eric Schulte
@ -74,13 +74,19 @@ current directory string."
(let* ((vars (org-babel--get-vars params))
(result-params (cdr (assq :result-params params)))
(print-level nil) (print-length nil)
(prologue (cdr (assq :prologue params)))
(epilogue (cdr (assq :epilogue params)))
(body (if (null vars) (org-trim body)
(concat "(let ("
(mapconcat
(lambda (var)
(format "(%S (quote %S))" (car var) (cdr var)))
vars "\n ")
")\n" body ")"))))
")\n"
(and prologue (concat prologue "\n"))
body
(and epilogue (concat "\n" epilogue "\n"))
")"))))
(if (or (member "code" result-params)
(member "pp" result-params))
(format "(pprint %s)" body)
@ -90,37 +96,41 @@ current directory string."
"Execute a block of Common Lisp code with Babel.
BODY is the contents of the block, as a string. PARAMS is
a property list containing the parameters of the block."
(require (pcase org-babel-lisp-eval-fn
(`slime-eval 'slime)
(`sly-eval 'sly)))
(org-babel-reassemble-table
(let ((result
(funcall (if (member "output" (cdr (assq :result-params params)))
#'car #'cadr)
(with-temp-buffer
(insert (org-babel-expand-body:lisp body params))
(funcall org-babel-lisp-eval-fn
`(swank:eval-and-grab-output
,(let ((dir (if (assq :dir params)
(cdr (assq :dir params))
default-directory)))
(format
(if dir (format org-babel-lisp-dir-fmt dir)
"(progn %s\n)")
(buffer-substring-no-properties
(point-min) (point-max)))))
(cdr (assq :package params)))))))
(org-babel-result-cond (cdr (assq :result-params params))
(org-strip-quotes result)
(condition-case nil
(read (org-babel-lisp-vector-to-list result))
(error result))))
(org-babel-pick-name (cdr (assq :colname-names params))
(cdr (assq :colnames params)))
(org-babel-pick-name (cdr (assq :rowname-names params))
(cdr (assq :rownames params)))))
(let (eval-and-grab-output)
(pcase org-babel-lisp-eval-fn
(`slime-eval (org-require-package 'slime "SLIME")
(setq eval-and-grab-output 'swank:eval-and-grab-output))
(`sly-eval (org-require-package 'sly "SLY")
(setq eval-and-grab-output 'slynk:eval-and-grab-output)))
(org-babel-reassemble-table
(let ((result
(funcall (if (member "output" (cdr (assq :result-params params)))
#'car #'cadr)
(with-temp-buffer
(insert (org-babel-expand-body:lisp body params))
(funcall org-babel-lisp-eval-fn
`(,eval-and-grab-output
,(let ((dir (if (assq :dir params)
(cdr (assq :dir params))
default-directory)))
(format
(if dir (format org-babel-lisp-dir-fmt dir)
"(progn %s\n)")
(buffer-substring-no-properties
(point-min) (point-max)))))
(cdr (assq :package params)))))))
(org-babel-result-cond (cdr (assq :result-params params))
(org-strip-quotes result)
(condition-case nil
(read (org-babel-lisp-vector-to-list result))
(error result))))
(org-babel-pick-name (cdr (assq :colname-names params))
(cdr (assq :colnames params)))
(org-babel-pick-name (cdr (assq :rowname-names params))
(cdr (assq :rownames params))))))
(defun org-babel-lisp-vector-to-list (results)
"Convert #(...) values in RESULTS string into a (...) list."
;; TODO: better would be to replace #(...) with [...]
(replace-regexp-in-string "#(" "(" results))

View File

@ -1,6 +1,6 @@
;;; ob-lob.el --- Functions Supporting the Library of Babel -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Authors: Eric Schulte
;; Dan Davison
@ -34,8 +34,8 @@
(declare-function org-babel-ref-split-args "ob-ref" (arg-string))
(declare-function org-element-at-point "org-element" (&optional pom cached-only))
(declare-function org-element-context "org-element" (&optional element))
(declare-function org-element-property "org-element" (property element))
(declare-function org-element-type "org-element" (element))
(declare-function org-element-property "org-element-ast" (property node))
(declare-function org-element-type "org-element-ast" (node &optional anonymous))
(defvar org-babel-library-of-babel nil
"Library of source-code blocks.

View File

@ -1,6 +1,6 @@
;;; ob-lua.el --- Org Babel functions for Lua evaluation -*- lexical-binding: t; -*-
;; Copyright (C) 2014, 2016-2023 Free Software Foundation, Inc.
;; Copyright (C) 2014, 2016-2024 Free Software Foundation, Inc.
;; Authors: Dieter Schoen
;; Keywords: literate programming, reproducible research
@ -82,7 +82,7 @@ This will typically be `lua-mode'."
:type 'symbol)
(defun org-babel-execute:lua (body params)
"Execute a block of Lua code with Babel.
"Execute Lua BODY according to PARAMS.
This function is called by `org-babel-execute-src-block'."
(let* ((session (org-babel-lua-initiate-session
(cdr (assq :session params))))
@ -129,7 +129,8 @@ VARS contains resolved variable references."
;; helper functions
(defun org-babel-variable-assignments:lua (params)
"Return a list of Lua statements assigning the block's variables."
"Return a list of Lua statements assigning the block's variables.
The variable definitions are defining in PARAMS."
(mapcar
(lambda (pair)
(format "%s=%s"
@ -176,13 +177,20 @@ Emacs-lisp table, otherwise return the results as a string."
(cdr (assoc session org-babel-lua-buffers)))
(defun org-babel-lua-with-earmuffs (session)
"Return buffer name for SESSION, as *SESSION*."
(let ((name (if (stringp session) session (format "%s" session))))
(if (and (string= "*" (substring name 0 1))
(string= "*" (substring name (- (length name) 1))))
name
(format "*%s*" name))))
(defun org-babel-session-buffer:lua (session &optional _)
"Return session buffer name for SESSION."
(or (org-babel-lua-session-buffer session)
(org-babel-lua-with-earmuffs session)))
(defun org-babel-lua-without-earmuffs (session)
"Remove stars around *SESSION*, leaving SESSION."
(let ((name (if (stringp session) session (format "%s" session))))
(if (and (string= "*" (substring name 0 1))
(string= "*" (substring name (- (length name) 1))))
@ -281,7 +289,11 @@ fd:close()")
(defun org-babel-lua-evaluate
(session body &optional result-type result-params preamble)
"Evaluate BODY as Lua code."
"Evaluate BODY in SESSION as Lua code.
RESULT-TYPE and RESULT-PARAMS are passed to
`org-babel-lua-evaluate-session' or
`org-babel-lua-evaluate-external-process'.
PREAMBLE is passed to `org-babel-lua-evaluate-external-process'."
(if session
(org-babel-lua-evaluate-session
session body result-type result-params)
@ -290,10 +302,12 @@ fd:close()")
(defun org-babel-lua-evaluate-external-process
(body &optional result-type result-params preamble)
"Evaluate BODY in external lua process.
"Evaluate BODY in external Lua process.
If RESULT-TYPE equals `output' then return standard output as a
string. If RESULT-TYPE equals `value' then return the value of the
last statement in BODY, as elisp."
last statement in BODY, as elisp.
RESULT-PARAMS list all the :result header arg parameters.
PREAMBLE string is appended to BODY."
(let ((raw
(pcase result-type
(`output (org-babel-eval org-babel-lua-command
@ -326,7 +340,7 @@ last statement in BODY, as elisp."
If RESULT-TYPE equals `output' then return standard output as a
string. If RESULT-TYPE equals `value' then return the value of the
last statement in BODY, as elisp."
(let* ((send-wait (lambda () (comint-send-input nil t) (sleep-for 0 5)))
(let* ((send-wait (lambda () (comint-send-input nil t) (sleep-for 0.005)))
(dump-last-value
(lambda
(tmp-file pp)
@ -399,7 +413,7 @@ fd:close()"
(org-babel-lua-table-or-string results)))))
(defun org-babel-lua-read-string (string)
"Strip single quotes from around Lua string."
"Strip single quotes from around Lua STRING."
(org-unbracket-string "'" "'" string))
(provide 'ob-lua)

View File

@ -1,6 +1,6 @@
;;; ob-makefile.el --- Babel Functions for Makefile -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Thomas S. Dye
@ -36,7 +36,8 @@
(defvar org-babel-default-header-args:makefile '())
(defun org-babel-execute:makefile (body _params)
"Execute a block of makefile code.
"Execute makefile BODY.
Second function argument is ignored.
This function is called by `org-babel-execute-src-block'."
body)

View File

@ -1,6 +1,6 @@
;;; ob-matlab.el --- Babel support for Matlab -*- lexical-binding: t; -*-
;; Copyright (C) 2010-2023 Free Software Foundation, Inc.
;; Copyright (C) 2010-2024 Free Software Foundation, Inc.
;; Author: Dan Davison
;; Keywords: literate programming, reproducible research

View File

@ -1,6 +1,6 @@
;;; ob-maxima.el --- Babel Functions for Maxima -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Author: Eric S Fraga
;; Eric Schulte
@ -37,6 +37,11 @@
(require 'ob)
(defconst org-babel-header-args:maxima
'((batch . ((batchload batch load)))
(graphics-pkg . ((plot draw))))
"Maxima-specific header arguments.")
(defvar org-babel-tangle-lang-exts)
(add-to-list 'org-babel-tangle-lang-exts '("maxima" . "max"))
@ -48,43 +53,102 @@
:group 'org-babel
:type 'string)
(defvar org-babel-maxima--command-arguments-default
"--very-quiet"
"Command-line arguments sent to Maxima by default.
If the `:batch' header argument is set to `batchload' or unset,
then the `:cmdline' header argument is appended to this default;
otherwise, if the `:cmdline' argument is set, it over-rides this
default. See `org-babel-maxima-command' and
`org-babel-execute:maxima'.")
(defvar org-babel-maxima--graphic-package-options
'((plot . "(set_plot_option ('[gnuplot_term, %s]), set_plot_option ('[gnuplot_out_file, %S]))$")
(draw . "(load(draw), set_draw_defaults(terminal='%s,file_name=%S))$"))
"An alist of graphics packages and Maxima code.
Each element is a cons (PACKAGE-NAME . FORMAT-STRING).
FORMAT-STRING contains Maxima code to configure the graphics
package; it must contain `%s' to set the terminal and `%S' to set
the filename, in that order. The default graphics package is
`plot'; `draw' is also supported. See
`org-babel-maxima-expand'.")
(defvar org-babel-maxima--default-epilogue
'((graphical-output . "gnuplot_close ()$")
(non-graphical-output . ""))
"The final Maxima code executed in a source block.
An alist with the epilogue for graphical and non-graphical
output. See `org-babel-maxima-expand'.")
(defun org-babel-maxima-expand (body params)
"Expand a block of Maxima code according to its header arguments."
(let ((vars (org-babel--get-vars params))
(epilogue (cdr (assq :epilogue params)))
(prologue (cdr (assq :prologue params))))
"Expand Maxima BODY according to its header arguments from PARAMS."
(let* ((vars (org-babel--get-vars params))
(graphic-file (ignore-errors (org-babel-graphical-output-file params)))
(epilogue (cdr (assq :epilogue params)))
(prologue (cdr (assq :prologue params))))
(mapconcat 'identity
(list
;; Any code from the specified prologue at the start.
prologue
;; graphic output
(let ((graphic-file (ignore-errors (org-babel-graphical-output-file params))))
(if graphic-file
(format
"set_plot_option ([gnuplot_term, png]); set_plot_option ([gnuplot_out_file, %S]);"
graphic-file)
""))
;; variables
(mapconcat 'org-babel-maxima-var-to-maxima vars "\n")
;; body
body
;; Any code from the specified epilogue at the end.
epilogue
"gnuplot_close ()$")
(delq nil
(list
;; Any code from the specified prologue at the start.
prologue
;; graphic output
(if graphic-file
(let* ((graphics-pkg (intern (or (cdr (assq :graphics-pkg params)) "plot")))
(graphic-format-string (cdr (assq graphics-pkg org-babel-maxima--graphic-package-options)))
(graphic-terminal (file-name-extension graphic-file))
(graphic-file (if (eq graphics-pkg 'plot) graphic-file (file-name-sans-extension graphic-file))))
(format graphic-format-string graphic-terminal graphic-file)))
;; variables
(mapconcat 'org-babel-maxima-var-to-maxima vars "\n")
;; body
body
;; Any code from the specified epilogue at the end.
epilogue
(if graphic-file
(cdr (assq :graphical-output org-babel-maxima--default-epilogue))
(cdr (assq :non-graphical-output org-babel-maxima--default-epilogue)))))
"\n")))
(defvar org-babel-maxima--output-filter-regexps
'("batch" ;; remove the `batch' or `batchload' line
"^rat: replaced .*$" ;; remove notices from `rat'
"^;;; Loading #P" ;; remove notices from the lisp implementation
"^read and interpret" ;; remove notice from `batch'
"^(%\\([i]-?[0-9]+\\))[ ]$" ;; remove empty input lines from `batch'-ing
)
"Regexps to remove extraneous lines from Maxima's output.
See `org-babel-maxima--output-filter'.")
(defun org-babel-maxima--output-filter (line)
"Filter empty or undesired lines from Maxima output.
Return nil if LINE is zero-length or it matches a regexp in
`org-babel-maxima--output-filter'; otherwise, return LINE."
(unless (or (= 0 (length line))
(cl-some #'(lambda(r) (string-match r line))
org-babel-maxima--output-filter-regexps))
line))
(defun org-babel-execute:maxima (body params)
"Execute a block of Maxima entries with org-babel.
"Execute Maxima BODY according to PARAMS.
This function is called by `org-babel-execute-src-block'."
(message "Executing Maxima source code block")
(let ((result-params (split-string (or (cdr (assq :results params)) "")))
(result
(let* ((cmdline (or (cdr (assq :cmdline params)) ""))
(batch/load (or (cdr (assq :batch params)) "batchload"))
(cmdline (if (or (equal cmdline "") (equal batch/load "batchload"))
;; legacy behaviour:
;; ensure that --very-quiet is on command-line by default
(concat cmdline " " org-babel-maxima--command-arguments-default)
;; if using an alternate loader, :cmdline overwrites default
cmdline))
(in-file (org-babel-temp-file "maxima-" ".max"))
(cmd (format "%s --very-quiet -r %s %s"
(cmd (format "%s -r %s %s"
org-babel-maxima-command
(shell-quote-argument
(format "batchload(%S)$" in-file))
;; bind linenum to 0 so the first line
;; of in-file has line number 1
(format "(linenum:0, %s(%S))$" batch/load in-file))
cmdline)))
(with-temp-file in-file (insert (org-babel-maxima-expand body params)))
(message cmd)
@ -93,12 +157,7 @@ This function is called by `org-babel-execute-src-block'."
(mapconcat
#'identity
(delq nil
(mapcar (lambda (line)
(unless (or (string-match "batch" line)
(string-match "^rat: replaced .*$" line)
(string-match "^;;; Loading #P" line)
(= 0 (length line)))
line))
(mapcar #'org-babel-maxima--output-filter
(split-string raw "[\r\n]"))) "\n")))))
(if (ignore-errors (org-babel-graphical-output-file params))
nil
@ -110,11 +169,11 @@ This function is called by `org-babel-execute-src-block'."
(defun org-babel-prep-session:maxima (_session _params)
"Throw an error. Maxima does not support sessions."
(error "Maxima does not support sessions"))
(defun org-babel-maxima-var-to-maxima (pair)
"Convert an elisp val into a string of maxima code specifying a var
of the same value."
"Convert an elisp variable-value PAIR to maxima code."
(let ((var (car pair))
(val (cdr pair)))
(when (symbolp val)

View File

@ -1,6 +1,6 @@
;;; ob-ocaml.el --- Babel Functions for Ocaml -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
@ -63,7 +63,7 @@
:type 'string)
(defun org-babel-execute:ocaml (body params)
"Execute a block of Ocaml code with Babel."
"Execute Ocaml BODY according to PARAMS."
(let* ((full-body (org-babel-expand-body:generic
body params
(org-babel-variable-assignments:ocaml params)))
@ -109,7 +109,7 @@
(defvar tuareg-interactive-buffer-name)
(defun org-babel-prep-session:ocaml (session _params)
"Prepare SESSION according to the header arguments in PARAMS."
(require 'tuareg)
(org-require-package 'tuareg)
(let ((tuareg-interactive-buffer-name (if (and (not (string= session "none"))
(not (string= session "default"))
(stringp session))
@ -121,7 +121,8 @@
(get-buffer tuareg-interactive-buffer-name)))
(defun org-babel-variable-assignments:ocaml (params)
"Return list of ocaml statements assigning the block's variables."
"Return list of ocaml statements assigning the block's variables.
The variables are defined in PARAMS."
(mapcar
(lambda (pair) (format "let %s = %s;;" (car pair)
(org-babel-ocaml-elisp-to-ocaml (cdr pair))))

View File

@ -1,6 +1,6 @@
;;; ob-octave.el --- Babel Functions for Octave and Matlab -*- lexical-binding: t; -*-
;; Copyright (C) 2010-2023 Free Software Foundation, Inc.
;; Copyright (C) 2010-2024 Free Software Foundation, Inc.
;; Author: Dan Davison
;; Keywords: literate programming, reproducible research
@ -70,11 +70,12 @@ end")
(defvar org-babel-octave-eoe-output "ans = org_babel_eoe")
(defun org-babel-execute:matlab (body params)
"Execute a block of matlab code with Babel."
"Execute Matlab BODY according to PARAMS."
(org-babel-execute:octave body params 'matlab))
(defun org-babel-execute:octave (body params &optional matlabp)
"Execute a block of octave code with Babel."
"Execute Octave or Matlab BODY according to PARAMS.
When MATLABP is non-nil, execute Matlab. Otherwise, execute Octave."
(let* ((session
(funcall (intern (format "org-babel-%s-initiate-session"
(if matlabp "matlab" "octave")))
@ -109,7 +110,8 @@ end")
(org-babel-prep-session:octave session params 'matlab))
(defun org-babel-variable-assignments:octave (params)
"Return list of octave statements assigning the block's variables."
"Return list of octave statements assigning the block's variables.
The variables are taken from PARAMS."
(mapcar
(lambda (pair)
(format "%s=%s;"
@ -120,21 +122,22 @@ end")
(defalias 'org-babel-variable-assignments:matlab
'org-babel-variable-assignments:octave)
(defun org-babel-octave-var-to-octave (var)
"Convert an emacs-lisp value into an octave variable.
(defun org-babel-octave-var-to-octave (value)
"Convert an emacs-lisp VALUE into an octave variable.
Converts an emacs-lisp variable into a string of octave code
specifying a variable of the same value."
(if (listp var)
(concat "[" (mapconcat #'org-babel-octave-var-to-octave var
(if (listp (car var)) "; " ",")) "]")
(if (listp value)
(concat "[" (mapconcat #'org-babel-octave-var-to-octave value
(if (listp (car value)) "; " ",")) "]")
(cond
((stringp var)
(format "'%s'" var))
((stringp value)
(format "'%s'" value))
(t
(format "%s" var)))))
(format "%s" value)))))
(defun org-babel-prep-session:octave (session params &optional matlabp)
"Prepare SESSION according to the header arguments specified in PARAMS."
"Prepare SESSION according to the header arguments specified in PARAMS.
The session will be an Octave session, unless MATLABP is non-nil."
(let* ((session (org-babel-octave-initiate-session session params matlabp))
(var-lines (org-babel-variable-assignments:octave params)))
(org-babel-comint-in-buffer session
@ -147,15 +150,18 @@ specifying a variable of the same value."
(defun org-babel-matlab-initiate-session (&optional session params)
"Create a matlab inferior process buffer.
If there is not a current inferior-process-buffer in SESSION then
create. Return the initialized session."
create. Return the initialized session. PARAMS are src block parameters."
(org-babel-octave-initiate-session session params 'matlab))
(defun org-babel-octave-initiate-session (&optional session _params matlabp)
"Create an octave inferior process buffer.
If there is not a current inferior-process-buffer in SESSION then
create. Return the initialized session."
(if matlabp (require 'matlab) (or (require 'octave-inf nil 'noerror)
(require 'octave)))
create. Return the initialized session. The session will be an
Octave session, unless MATLABP is non-nil."
(if matlabp
(org-require-package 'matlab "matlab-mode")
(or (require 'octave-inf nil 'noerror)
(require 'octave)))
(unless (string= session "none")
(let ((session (or session
(if matlabp "*Inferior Matlab*" "*Inferior Octave*"))))
@ -178,7 +184,8 @@ value of the last statement in BODY, as elisp."
(org-babel-octave-evaluate-external-process body result-type matlabp)))
(defun org-babel-octave-evaluate-external-process (body result-type matlabp)
"Evaluate BODY in an external octave process."
"Evaluate BODY in an external Octave or Matalab process.
Process the result as RESULT-TYPE. Use Octave, unless MATLABP is non-nil."
(let ((cmd (if matlabp
org-babel-matlab-shell-command
org-babel-octave-shell-command)))

View File

@ -1,6 +1,6 @@
;;; ob-org.el --- Babel Functions for Org Code Blocks -*- lexical-binding: t; -*-
;; Copyright (C) 2010-2023 Free Software Foundation, Inc.
;; Copyright (C) 2010-2024 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
@ -45,15 +45,25 @@
"Default header inserted during export of org blocks.")
(defun org-babel-expand-body:org (body params)
"Expand Org BODY according to PARAMS.
$VAR instances are replaced by VAR values defined in PARAMS."
(dolist (var (org-babel--get-vars params))
(setq body (replace-regexp-in-string
(regexp-quote (format "$%s" (car var)))
(format "%s" (cdr var))
body nil 'literal)))
body)
body 'fixedcase 'literal)))
(let ((prologue (cdr (assq :prologue params)))
(epilogue (cdr (assq :epilogue params))))
(concat
(and prologue (concat prologue "\n"))
body
(and epilogue (concat "\n" epilogue "\n")))))
(defun org-babel-execute:org (body params)
"Execute a block of Org code with.
"Execute a Org BODY according to PARAMS.
The BODY is returned expanded as is or exported, if PARAMS define
latex/html/ascii result type.
This function is called by `org-babel-execute-src-block'."
(let ((result-params (split-string (or (cdr (assq :results params)) "")))
(body (org-babel-expand-body:org

View File

@ -1,6 +1,6 @@
;;; ob-perl.el --- Babel Functions for Perl -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Authors: Dan Davison
;; Eric Schulte

View File

@ -1,6 +1,6 @@
;;; ob-plantuml.el --- Babel Functions for Plantuml -*- lexical-binding: t; -*-
;; Copyright (C) 2010-2023 Free Software Foundation, Inc.
;; Copyright (C) 2010-2024 Free Software Foundation, Inc.
;; Author: Zhang Weize
;; Keywords: literate programming, reproducible research
@ -143,6 +143,7 @@ This function is called by `org-babel-execute-src-block'."
("eps" '("-teps"))
("pdf" '("-tpdf"))
("tex" '("-tlatex"))
("tikz" '("-tlatex:nopreamble"))
("vdx" '("-tvdx"))
("xmi" '("-txmi"))
("scxml" '("-tscxml"))

View File

@ -1,6 +1,6 @@
;;; ob-processing.el --- Babel functions for processing -*- lexical-binding: t; -*-
;; Copyright (C) 2015-2023 Free Software Foundation, Inc.
;; Copyright (C) 2015-2024 Free Software Foundation, Inc.
;; Author: Jarmo Hurri (adapted from ob-asymptote.el written by Eric Schulte)
;; Maintainer: Jarmo Hurri <jarmo.hurri@iki.fi>
@ -78,7 +78,7 @@
(defun org-babel-processing-view-sketch ()
"Show the sketch of the Processing block under point in an external viewer."
(interactive)
(require 'processing-mode)
(org-require-package 'processing-mode)
(let ((info (org-babel-get-src-block-info)))
(if (string= (nth 0 info) "processing")
(let* ((body (nth 1 info))
@ -118,7 +118,7 @@
(message "Not inside a Processing source block."))))
(defun org-babel-execute:processing (body params)
"Execute a block of Processing code.
"Execute Processing code BODY according to PARAMS.
This function is called by `org-babel-execute-src-block'."
(let ((sketch-code
(org-babel-expand-body:generic
@ -144,7 +144,8 @@ Processing does not support sessions."
(error "Processing does not support sessions"))
(defun org-babel-variable-assignments:processing (params)
"Return list of processing statements assigning the block's variables."
"Return list of processing statements assigning the block's variables.
The variable assignments are defined in PARAMS."
(mapcar #'org-babel-processing-var-to-processing
(org-babel--get-vars params)))

View File

@ -1,6 +1,6 @@
;;; ob-python.el --- Babel Functions for Python -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Authors: Eric Schulte
;; Dan Davison
@ -36,53 +36,70 @@
(require 'org-macs)
(require 'python)
(declare-function py-shell "ext:python-mode" (&rest args))
(declare-function py-choose-shell "ext:python-mode" (&optional shell))
(declare-function py-shell-send-string "ext:python-mode" (strg &optional process))
(defvar org-babel-tangle-lang-exts)
(add-to-list 'org-babel-tangle-lang-exts '("python" . "py"))
(defvar org-babel-default-header-args:python '())
(defcustom org-babel-python-command "python"
"Name of the command for executing Python code."
:version "24.4"
:package-version '(Org . "8.0")
(defconst org-babel-header-args:python
'((return . :any)
(python . :any)
(async . ((yes no))))
"Python-specific header arguments.")
(defcustom org-babel-python-command 'auto
"Command (including arguments) for interactive and non-interactive Python code.
When not `auto', it overrides `org-babel-python-command-session'
and `org-babel-python-command-nonsession'."
:package-version '(Org . "9.7")
:group 'org-babel
:type '(choice string (const auto)))
(defcustom org-babel-python-command-session 'auto
"Command (including arguments) for starting interactive Python sessions.
If `auto' (the default), uses the values from
`python-shell-interpreter' and `python-shell-interpreter-args'.
If `org-babel-python-command' is set, then it overrides this
option."
:package-version '(Org . "9.7")
:group 'org-babel
:type '(choice string (const auto)))
(defcustom org-babel-python-command-nonsession "python"
"Command (including arguments) for executing non-interactive Python code.
If `org-babel-python-command' is set, then it overrides this option."
:package-version '(Org . "9.7")
:group 'org-babel
:type 'string)
(defcustom org-babel-python-mode
(if (featurep 'python-mode) 'python-mode 'python)
"Preferred python mode for use in running python interactively.
This will typically be either `python' or `python-mode'."
:group 'org-babel
:version "24.4"
:package-version '(Org . "8.0")
:type 'symbol)
(defcustom org-babel-python-hline-to "None"
"Replace hlines in incoming tables with this when translating to python."
:group 'org-babel
:version "24.4"
:package-version '(Org . "8.0")
:type 'string)
(defcustom org-babel-python-None-to 'hline
"Replace `None' in python tables with this before returning."
:group 'org-babel
:version "24.4"
:package-version '(Org . "8.0")
:type 'symbol)
(defun org-babel-python-associate-session (session)
"Associate Python code buffer with an Python session.
Make SESSION without earmuffs be the Python buffer name."
(setq-local python-shell-buffer-name
(org-babel-python-without-earmuffs session)))
(defun org-babel-execute:python (body params)
"Execute a block of Python code with Babel.
"Execute Python BODY according to PARAMS.
This function is called by `org-babel-execute-src-block'."
(let* ((org-babel-python-command
(or (cdr (assq :python params))
org-babel-python-command))
(session (org-babel-python-initiate-session
(cdr (assq :session params))))
(graphics-file (and (member "graphics" (assq :result-params params))
(org-babel-graphical-output-file params)))
(result-params (cdr (assq :result-params params)))
(result-type (cdr (assq :result-type params)))
(return-val (when (eq result-type 'value)
@ -98,7 +115,7 @@ This function is called by `org-babel-execute-src-block'."
(format (if session "\n%s" "\nreturn %s") return-val))))
(result (org-babel-python-evaluate
session full-body result-type
result-params preamble async)))
result-params preamble async graphics-file)))
(org-babel-reassemble-table
result
(org-babel-pick-name (cdr (assq :colname-names params))
@ -130,8 +147,63 @@ VARS contains resolved variable references."
;; helper functions
(defconst org-babel-python--output-graphics-wrapper "\
import matplotlib.pyplot
matplotlib.pyplot.gcf().clear()
%s
matplotlib.pyplot.savefig('%s')"
"Format string for saving Python graphical output.
Has two %s escapes, for the Python code to be evaluated, and the
file to save the graphics to.")
(defconst org-babel-python--def-format-value "\
def __org_babel_python_format_value(result, result_file, result_params):
with open(result_file, 'w') as f:
if 'graphics' in result_params:
result.savefig(result_file)
elif 'pp' in result_params:
import pprint
f.write(pprint.pformat(result))
elif 'list' in result_params and isinstance(result, dict):
f.write(str(['{} :: {}'.format(k, v) for k, v in result.items()]))
else:
if not set(result_params).intersection(\
['scalar', 'verbatim', 'raw']):
def dict2table(res):
if isinstance(res, dict):
return [(k, dict2table(v)) for k, v in res.items()]
elif isinstance(res, list) or isinstance(res, tuple):
return [dict2table(x) for x in res]
else:
return res
if 'table' in result_params:
result = dict2table(result)
try:
import pandas
except ImportError:
pass
else:
if isinstance(result, pandas.DataFrame) and 'table' in result_params:
result = [[result.index.name or ''] + list(result.columns)] + \
[None] + [[i] + list(row) for i, row in result.iterrows()]
elif isinstance(result, pandas.Series) and 'table' in result_params:
result = list(result.items())
try:
import numpy
except ImportError:
pass
else:
if isinstance(result, numpy.ndarray):
if 'table' in result_params:
result = result.tolist()
else:
result = repr(result)
f.write(str(result))"
"Python function to format value result and save it to file.")
(defun org-babel-variable-assignments:python (params)
"Return a list of Python statements assigning the block's variables."
"Return a list of Python statements assigning the block's variables.
The assignments are defined in PARAMS."
(mapcar
(lambda (pair)
(format "%s=%s"
@ -153,9 +225,13 @@ specifying a variable of the same value."
(defun org-babel-python-table-or-string (results)
"Convert RESULTS into an appropriate elisp value.
If the results look like a list or tuple, then convert them into an
Emacs-lisp table, otherwise return the results as a string."
(let ((res (org-babel-script-escape results)))
If the results look like a list or tuple (but not a dict), then
convert them into an Emacs-lisp table. Otherwise return the
results as a string."
(let ((res (if (and (> (length results) 0)
(string-equal "{" (substring results 0 1)))
results ;don't covert dicts to elisp
(org-babel-script-escape results))))
(if (listp res)
(mapcar (lambda (el) (if (eq el 'None)
org-babel-python-None-to el))
@ -169,6 +245,7 @@ Emacs-lisp table, otherwise return the results as a string."
(cdr (assoc session org-babel-python-buffers)))
(defun org-babel-python-with-earmuffs (session)
"Return SESSION name as string, ensuring *...* around."
(let ((name (if (stringp session) session (format "%s" session))))
(if (and (string= "*" (substring name 0 1))
(string= "*" (substring name (- (length name) 1))))
@ -176,74 +253,113 @@ Emacs-lisp table, otherwise return the results as a string."
(format "*%s*" name))))
(defun org-babel-python-without-earmuffs (session)
"Return SESSION name as string, without *...* around."
(let ((name (if (stringp session) session (format "%s" session))))
(if (and (string= "*" (substring name 0 1))
(string= "*" (substring name (- (length name) 1))))
(substring name 1 (- (length name) 1))
name)))
(defvar py-which-bufname)
(defvar python-shell-buffer-name)
(defun org-babel-session-buffer:python (session &optional _)
"Return session buffer name for SESSION."
(or (org-babel-python-session-buffer session)
(org-babel-python-with-earmuffs session)))
(defun org-babel-python--python-util-comint-end-of-output-p ()
"Return non-nil if the last prompt matches input prompt.
Backport of `python-util-comint-end-of-output-p' to emacs28. To
be removed after minimum supported version reaches emacs29."
(when-let ((prompt (python-util-comint-last-prompt)))
(python-shell-comint-end-of-output-p
(buffer-substring-no-properties
(car prompt) (cdr prompt)))))
(defun org-babel-python--command (is-session)
"Helper function to return the Python command.
This checks `org-babel-python-command', and then
`org-babel-python-command-session' (if IS-SESSION) or
`org-babel-python-command-nonsession' (if not IS-SESSION). If
IS-SESSION, this might return `nil', which means to use
`python-shell-calculate-command'."
(or (unless (eq org-babel-python-command 'auto)
org-babel-python-command)
(if is-session
(unless (eq org-babel-python-command-session 'auto)
org-babel-python-command-session)
org-babel-python-command-nonsession)))
(defvar-local org-babel-python--initialized nil
"Flag used to mark that python session has been initialized.")
(defun org-babel-python--setup-session ()
"Babel Python session setup code, to be run once per session.
Function should be run from within the Python session buffer.
This is often run as a part of `python-shell-first-prompt-hook',
unless the Python session was created outside Org."
(python-shell-send-string-no-output org-babel-python--def-format-value)
(setq-local org-babel-python--initialized t))
(defun org-babel-python-initiate-session-by-key (&optional session)
"Initiate a python session.
If there is not a current inferior-process-buffer in SESSION
then create. Return the initialized session."
If there is not a current inferior-process-buffer matching
SESSION then create it. If inferior process already
exists (e.g. if it was manually started with `run-python'), make
sure it's configured to work with ob-python. If session has
already been configured as such, do nothing. Return the
initialized session."
(save-window-excursion
(let* ((session (if session (intern session) :default))
(py-buffer (org-babel-python-session-buffer session))
(cmd (if (member system-type '(cygwin windows-nt ms-dos))
(concat org-babel-python-command " -i")
org-babel-python-command)))
(cond
((eq 'python org-babel-python-mode) ; python.el
(unless py-buffer
(setq py-buffer (org-babel-python-with-earmuffs session)))
(let ((python-shell-buffer-name
(org-babel-python-without-earmuffs py-buffer)))
(run-python cmd)
(with-current-buffer py-buffer
(add-hook
'python-shell-first-prompt-hook
(lambda ()
(setq-local org-babel-python--initialized t)
(message "I am running!!!"))
nil 'local))))
((and (eq 'python-mode org-babel-python-mode)
(fboundp 'py-shell)) ; python-mode.el
(require 'python-mode)
;; Make sure that py-which-bufname is initialized, as otherwise
;; it will be overwritten the first time a Python buffer is
;; created.
(py-choose-shell)
;; `py-shell' creates a buffer whose name is the value of
;; `py-which-bufname' with '*'s at the beginning and end
(let* ((bufname (if (and py-buffer (buffer-live-p py-buffer))
(replace-regexp-in-string ;; zap surrounding *
"^\\*\\([^*]+\\)\\*$" "\\1" py-buffer)
(concat "Python-" (symbol-name session))))
(py-which-bufname bufname))
(setq py-buffer (org-babel-python-with-earmuffs bufname))
(py-shell nil nil t org-babel-python-command py-buffer nil nil t nil)))
(t
(error "No function available for running an inferior Python")))
;; Wait until Python initializes.
(if (eq 'python org-babel-python-mode) ; python.el
;; This is more reliable compared to
;; `org-babel-comint-wait-for-output' as python may emit
;; multiple prompts during initialization.
(with-current-buffer py-buffer
(while (not org-babel-python--initialized)
(sleep-for 0 10)))
(org-babel-comint-wait-for-output py-buffer))
(py-buffer (org-babel-session-buffer:python session))
(python-shell-buffer-name
(org-babel-python-without-earmuffs py-buffer))
(existing-session-p (comint-check-proc py-buffer))
(cmd (org-babel-python--command t)))
(if cmd
(let* ((cmd-split (split-string-and-unquote cmd))
(python-shell-interpreter (car cmd-split))
(python-shell-interpreter-args
(combine-and-quote-strings
(append (cdr cmd-split)
(when (member system-type
'(cygwin windows-nt ms-dos))
(list "-i"))))))
(run-python))
(run-python))
(with-current-buffer py-buffer
(if existing-session-p
;; Session was created outside Org. Assume first prompt
;; already happened; run session setup code directly
(unless org-babel-python--initialized
;; Ensure first prompt. Based on python-tests.el
;; (`python-tests-shell-wait-for-prompt')
(while (not (org-babel-python--python-util-comint-end-of-output-p))
(sit-for 0.1))
(org-babel-python--setup-session))
;; Adding to `python-shell-first-prompt-hook' immediately
;; after `run-python' should be safe from race conditions,
;; because subprocess output only arrives when Emacs is
;; waiting (see elisp manual, "Output from Processes")
(add-hook
'python-shell-first-prompt-hook
#'org-babel-python--setup-session
nil 'local)))
;; Wait until Python initializes
;; This is more reliable compared to
;; `org-babel-comint-wait-for-output' as python may emit
;; multiple prompts during initialization.
(with-current-buffer py-buffer
(while (not org-babel-python--initialized)
(sleep-for 0.010)))
(setq org-babel-python-buffers
(cons (cons session py-buffer)
(assq-delete-all session org-babel-python-buffers)))
session)))
(defun org-babel-python-initiate-session (&optional session _params)
"Create a session named SESSION according to PARAMS."
"Initiate Python session named SESSION according to PARAMS.
If there is not a current inferior-process-buffer matching
SESSION then create it. If inferior process already
exists (e.g. if it was manually started with `run-python'), make
sure it's configured to work with ob-python. If session has
already been configured as such, do nothing."
(unless (string= session "none")
(org-babel-python-session-buffer
(org-babel-python-initiate-session-by-key session))))
@ -251,31 +367,10 @@ then create. Return the initialized session."
(defvar org-babel-python-eoe-indicator "org_babel_python_eoe"
"A string to indicate that evaluation has completed.")
(defconst org-babel-python-wrapper-method
"
def main():
%s
open('%s', 'w').write( str(main()) )")
(defconst org-babel-python-pp-wrapper-method
"
import pprint
def main():
%s
open('%s', 'w').write( pprint.pformat(main()) )")
(defconst org-babel-python--exec-tmpfile "\
with open('%s') as __org_babel_python_tmpfile:
exec(compile(__org_babel_python_tmpfile.read(), __org_babel_python_tmpfile.name, 'exec'))"
"Template for Python session command with output results.
Has a single %s escape, the tempfile containing the source code
to evaluate.")
(defun org-babel-python-format-session-value
(src-file result-file result-params)
"Return Python code to evaluate SRC-FILE and write result to RESULT-FILE."
"Return Python code to evaluate SRC-FILE and write result to RESULT-FILE.
RESULT-PARAMS defines the result type."
(format "\
import ast
with open('%s') as __org_babel_python_tmpfile:
@ -286,30 +381,25 @@ if isinstance(__org_babel_python_final, ast.Expr):
exec(compile(__org_babel_python_ast, '<string>', 'exec'))
__org_babel_python_final = eval(compile(ast.Expression(
__org_babel_python_final.value), '<string>', 'eval'))
with open('%s', 'w') as __org_babel_python_tmpfile:
if %s:
import pprint
__org_babel_python_tmpfile.write(pprint.pformat(__org_babel_python_final))
else:
__org_babel_python_tmpfile.write(str(__org_babel_python_final))
else:
exec(compile(__org_babel_python_ast, '<string>', 'exec'))
__org_babel_python_final = None"
__org_babel_python_final = None
__org_babel_python_format_value(__org_babel_python_final, '%s', %s)"
(org-babel-process-file-name src-file 'noquote)
(org-babel-process-file-name result-file 'noquote)
(if (member "pp" result-params) "True" "False")))
(org-babel-python-var-to-python result-params)))
(defun org-babel-python-evaluate
(session body &optional result-type result-params preamble async)
(session body &optional result-type result-params preamble async graphics-file)
"Evaluate BODY as Python code."
(if session
(if async
(org-babel-python-async-evaluate-session
session body result-type result-params)
session body result-type result-params graphics-file)
(org-babel-python-evaluate-session
session body result-type result-params))
session body result-type result-params graphics-file))
(org-babel-python-evaluate-external-process
body result-type result-params preamble)))
body result-type result-params preamble graphics-file)))
(defun org-babel-python--shift-right (body &optional count)
(with-temp-buffer
@ -325,33 +415,40 @@ else:
(buffer-string)))
(defun org-babel-python-evaluate-external-process
(body &optional result-type result-params preamble)
(body &optional result-type result-params preamble graphics-file)
"Evaluate BODY in external python process.
If RESULT-TYPE equals `output' then return standard output as a
string. If RESULT-TYPE equals `value' then return the value of the
last statement in BODY, as elisp."
string. If RESULT-TYPE equals `value' then return the value of
the last statement in BODY, as elisp. If GRAPHICS-FILE is
non-nil, then save graphical results to that file instead."
(let ((raw
(pcase result-type
(`output (org-babel-eval org-babel-python-command
(`output (org-babel-eval (org-babel-python--command nil)
(concat preamble (and preamble "\n")
body)))
(`value (let ((tmp-file (org-babel-temp-file "python-")))
(org-babel-eval
org-babel-python-command
(if graphics-file
(format org-babel-python--output-graphics-wrapper
body graphics-file)
body))))
(`value (let ((results-file (or graphics-file
(org-babel-temp-file "python-"))))
(org-babel-eval (org-babel-python--command nil)
(concat
preamble (and preamble "\n")
(format
(if (member "pp" result-params)
org-babel-python-pp-wrapper-method
org-babel-python-wrapper-method)
(org-babel-python--shift-right body)
(org-babel-process-file-name tmp-file 'noquote))))
(org-babel-eval-read-file tmp-file))))))
(concat org-babel-python--def-format-value "
def main():
%s
__org_babel_python_format_value(main(), '%s', %s)")
(org-babel-python--shift-right body)
(org-babel-process-file-name results-file 'noquote)
(org-babel-python-var-to-python result-params))))
(org-babel-eval-read-file results-file))))))
(org-babel-result-cond result-params
raw
(org-babel-python-table-or-string (org-trim raw)))))
(org-babel-python-table-or-string raw))))
(defun org-babel-python--send-string (session body)
(defun org-babel-python-send-string (session body)
"Pass BODY to the Python process in SESSION.
Return output."
(with-current-buffer session
@ -369,48 +466,54 @@ finally:
print('%s')"
(org-babel-python--shift-right body 4)
org-babel-python-eoe-indicator)))
(if (not (eq 'python-mode org-babel-python-mode))
(let ((python-shell-buffer-name
(org-babel-python-without-earmuffs session)))
(python-shell-send-string body))
(require 'python-mode)
(py-shell-send-string body (get-buffer-process session)))
(let ((python-shell-buffer-name
(org-babel-python-without-earmuffs session)))
(python-shell-send-string body))
;; same as `python-shell-comint-end-of-output-p' in emacs-25.1+
(while (not (string-match
org-babel-python-eoe-indicator
string-buffer))
(while (not (and (python-shell-comint-end-of-output-p string-buffer)
(string-match
org-babel-python-eoe-indicator
string-buffer)))
(accept-process-output (get-buffer-process (current-buffer))))
(org-babel-chomp (substring string-buffer 0 (match-beginning 0))))))
(defun org-babel-python-evaluate-session
(session body &optional result-type result-params)
(session body &optional result-type result-params graphics-file)
"Pass BODY to the Python process in SESSION.
If RESULT-TYPE equals `output' then return standard output as a
string. If RESULT-TYPE equals `value' then return the value of the
last statement in BODY, as elisp."
string. If RESULT-TYPE equals `value' then return the value of
the last statement in BODY, as elisp. If GRAPHICS-FILE is
non-nil, then save graphical results to that file instead."
(let* ((tmp-src-file (org-babel-temp-file "python-"))
(results
(progn
(with-temp-file tmp-src-file (insert body))
(with-temp-file tmp-src-file
(insert (if (and graphics-file (eq result-type 'output))
(format org-babel-python--output-graphics-wrapper
body graphics-file)
body)))
(pcase result-type
(`output
(let ((body (format org-babel-python--exec-tmpfile
(let ((body (format "\
with open('%s') as f:
exec(compile(f.read(), f.name, 'exec'))"
(org-babel-process-file-name
tmp-src-file 'noquote))))
(org-babel-python--send-string session body)))
(org-babel-python-send-string session body)))
(`value
(let* ((tmp-results-file (org-babel-temp-file "python-"))
(let* ((results-file (or graphics-file
(org-babel-temp-file "python-")))
(body (org-babel-python-format-session-value
tmp-src-file tmp-results-file result-params)))
(org-babel-python--send-string session body)
(sleep-for 0 10)
(org-babel-eval-read-file tmp-results-file)))))))
tmp-src-file results-file result-params)))
(org-babel-python-send-string session body)
(sleep-for 0.010)
(org-babel-eval-read-file results-file)))))))
(org-babel-result-cond result-params
results
(org-babel-python-table-or-string results))))
(defun org-babel-python-read-string (string)
"Strip \\='s from around Python string."
"Strip \\='s from around Python STRING."
(if (and (string-prefix-p "'" string)
(string-suffix-p "'" string))
(substring string 1 -1)
@ -428,7 +531,7 @@ last statement in BODY, as elisp."
(org-babel-python-table-or-string results))))
(defun org-babel-python-async-evaluate-session
(session body &optional result-type result-params)
(session body &optional result-type result-params graphics-file)
"Asynchronously evaluate BODY in SESSION.
Returns a placeholder string for insertion, to later be replaced
by `org-babel-comint-async-filter'."
@ -436,28 +539,37 @@ by `org-babel-comint-async-filter'."
session (current-buffer)
"ob_comint_async_python_\\(.+\\)_\\(.+\\)"
'org-babel-chomp 'org-babel-python-async-value-callback)
(let ((python-shell-buffer-name (org-babel-python-without-earmuffs session)))
(pcase result-type
(`output
(let ((uuid (md5 (number-to-string (random 100000000)))))
(with-temp-buffer
(insert (format org-babel-python-async-indicator "start" uuid))
(insert "\n")
(insert body)
(insert "\n")
(insert (format org-babel-python-async-indicator "end" uuid))
(python-shell-send-buffer))
uuid))
(`value
(let ((tmp-results-file (org-babel-temp-file "python-"))
(tmp-src-file (org-babel-temp-file "python-")))
(with-temp-file tmp-src-file (insert body))
(with-temp-buffer
(insert (org-babel-python-format-session-value tmp-src-file tmp-results-file result-params))
(insert "\n")
(insert (format org-babel-python-async-indicator "file" tmp-results-file))
(python-shell-send-buffer))
tmp-results-file)))))
(pcase result-type
(`output
(let ((uuid (org-id-uuid)))
(with-temp-buffer
(insert (format org-babel-python-async-indicator "start" uuid))
(insert "\n")
(insert (if graphics-file
(format org-babel-python--output-graphics-wrapper
body graphics-file)
body))
(insert "\n")
(insert (format org-babel-python-async-indicator "end" uuid))
(let ((python-shell-buffer-name
(org-babel-python-without-earmuffs session)))
(python-shell-send-buffer)))
uuid))
(`value
(let ((results-file (or graphics-file
(org-babel-temp-file "python-")))
(tmp-src-file (org-babel-temp-file "python-")))
(with-temp-file tmp-src-file (insert body))
(with-temp-buffer
(insert (org-babel-python-format-session-value
tmp-src-file results-file result-params))
(insert "\n")
(unless graphics-file
(insert (format org-babel-python-async-indicator "file" results-file)))
(let ((python-shell-buffer-name
(org-babel-python-without-earmuffs session)))
(python-shell-send-buffer)))
results-file))))
(provide 'ob-python)

View File

@ -1,6 +1,6 @@
;;; ob-ref.el --- Babel Functions for Referencing External Data -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Authors: Eric Schulte
;; Dan Davison
@ -59,8 +59,9 @@
(declare-function org-babel-lob-get-info "ob-lob" (&optional datum no-eval))
(declare-function org-element-at-point "org-element" (&optional pom cached-only))
(declare-function org-element-property "org-element" (property element))
(declare-function org-element-type "org-element" (element))
(declare-function org-element-property "org-element-ast" (property node))
(declare-function org-element-post-affiliated "org-element" (node))
(declare-function org-element-type "org-element-ast" (node &optional anonymous))
(declare-function org-end-of-meta-data "org" (&optional full))
(declare-function org-find-property "org" (property &optional value))
(declare-function org-id-find-id-file "org-id" (id))
@ -155,8 +156,9 @@ Emacs Lisp representation of the value of the variable."
(when (string-match "^\\(.+\\):\\(.+\\)$" ref)
(setq split-file (match-string 1 ref))
(setq split-ref (match-string 2 ref))
(find-file split-file)
(setq ref split-ref))
(when (file-exists-p split-file)
(find-file split-file)
(setq ref split-ref)))
(org-with-wide-buffer
(goto-char (point-min))
(let* ((params (append args '((:results . "none"))))
@ -171,7 +173,7 @@ Emacs Lisp representation of the value of the variable."
(let ((e (org-element-at-point)))
(when (equal (org-element-property :name e) ref)
(goto-char
(org-element-property :post-affiliated e))
(org-element-post-affiliated e))
(pcase (org-element-type e)
(`babel-call
(throw :found

View File

@ -1,6 +1,6 @@
;;; ob-ruby.el --- Babel Functions for Ruby -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
@ -73,7 +73,7 @@ It's possible to override it by using a header argument `:ruby'")
:type 'symbol)
(defun org-babel-execute:ruby (body params)
"Execute a block of Ruby code with Babel.
"Execute Ruby BODY according to PARAMS.
This function is called by `org-babel-execute-src-block'."
(let* ((session (org-babel-ruby-initiate-session
(cdr (assq :session params)) params))
@ -86,7 +86,7 @@ This function is called by `org-babel-execute-src-block'."
body params (org-babel-variable-assignments:ruby params)))
(result (if (member "xmp" result-params)
(with-temp-buffer
(require 'rcodetools)
(org-require-package 'rcodetools "rcodetools (gem package)")
(insert full-body)
(xmp (cdr (assq :xmp-option params)))
(buffer-string))
@ -127,7 +127,8 @@ This function is called by `org-babel-execute-src-block'."
;; helper functions
(defun org-babel-variable-assignments:ruby (params)
"Return list of ruby statements assigning the block's variables."
"Return list of ruby statements assigning the block's variables.
The assignments are defined in PARAMS."
(mapcar
(lambda (pair)
(format "%s=%s"
@ -140,7 +141,7 @@ This function is called by `org-babel-execute-src-block'."
Convert an elisp value into a string of ruby source code
specifying a variable of the same value."
(if (listp var)
(concat "[" (mapconcat #'org-babel-ruby-var-to-ruby var ", ") "]")
(concat "[" (mapconcat #'org-babel-ruby-var-to-ruby var ", \n") "]")
(if (eq var 'hline)
org-babel-ruby-hline-to
(format "%S" var))))
@ -152,20 +153,28 @@ Emacs-lisp table, otherwise return the results as a string."
(let ((res (org-babel-script-escape results)))
(if (listp res)
(mapcar (lambda (el) (if (not el)
org-babel-ruby-nil-to el))
org-babel-ruby-nil-to el))
res)
res)))
(defvar org-babel-ruby-prompt "_org_babel_ruby_prompt "
"String used for unique prompt.")
(defvar org-babel-ruby-define-prompt
(format "IRB.conf[:PROMPT][:CUSTOM] = { :PROMPT_I => \"%s\" }" org-babel-ruby-prompt))
(defun org-babel-ruby-initiate-session (&optional session params)
"Initiate a ruby session.
If there is not a current inferior-process-buffer in SESSION
then create one. Return the initialized session."
then create one. Return the initialized session.
Session settings (`:ruby' header arg value) are taken from PARAMS."
(unless (string= session "none")
(require 'inf-ruby)
(org-require-package 'inf-ruby)
(let* ((command (cdr (or (assq :ruby params)
(assoc inf-ruby-default-implementation
inf-ruby-implementations))))
(buffer (get-buffer (format "*%s*" session)))
(new-session? (not buffer))
(session-buffer (or buffer (save-window-excursion
(run-ruby-or-pop-to-buffer
(if (functionp command)
@ -176,16 +185,32 @@ then create one. Return the initialized session."
(inf-ruby-buffer)))
(current-buffer)))))
(if (org-babel-comint-buffer-livep session-buffer)
(progn (sit-for .25) session-buffer)
(progn
(sit-for .25)
;; Setup machine-readable prompt: no echo, prompts matching
;; uniquely by regexp.
(when new-session?
(with-current-buffer session-buffer
(setq-local
org-babel-comint-prompt-regexp-old comint-prompt-regexp
comint-prompt-regexp (concat "^" org-babel-ruby-prompt))
(insert org-babel-ruby-define-prompt ";")
(insert "_org_prompt_mode=conf.prompt_mode;conf.prompt_mode=:CUSTOM;")
(insert "conf.echo=false\n")
(comint-send-input nil t)))
session-buffer)
(sit-for .5)
(org-babel-ruby-initiate-session session)))))
(defvar org-babel-ruby-eoe-indicator ":org_babel_ruby_eoe"
"String to indicate that evaluation has completed.")
(defvar org-babel-ruby-f-write
"File.open('%s','w'){|f| f.write((_.class == String) ? _ : _.inspect)}")
(defvar org-babel-ruby-pp-f-write
"File.open('%s','w'){|f| $stdout = f; pp(results); $stdout = orig_out}")
(defvar org-babel-ruby-wrapper-method
"
def main()
@ -194,6 +219,7 @@ end
results = main()
File.open('%s', 'w'){ |f| f.write((results.class == String) ? results : results.inspect) }
")
(defvar org-babel-ruby-pp-wrapper-method
"
require 'pp'
@ -237,7 +263,6 @@ return the value of the last statement in BODY, as elisp."
(org-babel-comint-with-output
(buffer org-babel-ruby-eoe-indicator t eoe-string)
(insert eoe-string) (comint-send-input nil t))
;; Now we can start the evaluation.
(mapconcat
#'identity
(butlast
@ -246,14 +271,9 @@ return the value of the last statement in BODY, as elisp."
#'org-trim
(org-babel-comint-with-output
(buffer org-babel-ruby-eoe-indicator t body)
(mapc
(lambda (line)
(insert (org-babel-chomp line)) (comint-send-input nil t))
(list "conf.echo=false;_org_prompt_mode=conf.prompt_mode;conf.prompt_mode=:NULL"
body
"conf.prompt_mode=_org_prompt_mode;conf.echo=true"
eoe-string)))
"\n") "[\r\n]") 4) "\n")))
(insert (org-babel-chomp body) "\n" eoe-string)
(comint-send-input nil t))
"\n") "[\r\n]")) "\n")))
(`value
(let* ((tmp-file (org-babel-temp-file "ruby-"))
(ppp (or (member "code" result-params)
@ -273,7 +293,7 @@ return the value of the last statement in BODY, as elisp."
"results=_" "require 'pp'" "orig_out = $stdout"
(format org-babel-ruby-pp-f-write
(org-babel-process-file-name tmp-file 'noquote))))
(list org-babel-ruby-eoe-indicator)))
(list (format "puts \"%s\"" org-babel-ruby-eoe-indicator))))
(comint-send-input nil t))
(org-babel-eval-read-file tmp-file))))))

View File

@ -1,6 +1,6 @@
;;; ob-sass.el --- Babel Functions for the Sass CSS generation language -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research

View File

@ -1,6 +1,6 @@
;;; ob-scheme.el --- Babel Functions for Scheme -*- lexical-binding: t; -*-
;; Copyright (C) 2010-2023 Free Software Foundation, Inc.
;; Copyright (C) 2010-2024 Free Software Foundation, Inc.
;; Authors: Eric Schulte
;; Michael Gauland
@ -54,7 +54,7 @@
(defvar geiser-debug-jump-to-debug-p) ; Defined in geiser-debug.el
(defvar geiser-repl-use-other-window) ; Defined in geiser-repl.el
(defvar geiser-repl-window-allow-split) ; Defined in geiser-repl.el
(declare-function geiser-connect "ext:geiser-repl" (impl &optional host port))
(declare-function run-geiser "ext:geiser-repl" (impl))
(declare-function geiser "ext:geiser-repl" (impl))
(declare-function geiser-mode "ext:geiser-mode" ())
@ -65,6 +65,9 @@
(declare-function geiser-repl-exit "ext:geiser-repl" (&optional arg))
(declare-function geiser-eval--retort-output "ext:geiser-eval" (ret))
(declare-function geiser-eval--retort-result-str "ext:geiser-eval" (ret prefix))
(declare-function geiser-eval--retort-error "ext:geiser-eval" (ret))
(declare-function geiser-eval--retort-error-msg "ext:geiser-eval" (err))
(declare-function geiser-eval--error-msg "ext:geiser-eval" (err))
(defcustom org-babel-scheme-null-to 'hline
"Replace `null' and empty lists in scheme tables with this before returning."
@ -75,6 +78,17 @@
(defvar org-babel-default-header-args:scheme '()
"Default header arguments for scheme code blocks.")
(defconst org-babel-header-args:scheme '((host . :any)
(port . :any))
"Header arguments supported in Scheme.")
(defun org-babel-scheme-expand-header-arg-vars (vars)
"Expand :var header arguments given as VARS."
(mapconcat
(lambda (var)
(format "(define %S %S)" (car var) (cdr var)))
vars
"\n"))
(defun org-babel-expand-body:scheme (body params)
"Expand BODY according to PARAMS, return the expanded body."
@ -83,13 +97,7 @@
(postpends (cdr (assq :epilogue params))))
(concat (and prepends (concat prepends "\n"))
(if (null vars) body
(format "(let (%s)\n%s\n)"
(mapconcat
(lambda (var)
(format "%S" (print `(,(car var) ',(cdr var)))))
vars
"\n ")
body))
(concat (org-babel-scheme-expand-header-arg-vars vars) "\n" body))
(and postpends (concat "\n" postpends)))))
@ -116,13 +124,17 @@
(with-current-buffer (set-buffer buffer)
geiser-impl--implementation))
(defun org-babel-scheme-get-repl (impl name)
"Switch to a scheme REPL, creating it if it doesn't exist."
(defun org-babel-scheme-get-repl (impl name &optional host port)
"Switch to a Scheme REPL, creating it if it doesn't exist.
If the variables HOST and PORT are set, connect to the running Scheme REPL."
(let ((buffer (org-babel-scheme-get-session-buffer name)))
(or buffer
(progn
(if (fboundp 'geiser)
(geiser impl)
(if (and host port)
(geiser-connect impl host port)
(geiser impl))
;; Obsolete since Geiser 0.26.
(run-geiser impl))
(when name
@ -159,7 +171,7 @@ org-babel-scheme-execute-with-geiser will use a temporary session."
,@body
(current-message))))
(defun org-babel-scheme-execute-with-geiser (code output impl repl)
(defun org-babel-scheme-execute-with-geiser (code output impl repl &optional host port)
"Execute code in specified REPL.
If the REPL doesn't exist, create it using the given scheme
implementation.
@ -175,7 +187,7 @@ is true; otherwise returns the last value."
(let ((geiser-repl-window-allow-split nil)
(geiser-repl-use-other-window nil))
(let ((repl-buffer (save-current-buffer
(org-babel-scheme-get-repl impl repl))))
(org-babel-scheme-get-repl impl repl host port))))
(when (not (eq impl (org-babel-scheme-get-buffer-impl
(current-buffer))))
(message "Implementation mismatch: %s (%s) %s (%s)" impl (symbolp impl)
@ -193,22 +205,30 @@ is true; otherwise returns the last value."
#'geiser-eval-region)
(point-min)
(point-max))))
(setq result (if output
(let ((err (geiser-eval--retort-error ret)))
(setq result (cond
(output
(or (geiser-eval--retort-output ret)
"Geiser Interpreter produced no output")
(geiser-eval--retort-result-str ret "")))))
"Geiser Interpreter produced no output"))
(err nil)
(t (geiser-eval--retort-result-str ret ""))))
(when (not repl)
(save-current-buffer (set-buffer repl-buffer)
(geiser-repl-exit))
(set-process-query-on-exit-flag (get-buffer-process repl-buffer) nil)
(kill-buffer repl-buffer)))))
(kill-buffer repl-buffer))
(when err
(let ((msg (geiser-eval--error-msg err)))
(org-babel-eval-error-notify
nil
(concat (if (listp msg) (car msg) msg) "\n"))))))))))
result))
(defun org-babel-scheme--table-or-string (results)
"Convert RESULTS into an appropriate elisp value.
If the results look like a list or tuple, then convert them into an
Emacs-lisp table, otherwise return the results as a string."
(let ((res (org-babel-script-escape results)))
(let ((res (and results (org-babel-script-escape results))))
(cond ((listp res)
(mapcar (lambda (el)
(if (or (null el) (eq el 'null))
@ -231,6 +251,8 @@ This function is called by `org-babel-execute-src-block'."
geiser-scheme-implementation
geiser-default-implementation
(car geiser-active-implementations)))
(host (cdr (assq :host params)))
(port (cdr (assq :port params)))
(session (org-babel-scheme-make-session-name
source-buffer-name (cdr (assq :session params)) impl))
(full-body (org-babel-expand-body:scheme body params))
@ -240,7 +262,9 @@ This function is called by `org-babel-execute-src-block'."
full-body ; code
(string= result-type "output") ; output?
impl ; implementation
(and (not (string= session "none")) session)))) ; session
(and (not (string= session "none")) session) ; session
host ; REPL host
port))) ; REPL port
(let ((table
(org-babel-reassemble-table
result

View File

@ -1,6 +1,6 @@
;;; ob-screen.el --- Babel Support for Interactive Terminal -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Author: Benjamin Andresen
;; Maintainer: Ken Mankoff <mankoff@gmail.com>
@ -50,8 +50,8 @@ In case you want to use a different screen than one selected by your $PATH")
"Default arguments to use when running screen source blocks.")
(defun org-babel-execute:screen (body params)
"Send a block of code via screen to a terminal using Babel.
\"default\" session is used when none is specified."
"Send BODY via screen to a terminal using Babel, according to PARAMS.
\"default\" session is used when none is specified in the PARAMS."
(message "Sending source code block to interactive terminal session...")
(save-window-excursion
(let* ((session (cdr (assq :session params)))

View File

@ -1,6 +1,6 @@
;;; ob-sed.el --- Babel Functions for Sed Scripts -*- lexical-binding: t; -*-
;; Copyright (C) 2015-2023 Free Software Foundation, Inc.
;; Copyright (C) 2015-2024 Free Software Foundation, Inc.
;; Author: Bjarte Johansen
;; Keywords: literate programming, reproducible research

View File

@ -1,8 +1,9 @@
;;; ob-shell.el --- Babel Functions for Shell Evaluation -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Maintainer: Matthew Trzcinski <matt@excalamus.com>
;; Keywords: literate programming, reproducible research
;; URL: https://orgmode.org
@ -44,6 +45,11 @@
(declare-function orgtbl-to-generic "org-table" (table params))
(defvar org-babel-default-header-args:shell '())
(defconst org-babel-header-args:shell
'((async . ((yes no))))
"Shell-specific header arguments.")
(defvar org-babel-shell-names)
(defconst org-babel-shell-set-prompt-commands
@ -51,8 +57,6 @@
("fish" . "function fish_prompt\n\techo \"%s\"\nend")
;; prompt2 is like PS2 in POSIX shells.
("csh" . "set prompt=\"%s\"\nset prompt2=\"\"")
;; PowerShell, similar to fish, does not have PS2 equivalent.
("posh" . "function prompt { \"%s\" }")
;; PROMPT_COMMAND can override PS1 settings. Disable it.
;; Disable PS2 to avoid garbage in multi-line inputs.
(t . "PROMPT_COMMAND=;PS1=\"%s\";PS2="))
@ -66,28 +70,32 @@ that will be called with a single additional argument: prompt string.
The fallback association template is defined in (t . \"template\")
alist element.")
(defvar org-babel-prompt-command)
(defun org-babel-shell-initialize ()
"Define execution functions associated to shell names.
This function has to be called whenever `org-babel-shell-names'
is modified outside the Customize interface."
(interactive)
(dolist (name org-babel-shell-names)
(eval `(defun ,(intern (concat "org-babel-execute:" name))
(body params)
,(format "Execute a block of %s commands with Babel." name)
(let ((shell-file-name ,name)
(org-babel-prompt-command
(or (cdr (assoc ,name org-babel-shell-set-prompt-commands))
(alist-get t org-babel-shell-set-prompt-commands))))
(org-babel-execute:shell body params))))
(eval `(defalias ',(intern (concat "org-babel-variable-assignments:" name))
'org-babel-variable-assignments:shell
,(format "Return list of %s statements assigning to the block's \
(let ((fname (intern (concat "org-babel-execute:" name))))
(defalias fname
(lambda (body params)
(:documentation
(format "Execute a block of %s commands with Babel." name))
(let ((explicit-shell-file-name name)
(shell-file-name name))
(org-babel-execute:shell body params))))
(put fname 'definition-name 'org-babel-shell-initialize))
(defalias (intern (concat "org-babel-variable-assignments:" name))
#'org-babel-variable-assignments:shell
(format "Return list of %s statements assigning to the block's \
variables."
name)))
(eval `(defvar ,(intern (concat "org-babel-default-header-args:" name)) '()))))
name))
(funcall (if (fboundp 'defvar-1) #'defvar-1 #'set) ;Emacs-29
(intern (concat "org-babel-default-header-args:" name))
nil)
(funcall (if (fboundp 'defvar-1) #'defvar-1 #'set) ;Emacs-29
(intern (concat "org-babel-header-args:" name))
nil)))
(defcustom org-babel-shell-names
'("sh" "bash" "zsh" "fish" "csh" "ash" "dash" "ksh" "mksh" "posh")
@ -114,7 +122,7 @@ a shell execution being its exit code."
:package-version '(Org . "9.4"))
(defun org-babel-execute:shell (body params)
"Execute a block of Shell commands with Babel.
"Execute Shell BODY according to PARAMS.
This function is called by `org-babel-execute-src-block'."
(let* ((session (org-babel-sh-initiate-session
(cdr (assq :session params))))
@ -261,22 +269,38 @@ var of the same value."
(org-babel-comint-wait-for-output (current-buffer))
(org-babel-comint-input-command
(current-buffer)
(format org-babel-prompt-command org-babel-sh-prompt))
(setq-local comint-prompt-regexp
(concat "^" (regexp-quote org-babel-sh-prompt)
" *"))
(format
(or (cdr (assoc (file-name-nondirectory shell-file-name)
org-babel-shell-set-prompt-commands))
(alist-get t org-babel-shell-set-prompt-commands))
org-babel-sh-prompt))
(setq-local
org-babel-comint-prompt-regexp-old comint-prompt-regexp
comint-prompt-regexp
(concat "^" (regexp-quote org-babel-sh-prompt)
" *"))
;; Needed for Emacs 23 since the marker is initially
;; undefined and the filter functions try to use it without
;; checking.
(set-marker comint-last-output-start (point))
(get-buffer (current-buffer)))))))
(defconst ob-shell-async-indicator "echo 'ob_comint_async_shell_%s_%s'"
"Session output delimiter template.
See `org-babel-comint-async-indicator'.")
(defun ob-shell-async-chunk-callback (string)
"Filter applied to results before insertion.
See `org-babel-comint-async-chunk-callback'."
(replace-regexp-in-string comint-prompt-regexp "" string))
(defun org-babel-sh-evaluate (session body &optional params stdin cmdline)
"Pass BODY to the Shell process in BUFFER.
If RESULT-TYPE equals `output' then return a list of the outputs
of the statements in BODY, if RESULT-TYPE equals `value' then
return the value of the last statement in BODY."
(let* ((shebang (cdr (assq :shebang params)))
(async (org-babel-comint-use-async params))
(results-params (cdr (assq :result-params params)))
(value-is-exit-status
(or (and
@ -308,19 +332,37 @@ return the value of the last statement in BODY."
(concat (file-local-name script-file) " " cmdline)))))
(buffer-string))))
(session ; session evaluation
(mapconcat
#'org-babel-sh-strip-weird-long-prompt
(mapcar
#'org-trim
(butlast ; Remove eoe indicator
(org-babel-comint-with-output
(session org-babel-sh-eoe-output t body)
(insert (org-trim body) "\n"
org-babel-sh-eoe-indicator)
(comint-send-input nil t))
;; Remove `org-babel-sh-eoe-indicator' output line.
1))
"\n"))
(if async
(progn
(let ((uuid (org-id-uuid)))
(org-babel-comint-async-register
session
(current-buffer)
"ob_comint_async_shell_\\(.+\\)_\\(.+\\)"
'ob-shell-async-chunk-callback
nil)
(org-babel-comint-async-delete-dangling-and-eval
session
(insert (format ob-shell-async-indicator "start" uuid))
(comint-send-input nil t)
(insert (org-trim body))
(comint-send-input nil t)
(insert (format ob-shell-async-indicator "end" uuid))
(comint-send-input nil t))
uuid))
(mapconcat
#'org-babel-sh-strip-weird-long-prompt
(mapcar
#'org-trim
(butlast ; Remove eoe indicator
(org-babel-comint-with-output
(session org-babel-sh-eoe-output t body)
(insert (org-trim body) "\n"
org-babel-sh-eoe-indicator)
(comint-send-input nil t))
;; Remove `org-babel-sh-eoe-indicator' output line.
1))
"\n")))
;; External shell script, with or without a predefined
;; shebang.
((org-string-nw-p shebang)
@ -331,7 +373,13 @@ return the value of the last statement in BODY."
(when padline (insert "\n"))
(insert body))
(set-file-modes script-file #o755)
(org-babel-eval script-file "")))
(if (file-remote-p script-file)
;; Run remote script using its local path as COMMAND.
;; The remote execution is ensured by setting
;; correct `default-directory'.
(let ((default-directory (file-name-directory script-file)))
(org-babel-eval (file-local-name script-file) ""))
(org-babel-eval script-file ""))))
(t (org-babel-eval shell-file-name (org-trim body))))))
(when (and results value-is-exit-status)
(setq results (car (reverse (split-string results "\n" t)))))

View File

@ -1,6 +1,6 @@
;;; ob-sql.el --- Babel Functions for SQL -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Maintainer: Daniel Kraus <daniel@kraus.my>
@ -113,9 +113,7 @@
Set `sql-product' in Org edit buffer according to the
corresponding :engine source block header argument."
(let ((product (cdr (assq :engine (nth 2 info)))))
(condition-case nil
(sql-set-product product)
(user-error "Cannot set `sql-product' in Org Src edit buffer"))))
(sql-set-product product)))
(defun org-babel-sql-dbstring-mysql (host port user password database)
"Make MySQL cmd line args for database connection. Pass nil to omit that arg."
@ -409,11 +407,11 @@ argument mechanism."
val (if sqlite
nil
'(:fmt (lambda (el) (if (stringp el)
el
(format "%S" el))))))))
el
(format "%S" el))))))))
data-file)
(if (stringp val) val (format "%S" val))))
body)))
body t t)))
vars)
body)

View File

@ -1,6 +1,6 @@
;;; ob-sqlite.el --- Babel Functions for SQLite Databases -*- lexical-binding: t; -*-
;; Copyright (C) 2010-2023 Free Software Foundation, Inc.
;; Copyright (C) 2010-2024 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Maintainer: Nick Savage <nick@nicksavage.ca>
@ -57,13 +57,20 @@
(defun org-babel-expand-body:sqlite (body params)
"Expand BODY according to the values of PARAMS."
(org-babel-sql-expand-vars
body (org-babel--get-vars params) t))
(let ((prologue (cdr (assq :prologue params)))
(epilogue (cdr (assq :epilogue params))))
(mapconcat 'identity
(list
prologue
(org-babel-sql-expand-vars
body (org-babel--get-vars params) t)
epilogue)
"\n")))
(defvar org-babel-sqlite3-command "sqlite3")
(defun org-babel-execute:sqlite (body params)
"Execute a block of Sqlite code with Babel.
"Execute Sqlite BODY according to PARAMS.
This function is called by `org-babel-execute-src-block'."
(let ((result-params (split-string (or (cdr (assq :results params)) "")))
(db (cdr (assq :db params)))
@ -74,7 +81,6 @@ This function is called by `org-babel-execute-src-block'."
(lambda (arg) (car (assq arg params)))
(list :header :echo :bail :column
:csv :html :line :list)))))
(unless db (error "ob-sqlite: can't evaluate without a database"))
(with-temp-buffer
(insert
(org-babel-eval
@ -97,7 +103,7 @@ This function is called by `org-babel-execute-src-block'."
(member :html others) separator)
""
"-csv"))
(cons "db " db)))
(cons "db" (or db ""))))
;; body of the code block
(org-babel-expand-body:sqlite body params)))
(org-babel-result-cond result-params
@ -122,7 +128,8 @@ This function is called by `org-babel-execute-src-block'."
(org-babel-sql-expand-vars body vars t))
(defun org-babel-sqlite-table-or-scalar (result)
"If RESULT looks like a trivial table, then unwrap it."
"Cleanup cells in the RESULT table.
If RESULT is a trivial 1x1 table, then unwrap it."
(if (and (equal 1 (length result))
(equal 1 (length (car result))))
(org-babel-read (caar result) t)
@ -133,7 +140,7 @@ This function is called by `org-babel-execute-src-block'."
result)))
(defun org-babel-sqlite-offset-colnames (table headers-p)
"If HEADERS-P is non-nil then offset the first row as column names."
"If HEADERS-P is non-nil then offset the first row as column names in TABLE."
(if headers-p
(cons (car table) (cons 'hline (cdr table)))
table))

View File

@ -1,6 +1,6 @@
;;; ob-table.el --- Support for Calling Babel Functions from Tables -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
@ -87,18 +87,20 @@ is the equivalent of the following source code block:
results
#+end_src
NOTE: The quotation marks around the function name,
`source-block', are optional.
The quotation marks around the function name, `source-block', are
optional.
NOTE: By default, string variable names are interpreted as
references to source-code blocks, to force interpretation of a
cell's value as a string, prefix the identifier a \"$\" (e.g.,
\"$$2\" instead of \"$2\" or \"$@2$2\" instead of \"@2$2\").
By default, string variable names are interpreted as references to
source-code blocks, to force interpretation of a cell's value as a
string, prefix the identifier a \"$\" (e.g., \"$$2\" instead of \"$2\"
or \"$@2$2\" instead of \"@2$2\"). \"$\" will also force interpreting
string value literally: $\"value\" will refer to a string, not a
source block name.
NOTE: It is also possible to pass header arguments to the code
block. In this case a table cell should hold the string value of
the header argument which can then be passed before all variables
as shown in the example below.
It is also possible to pass header arguments to the code block. In
this case a table cell should hold the string value of the header
argument which can then be passed before all variables as shown in the
example below.
| 1 | 2 | :file nothing.png | nothing.png |
#+TBLFM: @1$4=\\='(org-sbe test-sbe $3 (x $1) (y $2))"
@ -117,7 +119,7 @@ as shown in the example below.
(prog1 nil (setq quote t))
(prog1
(cond
(quote (format "\"%s\"" el))
(quote (format "%S" el))
((stringp el) (org-no-properties el))
(t el))
(setq quote nil))))

View File

@ -1,6 +1,6 @@
;;; ob-tangle.el --- Extract Source Code From Org Files -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
@ -40,11 +40,11 @@
(declare-function org-babel-update-block-body "ob-core" (new-body))
(declare-function org-back-to-heading "org" (&optional invisible-ok))
(declare-function org-before-first-heading-p "org" ())
(declare-function org-element--cache-active-p "org-element" ())
(declare-function org-element-lineage "org-element" (datum &optional types with-self))
(declare-function org-element-property "org-element" (property element))
(declare-function org-element-lineage "org-element-ast" (datum &optional types with-self))
(declare-function org-element-property "org-element-ast" (property node))
(declare-function org-element-begin "org-element" (node))
(declare-function org-element-at-point "org-element" (&optional pom cached-only))
(declare-function org-element-type "org-element" (element))
(declare-function org-element-type-p "org-element-ast" (node types))
(declare-function org-heading-components "org" ())
(declare-function org-in-commented-heading-p "org" (&optional no-inheritance))
(declare-function org-in-archived-heading-p "org" (&optional no-inheritance))
@ -166,6 +166,23 @@ read-write permissions for the user, read-only for everyone else."
:package-version '(Org . "9.6")
:type 'integer)
(defcustom org-babel-tangle-remove-file-before-write 'auto
"How to overwrite the existing tangle target.
When set to nil, `org-babel-tangle' will replace contents of an existing
tangle target (and fail when tangle target is read-only).
When set to t, the tangle target (including read-only) will be deleted
first and a new file, possibly with different ownership and
permissions, will be created.
When set to symbol `auto', overwrite read-only tangle targets and
replace contents otherwise."
:group 'org-babel-tangle
:package-version '(Org . "9.7")
:type '(choice
(const :tag "Replace contents, but keep the same file" nil)
(const :tag "Re-create file" t)
(const :tag "Re-create when read-only" auto))
:safe t)
(defun org-babel-find-file-noselect-refresh (file)
"Find file ensuring that the latest changes on disk are
represented in the file."
@ -205,21 +222,20 @@ source code blocks by languages matching a regular expression.
Return list of the tangled file names."
(interactive "fFile to tangle: \nP")
(let* ((visited (find-buffer-visiting file))
(buffer (or visited (find-file-noselect file))))
(prog1
(with-current-buffer buffer
(org-with-wide-buffer
(mapcar #'expand-file-name
(org-babel-tangle nil target-file lang-re))))
(unless visited (kill-buffer buffer)))))
(org-with-file-buffer file
(org-with-wide-buffer
(mapcar #'expand-file-name
(org-babel-tangle nil target-file lang-re)))))
(defun org-babel-tangle-publish (_ filename pub-dir)
"Tangle FILENAME and place the results in PUB-DIR."
(unless (file-exists-p pub-dir)
(make-directory pub-dir t))
(setq pub-dir (file-name-as-directory pub-dir))
(mapc (lambda (el) (copy-file el pub-dir t)) (org-babel-tangle-file filename)))
;; Rename files to avoid copying to same file when publishing to ./
;; `copy-file' would throw an error when copying file to self.
(mapc (lambda (el) (rename-file el pub-dir t))
(org-babel-tangle-file filename)))
;;;###autoload
(defun org-babel-tangle (&optional arg target-file lang-re)
@ -253,7 +269,8 @@ matching a regular expression."
(when (equal arg '(16))
(or (cdr (assq :tangle (nth 2 (org-babel-get-src-block-info 'no-eval))))
(user-error "Point is not in a source code block"))))
path-collector)
path-collector
(source-file buffer-file-name))
(mapc ;; map over file-names
(lambda (by-fn)
(let ((file-name (car by-fn)))
@ -310,10 +327,28 @@ matching a regular expression."
(compare-buffer-substrings
nil nil nil
tangle-buf nil nil)))))))
;; erase previous file
(when (file-exists-p file-name)
(when (equal (if (file-name-absolute-p file-name)
file-name
(expand-file-name file-name))
(if (file-name-absolute-p source-file)
source-file
(expand-file-name source-file)))
(error "Not allowed to tangle into the same file as self"))
;; We do not erase, but overwrite previous file
;; to preserve any existing symlinks.
;; This behavior is modified using
;; `org-babel-tangle-remove-file-before-write' to
;; tangle to read-only files.
(when (and
(file-exists-p file-name)
(pcase org-babel-tangle-remove-file-before-write
(`auto (not (file-writable-p file-name)))
(`t t)
(`nil nil)
(_ (error "Invalid value of `org-babel-tangle-remove-file-before-write': %S"
org-babel-tangle-remove-file-before-write))))
(delete-file file-name))
(write-region nil nil file-name)
(write-region nil nil file-name)
(mapc (lambda (mode) (set-file-modes file-name mode)) modes))
(push file-name path-collector))))))
(if (equal arg '(4))
@ -378,7 +413,7 @@ references."
(goto-char (point-min))
(while (or (re-search-forward "\\[\\[file:.*\\]\\[.*\\]\\]" nil t)
(re-search-forward (org-babel-noweb-wrap) nil t))
(delete-region (save-excursion (beginning-of-line 1) (point))
(delete-region (save-excursion (forward-line) (point))
(save-excursion (end-of-line 1) (forward-char 1) (point)))))
(defun org-babel-spec-to-string (spec)
@ -427,17 +462,19 @@ that the appropriate major-mode is set. SPEC has the form:
org-babel-tangle-comment-format-end link-data)))))
(defun org-babel-effective-tangled-filename (buffer-fn src-lang src-tfile)
"Return effective tangled filename of a source-code block.
BUFFER-FN is the name of the buffer, SRC-LANG the language of the
block and SRC-TFILE is the value of the :tangle header argument,
as computed by `org-babel-tangle-single-block'."
(let ((base-name (cond
((string= "yes" src-tfile)
;; Use the buffer name
(file-name-sans-extension buffer-fn))
((string= "no" src-tfile) nil)
((> (length src-tfile) 0) src-tfile)))
(ext (or (cdr (assoc src-lang org-babel-tangle-lang-exts)) src-lang)))
"Return effective tangled absolute filename of a source-code block.
BUFFER-FN is the absolute file name of the buffer, SRC-LANG the
language of the block and SRC-TFILE is the value of the :tangle
header argument, as computed by `org-babel-tangle-single-block'."
(let* ((fnd (file-name-directory buffer-fn))
(base-name (cond
((string= "yes" src-tfile)
;; Use the buffer name
(file-name-sans-extension buffer-fn))
((string= "no" src-tfile) nil)
((> (length src-tfile) 0)
(expand-file-name src-tfile fnd))))
(ext (or (cdr (assoc src-lang org-babel-tangle-lang-exts)) src-lang)))
(when base-name
;; decide if we want to add ext to base-name
(if (and ext (string= "yes" src-tfile))
@ -454,13 +491,16 @@ source code blocks by languages matching a regular expression.
Optional argument TANGLE-FILE can be used to limit the collected
code blocks by target file."
(let ((counter 0) last-heading-pos blocks)
(let ((counter 0)
(buffer-fn (buffer-file-name (buffer-base-buffer)))
last-heading-pos blocks)
(org-babel-map-src-blocks (buffer-file-name)
(let ((current-heading-pos
(if (org-element--cache-active-p)
(or (org-element-property :begin (org-element-lineage (org-element-at-point) '(headline) t)) 1)
(org-with-wide-buffer
(org-with-limited-levels (outline-previous-heading))))))
(or (org-element-begin
(org-element-lineage
(org-element-at-point)
'headline t))
1)))
(if (eq last-heading-pos current-heading-pos) (cl-incf counter)
(setq counter 1)
(setq last-heading-pos current-heading-pos)))
@ -470,6 +510,7 @@ code blocks by target file."
(src-lang (nth 0 info))
(src-tfile (cdr (assq :tangle (nth 2 info)))))
(unless (or (string= src-tfile "no")
(not src-lang) ;; src block without lang
(and tangle-file (not (equal tangle-file src-tfile)))
(and lang-re (not (string-match-p lang-re src-lang))))
;; Add the spec for this block to blocks under its tangled
@ -477,7 +518,7 @@ code blocks by target file."
(let* ((block (org-babel-tangle-single-block counter))
(src-tfile (cdr (assq :tangle (nth 4 block))))
(file-name (org-babel-effective-tangled-filename
(nth 1 block) src-lang src-tfile))
buffer-fn src-lang src-tfile))
(by-fn (assoc file-name blocks)))
(if by-fn (setcdr by-fn (cons (cons src-lang block) (cdr by-fn)))
(push (cons file-name (list (cons src-lang block))) blocks)))))))
@ -491,12 +532,7 @@ code blocks by target file."
The PARAMS are the 3rd element of the info for the same src block."
(unless (string= "no" (cdr (assq :comments params)))
(save-match-data
(let* (;; The created link is transient. Using ID is not necessary,
;; but could have side-effects if used. An ID property may
;; be added to existing entries thus creating unexpected file
;; modifications.
(org-id-link-to-org-use-id nil)
(l (org-no-properties
(let* ((l (org-no-properties
(cl-letf (((symbol-function 'org-store-link-functions)
(lambda () nil)))
(org-store-link nil))))
@ -589,13 +625,12 @@ non-nil, return the full association list to be used by
link
source-name
params
(if org-src-preserve-indentation
(org-trim body t)
(if (org-src-preserve-indentation-p) (org-trim body t)
(org-trim (org-remove-indentation body)))
comment)))
(if only-this-block
(let* ((file-name (org-babel-effective-tangled-filename
(nth 1 result) src-lang src-tfile)))
file src-lang src-tfile)))
(list (cons file-name (list (cons src-lang result)))))
result)))
@ -616,9 +651,12 @@ by `org-babel-get-src-block-info'."
;; de-tangling functions
(defun org-babel-detangle (&optional source-code-file)
"Propagate changes in source file back original to Org file.
"Propagate changes from current source buffer back to the original Org file.
This requires that code blocks were tangled with link comments
which enable the original code blocks to be found."
which enable the original code blocks to be found.
Optional argument SOURCE-CODE-FILE is the file path to be used instead
of the current buffer."
(interactive)
(save-excursion
(when source-code-file (find-file source-code-file))
@ -673,8 +711,7 @@ which enable the original code blocks to be found."
(org-back-to-heading t))
;; Do not skip the first block if it begins at point min.
(cond ((or (org-at-heading-p)
(not (eq (org-element-type (org-element-at-point))
'src-block)))
(not (org-element-type-p (org-element-at-point) 'src-block)))
(org-babel-next-src-block n))
((= n 1))
(t (org-babel-next-src-block (1- n)))))

View File

@ -1,6 +1,6 @@
;;; ob.el --- Working with Code Blocks in Org -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Authors: Eric Schulte
;; Keywords: literate programming, reproducible research

View File

@ -1,6 +1,6 @@
;;; oc-basic.el --- basic back-end for citations -*- lexical-binding: t; -*-
;;; oc-basic.el --- basic backend for citations -*- lexical-binding: t; -*-
;; Copyright (C) 2021-2023 Free Software Foundation, Inc.
;; Copyright (C) 2021-2024 Free Software Foundation, Inc.
;; Author: Nicolas Goaziou <mail@nicolasgoaziou.fr>
@ -78,9 +78,19 @@
(declare-function org-open-at-point "org" (&optional arg))
(declare-function org-open-file "org" (path &optional in-emacs line search))
(declare-function org-element-create "org-element-ast" (type &optional props &rest children))
(declare-function org-element-set "org-element-ast" (old new &optional keep-props))
(declare-function org-element-interpret-data "org-element" (data))
(declare-function org-element-property "org-element" (property element))
(declare-function org-element-type "org-element" (element))
(declare-function org-element-parse-secondary-string "org-element" (string restriction &optional parent))
(declare-function org-element-map "org-element"
( data types fun
&optional
info first-match no-recursion
with-affiliated no-undefer))
(declare-function org-element-property "org-element-ast" (property node))
(declare-function org-element-type-p "org-element-ast" (node types))
(declare-function org-element-contents "org-element-ast" (node))
(declare-function org-export-data "org-export" (data info))
(declare-function org-export-derived-backend-p "org-export" (backend &rest backends))
@ -272,6 +282,9 @@ Optional argument INFO is the export state, as a property list."
(plist-get info :cite-basic/bibliography)
(let ((results nil))
(dolist (file (org-cite-list-bibliography-files))
;; Follow symlinks, to look into modification time of the
;; actual file, not its symlink.
(setq file (file-truename file))
(when (file-readable-p file)
(with-temp-buffer
(when (or (org-file-has-changed-p file)
@ -330,9 +343,11 @@ FIELD is a symbol. ENTRY-OR-KEY is either an association list, as returned by
Optional argument INFO is the export state, as a property list.
Return value may be nil or a string. If current export back-end is derived
from `latex', return a raw string instead, unless optional argument RAW is
non-nil."
Return value may be nil or a string. If current export backend is derived
from `latex', return a raw string object instead, unless optional
argument RAW is non-nil.
Throw an error if the field value is non-string and non-nil."
(let ((value
(cdr
(assq field
@ -343,6 +358,8 @@ non-nil."
entry-or-key)
(_
(error "Wrong value for ENTRY-OR-KEY: %S" entry-or-key)))))))
(when (and value (not (stringp value)))
(error "Non-string bibliography field value: %S" value))
(if (and value
(not raw)
(org-export-derived-backend-p (plist-get info :back-end) 'latex))
@ -351,17 +368,27 @@ non-nil."
(defun org-cite-basic--shorten-names (names)
"Return a list of family names from a list of full NAMES.
NAMES can be a string or raw string object.
To better accomomodate corporate names, this will only shorten
personal names of the form \"family, given\"."
(when (stringp names)
(mapconcat
(lambda (name)
(if (eq 1 (length name))
(cdr (split-string name))
(car (split-string name ", "))))
(split-string names " and ")
", ")))
(let (names-string raw-p)
(cond
((stringp names) (setq names-string names))
((org-element-type-p names 'raw)
(setq names-string (mapconcat #'identity (org-element-contents names) "")
raw-p t)))
(when names-string
(setq names-string
(mapconcat
(lambda (name)
(if (eq 1 (length name))
(cdr (split-string name))
(car (split-string name ", "))))
(split-string names-string " and ")
", "))
(if raw-p (org-export-raw-string names-string)
names-string))))
(defun org-cite-basic--number-to-suffix (n)
"Compute suffix associated to number N.
@ -417,7 +444,7 @@ necessary, unless optional argument NO-SUFFIX is non-nil."
(year
(or (org-cite-basic--get-field 'year entry-or-key info 'raw)
(let ((date
(org-cite-basic--get-field 'date entry-or-key info t)))
(org-cite-basic--get-field 'date entry-or-key info 'raw)))
(and (stringp date)
(string-match (rx string-start
(group (= 4 digit))
@ -445,6 +472,38 @@ necessary, unless optional argument NO-SUFFIX is non-nil."
new))))
(if no-suffix year (concat year suffix)))))))
(defun org-cite-basic--print-bibtex-string (element &optional info)
"Print Bibtex formatted string ELEMENT, according to Bibtex syntax.
Remove all the {...} that are not a part of LaTeX macros and parse the
LaTeX fragments. Do nothing when current backend is derived from
LaTeX, according to INFO.
Return updated ELEMENT."
(if (org-export-derived-backend-p (plist-get info :back-end) 'latex)
;; Derived from LaTeX, no need to use manual ad-hoc LaTeX
;; parser.
element
;; Convert ELEMENT to anonymous when ELEMENT is string.
;; Otherwise, we cannot modify ELEMENT by side effect.
(when (org-element-type-p element 'plain-text)
(setq element (org-element-create 'anonymous nil element)))
;; Approximately parse LaTeX fragments, assuming Org mode syntax
;; (it is close to original LaTeX, and we do not want to
;; re-implement complete LaTeX parser here))
(org-element-map element t
(lambda (str)
(when (stringp str)
(org-element-set
str
(org-element-parse-secondary-string
str '(latex-fragment entity))))))
;; Strip the remaining { and }.
(org-element-map element t
(lambda (str)
(when (stringp str)
(org-element-set str (replace-regexp-in-string "[{}]" "" str)))))
element))
(defun org-cite-basic--print-entry (entry style &optional info)
"Format ENTRY according to STYLE string.
ENTRY is an alist, as returned by `org-cite-basic--get-entry'.
@ -456,27 +515,29 @@ Optional argument INFO is the export state, as a property list."
(org-cite-basic--get-field 'journal entry info)
(org-cite-basic--get-field 'institution entry info)
(org-cite-basic--get-field 'school entry info))))
(pcase style
("plain"
(let ((year (org-cite-basic--get-year entry info 'no-suffix)))
(org-cite-concat
(org-cite-basic--shorten-names author) ". "
title (and from (list ", " from)) ", " year ".")))
("numeric"
(let ((n (org-cite-basic--key-number (cdr (assq 'id entry)) info))
(year (org-cite-basic--get-year entry info 'no-suffix)))
(org-cite-concat
(format "[%d] " n) author ", "
(org-cite-emphasize 'italic title)
(and from (list ", " from)) ", "
year ".")))
;; Default to author-year. Use year disambiguation there.
(_
(let ((year (org-cite-basic--get-year entry info)))
(org-cite-concat
author " (" year "). "
(org-cite-emphasize 'italic title)
(and from (list ", " from)) "."))))))
(org-cite-basic--print-bibtex-string
(pcase style
("plain"
(let ((year (org-cite-basic--get-year entry info 'no-suffix)))
(org-cite-concat
(org-cite-basic--shorten-names author) ". "
title (and from (list ", " from)) ", " year ".")))
("numeric"
(let ((n (org-cite-basic--key-number (cdr (assq 'id entry)) info))
(year (org-cite-basic--get-year entry info 'no-suffix)))
(org-cite-concat
(format "[%d] " n) author ", "
(org-cite-emphasize 'italic title)
(and from (list ", " from)) ", "
year ".")))
;; Default to author-year. Use year disambiguation there.
(_
(let ((year (org-cite-basic--get-year entry info)))
(org-cite-concat
author " (" year "). "
(org-cite-emphasize 'italic title)
(and from (list ", " from)) "."))))
info)))
;;; "Activate" capability
@ -580,8 +641,8 @@ INFO is the export state, as a property list."
(suffix (org-element-property :suffix ref)))
(funcall format-ref
prefix
(org-cite-basic--get-author k info)
(org-cite-basic--get-year k info)
(or (org-cite-basic--get-author k info) "??")
(or (org-cite-basic--get-year k info) "????")
suffix)))
(org-cite-get-references citation)
org-cite-basic-author-year-separator)
@ -649,20 +710,30 @@ export communication channel, as a property list."
;; "author" style.
(`(,(or "author" "a") . ,variant)
(let ((caps (member variant '("caps" "c"))))
(org-export-data
(mapconcat
(lambda (key)
(let ((author (org-cite-basic--get-author key info)))
(if caps (capitalize author) author)))
(org-cite-get-references citation t)
org-cite-basic-author-year-separator)
(org-cite-basic--format-author-year
citation
(lambda (p c s) (org-cite-concat p c s))
(lambda (prefix author _ suffix)
(org-cite-concat
prefix
(if caps (org-cite-capitalize author) author)
suffix))
info)))
;; "noauthor" style.
(`(,(or "noauthor" "na") . ,variant)
(format (if (funcall has-variant-p variant 'bare) "%s" "(%s)")
(mapconcat (lambda (key) (org-cite-basic--get-year key info))
(org-cite-get-references citation t)
org-cite-basic-author-year-separator)))
(let ((bare? (funcall has-variant-p variant 'bare)))
(org-cite-basic--format-author-year
citation
(lambda (prefix contents suffix)
(org-cite-concat
(unless bare? "(")
prefix
contents
suffix
(unless bare? ")")))
(lambda (prefix _ year suffix)
(org-cite-concat prefix year suffix))
info)))
;; "nocite" style.
(`(,(or "nocite" "n") . ,_) nil)
;; "text" and "note" styles.
@ -678,10 +749,11 @@ export communication channel, as a property list."
(lambda (p c s) (org-cite-concat p c s))
(lambda (p a y s)
(org-cite-concat p
(if caps (capitalize a) a)
(if caps (org-cite-capitalize a) a)
(if bare " " " (")
y s
(and (not bare) ")")))
y
(and (not bare) ")")
s))
info)))
;; "numeric" style.
;;
@ -702,7 +774,7 @@ export communication channel, as a property list."
(lambda (p c s)
(org-cite-concat (and (not bare) "(") p c s (and (not bare) ")")))
(lambda (p a y s)
(org-cite-concat p (if caps (capitalize a) a) ", " y s))
(org-cite-concat p (if caps (org-cite-capitalize a) a) ", " y s))
info)))
;; This should not happen.
(_ (error "Invalid style: %S" style)))))
@ -710,7 +782,7 @@ export communication channel, as a property list."
(defun org-cite-basic-export-bibliography (keys _files style _props backend info)
"Generate bibliography.
KEYS is the list of cited keys, as strings. STYLE is the expected bibliography
style, as a string. BACKEND is the export back-end, as a symbol. INFO is the
style, as a string. BACKEND is the export backend, as a symbol. INFO is the
export state, as a property list."
(mapconcat
(lambda (entry)
@ -734,7 +806,7 @@ When DATUM is a citation reference, open bibliography entry referencing
the citation key. Otherwise, select which key to follow among all keys
present in the citation."
(let* ((key
(if (eq 'citation-reference (org-element-type datum))
(if (org-element-type-p datum 'citation-reference)
(org-element-property :key datum)
(pcase (org-cite-get-references datum t)
(`(,key) key)
@ -806,7 +878,7 @@ Return nil if there are no bibliography files or no entries."
(let ((date (org-cite-basic--get-year entry nil 'no-suffix)))
(format "%4s" (or date "")))
org-cite-basic-column-separator
(org-cite-basic--get-field 'title entry nil t))))
(org-cite-basic--get-field 'title entry nil 'raw))))
(puthash completion key org-cite-basic--completion-cache)))
(unless (map-empty-p org-cite-basic--completion-cache) ;no key
(puthash entries t org-cite-basic--completion-cache)

View File

@ -1,6 +1,6 @@
;;; oc-biblatex.el --- biblatex citation processor for Org -*- lexical-binding: t; -*-
;; Copyright (C) 2021-2023 Free Software Foundation, Inc.
;; Copyright (C) 2021-2024 Free Software Foundation, Inc.
;; Author: Nicolas Goaziou <mail@nicolasgoaziou.fr>
@ -70,7 +70,8 @@
(require 'org-macs)
(require 'oc)
(declare-function org-element-property "org-element" (property element))
(declare-function org-element-property "org-element-ast" (property node))
(declare-function org-element-parent "org-element-ast" (node))
(declare-function org-export-data "org-export" (data info))
@ -231,7 +232,7 @@ When NO-OPT argument is non-nil, only provide mandatory arguments."
(let* ((origin (pcase references
(`(,reference) reference)
(`(,reference . ,_)
(org-element-property :parent reference))))
(org-element-parent reference))))
(suffix (org-element-property :suffix origin))
(prefix (org-element-property :prefix origin)))
(concat (and prefix
@ -375,61 +376,47 @@ INFO is the export state, as a property list."
(other
(user-error "Invalid entry %S in `org-cite-biblatex-styles'" other))))))
(defun org-cite-biblatex-prepare-preamble (output _keys files style &rest _)
"Prepare document preamble for \"biblatex\" usage.
(defun org-cite-biblatex--generate-latex-usepackage (info)
"Ensure that the biblatex package is loaded.
This is performed by extracting relevant information from the
INFO export plist, and modifying any existing
\\usepackage{biblatex} statement in the LaTeX header."
(let ((style (org-cite-bibliography-style info))
(usepackage-rx (rx "\\usepackage"
(opt (group "[" (*? anything) "]"))
"{biblatex}")))
(concat
(if (string-match usepackage-rx (plist-get info :latex-full-header))
;; "biblatex" package loaded, but with none (or different) options.
;; Replace with style-including command.
(plist-put info :latex-full-header
(replace-match
(format "\\usepackage%s{biblatex}"
(save-match-data
(org-cite-biblatex--package-options nil style)))
t t
(plist-get info :latex-full-header)))
;; No "biblatex" package loaded. Insert "usepackage" command
;; with appropriate options, including style.
(format "\\usepackage%s{biblatex}\n"
(org-cite-biblatex--package-options
org-cite-biblatex-options style))))))
OUTPUT is the final output of the export process. FILES is the list of file
names used as the bibliography.
This function ensures \"biblatex\" package is required. It also adds resources
to the document, and set styles."
(with-temp-buffer
(save-excursion (insert output))
(when (search-forward "\\begin{document}" nil t)
;; Ensure there is a \usepackage{biblatex} somewhere or add one.
;; Then set options.
(goto-char (match-beginning 0))
(let ((re (rx "\\usepackage"
(opt (group "[" (*? anything) "]"))
"{biblatex}")))
(cond
;; No "biblatex" package loaded. Insert "usepackage" command
;; with appropriate options, including style.
((not (re-search-backward re nil t))
(save-excursion
(insert
(format "\\usepackage%s{biblatex}\n"
(org-cite-biblatex--package-options
org-cite-biblatex-options style)))))
;; "biblatex" package loaded, but without any option.
;; Include style only.
((not (match-beginning 1))
(search-forward "{" nil t)
(insert (org-cite-biblatex--package-options nil style)))
;; "biblatex" package loaded with some options set. Override
;; style-related options with ours.
(t
(replace-match
(save-match-data
(org-cite-biblatex--package-options (match-string 1) style))
nil nil nil 1))))
;; Insert resources below.
(forward-line)
(insert (mapconcat (lambda (f)
(format "\\addbibresource%s{%s}"
(if (org-url-p f) "[location=remote]" "")
f))
files
"\n")
"\n"))
(buffer-string)))
(defun org-cite-biblatex--generate-latex-bibresources (info)
"From INFO generate LaTeX that loads the relevant bibliography resource files."
(let ((files (plist-get info :bibliography)))
(mapconcat (lambda (f)
(format "\\addbibresource%s{%s}"
(if (org-url-p f) "[location=remote]" "")
f))
files
"\n")))
;;; Register `biblatex' processor
(org-cite-register-processor 'biblatex
:export-bibliography #'org-cite-biblatex-export-bibliography
:export-citation #'org-cite-biblatex-export-citation
:export-finalizer #'org-cite-biblatex-prepare-preamble
:cite-styles #'org-cite-biblatex-list-styles)
(provide 'oc-biblatex)

View File

@ -1,6 +1,6 @@
;;; oc-bibtex.el --- Vanilla citation processor for LaTeX -*- lexical-binding: t; -*-
;; Copyright (C) 2021-2023 Free Software Foundation, Inc.
;; Copyright (C) 2021-2024 Free Software Foundation, Inc.
;; Author: Nicolas Goaziou <mail@nicolasgoaziou.fr>
@ -41,7 +41,7 @@
(require 'oc)
(declare-function org-element-property "org-element" (property element))
(declare-function org-element-property "org-element-ast" (property node))
(declare-function org-export-data "org-export" (data info))

View File

@ -1,6 +1,6 @@
;;; oc-csl.el --- csl citation processor for Org -*- lexical-binding: t; -*-
;; Copyright (C) 2021-2023 Free Software Foundation, Inc.
;; Copyright (C) 2021-2024 Free Software Foundation, Inc.
;; Author: Nicolas Goaziou <mail@nicolasgoaziou.fr>
;; Maintainer: András Simonyi <andras.simonyi@gmail.com>
@ -137,8 +137,8 @@
(declare-function org-element-interpret-data "org-element" (data))
(declare-function org-element-map "org-element" (data types fun &optional info first-match no-recursion with-affiliated))
(declare-function org-element-property "org-element" (property element))
(declare-function org-element-put-property "org-element" (element property value))
(declare-function org-element-property "org-element-ast" (property node))
(declare-function org-element-put-property "org-element-ast" (node property value))
(declare-function org-export-data "org-export" (data info))
(declare-function org-export-derived-backend-p "org-export" (backend &rest backends))
@ -184,8 +184,8 @@ looks for style files in this directory, too."
:safe #'booleanp)
(defcustom org-cite-csl-no-citelinks-backends '(ascii)
"List of export back-ends for which cite linking is disabled.
Cite linking for export back-ends derived from any of the back-ends listed here,
"List of export backends for which cite linking is disabled.
Cite linking for export backends derived from any of the backends listed here,
is also disabled."
:group 'org-cite
:package-version '(Org . "9.5")
@ -214,6 +214,112 @@ Used only when `second-field-align' is activated by the used CSL style."
:type 'string
:safe #'stringp)
(defcustom org-cite-csl-latex-label-separator "0.6em"
"Distance between citation label and bibliography item for LaTeX output.
The value is a string representing the distance in valid LaTeX units.
Used only when `second-field-align' is activated by the used CSL
style.
The indentation length in these cases is computed as the sum of
`org-cite-csl-latex-label-separator' and the maximal label width, for
example,
indentation length
<------------------------->
max. label width separator
<---------------><-------->
[Doe22] John Doe. A title...
[DoeSmithJones19] John Doe, Jane Smith and...
[SmithDoe02] Jane Smith and John Doe...
The maximal label width, in turn, is calculated as the product of
`org-cite-csl-latex-label-width-per-char' and the maximal label
length measured in characters."
:group 'org-cite
:package-version '(Org . "9.7")
:type 'string
:safe #'stringp)
(defcustom org-cite-csl-latex-label-width-per-char "0.45em"
"Character width in LaTeX units for calculating entry label widths.
Used only when `second-field-align' is activated by the used CSL
style.
See the documentation of `org-cite-csl-latex-label-separator' for
details."
:group 'org-cite
:package-version '(Org . "9.7")
:type 'string
:safe #'stringp)
;; The following was inspired by and in many details follows how
;; Pandoc's (<https://github.com/jgm/pandoc>) default LaTeX template
;; handles CSL output. Many thanks to the author, John MacFarlane!
(defcustom org-cite-csl-latex-preamble
"\\usepackage{calc}
\\newlength{\\cslhangindent}
\\setlength{\\cslhangindent}{[CSL-HANGINDENT]}
\\newlength{\\csllabelsep}
\\setlength{\\csllabelsep}{[CSL-LABELSEP]}
\\newlength{\\csllabelwidth}
\\setlength{\\csllabelwidth}{[CSL-LABELWIDTH-PER-CHAR] * [CSL-MAXLABEL-CHARS]}
\\newenvironment{cslbibliography}[2] % 1st arg. is hanging-indent, 2nd entry spacing.
{% By default, paragraphs are not indented.
\\setlength{\\parindent}{0pt}
% Hanging indent is turned on when first argument is 1.
\\ifodd #1
\\let\\oldpar\\par
\\def\\par{\\hangindent=\\cslhangindent\\oldpar}
\\fi
% Set entry spacing based on the second argument.
\\setlength{\\parskip}{\\parskip + #2\\baselineskip}
}%
{}
\\newcommand{\\cslblock}[1]{#1\\hfill\\break}
\\newcommand{\\cslleftmargin}[1]{\\parbox[t]{\\csllabelsep + \\csllabelwidth}{#1}}
\\newcommand{\\cslrightinline}[1]
{\\parbox[t]{\\linewidth - \\csllabelsep - \\csllabelwidth}{#1}\\break}
\\newcommand{\\cslindent}[1]{\\hspace{\\cslhangindent}#1}
\\newcommand{\\cslbibitem}[2]
{\\leavevmode\\vadjust pre{\\hypertarget{citeproc_bib_item_#1}{}}#2}
\\makeatletter
\\newcommand{\\cslcitation}[2]
{\\protect\\hyper@linkstart{cite}{citeproc_bib_item_#1}#2\\hyper@linkend}
\\makeatother"
"LaTeX preamble content inserted by the `csl' citation processor.
This preamble can be anything as long as it provides definitions
for the environment and commands that Citeproc's `org-latex'
formatter uses for formatting citations and bibliographies. In
particular, it has to define
- the commands \\cslblock{<text>}, \\cslleftmargin{<text>},
\\cslrightinline{<text>} and \\cslindent{<text>} for formatting
text that have, respectively, the CSL display attributes
`block', `left-margin', `right-inline' and `indent';
- the commands \\cslcitation{<item_no>}{<item_text>} and
\\cslbibitem{<item_no>}{<item_text>}, which are used to
format individual citations and bibliography items, including
hyperlinking citations to the corresponding bibliography entry
using their numerical id, which is passed as the first,
<item_no> argument;
- and the environment \\cslbibliography{<hanging-indent>}{<entry-spacing>},
in which bibliographies are wrapped; the value of the
<hanging-indent> argument is 1 if hanging indent should be
applied and 0 if not, while the <entry-spacing> argument is an
integer specifying the number of extra line-heights
required between bibliography entries in addition to normal
line spacing.
When present, the placeholders [CSL-HANGINDENT], [CSL-LABELSEP],
[CSL-LABELWIDTH-PER-CHAR] and [CSL-MAXLABEL-CHARS] are replaced,
respectively, by the contents of the customizable variables
`org-cite-csl-latex-hanging-indent', `org-cite-csl-latex-label-separator',
`org-cite-csl-latex-label-width-per-char', and the maximal label length
in the bibliography measured in characters."
:group 'org-cite
:type 'string
:package-version '(Org . "9.7"))
;;; Internal variables
(defconst org-cite-csl--etc-dir
@ -277,13 +383,17 @@ If nil then the Chicago author-date style is used as a fallback.")
("paragraph" . "paragraph")
("para." . "paragraph")
("paras." . "paragraph")
("\\P" . "paragraph")
("" . "paragraph")
("\\P\\P" . "paragraph")
("¶¶" . "paragraph")
("part" . "part")
("pt." . "part")
("pts." . "part")
("§" . "section")
("\\S" . "section")
("§§" . "section")
("\\S\\S" . "section")
("section" . "section")
("sec." . "section")
("secs." . "section")
@ -312,6 +422,7 @@ Label is in match group 1.")
;;; Internal functions
;; FIXME: We use `org-require-package' in other places.
(defun org-cite-csl--barf-without-citeproc ()
"Raise an error if Citeproc library is not loaded."
(unless (featurep 'citeproc)
@ -332,8 +443,8 @@ INFO is the export state, as a property list."
(defun org-cite-csl--create-structure-params (citation info)
"Return citeproc structure creation params for CITATION object.
STYLE is the citation style, as a string or nil. INFO is the export state, as
a property list."
STYLE is the citation style, as a string or nil. INFO is the export
state, as a property list."
(let ((style (org-cite-citation-style citation info)))
(pcase style
;; "author" style.
@ -393,7 +504,8 @@ a property list."
(_ (error "Invalid style: %S" style)))))
(defun org-cite-csl--no-citelinks-p (info)
"Non-nil when export BACKEND should not create cite-reference links."
"Non-nil when export backend should not create cite-reference links.
INFO is the info channel plist."
(or (not org-cite-csl-link-cites)
(and org-cite-csl-no-citelinks-backends
(apply #'org-export-derived-backend-p
@ -413,7 +525,7 @@ corresponding to one of the output formats supported by Citeproc: `html',
(let ((backend (plist-get info :back-end)))
(cond
((org-export-derived-backend-p backend 'html) 'html)
((org-export-derived-backend-p backend 'latex) 'latex)
((org-export-derived-backend-p backend 'latex) 'org-latex)
(t 'org))))
(defun org-cite-csl--style-file (info)
@ -670,6 +782,21 @@ value is the bibliography as rendered by Citeproc."
(plist-put info :cite-citeproc-rendered-bibliographies result)
result)))))
(defun org-cite-csl--generate-latex-preamble (info)
"Generate the CSL-related part of the LaTeX preamble.
INFO is the export state, as a property list."
(let* ((parameters (cadr (org-cite-csl--rendered-bibliographies info)))
(max-offset (cdr (assq 'max-offset parameters)))
(result org-cite-csl-latex-preamble))
(map-do (lambda (placeholder replacement)
(when (string-match placeholder result)
(setq result (replace-match replacement t t result))))
`("\\[CSL-HANGINDENT\\]" ,org-cite-csl-latex-hanging-indent
"\\[CSL-LABELSEP\\]" ,org-cite-csl-latex-label-separator
"\\[CSL-LABELWIDTH-PER-CHAR\\]" ,org-cite-csl-latex-label-width-per-char
"\\[CSL-MAXLABEL-CHARS\\]" ,(number-to-string max-offset)))
result))
;;; Export capability
(defun org-cite-csl-render-citation (citation _style _backend info)
@ -688,8 +815,8 @@ INFO is the export state, as a property list."
INFO is the export state, as a property list."
(org-cite-csl--barf-without-citeproc)
(pcase-let* ((format (org-cite-csl--output-format info))
(`(,outputs ,parameters) (org-cite-csl--rendered-bibliographies info))
(output (cdr (assoc props outputs))))
(`(,outputs ,parameters) (org-cite-csl--rendered-bibliographies info))
(output (cdr (assoc props outputs))))
(pcase format
('html
(concat
@ -714,42 +841,17 @@ INFO is the export state, as a property list."
org-cite-csl-html-hanging-indent
org-cite-csl-html-hanging-indent))
output))
('latex
(if (cdr (assq 'hanging-indent parameters))
(format "\\begin{hangparas}{%s}{1}\n%s\n\\end{hangparas}"
org-cite-csl-latex-hanging-indent
output)
output))
('org-latex output)
(_
;; Parse Org output to re-export it during the regular export
;; process.
(org-cite-parse-elements output)))))
(defun org-cite-csl-finalizer (output _keys _files _style _backend info)
"Add \"hanging\" package if missing from LaTeX output.
OUTPUT is the export document, as a string. INFO is the export state, as a
property list."
(org-cite-csl--barf-without-citeproc)
(if (not (eq 'latex (org-cite-csl--output-format info)))
output
(with-temp-buffer
(save-excursion (insert output))
(when (search-forward "\\begin{document}" nil t)
(goto-char (match-beginning 0))
;; Ensure that \citeprocitem is defined for citeproc-el.
(insert "\\makeatletter\n\\newcommand{\\citeprocitem}[2]{\\hyper@linkstart{cite}{citeproc_bib_item_#1}#2\\hyper@linkend}\n\\makeatother\n\n")
;; Ensure there is a \usepackage{hanging} somewhere or add one.
(let ((re (rx "\\usepackage" (opt "[" (*? nonl) "]") "{hanging}")))
(unless (re-search-backward re nil t)
(insert "\\usepackage[notquote]{hanging}\n"))))
(buffer-string))))
;;; Register `csl' processor
(org-cite-register-processor 'csl
:export-citation #'org-cite-csl-render-citation
:export-bibliography #'org-cite-csl-render-bibliography
:export-finalizer #'org-cite-csl-finalizer
:cite-styles
'((("author" "a") ("bare" "b") ("caps" "c") ("full" "f") ("bare-caps" "bc") ("caps-full" "cf") ("bare-caps-full" "bcf"))
(("noauthor" "na") ("bare" "b") ("caps" "c") ("bare-caps" "bc"))

View File

@ -1,6 +1,6 @@
;;; oc-natbib.el --- Citation processor using natbib LaTeX package -*- lexical-binding: t; -*-
;; Copyright (C) 2021-2023 Free Software Foundation, Inc.
;; Copyright (C) 2021-2024 Free Software Foundation, Inc.
;; Author: Nicolas Goaziou <mail@nicolasgoaziou.fr>
@ -48,7 +48,7 @@
(require 'oc)
(declare-function org-element-property "org-element" (property element))
(declare-function org-element-property "org-element-ast" (property node))
(declare-function org-export-data "org-export" (data info))
@ -77,6 +77,15 @@ If \"natbib\" package is already required in the document, e.g., through
(const :tag "redefine \\thebibliography to issue \\section* instead of \\chapter*" sectionbib)
(const :tag "keep all the authors' names in a citation on one line" nonamebreak)))
(defcustom org-cite-natbib-bibliography-style 'unsrtnat
"Default bibliography style."
:group 'org-cite
:package-version '(Org . "9.7")
:type
'(choice
(const unsrtnat)
(symbol :tag "Other")))
;;; Internal functions
(defun org-cite-natbib--style-to-command (style)
@ -143,11 +152,13 @@ CITATION is the citation object. INFO is the export state, as a property list."
"Print references from bibliography FILES.
FILES is a list of absolute file names. STYLE is the bibliography style, as
a string or nil."
(concat (and style (format "\\bibliographystyle{%s}\n" style))
(format "\\bibliography{%s}"
(mapconcat #'file-name-sans-extension
files
","))))
(concat
(format "\\bibliographystyle{%s}\n"
(or style org-cite-natbib-bibliography-style))
(format "\\bibliography{%s}"
(mapconcat #'file-name-sans-extension
files
","))))
(defun org-cite-natbib-export-citation (citation style _ info)
"Export CITATION object.
@ -157,32 +168,25 @@ state, as a property list."
(org-cite-natbib--build-optional-arguments citation info)
(org-cite-natbib--build-arguments citation)))
(defun org-cite-natbib-use-package (output &rest _)
"Ensure output requires \"natbib\" package.
OUTPUT is the final output of the export process."
(with-temp-buffer
(save-excursion (insert output))
(when (search-forward "\\begin{document}" nil t)
;; Ensure there is a \usepackage{natbib} somewhere or add one.
(goto-char (match-beginning 0))
(let ((re (rx "\\usepackage" (opt "[" (*? nonl) "]") "{natbib}")))
(unless (re-search-backward re nil t)
(insert
(format "\\usepackage%s{natbib}\n"
(if (null org-cite-natbib-options)
""
(format "[%s]"
(mapconcat #'symbol-name
org-cite-natbib-options
","))))))))
(buffer-string)))
(defun org-cite-natbib--generate-latex-preamble (info)
"Ensure that the \"natbib\" package is loaded.
INFO is a plist used as a communication channel."
(and (not (string-match
(rx "\\usepackage" (opt "[" (*? nonl) "]") "{natbib}")
(plist-get info :latex-full-header)))
(format "\\usepackage%s{natbib}\n"
(if (null org-cite-natbib-options)
""
(format "[%s]"
(mapconcat #'symbol-name
org-cite-natbib-options
","))))))
;;; Register `natbib' processor
(org-cite-register-processor 'natbib
:export-bibliography #'org-cite-natbib-export-bibliography
:export-citation #'org-cite-natbib-export-citation
:export-finalizer #'org-cite-natbib-use-package
:cite-styles
'((("author" "a") ("caps" "a") ("full" "f"))
(("noauthor" "na") ("bare" "b"))

View File

@ -1,6 +1,6 @@
;;; oc.el --- Org Cite library -*- lexical-binding: t; -*-
;; Copyright (C) 2021-2023 Free Software Foundation, Inc.
;; Copyright (C) 2021-2024 Free Software Foundation, Inc.
;; Author: Nicolas Goaziou <mail@nicolasgoaziou.fr>
@ -46,8 +46,8 @@
;; The "export" capability is slightly more involved as one need to
;; select the processor providing it, but may also provide a default
;; style for citations and bibliography. Also, the choice of an
;; export processor may depend of the current export back-end. The
;; association between export back-ends and triplets of parameters can
;; export processor may depend of the current export backend. The
;; association between export backends and triplets of parameters can
;; be set in `org-cite-export-processors' variable, or in a document,
;; through the "cite_export" keyword.
@ -71,25 +71,33 @@
(declare-function org-at-heading-p "org" (&optional _))
(declare-function org-collect-keywords "org" (keywords &optional unique directory))
(declare-function org-element-adopt-elements "org-element" (parent &rest children))
(declare-function org-element-adopt "org-element-ast" (parent &rest children))
(declare-function org-element-citation-parser "org-element" ())
(declare-function org-element-citation-reference-parser "org-element" ())
(declare-function org-element-class "org-element" (datum &optional parent))
(declare-function org-element-contents "org-element" (element))
(declare-function org-element-create "org-element" (type &optional props &rest children))
(declare-function org-element-extract-element "org-element" (element))
(declare-function org-element-insert-before "org-element" (element location))
(declare-function org-element-lineage "org-element" (datum &optional types with-self))
(declare-function org-element-contents "org-element-ast" (node))
(declare-function org-element-create "org-element-ast" (type &optional props &rest children))
(declare-function org-element-extract "org-element-ast" (node))
(declare-function org-element-insert-before "org-element-ast" (node location))
(declare-function org-element-lineage "org-element-ast" (datum &optional types with-self))
(declare-function org-element-map "org-element" (data types fun &optional info first-match no-recursion with-affiliated))
(declare-function org-element-normalize-string "org-element" (s))
(declare-function org-element-parse-buffer "org-element" (&optional granularity visible-only))
(declare-function org-element-parse-buffer "org-element" (&optional granularity visible-only keep-deferred))
(declare-function org-element-parse-secondary-string "org-element" (string restriction &optional parent))
(declare-function org-element-context "org-element" (&optional element))
(declare-function org-element-property "org-element" (property element))
(declare-function org-element-put-property "org-element" (element property value))
(declare-function org-element-property "org-element-ast" (property node))
(declare-function org-element-begin "org-element" (node))
(declare-function org-element-end "org-element" (node))
(declare-function org-element-post-affiliated "org-element" (node))
(declare-function org-element-post-blank "org-element" (node))
(declare-function org-element-contents-begin "org-element" (node))
(declare-function org-element-contents-end "org-element" (node))
(declare-function org-element-parent "org-element-ast" (node))
(declare-function org-element-put-property "org-element-ast" (node property value))
(declare-function org-element-restriction "org-element" (element))
(declare-function org-element-set-element "org-element" (old new))
(declare-function org-element-type "org-element" (element))
(declare-function org-element-set "org-element-ast" (old new))
(declare-function org-element-type "org-element-ast" (node &optional anonymous))
(declare-function org-element-type-p "org-element-ast" (node types))
(declare-function org-export-derived-backend-p "org-export" (backend &rest backends))
(declare-function org-export-get-next-element "org-export" (blob info &optional n))
@ -143,12 +151,12 @@ File names must be absolute."
When nil, citations and bibliography are not exported.
When non-nil, the value is an association list between export back-ends and
When non-nil, the value is an association list between export backends and
citation export processors:
(BACK-END . PROCESSOR)
(BACKEND . PROCESSOR)
where BACK-END is the name of an export back-end or t, and PROCESSOR is a
where BACKEND is the name of an export backend or t, and PROCESSOR is a
triplet following the pattern
(NAME BIBLIOGRAPHY-STYLE CITATION-STYLE)
@ -160,7 +168,7 @@ exporting a citation), as a string or nil. Both BIBLIOGRAPHY-STYLE and
CITATION-STYLE are optional. NAME is mandatory.
The export process selects the citation processor associated to the current
export back-end, or the most specific back-end the current one is derived from,
export backend, or the most specific backend the current one is derived from,
or, if all are inadequate, to the processor associated to t. For example, with
the following value
@ -168,9 +176,9 @@ the following value
(latex biblatex)
(t csl))
exporting with `beamer' or any back-end derived from it will use `natbib',
whereas exporting with `latex' or any back-end derived from it but different
from `beamer' will use `biblatex' processor. Any other back-end, such as
exporting with `beamer' or any backend derived from it will use `natbib',
whereas exporting with `latex' or any backend derived from it but different
from `beamer' will use `biblatex' processor. Any other backend, such as
`html', will use `csl' processor.
CITATION-STYLE is overridden by adding a style to any citation object. A nil
@ -187,7 +195,7 @@ or
#+CITE_EXPORT: basic
In that case, `basic' processor is used on every export, independently on the
back-end."
backend."
:group 'org-cite
:package-version '(Org . "9.5")
:type '(choice (const :tag "No export" nil)
@ -345,7 +353,7 @@ optional keys can be set:
arguments: the list of citation keys used in the document, as
strings, a list of bibliography files, the style, as a string
or nil, the local properties, as a property list, the export
back-end, as a symbol, and the communication channel, as a
backend, as a symbol, and the communication channel, as a
property list.
It is called at each \"print_bibliography\" keyword in the
@ -358,7 +366,7 @@ optional keys can be set:
Function rendering citations. It is called with four
arguments: a citation object, the style, as a pair, the
export back-end, as a symbol, and the communication channel,
export backend, as a symbol, and the communication channel,
as a property list.
It is called on each citation object in the parse tree. It
@ -373,7 +381,7 @@ optional keys can be set:
six arguments: the output, as a string, a list of citation
keys used in the document, a list of bibliography files, the
expected bibliography style, as a string or nil, the export
back-end, as a symbol, and the communication channel, as a
backend, as a symbol, and the communication channel, as a
property list.
It must return a string, which will become the final output
@ -468,11 +476,11 @@ PROCESSOR is the name of a cite processor, as a symbol. CAPABILITY is
"Set `:post-blank' property from element or object before DATUM to BLANKS.
DATUM is an element or object. BLANKS is an integer. DATUM is modified
by side-effect."
(if (not (eq 'plain-text (org-element-type datum)))
(if (not (org-element-type-p datum 'plain-text))
(org-element-put-property datum :post-blank blanks)
;; Remove any blank from string before DATUM so it is exported
;; with exactly BLANKS white spaces.
(org-element-set-element
(org-element-set
datum
(replace-regexp-in-string
"[ \t\n]*\\'" (make-string blanks ?\s) datum))))
@ -492,11 +500,11 @@ S is split at beginning of match group N upon matching REGEXP against it.
This function assumes S precedes CITATION."
;; When extracting the citation, remove white spaces before it, but
;; preserve those after it.
(let ((post-blank (org-element-property :post-blank citation)))
(let ((post-blank (org-element-post-blank citation)))
(when (and post-blank (> post-blank 0))
(org-element-insert-before (make-string post-blank ?\s) citation)))
(org-element-insert-before
(org-element-put-property (org-element-extract-element citation)
(org-element-put-property (org-element-extract citation)
:post-blank 0)
s)
(string-match regexp s)
@ -510,21 +518,21 @@ This function assumes S precedes CITATION."
(substring s split))))
(when (org-string-nw-p first-part)
(org-element-insert-before first-part citation))
(org-element-set-element s last-part)))
(org-element-set s last-part)))
(defun org-cite--move-punct-before (punct citation s info)
"Move punctuation PUNCT before CITATION object.
String S contains PUNCT. INFO is the export state, as a property list.
The function assumes S follows CITATION. Parse tree is modified by side-effect."
(if (equal s punct)
(org-element-extract-element s) ;it would be empty anyway
(org-element-set-element s (substring s (length punct))))
(org-element-extract s) ;it would be empty anyway
(org-element-set s (substring s (length punct))))
;; Remove blanks before citation.
(org-cite--set-previous-post-blank citation 0 info)
(org-element-insert-before
;; Blanks between citation and punct are now before punct and
;; citation.
(concat (make-string (or (org-element-property :post-blank citation) 0) ?\s)
(concat (make-string (or (org-element-post-blank citation) 0) ?\s)
punct)
citation))
@ -602,7 +610,18 @@ to (adaptive outside after)."
(append (mapcar (lambda (value)
(pcase value
(`(,f . ,d)
(expand-file-name (org-strip-quotes f) d))))
(setq f (org-strip-quotes f))
(if (or (file-name-absolute-p f)
(file-remote-p f)
(equal d default-directory))
;; Keep absolute paths, remote paths, and
;; local relative paths.
f
;; Adjust relative bibliography path for
;; #+SETUP files located in other directory.
;; Also, see `org-export--update-included-link'.
(file-relative-name
(expand-file-name f d) default-directory)))))
(pcase (org-collect-keywords
'("BIBLIOGRAPHY") nil '("BIBLIOGRAPHY"))
(`(("BIBLIOGRAPHY" . ,pairs)) pairs)))
@ -619,12 +638,12 @@ or from the current buffer."
(let ((contents (org-element-contents citation)))
(cond
((null contents)
(org-with-point-at (org-element-property :contents-begin citation)
(narrow-to-region (point) (org-element-property :contents-end citation))
(org-with-point-at (org-element-contents-begin citation)
(narrow-to-region (point) (org-element-contents-end citation))
(let ((references nil))
(while (not (eobp))
(let ((reference (org-element-citation-reference-parser)))
(goto-char (org-element-property :end reference))
(goto-char (org-element-end reference))
(push (if keys-only
(org-element-property :key reference)
reference)
@ -636,8 +655,8 @@ or from the current buffer."
(defun org-cite-boundaries (citation)
"Return the beginning and end strict position of CITATION.
Returns a (BEG . END) pair."
(let ((beg (org-element-property :begin citation))
(end (org-with-point-at (org-element-property :end citation)
(let ((beg (org-element-begin citation))
(end (org-with-point-at (org-element-end citation)
(skip-chars-backward " \t")
(point))))
(cons beg end)))
@ -646,15 +665,15 @@ Returns a (BEG . END) pair."
"Return citation REFERENCE's key boundaries as buffer positions.
The function returns a pair (START . END) where START and END denote positions
in the current buffer. Positions include leading \"@\" character."
(org-with-point-at (org-element-property :begin reference)
(let ((end (org-element-property :end reference)))
(org-with-point-at (org-element-begin reference)
(let ((end (org-element-end reference)))
(re-search-forward org-element-citation-key-re end t)
(cons (match-beginning 0) (match-end 0)))))
(defun org-cite-main-affixes (citation)
"Return main affixes for CITATION object.
Some export back-ends only support a single pair of affixes per
Some export backends only support a single pair of affixes per
citation, even if it contains multiple keys. This function
decides what affixes are the most appropriate.
@ -730,7 +749,7 @@ When removing the last reference, also remove the whole citation."
(org-with-point-at begin
(skip-chars-backward " \t")
(point)))
(pos-after-blank (org-element-property :end datum))
(pos-after-blank (org-element-end datum))
(first-on-line?
(= pos-before-blank (line-beginning-position)))
(last-on-line?
@ -753,22 +772,22 @@ When removing the last reference, also remove the whole citation."
(when (= pos-after-blank end)
(org-with-point-at pos-before-blank (insert " ")))))))
('citation-reference
(let* ((citation (org-element-property :parent datum))
(let* ((citation (org-element-parent datum))
(references (org-cite-get-references citation))
(begin (org-element-property :begin datum))
(end (org-element-property :end datum)))
(begin (org-element-begin datum))
(end (org-element-end datum)))
(cond
;; Single reference.
((= 1 (length references))
(org-cite-delete-citation citation))
;; First reference, no prefix.
((and (= begin (org-element-property :contents-begin citation))
((and (= begin (org-element-contents-begin citation))
(not (org-element-property :prefix citation)))
(org-with-point-at (org-element-property :begin datum)
(org-with-point-at (org-element-begin datum)
(skip-chars-backward " \t")
(delete-region (point) end)))
;; Last reference, no suffix.
((and (= end (org-element-property :contents-end citation))
((and (= end (org-element-contents-end citation))
(not (org-element-property :suffix citation)))
(delete-region (1- begin) (1- (cdr (org-cite-boundaries citation)))))
;; Somewhere in-between.
@ -838,6 +857,11 @@ tokens. Spurious spaces are ignored."
s))
(nreverse result))))
(defun org-cite-processor (info)
"Return expected citation/bibliography processor.
INFO is a plist used as a communication channel."
(car (plist-get info :cite-export)))
(defun org-cite-bibliography-style (info)
"Return expected bibliography style.
INFO is a plist used as a communication channel."
@ -937,11 +961,12 @@ the sole contents of the footnote, e.g., after calling `org-cite-wrap-citation'.
When non-nil, the return value if the footnote container."
(let ((footnote
(org-element-lineage citation
'(footnote-definition footnote-reference))))
(org-element-lineage
citation
'(footnote-definition footnote-reference))))
(and footnote
(or (not strict)
(equal (org-element-contents (org-element-property :parent citation))
(equal (org-element-contents (org-element-parent citation))
(list citation)))
;; Return value.
footnote)))
@ -959,15 +984,15 @@ Return newly created footnote object."
(list 'footnote-reference
(list :label nil
:type 'inline
:contents-begin (org-element-property :begin citation)
:contents-end (org-element-property :end citation)
:post-blank (org-element-property :post-blank citation)))))
:contents-begin (org-element-begin citation)
:contents-end (org-element-end citation)
:post-blank (org-element-post-blank citation)))))
;; Remove any white space before citation.
(org-cite--set-previous-post-blank citation 0 info)
;; Footnote swallows citation.
(org-element-insert-before footnote citation)
(org-element-adopt-elements footnote
(org-element-extract-element citation))))
(org-element-adopt footnote
(org-element-extract citation))))
(defun org-cite-adjust-note (citation info &optional rule punct)
"Adjust note number location for CITATION object, and punctuation around it.
@ -1046,8 +1071,8 @@ the same object, call `org-cite-adjust-note' first."
;; as an argument is not available.
(rx-to-string `(seq string-start ,final-punct) t)
"" next)))
(org-element-set-element previous new-prev)
(org-element-set-element next new-next)
(org-element-set previous new-prev)
(org-element-set next new-next)
(setq previous new-prev)
(setq next new-next)
(setq punct final-punct)
@ -1066,15 +1091,15 @@ the same object, call `org-cite-adjust-note' first."
(replace-regexp-in-string
previous-punct-re "" previous nil nil 1))
(new-next (if (stringp next) (concat punct next) punct)))
(org-element-set-element previous new-prev)
(org-element-set previous new-prev)
(cond
((stringp next)
(org-element-set-element next new-next))
(org-element-set next new-next))
(next
(org-element-insert-before new-next next))
(t
(org-element-adopt-elements
(org-element-property :parent citation)
(org-element-adopt
(org-element-parent citation)
new-next)))
(setq previous new-prev)
(setq next new-next)
@ -1141,7 +1166,7 @@ raises an error if S contains a headline."
(insert s)
(pcase (org-element-contents (org-element-parse-buffer))
('nil nil)
(`(,(and section (guard (eq 'section (org-element-type section)))))
(`(,(and section (guard (org-element-type-p section 'section))))
(org-element-contents section))
(_
(error "Headlines cannot replace a keyword")))))
@ -1201,14 +1226,23 @@ and must return either a string, an object, or a secondary string."
(org-cite-concat result separator (funcall function datum))))
result)))
(defun org-cite-capitalize (str)
"Capitalize string of raw string object STR."
(cond
((stringp str) (capitalize str))
((org-element-type-p str 'raw)
(org-export-raw-string
(capitalize (mapconcat #'identity (org-element-contents str) ""))))
(t (error "%S must be either a string or raw string object" str))))
;;; Internal interface with fontification (activate capability)
(defun org-cite-fontify-default (cite)
"Fontify CITE with `org-cite' and `org-cite-key' faces.
CITE is a citation object. The function applies `org-cite' face
on the whole citation, and `org-cite-key' face on each key."
(let ((beg (org-element-property :begin cite))
(end (org-with-point-at (org-element-property :end cite)
(let ((beg (org-element-begin cite))
(end (org-with-point-at (org-element-end cite)
(skip-chars-backward " \t")
(point))))
(add-text-properties beg end '(font-lock-multiline t))
@ -1237,7 +1271,7 @@ from the processor set in `org-cite-activate-processor'."
(save-match-data (funcall activate cite))
;; Move after cite object and make sure to return
;; a non-nil value.
(goto-char (org-element-property :end cite)))))))
(goto-char (org-element-end cite)))))))
;;; Internal interface with Org Export library (export capability)
@ -1274,12 +1308,12 @@ side-effect."
;; Value is an alist. It must come from
;; `org-cite-export-processors' variable. Find the most
;; appropriate processor according to current export
;; back-end.
;; backend.
((and (pred consp) alist)
(let* ((backend (plist-get info :back-end))
(candidates
;; Limit candidates to processors associated to
;; back-ends derived from or equal to the current
;; backends derived from or equal to the current
;; one.
(sort (seq-filter
(pcase-lambda (`(,key . ,_))
@ -1331,7 +1365,7 @@ selected citation processor."
(defun org-cite-export-bibliography (keyword _ info)
"Return bibliography associated to \"print_bibliography\" KEYWORD.
BACKEND is the export back-end, as a symbol. INFO is a plist
BACKEND is the export backend, as a symbol. INFO is a plist
used as a communication channel."
(pcase (plist-get info :cite-export)
('nil nil)
@ -1355,7 +1389,7 @@ INFO is the communication channel, as a plist. Parse tree is modified
by side-effect."
(dolist (cite (org-cite-list-citations info))
(let ((replacement (org-cite-export-citation cite nil info))
(blanks (or (org-element-property :post-blank cite) 0)))
(blanks (or (org-element-post-blank cite) 0)))
(if (null replacement)
;; Before removing the citation, transfer its `:post-blank'
;; property to the object before, if any.
@ -1389,7 +1423,7 @@ by side-effect."
(_
(error "Invalid return value from citation export processor: %S"
replacement))))
(org-element-extract-element cite))))
(org-element-extract cite))))
(defun org-cite-process-bibliography (info)
"Replace all \"print_bibliography\" keywords in the parse tree.
@ -1400,18 +1434,18 @@ by side effect."
(lambda (keyword)
(when (equal "PRINT_BIBLIOGRAPHY" (org-element-property :key keyword))
(let ((replacement (org-cite-export-bibliography keyword nil info))
(blanks (or (org-element-property :post-blank keyword) 0)))
(blanks (or (org-element-post-blank keyword) 0)))
(pcase replacement
;; Before removing the citation, transfer its
;; `:post-blank' property to the element before, if any.
('nil
(org-cite--set-previous-post-blank keyword blanks info)
(org-element-extract-element keyword))
(org-element-extract keyword))
;; Handle `:post-blank' before replacing keyword with string.
((pred stringp)
(let ((output (concat (org-element-normalize-string replacement)
(make-string blanks ?\n))))
(org-element-set-element keyword (org-export-raw-string output))))
(org-element-set keyword (org-export-raw-string output))))
;; List of elements: splice contents before keyword and
;; remove the latter. Transfer `:post-blank' to last
;; element.
@ -1421,11 +1455,11 @@ by side effect."
(setq last datum)
(org-element-insert-before datum keyword))
(org-cite--set-post-blank last blanks)
(org-element-extract-element keyword)))
(org-element-extract keyword)))
;; Single element: replace the keyword.
(`(,(pred symbolp) . ,_)
(org-cite--set-post-blank replacement blanks)
(org-element-set-element keyword replacement))
(org-element-set keyword replacement))
(_
(error "Invalid return value from citation export processor: %S"
replacement))))))
@ -1481,7 +1515,7 @@ CONTEXT is the element or object at point, as returned by `org-element-context'.
;;
;; XXX: Inserting citation in a secondary value is not allowed
;; yet. Is it useful?
((let ((post (org-element-property :post-affiliated context)))
((let ((post (org-element-post-affiliated context)))
(and post (< (point) post)))
(let ((case-fold-search t))
(looking-back
@ -1497,14 +1531,14 @@ CONTEXT is the element or object at point, as returned by `org-element-context'.
((memq type '(nil paragraph)))
;; So are contents of verse blocks.
((eq type 'verse-block)
(and (>= (point) (org-element-property :contents-begin context))
(< (point) (org-element-property :contents-end context))))
(and (>= (point) (org-element-contents-begin context))
(< (point) (org-element-contents-end context))))
;; In an headline or inlinetask, point must be either on the
;; heading itself or on the blank lines below.
((memq type '(headline inlinetask))
(or (not (org-at-heading-p))
(and (save-excursion
(beginning-of-line)
(forward-line 0)
(and (let ((case-fold-search t))
(not (looking-at-p "\\*+ END[ \t]*$")))
(let ((case-fold-search nil))
@ -1523,43 +1557,43 @@ CONTEXT is the element or object at point, as returned by `org-element-context'.
;; White spaces after an object or blank lines after an element
;; are OK.
((>= (point)
(save-excursion (goto-char (org-element-property :end context))
(skip-chars-backward " \r\t\n")
(if (eq (org-element-class context) 'object) (point)
(line-beginning-position 2)))))
(save-excursion (goto-char (org-element-end context))
(skip-chars-backward " \r\t\n")
(if (eq (org-element-class context) 'object) (point)
(line-beginning-position 2)))))
;; At the beginning of a footnote definition, right after the
;; label, is OK.
((eq type 'footnote-definition) (looking-at (rx space)))
;; At the start of a list item is fine, as long as the bullet is
;; unaffected.
((eq type 'item)
(> (point) (+ (org-element-property :begin context)
(> (point) (+ (org-element-begin context)
(org-current-text-indentation)
(if (org-element-property :checkbox context)
5 1))))
;; Other elements are invalid.
((eq (org-element-class context) 'element) nil)
;; Just before object is fine.
((= (point) (org-element-property :begin context)))
((= (point) (org-element-begin context)))
;; Within recursive object too, but not in a link.
((eq type 'link) nil)
((eq type 'table-cell)
;; :contents-begin is not reliable on empty cells, so special
;; case it.
(<= (save-excursion (skip-chars-backward " \t") (point))
(org-element-property :contents-end context)))
((let ((cbeg (org-element-property :contents-begin context))
(cend (org-element-property :contents-end context)))
(org-element-contents-end context)))
((let ((cbeg (org-element-contents-begin context))
(cend (org-element-contents-end context)))
(and cbeg (>= (point) cbeg) (<= (point) cend)))))))
(defun org-cite--insert-string-before (string reference)
"Insert STRING before citation REFERENCE object."
(org-with-point-at (org-element-property :begin reference)
(org-with-point-at (org-element-begin reference)
(insert string ";")))
(defun org-cite--insert-string-after (string reference)
"Insert STRING after citation REFERENCE object."
(org-with-point-at (org-element-property :end reference)
(org-with-point-at (org-element-end reference)
;; Make sure to move forward when we're inserting at point, so the
;; insertion can happen multiple times.
(if (char-equal ?\; (char-before))
@ -1630,7 +1664,7 @@ More specifically,
;; action depends on the point.
(if arg
(org-cite-delete-citation context)
(let* ((begin (org-element-property :begin context))
(let* ((begin (org-element-begin context))
(style-end (1- (org-with-point-at begin (search-forward ":")))))
(if (>= style-end (point))
;; On style part, edit the style.
@ -1644,7 +1678,7 @@ More specifically,
;; point.
(let* ((references (org-cite-get-references context))
(key (concat "@" (funcall select-key nil))))
(if (< (point) (org-element-property :contents-begin context))
(if (< (point) (org-element-contents-begin context))
(org-cite--insert-string-before key (car references))
(org-cite--insert-string-after key (org-last references))))))))
;; On a citation reference. If ARG is not nil, remove the
@ -1699,7 +1733,7 @@ ARG is the prefix argument received when calling interactively the function."
(let ((context (org-element-context))
(insert (org-cite-processor-insert (org-cite-get-processor name))))
(cond
((memq (org-element-type context) '(citation citation-reference))
((org-element-type-p context '(citation citation-reference))
(funcall insert context arg))
((org-cite--allowed-p context)
(funcall insert nil arg))

View File

@ -1,6 +1,6 @@
;;; ol-bbdb.el --- Links to BBDB entries -*- lexical-binding: t; -*-
;; Copyright (C) 2004-2023 Free Software Foundation, Inc.
;; Copyright (C) 2004-2024 Free Software Foundation, Inc.
;; Authors: Carsten Dominik <carsten.dominik@gmail.com>
;; Thomas Baumann <thomas dot baumann at ch dot tum dot de>
@ -226,7 +226,7 @@ date year)."
;;; Implementation
(defun org-bbdb-store-link ()
(defun org-bbdb-store-link (&optional _interactive?)
"Store a link to a BBDB database entry."
(when (eq major-mode 'bbdb-mode)
;; This is BBDB, we make this link!
@ -255,7 +255,7 @@ italicized, in all other cases it is left unchanged."
(defun org-bbdb-open (name _)
"Follow a BBDB link to NAME."
(require 'bbdb-com)
(org-require-package 'bbdb-com "bbdb")
(let ((inhibit-redisplay (not debug-on-error)))
(if (fboundp 'bbdb-name)
(org-bbdb-open-old name)
@ -369,7 +369,7 @@ This is used by Org to re-create the anniversary hash table."
"Extract anniversaries from BBDB for display in the agenda.
When called programmatically, this function expects the `date'
variable to be globally bound."
(require 'bbdb)
(org-require-package 'bbdb)
(require 'diary-lib)
(unless (hash-table-p org-bbdb-anniv-hash)
(setq org-bbdb-anniv-hash
@ -500,7 +500,7 @@ must be positive"))
(defun org-bbdb-complete-link ()
"Read a bbdb link with name completion."
(require 'bbdb-com)
(org-require-package 'bbdb-com "bbdb")
(let ((rec (bbdb-completing-read-record "Name: ")))
(concat "bbdb:"
(bbdb-record-name (if (listp rec)
@ -509,7 +509,7 @@ must be positive"))
(defun org-bbdb-anniv-export-ical ()
"Extract anniversaries from BBDB and convert them to icalendar format."
(require 'bbdb)
(org-require-package 'bbdb)
(require 'diary-lib)
(unless (hash-table-p org-bbdb-anniv-hash)
(setq org-bbdb-anniv-hash

View File

@ -1,6 +1,6 @@
;;; ol-bibtex.el --- Links to BibTeX entries -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2007-2023 Free Software Foundation, Inc.
;; Copyright (C) 2007-2024 Free Software Foundation, Inc.
;;
;; Authors: Bastien Guerry <bzg@gnu.org>
;; Carsten Dominik <carsten dot dominik at gmail dot com>
@ -266,7 +266,7 @@ a missing title field."
:type 'boolean)
(defcustom org-bibtex-headline-format-function
(lambda (entry) (cdr (assq :title entry)))
#'org-bibtex-headline-format-default
"Function returning the headline text for `org-bibtex-write'.
It should take a single argument, the bibtex entry (an alist as
returned by `org-bibtex-read'). The default value simply returns
@ -507,7 +507,7 @@ ARG, when non-nil, is a universal prefix argument. See
`org-open-file' for details."
(org-link-open-as-file path arg))
(defun org-bibtex-store-link ()
(defun org-bibtex-store-link (&optional _interactive?)
"Store a link to a BibTeX entry."
(when (eq major-mode 'bibtex-mode)
(let* ((search (org-create-file-search-in-bibtex))
@ -636,22 +636,27 @@ With prefix argument OPTIONAL also prompt for optional fields."
With prefix argument OPTIONAL also prompt for optional fields."
(interactive) (org-map-entries (lambda () (org-bibtex-check optional))))
(defun org-bibtex-create (&optional arg nonew)
(defun org-bibtex-headline-format-default (entry)
"Return headline text according to ENTRY title."
(cdr (assq :title entry)))
(defun org-bibtex-create (&optional arg update-heading)
"Create a new entry at the given level.
With a prefix arg, query for optional fields as well.
If nonew is t, add data to the headline of the entry at point."
With a prefix ARG, query for optional fields as well.
If UPDATE-HEADING is non-nil, add data to the headline of the entry at
point."
(interactive "P")
(let* ((type (completing-read
"Type: " (mapcar (lambda (type)
(substring (symbol-name (car type)) 1))
org-bibtex-types)
nil nil (when nonew
(org-bibtex-get org-bibtex-type-property-name))))
nil nil (when update-heading
(org-bibtex-get org-bibtex-type-property-name))))
(type (if (keywordp type) type (intern (concat ":" type))))
(org-bibtex-treat-headline-as-title (if nonew nil t)))
(org-bibtex-treat-headline-as-title (if update-heading nil t)))
(unless (assoc type org-bibtex-types)
(error "Type:%s is not known" type))
(if nonew
(if update-heading
(org-back-to-heading)
(org-insert-heading)
(let ((title (org-bibtex-ask :title)))
@ -718,29 +723,32 @@ Return the number of saved entries."
(interactive "fFile: ")
(org-bibtex-read-buffer (find-file-noselect file 'nowarn 'rawfile)))
(defun org-bibtex-write (&optional noindent)
(defun org-bibtex-write (&optional noindent update-heading)
"Insert a heading built from the first element of `org-bibtex-entries'.
When optional argument NOINDENT is non-nil, do not indent the properties
drawer."
drawer. If UPDATE-HEADING is non-nil, add data to the headline of the
entry at point."
(interactive)
(unless org-bibtex-entries
(error "No entries in `org-bibtex-entries'"))
(let* ((entry (pop org-bibtex-entries))
(org-special-properties nil) ; avoids errors with `org-entry-put'
(val (lambda (field) (cdr (assoc field entry))))
(togtag (lambda (tag) (org-toggle-tag tag 'on))))
(org-insert-heading)
(insert (funcall org-bibtex-headline-format-function entry))
(insert "\n:PROPERTIES:\n")
(org-bibtex-put "TITLE" (funcall val :title) 'insert)
(togtag (lambda (tag) (org-toggle-tag tag 'on)))
(insert-raw (not update-heading)))
(unless update-heading
(org-insert-heading)
(insert (funcall org-bibtex-headline-format-function entry))
(insert "\n:PROPERTIES:\n"))
(org-bibtex-put "TITLE" (funcall val :title) insert-raw)
(org-bibtex-put org-bibtex-type-property-name
(downcase (funcall val :type))
'insert)
insert-raw)
(dolist (pair entry)
(pcase (car pair)
(:title nil)
(:type nil)
(:key (org-bibtex-put org-bibtex-key-property (cdr pair) 'insert))
(:key (org-bibtex-put org-bibtex-key-property (cdr pair) insert-raw))
(:keywords (if org-bibtex-tags-are-keywords
(dolist (kw (split-string (cdr pair) ", *"))
(funcall
@ -748,25 +756,28 @@ drawer."
(replace-regexp-in-string
"[^[:alnum:]_@#%]" ""
(replace-regexp-in-string "[ \t]+" "_" kw))))
(org-bibtex-put (car pair) (cdr pair) 'insert)))
(_ (org-bibtex-put (car pair) (cdr pair) 'insert))))
(insert ":END:\n")
(org-bibtex-put (car pair) (cdr pair) insert-raw)))
(_ (org-bibtex-put (car pair) (cdr pair) insert-raw))))
(unless update-heading
(insert ":END:\n"))
(mapc togtag org-bibtex-tags)
(unless noindent
(org-indent-region
(save-excursion (org-back-to-heading t) (point))
(point)))))
(defun org-bibtex-yank ()
"If kill ring holds a bibtex entry yank it as an Org headline."
(interactive)
(defun org-bibtex-yank (&optional update-heading)
"If kill ring holds a bibtex entry yank it as an Org headline.
When called with non-nil prefix argument UPDATE-HEADING, add data to the
headline of the entry at point."
(interactive "P")
(let (entry)
(with-temp-buffer
(yank 1)
(bibtex-mode)
(setf entry (org-bibtex-read)))
(if entry
(org-bibtex-write)
(org-bibtex-write nil update-heading)
(error "Yanked text does not appear to contain a BibTeX entry"))))
(defun org-bibtex-import-from-file (file)

View File

@ -1,6 +1,6 @@
;;; ol-docview.el --- Links to Docview mode buffers -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Author: Jan Böcker <jan.boecker at jboecker dot de>
;; Keywords: outlines, hypermedia, calendar, wp
@ -57,20 +57,21 @@
:export #'org-docview-export
:store #'org-docview-store-link)
(defun org-docview-export (link description format)
"Export a docview link from Org files."
(defun org-docview-export (link description backend _info)
"Export a docview LINK with DESCRIPTION for BACKEND."
(let ((path (if (string-match "\\(.+\\)::.+" link) (match-string 1 link)
link))
(desc (or description link)))
(when (stringp path)
(setq path (expand-file-name path))
(cond
((eq format 'html) (format "<a href=\"%s\">%s</a>" path desc))
((eq format 'latex) (format "\\href{%s}{%s}" path desc))
((eq format 'ascii) (format "%s (%s)" desc path))
((eq backend 'html) (format "<a href=\"%s\">%s</a>" path desc))
((eq backend 'latex) (format "\\href{%s}{%s}" path desc))
((eq backend 'ascii) (format "[%s] (<%s>)" desc path))
(t path)))))
(defun org-docview-open (link _)
"Open docview: LINK."
(string-match "\\(.*?\\)\\(?:::\\([0-9]+\\)\\)?$" link)
(let ((path (match-string 1 link))
(page (and (match-beginning 2)
@ -82,7 +83,7 @@
(error "No such file: %s" path))
(when page (doc-view-goto-page page))))
(defun org-docview-store-link ()
(defun org-docview-store-link (&optional _interactive?)
"Store a link to a docview buffer."
(when (eq major-mode 'doc-view-mode)
;; This buffer is in doc-view-mode

View File

@ -1,6 +1,6 @@
;;; ol-doi.el --- DOI links support in Org -*- lexical-binding: t; -*-
;; Copyright (C) 2021-2023 Free Software Foundation, Inc.
;; Copyright (C) 2021-2024 Free Software Foundation, Inc.
;; Author: Nicolas Goaziou <mail@nicolasgoaziou.fr>
@ -40,7 +40,8 @@
(defun org-link-doi-open (path arg)
"Open a \"doi\" type link.
PATH is a the path to search for, as a string."
PATH is a the path to search for, as a string.
ARG is passed to `browse-url'."
(browse-url (url-encode-url (concat org-link-doi-server-url path)) arg))
(defun org-link-doi-export (path desc backend info)

View File

@ -1,6 +1,6 @@
;;; ol-eshell.el --- Links to Working Directories in Eshell -*- lexical-binding: t; -*-
;; Copyright (C) 2011-2023 Free Software Foundation, Inc.
;; Copyright (C) 2011-2024 Free Software Foundation, Inc.
;; Author: Konrad Hinsen <konrad.hinsen AT fastmail.net>
@ -37,8 +37,8 @@
:store #'org-eshell-store-link)
(defun org-eshell-open (link _)
"Switch to an eshell buffer and execute a command line.
The link can be just a command line (executed in the default
"Switch to an eshell buffer and execute a command line for LINK.
The LINK can be just a command line (executed in the default
eshell buffer) or a command line prefixed by a buffer name
followed by a colon."
(let* ((buffer-and-command
@ -60,9 +60,10 @@ followed by a colon."
(insert command)
(eshell-send-input)))
(defun org-eshell-store-link ()
"Store a link that, when opened, switches back to the current eshell buffer
and the current working directory."
(defun org-eshell-store-link (&optional _interactive?)
"Store eshell link.
When opened, the link switches back to the current eshell buffer and
the current working directory."
(when (eq major-mode 'eshell-mode)
(let* ((command (concat "cd " (eshell/pwd)))
(link (concat (buffer-name) ":" command)))

View File

@ -1,6 +1,6 @@
;;; ol-eww.el --- Store URL and kill from Eww mode -*- lexical-binding: t -*-
;; Copyright (C) 2014-2023 Free Software Foundation, Inc.
;; Copyright (C) 2014-2024 Free Software Foundation, Inc.
;; Author: Marco Wahl <marcowahlsoft>a<gmailcom>
;; Keywords: link, eww
@ -62,7 +62,7 @@
"Open URL with Eww in the current buffer."
(eww url))
(defun org-eww-store-link ()
(defun org-eww-store-link (&optional _interactive?)
"Store a link to the url of an EWW buffer."
(when (eq major-mode 'eww-mode)
(org-link-store-props
@ -162,6 +162,7 @@ keep the structure of the Org file."
;; Additional keys for eww-mode
(defun org-eww-extend-eww-keymap ()
"Add ol-eww bindings to `eww-mode-map'."
(define-key eww-mode-map "\C-c\C-x\M-w" 'org-eww-copy-for-org-mode)
(define-key eww-mode-map "\C-c\C-x\C-w" 'org-eww-copy-for-org-mode))

View File

@ -1,6 +1,6 @@
;;; ol-gnus.el --- Links to Gnus Groups and Messages -*- lexical-binding: t; -*-
;; Copyright (C) 2004-2023 Free Software Foundation, Inc.
;; Copyright (C) 2004-2024 Free Software Foundation, Inc.
;; Author: Carsten Dominik <carsten.dominik@gmail.com>
;; Tassilo Horn <tassilo at member dot fsf dot org>
@ -123,7 +123,7 @@ If `org-store-link' was called with a prefix arg the meaning of
(url-encode-url message-id))
(concat "gnus:" group "#" message-id)))
(defun org-gnus-store-link ()
(defun org-gnus-store-link (&optional _interactive?)
"Store a link to a Gnus folder or message."
(pcase major-mode
(`gnus-group-mode
@ -137,27 +137,23 @@ If `org-store-link' was called with a prefix arg the meaning of
(let* ((group
(pcase (gnus-find-method-for-group gnus-newsgroup-name)
(`(nnvirtual . ,_)
(save-excursion
(car (nnvirtual-map-article (gnus-summary-article-number)))))
(with-current-buffer gnus-summary-buffer
(save-excursion
(car (nnvirtual-map-article (gnus-summary-article-number))))))
(`(,(or `nnselect `nnir) . ,_) ; nnir is for Emacs < 28.
(save-excursion
(cond
((fboundp 'nnselect-article-group)
(nnselect-article-group (gnus-summary-article-number)))
((fboundp 'nnir-article-group)
(nnir-article-group (gnus-summary-article-number)))
(t
(error "No article-group variant bound")))))
(with-current-buffer gnus-summary-buffer
(save-excursion
(cond
((fboundp 'nnselect-article-group)
(nnselect-article-group (gnus-summary-article-number)))
((fboundp 'nnir-article-group)
(nnir-article-group (gnus-summary-article-number)))
(t
(error "No article-group variant bound"))))))
(_ gnus-newsgroup-name)))
(header (if (eq major-mode 'gnus-article-mode)
;; When in an article, first move to summary
;; buffer, with point on the summary of the
;; current article before extracting headers.
(save-window-excursion
(save-excursion
(gnus-article-show-summary)
(gnus-summary-article-header)))
(gnus-summary-article-header)))
(header (with-current-buffer gnus-summary-buffer
(save-excursion
(gnus-summary-article-header))))
(from (mail-header-from header))
(message-id (org-unbracket-string "<" ">" (mail-header-id header)))
(date (org-trim (mail-header-date header)))

View File

@ -1,6 +1,6 @@
;;; ol-info.el --- Links to Info Nodes -*- lexical-binding: t; -*-
;; Copyright (C) 2004-2023 Free Software Foundation, Inc.
;; Copyright (C) 2004-2024 Free Software Foundation, Inc.
;; Author: Carsten Dominik <carsten.dominik@gmail.com>
;; Keywords: outlines, hypermedia, calendar, wp
@ -50,7 +50,7 @@
:insert-description #'org-info-description-as-command)
;; Implementation
(defun org-info-store-link ()
(defun org-info-store-link (&optional _interactive?)
"Store a link to an Info file and node."
(when (eq major-mode 'Info-mode)
(let ((link (concat "info:"
@ -139,13 +139,17 @@ If LINK is not an info link then DESC is returned."
"List of Emacs documents available.
Taken from <https://www.gnu.org/software/emacs/manual/html_mono/.>")
(defconst org-info-other-documents
(defcustom org-info-other-documents
'(("dir" . "https://www.gnu.org/manual/manual.html") ; index
("libc" . "https://www.gnu.org/software/libc/manual/html_mono/libc.html")
("make" . "https://www.gnu.org/software/make/manual/make.html"))
"Alist of documents generated from Texinfo source.
When converting info links to HTML, links to any one of these manuals are
converted to use these URL.")
converted to use these URL."
:group 'org-link
:type '(alist :key-type string :value-type string)
:package-version '(Org . "9.7")
:safe t)
(defun org-info-map-html-url (filename)
"Return URL or HTML file associated to Info FILENAME.
@ -153,11 +157,11 @@ If FILENAME refers to an official GNU document, return a URL pointing to
the official page for that document, e.g., use \"gnu.org\" for all Emacs
related documents. Otherwise, append \".html\" extension to FILENAME.
See `org-info-emacs-documents' and `org-info-other-documents' for details."
(cond ((member filename org-info-emacs-documents)
(format "https://www.gnu.org/software/emacs/manual/html_mono/%s.html"
filename))
((cdr (assoc filename org-info-other-documents)))
(t (concat filename ".html"))))
(cond ((cdr (assoc filename org-info-other-documents)))
((member filename org-info-emacs-documents)
(format "https://www.gnu.org/software/emacs/manual/html_mono/%s.html"
filename))
(t (concat filename ".html"))))
(defun org-info--expand-node-name (node)
"Expand Info NODE to HTML cross reference."

View File

@ -1,6 +1,6 @@
;;; ol-irc.el --- Links to IRC Sessions -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2008-2023 Free Software Foundation, Inc.
;; Copyright (C) 2008-2024 Free Software Foundation, Inc.
;;
;; Author: Philip Jackson <emacs@shellarchive.co.uk>
;; Keywords: erc, irc, link, org
@ -103,7 +103,7 @@ attributes that are found."
parts))
;;;###autoload
(defun org-irc-store-link ()
(defun org-irc-store-link (&optional _interactive?)
"Dispatch to the appropriate function to store a link to an IRC session."
(cond
((eq major-mode 'erc-mode)

View File

@ -1,6 +1,6 @@
;;; ol-man.el --- Links to man pages -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2020-2023 Free Software Foundation, Inc.
;; Copyright (C) 2020-2024 Free Software Foundation, Inc.
;; Author: Carsten Dominik <carsten.dominik@gmail.com>
;; Maintainer: Bastien Guerry <bzg@gnu.org>
;; Keywords: outlines, hypermedia, calendar, wp
@ -24,12 +24,17 @@
;;
;;; Commentary:
;; This file implements links to man pages from within Org mode.
;;; Code:
(require 'org-macs)
(org-assert-version)
(require 'ol)
(org-link-set-parameters "man"
:complete #'org-man-complete
:follow #'org-man-open
:export #'org-man-export
:store #'org-man-store-link)
@ -37,15 +42,29 @@
(defcustom org-man-command 'man
"The Emacs command to be used to display a man page."
:group 'org-link
:type '(choice (const man) (const woman)))
:type '(choice (const man) (const :tag "WoMan (obsolete)" woman)))
(declare-function Man-translate-references "man" (ref))
(defun org-man-open (path _)
"Visit the manpage on PATH.
PATH should be a topic that can be thrown at the man command.
If PATH contains extra ::STRING which will use `occur' to search
matched strings in man buffer."
(require 'man) ; For `Man-translate-references'
(string-match "\\(.*?\\)\\(?:::\\(.*\\)\\)?$" path)
(let* ((command (match-string 1 path))
;; FIXME: Remove after we drop Emacs 29 support.
;; Working around security bug #66390.
(command (if (not (equal (Man-translate-references ";id") ";id"))
;; We are on Emacs that escapes man command args
;; (see Emacs commit 820f0793f0b).
command
;; Older Emacs without the fix - escape the
;; arguments ourselves.
(mapconcat 'identity
(mapcar #'shell-quote-argument
(split-string command "\\s-+"))
" ")))
(search (match-string 2 path))
(buffer (funcall org-man-command command)))
(when search
@ -63,7 +82,7 @@ matched strings in man buffer."
(set-window-point window point)
(set-window-start window point)))))))
(defun org-man-store-link ()
(defun org-man-store-link (&optional _interactive?)
"Store a link to a README file."
(when (memq major-mode '(Man-mode woman-mode))
;; This is a man page, we do make this link
@ -82,18 +101,31 @@ matched strings in man buffer."
(match-string 1 (buffer-name))
(error "Cannot create link to this man page")))
(defun org-man-export (link description format)
"Export a man page link from Org files."
(defun org-man-export (link description backend)
"Export a man page LINK with DESCRIPTION.
BACKEND is the current export backend."
(let ((path (format "http://man.he.net/?topic=%s&section=all" link))
(desc (or description link)))
(cond
((eq format 'html) (format "<a target=\"_blank\" href=\"%s\">%s</a>" path desc))
((eq format 'latex) (format "\\href{%s}{%s}" path desc))
((eq format 'texinfo) (format "@uref{%s,%s}" path desc))
((eq format 'ascii) (format "%s (%s)" desc path))
((eq format 'md) (format "[%s](%s)" desc path))
((eq backend 'html) (format "<a target=\"_blank\" href=\"%s\">%s</a>" path desc))
((eq backend 'latex) (format "\\href{%s}{%s}" path desc))
((eq backend 'texinfo) (format "@uref{%s,%s}" path desc))
((eq backend 'ascii) (format "[%s] (<%s>)" desc path))
((eq backend 'md) (format "[%s](%s)" desc path))
(t path))))
(defvar Man-completion-cache) ; Defined in `man'.
(defun org-man-complete (&optional _arg)
"Complete man pages for `org-insert-link'."
(require 'man)
(concat
"man:"
(let ((completion-ignore-case t) ; See `man' comments.
(Man-completion-cache)) ; See `man' implementation.
(completing-read
"Manual entry: "
'Man-completion-table))))
(provide 'ol-man)
;;; ol-man.el ends here

View File

@ -1,6 +1,6 @@
;;; ol-mhe.el --- Links to MH-E Messages -*- lexical-binding: t; -*-
;; Copyright (C) 2004-2023 Free Software Foundation, Inc.
;; Copyright (C) 2004-2024 Free Software Foundation, Inc.
;; Author: Thomas Baumann <thomas dot baumann at ch dot tum dot de>
;; Keywords: outlines, hypermedia, calendar, wp
@ -80,7 +80,7 @@ supported by MH-E."
(org-link-set-parameters "mhe" :follow #'org-mhe-open :store #'org-mhe-store-link)
;; Implementation
(defun org-mhe-store-link ()
(defun org-mhe-store-link (&optional _interactive?)
"Store a link to an MH-E folder or message."
(when (or (eq major-mode 'mh-folder-mode)
(eq major-mode 'mh-show-mode))

View File

@ -1,6 +1,6 @@
;;; ol-rmail.el --- Links to Rmail Messages -*- lexical-binding: t; -*-
;; Copyright (C) 2004-2023 Free Software Foundation, Inc.
;; Copyright (C) 2004-2024 Free Software Foundation, Inc.
;; Author: Carsten Dominik <carsten.dominik@gmail.com>
;; Keywords: outlines, hypermedia, calendar, wp
@ -51,7 +51,7 @@
:store #'org-rmail-store-link)
;; Implementation
(defun org-rmail-store-link ()
(defun org-rmail-store-link (&optional _interactive?)
"Store a link to an Rmail folder or message."
(when (or (eq major-mode 'rmail-mode)
(eq major-mode 'rmail-summary-mode))

View File

@ -1,6 +1,6 @@
;;; ol-w3m.el --- Copy and Paste From W3M -*- lexical-binding: t; -*-
;; Copyright (C) 2008-2023 Free Software Foundation, Inc.
;; Copyright (C) 2008-2024 Free Software Foundation, Inc.
;; Author: Andy Stewart <lazycat dot manatee at gmail dot com>
;; Keywords: outlines, hypermedia, calendar, wp

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
;;; org-archive.el --- Archiving for Org -*- lexical-binding: t; -*-
;; Copyright (C) 2004-2023 Free Software Foundation, Inc.
;; Copyright (C) 2004-2024 Free Software Foundation, Inc.
;; Author: Carsten Dominik <carsten.dominik@gmail.com>
;; Keywords: outlines, hypermedia, calendar, wp
@ -34,9 +34,9 @@
(require 'org)
(require 'cl-lib)
(declare-function org-element-type "org-element" (element))
(declare-function org-datetree-find-date-create "org-datetree" (date &optional keep-restriction))
(declare-function org-inlinetask-remove-END-maybe "org-inlinetask" ())
(declare-function org-timestamp-to-now "org" (timestamp-string &optional seconds))
;; From org-element.el
(defvar org-element--cache-avoid-synchronous-headline-re-parsing)
@ -154,10 +154,10 @@ archive location, but not yet deleted from the original file.")
;;;###autoload
(defun org-add-archive-files (files)
"Splice the archive files into the list of files.
"Splice the archive FILES into the list of files.
This implies visiting all these files and finding out what the
archive file is."
(org-uniquify
(seq-uniq
(apply
'append
(mapcar
@ -166,7 +166,9 @@ archive file is."
nil
(with-current-buffer (org-get-agenda-file-buffer f)
(cons f (org-all-archive-files)))))
files))))
files))
#'file-equal-p
))
(defun org-all-archive-files ()
"List of all archive files used in the current buffer."
@ -252,8 +254,7 @@ direct children of this heading."
(newfile-p (and (org-string-nw-p afile)
(not (file-exists-p afile))))
(buffer (cond ((not (org-string-nw-p afile)) this-buffer)
((find-buffer-visiting afile))
((find-file-noselect afile))
((find-file-noselect afile 'nowarn))
(t (error "Cannot access file \"%s\"" afile))))
(org-odd-levels-only
(if (local-variable-p 'org-odd-levels-only (current-buffer))
@ -477,9 +478,9 @@ Archiving time is retained in the ARCHIVE_TIME node property."
(goto-char e)
(or (bolp) (newline))
(insert leader org-archive-sibling-heading "\n")
(beginning-of-line 0)
(forward-line -1)
(org-toggle-tag org-archive-tag 'on))
(beginning-of-line 1)
(forward-line 0)
(if org-archive-reversed-order
(outline-next-heading)
(org-end-of-subtree t t))
@ -524,12 +525,12 @@ When TAG is non-nil, don't move trees, but mark them with the ARCHIVE tag."
(let (ts)
(and (re-search-forward org-ts-regexp end t)
(setq ts (match-string 0))
(< (org-time-stamp-to-now ts) 0)
(< (org-timestamp-to-now ts) 0)
(if (not (looking-at
(concat "--\\(" org-ts-regexp "\\)")))
(concat "--\\(" org-ts-regexp "\\)")))
(concat "old timestamp " ts)
(setq ts (concat "old timestamp " ts (match-string 0)))
(and (< (org-time-stamp-to-now (match-string 1)) 0)
(and (< (org-timestamp-to-now (match-string 1)) 0)
ts)))))
tag))
@ -590,8 +591,9 @@ don't move trees, but mark them with the ARCHIVE tag."
;;;###autoload
(defun org-toggle-archive-tag (&optional find-done)
"Toggle the archive tag for the current headline.
With prefix ARG, check all children of current headline and offer tagging
the children that do not contain any open TODO items."
With prefix argument FIND-DONE, check all children of current headline
and offer tagging the children that do not contain any open TODO
items."
(interactive "P")
(if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
(let ((cl (if (eq org-loop-over-headlines-in-active-region 'start-level)
@ -608,7 +610,7 @@ the children that do not contain any open TODO items."
(org-back-to-heading t)
(setq set (org-toggle-tag org-archive-tag))
(when set (org-fold-subtree t)))
(and set (beginning-of-line 1))
(and set (forward-line 0))
(message "Subtree %s" (if set "archived" "unarchived"))))))
(defun org-archive-set-tag ()

View File

@ -1,6 +1,6 @@
;;; org-attach-git.el --- Automatic git commit extension to org-attach -*- lexical-binding: t; -*-
;; Copyright (C) 2019-2023 Free Software Foundation, Inc.
;; Copyright (C) 2019-2024 Free Software Foundation, Inc.
;; Original Author: John Wiegley <johnw@newartisans.com>
;; Restructurer: Gustav Wikström <gustav@whil.se>

View File

@ -1,6 +1,6 @@
;;; org-attach.el --- Manage file attachments to Org outlines -*- lexical-binding: t; -*-
;; Copyright (C) 2008-2023 Free Software Foundation, Inc.
;; Copyright (C) 2008-2024 Free Software Foundation, Inc.
;; Author: John Wiegley <johnw@newartisans.com>
;; Keywords: org data attachment
@ -44,8 +44,12 @@
(declare-function dired-dwim-target-directory "dired-aux")
(declare-function dired-get-marked-files "dired" (&optional localp arg filter distinguish-one-marked error))
(declare-function org-element-property "org-element" (property element))
(declare-function org-element-type "org-element" (element))
(declare-function org-element-property "org-element-ast" (property node))
(declare-function org-element-begin "org-element" (node))
(declare-function org-element-end "org-element" (node))
(declare-function org-element-contents-begin "org-element" (node))
(declare-function org-element-contents-end "org-element" (node))
(declare-function org-element-type-p "org-element-ast" (node types))
(declare-function org-inlinetask-goto-beginning "org-inlinetask" ())
(declare-function org-inlinetask-in-task-p "org-inlinetask" ())
@ -138,7 +142,7 @@ Selective means to respect the inheritance setting in
(const :tag "Inherit parent node attachments" t)
(const :tag "Respect org-use-property-inheritance" selective)))
(defcustom org-attach-store-link-p nil
(defcustom org-attach-store-link-p 'attached
"Non-nil means store a link to a file when attaching it.
When t, store the link to original file location.
When `file', store link to the attached file location.
@ -297,67 +301,71 @@ ask the user instead, else remove without asking."
"The dispatcher for attachment commands.
Shows a list of commands and prompts for another key to execute a command."
(interactive)
(let ((dir (org-attach-dir nil 'no-fs-check))
c marker)
(let (c marker)
(when (eq major-mode 'org-agenda-mode)
(setq marker (or (get-text-property (point) 'org-hd-marker)
(get-text-property (point) 'org-marker)))
(unless marker
(error "No item in current line")))
(org-with-point-at marker
(if (and (featurep 'org-inlinetask)
(not (org-inlinetask-in-task-p)))
(org-with-limited-levels
(org-back-to-heading-or-point-min t))
(let ((dir (org-attach-dir nil 'no-fs-check)))
(if (and (featurep 'org-inlinetask)
(org-inlinetask-in-task-p))
(org-inlinetask-goto-beginning)
(org-back-to-heading-or-point-min t)))
(save-excursion
(save-window-excursion
(unless org-attach-expert
(org-switch-to-buffer-other-window "*Org Attach*")
(erase-buffer)
(setq cursor-type nil
header-line-format "Use C-v, M-v, C-n or C-p to navigate.")
(insert
(concat "Attachment folder:\n"
(or dir
"Can't find an existing attachment-folder")
(unless (and dir (file-directory-p dir))
"\n(Not yet created)")
"\n\n"
(format "Select an Attachment Command:\n\n%s"
(mapconcat
(lambda (entry)
(pcase entry
(`((,key . ,_) ,_ ,docstring)
(format "%c %s"
key
(replace-regexp-in-string "\n\\([\t ]*\\)"
" "
docstring
nil nil 1)))
(_
(user-error
"Invalid `org-attach-commands' item: %S"
entry))))
org-attach-commands
"\n")))))
(org-fit-window-to-buffer (get-buffer-window "*Org Attach*"))
(let ((msg (format "Select command: [%s]"
(concat (mapcar #'caar org-attach-commands)))))
(message msg)
(while (and (setq c (read-char-exclusive))
(memq c '(?\C-n ?\C-p ?\C-v ?\M-v)))
(org-scroll c t)))
(and (get-buffer "*Org Attach*") (kill-buffer "*Org Attach*"))))
(let ((command (cl-some (lambda (entry)
(and (memq c (nth 0 entry)) (nth 1 entry)))
org-attach-commands)))
(if (commandp command)
(command-execute command)
(error "No such attachment command: %c" c))))))
(not (org-inlinetask-in-task-p)))
(org-with-limited-levels
(org-back-to-heading-or-point-min t))
(if (and (featurep 'org-inlinetask)
(org-inlinetask-in-task-p))
(org-inlinetask-goto-beginning)
(org-back-to-heading-or-point-min t)))
(save-excursion
(save-window-excursion
(unless org-attach-expert
(switch-to-buffer-other-window "*Org Attach*")
(erase-buffer)
(setq cursor-type nil
header-line-format "Use C-v, M-v, C-n or C-p to navigate.")
(insert
(concat "Attachment folder:\n"
(or dir
"Can't find an existing attachment-folder")
(unless (and dir (file-directory-p dir))
"\n(Not yet created)")
"\n\n"
(format "Select an Attachment Command:\n\n%s"
(mapconcat
(lambda (entry)
(pcase entry
(`((,key . ,_) ,_ ,docstring)
(format "%c %s"
key
(replace-regexp-in-string "\n\\([\t ]*\\)"
" "
docstring
nil nil 1)))
(_
(user-error
"Invalid `org-attach-commands' item: %S"
entry))))
org-attach-commands
"\n"))))
(goto-char (point-min)))
(org-fit-window-to-buffer (get-buffer-window "*Org Attach*"))
(unwind-protect
(let ((msg (format "Select command: [%s]"
(concat (mapcar #'caar org-attach-commands)))))
(message msg)
(while (and (setq c (read-char-exclusive))
(memq c '(?\C-n ?\C-p ?\C-v ?\M-v)))
(org-scroll c t)))
(when-let ((window (get-buffer-window "*Org Attach*" t)))
(quit-window 'kill window))
(and (get-buffer "*Org Attach*") (kill-buffer "*Org Attach*")))))
(let ((command (cl-some (lambda (entry)
(and (memq c (nth 0 entry)) (nth 1 entry)))
org-attach-commands)))
(if (commandp command)
(command-execute command)
(error "No such attachment command: %c" c)))))))
;;;###autoload
(defun org-attach-dir (&optional create-if-not-exists-p no-fs-check)
@ -432,17 +440,26 @@ ignoring nils. If EXISTING is non-nil, then return the first path
found in the filesystem. Otherwise return the first non-nil value."
(let ((fun-list org-attach-id-to-path-function-list)
(base-dir (expand-file-name org-attach-id-dir))
(default-base-dir (expand-file-name "data/"))
preferred first)
(while (and fun-list
(not preferred))
(let* ((name (funcall (car fun-list) id))
(candidate (and name (expand-file-name name base-dir))))
(candidate (and name (expand-file-name name base-dir)))
;; Try the default value `org-attach-id-dir' as a fallback.
(candidate2 (and name (not (equal base-dir default-base-dir))
(expand-file-name name default-base-dir))))
(setq fun-list (cdr fun-list))
(when candidate
(if (or (not existing) (file-directory-p candidate))
(setq preferred candidate)
(unless first
(setq first candidate))))))
(setq first candidate)))
(when (and existing
candidate2
(not (file-directory-p candidate))
(file-directory-p candidate2))
(setq preferred candidate2)))))
(or preferred first)))
(defun org-attach-check-absolute-path (dir)
@ -512,9 +529,13 @@ DIR-property exists (that is different from the unset one)."
(defun org-attach-tag (&optional off)
"Turn the autotag on or (if OFF is set) off."
(when org-attach-auto-tag
(save-excursion
(org-back-to-heading t)
(org-toggle-tag org-attach-auto-tag (if off 'off 'on)))))
;; FIXME: There is currently no way to set #+FILETAGS
;; programatically. Do nothing when before first heading
;; (attaching to file) to avoid blocking error.
(unless (org-before-first-heading-p)
(save-excursion
(org-back-to-heading t)
(org-toggle-tag org-attach-auto-tag (if off 'off 'on))))))
(defun org-attach-untag ()
"Turn the autotag off."
@ -573,7 +594,7 @@ METHOD may be `cp', `mv', `ln', `lns' or `url' default taken from
((eq method 'url)
(if (org--should-fetch-remote-resource-p file)
(url-copy-file file attach-file)
(error "The remote resource %S is considered unsafe, and will not be downloaded."
(error "The remote resource %S is considered unsafe, and will not be downloaded"
file))))
(run-hook-with-args 'org-attach-after-change-hook attach-dir)
(org-attach-tag)
@ -736,20 +757,20 @@ It is meant to be added to `org-export-before-parsing-hook'."
(save-excursion
(while (re-search-forward "attachment:" nil t)
(let ((link (org-element-context)))
(when (and (eq 'link (org-element-type link))
(when (and (org-element-type-p link 'link)
(string-equal "attachment"
(org-element-property :type link)))
(let* ((description (and (org-element-property :contents-begin link)
(let* ((description (and (org-element-contents-begin link)
(buffer-substring-no-properties
(org-element-property :contents-begin link)
(org-element-property :contents-end link))))
(org-element-contents-begin link)
(org-element-contents-end link))))
(file (org-element-property :path link))
(new-link (org-link-make-string
(concat "file:" (org-attach-expand file))
description)))
(goto-char (org-element-property :end link))
(goto-char (org-element-end link))
(skip-chars-backward " \t")
(delete-region (org-element-property :begin link) (point))
(delete-region (org-element-begin link) (point))
(insert new-link)))))))
(defun org-attach-follow (file arg)

View File

@ -1,6 +1,6 @@
;;; org-capture.el --- Fast note taking in Org -*- lexical-binding: t; -*-
;; Copyright (C) 2010-2023 Free Software Foundation, Inc.
;; Copyright (C) 2010-2024 Free Software Foundation, Inc.
;; Author: Carsten Dominik <carsten.dominik@gmail.com>
;; Keywords: outlines, hypermedia, calendar, wp
@ -58,11 +58,13 @@
(declare-function org-at-table-p "org-table" (&optional table-type))
(declare-function org-clock-update-mode-line "org-clock" (&optional refresh))
(declare-function org-datetree-find-date-create "org-datetree" (date &optional keep-restriction))
(declare-function org-datetree-find-month-create (d &optional keep-restriction))
(declare-function org-datetree-find-month-create "org-datetree" (d &optional keep-restriction))
(declare-function org-decrypt-entry "org-crypt" ())
(declare-function org-element-at-point "org-element" (&optional pom cached-only))
(declare-function org-element-lineage "org-element" (datum &optional types with-self))
(declare-function org-element-property "org-element" (property element))
(declare-function org-element-lineage "org-element-ast" (datum &optional types with-self))
(declare-function org-element-property "org-element-ast" (property node))
(declare-function org-element-contents-end "org-element" (node))
(declare-function org-element-post-affiliated "org-element" (node))
(declare-function org-encrypt-entry "org-crypt" ())
(declare-function org-insert-link "ol" (&optional complete-file link-location default-description))
(declare-function org-link-make-string "ol" (link &optional description))
@ -220,6 +222,9 @@ target Specification of where the captured item should be placed.
(clock)
File to the entry that is currently being clocked
(here)
The position of point
(function function-finding-location)
Most general way: write your own function which both visits
the file and moves point to the right location
@ -366,6 +371,10 @@ be replaced with content and expanded:
%^{prompt} Prompt the user for a string and replace this sequence with it.
A default value and a completion table can be specified like this:
%^{prompt|default|completion2|completion3|...}.
%^{prompt}X where X is one of g, G, t, T, u, U, C, or L.
Same as %^X (see above), but also supply custom
prompt/completions. Default value and completions as in
%^{prompt|default|...}X are allowed.
%? After completing the template, position cursor here.
%\\1 ... %\\N Insert the text entered at the nth %^{prompt}, where N
is a number, starting from 1.
@ -496,12 +505,6 @@ The capture buffer is current and still narrowed."
:version "24.1"
:type 'hook)
(defcustom org-capture-bookmark t
"When non-nil, add bookmark pointing at the last stored position when capturing."
:group 'org-capture
:version "24.3"
:type 'boolean)
;;; The property list for keeping information about the capture process
(defvar org-capture-plist nil
@ -579,7 +582,9 @@ this template to be accessible only from `message-mode' buffers,
use this:
(setq org-capture-templates-contexts
\\='((\"c\" ((in-mode . \"message-mode\")))))
\\='((\"c\" ((in-mode . \"message-mode\")))
(\"d\" (my-context-function
(in-mode . \"org-mode\")))))
Here are the available contexts definitions:
@ -889,10 +894,16 @@ captured item after finalizing."
(goto-char (+ size pos))
(goto-char (if (< ipt pos) (+ size pos) pos))))))
;; Kill the target buffer if that is desired
(when (and base-buffer new-buffer kill-buffer)
(with-current-buffer base-buffer (save-buffer))
(kill-buffer base-buffer))
(if (and base-buffer org-note-abort new-buffer)
;; Unconditionally kill the new buffer when capture is
;; aborted.
(with-current-buffer base-buffer
(set-buffer-modified-p nil)
(kill-buffer))
;; Kill the target buffer if that is desired
(when (and base-buffer new-buffer kill-buffer)
(with-current-buffer base-buffer (save-buffer))
(kill-buffer base-buffer)))
;; Restore the window configuration before capture
(set-window-configuration return-wconf))
@ -985,14 +996,15 @@ Store them in the capture property list."
(let ((target-entry-p t))
(save-excursion
(pcase (or target (org-capture-get :target))
(`here
((or `here
`(here))
(org-capture-put :exact-position (point) :insert-here t))
(`(file ,path)
(set-buffer (org-capture-target-buffer path))
(org-capture-put-target-region-and-position)
(widen)
(setq target-entry-p nil))
(`(id ,id)
(`(id ,(and id (or (pred stringp) (pred symbolp))))
(pcase (org-id-find id)
(`(,path . ,position)
(set-buffer (org-capture-target-buffer path))
@ -1000,7 +1012,7 @@ Store them in the capture property list."
(org-capture-put-target-region-and-position)
(goto-char position))
(_ (error "Cannot find target ID \"%s\"" id))))
(`(file+headline ,path ,headline)
(`(file+headline ,path ,(and headline (pred stringp)))
(set-buffer (org-capture-target-buffer path))
;; Org expects the target file to be in Org mode, otherwise
;; it throws an error. However, the default notes files
@ -1017,12 +1029,12 @@ Store them in the capture property list."
(if (re-search-forward (format org-complex-heading-regexp-format
(regexp-quote headline))
nil t)
(beginning-of-line)
(forward-line 0)
(goto-char (point-max))
(unless (bolp) (insert "\n"))
(insert "* " headline "\n")
(beginning-of-line 0)))
(`(file+olp ,path . ,outline-path)
(forward-line -1)))
(`(file+olp ,path . ,(and outline-path (guard outline-path)))
(let ((m (org-find-olp (cons (org-capture-expand-file path)
outline-path))))
(set-buffer (marker-buffer m))
@ -1030,7 +1042,7 @@ Store them in the capture property list."
(widen)
(goto-char m)
(set-marker m nil)))
(`(file+regexp ,path ,regexp)
(`(file+regexp ,path ,(and regexp (pred stringp)))
(set-buffer (org-capture-target-buffer path))
(org-capture-put-target-region-and-position)
(widen)
@ -1098,7 +1110,7 @@ Store them in the capture property list."
;; the following is the keep-restriction argument for
;; org-datetree-find-date-create
(when outline-path 'subtree-at-point))))
(`(file+function ,path ,function)
(`(file+function ,path ,(and function (pred functionp)))
(set-buffer (org-capture-target-buffer path))
(org-capture-put-target-region-and-position)
(widen)
@ -1106,7 +1118,7 @@ Store them in the capture property list."
(org-capture-put :exact-position (point))
(setq target-entry-p
(and (derived-mode-p 'org-mode) (org-at-heading-p))))
(`(function ,fun)
(`(function ,(and fun (pred functionp)))
(funcall fun)
(org-capture-put :exact-position (point))
(setq target-entry-p
@ -1162,9 +1174,9 @@ When INHIBIT-WCONF-STORE is non-nil, don't store the window configuration, as it
may have been stored before."
(unless inhibit-wconf-store
(org-capture-put :return-to-wconf (current-window-configuration)))
(delete-other-windows)
(org-switch-to-buffer-other-window
(org-capture-get-indirect-buffer (org-capture-get :buffer) "CAPTURE"))
(pop-to-buffer
(org-capture-get-indirect-buffer (org-capture-get :buffer) "CAPTURE")
'(org-display-buffer-split))
(widen)
(org-fold-show-all)
(goto-char (org-capture-get :pos))
@ -1262,7 +1274,7 @@ may have been stored before."
(catch :found
(while (re-search-forward item-regexp end t)
(when (setq item (org-element-lineage
(org-element-at-point) '(plain-list) t))
(org-element-at-point) 'plain-list t))
(goto-char (org-element-property (if prepend? :post-affiliated
:contents-end)
item))
@ -1304,7 +1316,7 @@ may have been stored before."
(point-marker))))
(when item
(let ((i (save-excursion
(goto-char (org-element-property :post-affiliated item))
(goto-char (org-element-post-affiliated item))
(org-current-text-indentation))))
(save-excursion
(goto-char beg)
@ -1367,13 +1379,13 @@ may have been stored before."
;; Narrow to the table, possibly creating one if necessary.
(catch :found
(while (re-search-forward org-table-dataline-regexp end t)
(pcase (org-element-lineage (org-element-at-point) '(table) t)
(pcase (org-element-lineage (org-element-at-point) 'table t)
(`nil nil)
((pred (lambda (e) (eq 'table.el (org-element-property :type e))))
nil)
(table
(goto-char (org-element-property :contents-end table))
(narrow-to-region (org-element-property :post-affiliated table)
(goto-char (org-element-contents-end table))
(narrow-to-region (org-element-post-affiliated table)
(point))
(throw :found t))))
;; No table found. Create it with an empty header.
@ -1403,7 +1415,7 @@ may have been stored before."
(goto-char (point-min))
(cond
((not (re-search-forward org-table-hline-regexp nil t)))
((re-search-forward org-table-dataline-regexp nil t) (beginning-of-line))
((re-search-forward org-table-dataline-regexp nil t) (forward-line 0))
(t (goto-char (org-table-end)))))
(t
(goto-char (org-table-end))))
@ -1492,10 +1504,15 @@ Of course, if exact position has been required, just put it there."
(point))))))
(with-current-buffer (buffer-base-buffer (current-buffer))
(org-with-point-at pos
(when org-capture-bookmark
;; FIXME: `org-capture-bookmark' is obsolete. To be removed
;; in future Org releases.
(when (with-no-warnings org-capture-bookmark)
(let ((bookmark (plist-get org-bookmark-names-plist :last-capture)))
(when bookmark (with-demoted-errors "Bookmark set error: %S"
(bookmark-set bookmark)))))
(when bookmark
(condition-case err
(bookmark-set bookmark)
(error
(message "Bookmark set error: %S" err))))))
(move-marker org-capture-last-stored-marker (point))))))
(defun org-capture-narrow (beg end)
@ -1658,11 +1675,8 @@ Expansion occurs in a temporary Org mode buffer."
(org-no-properties org-clock-heading)
""))
(v-K (if (marker-buffer org-clock-marker)
(org-link-make-string
(format "%s::*%s"
(buffer-file-name (marker-buffer org-clock-marker))
v-k)
v-k)
(org-with-point-at org-clock-marker
(org-store-link nil nil))
""))
(v-f (or (org-capture-get :original-file-nondirectory) ""))
(v-F (or (org-capture-get :original-file) ""))
@ -1680,7 +1694,7 @@ Expansion occurs in a temporary Org mode buffer."
(message "no template") (ding)
(sit-for 1))
(save-window-excursion
(org-switch-to-buffer-other-window (get-buffer-create "*Capture*"))
(switch-to-buffer-other-window (get-buffer-create "*Capture*"))
(erase-buffer)
(setq buffer-file-name nil)
(setq mark-active nil)
@ -1852,7 +1866,7 @@ Expansion occurs in a temporary Org mode buffer."
(let* ((upcase? (equal (upcase key) key))
(org-end-time-was-given nil)
(time (org-read-date upcase? t nil prompt)))
(org-insert-time-stamp
(org-insert-timestamp
time (or org-time-was-given upcase?)
(member key '("u" "U"))
nil nil (list org-end-time-was-given))))

View File

@ -1,6 +1,6 @@
;;; org-clock.el --- The time clocking code for Org mode -*- lexical-binding: t; -*-
;; Copyright (C) 2004-2023 Free Software Foundation, Inc.
;; Copyright (C) 2004-2024 Free Software Foundation, Inc.
;; Author: Carsten Dominik <carsten.dominik@gmail.com>
;; Keywords: outlines, hypermedia, calendar, wp
@ -36,9 +36,11 @@
(declare-function calendar-iso-to-absolute "cal-iso" (date))
(declare-function notifications-notify "notifications" (&rest params))
(declare-function org-element-property "org-element" (property element))
(declare-function org-element-type "org-element" (element))
(declare-function org-element--cache-active-p "org-element" ())
(declare-function org-element-property "org-element-ast" (property node))
(declare-function org-element-contents-end "org-element" (node))
(declare-function org-element-end "org-element" (node))
(declare-function org-element-type "org-element-ast" (node &optional anonymous))
(declare-function org-element-type-p "org-element-ast" (node types))
(defvar org-element-use-cache)
(declare-function org-inlinetask-at-task-p "org-inlinetask" ())
(declare-function org-inlinetask-goto-beginning "org-inlinetask" ())
@ -51,6 +53,9 @@
(declare-function org-dynamic-block-define "org" (type func))
(declare-function w32-notification-notify "w32fns.c" (&rest params))
(declare-function w32-notification-close "w32fns.c" (&rest params))
(declare-function dbus-list-activatable-names "dbus" (&optional bus))
(declare-function dbus-call-method "dbus" (bus service path interface method &rest args))
(declare-function dbus-get-property "dbus" (bus service path interface property))
(defvar org-frame-title-format-backup nil)
(defvar org-state)
@ -125,7 +130,7 @@ clocking out."
"Rounding minutes when clocking in or out.
The default value is 0 so that no rounding is done.
When set to a non-integer value, use the car of
`org-time-stamp-rounding-minutes', like for setting a time-stamp.
`org-timestamp-rounding-minutes', like for setting a timestamp.
E.g. if `org-clock-rounding-minutes' is set to 5, time is 14:47
and you clock in: then the clock starts at 14:45. If you clock
@ -344,14 +349,16 @@ For more information, see `org-clocktable-write-default'."
:version "24.1"
:type 'function)
;; FIXME: translate es and nl last string "Clock summary at"
(defcustom org-clock-clocktable-language-setup
'(("en" "File" "L" "Timestamp" "Headline" "Time" "ALL" "Total time" "File time" "Clock summary at")
("es" "Archivo" "N" "Fecha y hora" "Tarea" "Tiempo" "TODO" "Tiempo total" "Tiempo archivo" "Clock summary at")
("fr" "Fichier" "N" "Horodatage" "En-tête" "Durée" "TOUT" "Durée totale" "Durée fichier" "Horodatage sommaire à")
("nl" "Bestand" "N" "Tijdstip" "Hoofding" "Duur" "ALLES" "Totale duur" "Bestandstijd" "Clock summary at")
("de" "Datei" "E" "Zeitstempel" "Kopfzeile" "Dauer" "GESAMT"
"Gesamtdauer" "Dateizeit" "Erstellt am"))
'(("en" "File" "L" "Timestamp" "Headline" "Time" "ALL" "Total time" "File time" "Clock summary at")
("de" "Datei" "E" "Zeitstempel" "Kopfzeile" "Dauer" "GESAMT" "Gesamtdauer" "Dateizeit" "Erstellt am")
("es" "Archivo" "N" "Fecha y hora" "Tarea" "Duración" "TODO" "Duración total" "Tiempo archivo" "Generado el")
("fr" "Fichier" "N" "Horodatage" "En-tête" "Durée" "TOUT" "Durée totale" "Durée fichier" "Horodatage sommaire à")
("nl" "Bestand" "N" "Tijdstip" "Rubriek" "Duur" "ALLES" "Totale duur" "Bestandstijd" "Klok overzicht op")
("nn" "Fil" "N" "Tidspunkt" "Overskrift" "Tid" "ALLE" "Total tid" "Filtid" "Tidsoversyn")
("pl" "Plik" "P" "Data i godzina" "Nagłówek" "Czas" "WSZYSTKO" "Czas całkowity" "Czas pliku" "Poddumowanie zegara na")
("pt-BR" "Arquivo" "N" "Data e hora" "Título" "Hora" "TODOS" "Hora total" "Hora do arquivo" "Resumo das horas em")
("sk" "Súbor" "L" "Časová značka" "Záhlavie" "Čas" "VŠETKO" "Celkový čas" "Čas súboru" "Časový súhrn pre"))
"Terms used in clocktable, translated to different languages."
:group 'org-clocktable
:version "24.1"
@ -411,8 +418,8 @@ play with them."
:type 'string)
(defcustom org-clock-clocked-in-display 'mode-line
"When clocked in for a task, Org can display the current
task and accumulated time in the mode line and/or frame title.
"Where to display clocked in task and accumulated time when clocked in.
Allowed values are:
both displays in both mode line and frame title
@ -438,7 +445,9 @@ This uses the same format as `frame-title-format', which see."
:group 'org-clock
:type 'sexp)
(defcustom org-clock-x11idle-program-name "x11idle"
(defcustom org-clock-x11idle-program-name
(if (executable-find "xprintidle")
"xprintidle" "x11idle")
"Name of the program which prints X11 idle time in milliseconds.
you can do \"~$ sudo apt-get install xprintidle\" if you are using
@ -447,8 +456,7 @@ a Debian-based distribution.
Alternatively, can find x11idle.c in
https://orgmode.org/worg/code/scripts/x11idle.c"
:group 'org-clock
:version "24.4"
:package-version '(Org . "8.0")
:package-version '(Org . "9.7")
:type 'string)
(defcustom org-clock-goto-before-context 2
@ -506,7 +514,11 @@ to add an effort property.")
(defvar org-clock-in-hook nil
"Hook run when starting the clock.")
(defvar org-clock-out-hook nil
"Hook run when stopping the current clock.")
"Hook run when stopping the current clock.
The point is at the current clock line when the hook is executed.
The hook functions can access `org-clock-out-removed-last-clock' to
check whether the latest CLOCK line has been cleared.")
(defvar org-clock-cancel-hook nil
"Hook run when canceling the current clock.")
@ -560,6 +572,10 @@ of a different task.")
Assume S in the English term to translate. Return S as-is if it
cannot be translated."
(or (nth (pcase s
;; "L" stands for "Level"
;; "ALL" stands for a line summarizing clock data across
;; all the files, when the clocktable includes multiple
;; files.
("File" 1) ("L" 2) ("Timestamp" 3) ("Headline" 4) ("Time" 5)
("ALL" 6) ("Total time" 7) ("File time" 8) ("Clock summary at" 9))
(assoc-string language org-clock-clocktable-language-setup t))
@ -574,6 +590,7 @@ cannot be translated."
(org-no-properties (org-get-heading t t t t))))))
(defun org-clock-menu ()
"Pop up org-clock menu."
(interactive)
(popup-menu
'("Clock"
@ -583,7 +600,12 @@ cannot be translated."
["Switch task" (lambda () (interactive) (org-clock-in '(4))) :active t :keys "C-u C-c C-x C-i"])))
(defun org-clock-history-push (&optional pos buffer)
"Push a marker to the clock history."
"Push point marker to the clock history.
When POS is provided, use it as marker point.
When BUFFER and POS are provided, use marker at POS in base buffer of
BUFFER."
;; When buffer is provided, POS must be provided.
(cl-assert (or (not buffer) pos))
(setq org-clock-history-length (max 1 org-clock-history-length))
(let ((m (move-marker (make-marker)
(or pos (point)) (org-base-buffer
@ -603,7 +625,10 @@ cannot be translated."
(push m org-clock-history)))
(defun org-clock-save-markers-for-cut-and-paste (beg end)
"Save relative positions of markers in region."
"Save relative positions of markers in region BEG..END.
Save `org-clock-marker', `org-clock-hd-marker',
`org-clock-default-task', `org-clock-interrupted-task', and the
markers in `org-clock-history'."
(org-check-and-save-marker org-clock-marker beg end)
(org-check-and-save-marker org-clock-hd-marker beg end)
(org-check-and-save-marker org-clock-default-task beg end)
@ -629,6 +654,7 @@ cannot be translated."
(defun org-clock-select-task (&optional prompt)
"Select a task that was recently associated with clocking.
PROMPT is the prompt text to be used, as a string.
Return marker position of the selected task. Raise an error if
there is no recent clock to choose from."
(let (och chl sel-list rpl (i 0) s)
@ -639,7 +665,7 @@ there is no recent clock to choose from."
(if (zerop chl)
(user-error "No recent clock")
(save-window-excursion
(org-switch-to-buffer-other-window
(switch-to-buffer-other-window
(get-buffer-create "*Clock Task Select*"))
(erase-buffer)
(when (marker-buffer org-clock-default-task)
@ -669,8 +695,11 @@ there is no recent clock to choose from."
;; `fit-window-to-buffer'
(fit-window-to-buffer nil nil (if (< chl 10) chl (+ 5 chl)))
(message (or prompt "Select task for clocking:"))
(setq cursor-type nil rpl (read-char-exclusive))
(kill-buffer)
(unwind-protect (setq cursor-type nil rpl (read-char-exclusive))
(when-let ((window (get-buffer-window "*Clock Task Select*" t)))
(quit-window 'kill window))
(when (get-buffer "*Clock Task Select*")
(kill-buffer "*Clock Task Select*")))
(cond
((eq rpl ?q) nil)
((eq rpl ?x) nil)
@ -897,7 +926,7 @@ If CLOCK-SOUND is non-nil, it overrides `org-clock-sound'."
(if (executable-find "aplay")
(start-process "org-clock-play-notification" nil
"aplay" file)
(condition-case nil
(condition-case-unless-debug nil
(play-sound-file file)
(error (beep t) (beep t))))))))))
@ -914,9 +943,11 @@ If CLOCK-SOUND is non-nil, it overrides `org-clock-sound'."
(save-excursion
(goto-char (point-min))
(while (re-search-forward org-clock-re nil t)
(push (cons (copy-marker (match-end 1) t)
(org-time-string-to-time (match-string 1)))
clocks))))
(when (save-match-data
(org-element-type-p (org-element-at-point) 'clock))
(push (cons (copy-marker (match-end 1) t)
(org-time-string-to-time (match-string 1)))
clocks)))))
clocks))
(defsubst org-is-active-clock (clock)
@ -930,7 +961,7 @@ If CLOCK-SOUND is non-nil, it overrides `org-clock-sound'."
`(with-current-buffer (marker-buffer (car ,clock))
(org-with-wide-buffer
(goto-char (car ,clock))
(beginning-of-line)
(forward-line 0)
,@forms)))
(defmacro org-with-clock (clock &rest forms)
@ -1036,8 +1067,8 @@ CLOCK is a cons cell of the form (MARKER START-TIME)."
(catch 'exit
(while (re-search-backward drawer-re beg t)
(let ((element (org-element-at-point)))
(when (eq (org-element-type element) 'drawer)
(when (> (org-element-property :end element) (car clock))
(when (org-element-type-p element 'drawer)
(when (> (org-element-end element) (car clock))
(org-fold-hide-drawer-toggle 'off nil element))
(throw 'exit nil)))))))))))
@ -1212,6 +1243,27 @@ If `only-dangling-p' is non-nil, only ask to resolve dangling
"Return the current X11 idle time in seconds."
(/ (string-to-number (shell-command-to-string org-clock-x11idle-program-name)) 1000))
(defvar org-logind-dbus-session-path
(when (and (boundp 'dbus-runtime-version)
(require 'dbus nil t)
(member "org.freedesktop.login1" (dbus-list-activatable-names)))
(ignore-errors
(dbus-call-method
:system "org.freedesktop.login1"
"/org/freedesktop/login1"
"org.freedesktop.login1.Manager"
"GetSessionByPID" (emacs-pid))))
"D-Bus session path for the elogind interface.")
(defun org-logind-user-idle-seconds ()
"Return the number of idle seconds for the user according to logind."
(- (float-time)
(/ (dbus-get-property
:system "org.freedesktop.login1"
org-logind-dbus-session-path
"org.freedesktop.login1.Session" "IdleSinceHint")
1e6)))
(defun org-user-idle-seconds ()
"Return the number of seconds the user has been idle for.
This routine returns a floating point number."
@ -1220,6 +1272,13 @@ This routine returns a floating point number."
(org-mac-idle-seconds))
((and (eq window-system 'x) org-x11idle-exists-p)
(org-x11-idle-seconds))
((and
org-logind-dbus-session-path
(dbus-get-property
:system "org.freedesktop.login1"
org-logind-dbus-session-path
"org.freedesktop.login1.Session" "IdleHint"))
(org-logind-user-idle-seconds))
(t
(org-emacs-idle-seconds))))
@ -1277,8 +1336,6 @@ time as the start time. See `org-clock-continuously' to make this
the default behavior."
(interactive "P")
(setq org-clock-notification-was-shown nil)
(unless org-element-use-cache
(org-refresh-effort-properties))
(catch 'abort
(let ((interrupting (and (not org-clock-resolving-clocks-due-to-idleness)
(org-clocking-p)))
@ -1356,8 +1413,8 @@ the default behavior."
(when newstate (org-todo newstate))))
((and org-clock-in-switch-to-state
(not (looking-at (concat org-outline-regexp "[ \t]*"
org-clock-in-switch-to-state
"\\>"))))
org-clock-in-switch-to-state
"\\>"))))
(org-todo org-clock-in-switch-to-state)))
(setq org-clock-heading (org-clock--mode-line-heading))
(org-clock-find-position org-clock-in-resume)
@ -1383,12 +1440,15 @@ the default behavior."
(sit-for 2)
(throw 'abort nil))
(t
;; Make sure that point moves after clock line upon
;; inserting it. Then, users can continue typing even if
;; point was right where the clock is inserted.
(insert-before-markers-and-inherit "\n")
(backward-char 1)
(when (and (save-excursion
(end-of-line 0)
(org-in-item-p)))
(beginning-of-line 1)
(forward-line 0)
(indent-line-to (max 0 (- (current-indentation) 2))))
(insert-and-inherit org-clock-string " ")
(setq org-clock-effort (org-entry-get (point) org-effort-property))
@ -1408,8 +1468,8 @@ the default behavior."
leftover)
start-time
(org-current-time org-clock-rounding-minutes t)))
(setq ts (org-insert-time-stamp org-clock-start-time
'with-hm 'inactive))
(setq ts (org-insert-timestamp org-clock-start-time
'with-hm 'inactive))
(org-indent-line)))
(move-marker org-clock-marker (point) (buffer-base-buffer))
(move-marker org-clock-hd-marker
@ -1445,6 +1505,33 @@ the default behavior."
(message "Clock starts at %s - %s" ts org--msg-extra)
(run-hooks 'org-clock-in-hook))))))
(defvar org-clock--auto-clockout-timer-obj nil
"Timer object holding the existing clockout timer.")
(defun org-clock--auto-clockout-maybe ()
"Clock out the currently clocked in task when idle.
See `org-clock-auto-clockout-timer' to set the idle time span.
This function is to be called by a timer."
(when (and (numberp org-clock-auto-clockout-timer)
org-clock-current-task)
(let ((user-idle-seconds (org-user-idle-seconds)))
(cond
;; Already idle. Clock out.
((>= user-idle-seconds org-clock-auto-clockout-timer)
(setq org-clock--auto-clockout-timer-obj nil)
(org-clock-out))
;; Emacs is idle but system is not. Retry assuming that system will remain idle.
((>= (org-emacs-idle-seconds) org-clock-auto-clockout-timer)
(setq org-clock--auto-clockout-timer-obj
(run-with-timer
(- org-clock-auto-clockout-timer user-idle-seconds)
nil #'org-clock--auto-clockout-maybe)))
;; Emacs is not idle. Check again next time we are idle.
(t
(setq org-clock--auto-clockout-timer-obj
(run-with-idle-timer
org-clock-auto-clockout-timer nil #'org-clock--auto-clockout-maybe)))))))
(defun org-clock-auto-clockout ()
"Clock out the currently clocked in task if Emacs is idle.
See `org-clock-auto-clockout-timer' to set the idle time span.
@ -1452,9 +1539,11 @@ See `org-clock-auto-clockout-timer' to set the idle time span.
This is only effective when `org-clock-auto-clockout-insinuate'
is present in the user configuration."
(when (and (numberp org-clock-auto-clockout-timer)
org-clock-current-task)
(run-with-idle-timer
org-clock-auto-clockout-timer nil #'org-clock-out)))
org-clock-current-task
(not (timerp org-clock--auto-clockout-timer-obj)))
(setq org-clock--auto-clockout-timer-obj
(run-with-idle-timer
org-clock-auto-clockout-timer nil #'org-clock--auto-clockout-maybe))))
;;;###autoload
(defun org-clock-toggle-auto-clockout ()
@ -1562,9 +1651,9 @@ line and position cursor in that line."
" *\\sw+ +[012][0-9]:[0-5][0-9]\\)\\][ \t]*$")))
(while (re-search-forward open-clock-re end t)
(let ((element (org-element-at-point)))
(when (and (eq (org-element-type element) 'clock)
(when (and (org-element-type-p element 'clock)
(eq (org-element-property :status element) 'running))
(beginning-of-line)
(forward-line 0)
(throw 'exit t))))))
;; Look for an existing clock drawer.
(when drawer
@ -1572,8 +1661,8 @@ line and position cursor in that line."
(let ((drawer-re (concat "^[ \t]*:" (regexp-quote drawer) ":[ \t]*$")))
(while (re-search-forward drawer-re end t)
(let ((element (org-element-at-point)))
(when (eq (org-element-type element) 'drawer)
(let ((cend (org-element-property :contents-end element)))
(when (org-element-type-p element 'drawer)
(let ((cend (org-element-contents-end element)))
(if (and (not org-log-states-order-reversed) cend)
(goto-char cend)
(forward-line))
@ -1586,7 +1675,7 @@ line and position cursor in that line."
(save-excursion
(while (re-search-forward clock-re end t)
(let ((element (org-element-at-point)))
(when (eq (org-element-type element) 'clock)
(when (org-element-type-p element 'clock)
(setq positions (cons (line-beginning-position) positions)
count (1+ count))))))
(cond
@ -1594,19 +1683,18 @@ line and position cursor in that line."
(org-fold-core-ignore-modifications
;; Skip planning line and property drawer, if any.
(org-end-of-meta-data)
(unless (bolp) (insert-and-inherit "\n"))
(unless (bolp) (insert-before-markers-and-inherit "\n"))
;; Create a new drawer if necessary.
(when (and org-clock-into-drawer
(or (not (wholenump org-clock-into-drawer))
(< org-clock-into-drawer 2)))
(let ((beg (point)))
(insert-and-inherit ":" drawer ":\n:END:\n")
;; Make sure that point moves after drawer upon
;; inserting it. Then, users can continue typing even
;; if point was right where the clock is inserted.
(insert-before-markers-and-inherit ":" drawer ":\n:END:\n")
(org-indent-region beg (point))
(if (eq org-fold-core-style 'text-properties)
(org-fold-region
(line-end-position -1) (1- (point)) t 'drawer)
(org-fold-region
(line-end-position -1) (1- (point)) t 'outline))
(org-fold-region (line-end-position -1) (1- (point)) t 'drawer)
(forward-line -1)))))
;; When a clock drawer needs to be created because of the
;; number of clock items or simply if it is missing, collect
@ -1631,13 +1719,13 @@ line and position cursor in that line."
"\n:END:\n")
(let ((end (point-marker)))
(goto-char beg)
(save-excursion (insert-and-inherit ":" drawer ":\n"))
(save-excursion (insert-before-markers-and-inherit ":" drawer ":\n"))
(org-fold-region (line-end-position) (1- end) t 'outline)
(org-indent-region (point) end)
(forward-line)
(unless org-log-states-order-reversed
(goto-char end)
(beginning-of-line -1))
(forward-line -2))
(set-marker end nil)))))
(org-log-states-order-reversed (goto-char (car (last positions))))
(t (goto-char (car positions))))))))
@ -1650,6 +1738,11 @@ and current `frame-title-format' is equal to `org-clock-frame-title-format'."
(equal frame-title-format org-clock-frame-title-format))
(setq frame-title-format org-frame-title-format-backup)))
(defvar org-clock-out-removed-last-clock nil
"When non-nil, the last `org-clock-out' removed the clock line.
This can happen when `org-clock-out-remove-zero-time-clocks' is set to
non-nil and the latest clock took 0 minutes.")
;;;###autoload
(defun org-clock-out (&optional switch-to-state fail-quietly at-time)
"Stop the currently running clock.
@ -1680,7 +1773,7 @@ to, overriding the existing value of `org-clock-out-switch-to-state'."
(save-restriction
(widen)
(goto-char org-clock-marker)
(beginning-of-line 1)
(forward-line 0)
(if (and (looking-at (concat "[ \t]*" org-keyword-time-regexp))
(equal (match-string 1) org-clock-string))
(setq ts (match-string 2))
@ -1689,7 +1782,7 @@ to, overriding the existing value of `org-clock-out-switch-to-state'."
(delete-region (point) (line-end-position))
(org-fold-core-ignore-modifications
(insert-and-inherit "--")
(setq te (org-insert-time-stamp (or at-time now) 'with-hm 'inactive))
(setq te (org-insert-timestamp (or at-time now) 'with-hm 'inactive))
(setq s (org-time-convert-to-integer
(time-subtract
(org-time-string-to-time te)
@ -1728,10 +1821,10 @@ to, overriding the existing value of `org-clock-out-switch-to-state'."
(when newstate (org-todo newstate))))
((and org-clock-out-switch-to-state
(not (looking-at
(concat
org-outline-regexp "[ \t]*"
org-clock-out-switch-to-state
"\\>"))))
(concat
org-outline-regexp "[ \t]*"
org-clock-out-switch-to-state
"\\>"))))
(org-todo org-clock-out-switch-to-state))))))
(force-mode-line-update)
(message (if remove
@ -1740,6 +1833,7 @@ to, overriding the existing value of `org-clock-out-switch-to-state'."
te (org-duration-from-minutes (+ (* 60 h) m)))
(unless (org-clocking-p)
(setq org-clock-current-task nil))
(setq org-clock-out-removed-last-clock remove)
(run-hooks 'org-clock-out-hook)
;; Add a note, but only if we didn't remove the clock line.
(when (and org-log-note-clock-out (not remove))
@ -1934,17 +2028,30 @@ PROPNAME lets you set a custom text property instead of :org-clock-minutes."
(save-excursion
(goto-char (point-max))
(while (re-search-backward re nil t)
(let ((element-type
(org-element-type
(save-match-data
(org-element-at-point)))))
(let* ((element (save-match-data (org-element-at-point)))
(element-type (org-element-type element)))
(cond
((and (eq element-type 'clock) (match-end 2))
;; Two time stamps.
(let* ((ss (match-string 2))
(se (match-string 3))
(ts (org-time-string-to-seconds ss))
(te (org-time-string-to-seconds se))
(let* ((timestamp (org-element-property :value element))
(ts (float-time
(org-encode-time
(list 0
(org-element-property :minute-start timestamp)
(org-element-property :hour-start timestamp)
(org-element-property :day-start timestamp)
(org-element-property :month-start timestamp)
(org-element-property :year-start timestamp)
nil -1 nil))))
(te (float-time
(org-encode-time
(list 0
(org-element-property :minute-end timestamp)
(org-element-property :hour-end timestamp)
(org-element-property :day-end timestamp)
(org-element-property :month-end timestamp)
(org-element-property :year-end timestamp)
nil -1 nil))))
(dt (- (if tend (min te tend) te)
(if tstart (max ts tstart) ts))))
(when (> dt 0) (cl-incf t1 (floor dt 60)))))
@ -2344,7 +2451,7 @@ have priority."
d (+ d shift)))
((or `week `thisweek)
(let* ((ws (or wstart 1))
(diff (+ (* -7 shift) (if (= dow 0) (- 7 ws) (- dow ws)))))
(diff (+ (* -7 shift) (mod (+ dow 7 (- ws)) 7))))
(setq m 0 h org-extend-today-until d (- d diff) d1 (+ 7 d))))
((or `month `thismonth)
(setq h org-extend-today-until m 0 d (or mstart 1)
@ -2495,7 +2602,7 @@ the currently selected interval size."
(goto-char b)
(insert ins)
(delete-region (point) (+ (point) (- e b)))
(beginning-of-line 1)
(forward-line 0)
(org-update-dblock)
t)))))
@ -2797,13 +2904,13 @@ from the dynamic block definition."
(if timestamp (concat ts "|") "") ;timestamp, maybe
(if tags (concat (mapconcat #'identity tgs ", ") "|") "") ;tags, maybe
(if properties ;properties columns, maybe
(concat (mapconcat (lambda (p) (or (cdr (assoc p props)) ""))
properties
"|")
"|")
(concat (mapconcat (lambda (p) (or (cdr (assoc p props)) ""))
properties
"|")
"|")
"")
(if indent ;indentation
(org-clocktable-indent-string level)
(org-clocktable-indent-string level)
"")
(format-field headline)
;; Empty fields for higher levels.
@ -2811,7 +2918,7 @@ from the dynamic block definition."
(format-field (org-duration-from-minutes time))
(make-string (max 0 (- time-columns level)) ?|)
(if (eq formula '%)
(format "%.1f |" (* 100 (/ time (float total-time))))
(format "%.1f |" (* 100 (/ time (float total-time))))
"")
"\n")))))))
(delete-char -1)
@ -2822,7 +2929,7 @@ from the dynamic block definition."
(when (and contents (string-match "^\\([ \t]*#\\+tblfm:.*\\)" contents))
(setq recalc t)
(insert "\n" (match-string 1 contents))
(beginning-of-line 0))))
(forward-line -1))))
;; Insert specified formula line.
((stringp formula)
(insert "\n#+TBLFM: " formula)
@ -3065,7 +3172,7 @@ Otherwise, return nil."
(let ((origin (point))) ;; `save-excursion' may not work when deleting.
(prog1
(save-excursion
(beginning-of-line 1)
(forward-line 0)
(skip-chars-forward " \t")
(when (looking-at org-clock-string)
(let ((re (concat "[ \t]*" org-clock-string

View File

@ -1,6 +1,6 @@
;;; org-colview.el --- Column View in Org -*- lexical-binding: t; -*-
;; Copyright (C) 2004-2023 Free Software Foundation, Inc.
;; Copyright (C) 2004-2024 Free Software Foundation, Inc.
;; Author: Carsten Dominik <carsten.dominik@gmail.com>
;; Keywords: outlines, hypermedia, calendar, wp
@ -37,13 +37,13 @@
(declare-function org-agenda-redo "org-agenda" (&optional all))
(declare-function org-agenda-do-context-action "org-agenda" ())
(declare-function org-clock-sum-today "org-clock" (&optional headline-filter))
(declare-function org-element-extract-element "org-element" (element))
(declare-function org-element-extract "org-element-ast" (node))
(declare-function org-element-interpret-data "org-element" (data))
(declare-function org-element-map "org-element" (data types fun &optional info first-match no-recursion with-affiliated))
(declare-function org-element-parse-secondary-string "org-element" (string restriction &optional parent))
(declare-function org-element-property "org-element" (property element))
(declare-function org-element-property "org-element-ast" (property node))
(declare-function org-element-restriction "org-element" (element))
(declare-function org-element-type "org-element" (element))
(declare-function org-element-type-p "org-element-ast" (node types))
(declare-function org-dynamic-block-define "org" (type func))
(declare-function org-link-display-format "ol" (s))
(declare-function org-link-open-from-string "ol" (s &optional arg))
@ -59,6 +59,19 @@
;;; Configuration
(defcustom org-columns-checkbox-allowed-values '("[ ]" "[X]")
"Allowed values for columns with SUMMARY-TYPE that uses checkbox.
The affected summary types are \"X%\", \"X/\", and \"X\" (see info
node `(org)Column attributes')."
:group 'org-properties
:package-version '(Org . "9.6")
:type '(repeat (choice
(const :tag "Unchecked [ ]" "[ ]")
(const :tag "Checked [X]" "[X]")
(const :tag "No checkbox" "")
(const :tag "Intermediate state [-]" "[-]")
(string :tag "Arbitrary string"))))
(defcustom org-columns-modify-value-for-display-function nil
"Function that modifies values for display in column view.
For example, it can be used to cut out a certain part from a time stamp.
@ -118,6 +131,9 @@ in `org-columns-summary-types-default', which see."
"Holds the list of current column overlays.")
(put 'org-columns-overlays 'permanent-local t)
(defvar-local org-columns-global nil
"Local variable, holds non-nil when current columns are global.")
(defvar-local org-columns-current-fmt nil
"Local variable, holds the currently active column format.")
@ -180,28 +196,10 @@ See `org-columns-summary-types' for details.")
(org-defkey org-columns-map "\M-b" #'backward-char)
(org-defkey org-columns-map "a" #'org-columns-edit-allowed)
(org-defkey org-columns-map "s" #'org-columns-edit-attributes)
(org-defkey org-columns-map "\M-f"
(lambda () (interactive) (goto-char (1+ (point)))))
(org-defkey org-columns-map [right]
(lambda () (interactive) (goto-char (1+ (point)))))
(org-defkey org-columns-map [down]
(lambda () (interactive)
(let ((col (current-column)))
(beginning-of-line 2)
(while (and (org-invisible-p2) (not (eobp)))
(beginning-of-line 2))
(move-to-column col)
(if (derived-mode-p 'org-agenda-mode)
(org-agenda-do-context-action)))))
(org-defkey org-columns-map [up]
(lambda () (interactive)
(let ((col (current-column)))
(beginning-of-line 0)
(while (and (org-invisible-p2) (not (bobp)))
(beginning-of-line 0))
(move-to-column col)
(if (eq major-mode 'org-agenda-mode)
(org-agenda-do-context-action)))))
(org-defkey org-columns-map "\M-f" #'forward-char)
(org-defkey org-columns-map [right] #'forward-char)
(org-defkey org-columns-map [up] #'org-columns-move-up)
(org-defkey org-columns-map [down] #'org-columns-move-down)
(org-defkey org-columns-map [(shift right)] #'org-columns-next-allowed-value)
(org-defkey org-columns-map "n" #'org-columns-next-allowed-value)
(org-defkey org-columns-map [(shift left)] #'org-columns-previous-allowed-value)
@ -210,6 +208,8 @@ See `org-columns-summary-types' for details.")
(org-defkey org-columns-map ">" #'org-columns-widen)
(org-defkey org-columns-map [(meta right)] #'org-columns-move-right)
(org-defkey org-columns-map [(meta left)] #'org-columns-move-left)
(org-defkey org-columns-map [(meta down)] #'org-columns-move-row-down)
(org-defkey org-columns-map [(meta up)] #'org-columns-move-row-up)
(org-defkey org-columns-map [(shift meta right)] #'org-columns-new)
(org-defkey org-columns-map [(shift meta left)] #'org-columns-delete)
(dotimes (i 10)
@ -231,6 +231,8 @@ See `org-columns-summary-types' for details.")
"--"
["Move column right" org-columns-move-right t]
["Move column left" org-columns-move-left t]
["Move row up" org-columns-move-row-up t]
["Move row down" org-columns-move-row-down t]
["Add column" org-columns-new t]
["Delete column" org-columns-delete t]
"--"
@ -376,17 +378,19 @@ ORIGINAL is the real string, i.e., before it is modified by
"Store the relative remapping of column header-line.
This is needed to later remove this relative remapping.")
(defvar org-columns--read-only-string nil)
(defun org-columns--display-here (columns &optional dateline)
"Overlay the current line with column display.
COLUMNS is an alist (SPEC VALUE DISPLAYED). Optional argument
DATELINE is non-nil when the face used should be
`org-agenda-column-dateline'."
(when (and (ignore-errors (require 'face-remap))
org-columns-header-line-remap)
(when (and (not org-columns-header-line-remap)
(or (fboundp 'face-remap-add-relative)
(ignore-errors (require 'face-remap))))
(setq org-columns-header-line-remap
(face-remap-add-relative 'header-line '(:inherit default))))
(save-excursion
(beginning-of-line)
(forward-line 0)
(let* ((level-face (and (looking-at "\\(\\**\\)\\(\\* \\)")
(org-get-level-face 2)))
(ref-face (or level-face
@ -449,18 +453,36 @@ DATELINE is non-nil when the face used should be
(line-end-position 0)
(line-beginning-position 2)
'read-only
(substitute-command-keys
"Type \\<org-columns-map>`\\[org-columns-edit-value]' \
to edit property")))))))
(or org-columns--read-only-string
(setq org-columns--read-only-string
(substitute-command-keys
"Type \\<org-columns-map>`\\[org-columns-edit-value]' \
to edit property")))))))))
(defun org-columns--truncate-below-width (string width)
"Return a substring of STRING no wider than WIDTH.
This substring must start at 0, and must be the longest possible
substring whose `string-width' does not exceed WIDTH."
(declare (side-effect-free t))
(let ((end (min width (length string))) res)
(while (and end (>= end 0))
(let* ((curr (string-width (substring string 0 end)))
(excess (- curr width)))
(if (> excess 0)
(cl-decf end (max 1 (/ excess 2)))
(setq res (substring string 0 end) end nil))))
res))
(defun org-columns-add-ellipses (string width)
"Truncate STRING with WIDTH characters, with ellipses."
(cond
((<= (length string) width) string)
((<= width (length org-columns-ellipses))
(substring org-columns-ellipses 0 width))
(t (concat (substring string 0 (- width (length org-columns-ellipses)))
org-columns-ellipses))))
((<= (string-width string) width) string)
((<= width (string-width org-columns-ellipses))
(org-columns--truncate-below-width org-columns-ellipses width))
(t (concat
(org-columns--truncate-below-width
string (- width (string-width org-columns-ellipses)))
org-columns-ellipses))))
(defvar org-columns-full-header-line-format nil
"The full header line format, will be shifted by horizontal scrolling." )
@ -728,7 +750,7 @@ an integer, select that value."
(let ((all
(or (org-property-get-allowed-values pom key)
(pcase (nth column org-columns-current-fmt-compiled)
(`(,_ ,_ ,_ ,(or "X" "X/" "X%") ,_) '("[ ]" "[X]")))
(`(,_ ,_ ,_ ,(or "X" "X/" "X%") ,_) org-columns-checkbox-allowed-values))
(org-colview-construct-allowed-dates value))))
(if previous (reverse all) all))))
(when (equal key "ITEM") (error "Cannot edit item headline from here"))
@ -818,7 +840,7 @@ current specifications. This function also sets
(let ((case-fold-search t))
(while (re-search-forward "^[ \t]*#\\+COLUMNS: .+$" nil t)
(let ((element (org-element-at-point)))
(when (eq (org-element-type element) 'keyword)
(when (org-element-type-p element 'keyword)
(throw :found (org-element-property :value element)))))
nil)))
org-columns-default-format)))
@ -851,6 +873,7 @@ turn on column view for the whole buffer unconditionally.
When COLUMNS-FMT-STRING is non-nil, use it as the column format."
(interactive "P")
(org-columns-remove-overlays)
(setq-local org-columns-global global)
(save-excursion
(when global (goto-char (point-min)))
(if (markerp org-columns-begin-marker)
@ -873,7 +896,7 @@ When COLUMNS-FMT-STRING is non-nil, use it as the column format."
;; Collect contents of columns ahead of time so as to
;; compute their maximum width.
(org-scan-tags
(lambda () (cons (point) (org-columns--collect-values))) t org--matcher-tags-todo-only)))
(lambda () (cons (point-marker) (org-columns--collect-values))) t org--matcher-tags-todo-only)))
(when cache
(org-columns--set-widths cache)
(org-columns--display-here-title)
@ -971,6 +994,30 @@ details."
(interactive "p")
(org-columns-widen (- arg)))
(defun org-columns-move-up ()
"In column view, move cursor up one row.
When in agenda column view, also call `org-agenda-do-context-action'."
(interactive)
(let ((col (current-column)))
(forward-line -1)
(while (and (org-invisible-p2) (not (bobp)))
(forward-line -1))
(move-to-column col)
(if (eq major-mode 'org-agenda-mode)
(org-agenda-do-context-action))))
(defun org-columns-move-down ()
"In column view, move cursor down one row.
When in agenda column view, also call `org-agenda-do-context-action'."
(interactive)
(let ((col (current-column)))
(forward-line 1)
(while (and (org-invisible-p2) (not (eobp)))
(forward-line 1))
(move-to-column col)
(if (derived-mode-p 'org-agenda-mode)
(org-agenda-do-context-action))))
(defun org-columns-move-right ()
"Swap this column with the one to the right."
(interactive)
@ -1005,6 +1052,27 @@ details."
(org-columns-move-right)
(backward-char 1)))
(defun org-columns--move-row (&optional up)
"Move the current table row down.
With non-nil optional argument UP, move it up."
(let ((inhibit-read-only t)
(col (current-column)))
(if up (org-move-subtree-up)
(org-move-subtree-down))
(let ((org-columns-inhibit-recalculation t))
(org-columns-redo)
(move-to-column col))))
(defun org-columns-move-row-down ()
"Move the current table row down."
(interactive)
(org-columns--move-row))
(defun org-columns-move-row-up ()
"Move the current table row up."
(interactive)
(org-columns--move-row 'up))
(defun org-columns-store-format ()
"Store the text version of the current columns format.
The format is stored either in the COLUMNS property of the node
@ -1022,7 +1090,7 @@ the current buffer."
(catch :found
(while (re-search-forward "^[ \t]*#\\+COLUMNS:\\(.*\\)" nil t)
(let ((element (save-match-data (org-element-at-point))))
(when (and (eq (org-element-type element) 'keyword)
(when (and (org-element-type-p element 'keyword)
(equal (org-element-property :key element)
"COLUMNS"))
(replace-match (concat " " fmt) t t nil 1)
@ -1072,7 +1140,7 @@ the current buffer."
(if (derived-mode-p 'org-mode)
;; Since we already know the columns format, provide it
;; instead of computing again.
(call-interactively #'org-columns org-columns-current-fmt)
(funcall-interactively #'org-columns org-columns-global org-columns-current-fmt)
(org-agenda-redo)
(call-interactively #'org-agenda-columns)))
(message "Recomputing columns...done")))
@ -1132,7 +1200,7 @@ This function updates `org-columns-current-fmt-compiled'."
(defun org-columns--age-to-minutes (s)
"Turn age string S into a number of minutes.
An age is either computed from a given time-stamp, or indicated
An age is either computed from a given timestamp, or indicated
as a canonical duration, i.e., using units defined in
`org-duration-canonical-units'."
(cond
@ -1161,8 +1229,8 @@ Return the result as a duration."
SPEC is a column format specification. When optional argument
UPDATE is non-nil, summarized values can replace existing ones in
properties drawers."
(let* ((lmax (if (bound-and-true-p org-inlinetask-min-level)
org-inlinetask-min-level
(let* ((lmax (if (bound-and-true-p org-inlinetask-max-level)
org-inlinetask-max-level
29)) ;Hard-code deepest level.
(lvals (make-vector (1+ lmax) nil))
(level 0)
@ -1198,9 +1266,9 @@ properties drawers."
;; property `org-summaries', in alist whose key is SPEC.
(let* ((summary
(and summarize
(let ((values (append (and (/= last-level inminlevel)
(aref lvals last-level))
(aref lvals inminlevel))))
(let ((values
(cl-loop for l from (1+ level) to lmax
append (aref lvals l))))
(and values (funcall summarize values printf))))))
;; Leaf values are not summaries: do not mark them.
(when summary
@ -1424,7 +1492,7 @@ an inline src-block."
(org-element-map data
'(footnote-reference inline-babel-call inline-src-block target
radio-target statistics-cookie)
#'org-element-extract-element)
#'org-element-extract)
(org-no-properties (org-element-interpret-data data))))
;;;###autoload
@ -1495,7 +1563,7 @@ PARAMS is a property list of parameters:
(setq view-file filename)
(setq view-pos position))
(_ (user-error "Cannot find entry with :ID: %s" id)))
(with-current-buffer (if view-file (get-file-buffer view-file)
(with-current-buffer (if view-file (org-get-agenda-file-buffer view-file)
(current-buffer))
(org-with-wide-buffer
(when view-pos (goto-char view-pos))
@ -1504,7 +1572,10 @@ PARAMS is a property list of parameters:
(plist-get params :skip-empty-rows)
(plist-get params :exclude-tags)
(plist-get params :format)
view-pos))))))
view-pos)))))
(width-specs
(mapcar (lambda (spec) (nth 2 spec))
org-columns-current-fmt-compiled)))
(when table
;; Prune level information from the table. Also normalize
;; headings: remove stars, add indentation entities, if
@ -1540,6 +1611,11 @@ PARAMS is a property list of parameters:
(append (mapcar (lambda (x) (if (eq 'hline x) x (cons "" x)))
table)
(list (cons "/" (make-list size "<>")))))))
(when (seq-find #'identity width-specs)
;; There are width specifiers in column format. Pass them
;; to the resulting table, adding alignment field as the first
;; row.
(push (mapcar (lambda (width) (when width (format "<%d>" width))) width-specs) table))
(let ((content-lines (org-split-string (plist-get params :content) "\n"))
recalc)
;; Insert affiliated keywords before the table.
@ -1561,7 +1637,9 @@ PARAMS is a property list of parameters:
(insert "\n" line)
(unless recalc (setq recalc t))))))
(when recalc (org-table-recalculate 'all t))
(org-table-align)))))
(org-table-align)
(when (seq-find #'identity width-specs)
(org-table-shrink))))))
;;;###autoload
(defun org-columns-insert-dblock ()

View File

@ -1,6 +1,6 @@
;;; org-compat.el --- Compatibility Code for Older Emacsen -*- lexical-binding: t; -*-
;; Copyright (C) 2004-2023 Free Software Foundation, Inc.
;; Copyright (C) 2004-2024 Free Software Foundation, Inc.
;; Author: Carsten Dominik <carsten.dominik@gmail.com>
;; Keywords: outlines, hypermedia, calendar, wp
@ -52,9 +52,15 @@
(declare-function org-element-at-point "org-element" (&optional pom cached-only))
(declare-function org-element-at-point-no-context "org-element" (&optional pom))
(declare-function org-element-context "org-element" (&optional element))
(declare-function org-element-lineage "org-element" (blob &optional types with-self))
(declare-function org-element-type "org-element" (element))
(declare-function org-element-property "org-element" (property element))
(declare-function org-element-lineage "org-element-ast" (blob &optional types with-self))
(declare-function org-element-type "org-element-ast" (node &optional anonymous))
(declare-function org-element-type-p "org-element-ast" (node types))
(declare-function org-element-property "org-element-ast" (property node))
(declare-function org-element-begin "org-element" (node))
(declare-function org-element-end "org-element" (node))
(declare-function org-element-contents-begin "org-element" (node))
(declare-function org-element-contents-end "org-element" (node))
(declare-function org-element-post-affiliated "org-element" (node))
(declare-function org-end-of-subtree "org" (&optional invisible-ok to-heading))
(declare-function org-get-heading "org" (&optional no-tags no-todo no-priority no-comment))
(declare-function org-get-tags "org" (&optional pos local))
@ -71,6 +77,7 @@
(declare-function outline-next-heading "outline" ())
(declare-function speedbar-line-directory "speedbar" (&optional depth))
(declare-function table--at-cell-p "table" (position &optional object at-column))
(declare-function ob-clojure-eval-with-cmd "ob-clojure" (cmd expanded))
(declare-function org-fold-folded-p "org-fold" (&optional pos spec-or-alias))
(declare-function org-fold-hide-sublevels "org-fold" (levels))
(declare-function org-fold-hide-subtree "org-fold" ())
@ -96,6 +103,25 @@
;;; Emacs < 29 compatibility
(if (fboundp 'display-buffer-full-frame)
(defalias 'org-display-buffer-full-frame #'display-buffer-full-frame)
(defun org-display-buffer-full-frame (buffer alist)
"Display BUFFER in the current frame, taking the entire frame.
ALIST is an association list of action symbols and values. See
Info node `(elisp) Buffer Display Action Alists' for details of
such alists.
This is an action function for buffer display, see Info
node `(elisp) Buffer Display Action Functions'. It should be
called only by `display-buffer' or a function directly or
indirectly called by the latter."
(when-let ((window (or (display-buffer-reuse-window buffer alist)
(display-buffer-same-window buffer alist)
(display-buffer-pop-up-window buffer alist)
(display-buffer-use-some-window buffer alist))))
(delete-other-windows window)
window)))
(defvar org-file-has-changed-p--hash-table (make-hash-table :test #'equal)
"Internal variable used by `org-file-has-changed-p'.")
@ -130,9 +156,41 @@ Upper-case and lower-case letters are treated as equal.
Unibyte strings are converted to multibyte for comparison."
(eq t (compare-strings string1 0 nil string2 0 nil t))))
(defun org-buffer-text-pixel-width ()
"Return pixel width of text in current buffer.
This function uses `buffer-text-pixel-size', when available, and falls
back to `window-text-pixel-size' otherwise."
(if (fboundp 'buffer-text-pixel-size)
(car (buffer-text-pixel-size nil nil t))
(if (get-buffer-window (current-buffer))
;; FIXME: 10000 because `most-positive-fixnum' ain't working
;; (tests failing) and this call will be removed after we drop
;; Emacs 28 support anyway.
(car (window-text-pixel-size
nil (point-min) (point-max) 10000))
(let ((dedicatedp (window-dedicated-p))
(oldbuffer (window-buffer)))
(unwind-protect
(progn
;; Do not throw error in dedicated windows.
(set-window-dedicated-p nil nil)
(set-window-buffer nil (current-buffer))
(car (window-text-pixel-size
nil (point-min) (point-max) 10000)))
(set-window-buffer nil oldbuffer)
(set-window-dedicated-p nil dedicatedp))))))
;;; Emacs < 28.1 compatibility
(if (= 2 (cdr (subr-arity (symbol-function 'get-buffer-create))))
;; Emacs >27.
(defalias 'org-get-buffer-create #'get-buffer-create)
(defun org-get-buffer-create (buffer-or-name &optional _)
"Call `get-buffer-create' with BUFFER-OR-NAME argument.
Ignore optional argument."
(get-buffer-create buffer-or-name)))
(if (fboundp 'file-name-concat)
(defalias 'org-file-name-concat #'file-name-concat)
(defun org-file-name-concat (directory &rest components)
@ -193,6 +251,18 @@ removed."
default)))
": ")))
(if (fboundp 'ensure-list)
(defalias 'org-ensure-list #'ensure-list)
(defun org-ensure-list (object)
"Return OBJECT as a list.
If OBJECT is already a list, return OBJECT itself. If it's
not a list, return a one-element list containing OBJECT.
Compatability substitute for `ensure-list' in Emacs 28."
(if (listp object)
object
(list object))))
;;; Emacs < 27.1 compatibility
@ -204,6 +274,25 @@ removed."
`(progn ,@body))
(defalias 'org-combine-change-calls 'combine-change-calls))
;; `flatten-tree' was added in Emacs 27.1.
(if (fboundp 'flatten-tree)
(defalias 'org--flatten-tree #'flatten-tree)
;; The implementation is taken from Emacs subr.el 8664ba18c7c5.
(defun org--flatten-tree (tree)
"Return a \"flattened\" copy of TREE.
A `flatten-tree' polyfill for compatibility with Emacs versions
older than 27.1"
(let (elems)
(while (consp tree)
(let ((elem (pop tree)))
(while (consp elem)
(push (cdr elem) tree)
(setq elem (car elem)))
(if elem (push elem elems))))
(if tree (push tree elems))
(nreverse elems))))
(if (version< emacs-version "27.1")
(defsubst org-replace-buffer-contents (source &optional _max-secs _max-costs)
(replace-buffer-contents source))
@ -290,6 +379,24 @@ Execute BODY, and unwind connection-local variables."
`(with-connection-local-profiles (connection-local-get-profiles nil)
,@body)))
;; assoc-delete-all missing from 26.1
(if (fboundp 'assoc-delete-all)
(defalias 'org-assoc-delete-all 'assoc-delete-all)
;; from compat/compat-27.el
(defun org-assoc-delete-all (key alist &optional test)
"Delete all matching key from alist, default test equal"
(unless test (setq test #'equal))
(while (and (consp (car alist))
(funcall test (caar alist) key))
(setq alist (cdr alist)))
(let ((tail alist) tail-cdr)
(while (setq tail-cdr (cdr tail))
(if (and (consp (car tail-cdr))
(funcall test (caar tail-cdr) key))
(setcdr tail (cdr tail-cdr))
(setq tail tail-cdr))))
alist))
;;; Emacs < 26.1 compatibility
@ -386,6 +493,10 @@ Counting starts at 1."
(define-obsolete-function-alias 'org-string-match-p 'string-match-p "9.0")
;;;; Functions and variables from previous releases now obsolete.
(define-obsolete-variable-alias 'org-export-ignored-local-variables
'org-element-ignored-local-variables "Org 9.7")
(define-obsolete-function-alias 'org-habit-get-priority
'org-habit-get-urgency "Org 9.7")
(define-obsolete-function-alias 'org-timestamp-format
'org-format-timestamp "Org 9.6")
(define-obsolete-variable-alias 'org-export-before-processing-hook
@ -411,7 +522,7 @@ Counting starts at 1."
'completing-read "9.0")
(define-obsolete-function-alias 'org-iread-file-name 'read-file-name "9.0")
(define-obsolete-function-alias 'org-days-to-time
'org-time-stamp-to-now "8.2")
'org-timestamp-to-now "8.2")
(define-obsolete-variable-alias 'org-agenda-ignore-drawer-properties
'org-agenda-ignore-properties "9.0")
(define-obsolete-function-alias 'org-preview-latex-fragment
@ -549,14 +660,419 @@ Counting starts at 1."
(define-obsolete-function-alias 'org-file-url-p 'org-url-p "9.6")
(define-obsolete-variable-alias 'org-plantuml-executable-args 'org-plantuml-args
"Org 9.6")
(defconst org-latex-line-break-safe "\\\\[0pt]"
"Linebreak protecting the following [...].
Without \"[0pt]\" it would be interpreted as an optional argument to
the \\\\.
This constant, for example, makes the below code not err:
\\begin{tabular}{c|c}
[t] & s\\\\[0pt]
[I] & A\\\\[0pt]
[m] & kg
\\end{tabular}")
(make-obsolete 'org-latex-line-break-safe
"should not be used - it is not safe in all the scenarios."
"9.7")
(defun org-in-fixed-width-region-p ()
"Non-nil if point in a fixed-width region."
(save-match-data
(eq 'fixed-width (org-element-type (org-element-at-point)))))
(org-element-type-p (org-element-at-point) 'fixed-width)))
(make-obsolete 'org-in-fixed-width-region-p
"use `org-element' library"
"9.0")
(define-obsolete-variable-alias
'org-format-latex-options 'org-latex-preview-appearance-options "9.7")
(make-obsolete-variable
'org-format-latex-signal-error "no longer used" "9.7")
(define-obsolete-variable-alias
'org-format-latex-header 'org-latex-preview-preamble "9.7")
(define-obsolete-variable-alias
'org-preview-latex-default-process 'org-latex-preview-process-default "9.7")
(define-obsolete-variable-alias
'org-preview-latex-process-alist 'org-latex-preview-process-alist "9.7")
(define-obsolete-function-alias
'org-clear-latex-preview 'org-latex-preview-clear-overlays "9.7")
(make-obsolete
'org-place-formula-image "no longer used" "9.7")
(define-obsolete-function-alias
'org-latex-color-format 'org-latex-preview--format-color "9.7")
(define-obsolete-function-alias
'org-latex-color 'org-latex-preview--attr-color "9.7")
;; MathML related functions from org-latex-preview.el
(define-obsolete-variable-alias
'org-latex-to-mathml-jar-file 'org-mathml-converter-jar-file "9.7")
(define-obsolete-variable-alias
'org-latex-to-mathml-convert-command 'org-mathml-convert-command "9.7")
(define-obsolete-function-alias
'org-format-latex-mathml-available-p 'org-mathml-converter-available-p "9.7")
(define-obsolete-function-alias
'org-create-math-formula 'org-mathml-convert-latex "9.7")
;; FIXME: Unused; obsoleted; to be removed.
(defun org-format-latex-as-mathml (latex-frag latex-frag-type
prefix &optional dir)
(let* ((absprefix (expand-file-name prefix dir))
(print-length nil) (print-level nil)
(formula-id (concat
"formula-"
(sha1
(prin1-to-string
(list latex-frag
org-latex-to-mathml-convert-command)))))
(formula-cache (format "%s-%s.mathml" absprefix formula-id))
(formula-cache-dir (file-name-directory formula-cache)))
(unless (file-directory-p formula-cache-dir)
(make-directory formula-cache-dir t))
(unless (file-exists-p formula-cache)
(org-mathml-convert-latex latex-frag formula-cache))
(if (file-exists-p formula-cache)
;; Successful conversion. Return the link to MathML file.
(org-add-props
(format "[[file:%s]]" (file-relative-name formula-cache dir))
(list 'org-latex-src (replace-regexp-in-string "\"" "" latex-frag)
'org-latex-src-embed-type (if latex-frag-type
'paragraph 'character)))
;; Failed conversion. Return the LaTeX fragment verbatim
latex-frag)))
(make-obsolete #'org-format-latex-as-mathml "to be removed" "9.7")
;; FIXME: Unused; obsoleted; to be removed.
(defun org-dvipng-color (attr)
"Return a RGB color specification for dvipng."
(org-dvipng-color-format (face-attribute 'default attr nil)))
;; FIXME: Unused; obsoleted; to be removed.
(defun org-dvipng-color-format (color-name)
"Convert COLOR-NAME to a RGB color value for dvipng."
(apply #'format "rgb %s %s %s"
(mapcar 'org-latex-preview--normalize-color
(color-values color-name))))
(make-obsolete
'org-dvipng-color "to be removed" "9.7")
(make-obsolete
'org-dvipng-color-format "to be removed" "9.7")
;; FIXME: Unused; obsoleted; to be removed.
(defun org-normalize-color (value)
"Return string to be used as color value for an RGB component."
(format "%g" (/ value 65535.0)))
(make-obsolete 'org-normalize-color "to be removed" "9.7")
;; FIXME: Unused; obsoleted; to be removed.
(defcustom org-preview-latex-image-directory "ltximg/"
"Path to store latex preview images.
A relative path here creates many directories relative to the
processed Org files paths. An absolute path puts all preview
images at the same place."
:group 'org-latex
:version "26.1"
:package-version '(Org . "9.0")
:type 'string)
(make-obsolete-variable
'org-preview-latex-image-directory "replaced with org-persist" "9.7")
;; FIXME: Unused; obsoleted; to be removed.
(defun org-format-latex
(prefix &optional beg end dir overlays msg forbuffer processing-type)
"Replace LaTeX fragments with links to an image.
The function takes care of creating the replacement image.
Only consider fragments between BEG and END when those are
provided.
When optional argument OVERLAYS is non-nil, display the image on
top of the fragment instead of replacing it.
PROCESSING-TYPE is the conversion method to use, as a symbol.
Some of the options can be changed using the variable
`org-format-latex-options', which see."
(when (and overlays (fboundp 'clear-image-cache)) (clear-image-cache))
(unless (eq processing-type 'verbatim)
(let* ((math-regexp "\\$\\|\\\\[([]\\|^[ \t]*\\\\begin{[A-Za-z0-9*]+}")
(cnt 0)
checkdir-flag)
(goto-char (or beg (point-min)))
;; Optimize overlay creation: (info "(elisp) Managing Overlays").
(when (and overlays (memq processing-type '(dvipng imagemagick)))
(overlay-recenter (or end (point-max))))
(while (re-search-forward math-regexp end t)
(unless (and overlays
(eq (get-char-property (point) 'org-overlay-type)
'org-latex-overlay))
(let* ((context (org-element-context))
(type (org-element-type context)))
(when (memq type '(latex-environment latex-fragment))
(let ((block-type (eq type 'latex-environment))
(value (org-element-property :value context))
(beg (org-element-property :begin context))
(end (save-excursion
(goto-char (org-element-property :end context))
(skip-chars-backward " \r\t\n")
(point))))
(cond
((eq processing-type 'mathjax)
;; Prepare for MathJax processing.
(if (not (string-match "\\`\\$\\$?" value))
(goto-char end)
(delete-region beg end)
(if (string= (match-string 0 value) "$$")
(insert "\\[" (substring value 2 -2) "\\]")
(insert "\\(" (substring value 1 -1) "\\)"))))
((eq processing-type 'html)
(goto-char beg)
(delete-region beg end)
(insert (org-format-latex-as-html value)))
((assq processing-type org-preview-latex-process-alist)
;; Process to an image.
(cl-incf cnt)
(goto-char beg)
(let* ((processing-info
(cdr (assq processing-type org-preview-latex-process-alist)))
(face (face-at-point))
;; Get the colors from the face at point.
(fg
(let ((color (plist-get org-format-latex-options
:foreground)))
(if forbuffer
(cond
((eq color 'auto)
(face-attribute face :foreground nil 'default))
((eq color 'default)
(face-attribute 'default :foreground nil))
(t color))
color)))
(bg
(let ((color (plist-get org-format-latex-options
:background)))
(if forbuffer
(cond
((eq color 'auto)
(face-attribute face :background nil 'default))
((eq color 'default)
(face-attribute 'default :background nil))
(t color))
color)))
(hash (sha1 (prin1-to-string
(list org-format-latex-header
org-latex-default-packages-alist
org-latex-packages-alist
org-format-latex-options
forbuffer value fg bg))))
(imagetype (or (plist-get processing-info :image-output-type) "png"))
(absprefix (expand-file-name prefix dir))
(linkfile (format "%s_%s.%s" prefix hash imagetype))
(movefile (format "%s_%s.%s" absprefix hash imagetype))
(sep (and block-type "\n\n"))
(link (concat sep "[[file:" linkfile "]]" sep))
(options
(org-combine-plists
org-format-latex-options
`(:foreground ,fg :background ,bg))))
(when msg (message msg cnt))
(unless checkdir-flag ; Ensure the directory exists.
(setq checkdir-flag t)
(let ((todir (file-name-directory absprefix)))
(unless (file-directory-p todir)
(make-directory todir t))))
(unless (file-exists-p movefile)
(org-create-formula-image
value movefile options forbuffer processing-type))
(org-place-formula-image link block-type beg end value overlays movefile imagetype)))
((eq processing-type 'mathml)
;; Process to MathML.
(unless (org-format-latex-mathml-available-p)
(user-error "LaTeX to MathML converter not configured"))
(cl-incf cnt)
(when msg (message msg cnt))
(goto-char beg)
(delete-region beg end)
(insert (org-format-latex-as-mathml
value block-type prefix dir)))
(t
(error "Unknown conversion process %s for LaTeX fragments"
processing-type)))))))))))
;; FIXME: Unused; obsoleted; to be removed.
(defun org-place-formula-image (link block-type beg end value overlays movefile imagetype)
"Place an overlay from BEG to END showing MOVEFILE.
The overlay will be above BEG if OVERLAYS is non-nil."
(if overlays
(progn
(dolist (o (overlays-in beg end))
(when (eq (overlay-get o 'org-overlay-type)
'org-latex-overlay)
(delete-overlay o)))
(let ((ov (make-overlay beg end))
(imagetype (or (intern imagetype) 'png)))
(overlay-put ov 'org-overlay-type 'org-latex-overlay)
(overlay-put ov 'evaporate t)
(overlay-put ov
'modification-hooks
(list (lambda (o _flag _beg _end &optional _l)
(delete-overlay o))))
(overlay-put ov
'display
(list 'image :type imagetype :file movefile :ascent 'center)))
(goto-char end))
(delete-region beg end)
(insert
(org-add-props link
(list 'org-latex-src
(replace-regexp-in-string "\"" "" value)
'org-latex-src-embed-type
(if block-type 'paragraph 'character))))))
;; FIXME: Unused; obsoleted; to be removed.
(defun org-create-formula-image
(string tofile options buffer &optional processing-type)
"Create an image from LaTeX source using external processes.
The LaTeX STRING is saved to a temporary LaTeX file, then
converted to an image file by process PROCESSING-TYPE defined in
`org-preview-latex-process-alist'. A nil value defaults to
`org-preview-latex-default-process'.
The generated image file is eventually moved to TOFILE.
The OPTIONS argument controls the size, foreground color and
background color of the generated image.
When BUFFER non-nil, this function is used for LaTeX previewing.
Otherwise, it is used to deal with LaTeX snippets showed in
a HTML file."
(let* ((processing-type (or processing-type
org-preview-latex-default-process))
(processing-info
(cdr (assq processing-type org-preview-latex-process-alist)))
(programs (plist-get processing-info :programs))
(error-message (or (plist-get processing-info :message) ""))
(image-input-type (plist-get processing-info :image-input-type))
(image-output-type (plist-get processing-info :image-output-type))
(post-clean (or (plist-get processing-info :post-clean)
'(".dvi" ".xdv" ".pdf" ".tex" ".aux" ".log"
".svg" ".png" ".jpg" ".jpeg" ".out")))
(latex-header
(or (plist-get processing-info :latex-header)
(org-latex-make-preamble
(org-export-get-environment (org-export-get-backend 'latex))
org-format-latex-header
'snippet)))
(latex-compiler (plist-get processing-info :latex-compiler))
(tmpdir temporary-file-directory)
(texfilebase (make-temp-name
(expand-file-name "orgtex" tmpdir)))
(texfile (concat texfilebase ".tex"))
(image-size-adjust (or (plist-get processing-info :image-size-adjust)
'(1.0 . 1.0)))
(scale (* (if buffer (car image-size-adjust) (cdr image-size-adjust))
(or (plist-get options (if buffer :scale :html-scale)) 1.0)))
(dpi (* scale (if (and buffer (display-graphic-p)) (org--get-display-dpi) 140.0)))
(fg (or (plist-get options (if buffer :foreground :html-foreground))
"Black"))
(bg (or (plist-get options (if buffer :background :html-background))
"Transparent"))
(image-converter
(or (and (string= bg "Transparent")
(plist-get processing-info :transparent-image-converter))
(plist-get processing-info :image-converter)))
(log-buf (get-buffer-create "*Org Preview LaTeX Output*"))
(resize-mini-windows nil)) ;Fix Emacs flicker when creating image.
(dolist (program programs)
(org-check-external-command program error-message))
(if (eq fg 'default)
(setq fg (org-latex-color :foreground))
(setq fg (org-latex-color-format fg)))
(setq bg (cond
((eq bg 'default) (org-latex-color :background))
((string= bg "Transparent") nil)
(t (org-latex-color-format bg))))
;; Remove TeX \par at end of snippet to avoid trailing space.
(if (string-suffix-p string "\n")
(aset string (1- (length string)) ?%)
(setq string (concat string "%")))
(with-temp-file texfile
(insert latex-header)
(insert "\n\\begin{document}\n"
"\\definecolor{fg}{rgb}{" fg "}%\n"
(if bg
(concat "\\definecolor{bg}{rgb}{" bg "}%\n"
"\n\\pagecolor{bg}%\n")
"")
"\n{\\color{fg}\n"
string
"\n}\n"
"\n\\end{document}\n"))
(let* ((err-msg (format "Please adjust `%s' part of \
`org-preview-latex-process-alist'."
processing-type))
(image-input-file
(org-compile-file
texfile latex-compiler image-input-type err-msg log-buf))
(image-output-file
(org-compile-file
image-input-file image-converter image-output-type err-msg log-buf
`((?D . ,(shell-quote-argument (format "%s" dpi)))
(?S . ,(shell-quote-argument (format "%s" (/ dpi 140.0))))))))
(copy-file image-output-file tofile 'replace)
(dolist (e post-clean)
(when (file-exists-p (concat texfilebase e))
(delete-file (concat texfilebase e))))
image-output-file)))
;; FIXME: Unused; obsoleted; to be removed.
(defun org-html-format-latex (latex-frag processing-type info)
"Format a LaTeX fragment LATEX-FRAG into HTML.
PROCESSING-TYPE designates the tool used for conversion. It can
be `mathjax', `verbatim', `html', nil, t or symbols in
`org-preview-latex-process-alist', e.g., `dvipng', `dvisvgm' or
`imagemagick'. See `org-html-with-latex' for more information.
INFO is a plist containing export properties."
(let ((cache-relpath "") (cache-dir ""))
(unless (or (eq processing-type 'mathjax)
(eq processing-type 'html))
(let ((bfn (or (buffer-file-name)
(make-temp-name
(expand-file-name "latex" temporary-file-directory))))
(latex-header
(let ((header (plist-get info :latex-header)))
(and header
(concat (mapconcat
(lambda (line) (concat "#+LATEX_HEADER: " line))
(org-split-string header "\n")
"\n")
"\n")))))
(setq cache-relpath
(concat (file-name-as-directory org-preview-latex-image-directory)
(file-name-sans-extension
(file-name-nondirectory bfn)))
cache-dir (file-name-directory bfn))
;; Re-create LaTeX environment from original buffer in
;; temporary buffer so that dvipng/imagemagick can properly
;; turn the fragment into an image.
(setq latex-frag (concat latex-header latex-frag))))
(org-export-with-buffer-copy
:to-buffer (get-buffer-create " *Org HTML Export LaTeX*")
:drop-visibility t :drop-narrowing t :drop-contents t
(erase-buffer)
(insert latex-frag)
(org-format-latex cache-relpath nil nil cache-dir nil
"Creating LaTeX Image..." nil processing-type)
(buffer-string))))
(make-obsolete #'org-format-latex "to be removed" "9.7")
(make-obsolete #'org-create-formula-image "to be removed" "9.7")
(make-obsolete #'org-html-format-latex "to be removed" "9.7")
;; FIXME: Unused; obsoleted; to be removed.
(defun org-let (list &rest body) ;FIXME: So many kittens are suffering here.
(declare (indent 1) (obsolete cl-progv "2021"))
@ -570,6 +1086,26 @@ Counting starts at 1."
(make-obsolete 'org-let "to be removed" "9.6")
(make-obsolete 'org-let2 "to be removed" "9.6")
(define-obsolete-function-alias 'org--math-always-on
'org--math-p "9.7")
(defmacro org-no-popups (&rest body)
"Suppress popup windows and evaluate BODY."
`(let (pop-up-frames pop-up-windows)
,@body))
(make-obsolete 'org-no-popups "no longer used" "9.7")
(defun org-switch-to-buffer-other-window (&rest args)
"Switch to buffer in a second window on the current frame.
In particular, do not allow pop-up frames.
Returns the newly created buffer."
(let (pop-up-frames pop-up-windows)
(apply #'switch-to-buffer-other-window args)))
(make-obsolete 'org-switch-to-buffer-other-window "no longer used" "9.7")
(make-obsolete 'org-refresh-category-properties "no longer used" "9.7")
(make-obsolete 'org-refresh-effort-properties "no longer used" "9.7")
(defun org-compatible-face (inherits specs)
"Make a compatible face specification.
If INHERITS is an existing face and if the Emacs version supports
@ -616,7 +1152,7 @@ See `org-link-parameters' for documentation on the other parameters."
(defun org-table-recognize-table.el ()
"If there is a table.el table nearby, recognize it and move into it."
(when (org-at-table.el-p)
(beginning-of-line)
(forward-line 0)
(unless (or (looking-at org-table-dataline-regexp)
(not (looking-at org-table1-hline-regexp)))
(forward-line)
@ -658,13 +1194,23 @@ See `org-link-parameters' for documentation on the other parameters."
(org-unbracket-string "<" ">" s))
(make-obsolete 'org-remove-angle-brackets 'org-unbracket-string "9.0")
(defcustom org-capture-bookmark t
"When non-nil, add bookmark pointing at the last stored position when capturing."
:group 'org-capture
:version "24.3"
:type 'boolean)
(make-obsolete-variable
'org-capture-bookmark
"use `org-bookmark-names-plist' instead."
"9.7")
(defcustom org-publish-sitemap-file-entry-format "%t"
"Format string for site-map file entry.
You could use brackets to delimit on what part the link will be.
%t is the title.
%a is the author.
%d is the date formatted using `org-publish-sitemap-date-format'."
%d is the date."
:group 'org-export-publish
:type 'string)
(make-obsolete-variable
@ -881,21 +1427,21 @@ When optional argument ELEMENT is a parsed drawer, as returned by
When buffer positions BEG and END are provided, hide or show that
region as a drawer without further ado."
(declare (obsolete "use `org-hide-drawer-toggle' instead." "9.4"))
(if (and beg end) (org-fold-region beg end flag (if (eq org-fold-core-style 'text-properties) 'drawer 'outline))
(if (and beg end) (org-fold-region beg end flag 'drawer)
(let ((drawer
(or element
(and (save-excursion
(beginning-of-line)
(forward-line 0)
(looking-at-p "^[ \t]*:\\(\\(?:\\w\\|[-_]\\)+\\):[ \t]*$"))
(org-element-at-point)))))
(when (memq (org-element-type drawer) '(drawer property-drawer))
(let ((post (org-element-property :post-affiliated drawer)))
(when (org-element-type-p drawer '(drawer property-drawer))
(let ((post (org-element-post-affiliated drawer)))
(org-fold-region
(save-excursion (goto-char post) (line-end-position))
(save-excursion (goto-char (org-element-property :end drawer))
(save-excursion (goto-char (org-element-end drawer))
(skip-chars-backward " \t\n")
(line-end-position))
flag (if (eq org-fold-core-style 'text-properties) 'drawer 'outline))
flag 'drawer)
;; When the drawer is hidden away, make sure point lies in
;; a visible part of the buffer.
(when (invisible-p (max (1- (point)) (point-min)))
@ -919,7 +1465,7 @@ an error. Return a non-nil value when toggling is successful."
(goto-char start)
(while (and (< (point) end)
(re-search-forward "^[ \t]*#\\+begin_?\
\\([^ \n]+\\)\\(\\([^\n]+\\)\\)?\n\\([^\000]+?\\)#\\+end_?\\1[ \t]*$" end t))
\\([^ \n]+\\)\\(\\([^\n]+\\)\\)?\n\\(\\(?:.\\|\n\\)+?\\)#\\+end_?\\1[ \t]*$" end t))
(save-excursion
(save-match-data
(goto-char (match-beginning 0))
@ -1116,6 +1662,26 @@ context. See the individual commands for more information."
(make-obsolete-variable 'org-latex-polyglossia-language-alist
"set `org-latex-language-alist' instead." "9.6")
(defconst org-babel-python-mode 'python
"Python mode for use in running python interactively.")
(make-obsolete-variable
'org-babel-python-mode
"Only the built-in Python mode is supported in ob-python now."
"9.7")
(define-obsolete-function-alias 'ob-clojure-eval-with-babashka
#'ob-clojure-eval-with-cmd "9.7")
(define-obsolete-function-alias 'org-export-get-parent
'org-element-parent "9.7")
(define-obsolete-function-alias 'org-export-get-parent-element
'org-element-parent-element "9.7")
(define-obsolete-function-alias 'org-print-speed-command
'org--print-speed-command "9.7"
"Internal function. Subject of unannounced changes.")
;;;; Obsolete link types
(eval-after-load 'ol
@ -1366,7 +1932,7 @@ ELEMENT is the element at point."
;; Only in inline footnotes, within the definition.
(and (eq (org-element-property :type object) 'inline)
(< (save-excursion
(goto-char (org-element-property :begin object))
(goto-char (org-element-begin object))
(search-forward ":" nil t 2))
(point))))
(otherwise t))))
@ -1375,7 +1941,7 @@ ELEMENT is the element at point."
"Function used for `flyspell-generic-check-word-predicate'."
(if (org-at-heading-p)
;; At a headline or an inlinetask, check title only.
(and (save-excursion (beginning-of-line)
(and (save-excursion (forward-line 0)
(and (let ((case-fold-search t))
(not (looking-at-p "\\*+ END[ \t]*$")))
(let ((case-fold-search nil))
@ -1387,19 +1953,19 @@ ELEMENT is the element at point."
;; Ignore checks in code, verbatim and others.
(org--flyspell-object-check-p (org-element-at-point-no-context)))
(let* ((element (org-element-at-point-no-context))
(post-affiliated (org-element-property :post-affiliated element)))
(post-affiliated (org-element-post-affiliated element)))
(cond
;; Ignore checks in all affiliated keywords but captions.
((< (point) post-affiliated)
(and (save-excursion
(beginning-of-line)
(forward-line 0)
(let ((case-fold-search t)) (looking-at "[ \t]*#\\+CAPTION:")))
(> (point) (match-end 0))
(org--flyspell-object-check-p element)))
;; Ignore checks in LOGBOOK (or equivalent) drawer.
((let ((log (org-log-into-drawer)))
(and log
(let ((drawer (org-element-lineage element '(drawer))))
(let ((drawer (org-element-lineage element 'drawer)))
(and drawer
(org-string-equal-ignore-case
log (org-element-property :drawer-name drawer))))))
@ -1413,7 +1979,7 @@ ELEMENT is the element at point."
(save-excursion
(end-of-line)
(skip-chars-forward " \r\t\n")
(< (point) (org-element-property :end element)))))
(< (point) (org-element-end element)))))
;; Arbitrary list of keywords where checks are meaningful.
;; Make sure point is on the value part of the element.
(keyword
@ -1425,8 +1991,8 @@ ELEMENT is the element at point."
;; table rows (after affiliated keywords) but some objects
;; must not be affected.
((paragraph table-row verse-block)
(let ((cbeg (org-element-property :contents-begin element))
(cend (org-element-property :contents-end element)))
(let ((cbeg (org-element-contents-begin element))
(cend (org-element-contents-end element)))
(and cbeg (>= (point) cbeg) (< (point) cend)
(org--flyspell-object-check-p element))))))))))
(put 'org-mode 'flyspell-mode-predicate 'org-mode-flyspell-verify)
@ -1561,7 +2127,7 @@ key."
"Run `org-back-to-heading' when in org-mode."
(if (derived-mode-p 'org-mode)
(progn
(beginning-of-line)
(forward-line 0)
(or (org-at-heading-p (not invisible-ok))
(let (found)
(save-excursion

View File

@ -1,6 +1,6 @@
;;; org-crypt.el --- Public Key Encryption for Org Entries -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2007-2023 Free Software Foundation, Inc.
;; Copyright (C) 2007-2024 Free Software Foundation, Inc.
;; Author: John Wiegley <johnw@gnu.org>
@ -71,16 +71,18 @@
(defvar epg-context)
(declare-function org-back-over-empty-lines "org" ())
(declare-function org-current-level "org" ())
(declare-function org-back-to-heading "org" (&optional invisible-ok))
(declare-function org-before-first-heading-p "org" ())
(declare-function org-end-of-meta-data "org" (&optional full))
(declare-function org-end-of-subtree "org" (&optional invisible-ok to-heading))
(declare-function org-end-of-subtree "org" (&optional invisible-ok to-heading element))
(declare-function org-entry-get "org" (pom property &optional inherit literal-nil))
(declare-function org-fold-subtree "org-fold" (flag))
(declare-function org-make-tags-matcher "org" (match))
(declare-function org-make-tags-matcher "org" (match &optional only-local-tags))
(declare-function org-previous-visible-heading "org" (arg))
(declare-function org-scan-tags "org" (action matcher todo-only &optional start-level))
(declare-function org-set-property "org" (property value))
(declare-function org-cycle-set-startup-visibility "org-cycle" ())
(defgroup org-crypt nil
"Org Crypt."
@ -113,16 +115,16 @@ This setting can be overridden in the CRYPTKEY property."
(defcustom org-crypt-disable-auto-save 'ask
"What org-decrypt should do if `auto-save-mode' is enabled.
t : Disable auto-save-mode for the current buffer
t : Disable `auto-save-mode' for the current buffer
prior to decrypting an entry.
nil : Leave auto-save-mode enabled.
nil : Leave `auto-save-mode' enabled.
This may cause data to be written to disk unencrypted!
`ask' : Ask user whether or not to disable auto-save-mode
`ask' : Ask user whether or not to disable `auto-save-mode'
for the current buffer.
`encrypt': Leave auto-save-mode enabled for the current buffer,
`encrypt': Leave `auto-save-mode' enabled for the current buffer,
but automatically re-encrypt all decrypted entries
*before* auto-saving.
NOTE: This only works for entries which have a tag
@ -165,7 +167,7 @@ and END are buffer positions delimiting the encrypted area."
(cons start (line-beginning-position 2)))))))))
(defun org-crypt-check-auto-save ()
"Check whether auto-save-mode is enabled for the current buffer.
"Check whether `auto-save-mode' is enabled for the current buffer.
`auto-save-mode' may cause leakage when decrypting entries, so
check whether it's enabled, and decide what to do about it.
@ -177,7 +179,7 @@ See `org-crypt-disable-auto-save'."
(eq org-crypt-disable-auto-save t)
(and
(eq org-crypt-disable-auto-save 'ask)
(y-or-n-p "org-decrypt: auto-save-mode may cause leakage. Disable it for current buffer? ")))
(y-or-n-p "`org-decrypt': auto-save-mode may cause leakage. Disable it for current buffer? ")))
(message "org-decrypt: Disabling auto-save-mode for %s"
(or (buffer-file-name) (current-buffer)))
;; The argument to auto-save-mode has to be "-1", since
@ -244,12 +246,13 @@ Assume `epg-context' is set."
;; contents in the buffer.
(error
(insert contents)
(error (error-message-string err)))))
(error "%s" (error-message-string err)))))
(when folded-heading
(goto-char folded-heading)
(org-fold-subtree t))
nil)))))
(defvar org-outline-regexp-bol)
;;;###autoload
(defun org-decrypt-entry ()
"Decrypt the content of the current headline."
@ -265,23 +268,44 @@ Assume `epg-context' is set."
(save-excursion
(org-previous-visible-heading 1)
(point))))
(level (org-current-level))
(encrypted-text (org-crypt--encrypted-text beg end))
(decrypted-text
(decode-coding-string
(epg-decrypt-string epg-context encrypted-text)
'utf-8)))
'utf-8))
origin-marker)
;; Delete region starting just before point, because the
;; outline property starts at the \n of the heading.
(delete-region (1- (point)) end)
;; Store a checksum of the decrypted and the encrypted text
;; value. This allows reusing the same encrypted text if the
;; text does not change, and therefore avoid a re-encryption
;; process.
(insert "\n"
(propertize decrypted-text
'org-crypt-checksum (sha1 decrypted-text)
'org-crypt-key (org-crypt-key-for-heading)
'org-crypt-text encrypted-text))
(setq origin-marker (point-marker))
(if (string-match (org-headline-re level) decrypted-text)
;; If decrypted text contains other headings with levels
;; below LEVEL, adjust the subtree.
(let ((start 0) (min-level level))
(while (string-match (org-headline-re level) decrypted-text start)
(setq min-level (min min-level (1- (length (match-string 0 decrypted-text))))
start (match-end 0)))
(insert "\n"
(replace-regexp-in-string
org-outline-regexp-bol
(concat (make-string (1+ (- level min-level)) ?*) "\\&")
decrypted-text)))
;; Store a checksum of the decrypted and the encrypted text
;; value. This allows reusing the same encrypted text if the
;; text does not change, and therefore avoid a re-encryption
;; process.
(insert "\n"
(propertize decrypted-text
'org-crypt-checksum (sha1 decrypted-text)
'org-crypt-key (org-crypt-key-for-heading)
'org-crypt-text encrypted-text)))
;; Apply initial visibility.
(save-restriction
(narrow-to-region origin-marker (point))
(set-marker origin-marker nil)
(org-cycle-set-startup-visibility))
;; ... but keep the previous folded state.
(when folded-heading
(goto-char folded-heading)
(org-fold-subtree t))

View File

@ -1,6 +1,6 @@
;;; org-ctags.el --- Integrate Emacs "tags" Facility with Org -*- lexical-binding: t; -*-
;; Copyright (C) 2007-2023 Free Software Foundation, Inc.
;; Copyright (C) 2007-2024 Free Software Foundation, Inc.
;; Author: Paul Sexton <eeeickythump@gmail.com>
;; Keywords: org, wp
@ -28,7 +28,7 @@
;;
;; Allows Org mode to make use of the Emacs `etags' system. Defines
;; tag destinations in Org files as any text between <<double angled
;; brackets>>. This allows the tags-generation program `exuberant
;; brackets>>. This allows the tags-generation program `exuberant
;; ctags' to parse these files and create tag tables that record where
;; these destinations are found. Plain [[links]] in org mode files
;; which do not have <<matching destinations>> within the same file
@ -66,7 +66,7 @@
;; search the entire text of the current buffer for 'tag'.
;;
;; This behavior can be modified by changing the value of
;; ORG-CTAGS-OPEN-LINK-FUNCTIONS. For example I have the following in my
;; ORG-CTAGS-OPEN-LINK-FUNCTIONS. For example, I have the following in my
;; .emacs, which describes the same behavior as the above paragraph with
;; one difference:
;;
@ -149,7 +149,7 @@
(defvar org-ctags-enabled-p t
"Activate ctags support in org mode?")
(defvar org-ctags-tag-regexp "/<<([^>]+)>>/\\1/d,definition/"
(defvar org-ctags-tag-regexp "/<<([^<>]+)>>/\\1/d,definition/"
"Regexp expression used by ctags external program.
The regexp matches tag destinations in Org files.
Format is: /REGEXP/TAGNAME/FLAGS,TAGTYPE/
@ -484,11 +484,11 @@ its subdirectories contain large numbers of taggable files."
(setq exitcode
(shell-command
(format (concat "%s --langdef=orgmode --langmap=orgmode:.org "
"--regex-orgmode=\"%s\" -f \"%s\" -e -R \"%s\"")
"--regex-orgmode=\"%s\" -f \"%s\" -e -R %s")
org-ctags-path-to-ctags
org-ctags-tag-regexp
(expand-file-name (concat dir-name "/TAGS"))
(expand-file-name (concat dir-name "/*")))))
(expand-file-name (concat (shell-quote-argument dir-name) "/*")))))
(cond
((eql 0 exitcode)
(setq-local org-ctags-tag-list
@ -506,12 +506,11 @@ its subdirectories contain large numbers of taggable files."
(defun org-ctags-find-tag-interactive ()
"Prompt for the name of a tag, with autocompletion, then visit the named tag.
Uses `ido-mode' if available.
If the user enters a string that does not match an existing tag, create
a new topic."
(interactive)
(let* ((tag (ido-completing-read "Topic: " org-ctags-tag-list
nil 'confirm nil 'org-ctags-find-tag-history)))
(let* ((tag (completing-read "Topic: " org-ctags-tag-list
nil 'confirm nil 'org-ctags-find-tag-history)))
(when tag
(cond
((member tag org-ctags-tag-list)

View File

@ -1,8 +1,8 @@
;;; org-cycle.el --- Visibility cycling of Org entries -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2020-2023 Free Software Foundation, Inc.
;; Copyright (C) 2020-2024 Free Software Foundation, Inc.
;;
;; Maintainer: Ihor Radchenko <yantar92 at gmail dot com>
;; Maintainer: Ihor Radchenko <yantar92 at posteo dot net>
;; Keywords: folding, visibility cycling, invisible text
;; URL: https://orgmode.org
;;
@ -35,9 +35,10 @@
(require 'org-macs)
(require 'org-fold)
(declare-function org-element-type "org-element" (element))
(declare-function org-element-property "org-element" (property element))
(declare-function org-element-lineage "org-element" (datum &optional types with-self))
(declare-function org-element-type-p "org-element-ast" (node types))
(declare-function org-element-property "org-element-ast" (property node))
(declare-function org-element-post-affiliated "org-element" (node))
(declare-function org-element-lineage "org-element-ast" (datum &optional types with-self))
(declare-function org-element-at-point "org-element" (&optional pom cached-only))
(declare-function org-display-inline-images "org" (&optional include-linked refresh beg end))
(declare-function org-get-tags "org" (&optional pos local fontify))
@ -115,6 +116,7 @@ than its value."
(const :tag "No limit" nil)
(integer :tag "Maximum level")))
(defvaralias 'org-hide-block-startup 'org-cycle-hide-block-startup)
(defcustom org-cycle-hide-block-startup nil
"Non-nil means entering Org mode will fold all blocks.
This can also be set in on a per-file basis with
@ -125,6 +127,7 @@ This can also be set in on a per-file basis with
:group 'org-cycle
:type 'boolean)
(defvaralias 'org-hide-drawer-startup 'org-cycle-hide-drawer-startup)
(defcustom org-cycle-hide-drawer-startup t
"Non-nil means entering Org mode will fold all drawers.
This can also be set in on a per-file basis with
@ -200,6 +203,7 @@ Special case: when 0, never leave empty lines in collapsed view."
:type 'integer)
(put 'org-cycle-separator-lines 'safe-local-variable 'integerp)
(defvaralias 'org-pre-cycle-hook 'org-cycle-pre-hook)
(defcustom org-cycle-pre-hook nil
"Hook that is run before visibility cycling is happening.
The function(s) in this hook must accept a single argument which indicates
@ -240,6 +244,7 @@ normal outline commands like `show-all', but not with the cycling commands."
:package-version '(Org . "9.6")
:type 'boolean)
(defvaralias 'org-tab-first-hook 'org-cycle-tab-first-hook)
(defvar org-cycle-tab-first-hook nil
"Hook for functions to attach themselves to TAB.
See `org-ctrl-c-ctrl-c-hook' for more information.
@ -335,6 +340,10 @@ same as `S-TAB') also when called without prefix argument."
(and org-cycle-level-after-item/entry-creation
(or (org-cycle-level)
(org-cycle-item-indentation))))
(when (and org-cycle-max-level
(or (not (integerp org-cycle-max-level))
(< org-cycle-max-level 1)))
(user-error "`org-cycle-max-level' must be a positive integer"))
(let* ((limit-level
(or org-cycle-max-level
(and (boundp 'org-inlinetask-min-level)
@ -388,8 +397,8 @@ same as `S-TAB') also when called without prefix argument."
((org-fold-hide-drawer-toggle nil t element))
;; Table: enter it or move to the next field.
((and (org-match-line "[ \t]*[|+]")
(org-element-lineage element '(table) t))
(if (and (eq 'table (org-element-type element))
(org-element-lineage element 'table t))
(if (and (org-element-type-p element 'table)
(eq 'table.el (org-element-property :type element)))
(message (substitute-command-keys "\\<org-mode-map>\
Use `\\[org-edit-special]' to edit table.el tables"))
@ -404,8 +413,8 @@ Use `\\[org-edit-special]' to edit table.el tables"))
t)))
(and item
(= (line-beginning-position)
(org-element-property :post-affiliated
item)))))
(org-element-post-affiliated
item)))))
(org-match-line org-outline-regexp))
(or (bolp) (not (eq org-cycle-emulate-tab 'exc-hl-bol))))
(org-cycle-internal-local))
@ -421,7 +430,7 @@ Use `\\[org-edit-special]' to edit table.el tables"))
(call-interactively (global-key-binding (kbd "TAB"))))
((or (eq org-cycle-emulate-tab t)
(and (memq org-cycle-emulate-tab '(white whitestart))
(save-excursion (beginning-of-line 1) (looking-at "[ \t]*"))
(save-excursion (forward-line 0) (looking-at "[ \t]*"))
(or (and (eq org-cycle-emulate-tab 'white)
(= (match-end 0) (line-end-position)))
(and (eq org-cycle-emulate-tab 'whitestart)
@ -480,7 +489,7 @@ Use `\\[org-edit-special]' to edit table.el tables"))
(save-excursion
(if (org-at-item-p)
(progn
(beginning-of-line)
(forward-line 0)
(setq struct (org-list-struct))
(setq eoh (line-end-position))
(setq eos (org-list-get-item-end-before-blank (point) struct))
@ -502,16 +511,16 @@ Use `\\[org-edit-special]' to edit table.el tables"))
(save-excursion
(org-list-search-forward (org-item-beginning-re) eos t))))))
;; Determine end invisible part of buffer (EOL)
(beginning-of-line 2)
(forward-line 1)
(if (eq org-fold-core-style 'text-properties)
(while (and (not (eobp)) ;this is like `next-line'
(org-fold-folded-p (1- (point))))
(goto-char (org-fold-next-visibility-change nil nil t))
(and (eolp) (beginning-of-line 2)))
(and (eolp) (forward-line 1)))
(while (and (not (eobp)) ;this is like `next-line'
(get-char-property (1- (point)) 'invisible))
(goto-char (next-single-char-property-change (point) 'invisible))
(and (eolp) (beginning-of-line 2))))
(and (eolp) (forward-line 1))))
(setq eol (point)))
;; Find out what to do next and set `this-command'
(cond
@ -545,7 +554,7 @@ Use `\\[org-edit-special]' to edit table.el tables"))
(save-excursion
(org-back-to-heading)
(while (org-list-search-forward (org-item-beginning-re) eos t)
(beginning-of-line 1)
(forward-line 0)
(let* ((struct (org-list-struct))
(prevs (org-list-prevs-alist struct))
(end (org-list-get-bottom-point struct)))
@ -608,7 +617,9 @@ With a numeric prefix, show all headlines up to that level."
(defun org-cycle-set-startup-visibility ()
"Set the visibility required by startup options and properties."
(cond
((eq org-startup-folded t)
;; `fold' is technically not allowed value, but it is often
;; intuitively tried by users by analogy with #+STARTUP: fold.
((memq org-startup-folded '(t fold overview))
(org-cycle-overview))
((eq org-startup-folded 'content)
(org-cycle-content))
@ -620,8 +631,10 @@ With a numeric prefix, show all headlines up to that level."
(org-cycle-content 4))
((eq org-startup-folded 'show5levels)
(org-cycle-content 5))
((or (eq org-startup-folded 'showeverything)
(eq org-startup-folded nil))
;; `nofold' and `showall' are technically not allowed values, but
;; they are often intuitively tried by users by analogy with
;; #+STARTUP: nofold or #STARUP: showall.
((memq org-startup-folded '(showeverything nil nofold showall))
(org-fold-show-all)))
(unless (eq org-startup-folded 'showeverything)
(when org-cycle-hide-block-startup (org-fold-hide-block-all))
@ -634,20 +647,21 @@ With a numeric prefix, show all headlines up to that level."
"Switch subtree visibility according to VISIBILITY property."
(interactive)
(let ((regexp (org-re-property "VISIBILITY")))
(org-with-point-at 1
(save-excursion
(goto-char (point-min))
(while (re-search-forward regexp nil t)
(let ((state (match-string 3)))
(let ((state (match-string 3)))
(if (not (org-at-property-p)) (outline-next-heading)
(save-excursion
(org-back-to-heading t)
(org-fold-subtree t)
(pcase state
("folded"
("folded"
(org-fold-subtree t))
("children"
("children"
(org-fold-show-hidden-entry)
(org-fold-show-children))
("content"
("content"
;; Newline before heading will be outside the
;; narrowing. Make sure that it is revealed.
(org-fold-heading nil)
@ -655,10 +669,9 @@ With a numeric prefix, show all headlines up to that level."
(save-restriction
(org-narrow-to-subtree)
(org-cycle-content))))
((or "all" "showall")
((or "all" "showall")
(org-fold-show-subtree))
(_ nil)))
(org-end-of-subtree)))))))
(_ nil)))))))))
(defun org-cycle-overview ()
"Switch to overview mode, showing only top-level headlines."
@ -683,7 +696,7 @@ With a numeric prefix, show all headlines up to that level."
(defun org-cycle-content (&optional arg)
"Show all headlines in the buffer, like a table of contents.
With numerical argument N, show content up to level N."
With numerical argument ARG, show content up to level ARG."
(interactive "p")
(org-fold-show-all '(headings))
(save-excursion
@ -705,7 +718,9 @@ With numerical argument N, show content up to level N."
"Temporarily store scroll position to restore.")
(defun org-cycle-optimize-window-after-visibility-change (state)
"Adjust the window after a change in outline visibility.
This function is the default value of the hook `org-cycle-hook'."
This function is the default value of the hook `org-cycle-hook'.
STATE is the current outline visibility state. It should be one of
symbols `content', `all', `folded', `children', or `subtree'."
(when (get-buffer-window (current-buffer))
(let ((repeat (eq last-command this-command)))
(unless repeat
@ -791,7 +806,9 @@ STATE should be one of the symbols listed in the docstring of
(defun org-cycle-display-inline-images (state)
"Auto display inline images under subtree when cycling.
It works when `org-cycle-inline-images-display' is non-nil."
It works when `org-cycle-inline-images-display' is non-nil.
STATE is the current outline visibility state. It should be one of
symbols `content', `all', `folded', `children', or `subtree'."
(when org-cycle-inline-images-display
(pcase state
('children

View File

@ -1,6 +1,6 @@
;;; org-datetree.el --- Create date entries in a tree -*- lexical-binding: t; -*-
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;; Author: Carsten Dominik <carsten.dominik@gmail.com>
;; Keywords: outlines, hypermedia, calendar, wp
@ -99,16 +99,15 @@ If time-period is month, then group entries by month."
(month (calendar-extract-month d))
(day (calendar-extract-day d)))
(org-datetree--find-create
"^\\*+[ \t]+\\([12][0-9]\\{3\\}\\)\\(\\s-*?\
\\([ \t]:[[:alnum:]:_@#%%]+:\\)?\\s-*$\\)"
year)
"\\([12][0-9]\\{3\\}\\)"
year nil nil nil t)
(org-datetree--find-create
"^\\*+[ \t]+%d-\\([01][0-9]\\) \\w+$"
year month)
"%d-\\([01][0-9]\\) \\w+"
year month nil nil t)
(when (eq time-grouping 'day)
(org-datetree--find-create
"^\\*+[ \t]+%d-%02d-\\([0123][0-9]\\) \\w+$"
year month day)))))
"%d-%02d-\\([0123][0-9]\\) \\w+"
year month day nil t)))))
;;;###autoload
(defun org-datetree-find-iso-week-create (d &optional keep-restriction)
@ -147,33 +146,51 @@ will be built under the headline at point."
(week (nth 0 iso-date)))
;; ISO 8601 week format is %G-W%V(-%u)
(org-datetree--find-create
"^\\*+[ \t]+\\([12][0-9]\\{3\\}\\)\\(\\s-*?\
\\([ \t]:[[:alnum:]:_@#%%]+:\\)?\\s-*$\\)"
weekyear nil nil
(format-time-string "%G" time))
"\\([12][0-9]\\{3\\}\\)"
weekyear nil nil (format-time-string "%G" time) t)
(org-datetree--find-create
"^\\*+[ \t]+%d-W\\([0-5][0-9]\\)$"
weekyear week nil
(format-time-string "%G-W%V" time))
"%d-W\\([0-5][0-9]\\)"
weekyear week nil (format-time-string "%G-W%V" time) t)
;; For the actual day we use the regular date instead of ISO week.
(org-datetree--find-create
"^\\*+[ \t]+%d-%02d-\\([0123][0-9]\\) \\w+$"
year month day))))
"%d-%02d-\\([0123][0-9]\\) \\w+" year month day nil t))))
(defun org-datetree--find-create
(regex-template year &optional month day insert)
(regex-template year &optional month day insert match-title)
"Find the datetree matched by REGEX-TEMPLATE for YEAR, MONTH, or DAY.
REGEX-TEMPLATE is passed to `format' with YEAR, MONTH, and DAY as
arguments. Match group 1 is compared against the specified date
arguments.
If MATCH-TITLE is non-nil, REGEX-TEMPLATE is matched against
heading title and the exact regexp matched against heading line is:
(format org-complex-heading-regexp-format
(format regex-template year month day))
If MATCH-TITLE is nil, the regexp matched against heading line is
REGEX-TEMPLATE:
(format regex-template year month day)
Match group 1 in REGEX-TEMPLATE is compared against the specified date
component. If INSERT is non-nil and there is no match then it is
inserted into the buffer."
(when (or month day)
(org-narrow-to-subtree))
(let ((re (format regex-template year month day))
;; ensure that the first match group in REGEX-TEMPLATE
;; is the first inside `org-complex-heading-regexp-format'
(when (and match-title
(not (string-match-p "\\\\(\\?1:" regex-template))
(string-match "\\\\(" regex-template))
(setq regex-template (replace-match "\\(?1:" nil t regex-template)))
(let ((re (if match-title
(format org-complex-heading-regexp-format
(format regex-template year month day))
(format regex-template year month day)))
match)
(goto-char (point-min))
(while (and (setq match (re-search-forward re nil t))
(goto-char (match-beginning 1))
(goto-char (match-beginning 1))
(< (string-to-number (match-string 1)) (or day month year))))
(cond
((not match)
@ -181,9 +198,9 @@ inserted into the buffer."
(unless (bolp) (insert "\n"))
(org-datetree-insert-line year month day insert))
((= (string-to-number (match-string 1)) (or day month year))
(beginning-of-line))
(forward-line 0))
(t
(beginning-of-line)
(forward-line 0)
(org-datetree-insert-line year month day insert)))))
(defun org-datetree-insert-line (year &optional month day text)
@ -205,11 +222,11 @@ inserted into the buffer."
(save-excursion
(insert "\n")
(org-indent-line)
(org-insert-time-stamp
(org-insert-timestamp
(org-encode-time 0 0 0 day month year)
nil
(eq org-datetree-add-timestamp 'inactive))))
(beginning-of-line))
(forward-line 0))
(defun org-datetree-file-entry-under (txt d)
"Insert a node TXT into the date tree under date D."

View File

@ -1,6 +1,6 @@
;;; org-duration.el --- Library handling durations -*- lexical-binding: t; -*-
;; Copyright (C) 2017-2023 Free Software Foundation, Inc.
;; Copyright (C) 2017-2024 Free Software Foundation, Inc.
;; Author: Nicolas Goaziou <mail@nicolasgoaziou.fr>
;; Keywords: outlines, hypermedia, calendar, wp

1150
lisp/org-element-ast.el Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
;;; org-entities.el --- Support for Special Entities -*- lexical-binding: t; -*-
;; Copyright (C) 2010-2023 Free Software Foundation, Inc.
;; Copyright (C) 2010-2024 Free Software Foundation, Inc.
;; Author: Carsten Dominik <carsten.dominik@gmail.com>,
;; Ulf Stegemann <ulf at zeitform dot de>
@ -29,6 +29,7 @@
(require 'org-macs)
(org-assert-version)
(require 'seq) ; Emacs 27 does not preload seq.el; for `seq-every-p'.
(declare-function org-mode "org" ())
(declare-function org-toggle-pretty-entities "org" ())
@ -277,8 +278,10 @@ packages to be loaded, add these packages to `org-latex-packages-alist'."
("vert" "\\vert{}" t "&vert;" "|" "|" "|")
("vbar" "|" nil "|" "|" "|" "|")
("brvbar" "\\textbrokenbar{}" nil "&brvbar;" "|" "¦" "¦")
("S" "\\S" nil "&sect;" "paragraph" "§" "§")
("sect" "\\S" nil "&sect;" "paragraph" "§" "§")
("S" "\\S" nil "&sect;" "section" "§" "§")
("sect" "\\S" nil "&sect;" "section" "§" "§")
("P" "\\P{}" nil "&para;" "paragraph" "" "")
("para" "\\P{}" nil "&para;" "paragraph" "" "")
("amp" "\\&" nil "&amp;" "&" "&" "&")
("lt" "\\textless{}" nil "&lt;" "<" "<" "<")
("gt" "\\textgreater{}" nil "&gt;" ">" ">" ">")
@ -494,7 +497,6 @@ packages to be loaded, add these packages to `org-latex-packages-alist'."
("checkmark" "\\checkmark" t "&check;" "[checkmark]" "[checkmark]" "")
"** Miscellaneous (seldom used)"
("para" "\\P{}" nil "&para;" "[pilcrow]" "" "")
("ordf" "\\textordfeminine{}" nil "&ordf;" "_a_" "ª" "ª")
("ordm" "\\textordmasculine{}" nil "&ordm;" "_o_" "º" "º")
("cedil" "\\c{}" nil "&cedil;" "[cedilla]" "¸" "¸")

View File

@ -1,6 +1,6 @@
;;; org-faces.el --- Face definitions -*- lexical-binding: t; -*-
;; Copyright (C) 2004-2023 Free Software Foundation, Inc.
;; Copyright (C) 2004-2024 Free Software Foundation, Inc.
;; Author: Carsten Dominik <carsten.dominik@gmail.com>
;; Keywords: outlines, hypermedia, calendar, wp
@ -389,6 +389,10 @@ changes."
"Face used for tables."
:group 'org-faces)
(defface org-table-row '((t :inherit org-table))
"Face used to fontify whole table rows (including newlines and indentation)."
:group 'org-faces)
(defface org-table-header '((t :inherit org-table
:background "LightGray"
:foreground "Black"))
@ -660,6 +664,10 @@ month and 365.24 days for a year)."
"Face used for agenda entries that come from the Emacs diary."
:group 'org-faces)
(defface org-agenda-calendar-daterange '((t :inherit default))
"Face used to show entries with a date range in the agenda."
:group 'org-faces)
(defface org-agenda-calendar-event '((t :inherit default))
"Face used to show events and appointments in the agenda."
:group 'org-faces)

View File

@ -1,6 +1,6 @@
;;; org-feed.el --- Add RSS feed items to Org files -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;;
;; Author: Carsten Dominik <carsten.dominik@gmail.com>
;; Keywords: outlines, hypermedia, calendar, wp
@ -475,7 +475,7 @@ This will find DRAWER and extract the alist."
(goto-char pos)
(let ((end (save-excursion (org-end-of-subtree t t))))
(if (re-search-forward
(concat "^[ \t]*:" drawer ":[ \t]*\n\\([^\000]*?\\)\n[ \t]*:END:")
(concat "^[ \t]*:" drawer ":[ \t]*\n\\(\\(?:.\\|\n\\)*?\\)\n[ \t]*:END:")
end t)
(read (match-string 1))
nil))))
@ -495,7 +495,7 @@ This will find DRAWER and extract the alist."
(match-beginning 0)))))
(outline-next-heading)
(insert " :" drawer ":\n :END:\n")
(beginning-of-line 0))
(forward-line -1))
(insert (pp-to-string status)))))
(defun org-feed-add-items (pos entries)
@ -508,7 +508,7 @@ This will find DRAWER and extract the alist."
(setq level (org-get-valid-level (length (match-string 1)) 1))
(org-end-of-subtree t t)
(skip-chars-backward " \t\n")
(beginning-of-line 2)
(forward-line 1)
(setq pos (point))
(while (setq entry (pop entries))
(org-paste-subtree level entry 'yank))
@ -565,7 +565,7 @@ If that property is already present, nothing changes."
(let ((v (plist-get entry (intern (concat ":" name)))))
(save-excursion
(save-match-data
(beginning-of-line)
(forward-line 0)
(if (looking-at
(concat "^\\([ \t]*\\)%" name "[ \t]*$"))
(org-feed-make-indented-block
@ -633,7 +633,7 @@ containing the properties `:guid' and `:item-full-text'."
end (and (re-search-forward "</item>" nil t)
(match-beginning 0)))
(setq item (buffer-substring beg end)
guid (if (string-match "<guid\\>.*?>\\([^\000]*?\\)</guid>" item)
guid (if (string-match "<guid\\>.*?>\\(\\(?:.\\|\n\\)*?\\)</guid>" item)
(xml-substitute-special (match-string-no-properties 1 item))))
(setq entry (list :guid guid :item-full-text item))
(push entry entries)
@ -647,7 +647,7 @@ containing the properties `:guid' and `:item-full-text'."
(with-temp-buffer
(insert (plist-get entry :item-full-text))
(goto-char (point-min))
(while (re-search-forward "<\\([a-zA-Z]+\\>\\).*?>\\([^\000]*?\\)</\\1>"
(while (re-search-forward "<\\([a-zA-Z]+\\>\\).*?>\\(\\(?:.\\|\n\\)*?\\)</\\1>"
nil t)
(setq entry (plist-put entry
(intern (concat ":" (match-string 1)))

View File

@ -1,8 +1,8 @@
;;; org-fold-core.el --- Folding buffer text -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2020-2023 Free Software Foundation, Inc.
;; Copyright (C) 2020-2024 Free Software Foundation, Inc.
;;
;; Author: Ihor Radchenko <yantar92 at gmail dot com>
;; Author: Ihor Radchenko <yantar92 at posteo dot net>
;; Keywords: folding, invisible text
;; URL: https://orgmode.org
;;
@ -280,12 +280,13 @@
;;; Customization
(defcustom org-fold-core-style 'text-properties
(defcustom org-fold-core-style (if (version< emacs-version "29")
'text-properties
'overlays)
"Internal implementation detail used to hide folded text.
Can be either `text-properties' or `overlays'.
The former is faster on large files, while the latter is generally
less error-prone with regard to third-party packages that haven't yet
adapted to the new folding implementation.
The former is faster on large files in Emacs <29, while the latter is
generally less error-prone with regard to third-party packages.
Important: This variable must be set before loading Org."
:group 'org
@ -380,6 +381,9 @@ The following properties are known:
`buffer-invisibility-spec' will be used as is.
Note that changing this property from nil to t may
clear the setting in `buffer-invisibility-spec'.
- :font-lock :: non-nil means that newlines after the fold should
be re-fontified upon folding/unfolding. See
`org-activate-folds'.
- :alias :: a list of aliases for the SPEC-SYMBOL.
- :fragile :: Must be a function accepting two arguments.
Non-nil means that changes in region may cause
@ -424,7 +428,7 @@ Return nil when there is no matching folding spec."
(unless org-fold-core--spec-symbols
(dolist (spec (org-fold-core-folding-spec-list))
(push (cons spec spec) org-fold-core--spec-symbols)
(dolist (alias (assq :alias (assq spec org-fold-core--specs)))
(dolist (alias (cdr (assq :alias (assq spec org-fold-core--specs))))
(push (cons alias spec) org-fold-core--spec-symbols))))
(alist-get spec-or-alias org-fold-core--spec-symbols)))
@ -433,7 +437,7 @@ Return nil when there is no matching folding spec."
(org-fold-core-get-folding-spec-from-alias spec-or-alias))
(defsubst org-fold-core--check-spec (spec-or-alias)
"Throw an error if SPEC-OR-ALIAS is not in `org-fold-core--spec-priority-list'."
"Throw an error if SPEC-OR-ALIAS is not in `org-fold-core-folding-spec-list'."
(unless (org-fold-core-folding-spec-p spec-or-alias)
(error "%s is not a valid folding spec" spec-or-alias)))
@ -553,7 +557,10 @@ and the setup appears to be created for different buffer,
copy the old invisibility state into new buffer-local text properties,
unless RETURN-ONLY is non-nil."
(if (eq org-fold-core-style 'overlays)
(org-fold-core-get-folding-property-symbol spec nil 'global)
(or (gethash (cons 'global spec) org-fold-core--property-symbol-cache)
(puthash (cons 'global spec)
(org-fold-core-get-folding-property-symbol spec nil 'global)
org-fold-core--property-symbol-cache))
(let* ((buf (or buffer (current-buffer))))
;; Create unique property symbol for SPEC in BUFFER
(let ((local-prop (or (gethash (cons buf spec) org-fold-core--property-symbol-cache)
@ -633,6 +640,10 @@ unless RETURN-ONLY is non-nil."
text-property-default-nonsticky
full-prop-list))))))))))))))
(defun org-fold-core--update-buffer-folds ()
"Copy folding state in a new buffer with text copied from old buffer."
(org-fold-core--property-symbol-get-create (car (org-fold-core-folding-spec-list))))
(defun org-fold-core-decouple-indirect-buffer-folds ()
"Copy and decouple folding state in a newly created indirect buffer.
This function is mostly intended to be used in
@ -640,7 +651,7 @@ This function is mostly intended to be used in
(when (and (buffer-base-buffer)
(eq org-fold-core-style 'text-properties)
(not (memql 'ignore-indirect org-fold-core--optimise-for-huge-buffers)))
(org-fold-core--property-symbol-get-create (car (org-fold-core-folding-spec-list)))))
(org-fold-core--update-buffer-folds)))
;;; API
@ -783,16 +794,19 @@ corresponding folding spec (if the text is folded using that spec)."
(when (and spec (not (eq spec 'all))) (org-fold-core--check-spec spec))
(org-with-point-at pom
(cond
((eq spec 'all)
(let ((result))
(dolist (spec (org-fold-core-folding-spec-list))
(let ((val (get-char-property (point) (org-fold-core--property-symbol-get-create spec nil t))))
(when val (push val result))))
(reverse result)))
((null spec)
(let ((result (get-char-property (point) 'invisible)))
(when (org-fold-core-folding-spec-p result) result)))
(t (get-char-property (point) (org-fold-core--property-symbol-get-create spec nil t)))))))
((or (null spec) (eq spec 'all))
(catch :single-spec
(let ((result))
(dolist (lspec (org-fold-core-folding-spec-list))
(let ((val (if (eq org-fold-core-style 'text-properties)
(get-text-property (point) (org-fold-core--property-symbol-get-create lspec nil t))
(get-char-property (point) (org-fold-core--property-symbol-get-create lspec nil t)))))
(when (and val (null spec)) (throw :single-spec val))
(when val (push val result))))
(reverse result))))
(t (if (eq org-fold-core-style 'text-properties)
(get-text-property (point) (org-fold-core--property-symbol-get-create spec nil t))
(get-char-property (point) (org-fold-core--property-symbol-get-create spec nil t))))))))
(defun org-fold-core-get-folding-specs-in-region (beg end)
"Get all folding specs in region from BEG to END."
@ -843,13 +857,20 @@ If PREVIOUS-P is non-nil, search backwards."
(next-change (if previous-p
(if ignore-hidden-p
(lambda (p) (org-fold-core-previous-folding-state-change (org-fold-core-get-folding-spec nil p) p limit))
(lambda (p) (max limit (1- (previous-single-char-property-change p 'invisible nil limit)))))
(lambda (p) (max limit (previous-single-char-property-change p 'invisible nil limit))))
(if ignore-hidden-p
(lambda (p) (org-fold-core-next-folding-state-change (org-fold-core-get-folding-spec nil p) p limit))
(lambda (p) (next-single-char-property-change p 'invisible nil limit)))))
(next pos))
(while (and (funcall cmp next limit)
(not (org-xor invisible-initially? (funcall invisible-p next))))
(not (org-xor
invisible-initially?
(funcall invisible-p
(if previous-p
;; NEXT-1 -> NEXT is the change.
(max limit (1- next))
;; NEXT -> NEXT+1 is the change.
next)))))
(setq next (funcall next-change next)))
next))
@ -897,14 +918,19 @@ Search backwards when PREVIOUS-P is non-nil."
(unless spec-or-alias
(setq spec-or-alias (org-fold-core-folding-spec-list)))
(setq pos (or pos (point)))
(apply (if previous-p
#'max
#'min)
(mapcar (if previous-p
(lambda (prop) (max (or limit (point-min)) (previous-single-char-property-change pos prop nil (or limit (point-min)))))
(lambda (prop) (next-single-char-property-change pos prop nil (or limit (point-max)))))
(mapcar (lambda (el) (org-fold-core--property-symbol-get-create el nil t))
spec-or-alias))))
(let ((limit (or limit (if previous-p (point-min) (point-max)))))
(catch :limit
(dolist (prop (mapcar
(lambda (el)
(org-fold-core--property-symbol-get-create el nil t))
spec-or-alias))
(when (= limit pos) (throw :limit limit))
(setq
limit
(if previous-p
(previous-single-char-property-change pos prop nil limit)
(next-single-char-property-change pos prop nil limit))))
limit)))
(defun org-fold-core-previous-folding-state-change (&optional spec-or-alias pos limit)
"Call `org-fold-core-next-folding-state-change' searching backwards."
@ -985,6 +1011,24 @@ WITH-MARKERS must be nil when RELATIVE is non-nil."
;;;;; Region visibility
(defvar org-fold-core--keep-overlays nil
"When non-nil, `org-fold-core-region' will not remove existing overlays.")
(defvar org-fold-core--isearch-overlays) ; defined below
(defmacro org-fold-core--keep-overlays (&rest body)
"Run BODY with `org-fold-core--keep-overlays' set to t."
(declare (debug (body)))
`(let ((org-fold-core--keep-overlays t))
,@body))
(defvar org-fold-core--isearch-active nil
"When non-nil, `org-fold-core-region' records created overlays.
New overlays will be added to `org-fold-core--isearch-overlays'.")
(defmacro org-fold-core--with-isearch-active (&rest body)
"Run BODY with `org-fold-core--isearch-active' set to t."
(declare (debug (body)))
`(let ((org-fold-core--isearch-active t))
,@body))
;; This is the core function performing actual folding/unfolding. The
;; folding state is stored in text property (folding property)
;; returned by `org-fold-core--property-symbol-get-create'. The value of the
@ -997,7 +1041,43 @@ If SPEC-OR-ALIAS is omitted and FLAG is nil, unfold everything in the region."
(when spec (org-fold-core--check-spec spec))
(with-silent-modifications
(org-with-wide-buffer
(when (eq org-fold-core-style 'overlays) (remove-overlays from to 'invisible spec))
;; Arrange fontifying newlines after all the folds between FROM
;; and TO to match the first character before the fold; not the
;; last as per Emacs defaults. This makes :extend faces span
;; past the ellipsis. See bug#65896. The face properties are
;; assigned via `org-activate-folds'.
(when (or (not spec) (org-fold-core-get-folding-spec-property spec :font-lock))
(when (equal ?\n (char-after from))
(font-lock-flush from (1+ from)))
(when (equal ?\n (char-after to))
(font-lock-flush to (1+ to)))
(dolist (region (org-fold-core-get-regions :from from :to to :specs spec))
(when (equal ?\n (char-after (cadr region)))
(font-lock-flush (cadr region) (1+ (cadr region))))
;; Re-fontify beginning of the fold - we may
;; unfold inside an existing fold, with FROM begin a newline
;; after spliced fold.
(when (equal ?\n (char-after (car region)))
(font-lock-flush (car region) (1+ (car region))))))
(when (eq org-fold-core-style 'overlays)
(if org-fold-core--keep-overlays
(mapc
(lambda (ov)
(when (or (not spec)
(eq spec (overlay-get ov 'invisible)))
(when (and org-fold-core--isearch-active
(overlay-get ov 'invisible)
(org-fold-core-get-folding-spec-property
(overlay-get ov 'invisible) :isearch-open))
(when (overlay-get ov 'invisible)
(overlay-put ov 'org-invisible (overlay-get ov 'invisible)))
(overlay-put ov 'invisible nil)
(when org-fold-core--isearch-active
(cl-pushnew ov org-fold-core--isearch-overlays)))))
(overlays-in from to))
(when spec
(remove-overlays from to 'org-invisible spec)
(remove-overlays from to 'invisible spec))))
(if flag
(if (not spec)
(error "Calling `org-fold-core-region' with missing SPEC")
@ -1007,17 +1087,15 @@ If SPEC-OR-ALIAS is omitted and FLAG is nil, unfold everything in the region."
(let ((o (make-overlay from to nil
(org-fold-core-get-folding-spec-property spec :front-sticky)
(org-fold-core-get-folding-spec-property spec :rear-sticky))))
(when org-fold-core--isearch-active
(push o org-fold-core--isearch-overlays))
(overlay-put o 'evaporate t)
(overlay-put o (org-fold-core--property-symbol-get-create spec) spec)
(overlay-put o 'invisible spec)
;; Preserve priority.
(overlay-put o 'priority (length (member spec (org-fold-core-folding-spec-list))))
(overlay-put o 'isearch-open-invisible #'org-fold-core--isearch-show)
;; FIXME: Disabling to work around Emacs bug#60399
;; and https://orgmode.org/list/87zgb6tk6h.fsf@localhost.
;; The proper fix will require making sure that
;; `org-fold-core-isearch-open-function' does not
;; delete the overlays used by isearch.
;; (overlay-put o 'isearch-open-invisible-temporary #'org-fold-core--isearch-show-temporary)
)
(overlay-put o 'isearch-open-invisible-temporary #'org-fold-core--isearch-show-temporary))
(put-text-property from to (org-fold-core--property-symbol-get-create spec) spec)
(put-text-property from to 'isearch-open-invisible #'org-fold-core--isearch-show)
(put-text-property from to 'isearch-open-invisible-temporary #'org-fold-core--isearch-show-temporary)
@ -1041,7 +1119,13 @@ If SPEC-OR-ALIAS is omitted and FLAG is nil, unfold everything in the region."
(setq pos next))
(setq pos (next-single-char-property-change pos 'invisible nil to)))))))
(when (eq org-fold-core-style 'text-properties)
(remove-text-properties from to (list (org-fold-core--property-symbol-get-create spec) nil)))))))))
(remove-text-properties from to (list (org-fold-core--property-symbol-get-create spec) nil)))))
;; Re-calculate trailing faces for all the folds revealed
;; by unfolding or created by folding.
(when (or (not spec) (org-fold-core-get-folding-spec-property spec :font-lock))
(dolist (region (org-fold-core-get-regions :from from :to to :specs spec))
(when (equal ?\n (char-after (cadr region)))
(font-lock-flush (cadr region) (1+ (cadr region))))))))))
(cl-defmacro org-fold-core-regions (regions &key override clean-markers relative)
"Fold every region in REGIONS list in current buffer.
@ -1104,13 +1188,19 @@ TYPE can be either `text-properties' or `overlays'."
(setq-local isearch-filter-predicate #'org-fold-core--isearch-filter-predicate-text-properties))
(`overlays
(when (eq org-fold-core-style 'text-properties)
(setq-local isearch-filter-predicate #'org-fold-core--isearch-filter-predicate-overlays)
(add-hook 'isearch-mode-end-hook #'org-fold-core--clear-isearch-overlays nil 'local)))
(add-function :before (local 'isearch-filter-predicate) #'org-fold-core--create-isearch-overlays)
;; When `isearch-filter-predicate' is called outside isearch,
;; it is common that `isearch-mode-end-hook' does not get
;; executed, but `isearch-clean-overlays' usually does.
(advice-add
'isearch-clean-overlays :after
#'org-fold-core--clear-isearch-overlays
'((name . isearch-clean-overlays@org-fold-core)))))
(_ (error "%s: Unknown type of setup for `org-fold-core--isearch-setup'" type))))
(defun org-fold-core--isearch-reveal (pos)
"Default function used to reveal hidden text at POS for isearch."
(let ((region (org-fold-core-get-region-at-point pos)))
(let ((region (org-fold-core-get-region-at-point nil pos)))
(org-fold-core-region (car region) (cdr region) nil)))
(defun org-fold-core--isearch-filter-predicate-text-properties (beg end)
@ -1145,34 +1235,35 @@ This function is intended to be used as `isearch-filter-predicate'."
"Clear `org-fold-core--isearch-local-regions'."
(clrhash org-fold-core--isearch-local-regions))
(defun org-fold-core--isearch-show (_)
"Reveal text at point found by isearch."
(funcall org-fold-core-isearch-open-function (point)))
(defun org-fold-core--isearch-show (overlay-or-region)
"Reveal text at OVERLAY-OR-REGION found by isearch."
(let (beg end)
(if (overlayp overlay-or-region)
(setq beg (overlay-start overlay-or-region)
end (overlay-end overlay-or-region))
(setq beg (car overlay-or-region)
end (cdr overlay-or-region)))
;; FIXME: Reveal the match (usually point, but may sometimes go beyond the region).
(when (< beg (point) end)
(funcall org-fold-core-isearch-open-function (point)))
(org-fold-core-region beg end nil)))
(defun org-fold-core--isearch-show-temporary (region hide-p)
"Temporarily reveal text in REGION.
Hide text instead if HIDE-P is non-nil.
REGION can also be an overlay in current buffer."
(when (overlayp region)
(setq region (cons (overlay-start region)
(overlay-end region))))
(if (not hide-p)
(let ((pos (car region)))
(while (< pos (cdr region))
(let ((spec-no-open
(catch :found
(dolist (spec (org-fold-core-get-folding-spec 'all pos))
(unless (org-fold-core-get-folding-spec-property spec :isearch-open)
(throw :found spec))))))
(if spec-no-open
;; Skip regions folded with folding specs that cannot be opened.
(setq pos (org-fold-core-next-folding-state-change spec-no-open pos (cdr region)))
(dolist (spec (org-fold-core-get-folding-spec 'all pos))
(push (cons spec (org-fold-core-get-region-at-point spec pos)) (gethash region org-fold-core--isearch-local-regions)))
(org-fold-core--isearch-show region)
(setq pos (org-fold-core-next-folding-state-change nil pos (cdr region)))))))
(mapc (lambda (val) (org-fold-core-region (cadr val) (cddr val) t (car val))) (gethash region org-fold-core--isearch-local-regions))
(remhash region org-fold-core--isearch-local-regions)))
(save-match-data ; match data must not be modified.
(let ((org-fold-core-style (if (overlayp region) 'overlays 'text-properties)))
(if hide-p
(if (not (overlayp region))
nil ;; FIXME: after isearch supports text properties.
(when (overlay-get region 'org-invisible)
(overlay-put region 'invisible (overlay-get region 'org-invisible))))
;; isearch expects all the temporarily opened overlays to exist.
;; See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=60399
(org-fold-core--keep-overlays
(org-fold-core--with-isearch-active
(org-fold-core--isearch-show region)))))))
(defvar-local org-fold-core--isearch-special-specs nil
"List of specs that can break visibility state when converted to overlays.
@ -1187,49 +1278,28 @@ instead of text properties. The created overlays will be stored in
(while (< pos end)
;; We need loop below to make sure that we clean all invisible
;; properties, which may be nested.
(dolist (spec (org-fold-core-get-folding-spec 'all pos))
(unless (org-fold-core-get-folding-spec-property spec :isearch-ignore)
(let* ((region (org-fold-core-get-region-at-point spec pos)))
(when (memq spec org-fold-core--isearch-special-specs)
(setq pos (min pos (car region)))
(setq end (max end (cdr region))))
;; Changing text properties is considered buffer modification.
;; We do not want it here.
(with-silent-modifications
(org-fold-core-region (car region) (cdr region) nil spec)
;; The overlay is modeled after `outline-flag-region'
;; [2020-05-09 Sat] overlay for 'outline blocks.
(let ((o (make-overlay (car region) (cdr region) nil 'front-advance)))
(overlay-put o 'evaporate t)
(overlay-put o 'invisible spec)
(overlay-put o 'org-invisible spec)
;; Make sure that overlays are applied in the same order
;; with the folding specs.
;; Note: `memq` returns cdr with car equal to the first
;; found matching element.
(overlay-put o 'priority (length (memq spec (org-fold-core-folding-spec-list))))
;; `delete-overlay' here means that spec information will be lost
;; for the region. The region will remain visible.
(if (org-fold-core-get-folding-spec-property spec :isearch-open)
(overlay-put o 'isearch-open-invisible #'delete-overlay)
(overlay-put o 'isearch-open-invisible #'ignore)
(overlay-put o 'isearch-open-invisible-temporary #'ignore))
(push o org-fold-core--isearch-overlays))))))
(setq pos (org-fold-core-next-folding-state-change nil pos end)))))
(defun org-fold-core--isearch-filter-predicate-overlays (beg end)
"Return non-nil if text between BEG and END is deemed visible by isearch.
This function is intended to be used as `isearch-filter-predicate'."
(org-fold-core--create-isearch-overlays beg end) ;; trick isearch by creating overlays in place of invisible text
(isearch-filter-visible beg end))
(catch :repeat
(dolist (spec (org-fold-core-get-folding-spec 'all pos))
(unless (org-fold-core-get-folding-spec-property spec :isearch-ignore)
(let* ((region (org-fold-core-get-region-at-point spec pos)))
(when (memq spec org-fold-core--isearch-special-specs)
(setq end (max end (cdr region)))
(when (< (car region) beg)
(setq beg (car region))
(setq pos beg)
(throw :repeat t)))
;; Changing text properties is considered buffer modification.
;; We do not want it here.
(with-silent-modifications
(org-fold-core-region (car region) (cdr region) nil spec)
(let ((org-fold-core-style 'overlays))
(org-fold-core--with-isearch-active
(org-fold-core-region (car region) (cdr region) t spec)))))))
(setq pos (org-fold-core-next-folding-state-change nil pos end))))))
(defun org-fold-core--clear-isearch-overlay (ov)
"Convert OV region back into using text properties."
(let ((spec (if isearch-mode-end-hook-quit
;; Restore all folds.
(overlay-get ov 'org-invisible)
;; Leave opened folds open.
(overlay-get ov 'invisible))))
(let ((spec (overlay-get ov 'invisible)))
;; Ignore deleted overlays.
(when (and spec
(overlay-buffer ov))
@ -1238,8 +1308,6 @@ This function is intended to be used as `isearch-filter-predicate'."
(with-silent-modifications
(when (<= (overlay-end ov) (point-max))
(org-fold-core-region (overlay-start ov) (overlay-end ov) t spec)))))
(when (member ov isearch-opened-overlays)
(setq isearch-opened-overlays (delete ov isearch-opened-overlays)))
(delete-overlay ov))
(defun org-fold-core--clear-isearch-overlays ()
@ -1254,6 +1322,8 @@ This function is intended to be used as `isearch-filter-predicate'."
"Non-nil: skip processing modifications in `org-fold-core--fix-folded-region'.")
(defvar org-fold-core--ignore-fragility-checks nil
"Non-nil: skip fragility checks in `org-fold-core--fix-folded-region'.")
(defvar org-fold-core--suppress-folding-fix nil
"Non-nil: skip folding fix in `org-fold-core--fix-folded-region'.")
(defmacro org-fold-core-ignore-modifications (&rest body)
"Run BODY ignoring buffer modifications in `org-fold-core--fix-folded-region'."
@ -1262,12 +1332,47 @@ This function is intended to be used as `isearch-filter-predicate'."
(unwind-protect (progn ,@body)
(setq org-fold-core--last-buffer-chars-modified-tick (buffer-chars-modified-tick)))))
(defmacro org-fold-core-suppress-folding-fix (&rest body)
"Run BODY skipping re-folding checks in `org-fold-core--fix-folded-region'."
(declare (debug (form body)) (indent 0))
`(let ((org-fold-core--suppress-folding-fix t))
(progn ,@body)))
(defmacro org-fold-core-ignore-fragility-checks (&rest body)
"Run BODY skipping :fragility checks in `org-fold-core--fix-folded-region'."
(declare (debug (form body)) (indent 0))
`(let ((org-fold-core--ignore-fragility-checks t))
(progn ,@body)))
(defvar org-fold-core--region-delayed-list nil
"List holding (MKFROM MKTO FLAG SPEC-OR-ALIAS) arguments to process.
The list is used by `org-fold-core--region-delayed'.")
(defun org-fold-core--region-delayed (from to flag &optional spec-or-alias)
"Call `org-fold-core-region' after current command.
Pass the same FROM, TO, FLAG, and SPEC-OR-ALIAS."
;; Setup delayed folding.
(add-hook 'post-command-hook #'org-fold-core--process-delayed)
(let ((frommk (make-marker))
(tomk (make-marker)))
(set-marker frommk from (current-buffer))
(set-marker tomk to (current-buffer))
(push (list frommk tomk flag spec-or-alias) org-fold-core--region-delayed-list)))
(defun org-fold-core--process-delayed ()
"Perform folding for `org-fold-core--region-delayed-list'."
(when org-fold-core--region-delayed-list
(mapc (lambda (args)
(when (and (buffer-live-p (marker-buffer (nth 0 args)))
(buffer-live-p (marker-buffer (nth 1 args)))
(< (nth 0 args) (nth 1 args)))
(org-with-point-at (car args)
(apply #'org-fold-core-region args))))
;; Restore the initial folding order.
(nreverse org-fold-core--region-delayed-list))
;; Cleanup `post-command-hook'.
(remove-hook 'post-command-hook #'org-fold-core--process-delayed)
(setq org-fold-core--region-delayed-list nil)))
(defvar-local org-fold-core--last-buffer-chars-modified-tick nil
"Variable storing the last return value of `buffer-chars-modified-tick'.")
@ -1295,7 +1400,7 @@ property, unfold the region if the :fragile function returns non-nil."
;; buffer. Work around Emacs bug#46982.
;; Re-hide text inserted in the middle/front/back of a folded
;; region.
(unless (equal from to) ; Ignore deletions.
(unless (or org-fold-core--suppress-folding-fix (equal from to)) ; Ignore deletions.
(when (eq org-fold-core-style 'text-properties)
(org-fold-core-cycle-over-indirect-buffers
(dolist (spec (org-fold-core-folding-spec-list))
@ -1385,7 +1490,10 @@ property, unfold the region if the :fragile function returns non-nil."
(cons fold-begin fold-end)
spec))
;; Reveal completely, not just from the SPEC.
(org-fold-core-region fold-begin fold-end nil)))))
;; Do it only after command is finished -
;; some Emacs commands assume that
;; visibility is not altered by `after-change-functions'.
(org-fold-core--region-delayed fold-begin fold-end nil)))))
;; Move to next fold.
(setq pos (org-fold-core-next-folding-state-change spec pos local-to)))))))))))))

View File

@ -1,8 +1,8 @@
;;; org-fold.el --- Folding of Org entries -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2020-2023 Free Software Foundation, Inc.
;; Copyright (C) 2020-2024 Free Software Foundation, Inc.
;;
;; Author: Ihor Radchenko <yantar92 at gmail dot com>
;; Author: Ihor Radchenko <yantar92 at posteo dot net>
;; Keywords: folding, invisible text
;; URL: https://orgmode.org
;;
@ -61,11 +61,12 @@
(defvar org-element-headline-re)
(declare-function isearch-filter-visible "isearch" (beg end))
(declare-function org-element-type "org-element" (element))
(declare-function org-element-type "org-element-ast" (node &optional anonymous))
(declare-function org-element-at-point "org-element" (&optional pom cached-only))
(declare-function org-element-property "org-element" (property element))
(declare-function org-element-property "org-element-ast" (property node))
(declare-function org-element-end "org-element" (node))
(declare-function org-element-post-affiliated "org-element" (node))
(declare-function org-element--current-element "org-element" (limit &optional granularity mode structure))
(declare-function org-element--cache-active-p "org-element" ())
(declare-function org-toggle-custom-properties-visibility "org" ())
(declare-function org-item-re "org-list" ())
(declare-function org-up-heading-safe "org" ())
@ -189,7 +190,10 @@ smart Make point visible, and do insertion/deletion if it is
Never delete a previously invisible character or add in the
middle or right after an invisible region. Basically, this
allows insertion and backward-delete right before ellipses.
FIXME: maybe in this case we should not even show?"
FIXME: maybe in this case we should not even show?
This variable only affects commands listed in
`org-fold-catch-invisible-edits-commands'."
:group 'org-edit-structure
:version "24.1"
:type '(choice
@ -199,6 +203,33 @@ smart Make point visible, and do insertion/deletion if it is
(const :tag "Show invisible part and do the edit" show)
(const :tag "Be smart and do the right thing" smart)))
(defcustom org-fold-catch-invisible-edits-commands
;; We do not add non-Org commands here by default to avoid advising
;; globally. See `org-fold--advice-edit-commands'.
'((org-self-insert-command . insert)
(org-delete-backward-char . delete-backward)
(org-delete-char . delete)
(org-meta-return . insert)
(org-return . insert))
"Alist of commands where Org checks for invisible edits.
Each element is (COMMAND . KIND), where COMMAND is symbol representing
command as stored in `this-command' and KIND is symbol `insert',
symbol `delete', or symbol `delete-backward'.
The checks are performed around `point'.
This variable must be set before loading Org in order to take effect.
Also, see `org-fold-catch-invisible-edits'."
:group 'org-edit-structure
:package-version '("Org" . "9.7")
:type '(alist
:key-type symbol
:value-type (choice
(const insert)
(const delete)
(const delete-backward))))
;;; Core functionality
;;; API
@ -224,6 +255,7 @@ smart Make point visible, and do insertion/deletion if it is
(:ellipsis . ,ellipsis)
(:fragile . ,#'org-fold--reveal-outline-maybe)
(:isearch-open . t)
(:font-lock . t)
;; This is needed to make sure that inserting a
;; new planning line in folded heading is not
;; revealed. Also, the below combination of :front-sticky and
@ -236,6 +268,7 @@ smart Make point visible, and do insertion/deletion if it is
(:ellipsis . ,ellipsis)
(:fragile . ,#'org-fold--reveal-drawer-or-block-maybe)
(:isearch-open . t)
(:font-lock . t)
(:front-sticky . t)
(:alias . ( block center-block comment-block
dynamic-block example-block export-block
@ -245,6 +278,7 @@ smart Make point visible, and do insertion/deletion if it is
(:ellipsis . ,ellipsis)
(:fragile . ,#'org-fold--reveal-drawer-or-block-maybe)
(:isearch-open . t)
(:font-lock . t)
(:front-sticky . t)
(:alias . (drawer property-drawer)))
,org-link--description-folding-spec
@ -358,7 +392,7 @@ of the current heading, or to 1 if the current line is not a heading."
(interactive (list
(cond
(current-prefix-arg (prefix-numeric-value current-prefix-arg))
((save-excursion (beginning-of-line)
((save-excursion (forward-line 0)
(looking-at outline-regexp))
(funcall outline-level))
(t 1))))
@ -419,20 +453,21 @@ Show the heading too, if it is currently invisible."
(defun org-fold-show-children (&optional level)
"Show all direct subheadings of this heading.
Prefix arg LEVEL is how many levels below the current level
should be shown. Default is enough to cause the following
heading to appear."
Prefix arg LEVEL is how many levels below the current level should be
shown. If direct subheadings are deeper than LEVEL, they are still
displayed."
(interactive "p")
(unless (org-before-first-heading-p)
(save-excursion
(org-with-limited-levels (org-back-to-heading t))
(let* ((current-level (funcall outline-level))
(parent-level current-level)
(max-level (org-get-valid-level
current-level
parent-level
(if level (prefix-numeric-value level) 1)))
(min-level-direct-child most-positive-fixnum)
(end (save-excursion (org-end-of-subtree t t)))
(regexp-fmt "^\\*\\{%d,%s\\}\\(?: \\|$\\)")
(past-first-child nil)
;; Make sure to skip inlinetasks.
(re (format regexp-fmt
current-level
@ -448,11 +483,12 @@ heading to appear."
;; MAX-LEVEL. Since we want to display it anyway, adjust
;; MAX-LEVEL accordingly.
(while (re-search-forward re end t)
(unless past-first-child
(setq re (format regexp-fmt
current-level
(max (funcall outline-level) max-level)))
(setq past-first-child t))
(setq current-level (funcall outline-level))
(when (< current-level min-level-direct-child)
(setq min-level-direct-child current-level
re (format regexp-fmt
parent-level
(max min-level-direct-child max-level))))
(org-fold-heading nil))))))
(defun org-fold-show-subtree ()
@ -496,12 +532,12 @@ Return a non-nil value when toggling is successful."
comment-block dynamic-block example-block export-block
quote-block special-block src-block verse-block))
(_ (error "Unknown category: %S" category))))
(let* ((post (org-element-property :post-affiliated element))
(let* ((post (org-element-post-affiliated element))
(start (save-excursion
(goto-char post)
(line-end-position)))
(end (save-excursion
(goto-char (org-element-property :end element))
(goto-char (org-element-end element))
(skip-chars-backward " \t\n")
(line-end-position))))
;; Do nothing when not before or at the block opening line or
@ -560,10 +596,12 @@ Return a non-nil value when toggling is successful."
(interactive)
(org-block-map (apply-partially #'org-fold-hide-block-toggle 'hide)))
(defun org-fold-hide-drawer-all ()
"Fold all drawers in the current buffer."
(let ((begin (point-min))
(end (point-max)))
(defun org-fold-hide-drawer-all (&optional begin end)
"Fold all drawers in the current buffer or active region BEGIN..END."
(interactive (list (and (use-region-p) (region-beginning))
(and (use-region-p) (region-end))))
(let ((begin (or begin (point-min)))
(end (or end (point-max))))
(org-fold--hide-drawers begin end)))
(defun org-fold--hide-drawers (begin end)
@ -582,7 +620,7 @@ Return a non-nil value when toggling is successful."
;; Make sure to skip drawer entirely or we might flag it
;; another time when matching its ending line with
;; `org-drawer-regexp'.
(goto-char (org-element-property :end drawer))))))))
(goto-char (org-element-end drawer))))))))
(defun org-fold-hide-archived-subtrees (beg end)
"Re-hide all archived subtrees after a visibility state change."
@ -591,7 +629,7 @@ Return a non-nil value when toggling is successful."
(re (concat org-outline-regexp-bol ".*:" org-archive-tag ":")))
(goto-char beg)
;; Include headline point is currently on.
(beginning-of-line)
(forward-line 0)
(while (and (< (point) end) (re-search-forward re end t))
(when (member org-archive-tag (org-get-tags nil t))
(org-fold-subtree t)
@ -626,32 +664,33 @@ DETAIL is either nil, `minimal', `local', `ancestors',
(when (org-invisible-p)
;; FIXME: No clue why, but otherwise the following might not work.
(redisplay)
(let ((region (org-fold-get-region-at-point)))
;; Reveal emphasis markers.
(when (eq detail 'local)
(let (org-hide-emphasis-markers
org-link-descriptive
org-pretty-entities
(org-hide-macro-markers nil)
(region (or (org-find-text-property-region (point) 'org-emphasis)
(org-find-text-property-region (point) 'org-macro)
(org-find-text-property-region (point) 'invisible)
region)))
;; Silence byte-compiler.
(ignore org-hide-macro-markers)
(when region
(org-with-point-at (car region)
(beginning-of-line)
(let (font-lock-extend-region-functions)
(font-lock-fontify-region (max (point-min) (1- (car region))) (cdr region))))))
;; Unfold links.
;; Reveal emphasis markers.
(when (eq detail 'local)
(let (org-hide-emphasis-markers
org-link-descriptive
org-pretty-entities
(org-hide-macro-markers nil)
(region (or (org-find-text-property-region (point) 'org-emphasis)
(org-find-text-property-region (point) 'org-macro)
(org-find-text-property-region (point) 'invisible))))
;; Silence byte-compiler.
(ignore org-hide-macro-markers)
(when region
(dolist (spec '(org-link org-link-description))
(org-fold-region (car region) (cdr region) nil spec))))
(when region
(dolist (spec (org-fold-core-folding-spec-list))
;; Links are taken care by above.
(unless (memq spec '(org-link org-link-description))
(org-with-point-at (car region)
(forward-line 0)
(let (font-lock-extend-region-functions)
(font-lock-fontify-region (max (point-min) (1- (car region))) (cdr region))))))
;; Unfold links.
(let (region)
(dolist (spec '(org-link org-link-description))
(setq region (org-fold-get-region-at-point spec))
(when region (org-fold-region (car region) (cdr region) nil spec)))))
(let (region)
(dolist (spec (org-fold-core-folding-spec-list))
;; Links are taken care by above.
(unless (memq spec '(org-link org-link-description))
(setq region (org-fold-get-region-at-point spec))
(when region
(org-fold-region (car region) (cdr region) nil spec))))))
(unless (org-before-first-heading-p)
(org-with-limited-levels
@ -697,9 +736,10 @@ go to the parent and show the entire tree."
;;; Make isearch search in some text hidden via text properties.
(defun org-fold--isearch-reveal (&rest _)
(defun org-fold--isearch-reveal (pos)
"Reveal text at POS found by isearch."
(org-fold-show-context 'isearch))
(org-with-point-at pos
(org-fold-show-context 'isearch)))
;;; Handling changes in folded elements
@ -724,7 +764,7 @@ the contents consists of blank lines.
Assume that point is located at the header line."
(org-with-wide-buffer
(beginning-of-line)
(forward-line 0)
(org-fold-region
(max (point-min) (1- (point)))
(let ((endl (line-end-position)))
@ -735,7 +775,7 @@ Assume that point is located at the header line."
(if (equal (point)
(save-excursion
(goto-char endl)
(org-end-of-subtree)
(org-end-of-subtree t)
(skip-chars-forward "\n\t\r ")))
(point)
endl)))
@ -752,7 +792,7 @@ This function is intended to be used as :fragile property of
;; The line before beginning of the fold should be either a
;; headline or a list item.
(backward-char)
(beginning-of-line)
(forward-line 0)
;; Make sure that headline is not partially hidden.
(unless (org-fold-folded-p nil 'headline)
(org-fold--reveal-headline-at-point))
@ -764,14 +804,14 @@ This function is intended to be used as :fragile property of
(org-fold--reveal-headline-at-point))))
;; Make sure that headline after is not partially hidden.
(goto-char (cdr region))
(beginning-of-line)
(forward-line 0)
(unless (org-fold-folded-p nil 'headline)
(when (looking-at-p org-element-headline-re)
(org-fold--reveal-headline-at-point)))
;; Check the validity of headline
(goto-char (car region))
(backward-char)
(beginning-of-line)
(forward-line 0)
(unless (let ((case-fold-search t))
(looking-at (rx-to-string
`(or (regex ,(org-item-re))
@ -807,7 +847,7 @@ This function is intended to be used as :fragile property of
;; The line before beginning of the fold should be the
;; first line of the drawer/block.
(backward-char)
(beginning-of-line)
(forward-line 0)
(unless (let ((case-fold-search t))
(looking-at begin-re)) ; the match-data will be used later
(throw :exit (setq unfold? t))))
@ -827,7 +867,7 @@ This function is intended to be used as :fragile property of
;; The last line of the folded text should match `end-re'.
(save-excursion
(goto-char fold-end)
(beginning-of-line)
(forward-line 0)
(unless (let ((case-fold-search t))
(looking-at end-re))
(throw :exit (setq unfold? t))))
@ -901,6 +941,19 @@ The detailed reaction depends on the user option
;; Don't do the edit, make the user repeat it in full visibility
(user-error "Edit in invisible region aborted, repeat to confirm with text visible"))))))))
(defun org-fold-check-before-invisible-edit-maybe (&rest _)
"Check before invisible command by `this-command'."
(when (derived-mode-p 'org-mode)
(pcase (alist-get this-command org-fold-catch-invisible-edits-commands)
((pred null) nil)
(kind (org-fold-check-before-invisible-edit kind)))))
(defun org-fold--advice-edit-commands ()
"Advice editing commands according to `org-fold-catch-invisible-edits-commands'.
The advices are installed in current buffer."
(dolist (command (mapcar #'car org-fold-catch-invisible-edits-commands))
(advice-add command :before #'org-fold-check-before-invisible-edit-maybe)))
(provide 'org-fold)
;;; org-fold.el ends here

View File

@ -1,6 +1,6 @@
;;; org-footnote.el --- Footnote support in Org -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2009-2023 Free Software Foundation, Inc.
;; Copyright (C) 2009-2024 Free Software Foundation, Inc.
;;
;; Author: Carsten Dominik <carsten.dominik@gmail.com>
;; Keywords: outlines, hypermedia, calendar, wp
@ -45,9 +45,10 @@
(declare-function org-element-at-point "org-element" (&optional pom cached-only))
(declare-function org-element-class "org-element" (datum &optional parent))
(declare-function org-element-context "org-element" (&optional element))
(declare-function org-element-lineage "org-element" (blob &optional types with-self))
(declare-function org-element-property "org-element" (property element))
(declare-function org-element-type "org-element" (element))
(declare-function org-element-lineage "org-element-ast" (blob &optional types with-self))
(declare-function org-element-property "org-element-ast" (property node))
(declare-function org-element-type "org-element-ast" (node &optional anonymous))
(declare-function org-element-type-p "org-element-ast" (node types))
(declare-function org-end-of-subtree "org" (&optional invisible-ok to-heading))
(declare-function org-fill-paragraph "org" (&optional justify region))
(declare-function org-in-block-p "org" (names))
@ -136,6 +137,7 @@ Possible values are:
nil Prompt the user for each label.
t Create unique labels of the form [fn:1], [fn:2], etc.
anonymous Create anonymous footnotes
confirm Like t, but let the user edit the created value.
The label can be removed from the minibuffer to create
an anonymous footnote.
@ -145,6 +147,7 @@ random Automatically generate a unique, random label."
(const :tag "Prompt for label" nil)
(const :tag "Create automatic [fn:N]" t)
(const :tag "Offer automatic [fn:N] for editing" confirm)
(const :tag "Create anoymous [fn::]" anonymous)
(const :tag "Create a random label" random))
:safe #'symbolp)
@ -183,21 +186,21 @@ extracted will be filled again."
"Is point in a context where footnotes are allowed?"
(save-match-data
(not (or (org-at-comment-p)
(org-inside-LaTeX-fragment-p)
;; Avoid literal example.
(org-in-verbatim-emphasis)
(save-excursion
(beginning-of-line)
(looking-at "[ \t]*:[ \t]+"))
;; Avoid forbidden blocks.
(org-in-block-p org-footnote-forbidden-blocks)))))
(org-inside-LaTeX-fragment-p)
;; Avoid literal example.
(org-in-verbatim-emphasis)
(save-excursion
(forward-line 0)
(looking-at "[ \t]*:[ \t]+"))
;; Avoid forbidden blocks.
(org-in-block-p org-footnote-forbidden-blocks)))))
(defun org-footnote-at-reference-p ()
"Non-nil if point is at a footnote reference.
If so, return a list containing its label, beginning and ending
positions, and the definition, when inline."
(let ((reference (org-element-context)))
(when (eq 'footnote-reference (org-element-type reference))
(when (org-element-type-p reference 'footnote-reference)
(let ((end (save-excursion
(goto-char (org-element-property :end reference))
(skip-chars-backward " \t")
@ -223,7 +226,7 @@ defined locally.
The return value is nil if not at a footnote definition, and
a list with label, start, end and definition of the footnote
otherwise."
(pcase (org-element-lineage (org-element-at-point) '(footnote-definition) t)
(pcase (org-element-lineage (org-element-at-point) 'footnote-definition t)
(`nil nil)
(definition
(let* ((label (org-element-property :label definition))
@ -269,7 +272,7 @@ otherwise."
((memq type '(headline inlinetask))
(or (not (org-at-heading-p))
(and (save-excursion
(beginning-of-line)
(forward-line 0)
(and (let ((case-fold-search t))
(not (looking-at-p "\\*+ END[ \t]*$")))
(let ((case-fold-search nil))
@ -281,10 +284,10 @@ otherwise."
;; White spaces after an object or blank lines after an element
;; are OK.
((>= (point)
(save-excursion (goto-char (org-element-property :end context))
(skip-chars-backward " \r\t\n")
(if (eq (org-element-class context) 'object) (point)
(line-beginning-position 2)))))
(save-excursion (goto-char (org-element-property :end context))
(skip-chars-backward " \r\t\n")
(if (eq (org-element-class context) 'object) (point)
(line-beginning-position 2)))))
;; At the beginning of a footnote definition, right after the
;; label, is OK.
((eq type 'footnote-definition) (looking-at (rx space)))
@ -298,7 +301,7 @@ otherwise."
;; :contents-begin is not reliable on empty cells, so special
;; case it.
(<= (save-excursion (skip-chars-backward " \t") (point))
(org-element-property :contents-end context)))
(org-element-property :contents-end context)))
((let ((cbeg (org-element-property :contents-begin context))
(cend (org-element-property :contents-end context)))
(and cbeg (>= (point) cbeg) (<= (point) cend))))))))
@ -368,14 +371,14 @@ References are sorted according to a deep-reading order."
;; Ensure point is within the reference before parsing it.
(backward-char)
(let ((object (org-element-context)))
(when (eq (org-element-type object) 'footnote-reference)
(when (org-element-type-p object 'footnote-reference)
(let* ((label (org-element-property :label object))
(begin (org-element-property :begin object))
(size
(and (eq (org-element-property :type object) 'inline)
(- (org-element-property :contents-end object)
(org-element-property :contents-begin object)))))
(let ((d (org-element-lineage object '(footnote-definition))))
(let ((d (org-element-lineage object 'footnote-definition)))
(push (list label (copy-marker begin) (not d) size)
references)
(when d
@ -420,7 +423,7 @@ while collecting them."
(backward-char)
(let ((element (org-element-at-point)))
(let ((label (org-element-property :label element)))
(when (and (eq (org-element-type element) 'footnote-definition)
(when (and (org-element-type-p element 'footnote-definition)
(not (member label seen)))
(push label seen)
(let* ((beg (progn
@ -516,7 +519,7 @@ This function is meant to be used for fontification only."
;; Definition: also grab the last square bracket, matched in
;; `org-footnote-re' for non-inline footnotes.
((and (save-excursion
(beginning-of-line)
(forward-line 0)
(save-match-data (org-footnote-in-valid-context-p)))
(save-excursion
(end-of-line)
@ -633,8 +636,8 @@ This function ignores narrowing, if any."
(while (re-search-forward org-footnote-re nil t)
(backward-char)
(let ((context (org-element-context)))
(when (memq (org-element-type context)
'(footnote-definition footnote-reference))
(when (org-element-type-p
context '(footnote-definition footnote-reference))
(let ((label (org-element-property :label context)))
(when label (cl-pushnew label all :test #'equal))))))
all)))
@ -665,15 +668,16 @@ or new, let the user edit the definition of the footnote."
(user-error "Cannot insert a footnote here"))
(let* ((all (org-footnote-all-labels))
(label
(if (eq org-footnote-auto-label 'random)
(format "%x" (abs (random)))
(org-footnote-normalize-label
(let ((propose (org-footnote-unique-label all)))
(if (eq org-footnote-auto-label t) propose
(completing-read
"Label (leave empty for anonymous): "
(mapcar #'list all) nil nil
(and (eq org-footnote-auto-label 'confirm) propose))))))))
(unless (eq org-footnote-auto-label 'anonymous)
(if (eq org-footnote-auto-label 'random)
(format "%x" (abs (random)))
(org-footnote-normalize-label
(let ((propose (org-footnote-unique-label all)))
(if (eq org-footnote-auto-label t) propose
(completing-read
"Label (leave empty for anonymous): "
(mapcar #'list all) nil nil
(and (eq org-footnote-auto-label 'confirm) propose)))))))))
(cond ((not label)
(insert "[fn::]")
(backward-char 1))

View File

@ -1,6 +1,6 @@
;;; org-goto.el --- Fast navigation in an Org buffer -*- lexical-binding: t; -*-
;; Copyright (C) 2012-2023 Free Software Foundation, Inc.
;; Copyright (C) 2012-2024 Free Software Foundation, Inc.
;; Author: Carsten Dominik <carsten.dominik@gmail.com>
;; Keywords: outlines, hypermedia, calendar, wp
@ -102,7 +102,11 @@ When nil, you can use these keybindings to navigate the buffer:
mouse-drag-region universal-argument org-occur)))
(dolist (cmd cmds)
(substitute-key-definition cmd cmd map global-map)))
(suppress-keymap map)
(if org-goto-auto-isearch
;; Suppress 0-9 interpreted as digital arguments.
;; Make them initiate isearch instead.
(suppress-keymap map t)
(suppress-keymap map))
(org-defkey map "\C-m" 'org-goto-ret)
(org-defkey map [(return)] 'org-goto-ret)
(org-defkey map [(left)] 'org-goto-left)
@ -145,7 +149,7 @@ When nil, you can use these keybindings to navigate the buffer:
(search-backward string bound noerror))
(when (save-match-data
(and (save-excursion
(beginning-of-line)
(forward-line 0)
(looking-at org-complex-heading-regexp))
(or (not (match-beginning 5))
(< (point) (match-beginning 5)))))
@ -172,7 +176,7 @@ When nil, you can use these keybindings to navigate the buffer:
(interactive)
(if (org-at-heading-p)
(progn
(beginning-of-line 1)
(forward-line 0)
(setq org-goto-selected-point (point)
org-goto-exit-command 'left)
(throw 'exit nil))
@ -211,12 +215,12 @@ position or nil."
(help (or help org-goto-help)))
(save-excursion
(save-window-excursion
(delete-other-windows)
(and (get-buffer "*org-goto*") (kill-buffer "*org-goto*"))
(pop-to-buffer-same-window
(condition-case nil
(pop-to-buffer
(condition-case nil
(make-indirect-buffer (current-buffer) "*org-goto*" t)
(error (make-indirect-buffer (current-buffer) "*org-goto*" t))))
(error (make-indirect-buffer (current-buffer) "*org-goto*" t)))
'(org-display-buffer-full-frame))
(let (temp-buffer-show-function temp-buffer-show-hook)
(with-output-to-temp-buffer "*Org Help*"
(princ (format help (if org-goto-auto-isearch
@ -234,8 +238,10 @@ position or nil."
(let (org-special-ctrl-a/e) (org-beginning-of-line))
(message "Select location and press RET")
(use-local-map org-goto-map)
(recursive-edit)))
(kill-buffer "*org-goto*")
(unwind-protect (recursive-edit)
(when-let ((window (get-buffer-window "*Org Help*" t)))
(quit-window 'kill window)))))
(when (get-buffer "*org-goto*") (kill-buffer "*org-goto*"))
(cons org-goto-selected-point org-goto-exit-command)))
;;;###autoload

Some files were not shown because too many files have changed in this diff Show More