diff options
| author | Fabián Ezequiel Gallina | 2013-02-13 20:07:59 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina | 2013-02-13 20:07:59 -0300 |
| commit | dcbec5e2e6799049a0b3535986f4674d452970a3 (patch) | |
| tree | cae3fc6a66f68130a304cecafc9325e203c5e5c3 | |
| parent | 0e4e7b741b515be091e2ec3b3ff63f1b16084555 (diff) | |
| download | emacs-dcbec5e2e6799049a0b3535986f4674d452970a3.tar.gz emacs-dcbec5e2e6799049a0b3535986f4674d452970a3.zip | |
* progmodes/python.el (python-info-current-defun): Fix current
defun detection.
Fixes: debbugs:13618
| -rw-r--r-- | lisp/progmodes/python.el | 87 |
1 files changed, 54 insertions, 33 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 2a7a3765ac2..e611864e0c1 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -2936,40 +2936,61 @@ Optional argument INCLUDE-TYPE indicates to include the type of the defun. | |||
| 2936 | This function is compatible to be used as | 2936 | This function is compatible to be used as |
| 2937 | `add-log-current-defun-function' since it returns nil if point is | 2937 | `add-log-current-defun-function' since it returns nil if point is |
| 2938 | not inside a defun." | 2938 | not inside a defun." |
| 2939 | (save-restriction | 2939 | (save-restriction |
| 2940 | (widen) | 2940 | (widen) |
| 2941 | (save-excursion | 2941 | (save-excursion |
| 2942 | (end-of-line 1) | 2942 | (end-of-line 1) |
| 2943 | (let ((names) | 2943 | (let ((names) |
| 2944 | (starting-indentation | 2944 | (starting-indentation (current-indentation)) |
| 2945 | (save-excursion | 2945 | (starting-pos (point)) |
| 2946 | (and | 2946 | (first-run t) |
| 2947 | (python-nav-beginning-of-defun 1) | 2947 | (last-indent) |
| 2948 | ;; This extra number is just for checking code | 2948 | (type)) |
| 2949 | ;; against indentation to work well on first run. | 2949 | (catch 'exit |
| 2950 | (+ (current-indentation) 4)))) | 2950 | (while (python-nav-beginning-of-defun 1) |
| 2951 | (starting-point (point))) | 2951 | (when (and |
| 2952 | ;; Check point is inside a defun. | 2952 | (or (not last-indent) |
| 2953 | (when (and starting-indentation | 2953 | (< (current-indentation) last-indent)) |
| 2954 | (< starting-point | 2954 | (or |
| 2955 | (and first-run | ||
| 2955 | (save-excursion | 2956 | (save-excursion |
| 2956 | (python-nav-end-of-defun) | 2957 | ;; If this is the first run, we may add |
| 2957 | (point)))) | 2958 | ;; the current defun at point. |
| 2958 | (catch 'exit | 2959 | (setq first-run nil) |
| 2959 | (while (python-nav-beginning-of-defun 1) | 2960 | (goto-char starting-pos) |
| 2960 | (when (< (current-indentation) starting-indentation) | 2961 | (python-nav-beginning-of-statement) |
| 2961 | (setq starting-indentation (current-indentation)) | 2962 | (beginning-of-line 1) |
| 2962 | (setq names | 2963 | (looking-at-p |
| 2963 | (cons | 2964 | python-nav-beginning-of-defun-regexp))) |
| 2964 | (if (not include-type) | 2965 | (< starting-pos |
| 2965 | (match-string-no-properties 1) | 2966 | (save-excursion |
| 2966 | (mapconcat 'identity | 2967 | (let ((min-indent |
| 2967 | (split-string | 2968 | (+ (current-indentation) |
| 2968 | (match-string-no-properties 0)) " ")) | 2969 | python-indent-offset))) |
| 2969 | names))) | 2970 | (if (< starting-indentation min-indent) |
| 2970 | (and (= (current-indentation) 0) (throw 'exit t))))) | 2971 | ;; If the starting indentation is not |
| 2971 | (and names | 2972 | ;; within the min defun indent make the |
| 2972 | (mapconcat (lambda (string) string) names ".")))))) | 2973 | ;; check fail. |
| 2974 | starting-pos | ||
| 2975 | ;; Else go to the end of defun and add | ||
| 2976 | ;; up the current indentation to the | ||
| 2977 | ;; ending position. | ||
| 2978 | (python-nav-end-of-defun) | ||
| 2979 | (+ (point) | ||
| 2980 | (if (>= (current-indentation) min-indent) | ||
| 2981 | (1+ (current-indentation)) | ||
| 2982 | 0)))))))) | ||
| 2983 | (setq last-indent (current-indentation)) | ||
| 2984 | (if (or (not include-type) type) | ||
| 2985 | (setq names (cons (match-string-no-properties 1) names)) | ||
| 2986 | (let ((match (split-string (match-string-no-properties 0)))) | ||
| 2987 | (setq type (car match)) | ||
| 2988 | (setq names (cons (cadr match) names))))) | ||
| 2989 | ;; Stop searching ASAP. | ||
| 2990 | (and (= (current-indentation) 0) (throw 'exit t)))) | ||
| 2991 | (and names | ||
| 2992 | (concat (and type (format "%s " type)) | ||
| 2993 | (mapconcat 'identity names "."))))))) | ||
| 2973 | 2994 | ||
| 2974 | (defun python-info-current-symbol (&optional replace-self) | 2995 | (defun python-info-current-symbol (&optional replace-self) |
| 2975 | "Return current symbol using dotty syntax. | 2996 | "Return current symbol using dotty syntax. |