diff options
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 37018122f30..d8262dd0a75 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; python.el --- Python's flying circus support for Emacs -*- lexical-binding: t -*- | 1 | ;;; python.el --- Python's flying circus support for Emacs -*- lexical-binding: t -*- |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 2003-2016 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 2003-2017 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: Fabián E. Gallina <fgallina@gnu.org> | 5 | ;; Author: Fabián E. Gallina <fgallina@gnu.org> |
| 6 | ;; URL: https://github.com/fgallina/python.el | 6 | ;; URL: https://github.com/fgallina/python.el |
| @@ -4415,6 +4415,15 @@ It must be a function with two arguments: TYPE and NAME.") | |||
| 4415 | "*class definition*" | 4415 | "*class definition*" |
| 4416 | "*function definition*")) | 4416 | "*function definition*")) |
| 4417 | 4417 | ||
| 4418 | (defun python-imenu--get-defun-type-name () | ||
| 4419 | "Return defun type and name at current position." | ||
| 4420 | (when (looking-at python-nav-beginning-of-defun-regexp) | ||
| 4421 | (let ((split (split-string (match-string-no-properties 0)))) | ||
| 4422 | (if (= (length split) 2) | ||
| 4423 | split | ||
| 4424 | (list (concat (car split) " " (cadr split)) | ||
| 4425 | (car (last split))))))) | ||
| 4426 | |||
| 4418 | (defun python-imenu--put-parent (type name pos tree) | 4427 | (defun python-imenu--put-parent (type name pos tree) |
| 4419 | "Add the parent with TYPE, NAME and POS to TREE." | 4428 | "Add the parent with TYPE, NAME and POS to TREE." |
| 4420 | (let ((label | 4429 | (let ((label |
| @@ -4432,11 +4441,9 @@ not be passed explicitly unless you know what you are doing." | |||
| 4432 | (setq min-indent (or min-indent 0) | 4441 | (setq min-indent (or min-indent 0) |
| 4433 | prev-indent (or prev-indent python-indent-offset)) | 4442 | prev-indent (or prev-indent python-indent-offset)) |
| 4434 | (let* ((pos (python-nav-backward-defun)) | 4443 | (let* ((pos (python-nav-backward-defun)) |
| 4435 | (type) | 4444 | (defun-type-name (and pos (python-imenu--get-defun-type-name))) |
| 4436 | (name (when (and pos (looking-at python-nav-beginning-of-defun-regexp)) | 4445 | (type (car defun-type-name)) |
| 4437 | (let ((split (split-string (match-string-no-properties 0)))) | 4446 | (name (cadr defun-type-name)) |
| 4438 | (setq type (car split)) | ||
| 4439 | (cadr split)))) | ||
| 4440 | (label (when name | 4447 | (label (when name |
| 4441 | (funcall python-imenu-format-item-label-function type name))) | 4448 | (funcall python-imenu-format-item-label-function type name))) |
| 4442 | (indent (current-indentation)) | 4449 | (indent (current-indentation)) |