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

eval-dante-block on first line of file causes infinite loop #182

Open
eppolito opened this issue Nov 27, 2024 · 0 comments
Open

eval-dante-block on first line of file causes infinite loop #182

eppolito opened this issue Nov 27, 2024 · 0 comments

Comments

@eppolito
Copy link

Description

When the first line of a file is a -- comment, an infinite loop is caused when dante-eval-block is evoked from anywhere within the corresponding comment block.

Steps to Reproduce

  1. Write a simple config file for dante and haskell packages, saving to PATH/TO/SIMPLE/CONFIG:
(let ((default-directory "PATH/TO/ELISP/DIRECTORY")) (normal-top-level-add-subdirs-to-load-path))
(require 'haskell)
(require 'dante)
(add-hook 'haskell-mode-hook 'dante-mode)
(provide 'init)
  1. Launch emacs with emacs -Q -l "PATH/TO/SIMPLE/CONFIG" "tmp.hs" (this also visits a haskell file).
  2. Add a dante block or comment to the first line of the file and position the point anywhere on the line.
-- >>> :t [1,2,3]
  1. Run dante-eval-block on that line (or don't---it will freeze emacs and chew up a ton of CPU).

Cause and Fix

The while condition at line 858 of dante.el always evaluates to non-nil in the case that the first line is a -- comment (and is reached by the loop).

You can verify this issue is caused by the while as follows: paste the snippet below into a new elisp buffer and run eval-last-sexp from the end of either progn expression.

--
--
--
--

(progn
  ;; place point on the last `--` above
  (beginning-of-buffer)
  (forward-line 3)
  ;; current: will enter an infinite loop
  (while (looking-at "[ \t]*--") (forward-line -1)))

(progn
  ;; place point on the last `--` above
  (beginning-of-buffer)
  (forward-line 3)
  ;; corrected: stops when `forward-line` can no longer make progress
  (while (and (looking-at "[ \t]*--") (eq 0 (forward-line -1)))))

Thus, this issue is fixed if line 858 of dante.el is replaced by the following:

(while (and (looking-at "[ \t]*--") (eq 0 (forward-line -1))))

I will submit a pull request shortly.

Related Note

The same trick used to fix this infinite loop can also simplify block-end's while loop a few lines prior. It currently works and this is not my code base, so I won't submit a pull request for that (unless you think it would be worthwhile to do so).

eppolito added a commit to eppolito/dante that referenced this issue Nov 27, 2024
When `dante-eval-block` finds a comment at the beginning of the file, it previously entered an infinite loop.  See Issue jyp#182 for a full description of the problem and code blocks to illustrate the issue and fix.
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

1 participant