emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* :mkdirp without path specifier
@ 2014-05-01 19:47 Michael Weylandt
  2014-05-03  3:43 ` R. Michael Weylandt
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Weylandt @ 2014-05-01 19:47 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

If it intended that setting :mkdirp yes should break tangling with 'directory-free' file names?

I.e., should
#############
#+TITLE: test
#+BEGIN_SRC python :mkdirp yes :tangle test.py
print 1+2
#+END_SRC
###############

tangle without error? 

It currently doesn't because (file-name-directory "test.py"), which is nil, gets passed to make-directory, which throws an error. 

The manual is ambiguous, stating only that the arg to :tangle is interpreted as a path. A strict reading says this shouldn't work, regardless of :mkdirp, since we're not giving a path, but I think the "understood ./" of :mkdirp no is reasonable. 

I'm not in a position to do so now, but can send a one-line patch to fix tonight if wanted. 

Michael

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: :mkdirp without path specifier
  2014-05-01 19:47 :mkdirp without path specifier Michael Weylandt
@ 2014-05-03  3:43 ` R. Michael Weylandt
  2014-05-03  3:47   ` R. Michael Weylandt
  0 siblings, 1 reply; 5+ messages in thread
From: R. Michael Weylandt @ 2014-05-03  3:43 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

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

On Thu, May 1, 2014 at 3:47 PM, Michael Weylandt
<michael.weylandt@gmail.com> wrote:
> If it intended that setting :mkdirp yes should break tangling with 'directory-free' file names?
>
> I.e., should
> #############
> #+TITLE: test
> #+BEGIN_SRC python :mkdirp yes :tangle test.py
> print 1+2
> #+END_SRC
> ###############
>
> tangle without error?
>
> It currently doesn't because (file-name-directory "test.py"), which is nil, gets passed to make-directory, which throws an error.
>
> The manual is ambiguous, stating only that the arg to :tangle is interpreted as a path. A strict reading says this shouldn't work, regardless of :mkdirp, since we're not giving a path, but I think the "understood ./" of :mkdirp no is reasonable.
>

Patch attached. Should apply cleanly against master and maint.

Michael

[-- Attachment #2: 0001-Fix-tangle-with-mkdirp-yes-tangle-FILE.patch --]
[-- Type: application/octet-stream, Size: 1272 bytes --]

From d4dc8067f3a97fbd6061537e4f52bbcea0b50bc8 Mon Sep 17 00:00:00 2001
From: Michael Weylandt <michael.weylandt@gmail.com>
Date: Fri, 2 May 2014 23:30:42 -0400
Subject: [PATCH] Fix tangle with ":mkdirp yes :tangle FILE"

* ob-tangle.el (org-babel-tangle): Fix tangling with :mkdirp and :tangle FILE.
Since (file-name-directory FILE) returns nil, don't pass it to
make-directory without checking.

Fixes tangling of files like:
print 1 + 2 + 3

TINYCHANGE
---
 lisp/ob-tangle.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el
index be7e9a6..dd92345 100644
--- a/lisp/ob-tangle.el
+++ b/lisp/ob-tangle.el
@@ -234,7 +234,8 @@ used to limit the exported source code blocks by language."
 		      ;; Possibly create the parent directories for file.
 		      (when (let ((m (funcall get-spec :mkdirp)))
                               (and m (not (string= m "no"))))
-			(make-directory (file-name-directory file-name) 'parents))
+			(if (file-name-directory file-name)
+			    (make-directory (file-name-directory file-name) 'parents)))
 		      ;; delete any old versions of file
 		      (when (and (file-exists-p file-name)
 				 (not (member file-name (mapcar #'car path-collector))))
-- 
1.8.3.4 (Apple Git-47)


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: :mkdirp without path specifier
  2014-05-03  3:43 ` R. Michael Weylandt
@ 2014-05-03  3:47   ` R. Michael Weylandt
  2014-05-03  8:19     ` Achim Gratz
  0 siblings, 1 reply; 5+ messages in thread
From: R. Michael Weylandt @ 2014-05-03  3:47 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

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

On Fri, May 2, 2014 at 11:43 PM, R. Michael Weylandt
<michael.weylandt@gmail.com> wrote:
> Patch attached. Should apply cleanly against master and maint.


Bah, botched the formatting. Attached should be fixed.

[-- Attachment #2: 0001-Fix-tangle-with-mkdirp-yes-tangle-FILE.patch --]
[-- Type: application/octet-stream, Size: 1408 bytes --]

From 69be77b0de028b32a7c102affc14f49a4eb98279 Mon Sep 17 00:00:00 2001
From: Michael Weylandt <michael.weylandt@gmail.com>
Date: Fri, 2 May 2014 23:30:42 -0400
Subject: [PATCH] Fix tangle with ":mkdirp yes :tangle FILE"

* ob-tangle.el (org-babel-tangle): Fix tangling with :mkdirp and :tangle FILE.
Since (file-name-directory FILE) returns nil, don't pass it to
make-directory without checking.

Fixes tangling of files like:
,#############################
,#+TITLE: Test
,#+BEGIN_SRC python :mkdir yes :tangle test.py
,print 1 + 2 + 3
,#+END_SRC
,#############################

TINYCHANGE
---
 lisp/ob-tangle.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el
index be7e9a6..dd92345 100644
--- a/lisp/ob-tangle.el
+++ b/lisp/ob-tangle.el
@@ -234,7 +234,8 @@ used to limit the exported source code blocks by language."
 		      ;; Possibly create the parent directories for file.
 		      (when (let ((m (funcall get-spec :mkdirp)))
                               (and m (not (string= m "no"))))
-			(make-directory (file-name-directory file-name) 'parents))
+			(if (file-name-directory file-name)
+			    (make-directory (file-name-directory file-name) 'parents)))
 		      ;; delete any old versions of file
 		      (when (and (file-exists-p file-name)
 				 (not (member file-name (mapcar #'car path-collector))))
-- 
1.8.3.4 (Apple Git-47)


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: :mkdirp without path specifier
  2014-05-03  3:47   ` R. Michael Weylandt
@ 2014-05-03  8:19     ` Achim Gratz
  2014-05-03 14:52       ` R. Michael Weylandt
  0 siblings, 1 reply; 5+ messages in thread
From: Achim Gratz @ 2014-05-03  8:19 UTC (permalink / raw)
  To: emacs-orgmode

R. Michael Weylandt writes:
>  		      ;; Possibly create the parent directories for file.
>  		      (when (let ((m (funcall get-spec :mkdirp)))
>                                (and m (not (string= m "no"))))
> -			(make-directory (file-name-directory file-name) 'parents))
> +			(if (file-name-directory file-name)
> +			    (make-directory (file-name-directory file-name) 'parents)))

If the else clause is intentionally missing, some folks prefer to use
"when" instead of "if" to advertise that fact (see some surrounding code
for example).  In this case the additional "if" should be rolled into
the condition check of the former "when" anyway (and let-bind the result
to avoid the duplicate "file-name-directory" call).  The conditional is
actually superfluous since we can short-circuit from the "and".

A patch to that effect has been installed in 063c8b03b7.


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Wavetables for the Waldorf Blofeld:
http://Synth.Stromeko.net/Downloads.html#BlofeldUserWavetables

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: :mkdirp without path specifier
  2014-05-03  8:19     ` Achim Gratz
@ 2014-05-03 14:52       ` R. Michael Weylandt
  0 siblings, 0 replies; 5+ messages in thread
From: R. Michael Weylandt @ 2014-05-03 14:52 UTC (permalink / raw)
  To: Achim Gratz; +Cc: emacs-orgmode@gnu.org

On Sat, May 3, 2014 at 4:19 AM, Achim Gratz <Stromeko@nexgo.de> wrote:
> R. Michael Weylandt writes:
>>                     ;; Possibly create the parent directories for file.
>>                     (when (let ((m (funcall get-spec :mkdirp)))
>>                                (and m (not (string= m "no"))))
>> -                     (make-directory (file-name-directory file-name) 'parents))
>> +                     (if (file-name-directory file-name)
>> +                         (make-directory (file-name-directory file-name) 'parents)))
>
> If the else clause is intentionally missing, some folks prefer to use
> "when" instead of "if" to advertise that fact (see some surrounding code
> for example).  In this case the additional "if" should be rolled into
> the condition check of the former "when" anyway (and let-bind the result
> to avoid the duplicate "file-name-directory" call).  The conditional is
> actually superfluous since we can short-circuit from the "and".
>
> A patch to that effect has been installed in 063c8b03b7.
>

Thanks for the feedback and applying a fix.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-05-03 14:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-01 19:47 :mkdirp without path specifier Michael Weylandt
2014-05-03  3:43 ` R. Michael Weylandt
2014-05-03  3:47   ` R. Michael Weylandt
2014-05-03  8:19     ` Achim Gratz
2014-05-03 14:52       ` R. Michael Weylandt

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).