Simplify `org-latex-engraved-source-block-filter'

This commit is contained in:
Gerard Vermeulen 2024-02-10 10:20:10 +01:00
parent e7c4bbbe6d
commit c943430f8d

View File

@ -3494,21 +3494,13 @@ environment and an unbreakable Code (floating) environment."
org-latex-engraved-preamble)
(user-error "`org-latex-engraved-preamble' defines no `Breakable' environment"))
(when (eq org-latex-src-block-backend 'engraved)
(let ((enter "^\\\\begin{Code}\n\\\\begin{Verbatim}")
(leave "^\\\\end{Verbatim}\n\\\\end{Code}"))
;; Transform only blocks matching the enter regexp at position 0.
;; Do not transform blocks that are listing environments.
(when (and (string-match enter data) (eql 0 (match-beginning 0)))
(setq data (replace-match
"\\begin{Breakable}\n\\begin{Verbatim}" t t data))
(when (string-match leave data (match-end 0))
(setq data (replace-match
"\\end{Verbatim}\n\\end{Breakable}" t t data))
(when (string-match enter data)
(user-error "The `enter' regexp `%s' should not match" enter))
(when (string-match leave data)
(user-error "The `leave' regexp `%s' should not match" leave))
data)))))
;; Transform only blocks matching at position 0. Therefore, do
;; not transform blocks that are listing environments.
(when (string-match "\\`\\\\begin{Code}\n" data)
(setq data (replace-match "\\begin{Breakable}\n" t 'literal data))
(if (string-match "^\\\\end{Code}\n" data)
(setq data (replace-match "\\end{Breakable}\n" t 'literal data))
(error "Match `^\\\\end{Code}' failure")))))
#+end_src
#+caption[Smart LaTeX engraving of =org-src-mode= blocks]: