From d6b99e92546a752419ff8b8bf919c7001e8e1ec2 Mon Sep 17 00:00:00 2001 From: Nicolas Berthier Date: Fri, 13 Jun 2014 15:32:54 +0200 Subject: [PATCH 1/2] ob: Support for exporting inline source code * lisp/ob-exp.el (org-babel-exp-inline-code-template): New customizable variable to export inline source code (similar to `org-babel-exp-code-template'). (org-babel-exp-code): New `type' argument to differentiate between inline and standard code blocks. * lisp/ob-core.el (org-babel-inline-src-block-regexp): Allow empty set of switches and header arguments as in "src_sh[]{echo foo;}". Until now pieces of inline source code were handled as standard code blocks during export. These changes enable them to be exported. --- lisp/ob-core.el | 2 +- lisp/ob-exp.el | 30 ++++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index e1d4f39..062d4e1 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -203,7 +203,7 @@ This string must include a \"%s\" which will be replaced by the results." (defvar org-babel-inline-src-block-regexp (concat ;; (1) replacement target (2) lang - "\\(?:^\\|[^-[:alnum:]]\\)\\(src_\\([^ \f\t\n\r\v]+\\)" + "\\(?:^\\|[^-[:alnum:]]\\)\\(src_\\([^ \f\t\n\r\v\\[]+\\)" ;; (3,4) (unused, headers) "\\(\\|\\[\\(.*?\\)\\]\\)" ;; (5) body diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el index 3a47661..37625ab 100644 --- a/lisp/ob-exp.el +++ b/lisp/ob-exp.el @@ -318,10 +318,10 @@ The function respects the value of the :exports header argument." (clean (lambda () (unless (eq type 'inline) (org-babel-remove-result info))))) (case (intern (or (cdr (assoc :exports (nth 2 info))) "code")) ('none (funcall silently) (funcall clean) "") - ('code (funcall silently) (funcall clean) (org-babel-exp-code info)) + ('code (funcall silently) (funcall clean) (org-babel-exp-code info type)) ('results (org-babel-exp-results info type nil hash) "") ('both (org-babel-exp-results info type nil hash) - (org-babel-exp-code info))))) + (org-babel-exp-code info type))))) (defcustom org-babel-exp-code-template "#+BEGIN_SRC %lang%switches%flags\n%body\n#+END_SRC" @@ -343,7 +343,27 @@ replaced with its value." :group 'org-babel :type 'string) -(defun org-babel-exp-code (info) +(defcustom org-babel-exp-inline-code-template + "src_%lang[%switches%flags]{%body}" + "Template used to export the body of inline code blocks. +This template may be customized to include additional information +such as the code block name, or the values of particular header +arguments. The template is filled out using `org-fill-template', +and the following %keys may be used. + + lang ------ the language of the code block + name ------ the name of the code block + body ------ the body of the code block + switches -- the switches associated to the code block + flags ----- the flags passed to the code block + +In addition to the keys mentioned above, every header argument +defined for the code block may be used as a key and will be +replaced with its value." + :group 'org-babel + :type 'string) + +(defun org-babel-exp-code (info type) "Return the original code block formatted for export." (setf (nth 1 info) (if (string= "strip-export" (cdr (assoc :noweb (nth 2 info)))) @@ -354,7 +374,9 @@ replaced with its value." info org-babel-exp-reference-buffer) (nth 1 info)))) (org-fill-template - org-babel-exp-code-template + (if (eq type 'inline) + org-babel-exp-inline-code-template + org-babel-exp-code-template) `(("lang" . ,(nth 0 info)) ("body" . ,(org-escape-code-in-string (nth 1 info))) ("switches" . ,(let ((f (nth 3 info))) -- 2.0.0.rc4