diff options
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 55 |
1 files changed, 33 insertions, 22 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 71c5453ee2d..4654143a160 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -1134,30 +1134,39 @@ With negative argument, move backward repeatedly to start of sentence." | |||
| 1134 | (forward-line -1) | 1134 | (forward-line -1) |
| 1135 | (setq arg (1+ arg)))) | 1135 | (setq arg (1+ arg)))) |
| 1136 | 1136 | ||
| 1137 | (defun python-nav-list-defun-positions (&optional include-type) | 1137 | (defvar python-nav-list-defun-positions-cache nil) |
| 1138 | (make-variable-buffer-local 'python-nav-list-defun-positions-cache) | ||
| 1139 | |||
| 1140 | (defun python-nav-list-defun-positions (&optional include-type rescan) | ||
| 1138 | "Make an Alist of defun names and point markers for current buffer. | 1141 | "Make an Alist of defun names and point markers for current buffer. |
| 1139 | When optional argument INCLUDE-TYPE is non-nil the type is | 1142 | When optional argument INCLUDE-TYPE is non-nil the type is |
| 1140 | included the defun name." | 1143 | included the defun name. With optional argument RESCAN the |
| 1141 | (let ((defs)) | 1144 | `python-nav-list-defun-positions-cache' is invalidated and the |
| 1142 | (save-restriction | 1145 | list of defun is regenerated again." |
| 1143 | (widen) | 1146 | (if (and python-nav-list-defun-positions-cache (not rescan)) |
| 1144 | (save-excursion | 1147 | python-nav-list-defun-positions-cache |
| 1145 | (goto-char (point-max)) | 1148 | (let ((defs)) |
| 1146 | (while (re-search-backward python-nav-beginning-of-defun-regexp nil t) | 1149 | (save-restriction |
| 1147 | (when (and (not (python-info-ppss-context 'string)) | 1150 | (widen) |
| 1148 | (not (python-info-ppss-context 'comment)) | 1151 | (save-excursion |
| 1149 | (not (python-info-ppss-context 'parent))) | 1152 | (goto-char (point-max)) |
| 1150 | (add-to-list | 1153 | (while (re-search-backward python-nav-beginning-of-defun-regexp nil t) |
| 1151 | 'defs (cons | 1154 | (when (and (not (python-info-ppss-context 'string)) |
| 1152 | (python-info-current-defun include-type) | 1155 | (not (python-info-ppss-context 'comment)) |
| 1153 | (point-marker))))) | 1156 | (not (python-info-ppss-context 'parent))) |
| 1154 | defs)))) | 1157 | (add-to-list |
| 1155 | 1158 | 'defs (cons | |
| 1156 | (defun python-nav-read-defun () | 1159 | (python-info-current-defun include-type) |
| 1160 | (point-marker))))) | ||
| 1161 | (setq python-nav-list-defun-positions-cache defs)))))) | ||
| 1162 | |||
| 1163 | (defun python-nav-read-defun (&optional rescan) | ||
| 1157 | "Read a defun name of current buffer and return its point marker. | 1164 | "Read a defun name of current buffer and return its point marker. |
| 1158 | A cons cell with the form (DEFUN-NAME . POINT-MARKER) is returned | 1165 | A cons cell with the form (DEFUN-NAME . POINT-MARKER) is returned |
| 1159 | when defun is completed, else nil." | 1166 | when defun is completed, else nil. With optional argument RESCAN |
| 1160 | (let ((defs (python-nav-list-defun-positions))) | 1167 | forces `python-nav-list-defun-positions' to invalidate its |
| 1168 | cache." | ||
| 1169 | (let ((defs (python-nav-list-defun-positions nil rescan))) | ||
| 1161 | (minibuffer-with-setup-hook | 1170 | (minibuffer-with-setup-hook |
| 1162 | (lambda () | 1171 | (lambda () |
| 1163 | (setq minibuffer-completion-table (mapcar 'car defs))) | 1172 | (setq minibuffer-completion-table (mapcar 'car defs))) |
| @@ -1169,9 +1178,11 @@ when defun is completed, else nil." | |||
| 1169 | (assoc-string stringdef defs)))))) | 1178 | (assoc-string stringdef defs)))))) |
| 1170 | 1179 | ||
| 1171 | (defun python-nav-jump-to-defun (def) | 1180 | (defun python-nav-jump-to-defun (def) |
| 1172 | "Jump to the definition of DEF in current file." | 1181 | "Jump to the definition of DEF in current file. |
| 1182 | Locations are cached; use a C-u prefix argument to force a | ||
| 1183 | rescan." | ||
| 1173 | (interactive | 1184 | (interactive |
| 1174 | (list (python-nav-read-defun))) | 1185 | (list (python-nav-read-defun current-prefix-arg))) |
| 1175 | (when (not (called-interactively-p 'interactive)) | 1186 | (when (not (called-interactively-p 'interactive)) |
| 1176 | (setq def (assoc-string def (python-nav-list-defun-positions)))) | 1187 | (setq def (assoc-string def (python-nav-list-defun-positions)))) |
| 1177 | (let ((def-marker (cdr def))) | 1188 | (let ((def-marker (cdr def))) |