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: Sun, 05 Mar 2017 01:12:45 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)

tags 21343 patch
quit

address@hidden writes:

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

Actually, it turns out using syntax-ppss in the loop is slower, at least
in the case of calling `pp' on a big list (which is a pessimal case for
a cache based parser).

Here is a patch (the first one just simplifies the code).

Attachment: v1-0001-lisp-emacs-lisp-lisp-mode.el-indent-sexp-Simplify.patch
Description: patch

>From b318e8c0bdd0f08b49f7f8c635bf886d967bc742 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <address@hidden>
Date: Sun, 5 Mar 2017 00:53:58 -0500
Subject: [PATCH v1 2/2] Fix indent-sexp when called from inside a string
 (Bug#21343)

* lisp/emacs-lisp/lisp-mode.el (indent-sexp): Get initial syntax parse
state from `syntax-ppss'.
---
 lisp/emacs-lisp/lisp-mode.el | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el
index de0e66039a..ce61c69f3c 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -1062,10 +1062,14 @@ indent-sexp
          ;; since every line we indent is more deeply nested than point is.
          (starting-point (save-excursion (if endpos (beginning-of-defun))
                                          (point)))
-         (state nil)
-         (init-depth 0)
-         (next-depth 0)
-         (last-depth 0)
+         ;; Use `syntax-ppss' to get initial state so we don't get
+         ;; confused by starting inside a string.  We don't use
+         ;; `syntax-ppss' in the loop, because this is measurably
+         ;; slower when we're called on a long list.
+         (state (syntax-ppss))
+         (init-depth (car state))
+         (next-depth init-depth)
+         (last-depth init-depth)
          (last-syntax-point (point)))
     (unless endpos
       ;; Get error now if we don't have a complete sexp after point.
-- 
2.11.1


reply via email to

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