Fix Imenu regression.
authorFabián Ezequiel Gallina <fgallina@gnu.org>
Mon, 26 Nov 2012 21:45:58 +0000 (18:45 -0300)
committerFabián Ezequiel Gallina <fgallina@gnu.org>
Mon, 26 Nov 2012 21:45:58 +0000 (18:45 -0300)
* progmodes/python.el:
(python-nav-beginning-of-defun): Fix forward movement when
statement(s) separates point from defun.
(python-imenu-prev-index-position): New function.

lisp/ChangeLog
lisp/progmodes/python.el

index e6bad79..a5ce3fc 100644 (file)
@@ -1,3 +1,11 @@
+2012-11-26  Fabián Ezequiel Gallina  <fgallina@cuca>
+
+       Fix Imenu regression.
+       * progmodes/python.el:
+       (python-nav-beginning-of-defun): Fix forward movement when
+       statement(s) separates point from defun.
+       (python-imenu-prev-index-position): New function.
+
 2012-11-26  Eli Zaretskii  <eliz@gnu.org>
 
        * subr.el (buffer-file-type): Declare with defvar-local.  Doc fix.
index 949b025..cfd3a73 100644 (file)
@@ -33,7 +33,7 @@
 ;; Implements Syntax highlighting, Indentation, Movement, Shell
 ;; interaction, Shell completion, Shell virtualenv support, Pdb
 ;; tracking, Symbol completion, Skeletons, FFAP, Code Check, Eldoc,
-;; imenu.
+;; Imenu.
 
 ;; Syntax highlighting: Fontification of code is provided and supports
 ;; python's triple quoted strings properly.
 ;; might guessed you should run `python-shell-send-buffer' from time
 ;; to time to get better results too.
 
-;; imenu: This mode supports imenu in its most basic form, letting it
+;; Imenu: This mode supports Imenu in its most basic form, letting it
 ;; build the necessary alist via `imenu-default-create-index-function'
 ;; by having set `imenu-extract-index-name-function' to
-;; `python-info-current-defun'.
+;; `python-info-current-defun' and
+;; `imenu-prev-index-position-function' to
+;; `python-imenu-prev-index-position'.
 
 ;; If you used python-mode.el you probably will miss auto-indentation
 ;; when inserting newlines.  To achieve the same behavior you have
@@ -1087,12 +1089,12 @@ With positive ARG search backwards, else search forwards."
          (beg-indentation
           (and (> arg 0)
                (save-excursion
-                 (and (python-info-current-line-empty-p)
-                      (python-util-forward-comment -1))
-                 (python-nav-beginning-of-statement)
-                 (if (python-info-looking-at-beginning-of-defun)
-                     (+ (current-indentation) python-indent-offset)
-                   (current-indentation)))))
+                 (while (and
+                         (not (python-info-looking-at-beginning-of-defun))
+                         (python-nav-backward-block)))
+                 (or (and (python-info-looking-at-beginning-of-defun)
+                          (+ (current-indentation) python-indent-offset))
+                     0))))
          (found
           (progn
             (when (and (< arg 0)
@@ -2870,6 +2872,19 @@ Interactively, prompt for symbol."
              "^Eldoc needs an inferior Python process running.")
 
 \f
+;;; Imenu
+
+(defun python-imenu-prev-index-position ()
+  "Python mode's `imenu-prev-index-position-function'."
+  (let ((found))
+    (while (and (setq found
+                      (re-search-backward python-nav-beginning-of-defun-regexp nil t))
+                (not (python-info-looking-at-beginning-of-defun))))
+    (and found
+         (python-info-looking-at-beginning-of-defun)
+         (python-info-current-defun))))
+
+\f
 ;;; Misc helpers
 
 (defun python-info-current-defun (&optional include-type)
@@ -3214,6 +3229,9 @@ if that value is non-nil."
   (set (make-local-variable 'imenu-extract-index-name-function)
        #'python-info-current-defun)
 
+  (set (make-local-variable 'imenu-prev-index-position-function)
+       #'python-imenu-prev-index-position)
+
   (set (make-local-variable 'add-log-current-defun-function)
        #'python-info-current-defun)