aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el38
1 files changed, 28 insertions, 10 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 550c5f5a129..a2c8453a011 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -33,7 +33,7 @@
33;; Implements Syntax highlighting, Indentation, Movement, Shell 33;; Implements Syntax highlighting, Indentation, Movement, Shell
34;; interaction, Shell completion, Shell virtualenv support, Pdb 34;; interaction, Shell completion, Shell virtualenv support, Pdb
35;; tracking, Symbol completion, Skeletons, FFAP, Code Check, Eldoc, 35;; tracking, Symbol completion, Skeletons, FFAP, Code Check, Eldoc,
36;; imenu. 36;; Imenu.
37 37
38;; Syntax highlighting: Fontification of code is provided and supports 38;; Syntax highlighting: Fontification of code is provided and supports
39;; python's triple quoted strings properly. 39;; python's triple quoted strings properly.
@@ -169,10 +169,12 @@
169;; might guessed you should run `python-shell-send-buffer' from time 169;; might guessed you should run `python-shell-send-buffer' from time
170;; to time to get better results too. 170;; to time to get better results too.
171 171
172;; imenu: This mode supports imenu in its most basic form, letting it 172;; Imenu: This mode supports Imenu in its most basic form, letting it
173;; build the necessary alist via `imenu-default-create-index-function' 173;; build the necessary alist via `imenu-default-create-index-function'
174;; by having set `imenu-extract-index-name-function' to 174;; by having set `imenu-extract-index-name-function' to
175;; `python-info-current-defun'. 175;; `python-info-current-defun' and
176;; `imenu-prev-index-position-function' to
177;; `python-imenu-prev-index-position'.
176 178
177;; If you used python-mode.el you probably will miss auto-indentation 179;; If you used python-mode.el you probably will miss auto-indentation
178;; when inserting newlines. To achieve the same behavior you have 180;; when inserting newlines. To achieve the same behavior you have
@@ -656,7 +658,7 @@ These make `python-indent-calculate-indentation' subtract the value of
656 (python-util-forward-comment) 658 (python-util-forward-comment)
657 (current-indentation)))) 659 (current-indentation))))
658 (if indentation 660 (if indentation
659 (setq python-indent-offset indentation) 661 (set (make-local-variable 'python-indent-offset) indentation)
660 (message "Can't guess python-indent-offset, using defaults: %s" 662 (message "Can't guess python-indent-offset, using defaults: %s"
661 python-indent-offset))))))) 663 python-indent-offset)))))))
662 664
@@ -1098,12 +1100,12 @@ With positive ARG search backwards, else search forwards."
1098 (beg-indentation 1100 (beg-indentation
1099 (and (> arg 0) 1101 (and (> arg 0)
1100 (save-excursion 1102 (save-excursion
1101 (and (python-info-current-line-empty-p) 1103 (while (and
1102 (python-util-forward-comment -1)) 1104 (not (python-info-looking-at-beginning-of-defun))
1103 (python-nav-beginning-of-statement) 1105 (python-nav-backward-block)))
1104 (if (python-info-looking-at-beginning-of-defun) 1106 (or (and (python-info-looking-at-beginning-of-defun)
1105 (+ (current-indentation) python-indent-offset) 1107 (+ (current-indentation) python-indent-offset))
1106 (current-indentation))))) 1108 0))))
1107 (found 1109 (found
1108 (progn 1110 (progn
1109 (when (and (< arg 0) 1111 (when (and (< arg 0)
@@ -2881,6 +2883,19 @@ Interactively, prompt for symbol."
2881 "^Eldoc needs an inferior Python process running.") 2883 "^Eldoc needs an inferior Python process running.")
2882 2884
2883 2885
2886;;; Imenu
2887
2888(defun python-imenu-prev-index-position ()
2889 "Python mode's `imenu-prev-index-position-function'."
2890 (let ((found))
2891 (while (and (setq found
2892 (re-search-backward python-nav-beginning-of-defun-regexp nil t))
2893 (not (python-info-looking-at-beginning-of-defun))))
2894 (and found
2895 (python-info-looking-at-beginning-of-defun)
2896 (python-info-current-defun))))
2897
2898
2884;;; Misc helpers 2899;;; Misc helpers
2885 2900
2886(defun python-info-current-defun (&optional include-type) 2901(defun python-info-current-defun (&optional include-type)
@@ -3225,6 +3240,9 @@ if that value is non-nil."
3225 (set (make-local-variable 'imenu-extract-index-name-function) 3240 (set (make-local-variable 'imenu-extract-index-name-function)
3226 #'python-info-current-defun) 3241 #'python-info-current-defun)
3227 3242
3243 (set (make-local-variable 'imenu-prev-index-position-function)
3244 #'python-imenu-prev-index-position)
3245
3228 (set (make-local-variable 'add-log-current-defun-function) 3246 (set (make-local-variable 'add-log-current-defun-function)
3229 #'python-info-current-defun) 3247 #'python-info-current-defun)
3230 3248