From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: npostavs@users.sourceforge.net Newsgroups: gmane.emacs.bugs Subject: bug#25122: 24.5; function describe-variable hangs on large variables Date: Wed, 15 Mar 2017 22:54:24 -0400 Message-ID: <878to653tr.fsf@users.sourceforge.net> References: <20161206022112.GF25778@E15-2016.optimum.net> <87twahk19y.fsf@gmail.com> <87d1h4fld5.fsf@users.sourceforge.net> <871sxkyv2m.fsf@gmail.com> <87mvcs8j7w.fsf@users.sourceforge.net> <87lgsbtxwe.fsf@gmail.com> <871su38ogm.fsf@users.sourceforge.net> <87d1dnrq96.fsf@gmail.com> <87wpbu7f9i.fsf@users.sourceforge.net> <87r32278wf.fsf@users.sourceforge.net> <87lgs97pg5.fsf@users.sourceforge.net> <87innd6zti.fsf@users.sourceforge.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1489632884 15836 195.159.176.226 (16 Mar 2017 02:54:44 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 16 Mar 2017 02:54:44 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) Cc: 25122@debbugs.gnu.org, Stefan Monnier , Boruch Baum To: Thierry Volpiatto Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Mar 16 03:54:37 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1coLYi-0003C5-AQ for geb-bug-gnu-emacs@m.gmane.org; Thu, 16 Mar 2017 03:54:36 +0100 Original-Received: from localhost ([::1]:40559 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coLYm-0006wk-SK for geb-bug-gnu-emacs@m.gmane.org; Wed, 15 Mar 2017 22:54:40 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54017) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coLYD-0006dK-8q for bug-gnu-emacs@gnu.org; Wed, 15 Mar 2017 22:54:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1coLYA-0002Ww-5c for bug-gnu-emacs@gnu.org; Wed, 15 Mar 2017 22:54:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:59593) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1coLYA-0002Wr-06 for bug-gnu-emacs@gnu.org; Wed, 15 Mar 2017 22:54:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1coLY9-0003o6-Me for bug-gnu-emacs@gnu.org; Wed, 15 Mar 2017 22:54:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: npostavs@users.sourceforge.net Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 16 Mar 2017 02:54:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25122 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 25122-submit@debbugs.gnu.org id=B25122.148963279714573 (code B ref 25122); Thu, 16 Mar 2017 02:54:01 +0000 Original-Received: (at 25122) by debbugs.gnu.org; 16 Mar 2017 02:53:17 +0000 Original-Received: from localhost ([127.0.0.1]:57792 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1coLXR-0003mz-C3 for submit@debbugs.gnu.org; Wed, 15 Mar 2017 22:53:17 -0400 Original-Received: from mail-it0-f67.google.com ([209.85.214.67]:34206) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1coLXP-0003mh-2N for 25122@debbugs.gnu.org; Wed, 15 Mar 2017 22:53:15 -0400 Original-Received: by mail-it0-f67.google.com with SMTP id r141so5049161ita.1 for <25122@debbugs.gnu.org>; Wed, 15 Mar 2017 19:53:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=MdPBWcA7Zs9nZl3pX2HPrHTur8ES56gcGrJ0XXcTpyw=; b=PRfk6HOqidWoYAaDFqVGk0OkNrJbBtbC+4i/u4U3YlApLk2efSCye8pI7M5vK3uDh6 SI4UiALfRV+2sp1n0GlMpxXFWO6Qv+mKiwgERoszvp64F8sMyhsx5e9KclKi//T5FBT3 ihmEbv+bzkLKci/W8/3g+xoYZ92RLl4NOCeBHamD7h25W3dsLjsO1HCJ/a8a1xVOAmLS brn7NKlgJPpBfDZOuNltB37Emn1igPWp/NpXtcPGl9TbBYZfKEE9hX5lBWnyGEQeuhMY FDedDvRogXULvFT3SZzvh2iofvGoL26sqrgYtX1QquIAzaqOweOuSd/pnM3o+7zRBSN7 dg+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=MdPBWcA7Zs9nZl3pX2HPrHTur8ES56gcGrJ0XXcTpyw=; b=Y+gAh0c86idayZSEVtgCXZ50d8RL9pVbVwgjdKAMpUCSUFDvo5wsktA+CvoA6TOYUe yON1qT/TAZu+o+YnNoHcGbezr1rxj+0LXoPLC8+G4AL7EsrsfW4w+lhXBDxUGu34LCWV zr4EuVH/Yaqg3vbpxrjwPgLXM369YgvxlJQGGtSg3UnMFi2HJdGHQuizWMnT0qV+xbZu ZClCSUoLbDxikAa2NKguzCGEPHUucOBf0IYoYtP6gAwHf7CxvPfsaO4WGpe4I/UACgXn zjCtf1nLzaqC8q7Zi1PgMbZsv57skq1Xx9z+R7vkff5rtrpcSqghhBVaF3Ai+z/zPp79 uX4Q== X-Gm-Message-State: AFeK/H38ekGqaW6P1FGwlvo0x3O2dbS/8VzWPH6oc+m1qGsa7FUhhhc2F0R8i/FCyhZ0gg== X-Received: by 10.36.58.207 with SMTP id m198mr8430657itm.31.1489632789483; Wed, 15 Mar 2017 19:53:09 -0700 (PDT) Original-Received: from zony ([45.2.7.65]) by smtp.googlemail.com with ESMTPSA id w73sm2386822ioi.16.2017.03.15.19.53.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 Mar 2017 19:53:08 -0700 (PDT) In-Reply-To: <87innd6zti.fsf@users.sourceforge.net> (npostavs@users.sourceforge.net's message of "Mon, 13 Mar 2017 10:01:13 -0400") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:130638 Archived-At: --=-=-= Content-Type: text/plain >> npostavs@users.sourceforge.net writes: >> >> Okay, I think I found the real fix now: Same issue with indent-region. The gains are not so dramatic for typical lisp code that has normal size sexps, but C-x h C-M-\ on subr.el's text runs twice as fast for me with the new lisp-indent-region function. --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=v2-0002-Remove-ignored-argument-from-lisp-indent-line.patch Content-Description: patch >From 1a5464d36582b5efcea43aac37bf0b9ddd4c1ff1 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Wed, 15 Mar 2017 21:59:13 -0400 Subject: [PATCH v2 2/4] Remove ignored argument from lisp-indent-line * lisp/emacs-lisp/lisp-mode.el (lisp-indent-line): Remove WHOLE-EXP argument, the behvior has long since been handled in `indent-for-tab-command'. --- lisp/emacs-lisp/lisp-mode.el | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index 3fefb69066..7eb8b986be 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el @@ -744,11 +744,9 @@ lisp-indent-function :type 'function :group 'lisp) -(defun lisp-indent-line (&optional _whole-exp) - "Indent current line as Lisp code. -With argument, indent any additional lines of the same expression -rigidly along with this one." - (interactive "P") +(defun lisp-indent-line () + "Indent current line as Lisp code." + (interactive) (let ((indent (calculate-lisp-indent)) shift-amt (pos (- (point-max) (point))) (beg (progn (beginning-of-line) (point)))) -- 2.11.1 --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=v2-0003-Add-new-lisp-indent-region-that-doesn-t-reparse-t.patch Content-Description: patch >From 9cf8f32910c0c899f108c3907d099a18fff2cec4 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Wed, 15 Mar 2017 22:27:27 -0400 Subject: [PATCH v2 3/4] Add new `lisp-indent-region' that doesn't reparse the code. * lisp/emacs-lisp/lisp-mode.el (lisp-indent-region): New function, like `indent-region-line-by-line' but additionally keep a running parse state to avoid reparsing the code repeatedly. (lisp-indent-line): Take optional PARSE-STATE argument, pass it to `calculate-lisp-indent'. (lisp-mode-variables): Set `indent-region-function' to `lisp-indent-region'. --- lisp/emacs-lisp/lisp-mode.el | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index 7eb8b986be..7577267903 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el @@ -586,6 +586,7 @@ lisp-mode-variables ;; I believe that newcomment's auto-fill code properly deals with it -stef ;;(set (make-local-variable 'adaptive-fill-mode) nil) (setq-local indent-line-function 'lisp-indent-line) + (setq-local indent-region-function 'lisp-indent-region) (setq-local outline-regexp ";;;\\(;* [^ \t\n]\\|###autoload\\)\\|(") (setq-local outline-level 'lisp-outline-level) (setq-local add-log-current-defun-function #'lisp-current-defun-name) @@ -744,10 +745,38 @@ lisp-indent-function :type 'function :group 'lisp) -(defun lisp-indent-line () +(defun lisp-indent-region (start end) + "Indent region as Lisp code, efficiently." + (save-excursion + (setq end (copy-marker end)) + (goto-char start) + ;; The default `indent-region-line-by-line' doesn't hold a running + ;; parse state, which forces each indent call to reparse from the + ;; beginning. That has O(n^2) complexity. + (let* ((parse-state (syntax-ppss start)) + (last-syntax-point start) + (pr (unless (minibufferp) + (make-progress-reporter "Indenting region..." (point) end)))) + (while (< (point) end) + (unless (and (bolp) (eolp)) + (lisp-indent-line parse-state)) + (forward-line 1) + (let ((last-sexp (nth 2 parse-state))) + (setq parse-state (parse-partial-sexp last-syntax-point (point) + nil nil parse-state)) + ;; It's important to preserve last sexp location for + ;; `calculate-lisp-indent'. + (unless (nth 2 parse-state) + (setf (nth 2 parse-state) last-sexp)) + (setq last-syntax-point (point))) + (and pr (progress-reporter-update pr (point)))) + (and pr (progress-reporter-done pr)) + (move-marker end nil)))) + +(defun lisp-indent-line (&optional parse-state) "Indent current line as Lisp code." (interactive) - (let ((indent (calculate-lisp-indent)) shift-amt + (let ((indent (calculate-lisp-indent parse-state)) shift-amt (pos (- (point-max) (point))) (beg (progn (beginning-of-line) (point)))) (skip-chars-forward " \t") -- 2.11.1 --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=v2-0004-lisp-emacs-lisp-lisp-mode.el-indent-sexp-Clean-up.patch Content-Description: patch >From 4dbe8fd84064b1b3fed4188f0a2a84de5550cf11 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Wed, 15 Mar 2017 22:35:47 -0400 Subject: [PATCH v2 4/4] * lisp/emacs-lisp/lisp-mode.el (indent-sexp): Clean up marker. --- lisp/emacs-lisp/lisp-mode.el | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index 7577267903..4fa9eb97de 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el @@ -1112,12 +1112,13 @@ indent-sexp (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. - (save-excursion (forward-sexp 1) - ;; We need a marker because we modify the buffer - ;; text preceding endpos. - (setq endpos (point-marker)))) + ;; We need a marker because we modify the buffer + ;; text preceding endpos. + (setq endpos (copy-marker + (if endpos endpos + ;; Get error now if we don't have a complete sexp + ;; after point. + (save-excursion (forward-sexp 1) (point))))) (save-excursion (while (< (point) endpos) ;; Parse this line so we can learn the state to indent the @@ -1177,7 +1178,8 @@ indent-sexp ;; `calculate-lisp-indent' only returns nil ;; when we're in a string, but this won't ;; happen because we skip strings above. - (t (error "This shouldn't happen!")))))))))))) + (t (error "This shouldn't happen!")))))))))) + (move-marker endpos nil))) (defun indent-pp-sexp (&optional arg) "Indent each line of the list starting just after point, or prettyprint it. -- 2.11.1 --=-=-=--