emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jacopo De Simoi <jacopods@protonmail.com>
To: Org-mode Org-Mode <emacs-orgmode@gnu.org>
Subject: [PATCH} Do not throw error when parameter of :tangle is not a string
Date: Thu, 01 Jul 2021 04:01:01 +0000	[thread overview]
Message-ID: <7267271.EvYhyI6sBW@bl4ckspoons> (raw)

[-- Attachment #1: Type: text/plain, Size: 425 bytes --]

Dear All,

 in the current master branch, if the parameter :tangle of a src block is not
a string, tangling fails by throwing  an error when calling `file-name-
directory'  This patch checks if the parameter is a string before calling
`file-name-directory'.

This makes construct such as :tangle (when condition-applies "filename") work
again (as they did a few versions ago…)

Thanks for your time
Best
 Jacopo

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-tangle.el-Handle-non-string-arguments-more-gracef.patch --]
[-- Type: text/x-patch; name=0001-ob-tangle.el-Handle-non-string-arguments-more-gracef.patch, Size: 2134 bytes --]

From f08ecdb79ec71ecc94fe006043bd8eacc8ac41a0 Mon Sep 17 00:00:00 2001
From: Jacopo De Simoi <jacopods@protonmail.com>
Date: Mon, 28 Jun 2021 15:42:29 -0400
Subject: [PATCH 1/2] ob-tangle.el: Handle non-string arguments more gracefullu

* 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
---
 lisp/ob-tangle.el | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el
index 562776ae8..02379d44e 100644
--- a/lisp/ob-tangle.el
+++ b/lisp/ob-tangle.el
@@ -469,6 +469,7 @@ non-nil, return the full association list to be used by
 			 (match-end 0)
 		       (point-min))))
 	      (point)))))
+         (src-tfile (cdr (assq :tangle params)))
 	 (result
 	  (list start-line
 		(if org-babel-tangle-use-relative-file-links
@@ -476,11 +477,12 @@ non-nil, return the full association list to be used by
 		  file)
 		(if (and org-babel-tangle-use-relative-file-links
 			 (string-match org-link-types-re link)
-			 (string= (match-string 1 link) "file"))
+			 (string= (match-string 1 link) "file")
+                         (stringp src-tfile))
 		    (concat "file:"
 			    (file-relative-name (substring link (match-end 0))
 						(file-name-directory
-						 (cdr (assq :tangle params)))))
+						 src-tfile)))
 		  link)
 		source-name
 		params
@@ -489,8 +491,7 @@ non-nil, return the full association list to be used by
 		  (org-trim (org-remove-indentation body)))
 		comment)))
     (if only-this-block
-        (let* ((src-tfile (cdr (assq :tangle (nth 4 result))))
-               (file-name (org-babel-effective-tangled-filename
+        (let* ((file-name (org-babel-effective-tangled-filename
                            (nth 1 result) src-lang src-tfile)))
           (list (cons file-name (list (cons src-lang result)))))
       result)))
-- 
2.31.1


[-- Attachment #3: attachment.asc --]
[-- Type: application/pgp-signature, Size: 499 bytes --]

             reply	other threads:[~2021-07-01 10:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-01  4:01 Jacopo De Simoi [this message]
2021-07-08  8:44 ` [PATCH] Do not throw error when parameter of :tangle is not a string Sébastien Miquel
2021-07-08 14:53   ` Jacopo De Simoi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7267271.EvYhyI6sBW@bl4ckspoons \
    --to=jacopods@protonmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).