]> git.eshelyaron.com Git - emacs.git/commitdiff
* progmodes/python.el (python-info-current-defun): Enhance
authorFabián Ezequiel Gallina <fgallina@gnu.org>
Wed, 20 Feb 2013 20:41:46 +0000 (17:41 -0300)
committerFabián Ezequiel Gallina <fgallina@gnu.org>
Wed, 20 Feb 2013 20:41:46 +0000 (17:41 -0300)
match-data cluttering prevention.

lisp/ChangeLog
lisp/progmodes/python.el

index 9fe6fd4f1f988ab9c00bf5bfc17d784da686bd48..a3cd719895cd8fc7a9e283e23ecb9507e4b17a13 100644 (file)
@@ -1,3 +1,8 @@
+2013-02-20  Fabián Ezequiel Gallina  <fgallina@cuca>
+
+       * progmodes/python.el (python-info-current-defun): Enhance
+       match-data cluttering prevention.
+
 2013-02-19  Glenn Morris  <rgm@gnu.org>
 
        * net/tramp.el (tramp-get-debug-buffer): Ensure outline.el is not
index 1ee95daa0a95a1222071b4f851aa78df6a97fde8..c2739ce80a1eb57c2f77eb1be8f51e598060eb0f 100644 (file)
@@ -2949,42 +2949,40 @@ not inside a defun."
             (type))
         (catch 'exit
           (while (python-nav-beginning-of-defun 1)
-            (when (and
-                   (or (not last-indent)
-                       (< (current-indentation) last-indent))
-                   (or
-                    (and first-run
+            (when (save-match-data
+                    (and
+                     (or (not last-indent)
+                         (< (current-indentation) last-indent))
+                     (or
+                      (and first-run
+                           (save-excursion
+                             ;; If this is the first run, we may add
+                             ;; the current defun at point.
+                             (setq first-run nil)
+                             (goto-char starting-pos)
+                             (python-nav-beginning-of-statement)
+                             (beginning-of-line 1)
+                             (looking-at-p
+                              python-nav-beginning-of-defun-regexp)))
+                      (< starting-pos
                          (save-excursion
-                           ;; If this is the first run, we may add
-                           ;; the current defun at point.
-                           (setq first-run nil)
-                           (goto-char starting-pos)
-                           (python-nav-beginning-of-statement)
-                           (beginning-of-line 1)
-                           (looking-at-p
-                            python-nav-beginning-of-defun-regexp)))
-                    (< starting-pos
-                       (save-excursion
-                         (let ((min-indent
-                                (+ (current-indentation)
-                                   python-indent-offset)))
-                           (if (< starting-indentation  min-indent)
-                               ;; If the starting indentation is not
-                               ;; within the min defun indent make the
-                               ;; check fail.
-                               starting-pos
-                             ;; Else go to the end of defun and add
-                             ;; up the current indentation to the
-                             ;; ending position.
-                             (save-match-data
-                               ;; FIXME: avoid cluttering match-data
-                               ;; where's not wanted.
-                               (python-nav-end-of-defun))
-                             (+ (point)
-                                (if (>= (current-indentation) min-indent)
-                                    (1+ (current-indentation))
-                                  0))))))))
-              (setq last-indent (current-indentation))
+                           (let ((min-indent
+                                  (+ (current-indentation)
+                                     python-indent-offset)))
+                             (if (< starting-indentation  min-indent)
+                                 ;; If the starting indentation is not
+                                 ;; within the min defun indent make the
+                                 ;; check fail.
+                                 starting-pos
+                               ;; Else go to the end of defun and add
+                               ;; up the current indentation to the
+                               ;; ending position.
+                               (python-nav-end-of-defun)
+                               (+ (point)
+                                  (if (>= (current-indentation) min-indent)
+                                      (1+ (current-indentation))
+                                    0)))))))))
+              (save-match-data (setq last-indent (current-indentation)))
               (if (or (not include-type) type)
                   (setq names (cons (match-string-no-properties 1) names))
                 (let ((match (split-string (match-string-no-properties 0))))