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
|
;; Automatically insert #+ATTR_LATEX tabularx before tables on LaTeX export
|
||||||
(defun my/org-auto-tabularx (backend)
|
(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)
|
(when (org-export-derived-backend-p backend 'latex)
|
||||||
(save-excursion
|
(let ((inhibit-modification-hooks t))
|
||||||
(goto-char (point-min))
|
(save-excursion
|
||||||
(while (not (eobp))
|
(goto-char (point-min))
|
||||||
(cond
|
(while (not (eobp))
|
||||||
((looking-at "^|")
|
(cond
|
||||||
(let ((prev-line (save-excursion
|
((looking-at "^|")
|
||||||
(forward-line -1)
|
(let ((prev-line (save-excursion
|
||||||
(buffer-substring-no-properties
|
(forward-line -1)
|
||||||
(line-beginning-position) (line-end-position)))))
|
(buffer-substring-no-properties
|
||||||
(when (not (string-match-p "^|" prev-line))
|
(line-beginning-position) (line-end-position)))))
|
||||||
(when (not (string-match-p "^#\\+ATTR_LATEX" prev-line))
|
(when (not (string-match-p "^|" prev-line))
|
||||||
(let* ((table-line (buffer-substring-no-properties
|
(when (not (string-match-p "^#\\+ATTR_LATEX" prev-line))
|
||||||
(line-beginning-position) (line-end-position)))
|
(let* ((table-line (buffer-substring-no-properties
|
||||||
(ncols (my/org-count-table-columns table-line))
|
(line-beginning-position) (line-end-position)))
|
||||||
(spec (my/org-table-attr-latex-spec ncols))
|
(ncols (my/org-count-table-columns table-line))
|
||||||
(attr (format "#+ATTR_LATEX: :environment tabularx :width \\textwidth :align %s\n"
|
(spec (my/org-table-attr-latex-spec ncols))
|
||||||
spec)))
|
(attr (format "#+ATTR_LATEX: :environment tabularx :width \\textwidth :align %s\n"
|
||||||
(when (> ncols 0)
|
spec)))
|
||||||
(insert attr)))))
|
(when (> ncols 0)
|
||||||
(forward-line))
|
(insert attr)))))
|
||||||
(t
|
(forward-line))
|
||||||
(forward-line))))))))
|
(t
|
||||||
|
(forward-line)))))))))
|
||||||
|
)
|
||||||
|
|
||||||
(add-hook 'org-export-before-processing-hook #'my/org-auto-tabularx)
|
(add-hook 'org-export-before-processing-hook #'my/org-auto-tabularx)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user