abo-abo / lispy

Short and sweet LISP editing
http://oremacs.com/lispy/
1.19k stars 129 forks source link

`lispy--find-unmatched-delimiters` can go into infinite loop inside a comment #634

Open benjamin-asdf opened 2 years ago

benjamin-asdf commented 2 years ago
 ;; (foo)
   ;; (bar)
   ;; (baz)

you literally need a comment with this indentation, this is the only way I reproduced it.
Note that the first line is indented differently. It will infinetely loop there now. I can eval (lispy--find-safe-regions (point-min) (point-max)) to repro it.

tracing a few funs

1 -> (lispyville--safe-string 39 61 t)
| 2 -> (lispy--find-safe-regions 39 61)
| | 3 -> (lispy--find-unmatched-delimiters 39 61)
| | | 4 -> (lispy--bounds-comment)
| | | 4 <- lispy--bounds-comment: (40 . 48)
| | | 4 -> (lispy--bounds-comment)
| | | 4 <- lispy--bounds-comment: (40 . 48)
| | | 4 -> (lispy--bounds-comment)
| | | 4 <- lispy--bounds-comment: (40 . 48)
| | | 4 -> (lispy--bounds-comment)
| | | 4 <- lispy--bounds-comment: (40 . 48)
| | | 4 -> (lispy--bounds-comment)
| | | 4 <- lispy--bounds-comment: (40 . 48)
| | | 4 -> (lispy--bounds-comment)
| | | 4 <- lispy--bounds-comment: (40 . 48)
| | | 4 -> (lispy--bounds-comment)
| | | 4 <- lispy--bounds-comment: (40 . 48)
| | | 4 -> (lispy--bounds-comment)

stackrace I get by enableling debug-on-quit to true

  undo-auto--undoable-change()
  #f(compiled-function (body &rest args) #<bytecode 0x146b417629917a57>)((closure (t) nil "Return bounds of current comment." (and (lispy--in-comment-p) (save-excursion (when (lispy--beginning-of-comment) (let ((pt ...)) (while (and ... ... ... ...) (setq pt ...)) (goto-char pt)) (if (looking-at "#|") (cons (point) (progn ... ...)) (let (... ... ...) (while ... ...) (goto-char pt) (end-of-line) (cons beg ...))))))))
  apply(#f(compiled-function (body &rest args) #<bytecode 0x146b417629917a57>) (closure (t) nil "Return bounds of current comment." (and (lispy--in-comment-p) (save-excursion (when (lispy--beginning-of-comment) (let ((pt ...)) (while (and ... ... ... ...) (setq pt ...)) (goto-char pt)) (if (looking-at "#|") (cons (point) (progn ... ...)) (let (... ... ...) (while ... ...) (goto-char pt) (end-of-line) (cons beg ...))))))) nil)
  lispy--bounds-comment()
  #<subr lispy--find-unmatched-delimiters>(39 61)
  apply(#<subr lispy--find-unmatched-delimiters> (39 61))
  #f(compiled-function (body &rest args) #<bytecode 0x146b4126e2417a57>)(#<subr lispy--find-unmatched-delimiters> 39 61)
  apply(#f(compiled-function (body &rest args) #<bytecode 0x146b4126e2417a57>) #<subr lispy--find-unmatched-delimiters> (39 61))
  lispy--find-unmatched-delimiters(39 61)
  #<subr lispy--find-safe-regions>(39 61)
  apply(#<subr lispy--find-safe-regions> (39 61))
  #f(compiled-function (body &rest args) #<bytecode 0x146b4126eab97a57>)(#<subr lispy--find-safe-regions> 39 61)
  apply(#f(compiled-function (body &rest args) #<bytecode 0x146b4126eab97a57>) #<subr lispy--find-safe-regions> (39 61))
  lispy--find-safe-regions(39 61)
  #<subr lispyville--safe-string>(39 61 t)
  apply(#<subr lispyville--safe-string> (39 61 t))
  #f(compiled-function (body &rest args) #<bytecode -0x6e234237f8ae336>)(#<subr lispyville--safe-string> 39 61 t)
  apply(#f(compiled-function (body &rest args) #<bytecode -0x6e234237f8ae336>) #<subr lispyville--safe-string> (39 61 t))
  lispyville--safe-string(39 61 t)
  lispyville--safe-manipulate(39 61 line t t nil nil)
  lispyville-delete(39 61 line nil nil)
  funcall-interactively(lispyville-delete 39 61 line nil nil)
  command-execute(lispyville-delete)