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
- 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)
- Launch emacs with
emacs -Q -l "PATH/TO/SIMPLE/CONFIG" "tmp.hs" (this also visits a haskell file).
- Add a dante block or comment to the first line of the file and position the point anywhere on the line.
- 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).
Description
When the first line of a file is a
--comment, an infinite loop is caused whendante-eval-blockis evoked from anywhere within the corresponding comment block.Steps to Reproduce
danteandhaskellpackages, saving toPATH/TO/SIMPLE/CONFIG:emacs -Q -l "PATH/TO/SIMPLE/CONFIG" "tmp.hs"(this also visits a haskell file).-- >>> :t [1,2,3]dante-eval-blockon that line (or don't---it will freeze emacs and chew up a ton of CPU).Cause and Fix
The
whilecondition at line 858 ofdante.elalways 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
whileas follows: paste the snippet below into a new elisp buffer and runeval-last-sexpfrom the end of eitherprognexpression.Thus, this issue is fixed if line 858 of
dante.elis replaced by the following: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).