From f90322377c162aa3b8c3e0008e299f958e96083b Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Sat, 24 Feb 2024 12:48:35 +0300 Subject: [PATCH] ox: Fix exporting code blocks with missing language specifier * lisp/ox-latex.el (org-latex-inline-src-block): Export code blocks without language as verbatim. * lisp/ox-man.el (org-man-inline-src-block): (org-man-src-block): Do not try to call source-highlight executable when code block language is missing. * lisp/ox-odt.el (org-odt-do-format-code): * lisp/ox-texinfo.el (org-texinfo-src-block): Do not throw error when code block language is missing. Reproducer (not available on the list): To reproduce my problem you can write create an org-mode buffer (C-x b 1.org M-x org-mode) with the following content: #+begin_src lua :tangle yes :noweb yes aaa <> #+end_src #+name: second #+begin_src bbb #+end_src Then enable exporting to texinfo and export the buffer: M-: (require 'ox-texinfo) C-c C-e i t The folllowing backtrace appears (providing you already enabled debugging on errors): Debugger entered--Lisp error: (wrong-type-argument stringp nil) apply(debug error (wrong-type-argument stringp nil)) edebug(error (wrong-type-argument stringp nil)) signal(wrong-type-argument (stringp nil)) edebug-signal(wrong-type-argument (stringp nil)) string-match("lisp" nil nil t) string-match-p("lisp" nil) (edebug-after (edebug-before 1) 5 (string-match-p "lisp" (edebug-after (edebug-before 2) 4 (org-element-property :language (edebug-after 0 3 src-block))))) Reported-by: pva-outdoor@yandex.ru Link: https://list.orgmode.org/orgmode/87jzn7oz1u.fsf@yandex.ru/ --- lisp/ox-latex.el | 2 +- lisp/ox-man.el | 10 ++++++---- lisp/ox-odt.el | 2 +- lisp/ox-texinfo.el | 5 +++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index d30467aab..1b0fcb7c4 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -2451,7 +2451,7 @@ contextual information." (let ((code (org-element-property :value inline-src-block)) (lang (org-element-property :language inline-src-block))) (pcase (plist-get info :latex-src-block-backend) - (`verbatim (org-latex--text-markup code 'code info)) + ((or `verbatim (guard (not lang))) (org-latex--text-markup code 'code info)) (`minted (org-latex-inline-src-block--minted info code lang)) (`engraved (org-latex-inline-src-block--engraved info code lang)) (`listings (org-latex-inline-src-block--listings info code lang)) diff --git a/lisp/ox-man.el b/lisp/ox-man.el index 1f296baeb..5ef4dc63f 100644 --- a/lisp/ox-man.el +++ b/lisp/ox-man.el @@ -510,8 +510,9 @@ contextual information." (expand-file-name "reshilite" tmpdir))) (org-lang (org-element-property :language inline-src-block)) (lst-lang - (cadr (assq (intern org-lang) - (plist-get info :man-source-highlight-langs)))) + (and org-lang + (cadr (assq (intern org-lang) + (plist-get info :man-source-highlight-langs))))) (cmd (concat (expand-file-name "source-highlight") " -s " lst-lang @@ -757,8 +758,9 @@ contextual information." (code (org-element-property :value src-block)) (org-lang (org-element-property :language src-block)) (lst-lang - (cadr (assq (intern org-lang) - (plist-get info :man-source-highlight-langs)))) + (and org-lang + (cadr (assq (intern org-lang) + (plist-get info :man-source-highlight-langs))))) (cmd (concat "source-highlight" " -s " lst-lang " -f groff_man " diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el index f180660de..a7323c657 100644 --- a/lisp/ox-odt.el +++ b/lisp/ox-odt.el @@ -3111,7 +3111,7 @@ and prefix with \"OrgSrc\". For example, (defun org-odt-do-format-code (code info &optional lang refs retain-labels num-start) (let* ((lang (or (assoc-default lang org-src-lang-modes) lang)) - (lang-mode (and lang (intern (format "%s-mode" lang)))) + (lang-mode (if lang (intern (format "%s-mode" lang)) #'ignore)) (code-lines (org-split-string code "\n")) (code-length (length code-lines)) (use-htmlfontify-p (and (functionp lang-mode) diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el index ed2c3102e..bd01effaa 100644 --- a/lisp/ox-texinfo.el +++ b/lisp/ox-texinfo.el @@ -1681,8 +1681,9 @@ as a communication channel." "Transcode a SRC-BLOCK element from Org to Texinfo. CONTENTS holds the contents of the item. INFO is a plist holding contextual information." - (let* ((lisp (string-match-p "lisp" - (org-element-property :language src-block))) + (let* ((lisp (string-match-p + "lisp" + (or (org-element-property :language src-block) ""))) (code (org-texinfo--sanitize-content (org-export-format-code-default src-block info))) (value (format