diff --git a/lisp/org-exp.el b/lisp/org-exp.el index 2aad322..8255021 100644 --- a/lisp/org-exp.el +++ b/lisp/org-exp.el @@ -1171,7 +1171,15 @@ on this string to produce the exported version." ;; Export code blocks (org-export-blocks-preprocess) + ;; Select and protect backend specific stuff, throw away stuff + ;; that is specific for other backends + (run-hooks 'org-export-preprocess-before-selecting-backend-code-hook) + (org-export-select-backend-specific-text) + + ;; Attach captions to the correct object + (setq target-alist (org-export-attach-captions-and-attributes target-alist)) ;; Mark lists with properties + (org-export-mark-list-properties) ;; Handle source code snippets @@ -1213,11 +1221,6 @@ on this string to produce the exported version." ;; but mark them as targets that should be invisible (setq target-alist (org-export-handle-invisible-targets target-alist)) - ;; Select and protect backend specific stuff, throw away stuff - ;; that is specific for other backends - (run-hooks 'org-export-preprocess-before-selecting-backend-code-hook) - (org-export-select-backend-specific-text) - ;; Protect quoted subtrees (org-export-protect-quoted-subtrees) @@ -1235,9 +1238,6 @@ on this string to produce the exported version." (unless (plist-get parameters :timestamps) (org-export-remove-timestamps)) - ;; Attach captions to the correct object - (setq target-alist (org-export-attach-captions-and-attributes target-alist)) - ;; Find matches for radio targets and turn them into internal links (org-export-mark-radio-links) (run-hooks 'org-export-preprocess-after-radio-targets-hook) @@ -1894,7 +1894,11 @@ table line. If it is a link, add it to the line containing the link." "\\|" "^[ \t]*\\(|[^-]\\)" "\\|" - "^[ \t]*\\[\\[.*\\]\\][ \t]*$")) + "^[ \t]*\\[\\[.*\\]\\][ \t]*$" + "\\|" + "^[ \t]*#\\+begin_src.*$" + "\\|" + "^[ \t]*#\\+begin_example.*$")) cap shortn attr label end) (while (re-search-forward re nil t) (cond @@ -2468,7 +2472,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 caption) + lang code trans opts indent caption label attr) (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?\\)" @@ -2489,15 +2493,19 @@ in the list) and remove property and value from the list in LISTVAR." opts (match-string 5) code (match-string 6) indent (length (match-string 2)) - caption (get-text-property 0 'org-caption (match-string 0)))) + caption (get-text-property 0 'org-caption (match-string 0)) + label (get-text-property 0 'org-label (match-string 0)) + attr (get-text-property 0 'org-attributes (match-string 0)))) (setq lang nil opts (match-string 9) code (match-string 10) indent (length (match-string 8)) - caption (get-text-property 0 'org-caption (match-string 0)))) + caption (get-text-property 0 'org-caption (match-string 0)) + label (get-text-property 0 'org-label (match-string 0)) + attr (get-text-property 0 'org-attributes (match-string 0)))) (setq trans (org-export-format-source-code-or-example - lang code opts indent caption)) + lang code opts indent caption label attr)) (replace-match trans t t)))) (defvar org-export-latex-verbatim-wrap) ;; defined in org-latex.el @@ -2519,7 +2527,7 @@ in the list) and remove property and value from the list in LISTVAR." (forward-char 1)))) (defun org-export-format-source-code-or-example - (lang code &optional opts indent caption) + (lang code &optional opts indent caption label attr) "Format CODE from language LANG and return it formatted for export. The CODE is marked up in `org-export-current-backend' format. @@ -2664,13 +2672,13 @@ INDENT was the original indentation of the block." ((eq org-export-current-backend 'latex) (setq rtn (org-export-number-lines rtn 0 0 num cont rpllbl fmt)) (cond - ((and lang org-export-latex-listings) + (org-export-latex-listings (flet ((make-option-string (pair) (concat (first pair) (if (> (length (second pair)) 0) (concat "=" (second pair)))))) - (let* ((lang-sym (intern lang)) + (let* ((lang-sym (cond (lang (intern lang)) (t nil))) (minted-p (eq org-export-latex-listings 'minted)) (listings-p (not minted-p)) (backend-lang @@ -2687,13 +2695,6 @@ INDENT was the original indentation of the block." lang-sym org-export-latex-custom-lang-environments)))) (concat - (when (and listings-p (not custom-environment)) - (format - "\\lstset{%s}\n" - (mapconcat - #'make-option-string - (append org-export-latex-listings-options - `(("language" ,backend-lang))) ","))) (when (and caption org-export-latex-listings-w-names) (format "\n%s $\\equiv$ \n" @@ -2703,8 +2704,26 @@ INDENT was the original indentation of the block." (format "\\begin{%s}\n%s\\end{%s}\n" custom-environment rtn custom-environment)) (listings-p - (format "\\begin{%s}\n%s\\end{%s}" - "lstlisting" rtn "lstlisting")) + (concat + "\\begin{lstlisting}" + (when (or (and caption (not org-export-latex-listings-w-names)) attr label backend-lang org-export-latex-listings-options) "[") + (when org-export-latex-listings-options + (mapconcat + #'make-option-string + org-export-latex-listings-options ",")) + (when (and org-export-latex-listings-options (or (and caption (not org-export-latex-listings-w-names)) attr label backend-lang)) ",") + (when backend-lang (concat "language=" backend-lang)) + (when (and backend-lang (or (and caption (not org-export-latex-listings-w-names)) attr label)) ",") + (when (and caption (not org-export-latex-listings-w-names)) + (format "caption={%s}" (replace-regexp-in-string "_" "\\\\_" caption))) + (when (and caption (not org-export-latex-listings-w-names) label) ",") + (when label (format "label=%s" label)) + (when (and (or (and caption (not org-export-latex-listings-w-names)) label) attr) ",") + attr + (when (or (and caption (not org-export-latex-listings-w-names)) attr label backend-lang org-export-latex-listings-options) "]") + "\n" + rtn + "\\end{lstlisting}\n")) (minted-p (format "\\begin{minted}[%s]{%s}\n%s\\end{minted}"