summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <schulte.eric@gmail.com>2011-10-08 16:31:50 -0600
committerEric Schulte <schulte.eric@gmail.com>2011-10-08 16:31:50 -0600
commit9135ec76dd931698dfb028865a28b4f313bb40b4 (patch)
tree1508d4a7c36ebff5864a6220709fb462e0599ae4
parent85d0a9fc05928ce088bac1b9dab8a0f17a94f79a (diff)
downloadorg-mode-9135ec76dd931698dfb028865a28b4f313bb40b4.tar.gz
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.
-rw-r--r--lisp/ob.el69
1 files changed, 61 insertions, 8 deletions
diff --git a/lisp/ob.el b/lisp/ob.el
index d20205f..48ad04a 100644
--- a/lisp/ob.el
+++ b/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)
+(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
- '(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.
Note that individual languages may define their own language
specific header arguments as well.")
@@ -573,6 +598,35 @@ arguments and pop open the results in a preview buffer."
(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
(defun org-babel-load-in-session (&optional arg info)
"Load the body of the current source-code block.
Evaluate the header arguments for the source block before
@@ -1804,12 +1858,11 @@ Later elements of PLISTS override the values of previous elements.
This takes into account some special considerations for certain
parameters when merging lists."
(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
- '(("code" "results" "both" "none")))
+ (mapcar (lambda (group) (mapcar #'symbol-name group))
+ (cdr (assoc 'exports org-babel-common-header-args-w-values))))
(variable-index 0)
params results exports tangle noweb cache vars shebang comments padline)
(flet ((e-merge (exclusive-groups &rest result-params)