diff --git a/contrib/babel/lisp/org-babel-exp.el b/contrib/babel/lisp/org-babel-exp.el index 0cfd744ef..9e790fa35 100644 --- a/contrib/babel/lisp/org-babel-exp.el +++ b/contrib/babel/lisp/org-babel-exp.el @@ -135,22 +135,10 @@ options are taken from `org-babel-default-header-args'." (case type ('inline (format "=%s=" (second info))) ('block - (when args - (unless (string-match "-i\\>" switches) - (setq switches (concat switches " -i"))) - (setq body (with-temp-buffer - (insert body) - (indent-code-rigidly (point-min) (point-max) org-babel-function-def-export-indent) - (buffer-string))) - (setq args (mapconcat #'identity - (delq nil (mapcar (lambda (el) (and (length (cdr el)) (cdr el))) args)) - ", ")) - (setq function-def-line - (format "#+BEGIN_SRC org-babel-lob\n%s %s(%s):\n#+END_SRC\n" - org-babel-function-def-export-keyword name args))) - (concat function-def-line - (format "#+BEGIN_SRC %s %s\n%s%s#+END_SRC" lang switches body + (let ((str (format "#+BEGIN_SRC %s %s\n%s%s#+END_SRC\n" lang switches body (if (string-match "\n$" body) "" "\n")))) + (add-text-properties 0 (length str) (list 'org-caption name) str) + str)) ('lob (save-excursion (re-search-backward org-babel-lob-one-liner-regexp) (format "#+BEGIN_SRC org-babel-lob\n%s\n#+END_SRC" diff --git a/lisp/org-exp.el b/lisp/org-exp.el index 5176b2597..b5af06a1c 100644 --- a/lisp/org-exp.el +++ b/lisp/org-exp.el @@ -2295,7 +2295,7 @@ in the list) and remove property and value from the list in LISTVAR." "Replace source code segments with special code for export." (setq org-export-last-code-line-counter-value 0) (let ((case-fold-search t) - lang code trans opts indent) + lang code trans opts indent caption) (goto-char (point-min)) (while (re-search-forward "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\n?\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\n?\\)" @@ -2305,14 +2305,16 @@ in the list) and remove property and value from the list in LISTVAR." (setq lang (match-string 3) opts (match-string 4) code (match-string 5) - indent (length (match-string 2))) + indent (length (match-string 2)) + caption (get-text-property 0 'org-caption (match-string 0))) (setq lang nil opts (match-string 8) code (match-string 9) - indent (length (match-string 7)))) + indent (length (match-string 7)) + caption (get-text-property 0 'org-caption (match-string 0)))) (setq trans (org-export-format-source-code-or-example - backend lang code opts indent)) + backend lang code opts indent caption)) (replace-match trans t t)))) (defvar htmlp) ;; dynamically scoped @@ -2322,7 +2324,7 @@ in the list) and remove property and value from the list in LISTVAR." (defvar org-export-latex-listings-langs) ;; defined in org-latex.el (defun org-export-format-source-code-or-example - (backend lang code &optional opts indent) + (backend lang code &optional opts indent caption) "Format CODE from language LANG and return it formatted for export. If LANG is nil, do not add any fontification. OPTS contains formatting options, like `-n' for triggering numbering lines, @@ -2410,9 +2412,14 @@ INDENT was the original indentation of the block." (org-export-htmlize-region-for-paste (point-min) (point-max)))) (if (string-match "
]*\\)>\n*" rtn) - (setq rtn (replace-match + (setq rtn + (concat + (if caption + (format "\n" caption) + "") + (replace-match (format "\n" lang) - t t rtn)))) + t t rtn))))) (if textareap (setq rtn (concat (format "\n