fix(org-latex): inhibit-modification-hooks in auto-tabularx to prevent recursion
The insert call in my/org-auto-tabularx triggered buffer-change hooks (e.g. org-element-cache) during LaTeX export, causing infinite recursion and 'max-lisp-eval-depth exceeded'. HTML export was unaffected (hook only runs for latex backend). Fix: wrap body in (let ((inhibit-modification-hooks t))).
This commit is contained in:
49
config.el
49
config.el
@@ -339,30 +339,33 @@ Bound to cmd+v in org-mode and markdown-mode."
|
||||
|
||||
;; Automatically insert #+ATTR_LATEX tabularx before tables on LaTeX export
|
||||
(defun my/org-auto-tabularx (backend)
|
||||
"Insert #+ATTR_LATEX tabularx before each table when exporting to LaTeX."
|
||||
"Insert #+ATTR_LATEX tabularx before each table when exporting to LaTeX.
|
||||
Uses inhibit-modification-hooks to prevent recursive hook calls during insert."
|
||||
(when (org-export-derived-backend-p backend 'latex)
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(while (not (eobp))
|
||||
(cond
|
||||
((looking-at "^|")
|
||||
(let ((prev-line (save-excursion
|
||||
(forward-line -1)
|
||||
(buffer-substring-no-properties
|
||||
(line-beginning-position) (line-end-position)))))
|
||||
(when (not (string-match-p "^|" prev-line))
|
||||
(when (not (string-match-p "^#\\+ATTR_LATEX" prev-line))
|
||||
(let* ((table-line (buffer-substring-no-properties
|
||||
(line-beginning-position) (line-end-position)))
|
||||
(ncols (my/org-count-table-columns table-line))
|
||||
(spec (my/org-table-attr-latex-spec ncols))
|
||||
(attr (format "#+ATTR_LATEX: :environment tabularx :width \\textwidth :align %s\n"
|
||||
spec)))
|
||||
(when (> ncols 0)
|
||||
(insert attr)))))
|
||||
(forward-line))
|
||||
(t
|
||||
(forward-line))))))))
|
||||
(let ((inhibit-modification-hooks t))
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(while (not (eobp))
|
||||
(cond
|
||||
((looking-at "^|")
|
||||
(let ((prev-line (save-excursion
|
||||
(forward-line -1)
|
||||
(buffer-substring-no-properties
|
||||
(line-beginning-position) (line-end-position)))))
|
||||
(when (not (string-match-p "^|" prev-line))
|
||||
(when (not (string-match-p "^#\\+ATTR_LATEX" prev-line))
|
||||
(let* ((table-line (buffer-substring-no-properties
|
||||
(line-beginning-position) (line-end-position)))
|
||||
(ncols (my/org-count-table-columns table-line))
|
||||
(spec (my/org-table-attr-latex-spec ncols))
|
||||
(attr (format "#+ATTR_LATEX: :environment tabularx :width \\textwidth :align %s\n"
|
||||
spec)))
|
||||
(when (> ncols 0)
|
||||
(insert attr)))))
|
||||
(forward-line))
|
||||
(t
|
||||
(forward-line)))))))))
|
||||
)
|
||||
|
||||
(add-hook 'org-export-before-processing-hook #'my/org-auto-tabularx)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user