From 457b9d3d4c90ec9195b966388d9bea2b903c1672 Mon Sep 17 00:00:00 2001 From: Daneel Date: Mon, 23 Feb 2026 14:44:32 +0100 Subject: [PATCH] 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))). --- config.el | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/config.el b/config.el index 2fc4ba0..84a264e 100644 --- a/config.el +++ b/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)