I am using emacs 25.3 and I observe that one indentation function that I wrote loop mysteriously. My function goes following:
(defun aut-indent-func () (interactive) (defun loop (begin) (goto-char begin) (let* ((end (line-end-position 1)) (substr (buffer-substring-no-properties begin end))) (if (string-match-p (regexp-quote "=") substr) ; then we are in a definition line (let ((field (string-trim (substring-no-properties substr 0 (string-match (regexp-quote "=") substr))))) (string-equal field "transitions")) ; then we need to call recursively (if (/= begin (line-beginning-position 0)) (loop (line-beginning-position 0)))))) (if (save-excursion (loop (line-beginning-position 0))) (progn (indent-to-left-margin) (back-to-indentation) (indent-to-column (+ 2 (aut-eq-line-offset)))) (indent-relative)))
Essentially, it tries to loop over each line and try to identify a lines comes with
transitions = and put the indentation at the same column as the equal sign there.
However, this functions loops.
It's impossible, since it keep scanning up and stop when it hits the top. What's even more mysterious is, if I evaluate the function definition again, it stops looping, until the next time I open up emacs again(and the file containing this function got reloaded). So I do
M-x toggle-debug-on-quit, and it shows following:
Debugger entered--Lisp error: (quit) (while t (line-beginning-position 0)) (save-excursion (while t (line-beginning-position 0))) (if (save-excursion (while t (line-beginning-position 0))) (progn (indent-to-left-margin) (back-to-indentation) (indent-to-column (+ 2 (aut-eq-line-offset)))) (indent-relative)) aut-indent-func() indent-according-to-mode() electric-indent-post-self-insert-function() self-insert-command(1) newline(nil 1) funcall-interactively(newline nil 1) call-interactively(newline nil nil) command-execute(newline)
well, this trace shows something seriously insane. As you can tell from the code, there isn't
(while t ...), so who adds those? Is it a bug that emacs add
while automatically in some occasion?