summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Herrlin <jherrlin@gmail.com>2020-08-02 10:39:02 +0200
committerKyle Meyer <kyle@kyleam.com>2020-08-02 22:59:25 -0400
commitea946353aaf0a2e5022ebe6c7b012c70833ec0ba (patch)
tree063c170bb3f2f3fccc3e220424a6ed94a40533e3
parenta103f3f3ee1cc0beb05881cd4e58a38fca1ad30a (diff)
downloadorg-mode-ea946353aaf0a2e5022ebe6c7b012c70833ec0ba.tar.gz
ob-core: file-mode option in source code block arguments
* ob-core.el (org-babel-execute-src-block): Source code block header argument `:file-mode' can set file permissions if `:file' argument is provided. (org-babel-common-header-args-w-values): Add `:file-mode' to common header arguments. TINYCHANGE
-rw-r--r--doc/org-manual.org11
-rw-r--r--etc/ORG-NEWS5
-rw-r--r--lisp/ob-core.el7
-rw-r--r--testing/lisp/test-ob.el14
4 files changed, 36 insertions, 1 deletions
diff --git a/doc/org-manual.org b/doc/org-manual.org
index 0f012d4..3eb745b 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -17444,6 +17444,17 @@ default behavior is to automatically determine the result type.
TAB-delimited output. You can choose a different separator with
the =sep= header argument.
+ #+cindex: @samp{file-mode}, header argument
+ The =file-mode= header argument defines the file permissions. To
+ make it executable, use =:file-mode (identity #o755)=.
+
+ #+begin_example
+ ,#+BEGIN_SRC shell :results file :file script.sh :file-mode (identity #o755)
+ echo "#!/bin/bash"
+ echo "echo Hello World"
+ ,#+END_SRC
+ #+end_example
+
*** Format
:PROPERTIES:
:UNNUMBERED: notoc
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 1ac7486..8a3589e 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -261,6 +261,11 @@ explicitly:
In situations where ~org-return~ calls ~newline~, multiple newlines
can now be inserted with this prefix argument.
+*** New source code block header argument =:file-mode=
+
+Source code block header argument =:file-mode= can set file
+permissions if =:file= argument is provided.
+
** New commands
*** ~org-table-header-line-mode~
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 230706b..5786222 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -403,6 +403,7 @@ then run `org-babel-switch-to-session'."
(file . :any)
(file-desc . :any)
(file-ext . :any)
+ (file-mode . ((#o755 #o555 #o444 :any)))
(hlines . ((no yes)))
(mkdirp . ((yes no)))
(no-expand)
@@ -734,7 +735,11 @@ block."
(with-temp-file file
(insert (org-babel-format-result
result
- (cdr (assq :sep params))))))
+ (cdr (assq :sep params)))))
+ ;; Set file permissions if header argument
+ ;; `:file-mode' is provided.
+ (when (assq :file-mode params)
+ (set-file-modes file (cdr (assq :file-mode params)))))
(setq result file))
;; Possibly perform post process provided its
;; appropriate. Dynamically bind "*this*" to the
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index fe59c5e..afaf135 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -1746,6 +1746,20 @@ line 1
(cdr (assq :file (nth 2 (org-babel-get-src-block-info t))))))
))
+(ert-deftest test-ob/file-mode ()
+ "Ensure that :file-mode results in expected permissions."
+ (should
+ (equal #o755
+ (org-test-with-temp-text-in-file "
+#+begin_src emacs-lisp :results file :file t.sh :file-mode (identity #o755)
+nil
+#+end_src"
+ (org-babel-next-src-block)
+ (org-babel-execute-src-block)
+ (unwind-protect
+ (file-modes "t.sh")
+ (delete-file "t.sh"))))))
+
(ert-deftest test-ob-core/dir-mkdirp ()
"Test :mkdirp with :dir header combination."
(should-not