Преглед на файлове

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 преди 11 години
родител
ревизия
2a73e06a6d
променени са 4 файла, в които са добавени 31 реда и са изтрити 10 реда
  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
 * colnames::                    Handle column names in tables
 * rownames::                    Handle row names in tables
 * rownames::                    Handle row names in tables
 * shebang::                     Make tangled files executable
 * shebang::                     Make tangled files executable
+* tangle-mode::                 Set permission of tangled files
 * eval::                        Limit evaluation of specific code blocks
 * eval::                        Limit evaluation of specific code blocks
 * wrap::                        Mark source block evaluation results
 * wrap::                        Mark source block evaluation results
 * post::                        Post processing of code block 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
 * colnames::                    Handle column names in tables
 * rownames::                    Handle row names in tables
 * rownames::                    Handle row names in tables
 * shebang::                     Make tangled files executable
 * shebang::                     Make tangled files executable
+* tangle-mode::                 Set permission of tangled files
 * eval::                        Limit evaluation of specific code blocks
 * eval::                        Limit evaluation of specific code blocks
 * wrap::                        Mark source block evaluation results
 * wrap::                        Mark source block evaluation results
 * post::                        Post processing of code block results
 * post::                        Post processing of code block results
@@ -15061,7 +15063,7 @@ variable indexing @xref{var, Indexable variable values}.
 
 
 @end itemize
 @end itemize
 
 
-@node shebang, eval, rownames, Specific header arguments
+@node shebang, tangle-mode, rownames, Specific header arguments
 @subsubsection @code{:shebang}
 @subsubsection @code{:shebang}
 
 
 Setting the @code{:shebang} header argument to a string value
 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
 first line of any tangled file holding the code block, and the file
 permissions of the tangled file are set to make it executable.
 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}
 @subsubsection @code{:eval}
 The @code{:eval} header argument can be used to limit the evaluation of
 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
 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)
     (session	. :any)
     (shebang	. :any)
     (shebang	. :any)
     (tangle	. ((tangle yes no :any)))
     (tangle	. ((tangle yes no :any)))
+    (tangle-mode . ((#o755 #o555 #o444 :any)))
     (var	. :any)
     (var	. :any)
     (wrap       . :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)
 (defun org-babel-read (cell &optional inhibit-lisp-eval)
   "Convert the string value of CELL to a number if appropriate.
   "Convert the string value of CELL to a number if appropriate.
 Otherwise if cell looks like lisp (meaning it starts with a
 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 "")))
   (if (and (stringp cell) (not (equal cell "")))
       (or (org-babel-number-p cell)
       (or (org-babel-number-p cell)
           (if (and (not inhibit-lisp-eval)
           (if (and (not inhibit-lisp-eval)
-		   (or (member (substring cell 0 1) '("(" "'" "`" "["))
+		   (or (member (substring cell 0 1) '("(" "'" "`" "[" "#"))
 		       (string= cell "*this*")))
 		       (string= cell "*this*")))
               (eval (read cell))
               (eval (read cell))
             (if (string= (substring cell 0 1) "\"")
             (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))
 		  (let* ((tangle (funcall get-spec :tangle))
 			 (she-bang ((lambda (sheb) (when (> (length sheb) 0) sheb))
 			 (she-bang ((lambda (sheb) (when (> (length sheb) 0) sheb))
 				    (funcall get-spec :shebang)))
 				    (funcall get-spec :shebang)))
+			 (tangle-mode (funcall get-spec :tangle-mode))
 			 (base-name (cond
 			 (base-name (cond
 				     ((string= "yes" tangle)
 				     ((string= "yes" tangle)
 				      (file-name-sans-extension
 				      (file-name-sans-extension
@@ -244,8 +245,11 @@ used to limit the exported source code blocks by language."
 			    (goto-char (point-max))
 			    (goto-char (point-max))
 			    (insert content)
 			    (insert content)
 			    (write-region nil nil file-name))))
 			    (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
 		      ;; update counter
 		      (setq block-counter (+ 1 block-counter))
 		      (setq block-counter (+ 1 block-counter))
 		      (add-to-list 'path-collector file-name)))))
 		      (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"
 	  '("-n" "-r" "-l"
 	    ":cache" ":colnames" ":comments" ":dir" ":eval" ":exports"
 	    ":cache" ":colnames" ":comments" ":dir" ":eval" ":exports"
 	    ":file" ":hlines" ":no-expand" ":noweb" ":results" ":rownames"
 	    ":file" ":hlines" ":no-expand" ":noweb" ":results" ":rownames"
-	    ":session" ":shebang" ":tangle" ":var"))))
+	    ":session" ":shebang" ":tangle" ":tangle-mode" ":var"))))
 
 
 (defun pcomplete/org-mode/block-option/clocktable ()
 (defun pcomplete/org-mode/block-option/clocktable ()
   "Complete keywords in a clocktable line."
   "Complete keywords in a clocktable line."