all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Daniel Colascione <dancol@dancol.org>
To: 13182@debbugs.gnu.org
Subject: bug#13182: [PATCH] long delays in python-mode buffer parsing
Date: Fri, 14 Dec 2012 03:40:28 -0800	[thread overview]
Message-ID: <50CB102C.6020306@dancol.org> (raw)

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

Some python-mode operations slow down noticeably when the region being edited
contains an unclosed bracket or string: these constructs lead to python-mode
scanning the entire remainder of the buffer, and this scan appears to take time
O(nr_lines^2). When which-func mode is enabled, this slowness renders Emacs
unusable, since we'll call python-info-current-defun frequently in order to
update the modeline, and this function will take several seconds to complete.

The following patch appears to remedy the problem without breaking anythig.

=== modified file 'lisp/progmodes/python.el'
--- lisp/progmodes/python.el	2012-11-27 03:10:32 +0000
+++ lisp/progmodes/python.el	2012-12-14 11:28:58 +0000
@@ -1184,13 +1184,21 @@
 (defun python-nav-end-of-statement ()
   "Move to end of current statement."
   (interactive "^")
-  (while (and (goto-char (line-end-position))
-              (not (eobp))
-              (when (or
-                     (python-info-line-ends-backslash-p)
-                     (python-syntax-context 'string)
-                     (python-syntax-context 'paren))
-                (forward-line 1))))
+
+  (let (string-start bs-pos)
+    (while (and (goto-char (line-end-position))
+                (not (eobp))
+                (cond ((setq string-start (python-syntax-context 'string))
+                       (goto-char string-start)
+                       (forward-sexp))
+                      ((python-syntax-context 'paren)
+                       ;; The statement won't end before we've escaped
+                       ;; at least one level of parenthesis.
+                       (condition-case err
+                           (goto-char (scan-lists (point) 1 -1))
+                         (scan-error (goto-char (nth 3 err)))))
+                      ((setq bs-pos (python-info-line-ends-backslash-p))
+                       (goto-char bs-pos))))))
   (point-marker))

 (defun python-nav-backward-statement (&optional arg)



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 258 bytes --]

             reply	other threads:[~2012-12-14 11:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-14 11:40 Daniel Colascione [this message]
2012-12-15  6:44 ` bug#13182: [PATCH] long delays in python-mode buffer parsing Daniel Colascione
2012-12-15 14:50   ` Stefan Monnier
2012-12-28 15:29 ` Fabián Ezequiel Gallina
2012-12-31 21:02 ` Fabián Ezequiel Gallina
2012-12-31 21:05 ` Fabián Ezequiel Gallina

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=50CB102C.6020306@dancol.org \
    --to=dancol@dancol.org \
    --cc=13182@debbugs.gnu.org \
    /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.