(forward-line -1)
(setq arg (1+ arg))))
-(defun python-nav-list-defun-positions (&optional include-type)
+(defvar python-nav-list-defun-positions-cache nil)
+(make-variable-buffer-local 'python-nav-list-defun-positions-cache)
+
+(defun python-nav-list-defun-positions (&optional include-type rescan)
"Make an Alist of defun names and point markers for current buffer.
When optional argument INCLUDE-TYPE is non-nil the type is
-included the defun name."
- (let ((defs))
- (save-restriction
- (widen)
- (save-excursion
- (goto-char (point-max))
- (while (re-search-backward python-nav-beginning-of-defun-regexp nil t)
- (when (and (not (python-info-ppss-context 'string))
- (not (python-info-ppss-context 'comment))
- (not (python-info-ppss-context 'parent)))
- (add-to-list
- 'defs (cons
- (python-info-current-defun include-type)
- (point-marker)))))
- defs))))
-
-(defun python-nav-read-defun ()
+included the defun name. With optional argument RESCAN the
+`python-nav-list-defun-positions-cache' is invalidated and the
+list of defun is regenerated again."
+ (if (and python-nav-list-defun-positions-cache (not rescan))
+ python-nav-list-defun-positions-cache
+ (let ((defs))
+ (save-restriction
+ (widen)
+ (save-excursion
+ (goto-char (point-max))
+ (while (re-search-backward python-nav-beginning-of-defun-regexp nil t)
+ (when (and (not (python-info-ppss-context 'string))
+ (not (python-info-ppss-context 'comment))
+ (not (python-info-ppss-context 'parent)))
+ (add-to-list
+ 'defs (cons
+ (python-info-current-defun include-type)
+ (point-marker)))))
+ (setq python-nav-list-defun-positions-cache defs))))))
+
+(defun python-nav-read-defun (&optional rescan)
"Read a defun name of current buffer and return its point marker.
A cons cell with the form (DEFUN-NAME . POINT-MARKER) is returned
-when defun is completed, else nil."
- (let ((defs (python-nav-list-defun-positions)))
+when defun is completed, else nil. With optional argument RESCAN
+forces `python-nav-list-defun-positions' to invalidate its
+cache."
+ (let ((defs (python-nav-list-defun-positions nil rescan)))
(minibuffer-with-setup-hook
(lambda ()
(setq minibuffer-completion-table (mapcar 'car defs)))
(assoc-string stringdef defs))))))
(defun python-nav-jump-to-defun (def)
- "Jump to the definition of DEF in current file."
+ "Jump to the definition of DEF in current file.
+Locations are cached; use a C-u prefix argument to force a
+rescan."
(interactive
- (list (python-nav-read-defun)))
+ (list (python-nav-read-defun current-prefix-arg)))
(when (not (called-interactively-p 'interactive))
(setq def (assoc-string def (python-nav-list-defun-positions))))
(let ((def-marker (cdr def)))