Subject: Re: bug#16202: 24.3.50; lisp-mode's indent-sexp might be buggy (for slime in particular, and lisp in general)

From: [email-masked]
Date: Sat, 04 Mar 2017 16:39:34 -0500

tags 16202 notabug
quit

[email-masked] (João Távora) writes:

> Hi maintainers,
>
> This was started by bug reports in the slime-devel mailing list
>
>   http://comments.gmane.org/gmane.lisp.slime.devel/11196
>   http://comments.gmane.org/gmane.lisp.slime.devel/11189
>
> The reproduction recipe described in these messages requires,
> unfortunately, that you install slime.

Unfortunately, it no longer works with current slime.

    Debugger entered--Lisp error: (void-function common-lisp-run-indentation-tests)

I can't find a definition of common-lisp-run-indentation-tests anywhere
in slime's code.

>
> which indented the two comment lines to comment-column, I think. The
> patch I attach at the end of this message fixes it.
>
> ...as does indenting the sexp with indent-region. This might be naive,
> but why not super-simplify indent-sexp to be something like this?

Both your patch and indent-region do not indent comments that occur
after code.  But I don't think doing this indentation is a bug, rather,
slime should change `comment-indent-function' and/or
`comment-insert-comment-function' so that comments will be indented in
the way it expects.

>   	;; unless a line ends inside a string.
>   	(while (and (not inner-loop-done)
>   		    (not (setq outer-loop-done (eobp))))
> + 	  (setq before-parse (point))
>   	  (setq state (parse-partial-sexp (point) (progn (end-of-line) (point))
>   					  nil nil state))
>   	  (setq next-depth (car state))
> ! 	  ;; If the line contains nothing but a comment other than the sort that
> ! 	  ;; is indented like code, indent it now with indent-for-comment.
> ! 	  ;; Comments indented like code are right already.  In any case clear
> ! 	  ;; the in-comment flag in the state because parse-partial-sexp never
> ! 	  ;; sees the newlines.
> ! 	  (when (car (nthcdr 4 state))
> !             (when (<= (nth 8 state) before-parse)

I think this would only indent comments starting at the beginning of the
line, which never need to be indented anyway...

> !               (indent-for-comment)
> !               (end-of-line))
> !             (setcar (nthcdr 4 state) nil))