unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: npostavs@users.sourceforge.net
To: Thierry Volpiatto <thierry.volpiatto@gmail.com>
Cc: 25122@debbugs.gnu.org, Stefan Monnier <monnier@iro.umontreal.ca>,
	Boruch Baum <boruch_baum@gmx.com>
Subject: bug#25122: 24.5; function describe-variable hangs on large variables
Date: Mon, 13 Mar 2017 00:47:38 -0400	[thread overview]
Message-ID: <87lgs97pg5.fsf@users.sourceforge.net> (raw)
In-Reply-To: <87r32278wf.fsf@users.sourceforge.net> (npostavs@users.sourceforge.net's message of "Sun, 12 Mar 2017 12:32:48 -0400")

[-- Attachment #1: Type: text/plain, Size: 258 bytes --]

tags 25122 patch
quit

npostavs@users.sourceforge.net writes:

> Also, this doesn't really solve the performance problem, it just makes
> it much less likely to occur, e.g., (pp (list load-history)) is still
> slow.

Okay, I think I found the real fix now:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 3568 bytes --]

From 5188d6e366426d83934505296b585744f50e24a5 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Sun, 12 Mar 2017 23:59:19 -0400
Subject: [PATCH] Don't reparse the sexp in indent-sexp (Bug#25122)

* lisp/emacs-lisp/lisp-mode.el (calculate-lisp-indent): Let
PARSE-START be a parse state that can be reused.
(indent-sexp): Pass the running parse state to calculate-lisp-indent
instead of the sexp beginning position.
---
 lisp/emacs-lisp/lisp-mode.el | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el
index eb07c18b03..8d4abc24e8 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -781,6 +781,10 @@ calculate-lisp-indent
 If the value is nil, that means don't change the indentation
 because the line starts inside a string.
 
+PARSE-START may be a buffer position to start parsing from, or a
+parse state as returned by calling `parse-partial-sexp' up to the
+beginning of the current line.
+
 The value can also be a list of the form (COLUMN CONTAINING-SEXP-START).
 This means that following lines at the same level of indentation
 should not necessarily be indented the same as this line.
@@ -794,12 +798,14 @@ calculate-lisp-indent
           (desired-indent nil)
           (retry t)
           calculate-lisp-indent-last-sexp containing-sexp)
-      (if parse-start
-          (goto-char parse-start)
-          (beginning-of-defun))
-      ;; Find outermost containing sexp
-      (while (< (point) indent-point)
-        (setq state (parse-partial-sexp (point) indent-point 0)))
+      (cond ((or (markerp parse-start) (integerp parse-start))
+             (goto-char parse-start))
+            ((null parse-start) (beginning-of-defun))
+            (t (setq state parse-start)))
+      (unless state
+        ;; Find outermost containing sexp
+        (while (< (point) indent-point)
+          (setq state (parse-partial-sexp (point) indent-point 0))))
       ;; Find innermost containing sexp
       (while (and retry
 		  state
@@ -1070,11 +1076,6 @@ indent-sexp
 ENDPOS is encountered."
   (interactive)
   (let* ((indent-stack (list nil))
-         ;; If ENDPOS is non-nil, use beginning of defun as STARTING-POINT.
-         ;; If ENDPOS is nil, it is safe not to scan before point
-         ;; since every line we indent is more deeply nested than point is.
-         (starting-point (save-excursion (if endpos (beginning-of-defun))
-                                         (point)))
          ;; 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
@@ -1132,8 +1133,12 @@ indent-sexp
           (unless (or (eolp) (eq (char-syntax (char-after)) ?<))
             (let ((this-indent (car indent-stack)))
               (when (listp this-indent)
-                (let ((val (calculate-lisp-indent
-                            (or (car this-indent) starting-point))))
+                ;; The state here is actually to the end of the
+                ;; previous line, but that's fine for our purposes.
+                ;; And continuing the parse to the next line would
+                ;; destroy element 2 (last sexp position) which
+                ;; `calculate-lisp-indent' needs.
+                (let ((val (calculate-lisp-indent state)))
                   (setq
                    this-indent
                    (cond ((integerp val)
-- 
2.11.1


  reply	other threads:[~2017-03-13  4:47 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-06  2:21 bug#25122: 24.5; function describe-variable hangs on large variables Boruch Baum
2016-12-06  6:41 ` Thierry Volpiatto
2016-12-07  3:50   ` npostavs
2016-12-07  8:58     ` Thierry Volpiatto
2017-03-11  5:40       ` npostavs
2017-03-11 15:33         ` Stefan Monnier
2017-03-11 19:29           ` Thierry Volpiatto
2017-03-11 21:59             ` npostavs
2017-03-11 23:55               ` Drew Adams
2017-03-12  5:57               ` Thierry Volpiatto
2017-03-12 14:07                 ` Stefan Monnier
2017-03-12 14:15                 ` npostavs
2017-03-12 14:59                   ` Drew Adams
2017-03-12 16:29                   ` Stefan Monnier
2017-03-12 16:32                   ` npostavs
2017-03-13  4:47                     ` npostavs [this message]
2017-03-13 14:01                       ` npostavs
2017-03-16  2:54                         ` npostavs
2017-04-18  3:53                           ` npostavs
2017-04-22 18:25                             ` npostavs
2017-04-26  3:57                               ` Michael Heerdegen
2017-04-26 10:35                                 ` Michael Heerdegen
2017-03-11 19:34         ` Thierry Volpiatto
2017-03-12 16:07           ` npostavs
2017-03-11 15:21   ` Stefan Monnier
2017-03-11 15:35     ` npostavs
2017-03-11 19:26     ` Thierry Volpiatto

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87lgs97pg5.fsf@users.sourceforge.net \
    --to=npostavs@users.sourceforge.net \
    --cc=25122@debbugs.gnu.org \
    --cc=boruch_baum@gmx.com \
    --cc=monnier@iro.umontreal.ca \
    --cc=thierry.volpiatto@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 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).