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
    <<second>>
  #+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/
This commit is contained in:
Ihor Radchenko 2024-02-24 12:48:35 +03:00
parent 505778950a
commit f90322377c
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
4 changed files with 11 additions and 8 deletions

View File

@ -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))

View File

@ -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 "

View File

@ -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)

View File

@ -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