Commit Graph

52 Commits

Author SHA1 Message Date
Ihor Radchenko 1523e21d82
org-babel-expand-noweb-references: Add trialing newline after comments
* lisp/ob-core.el (org-babel-expand-noweb-references): After closing
comment, when using :comments noweb, leave trailing newline after the
closing comment.
* testing/lisp/test-ob-tangle.el (ob-tangle/comment-noweb-relative):
Modify test to check for the newline.

Reported-by: João Pedro <jpedrodeamorim@gmail.com>
Link: https://orgmode.org/list/87fruy2rw6.fsf@ergo
2024-05-04 14:30:25 +03: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 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 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
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 18f003a164
Merge branch 'bugfix' 2023-06-24 15:36:34 +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 200d168275
Merge branch 'bugfix' 2023-06-22 12:54:51 +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
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
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
Stefan Monnier 1a5e3f931c
testing: Make all files use `lexical-binding`
Mainly, add the corresponding cookie, but also add various `require`s
so that the compiler knows which vars should be trated as dynbound.
This does not fix all the warnings, but does try to eliminate
all those about "unused" variables.  For the variables truly unused,
the patch usually adds an underscore to their name to silence the warning.

Some of the fixes affect files which already used `lexical-binding`.
Not sure why the test worked before: maybe because the tests were run
without compiling them first (which could cause some of the
missing `require`d packages to be autoloaded before we got to the
problematic code, thus hiding the problem)?

I found some suspicious code, for which I added FIXMEs.

There are also a few changes to the main files.

* lisp/org-protocol.el (org-protocol-check-filename-for-protocol):
Don't call `server-edit` if it's not yet defined.  [ Needed to get
the tests to pass. ]

* lisp/ob-core.el (org-babel-temporary-directory)
(org-babel-temporary-stable-directory): Always define (and use nil
if we don't want to create a directory for it).  Simplify the code based
on the fact that (defvar V E) only evaluates E if V is not yet `boundp`.
(org-babel-temp-file, org-babel-temp-stable-file)
(org-babel-remove-temporary-directory)
(org-babel-remove-temporary-stable-directory): Adjust accordingly.

* lisp/org.el (org-log-beginning): Add FIXME.

* testing/org-test.el: Require `org` and `org-id`.
(org-id-locations-file): Don't `defconst` it.
(org-test-at-id, org-test-in-example-file, org-test-at-marker)
(org-test-with-temp-text, org-test-with-temp-text-in-file): Move edebug
specs into `declare` (and simplify them).
(org-test-with-tramp-remote-dir--worker): Declare dynbound tramp vars.
(org--compile-when): Fix quoting of `exp`.
(org-test-load): Tweak regexps.

* testing/org-batch-test-init.el: Tweak regexp, remove dead code and
add a FIXME about it.

* testing/lisp/test-ox.el: Require `ox` instead of
erroring out if it's not already loaded.  Also require `org-inlinetask`.
(org-test-with-parsed-data): Silence warnings when `info` is not used.
(test-org-export/bind-keyword): Add FIXME.

* testing/lisp/test-ox-publish.el: Require `org-test` and `ox-publish`.
(test-org-publish/resolve-external-link): Expose lambdas to
the compiler.  Remove unused var `ids`.
(test-org-publish/get-project-from-filename): Remove unused var `file`.

* testing/lisp/test-org.el: Require `org-macs`, `org`,
`org-inlinetask`, `org-refile`, and `org-agenda`.
(test-org/org-read-date): Declare `org-time-was-given` as dynbound.
(test-org/set-regexps-and-options): Add FIXME.

* testing/lisp/test-org-timer.el: Require `org-timer`.

* testing/lisp/test-org-table.el: Require `ox`.

* testing/lisp/test-org-protocol.el: Require `org-protocol` instead of
erroring out if it's not already loaded.  Also require `capture`, and
add missing `provide` statement.

* testing/lisp/test-org-pcomplete.el: Require `org`.

* testing/lisp/test-org-list.el: Require `org-list` and `org`.

* testing/lisp/test-org-lint.el: Require `org-footnote` and `org-lint`.

* testing/lisp/test-org-footnote.el: Require `org-footnote`.

* testing/lisp/test-org-element.el: Require `org-element` instead of
erroring out if it's not already loaded.  Also require `org` and
`org-inlinetask`.

* testing/lisp/test-org-duration.el: Require `org-duration`.

* testing/lisp/test-org-datetree.el: Require `org-datetree`.

* testing/lisp/test-org-colview.el: Require `org-colview`,
`org-duration`, and `org-inlinetask`.

* testing/lisp/test-org-clock.el: Require `org-duration` and `org-clock`.

* testing/lisp/test-org-archive.el: Require `org-archive`.

* testing/lisp/test-org-agenda.el
(test-org-agenda/bulk-custom-arg-func): Add FIXME.

* testing/lisp/test-ol.el: Require `ol` and `org-id`.
(test-org-link/store-link): Declare `org-store-link-props` and add FIXME.

* testing/lisp/test-oc.el (test-org-cite/export-capability): Add FIXME.

* testing/lisp/test-ob.el: Require `ob-core`, `org-src`, `ob-ref`,
and `org-table`.
(test-ob/eval-header-argument): Rename `foo` to `test-ob--foo` and
declare it as dynbound.
(test-ob/blocks-with-spaces, test-ob/specific-colnames): Add FIXME.
(test-ob/noweb-expansions-in-cache):
Declare `noweb-expansions-in-cache-var` as dynbound.

* testing/lisp/test-ob-tangle.el: Require `org` and `ob-tangle`.

* testing/lisp/test-ob-shell.el:
* testing/lisp/test-ob-python.el: Require `ob-core`.

* testing/lisp/test-ob-lob.el: Require `ob-lob`.
(temporary-value-for-test): Declare as dynbound.

* testing/lisp/test-ob-plantuml.el: Require `ob-plantuml` instead of
erroring out if it's not already loaded.
* testing/lisp/test-ob-lilypond.el: Require `ob-lilypond` instead of
erroring out if it's not already loaded.  Use `with-current-buffer`.

* testing/lisp/test-ob-julia.el: Require `ob-core`.

* testing/lisp/test-ob-java.el (org-babel-temporary-directory):
Remove dead code now that `org-babel-temporary-directory` is always bound.

* testing/lisp/test-ob-exp.el: Require `ob-exp`, `org-src`, and `org-test`.
(ob-exp/evaluate-all-executables-in-order):
Declare `*evaluation-collector*` as dynbound.

* testing/lisp/test-ob-emacs-lisp.el (ob-emacs-lisp/dynamic-lexical-edit)
(ob-emacs-lisp/dynamic-lexical-execute):
Rename dynbound var to `ob-emacs--x` and declare it as such.

* testing/lisp/test-ob-R.el: Require `ob-core`.
(ess-ask-for-ess-directory, ess-history-file): Declare vars.
2022-09-15 19:17:19 +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
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
Stefan Kangas 8cc992f7b2 Prefer HTTPS to HTTP for links to gnu.org 2021-03-21 14:29:13 -04:00
Kyle Meyer 469ee63401 ob-core: Fix handling of multiple noweb refs in same line
* lisp/ob-core.el (org-babel-expand-noweb-references): Don't anchor
noweb regexp at start of line to allow multiple matches per line.
* testing/lisp/test-ob-tangle.el (ob-tangle/multiple-noweb-in-line):
Add test.

This fixes a regression introduced by c1aed9f80 (ob-core: Refactor
`org-babel-expand-noweb-references', 2020-01-12), which was part of
the 9.4 release.

Reported-by: Tom Gillespie <tgbugs@gmail.com>
Ref: https://orgmode.org/list/CA+G3_PO2yO1jMMpdrkc39BGQQ2eU5X4FzTEJVotjDJo-50dsqQ@mail.gmail.com
2020-09-15 23:45:16 -04:00
Bastien 3e191242dc Fix tests wrt 2f53429413
* testing/lisp/test-ob.el (test-ob/inline-src_blk-default-results-replace-line-1)
(test-ob/just-one-results-block)
(test-ob/org-babel-remove-result--results-default)
(test-ob/specific-colnames): Fix tests.

* testing/lisp/test-ob-tangle.el (ob-tangle/comment-links-at-left-margin): Ditto.

* testing/lisp/test-ob-shell.el (ob-shell/generic-uses-no-arrays)
(ob-shell/bash-uses-arrays)
(ob-shell/generic-uses-no-assoc-arrays)
(ob-shell/bash-uses-assoc-arrays, ob-shell/simple-list): Ditto.

* testing/lisp/test-ob-exp.el (ob-exp/exports-inline)
(ob-exp/exports-inline-code): Ditto.

* testing/examples/ob-shell-test.org (Generic shell: no arrays)
(Bash shell: support for arrays)
(Generic shell: no special handing)
(Bash shell: support for associative arrays)
(Generic shell: no special handing)
(Bash shell: support for associative arrays with lists): Ditto.
2020-09-06 22:37:32 +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
Kévin Le Gouguec c8f7e89d7e Make tests robust with respect to mailcap entries
When /etc/mailcap specifies a program for text/plain
files (e.g. less(1)), org-open-file will run this program instead of
visiting the file.  This throws off some tests which expect
extension-less temporary files to be visited.

* testing/lisp/test-ob-tangle.el (ob-tangle/jump-to-org):
* testing/lisp/test-org-attach.el (test-org-attach/dir): Rig
org-file-apps so that temporary files are visited inside Emacs.
2020-06-03 00:11:46 -04:00
Kevin J. Foley 7a2b785d6a test-ob-tangle.el: Fix dirty repo state caused by testing
* testing/lisp/test-ob-tangle.el (ob-tangle/detangle-false-positive):
Kill modified buffer after test.

Another test is causing the modifications to be saved which leaves the
repo in a dirty state after testing.

Modified-by: Kyle Meyer <kyle@kyleam.com>
  Changed to kill a let-bound buffer rather than a buffer name.
2020-05-26 21:51:47 -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
Sebastian Miele 787fa238a9 Add tests about omission of commented src blocks when e.g. tangling
* testing/lisp/test-ob.el (test-ob/noweb-expansion): Add clause to
test.
* testing/lisp/test-ob-tangle.el (ob-tangle/commented-src-blocks): Add
test.
2019-11-24 10:27:35 +01:00
Bastien f584d37a67 Update copyright year 2019-01-01 11:50:56 +01:00
Nicolas Goaziou 085f150372 ob-tangle: Add a test
* testing/lisp/test-ob-tangle.el (ob-tangle/block-order): Add test.
2018-10-14 09:08:44 +02:00
Nicolas Goaziou 2fda33bfef ob-tangle: Fix tangling order
* lisp/ob-tangle.el (org-babel-tangle-collect-blocks): Preserver order
  of code blocks from the source document.
* testing/lisp/test-ob-tangle.el (ob-tangle/block-order): New test.

Reported-by: Kaushal Modi <kaushal.modi@gmail.com>
<http://lists.gnu.org/r/emacs-orgmode/2018-10/msg00062.html>
2018-10-11 00:01:50 +02:00
Tim Landscheidt 63c0266688 Update URLs in source code or tests
TINYCHANGE
2018-01-19 18:30:40 +01:00
thibault 1613153aac Fix tangling of org block with nested source block
* lisp/ob-tangle.el (org-babel-tangle-single-block): Prevent double unescaping
of source block by removing unnecessary call to `org-unescape-code-in-string'.

* testing/lisp/test-ob-tangle.el (ob-tangle/nested-block) New function.
2017-10-22 12:42:05 +02:00
Nicolas Goaziou 00ea6a286c ob-tangle: Fix last commit
* lisp/ob-tangle.el (org-babel-tangle-single-block):
  `org-babel-expand-noweb-references' specifically needs to be run in
  the Org document so as to resolve references.
* testing/lisp/test-ob-tangle.el (ob-tangle/continued-code-blocks-w-noweb-ref):
  Make sure a failing test doesn't leave a file behind it.
2016-12-10 00:59:08 +01:00
Nicolas Goaziou de24694f05 Turn org-mode into Org or Org mode
Use Org or Org mode instead of org-mode or Org-mode according to
"Documentation standards".
2016-08-23 22:13:56 +02:00
Nicolas Goaziou 67efff2fd8 ob-tangle: Fix `org-babel-tangle-jump-to-org'
* lisp/ob-tangle.el (org-babel-tangle-jump-to-org): Find correct
  location in the Org document.

* testing/lisp/test-ob-tangle.el (ob-tangle/jump-to-org): New test.
2016-01-31 20:38:35 +01:00
Nicolas Goaziou 59f00529d4 Update copyright years 2016-01-02 17:06:30 +01:00
Nicolas Goaziou e2ac979d9e ob-tangle: Fix commented links
* lisp/ob-tangle.el (org-babel-spec-to-string):
(org-babel-tangle-collect-blocks): Fix numbering and relative path of
commented links.

* testing/lisp/test-ob-tangle.el (ob-tangle/comment-links-numbering):
  New test.

Reported-by: Tobias Müller <mllertobias@gmx.de>
<http://permalink.gmane.org/gmane.emacs.orgmode/103861>
2016-01-02 17:05:00 +01:00
Nicolas Goaziou 62dc515ae5 ob-tangle: Fix commenting links at column 0
* lisp/ob-tangle.el (org-babel-spec-to-string): Ignore invisible
  characters when commenting in destination file.

* testing/lisp/test-ob-tangle.el (ob-tangle/comment-links-at-left-margin):
New test.

Reported-by: Rainer M Krug <Rainer@krugs.de>
<http://permalink.gmane.org/gmane.emacs.orgmode/101002>
2015-09-10 11:12:20 +02:00
Bastien Guerry 7d9a883b50 Update copyright years again.
Hint: copyright years are all updated in Emacs.
2014-01-07 14:18:17 +01:00
Bastien Guerry 0beda99171 Revert "Update copyright years."
This reverts commit 21105594fc.
2014-01-05 06:28:07 +01:00
Bastien Guerry 21105594fc Update copyright years. 2014-01-04 18:56:11 +01:00
Bastien Guerry 98cd4687a2 Update copyright years.
Happy new year!
2013-01-01 16:04:24 +01:00
Bastien Guerry 70b0f422b4 Fix copyright notices for test files. 2012-12-13 17:24:19 +01:00
Bastien Guerry ecd0562c5f Fix the master branch.
I started from the 78ec8e commit then cherry-picked and squashed
commits that have been done in master since then, except the bad
commits that overwrote the tree (in master) with the tree in maint.

This commit also bumps the version number to 7.8.06.

The only "fix" that was made between 78ec8e and the previous commit
is e0072f which has been reported to break stuff.
2012-03-19 22:01:29 +01:00
Bastien Guerry de42649f7b Manually revert maint to e85080.
e85080 is the last correct commit in the maint branch
before releasing 7.8.04.  The 7.8.05 release should be
done from this commit.
2012-03-17 16:28:46 +01:00
Bastien Guerry 73bb18ba37 Manually revert to the Release 7.8.04 tag. 2012-03-17 15:52:24 +01:00
Bastien Guerry 6e534f9c61 Manually revert back to commit e85080.
This fixes a wrong merge that should not have happened:
commit 7e903a merges the master branch into the maint branch,
while we really want to keep the maint branch a bugfix-only
branch.

This commit reverts back the maint branch to its state before
merging the master branch.  From there, we will fix remaining
problems with the maint branch (e.g. copyright issues) then
release this maint branch as Org-mode 7.8.05.
2012-03-17 14:34:01 +01:00
Eric Schulte 3234811c49 cleaning headers of test files -- removing loads and requires 2012-02-29 09:10:08 -07:00
Bastien Guerry e44d2975ff Fix copyright (to 2012) year and Org version (to 7.8.03). 2012-01-03 18:47:01 +01:00
Eric Schulte def5a2f567 test: updated babel tangling test to reflect body-parsing change 2011-07-15 09:31:36 -06:00
Eric Schulte b18e0cb117 test: tests for expanding noweb references 2011-06-28 13:04:58 -07:00
Eric Schulte ff62c5d700 added a test for the new noweb-ref header argument, passing all tests
* testing/examples/babel.org: Example data for new test.
* testing/lisp/test-ob-tangle.el
  (ob-tangle/no-excessive-id-insertion-on-tangle): Safer to narrow,
  and less work.
  (ob-tangle/continued-code-blocks-w-noweb-ref): Testing new
  :noweb-ref header argument.
2011-06-15 21:27:58 -07:00
Eric Schulte 978cdf276d Babel: code block may have empty bodies, now passing all tests
* lisp/ob.el (org-babel-src-block-regexp): Babel: code block may have
  empty bodies.
* testing/lisp/test-ob-tangle.el
  (ob-tangle/no-excessive-id-insertion-on-tangle): Updated the ID.
* testing/lisp/test-ob.el (test-org-babel/src-block-regexp): Cleaned
  up the test.
  (test-org-babel/default-header-args): Removed trivial test.
  (test-org-babel/get-header): Indentation.
  (test-org-babel/sha1-hash): Updated Hash for new sorting schema.
2011-06-14 13:41:32 -07:00
Martyn Jago 38bc761e21 Modified testing/README.org to include ERT installation information for Emacs version < 24. Added new tests 2011-03-02 11:46:47 -07:00