bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#21343: 24.5; parse-partial-sexp mistakes string for a comment


From: npostavs
Subject: bug#21343: 24.5; parse-partial-sexp mistakes string for a comment
Date: Sat, 02 Jul 2016 22:40:56 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.93 (gnu/linux)

tags 21343 confirmed
quit

Oleh Krehel <ohwoeowho@gmail.com> writes:

>> Am 25.08.2015 um 15:11 schrieb Oleh Krehel:
>>> To reproduce, paste this code into *scratch*, "|" is the point:
>>>
>>> ("|foo"
>>>   ";; (bar)")
>>>
>>> M-x indent-sexp will result in "    ;" being inserted after the sexp.
>
> `parse-partial-sexp' will detect comment on line 2 only when called in a
> sequence that `indent-sexp' calls it, i.e. with the previous pps data
> passed to the second pps call.

In fact, the problem already occurs on the 1st line: calling
`parse-partial-sexp' from within a string gives wrong results, since it
doesn't look at the starting quote.  You can reproduce the bug with just

"|;"

A solution could be to use syntax-ppss to go to start of string before
parsing (though I wonder if syntax-ppss should be used more for the
parsing itself in that case, it seems like there's a lot of work going
that probably duplicates what's already being done):

diff --git c/lisp/emacs-lisp/lisp-mode.el i/lisp/emacs-lisp/lisp-mode.el
index a277d7a..8b5efa3 100644
--- c/lisp/emacs-lisp/lisp-mode.el
+++ i/lisp/emacs-lisp/lisp-mode.el
@@ -1070,6 +1070,10 @@ indent-sexp
        ;; Get error now if we don't have a complete sexp after point.
        (save-excursion (forward-sexp 1)))
     (save-excursion
+      (let ((syn-start (nth 8 (syntax-ppss))))
+        (when syn-start
+          (unless endpos (setq starting-point syn-start))
+          (goto-char syn-start)))
       (setq outer-loop-done nil)
       (while (if endpos (< (point) endpos)
               (not outer-loop-done))






reply via email to

[Prev in Thread] Current Thread [Next in Thread]