* progmodes/python.el (python-nav-end-of-statement): Rewrite in
authorFabián Ezequiel Gallina <fgallina@gnu.org>
Mon, 31 Dec 2012 20:58:57 +0000 (17:58 -0300)
committerFabián Ezequiel Gallina <fgallina@gnu.org>
Mon, 31 Dec 2012 20:58:57 +0000 (17:58 -0300)
order to improve efficiency (Based on Daniel Colascione's
<dancol@dancol.org> patch).

Fixes: debbugs:13182

lisp/ChangeLog
lisp/progmodes/python.el

index e910b2c..a62a9cd 100644 (file)
@@ -1,3 +1,9 @@
+2012-12-31  Fabián Ezequiel Gallina  <fgallina@cuca>
+
+       * progmodes/python.el (python-nav-end-of-statement): Rewrite in
+       order to improve efficiency (Based on Daniel Colascione's
+       <dancol@dancol.org> patch).  (Bug#13182)
+
 2012-12-31  Glenn Morris  <rgm@gnu.org>
 
        * vc/log-edit.el (log-edit-header-contents-regexp): Add doc string.
index 90e0d60..c168b38 100644 (file)
@@ -1177,16 +1177,27 @@ Returns nil if point is not in a def or class."
                 (forward-line -1))))
   (point-marker))
 
-(defun python-nav-end-of-statement ()
-  "Move to end of current statement."
+(defun python-nav-end-of-statement (&optional noend)
+  "Move to end of current statement.
+Optional argument NOEND is internal and makes the logic to not
+jump to the end of line when moving forward searching for the end
+of the 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 (or noend (goto-char (line-end-position)))
+                (not (eobp))
+                (cond ((setq string-start (python-syntax-context 'string))
+                       (goto-char string-start)
+                       (python-nav-end-of-statement t))
+                      ((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)
+                       (forward-line 1))))))
   (point-marker))
 
 (defun python-nav-backward-statement (&optional arg)