Commit Graph

261 Commits

Author SHA1 Message Date
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 421b443483
org-babel-tangle-single-block: Fix compiler warning
* lisp/ob-tangle.el (org-outline-regexp): Declare variable.
2023-06-24 15:34:22 +03:00
Ihor Radchenko f56ca5009e
fixup! org-babel-tangle-single-block: Do not rely on match-data from `org-back-to-heading' 2023-06-24 15:32:40 +03:00
Ihor Radchenko 79ec91584c
org-babel-tangle-single-block: Do not rely on match-data from `org-back-to-heading'
* lisp/ob-tangle.el (org-babel-tangle-single-block): Explicitly move
to the beginning of title instead of assuming that
`org-back-to-heading' sets match data appropriately (it is not
documented to do so).
* testing/lisp/test-ob-tangle.el (ob-tangle/comment-org): Add test.

Reported-by: Nick Dokos <ndokos@redhat.com>
Link: https://orgmode.org/list/87bkh8k3at.fsf@alphaville.usersys.redhat.com
2023-06-22 12:54:23 +03:00
TEC 6a96054f05
ob-tangle: Edit default file mode to match docstr
* lisp/ob-tangle.el (org-babel-tangle-default-file-mode): The docstring
states that it the default value is read-write for the user, read only
for everyone else.  This is not consistent with the default value which
is actually read-*execute* for the user, read only for everyone else.
The default value is updated to be read-write for the user, as stated in
the docstring.

Reported-by: Ruijie Yu <ruijie@netyu.xyz>
Link: https://list.orgmode.org/orgmode/sdv3554xtat.fsf@fw.net.yu
2023-04-13 08:59:47 +02:00
TEC 81fc8c06ce
ob-tangle: Fix interpretation of rw-r--r-- modes
* lisp/ob-tangle.el (org-babel-interpret-file-mode): When specifying a
file mode in the "rw-r--r--" style, this is interpreted by splicing the
user, group, and other compenents into a "u=rw,g=r,o=r" style string and
applying `file-modes-symbolic-to-number`.  For correct interpretation,
we need to ensure the dashes are removed in this process.
2023-04-13 08:59:27 +02:00
Eli Zaretskii e0815d7545 Backport commit cae528457 from Emacs
; Add 2023 to copyright years.
cae528457cb862dc886a34240c9d4c73035b6659
Eli Zaretskii
Sun Jan 1 05:31:12 2023 -0500
2023-01-01 12:44:47 -05:00
Tom Gillespie a8c9f11757
Fix missing null check for tangle links during export
* lisp/ob-tangle.el (org-babel-tangle--unbracketed-link): Add the let
bound variable l to the and statement to prevent l from being passed
to `string-match' in the event that it is nil.

When tangling nested noweb blocks during export it is possible for the
results of `org-store-link' to return nil.  This commit ensures that
the value returned for l is only passed to `string-match' when it is
non-nil, avoiding a `wrong-type-argument' (stringp nil) error.

Handling of comments and nesting of babel blocks is known to have
issues.  The bug is from 8a781d35dc
where new code was introduced to obtain the value for bare which was
not present in early code.  I'm guessing that the bug appears now
because `string-match' is called on l (aka link) at a point in time
when it was never previously called and it was thus masked because in
the old version it was impossible to call `string-match' when `link'
was nil because another variable was always nil, masking the issue.
2022-12-21 15:40:27 +03:00
Stefan Kangas c8ad9e4b28 Backport commit 8617edfff from Emacs
; Fix typos
8617edfffd07eb80561b4de6a37c5b0b5f442e07
Stefan Kangas
Wed Nov 30 16:59:41 2022 +0100
2022-11-30 17:19:12 -05:00
Kyrylo Simonov 00778ce2a6
Fix missing customization groups
* lisp/ob-tangle.el (org-babel-tangle): Add missing group definition.
(org-babel-post-tangle-hook):
(org-babel-pre-tangle-hook):
(org-babel-tangle-body-hook):
(org-babel-tangle-finished-hook):
(org-babel-tangle-comment-format-beg):
(org-babel-tangle-comment-format-end):
(org-babel-tangle-uncomment-comments):
(org-babel-process-comment-text):
(org-babel-tangle-default-file-mode): Move under `org-babel-tangle'
group.
* lisp/ol-bbdb.el (org-bbdb-anniversaries): Move under `org-agenda'
instead of a non-existent `org-bbdb'.
* lisp/ol-bibtex.el (org-bibtex): Add missing group definition.
* lisp/ol-gnus.el (org-gnus-no-server): Move under group
`org-link-follow' instead of a non-existent `org-gnus'.
* lisp/org-plot.el (org-plot): Add missing group definition.
* lisp/org.el (org-startup): Add missing group definition.
* lisp/ox-latex.el (org-latex-pdf-process): Move under
`org-export-latex' instead of a non-existent `org-export-pdf'.
* lisp/ox-man.el (org-man-pdf-process): Remove reference to
non-existent group `org-export-pdf'.

TINYCHANGE
2022-11-16 09:59:44 +08:00
Ihor Radchenko 51bb222260
ob-tangle: Update docstrings
* lisp/ob-tangle.el (org-babel-tangle-file):
* lisp/ob-tangle.el (org-babel-tangle): Clarify return values.
2022-11-10 13:36:01 +08:00
Daniel Ziltener 5e0c5c186d
org-babel: Add new "strip-tangle" :noweb argument value
* lisp/ob-tangle.el (org-babel-tangle-single-block): Strip noweb tags
from block if :noweb has been set to "strip-tangle".
* lisp/ob-core.el (org-babel-common-header-args-w-values): Add
"strip-tangle" as new allowed value.
* lisp/ob-core.el (org-babel-noweb-p): Add "strip-tangle" at the
appropriate positions.
* testing/lisp/test-ob-tangle.el (ob-tangle/strip-tangle): Add new test
case for "strip-tangle".
* doc/org-manual.org (Noweb Reference Syntax): Adjust documentation for
the noweb header argument.
* etc/ORG-NEWS: Add entry for new header argument value.

This patch adds the "strip-tangle" option for the :noweb header
argument.  This strips the noweb tags before tangling the block.  This can
be useful for e.g. testing purposes where one wants to use a block as
test case that can be both run inline as well as tangled into a file for
automated testing.

TINYCHANGE
2022-11-07 10:54:13 +08:00
fpi e58bd039e3
org-babel-get-src-block-info: Rename light argument
* lisp/ob-core.el (org-babel-get-src-block-info): Rename argument
light to no-eval.
2022-10-19 14:55:53 +08:00
TEC 6a82d17c89
ob-tangle: New tangle-finished hook
* lisp/ob-tangle.el (org-babel-tangle, org-babel-tangle-finished-hook):
Create a new hook, `org-babel-tangle-finished-hook', and run it at the
end of `org-babel-tangle'.
(org-babel-pre-tangle-hook): Update docstring to mention buffer the hook
is run in, to match the docstring of `org-babel-tangle-finished-hook`.
2022-09-23 20:14:52 +08:00
Ihor Radchenko e81a094383
Assert all the Org files to load the same Org version
* lisp/org-compat.el (org-assert-version): New macro comparing Org
version at compile time and laod time.

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

* lisp/org-macs.el:
* lisp/org-crypt.el:
* lisp/org-ctags.el:
* lisp/org-cycle.el:
* lisp/org-datetree.el:
* lisp/org-duration.el:
* lisp/org-element.el (avl-tree):
* lisp/org-entities.el:
* lisp/org-faces.el:
* lisp/org-feed.el:
* lisp/org-fold-core.el:
* lisp/org-fold.el:
* lisp/org-footnote.el:
* lisp/org-goto.el:
* lisp/org-habit.el:
* lisp/org-id.el:
* lisp/org-indent.el:
* lisp/org-inlinetask.el:
* lisp/org-keys.el:
* lisp/org-lint.el:
* lisp/org-list.el:
* lisp/org-macro.el:
* lisp/org-mobile.el:
* lisp/org-mouse.el:
* lisp/org-num.el:
* lisp/org-pcomplete.el:
* lisp/org-persist.el:
* lisp/org-plot.el:
* lisp/org-protocol.el:
* lisp/org-refile.el:
* lisp/org-src.el:
* lisp/org-table.el:
* lisp/org-tempo.el:
* lisp/org-timer.el:
* lisp/org.el:
* lisp/ox-ascii.el:
* lisp/ox-beamer.el:
* lisp/ox-html.el:
* lisp/ox-icalendar.el:
* lisp/ox-koma-letter.el:
* lisp/ox-latex.el:
* lisp/ox-man.el:
* lisp/ox-md.el:
* lisp/ox-odt.el:
* lisp/ox-org.el:
* lisp/ox-publish.el:
* lisp/ox-texinfo.el:
* lisp/ox.el:
2022-09-04 12:24:55 +08:00
Hraban Luyat 8a781d35dc
ob-tangle.el: fix ‘:comments noweb’ double linking
* lisp/ob-tangle.el: Refactor the double implementation to a single
helper function.  This avoids the double link wrapping.

* testing/lisp/test-ob-tangle.el: Add unit tests.

Babel tangle allows inserting comments at the tangled site which link
back to the source in the org file.  This linking was implemented
twice, to handle separate cases, but when using ‘:comments noweb’ it
ended up going through both codepaths.  This resulted in doubly
wrapped links.

By refactoring all link generation into a single function, this double
wrapping is avoided.

Example file, /tmp/test.org:

    * Inner
    #+name: inner
    #+begin_src emacs-lisp
    2
    #+end_src

    * Main
    #+header: :tangle test.el :comments noweb :noweb yes
    #+begin_src emacs-lisp
    1
    <<inner>>
    #+end_src

Before:

    ;; [[file:test.org::*Main][Main:1]]
    1
    ;; [[[[file:/tmp/test.org::inner][inner]]][inner]]
    2
    ;; inner ends here
    ;; Main:1 ends here

After:

    ;; [[file:test.org::*Main][Main:1]]
    1
    ;; [[file:test.org::inner][inner]]
    2
    ;; inner ends here
    ;; Main:1 ends here
2022-08-13 14:39:09 +08:00
Ihor Radchenko 0d3bf2ed49
org-babel-tangle-single-block: Do not create comment link when not requested
* lisp/ob-tangle.el (org-babel-tangle-single-block): Do not spend
extra time creating link to source block when :comments is set to
"no".
2022-07-31 14:22:11 +08:00
Ihor Radchenko 6c1e3dfa28
Merge branch 'bugfix' 2022-07-23 10:14:01 +08:00
Ihor Radchenko c779b7aa0e
org-babel-detangle: Fix :comments link for src blocks before first heading
* lisp/ob-tangle.el (org-babel-tangle-jump-to-org): Allow fuzzy
matching when following the backlink to src block from tangles
source.  The current default value of
`org-link-search-must-match-exact-headline` makes
`org-link-open-from-string` treat fuzzy links as headlines without
falling back to fuzzy text search.  Bind it to nil to force fuzzy text
matching while detangling.

Fixes https://orgmode.org/list/87zgh1qxfk.fsf@posteo.net
2022-07-23 10:10:24 +08:00
Stefan Kangas 13d97ee18c
Prefer "website" to "homepage"
Emacs now advises using "website" (instead of "homepage") and
consequently to use the "URL" comment header instead of "Homepage".

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

* lisp/*.el:
* mk/org-fixup.el: Replace the "Homepage" header comment with "URL".
2022-06-26 10:10:48 +08:00
Ihor Radchenko f6f26d4ce4
org-babel-tangle: Do not overwrite when contents does not change
* lisp/ob-tangle.el (org-babel-tangle): Do not overwrite existing
tangled files if their contents is exactly the same as we are going to
write during tangle process.  This avoids unneeded disk writes and can
speed up tangling significantly when many small files are tangled from
a single .org source.

An example of performance improvement when tangling an .org file into
~200 files:
(benchmark-run 10 (org-babel-tangle))
Before the commit (on SSD): (76.33826743 8 11.551725374)
After the commit:           (43.628606052 4 5.751274237)
2022-05-30 11:02:07 +08:00
Jacopo De Simoi 2bd34edb64
ob-tangle.el: Handle non-string arguments more gracefully
* lisp/ob-tangle.el (org-babel-tangle-single-block): If the
  argument to :tangle is nil (e.g. when parsing conditional
  tangling such as (when condition "yes") the current code
  throws an error in `file-name-directory'.  This commit
  checks if the argument is a string before calling the fun

TINYCHANGE
2022-05-01 11:36:04 +08:00
Ihor Radchenko 7f6b6e4891
Merge branch 'bugfix' 2022-01-30 16:52:15 +08:00
Ihor Radchenko dd6486a070
Make sure that declarative defvars do not set variable value
* lisp/ob-tangle.el (org-id-link-to-org-use-id):
* lisp/org-agenda.el (org-agenda-overriding-header): Do not try set
value of a variable defined elsewhere.  This may interfere with custom
interface.  See
https://list.orgmode.org/orgmode/871r19ryxb.fsf@localhost/

(org-agenda-restrict):
* lisp/ol-bibtex.el (org-bibtex-description): Remove incorrect
comments.
2022-01-30 16:46:12 +08:00
Ihor Radchenko 2ae8d6c1cf
org-babel-tangle-collect-blocks: Use cache
* lisp/ob-tangle.el (org-babel-tangle-collect-blocks): Use element
cache to find the containing headline instead of regexp search.
Direct regexp search sometimes causes quadratic scaling.

See https://lists.gnu.org/r/emacs-orgmode/2022-01/msg00484.html
2022-01-26 19:27:03 +08:00
Mark A. Hershberger 1537bb4029
Fix signature for org-element-at-point 2022-01-12 22:26:10 +08:00
Kyle Meyer aae2ac3a68 Merge branch 'bugfix' 2022-01-01 15:21:37 -05:00
Kyle Meyer 5a229cbc44 Update copyright year to 2022 2022-01-01 15:17:08 -05:00
Kyle Meyer e26b825e6e Merge branch 'bugfix' 2021-12-18 13:21:14 -05:00
Kyle Meyer a18849b786 org-babel-tangle-file: Revert recent change in return value
* lisp/ob-tangle.el (org-babel-tangle-file): Restore the recently
removed prog1 so that the return value matches the documented one.
2021-12-18 13:20:45 -05:00
Kyle Meyer f4e72ffcd4 org-babel-tangle-file: Fix void variable error from last commit
* lisp/ob-tangle.el (org-babel-tangle-file): Switch let to let* to fix
void variable error.
2021-12-18 13:16:26 -05:00
Nicolas Goaziou 2b7ea20346 Merge branch 'bugfix' 2021-12-18 15:41:13 +01:00
Nicolas Goaziou aabcf9edf2 ob-tangle: Ignore narrowing when tangling a file
* lisp/ob-tangle.el (org-babel-tangle-file): Ignore narrowing in
a buffer visiting the file being tangled.
2021-12-18 15:40:25 +01:00
TEC 9ce7802b79
ob-tangle: allow ls -l style suid/sgid tangle mode
* lisp/ob-tangle.el (org-babel-interpret-file-mode): Modify the regexp
for the ls -l style tangle file mode to allow for the suid/sgid bits to
be set.  While I was at it I noticed that the a= parameter should have
been o=, and so that has been fixed too.

The sticky bit is ignored, but that is not a concern as it is only
relevant to directories.
2021-11-30 02:48:03 +08:00
Kyle Meyer 27edae8ced tangle: Fix :version keyword of org-babel-tangle-default-file-mode
* lisp/ob-tangle.el (org-babel-tangle-default-file-mode): Prefer
":package-version" to ":version".

The :version keyword should correspond to the Emacs version.  Using
the Org version leads to an incorrect help message:

  This variable was introduced, or its default value was changed, in
  version 9.6 of Emacs.

Instead go through :package-version so that the displayed message is

  This variable was introduced, or its default value was changed, in
  version 9.6 of the Org package that is part of Emacs 29.1.
2021-11-20 14:36:21 -05:00
TEC e6ae351f96
ob-tangle: Rename org-babel-tangle-default-mode
* lisp/ob-tangle.el (org-babel-tangle-default-mode,
org-babel-interpret-file-mode): Rename `org-babel-tangle-default-mode`
to the slightly more apt `org-babel-tangle-default-file-mode`, and
update `org-babel-interpret-file-mode` accordingly.
2021-11-21 03:06:19 +08:00
TEC 048f478799
ob-tangle: Make ls-style file mode regex stricter
* lisp/ob-tangle (org-babel-interpret-file-mode): Instead of allowing 9
characters from [rwx-], require [r-][w-][x-] repeated thrice.  This no
longer allows invalid ls-style file modes.
2021-11-20 22:57:20 +08:00
TEC ff6fd93876
ob-tangle: Check that integer file modes are valid
* lisp/ob-tangle.el (org-babel-interpret-file-mode): Check that the
integer as an octal represents a valid file mode, and complain
otherwise.
2021-11-20 22:57:20 +08:00
TEC 3a6686010e
ob-tangle: Use oXXX as file mode octal shorthand
* lisp/ob-tangle (org-babel-interpret-file-mode): Accept "o755" and
similar as octal shorthand. A non-digit character must be included as
otherwise `org-babel-parse-header-arguments' will convert it to a
base-10 integer.
2021-11-20 22:57:20 +08:00
TEC fa97f9a395
ob-tangle: Accept more :tangle-mode forms
* lisp/ob-tangle.el (org-babel-tangle): Accept many more forms for
:tangle-mode, including octal strings (#o755, 0755, 755), ls forms (rwx,
rw-r--r--), and chmod forms (a=rw,u+x).  The interpretation of the input
is now handled by the new function `org-babel-interpret-file-mode' which
references the new variable `org-babel-tangle-default-mode' when
considering relative mode forms.
2021-11-18 18:18:00 +08:00
Bastien 578d99b2aa lisp/ob-tangle.el: Add variable declaration
This completes commit 0b4e357d6.
2021-09-26 14:34:41 +02:00
Bastien 46511212e9 Merge branch 'bugfix' 2021-09-26 08:59:43 +02:00
Ihor Radchenko 0b4e357d62 Avoid creating ID property during tangling
* lisp/ob-tangle.el (org-babel-tangle-single-block,
org-babel-tangle-comment-links): Suppress org-id-link-to-org-use-id
during tangling.  The links used during tangle process are transient
and do not really need to use ID.  Using ID may create unexpected
edits in the tangled Org buffer when org-id-link-to-org-use-id is set
to t.  Fixes [1].

[1] https://orgmode.org/list/9eb31da73b12fcaf6820484834cc8cd3@libre.brussels/T/#t
2021-09-26 08:59:24 +02:00
Mark Dawson ef31364bc8
ob-tangle: Fix incorrect buff name in org-src edit
* lisp/ob-tangle.el (org-babel-tangle): Fix stringp error which happens
when confirming successful tangle when `org-babel-tangle' is called from
an org-src edit buffer.

TINYCHANGE
2021-09-19 20:58:49 +08:00
Stefan Kangas 51cdd6e30f Various minor docfixes found by checkdoc 2021-09-16 21:24:59 +02:00
Jacopo De Simoi 221c8e298f ob-tangle: Parse correctly tangle options
* lisp/ob-tangle.el (org-babel-effective-tangled-filename): Check for
  the "no" parameter in this function to avoid erroneous tangling of a
  single block (e.g. with C-u C-c C-v t) even with the parameter
  :tangle no

TINYCHANGE
2021-07-01 15:42:29 +02:00
Sébastien Miquel 6e5b39acd1 ob-tangle.el: Fix single block tangle
lisp/ob-tangle.el (org-babel-tangle-single-block): Fix the result when
`only-this-block' is `t' to match what is expected by
`org-babel-tangle'.
(org-babel-effective-tangled-filename): Extract the
computation of filename of tangled src block.
(org-babel-tangle-collect-blocks): Use `org-babel-effective-tangled-filename'.
2021-05-06 13:37:18 +02:00
Sébastien Miquel 501b2a191c ob-tangle.el: (org-babel-tangle-collect-blocks): Use correct tangle name
* lisp/ob-tangle.el: (org-babel-tangle-collect-blocks): Use correct
tangle name.

The :tangle header argument might be some elisp, to be evaluated.
2021-05-05 09:03:45 +02:00
Sébastien Miquel d59f35fbb7 ob-tangle.el (org-babel-tangle): Fix readonly tangle
* lisp/ob-tangle.el (org-babel-tangle): Fix readonly tangle.
2021-05-05 08:42:46 +02:00
Sébastien Miquel a2cb9b853d ob-tangle.el: Improve tangling
* lisp/ob-tangle.el (org-babel-tangle-collect-blocks): Group
collected blocks by tangled file name.
(org-babel-tangle): Avoid quadratic behavior in number of blocks and
set modes before writing to file.
* testing/lisp/test-ob-tangle.el (ob-tangle/block-order): Update test.
2021-05-01 22:30:42 +02:00