unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#16202: 24.3.50; lisp-mode's indent-sexp might be buggy (for slime in particular, and lisp in general)
@ 2013-12-20 15:08 João Távora
  2016-07-14  1:47 ` npostavs
  2017-03-04 21:39 ` npostavs
  0 siblings, 2 replies; 4+ messages in thread
From: João Távora @ 2013-12-20 15:08 UTC (permalink / raw)
  To: 16202

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.

However, I do think there is a slight bug on emacs's side (which is
probably not visible in emacs-lisp's testing rules). You see, the common
lisp loop macro likes its comments indented like (this is slime's test
nr 11).

   (loop when foo
           do (fubar)
           and collect cash
         else do ;; this is the body of the first else
                 ;; the body is ...
                 (indented to the above comment)
                 (ZMACS gets this wrong)
         do
         when funny-predicate do ;; Here's a comment
                                 (body filled to comment))

and sometimes indent-sexp insists on

   (loop when foo
           do (fubar)
           and collect cash
         else do       ;; this is the body of the first else
                       ;; the body is ...
                 (indented to the above comment)
                 (ZMACS gets this wrong)
         do
         when funny-predicate do ;; Here's a comment
                                 (body filled to comment))

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?

   (defun indent-sexp (&optional endpos)
     (interactive)
     (if endpos
         (indent-region (point) endpos)
       (indent-region (point) (save-excursion
                                (forward-sexp 1)
                                (point)))))

Thanks,
João

*** d:/joaot/Vendor/emacs-24.3.5-old/share/emacs/24.3.50/lisp/emacs-lisp/lisp-mode.el
--- #<buffer lisp-mode.el|emacs-24.3.5-old>
***************
*** 1578,1596 ****
  	;; unless a line ends inside a string.
  	(while (and (not inner-loop-done)
  		    (not (setq outer-loop-done (eobp))))
  	  (setq state (parse-partial-sexp (point) (progn (end-of-line) (point))
  					  nil nil state))
  	  (setq next-depth (car state))
! 	  ;; If the line contains 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.
! 	  (if (car (nthcdr 4 state))
! 	      (progn (indent-for-comment)
! 		     (end-of-line)
! 		     (setcar (nthcdr 4 state) nil)))
  	  ;; If this line ends inside a string,
  	  ;; go straight to next line, remaining within the inner loop,
  	  ;; and turn off the \-flag.
--- 1578,1597 ----
  	;; 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)
!               (indent-for-comment)
!               (end-of-line))
!             (setcar (nthcdr 4 state) nil))
  	  ;; If this line ends inside a string,
  	  ;; go straight to next line, remaining within the inner loop,
  	  ;; and turn off the \-flag.

Diff finished.  Fri Dec 20 13:30:32 2013





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-12-17  2:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-20 15:08 bug#16202: 24.3.50; lisp-mode's indent-sexp might be buggy (for slime in particular, and lisp in general) João Távora
2016-07-14  1:47 ` npostavs
2017-03-04 21:39 ` npostavs
2017-12-17  2:18   ` Noam Postavsky

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).