all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: npostavs@users.sourceforge.net
To: Oleh Krehel <ohwoeowho@gmail.com>
Cc: 21343@debbugs.gnu.org
Subject: bug#21343: 24.5; parse-partial-sexp mistakes string for a comment
Date: Sat, 02 Jul 2016 22:40:56 -0400	[thread overview]
Message-ID: <87lh1jfnpj.fsf@users.sourceforge.net> (raw)
In-Reply-To: <87pp2awaqp.fsf@gmail.com> (Oleh Krehel's message of "Wed, 26 Aug 2015 13:27:26 +0200")

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))






  parent reply	other threads:[~2016-07-03  2:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-25 13:11 bug#21343: 24.5; parse-partial-sexp mistakes string for a comment Oleh Krehel
2015-08-25 17:45 ` Andreas Röhler
2015-08-26 11:27   ` Oleh Krehel
2015-08-26 14:52     ` Andreas Röhler
2016-07-03  2:40     ` npostavs [this message]
2017-03-05  6:12       ` npostavs
2017-03-05 13:59         ` npostavs
2017-03-13  0:15           ` npostavs

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lh1jfnpj.fsf@users.sourceforge.net \
    --to=npostavs@users.sourceforge.net \
    --cc=21343@debbugs.gnu.org \
    --cc=ohwoeowho@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.