diff --git a/doc/org.texi b/doc/org.texi index 6d5eca070..2297202e7 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -722,6 +722,7 @@ Specific header arguments * colnames:: Handle column names in tables * rownames:: Handle row names in tables * shebang:: Make tangled files executable +* tangle-mode:: Set permission of tangled files * eval:: Limit evaluation of specific code blocks * wrap:: Mark source block evaluation results * post:: Post processing of code block results @@ -14167,6 +14168,7 @@ argument in lowercase letters. The following header arguments are defined: * colnames:: Handle column names in tables * rownames:: Handle row names in tables * shebang:: Make tangled files executable +* tangle-mode:: Set permission of tangled files * eval:: Limit evaluation of specific code blocks * wrap:: Mark source block evaluation results * post:: Post processing of code block results @@ -15061,7 +15063,7 @@ variable indexing @xref{var, Indexable variable values}. @end itemize -@node shebang, eval, rownames, Specific header arguments +@node shebang, tangle-mode, rownames, Specific header arguments @subsubsection @code{:shebang} Setting the @code{:shebang} header argument to a string value @@ -15069,7 +15071,21 @@ Setting the @code{:shebang} header argument to a string value first line of any tangled file holding the code block, and the file permissions of the tangled file are set to make it executable. -@node eval, wrap, shebang, Specific header arguments + +@node tangle-mode, eval, shebang, Specific header arguments +@subsubsection @code{:tangle-mode} + +The @code{tangle-mode} header argument controls the permission set on tangled +files. The value of this header argument will be passed to +@code{set-file-modes}. For example, to set a tangled file as read only use +@code{:tangle-mode #o444}, or to set a tangled file as executable use +@code{:tangle-mode #o755}. Files with @ref{shebang} header arguments will +automatically be made executable unless the @code{tangle-mode} header +argument is also used. The behavior is undefined if multiple code blocks +with different values for the @code{tangle-mode} header argument are tangled +to the same file. + +@node eval, wrap, tangle-mode, Specific header arguments @subsubsection @code{:eval} The @code{:eval} header argument can be used to limit the evaluation of specific code blocks. The @code{:eval} header argument can be useful for diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 3e28cefe8..c3b1333bb 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -464,6 +464,7 @@ then run `org-babel-switch-to-session'." (session . :any) (shebang . :any) (tangle . ((tangle yes no :any))) + (tangle-mode . ((#o755 #o555 #o444 :any))) (var . :any) (wrap . :any))) @@ -2527,14 +2528,14 @@ block but are passed literally to the \"example-block\"." (defun org-babel-read (cell &optional inhibit-lisp-eval) "Convert the string value of CELL to a number if appropriate. Otherwise if cell looks like lisp (meaning it starts with a -\"(\", \"'\", \"`\" or a \"[\") then read it as lisp, otherwise -return it unmodified as a string. Optional argument NO-LISP-EVAL -inhibits lisp evaluation for situations in which is it not -appropriate." +\"(\", \"'\", \"`\" \"#\" or a \"[\") then read it as lisp, +otherwise return it unmodified as a string. Optional argument +NO-LISP-EVAL inhibits lisp evaluation for situations in which is +it not appropriate." (if (and (stringp cell) (not (equal cell ""))) (or (org-babel-number-p cell) (if (and (not inhibit-lisp-eval) - (or (member (substring cell 0 1) '("(" "'" "`" "[")) + (or (member (substring cell 0 1) '("(" "'" "`" "[" "#")) (string= cell "*this*"))) (eval (read cell)) (if (string= (substring cell 0 1) "\"") diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index 82f2c10ac..9b7129ed0 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -210,6 +210,7 @@ used to limit the exported source code blocks by language." (let* ((tangle (funcall get-spec :tangle)) (she-bang ((lambda (sheb) (when (> (length sheb) 0) sheb)) (funcall get-spec :shebang))) + (tangle-mode (funcall get-spec :tangle-mode)) (base-name (cond ((string= "yes" tangle) (file-name-sans-extension @@ -244,8 +245,11 @@ used to limit the exported source code blocks by language." (goto-char (point-max)) (insert content) (write-region nil nil file-name)))) - ;; if files contain she-bangs, then make the executable - (when she-bang (set-file-modes file-name #o755)) + ;; set permissions on the tangled file + (if tangle-mode + (set-file-modes file-name tangle-mode) + ;; if files contain she-bangs, then make the executable + (when she-bang (set-file-modes file-name #o755))) ;; update counter (setq block-counter (+ 1 block-counter)) (add-to-list 'path-collector file-name))))) diff --git a/lisp/org-pcomplete.el b/lisp/org-pcomplete.el index 43b5f46fe..77e2b3b43 100644 --- a/lisp/org-pcomplete.el +++ b/lisp/org-pcomplete.el @@ -391,7 +391,7 @@ Complete a language in the first field, the header arguments and switches." '("-n" "-r" "-l" ":cache" ":colnames" ":comments" ":dir" ":eval" ":exports" ":file" ":hlines" ":no-expand" ":noweb" ":results" ":rownames" - ":session" ":shebang" ":tangle" ":var")))) + ":session" ":shebang" ":tangle" ":tangle-mode" ":var")))) (defun pcomplete/org-mode/block-option/clocktable () "Complete keywords in a clocktable line."