    "[ \t]*:"				; and the final :
    "\\)"				; >>classes<<
    )
-  "Regexp for Python classes for use with the imenu package."
+  "Regexp for Python classes for use with the Imenu package."
   )
 
-(defvar imenu-example--python-method-regexp
+(defvar py-imenu-method-regexp
   (concat                               ; <<methods and functions>>
    "\\("                                ; 
    "^[ \t]*"                            ; new line and maybe whitespace


This function should not be called directly, as it calls itself
recursively and requires some setup.  Rather this is the engine for
the function \\[imenu-example--create-python-index].

It works recursively by looking for all definitions at the current
indention level.  When it finds one, it adds it to the alist.  If it
finds a definition at a greater indentation level, it removes the
previous definition from the alist. In its place it adds all
definitions found at the next indentation level.  When it finds a
definition that is less indented then the current level, it retuns the
alist it has created thus far.

The optional argument START-INDENT indicates the starting indentation
at which to continue looking for Python classes, methods, or
functions.  If this is not supplied, the function uses the indentation
of the first definition found."
  (let ((index-alist '())
	(sub-method-alist '())
	looking-p
	def-name prev-name
	cur-indent def-pos
	(class-paren (first  imenu-example--python-generic-parens)) 
	(def-paren   (second imenu-example--python-generic-parens)))
    (setq looking-p
	  (re-search-forward imenu-example--python-generic-regexp
			     (point-max) t))
    (while looking-p
      (save-excursion
	;; used to set def-name to this value but generic-extract-name is
	;; new to imenu-1.14. this way it still works with imenu-1.11
	;;(imenu--generic-extract-name imenu-example--python-generic-parens))
	(let ((cur-paren (if (match-beginning class-paren)
			     class-paren def-paren)))
	  (setq def-name
		(buffer-substring-no-properties (match-beginning cur-paren)
						(match-end  cur-paren))))
	(save-match-data
	  (py-beginning-of-def-or-class))
	(beginning-of-line)
	(setq cur-indent (current-indentation)))

      ;; HACK: want to go to the next correct definition location. we
      ;; explicitly list them here. would be better to have them in a
      ;; list.
      (setq def-pos
	    (or  (match-beginning class-paren)
		 (match-beginning def-paren)))

      ;; if we don't have a starting indent level, take this one
      (or start-indent
	  (setq start-indent cur-indent))

      ;; if we don't have class name yet, take this one
      (or prev-name
	  (setq prev-name def-name))

      ;; what level is the next definition on?  must be same, deeper
      ;; or shallower indentation
      (cond
       ;; at the same indent level, add it to the list...
       ((= start-indent cur-indent)

	;; if we don't have push, use the following...
	;;(setf index-alist (cons (cons def-name def-pos) index-alist))
	(push (cons def-name def-pos) index-alist))

       ;; deeper indented expression, recur...
       ((< start-indent cur-indent)

	;; the point is currently on the expression we're supposed to
	;; start on, so go back to the last expression. The recursive
	;; call will find this place again and add it to the correct
	;; list
	(re-search-backward imenu-example--python-generic-regexp
			    (point-min) 'move)
	(setq sub-method-alist (imenu-example--create-python-index-engine
				cur-indent))

	(if sub-method-alist
	    ;; we put the last element on the index-alist on the start
	    ;; of the submethod alist so the user can still get to it.

     ))
  "Additional expressions to highlight in Python mode.")
(put 'python-mode 'font-lock-defaults '(python-font-lock-keywords))

;; have to bind py-file-queue before installing the kill-emacs-hook
(defvar py-file-queue nil
