瀏覽代碼

New helper function for inserting common code block header arguments

* lisp/ob.el (org-babel-common-header-args-w-values): New variable to
  hold common header arguments and their default values.
  (org-babel-header-arg-names): Redefined using the new common header
  arg variable.
  (org-babel-insert-header-arg): New function to help when inserting
  header arguments.
Eric Schulte 13 年之前
父節點
當前提交
9135ec76dd
共有 1 個文件被更改,包括 61 次插入8 次删除
  1. 61 8
      lisp/ob.el

+ 61 - 8
lisp/ob.el

@@ -353,10 +353,35 @@ then run `org-babel-pop-to-session'."
 
 
 (add-hook 'org-metadown-hook 'org-babel-pop-to-session-maybe)
 (add-hook 'org-metadown-hook 'org-babel-pop-to-session-maybe)
 
 
+(defconst org-babel-common-header-args-w-values
+  '((cache	. ((no yes)))
+    (cmdline	. :any)
+    (colnames	. ((nil no yes)))
+    (comments	. ((no link yes org both noweb)))
+    (dir	. :any)
+    (eval	. ((never query)))
+    (exports	. ((code results both none)))
+    (file	. :any)
+    (hlines	. ((no yes)))
+    (mkdirp	. ((yes no)))
+    (no-expand)
+    (noeval)
+    (noweb	. ((yes no tangle)))
+    (noweb-ref	. :any)
+    (padline	. ((yes no)))
+    (results	. ((file list vector table scalar verbatim)
+		    (raw org html latex code pp wrap)
+		    (replace silent append prepend)
+		    (output value)))
+    (rownames	. ((no yes)))
+    (sep	. :any)
+    (session	. :any)
+    (shebang	. :any)
+    (tangle	. ((tangle yes no :any)))
+    (var	. :any)))
+
 (defconst org-babel-header-arg-names
 (defconst org-babel-header-arg-names
-  '(cache cmdline colnames dir exports file noweb results
-    session tangle var eval noeval comments no-expand shebang
-    padline noweb-ref)
+  (mapcar #'car org-babel-common-header-args-w-values)
   "Common header arguments used by org-babel.
   "Common header arguments used by org-babel.
 Note that individual languages may define their own language
 Note that individual languages may define their own language
 specific header arguments as well.")
 specific header arguments as well.")
@@ -572,6 +597,35 @@ arguments and pop open the results in a preview buffer."
 		 header name))))
 		 header name))))
     (message "No suspicious header arguments found.")))
     (message "No suspicious header arguments found.")))
 
 
+;;;###autoload
+(defun org-babel-insert-header-arg ()
+  "Insert a header argument selecting from lists of common args and values."
+  (interactive)
+  (let ((arg (org-icompleting-read
+	      "Header Arg: "
+	      (mapcar
+	       (lambda (header-spec) (symbol-name (car header-spec)))
+	       org-babel-common-header-args-w-values))))
+    (insert arg ":")
+    (let ((vals (cdr (assoc (intern arg)
+			    org-babel-common-header-args-w-values))))
+      (when vals
+	(insert
+	 " "
+	 (cond
+	  ((eq vals :any)
+	   (read-from-minibuffer "value: "))
+	  ((listp vals)
+	   (mapconcat
+	    (lambda (group)
+	      (let ((arg (org-icompleting-read
+			  "value: "
+			  (cons "default" (mapcar #'symbol-name group)))))
+		(if (and arg (not (string= "default" arg)))
+		    (concat arg " ")
+		  "")))
+	    vals ""))))))))
+
 ;;;###autoload
 ;;;###autoload
 (defun org-babel-load-in-session (&optional arg info)
 (defun org-babel-load-in-session (&optional arg info)
   "Load the body of the current source-code block.
   "Load the body of the current source-code block.
@@ -1804,12 +1858,11 @@ Later elements of PLISTS override the values of previous elements.
 This takes into account some special considerations for certain
 This takes into account some special considerations for certain
 parameters when merging lists."
 parameters when merging lists."
   (let ((results-exclusive-groups
   (let ((results-exclusive-groups
-	 '(("file" "list" "vector" "table" "scalar" "verbatim")
-	   ("raw" "org" "html" "latex" "code" "pp" "wrap")
-	   ("replace" "silent" "append" "prepend")
-	   ("output" "value")))
+	 (mapcar (lambda (group) (mapcar #'symbol-name group))
+		 (cdr (assoc 'results org-babel-common-header-args-w-values))))
 	(exports-exclusive-groups
 	(exports-exclusive-groups
-	 '(("code" "results" "both" "none")))
+	 (mapcar (lambda (group) (mapcar #'symbol-name group))
+		 (cdr (assoc 'exports org-babel-common-header-args-w-values))))
 	(variable-index 0)
 	(variable-index 0)
 	params results exports tangle noweb cache vars shebang comments padline)
 	params results exports tangle noweb cache vars shebang comments padline)
     (flet ((e-merge (exclusive-groups &rest result-params)
     (flet ((e-merge (exclusive-groups &rest result-params)