Browse Source

adding a new global tangle-mode header argument

* doc/org.texi (Top): Documentation for new tangle-mode header argument.
  (Specific header arguments): Documentation for new tangle-mode header
  argument.
  (rownames): Documentation for new tangle-mode header argument.
  (tangle-mode): Documentation for new tangle-mode header argument.

* lisp/ob-core.el (org-babel-common-header-args-w-values): Adding the
  new :tangle-mode header argument.
  (org-babel-read): Read values starting with a "#" character as emacs
  lisp.

* lisp/ob-tangle.el (org-babel-tangle): Use the new :tangle-mode header
  argument.

* lisp/org-pcomplete.el (pcomplete/org-mode/block-option/src): Use the
  new :tangle-mode header argument.
Eric Schulte 7 years ago
parent
commit
2a73e06a6d
4 changed files with 31 additions and 10 deletions
  1. 18 2
      doc/org.texi
  2. 6 5
      lisp/ob-core.el
  3. 6 2
      lisp/ob-tangle.el
  4. 1 1
      lisp/org-pcomplete.el

+ 18 - 2
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

+ 6 - 5
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) "\"")

+ 6 - 2
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)))))

+ 1 - 1
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."