Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable binding depth exceeds max-specpdl-size when document has too many code blocks #512

Closed
raxod502 opened this issue Jul 9, 2020 · 3 comments

Comments

@raxod502
Copy link
Contributor

raxod502 commented Jul 9, 2020

Expected Behavior

markdown-mode should have no problem with documents that have many code blocks.

Actual Behavior

When viewing a file that has enough code blocks (on the order of 1000), the following error occurs:

File mode specification error: (error Variable binding depth exceeds max-specpdl-size)

This is because markdown-syntax-propertize-pre-blocks is implemented recursively although there is no reason to assume that the number of loop iterations will be bounded by a reasonable constant.

markdown-mode/markdown-mode.el

Lines 1234 to 1235 in 399df42

;; Recursively search again
(markdown-syntax-propertize-pre-blocks (point) end)))))

Steps to Reproduce

Open this file. The error occurs.

Backtrace

Backtrace

Debugger entered--Lisp error: (error "Lisp nesting exceeds ‘max-lisp-eval-depth’")
  (= (current-indentation) 0)
  (and (= (current-indentation) 0) (not (looking-at markdown-regex-list)) (markdown-prev-line-blank))
  (or (looking-at markdown-regex-header) (looking-at markdown-regex-hr) (and (= (current-indentation) 0) (not (looking-at markdown-regex-list)) (markdown-prev-line-blank)))
  markdown-new-baseline()
  (cond ((markdown-new-baseline) (setq stop t)) ((looking-at-p markdown-regex-list) (setq stop nil)) (t (setq stop t)))
  (progn (goto-char (match-end 2)) (cond ((markdown-new-baseline) (setq stop t)) ((looking-at-p markdown-regex-list) (setq stop nil)) (t (setq stop t))))
  (if (match-end 2) (progn (goto-char (match-end 2)) (cond ((markdown-new-baseline) (setq stop t)) ((looking-at-p markdown-regex-list) (setq stop nil)) (t (setq stop t)))))
  (while (not (or stop (bobp))) (re-search-backward markdown-regex-block-separator-noindent nil t) (if (match-end 2) (progn (goto-char (match-end 2)) (cond ((markdown-new-baseline) (setq stop t)) ((looking-at-p$
  (let (stop) (while (not (or stop (bobp))) (re-search-backward markdown-regex-block-separator-noindent nil t) (if (match-end 2) (progn (goto-char (match-end 2)) (cond ((markdown-new-baseline) (setq stop t)) (($
  markdown-search-backward-baseline()
  (let ((first (point)) levels indent pre-regexp) (markdown-search-backward-baseline) (while (and (< (point) first) (re-search-forward markdown-regex-list first t)) (setq pre-regexp (format "^\\(    \\|\11\\)\\$
  (save-excursion (let ((first (point)) levels indent pre-regexp) (markdown-search-backward-baseline) (while (and (< (point) first) (re-search-forward markdown-regex-list first t)) (setq pre-regexp (format "^\\$
  markdown-calculate-list-levels()
  (let ((levels (markdown-calculate-list-levels)) indent pre-regexp close-regexp open close) (while (and (< (point) end) (not close)) (if (null levels) (setq indent 1) (setq indent (1+ (length levels)))) (setq $
  (save-excursion (goto-char start) (let ((levels (markdown-calculate-list-levels)) indent pre-regexp close-regexp open close) (while (and (< (point) end) (not close)) (if (null levels) (setq indent 1) (setq in$
  markdown-syntax-propertize-pre-blocks(2141 37366)
  (progn (put-text-property open close 'markdown-pre (list open close)) (markdown-syntax-propertize-pre-blocks (point) end))
  (if (and open close) (progn (put-text-property open close 'markdown-pre (list open close)) (markdown-syntax-propertize-pre-blocks (point) end)))
  (let ((levels (markdown-calculate-list-levels)) indent pre-regexp close-regexp open close) (while (and (< (point) end) (not close)) (if (null levels) (setq indent 1) (setq indent (1+ (length levels)))) (setq $
  (save-excursion (goto-char start) (let ((levels (markdown-calculate-list-levels)) indent pre-regexp close-regexp open close) (while (and (< (point) end) (not close)) (if (null levels) (setq indent 1) (setq in$
  markdown-syntax-propertize-pre-blocks(2127 37366)
  (progn (put-text-property open close 'markdown-pre (list open close)) (markdown-syntax-propertize-pre-blocks (point) end))
  (if (and open close) (progn (put-text-property open close 'markdown-pre (list open close)) (markdown-syntax-propertize-pre-blocks (point) end)))
  (let ((levels (markdown-calculate-list-levels)) indent pre-regexp close-regexp open close) (while (and (< (point) end) (not close)) (if (null levels) (setq indent 1) (setq indent (1+ (length levels)))) (setq $
  (save-excursion (goto-char start) (let ((levels (markdown-calculate-list-levels)) indent pre-regexp close-regexp open close) (while (and (< (point) end) (not close)) (if (null levels) (setq indent 1) (setq in$
  markdown-syntax-propertize-pre-blocks(2113 37366)
  (progn (put-text-property open close 'markdown-pre (list open close)) (markdown-syntax-propertize-pre-blocks (point) end))
  (if (and open close) (progn (put-text-property open close 'markdown-pre (list open close)) (markdown-syntax-propertize-pre-blocks (point) end)))
  (let ((levels (markdown-calculate-list-levels)) indent pre-regexp close-regexp open close) (while (and (< (point) end) (not close)) (if (null levels) (setq indent 1) (setq indent (1+ (length levels)))) (setq $
  (save-excursion (goto-char start) (let ((levels (markdown-calculate-list-levels)) indent pre-regexp close-regexp open close) (while (and (< (point) end) (not close)) (if (null levels) (setq indent 1) (setq in$

... and so on ...

  markdown-syntax-propertize-pre-blocks(27 37366)                                                                                                                                                                  
  (progn (put-text-property open close 'markdown-pre (list open close)) (markdown-syntax-propertize-pre-blocks (point) end))                                                                                       
  (if (and open close) (progn (put-text-property open close 'markdown-pre (list open close)) (markdown-syntax-propertize-pre-blocks (point) end)))                                                                 
  (let ((levels (markdown-calculate-list-levels)) indent pre-regexp close-regexp open close) (while (and (< (point) end) (not close)) (if (null levels) (setq indent 1) (setq indent (1+ (length levels)))) (setq $
  (save-excursion (goto-char start) (let ((levels (markdown-calculate-list-levels)) indent pre-regexp close-regexp open close) (while (and (< (point) end) (not close)) (if (null levels) (setq indent 1) (setq in$
  markdown-syntax-propertize-pre-blocks(13 37366)                                                                                                                                                                  
  (progn (put-text-property open close 'markdown-pre (list open close)) (markdown-syntax-propertize-pre-blocks (point) end))                                                                                       
  (if (and open close) (progn (put-text-property open close 'markdown-pre (list open close)) (markdown-syntax-propertize-pre-blocks (point) end)))                                                                 
  (let ((levels (markdown-calculate-list-levels)) indent pre-regexp close-regexp open close) (while (and (< (point) end) (not close)) (if (null levels) (setq indent 1) (setq indent (1+ (length levels)))) (setq $
  (save-excursion (goto-char start) (let ((levels (markdown-calculate-list-levels)) indent pre-regexp close-regexp open close) (while (and (< (point) end) (not close)) (if (null levels) (setq indent 1) (setq in$
  markdown-syntax-propertize-pre-blocks(1 37366)                                                                                                                                                                   
  (save-excursion (remove-text-properties start end markdown--syntax-properties) (markdown-syntax-propertize-fenced-block-constructs start end) (markdown-syntax-propertize-list-items start end) (markdown-syntax$
  (progn (save-excursion (remove-text-properties start end markdown--syntax-properties) (markdown-syntax-propertize-fenced-block-constructs start end) (markdown-syntax-propertize-list-items start end) (markdown$
  (unwind-protect (progn (save-excursion (remove-text-properties start end markdown--syntax-properties) (markdown-syntax-propertize-fenced-block-constructs start end) (markdown-syntax-propertize-list-items star$
  (let* ((modified (buffer-modified-p)) (buffer-undo-list t) (inhibit-read-only t) (inhibit-modification-hooks t)) (unwind-protect (progn (save-excursion (remove-text-properties start end markdown--syntax-prope$
  markdown-syntax-propertize(1 37366)                                                                                                                                                                              
  syntax-propertize(37366)                                                                                                                                                                                         
  (let ((delay-mode-hooks t)) (text-mode) (setq major-mode 'markdown-mode) (setq mode-name "Markdown") (progn (if (get 'text-mode 'mode-class) (put 'markdown-mode 'mode-class (get 'text-mode 'mode-class))) (if $
  (progn (make-local-variable 'delay-mode-hooks) (let ((delay-mode-hooks t)) (text-mode) (setq major-mode 'markdown-mode) (setq mode-name "Markdown") (progn (if (get 'text-mode 'mode-class) (put 'markdown-mode $
  markdown-mode()                                                                                                                                                                                                  
  set-auto-mode-0(markdown-mode nil)                                                                                                                                                                               
  set-auto-mode()                                                                                                                                                                                                  
  normal-mode(t)                                                                                                                                                                                                   
  after-find-file(nil t)                                                                                                                                                                                           
  find-file-noselect-1(#<buffer example.md> "~/files/temp/example.md" nil nil "~/files/temp/example.md" (18221111 66309))                                                                                          
  find-file-noselect("~/files/temp/example.md" nil nil t)                                                                                                                                                          
  find-alternate-file("~/files/temp/example.md" t)                                                                                                                                                                 
  funcall-interactively(find-alternate-file "~/files/temp/example.md" t)                                                                                                                                           
  call-interactively(find-alternate-file nil nil)                                                                                                                                                                  
  command-execute(find-alternate-file)                                                                                                                                                                             

Software Versions

  • markdown-mode commit 399df42 of 2020-06-22
  • emacs 28.0.5.0 of 2020-06-28
  • os: Manjaro
@raxod502
Copy link
Contributor Author

raxod502 commented Aug 1, 2020

A simple workaround is to increase the values of max-specpdl-size and max-lisp-eval-depth, as follows:

(setq max-specpdl-size 16000)
(setq max-lisp-eval-depth 8000)

@syohex
Copy link
Collaborator

syohex commented Sep 9, 2020

Sorry berated reply. I have merged #544. Please check latest version.
Thanks for reporting issue

@syohex syohex closed this as completed Sep 9, 2020
@raxod502
Copy link
Contributor Author

Nailed it! I can definitely confirm this fixes the issue :)
No longer will my init-file contain a weird hack to bump max-specpdl-size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants