Commit Graph

249 Commits

Author SHA1 Message Date
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
Nicolas Goaziou 80bce047ff Merge branch 'maint' 2021-04-10 00:03:31 +02:00
Tom Gillespie b523ad491d ob-tangle.el: Fix coderef removal during tangling
* lisp/ob-tangle.el (orb-babel-tangle-single-block): Regularize
behavior when removing coderefs during tangling. This fixes an issue
where trailing whitespace would be retained when coderefs were removed
for tangling.
2021-04-10 00:01:49 +02:00
Stefan Monnier 7dd1cfb6ca Backport commit f8dbefbaa from Emacs
* lisp/ob-comint.el (org-babel-comint-in-buffer)
(org-babel-comint-with-output): Use `declare`.

* lisp/ob-core.el (org-babel-map-src-blocks): Use `declare`.
(org-babel-result-cond): Simplify edebug spec.

* lisp/org-clock.el (org-with-clock-position, org-with-clock):
* lisp/org-agenda.el (org-agenda-with-point-at-orig-entry):
* lisp/ob-tangle.el (org-babel-with-temp-filebuffer): Use `declare`.

Use `declare` instead of `def-edebug-spec` in most places
f8dbefbaa59bb17dd4a2dfa4d9ff560c46785792
Stefan Monnier
Fri Feb 12 16:08:01 2021 -0500
2021-02-14 17:38:07 -05:00
Kyle Meyer 99eafe3787 Update copyright year to 2021 2021-01-01 14:59:01 -05:00
Bastien 9f0af69dd2 Skip archived headings when tangling and exporting
* lisp/org.el (org-in-archived-heading-p): New function.

* lisp/ob-exp.el (org-babel-exp-process-buffer):
* lisp/ob-tangle.el (org-babel-tangle-collect-blocks): Use
`org-in-archived-heading-p' to skip archived headings when tangling
and exporting.

* testing/lisp/test-org.el (test-org/in-archived-heading-p): Add
test for `org-in-archived-heading-p'.

Reported-by: flare <gabrielxaviersmith@gmail.com>
See https://orgmode.org/list/877dt9ey2c.fsf@gmail.com/
2020-09-07 06:51:06 +02:00
Kyle Meyer 8d731ad256 Merge branch 'maint' 2020-06-08 20:28:03 -04:00
Kyle Meyer 3ebee03310 ob-tangle: Restore handling of relative file links
* lisp/ob-tangle.el (org-babel-tangle-single-block): Fix regression
from v9.0.2 that resulted in org-babel-tangle-use-relative-file-links
being ignored.
* testing/lisp/test-ob-tangle.el
(ob-tangle/comment-links-relative-file): Add test.

As of 7b148e2d0 (ob-tangle: Respect buffer local variables,
2016-12-10), the condition in org-babel-tangle-single-block that
checks whether to return a file link with a relative target always
returns nil because the full org-link-types-re match, including the
final colon, is compared with "file" (no colon).  Also, were this
condition to succeed, "file:" would be used as the file name.

Adjust the condition and fix the extracted file name.

Reported-by: Jeremias Gonzalez <jgonzalez49@ucmerced.edu>
https://orgmode.org/list/6fb12326-52d3-7177-eff5-62603261b388@ucmerced.edu
2020-06-08 20:25:22 -04:00
Kevin J. Foley 010d1e3b6e Fix `org-babel-detangle' handling of false positives
* lisp/ob-tangle.el (org-babel-detangle): Handle false positive
matches of `org-link-bracket-re'.

* testing/examples/babel.el: New file for Babel detangle false
positive test.

* testing/examples/babel.org (detangle): Add detangle/false positive
example.

* testing/lisp/test-ob-tangle.el (ob-tangle/detangle-false-positive):
Add test for detangle false positive.
2020-05-24 15:40:21 +02:00
Bastien 6a1f6ee1f8 Tiny formatting fixes
* lisp/ox.el (org-export-table-dimensions):
* lisp/ox-texinfo.el (org-texinfo-template):
* lisp/ox-md.el (org-md-link):
* lisp/ox-icalendar.el (org-icalendar-use-UTC-date-time-p):
* lisp/ox-ascii.el (org-ascii-fixed-width):
* lisp/org.el (org-context):
* lisp/org-table.el (org-table-eval-formula)
(org-table-export):
* lisp/org-refile.el:
* lisp/org-plot.el (org-plot/gnuplot-to-grid-data):
* lisp/org-num.el (org-num):
* lisp/org-mouse.el (org-mouse-popup-global-menu)
(org-mouse-context-menu):
* lisp/org-macro.el (org-macro):
* lisp/org-lint.el (org-lint):
* lisp/org-keys.el (org-keys):
* lisp/org-duration.el:
* lisp/org-clock.el (org-clock-get-last-clock-out-time)
(org-clock-update-mode-line, org-find-open-clocks):
* lisp/org-agenda.el (org-diary)
(org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item)
(org-agenda-highlight-todo, org-cmp-alpha)
(org-agenda-filter-by-category):
* lisp/ol.el (org-link-expand-abbrev, ol):
* lisp/ol-docview.el (ol-docview):
* lisp/ol-bibtex.el (org-execute-file-search-in-bibtex)
(org-bibtex, org-bibtex-read):
* lisp/ol-bbdb.el (org-bbdb-anniversary-description):
* lisp/ob-tangle.el (org-babel-tangle-jump-to-org):
* lisp/ob-table.el (org-babel-table-truncate-at-newline):
* lisp/ob-stan.el:
* lisp/ob-sqlite.el (org-babel-sqlite-table-or-scalar):
* lisp/ob-sql.el:
* lisp/ob-shen.el:
* lisp/ob-shell.el (org-babel-prep-session:shell)
(org-babel-prep-session:shell):
* lisp/ob-sed.el (org-babel-execute:sed)
(org-babel-execute:sed):
* lisp/ob-screen.el:
* lisp/ob-sass.el:
* lisp/ob-ruby.el (org-babel-prep-session:ruby)
(org-babel-prep-session:ruby):
* lisp/ob-ref.el (org-babel-ref-resolve, ob-ref):
* lisp/ob-python.el (org-babel-prep-session:python)
(org-babel-prep-session:python):
* lisp/ob-plantuml.el:
* lisp/ob-picolisp.el:
* lisp/ob-perl.el:
* lisp/ob-org.el:
* lisp/ob-octave.el (org-babel-prep-session:octave)
(org-babel-prep-session:octave)
(org-babel-octave-evaluate-session):
* lisp/ob-ocaml.el:
* lisp/ob-mscgen.el (org-babel-execute:mscgen)
(org-babel-execute:mscgen):
* lisp/ob-maxima.el:
(ob-maxima):
* lisp/ob-matlab.el:
* lisp/ob-makefile.el:
* lisp/ob-lua.el (org-babel-prep-session:lua)
(org-babel-prep-session:lua):
* lisp/ob-lisp.el:
* lisp/ob-ledger.el:
* lisp/ob-latex.el (org-babel-expand-body:latex)
(org-babel-expand-body:latex, ob-latex):
* lisp/ob-js.el:
* lisp/ob-java.el:
* lisp/ob-io.el (org-babel-prep-session:io)
(org-babel-prep-session:io):
* lisp/ob-hledger.el:
* lisp/ob-haskell.el:
* lisp/ob-groovy.el (org-babel-groovy-wrapper-method)
(org-babel-groovy-evaluate):
* lisp/ob-gnuplot.el:
* lisp/ob-fortran.el (org-babel-expand-body:fortran)
(org-babel-expand-body:fortran):
* lisp/ob-forth.el (org-babel-forth-session-execute):
* lisp/ob-exp.el (ob-exp):
* lisp/ob-eval.el:
* lisp/ob-emacs-lisp.el:
* lisp/ob-ebnf.el:
* lisp/ob-dot.el:
* lisp/ob-ditaa.el:
* lisp/ob-css.el:
* lisp/ob-core.el (org-babel-put-rownames):
* lisp/ob-coq.el:
* lisp/ob-comint.el:
* lisp/ob-calc.el:
* lisp/ob-awk.el:
* lisp/ob-asymptote.el:
* lisp/ob-abc.el:
* lisp/ob-R.el (org-babel-prep-session:R): Formatting fixes.
2020-02-18 22:57:37 +01:00
Bastien be93859c78 org.el (org-babel-load-file): Load emacs-lisp and elisp src blocks
* lisp/org.el (org-babel-load-file): Load both "emacs-lisp"
and "elisp" source blocks.

* lisp/ob-tangle.el (org-babel-tangle-file)
(org-babel-tangle, org-babel-tangle-collect-blocks): Use a
regular expression to match the language(s) to tangle.

Thanks to Troy Hinckley for reporting this.
2020-02-12 22:40:45 +01:00
Kyle Meyer ff5fc050d3 Update copyright year to 2020 2020-01-01 13:38:46 -05:00
Nicolas Goaziou df30a056b2 Fix tangling bug when major mode for LANGUAGE is not `LANGUAGE-mode'
* lisp/ob-core.el (org-babel-expand-noweb-references):
* lisp/ob-tangle.el (org-babel-tangle): Use `org-src-get-lang-mode' so
as to use proper major mode.

Reported-by: immanuel <immanuel.litzroth@gmail.com>
<http://lists.gnu.org/r/emacs-orgmode/2019-08/msg00272.html>
2019-08-30 23:36:00 +02:00