diff options
| author | Paul Eggert | 2013-02-14 22:35:54 -0800 |
|---|---|---|
| committer | Paul Eggert | 2013-02-14 22:35:54 -0800 |
| commit | 648e5523fbfc3dfbce58f66437112bc442470c87 (patch) | |
| tree | 6ead7871ba1026168c7f7c4d1f4cffa5241f864b /lisp/progmodes/python.el | |
| parent | dec2a322921d74de8f251a54931d4c50ab00713d (diff) | |
| parent | 974c7646ec5b2985a50007c9d599154d667df349 (diff) | |
| download | emacs-648e5523fbfc3dfbce58f66437112bc442470c87.tar.gz emacs-648e5523fbfc3dfbce58f66437112bc442470c87.zip | |
Merge from emacs-24; up to 2012-12-19T13:01:16Z!michael.albinus@gmx.de
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 129 |
1 files changed, 76 insertions, 53 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 35c5ba19e33..eadb06fa61e 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -54,8 +54,13 @@ | |||
| 54 | ;; `python-nav-beginning-of-statement', `python-nav-end-of-statement', | 54 | ;; `python-nav-beginning-of-statement', `python-nav-end-of-statement', |
| 55 | ;; `python-nav-beginning-of-block' and `python-nav-end-of-block' are | 55 | ;; `python-nav-beginning-of-block' and `python-nav-end-of-block' are |
| 56 | ;; included but no bound to any key. At last but not least the | 56 | ;; included but no bound to any key. At last but not least the |
| 57 | ;; specialized `python-nav-forward-sexp' allows easy | 57 | ;; specialized `python-nav-forward-sexp' allows easy navigation |
| 58 | ;; navigation between code blocks. | 58 | ;; between code blocks. If you prefer `cc-mode'-like `forward-sexp' |
| 59 | ;; movement, setting `forward-sexp-function' to nil is enough, You can | ||
| 60 | ;; do that using the `python-mode-hook': | ||
| 61 | |||
| 62 | ;; (add-hook 'python-mode-hook | ||
| 63 | ;; (lambda () (setq forward-sexp-function nil))) | ||
| 59 | 64 | ||
| 60 | ;; Shell interaction: is provided and allows you to execute easily any | 65 | ;; Shell interaction: is provided and allows you to execute easily any |
| 61 | ;; block of code of your current buffer in an inferior Python process. | 66 | ;; block of code of your current buffer in an inferior Python process. |
| @@ -1349,13 +1354,10 @@ backwards." | |||
| 1349 | 're-search-backward)) | 1354 | 're-search-backward)) |
| 1350 | (context-type (python-syntax-context-type))) | 1355 | (context-type (python-syntax-context-type))) |
| 1351 | (cond | 1356 | (cond |
| 1352 | ((eq context-type 'string) | 1357 | ((memq context-type '(string comment)) |
| 1353 | ;; Inside of a string, get out of it. | 1358 | ;; Inside of a string, get out of it. |
| 1354 | (while (and (funcall re-search-fn "[\"']" nil t) | 1359 | (let ((forward-sexp-function)) |
| 1355 | (python-syntax-context 'string)))) | 1360 | (forward-sexp dir))) |
| 1356 | ((eq context-type 'comment) | ||
| 1357 | ;; Inside of a comment, just move forward. | ||
| 1358 | (python-util-forward-comment dir)) | ||
| 1359 | ((or (eq context-type 'paren) | 1361 | ((or (eq context-type 'paren) |
| 1360 | (and forward-p (looking-at (python-rx open-paren))) | 1362 | (and forward-p (looking-at (python-rx open-paren))) |
| 1361 | (and (not forward-p) | 1363 | (and (not forward-p) |
| @@ -1378,16 +1380,16 @@ backwards." | |||
| 1378 | (save-excursion | 1380 | (save-excursion |
| 1379 | (python-nav-lisp-forward-sexp-safe dir) | 1381 | (python-nav-lisp-forward-sexp-safe dir) |
| 1380 | (point))) | 1382 | (point))) |
| 1381 | (next-sexp-context | 1383 | (next-sexp-context |
| 1382 | (save-excursion | 1384 | (save-excursion |
| 1383 | (goto-char next-sexp-pos) | 1385 | (goto-char next-sexp-pos) |
| 1384 | (cond | 1386 | (cond |
| 1385 | ((python-info-beginning-of-block-p) 'block-start) | 1387 | ((python-info-beginning-of-block-p) 'block-start) |
| 1386 | ((python-info-end-of-block-p) 'block-end) | 1388 | ((python-info-end-of-block-p) 'block-end) |
| 1387 | ((python-info-beginning-of-statement-p) 'statement-start) | 1389 | ((python-info-beginning-of-statement-p) 'statement-start) |
| 1388 | ((python-info-end-of-statement-p) 'statement-end) | 1390 | ((python-info-end-of-statement-p) 'statement-end) |
| 1389 | ((python-info-statement-starts-block-p) 'starts-block) | 1391 | ((python-info-statement-starts-block-p) 'starts-block) |
| 1390 | ((python-info-statement-ends-block-p) 'ends-block))))) | 1392 | ((python-info-statement-ends-block-p) 'ends-block))))) |
| 1391 | (if forward-p | 1393 | (if forward-p |
| 1392 | (cond ((and (not (eobp)) | 1394 | (cond ((and (not (eobp)) |
| 1393 | (python-info-current-line-empty-p)) | 1395 | (python-info-current-line-empty-p)) |
| @@ -1411,8 +1413,8 @@ backwards." | |||
| 1411 | (t (goto-char next-sexp-pos))) | 1413 | (t (goto-char next-sexp-pos))) |
| 1412 | (cond ((and (not (bobp)) | 1414 | (cond ((and (not (bobp)) |
| 1413 | (python-info-current-line-empty-p)) | 1415 | (python-info-current-line-empty-p)) |
| 1414 | (python-util-forward-comment dir) | 1416 | (python-util-forward-comment dir) |
| 1415 | (python-nav--forward-sexp dir)) | 1417 | (python-nav--forward-sexp dir)) |
| 1416 | ((eq context 'block-end) | 1418 | ((eq context 'block-end) |
| 1417 | (python-nav-beginning-of-block)) | 1419 | (python-nav-beginning-of-block)) |
| 1418 | ((eq context 'statement-end) | 1420 | ((eq context 'statement-end) |
| @@ -2946,40 +2948,61 @@ Optional argument INCLUDE-TYPE indicates to include the type of the defun. | |||
| 2946 | This function is compatible to be used as | 2948 | This function is compatible to be used as |
| 2947 | `add-log-current-defun-function' since it returns nil if point is | 2949 | `add-log-current-defun-function' since it returns nil if point is |
| 2948 | not inside a defun." | 2950 | not inside a defun." |
| 2949 | (save-restriction | 2951 | (save-restriction |
| 2950 | (widen) | 2952 | (widen) |
| 2951 | (save-excursion | 2953 | (save-excursion |
| 2952 | (end-of-line 1) | 2954 | (end-of-line 1) |
| 2953 | (let ((names) | 2955 | (let ((names) |
| 2954 | (starting-indentation | 2956 | (starting-indentation (current-indentation)) |
| 2955 | (save-excursion | 2957 | (starting-pos (point)) |
| 2956 | (and | 2958 | (first-run t) |
| 2957 | (python-nav-beginning-of-defun 1) | 2959 | (last-indent) |
| 2958 | ;; This extra number is just for checking code | 2960 | (type)) |
| 2959 | ;; against indentation to work well on first run. | 2961 | (catch 'exit |
| 2960 | (+ (current-indentation) 4)))) | 2962 | (while (python-nav-beginning-of-defun 1) |
| 2961 | (starting-point (point))) | 2963 | (when (and |
| 2962 | ;; Check point is inside a defun. | 2964 | (or (not last-indent) |
| 2963 | (when (and starting-indentation | 2965 | (< (current-indentation) last-indent)) |
| 2964 | (< starting-point | 2966 | (or |
| 2967 | (and first-run | ||
| 2965 | (save-excursion | 2968 | (save-excursion |
| 2966 | (python-nav-end-of-defun) | 2969 | ;; If this is the first run, we may add |
| 2967 | (point)))) | 2970 | ;; the current defun at point. |
| 2968 | (catch 'exit | 2971 | (setq first-run nil) |
| 2969 | (while (python-nav-beginning-of-defun 1) | 2972 | (goto-char starting-pos) |
| 2970 | (when (< (current-indentation) starting-indentation) | 2973 | (python-nav-beginning-of-statement) |
| 2971 | (setq starting-indentation (current-indentation)) | 2974 | (beginning-of-line 1) |
| 2972 | (setq names | 2975 | (looking-at-p |
| 2973 | (cons | 2976 | python-nav-beginning-of-defun-regexp))) |
| 2974 | (if (not include-type) | 2977 | (< starting-pos |
| 2975 | (match-string-no-properties 1) | 2978 | (save-excursion |
| 2976 | (mapconcat 'identity | 2979 | (let ((min-indent |
| 2977 | (split-string | 2980 | (+ (current-indentation) |
| 2978 | (match-string-no-properties 0)) " ")) | 2981 | python-indent-offset))) |
| 2979 | names))) | 2982 | (if (< starting-indentation min-indent) |
| 2980 | (and (= (current-indentation) 0) (throw 'exit t))))) | 2983 | ;; If the starting indentation is not |
| 2981 | (and names | 2984 | ;; within the min defun indent make the |
| 2982 | (mapconcat (lambda (string) string) names ".")))))) | 2985 | ;; check fail. |
| 2986 | starting-pos | ||
| 2987 | ;; Else go to the end of defun and add | ||
| 2988 | ;; up the current indentation to the | ||
| 2989 | ;; ending position. | ||
| 2990 | (python-nav-end-of-defun) | ||
| 2991 | (+ (point) | ||
| 2992 | (if (>= (current-indentation) min-indent) | ||
| 2993 | (1+ (current-indentation)) | ||
| 2994 | 0)))))))) | ||
| 2995 | (setq last-indent (current-indentation)) | ||
| 2996 | (if (or (not include-type) type) | ||
| 2997 | (setq names (cons (match-string-no-properties 1) names)) | ||
| 2998 | (let ((match (split-string (match-string-no-properties 0)))) | ||
| 2999 | (setq type (car match)) | ||
| 3000 | (setq names (cons (cadr match) names))))) | ||
| 3001 | ;; Stop searching ASAP. | ||
| 3002 | (and (= (current-indentation) 0) (throw 'exit t)))) | ||
| 3003 | (and names | ||
| 3004 | (concat (and type (format "%s " type)) | ||
| 3005 | (mapconcat 'identity names "."))))))) | ||
| 2983 | 3006 | ||
| 2984 | (defun python-info-current-symbol (&optional replace-self) | 3007 | (defun python-info-current-symbol (&optional replace-self) |
| 2985 | "Return current symbol using dotty syntax. | 3008 | "Return current symbol using dotty syntax. |