diff options
| author | Fabián Ezequiel Gallina | 2012-10-08 23:07:26 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina | 2012-10-08 23:07:26 -0300 |
| commit | a4ff7fe1452e56d2c11ca31652bd145868e87e17 (patch) | |
| tree | a5147d1d065e92aa928dab125bf3134002bf9ebc /lisp/progmodes/python.el | |
| parent | 24517d82a98eaeb33f44854e72bfbf342bf24ea4 (diff) | |
| download | emacs-a4ff7fe1452e56d2c11ca31652bd145868e87e17.tar.gz emacs-a4ff7fe1452e56d2c11ca31652bd145868e87e17.zip | |
Implemented `backward-up-list'-like navigation.
* progmodes/python.el (python-nav-up-list)
(python-nav-backward-up-list): New functions.
(python-mode-map): Define substitute key for backward-up-list to
python-nav-backward-up-list.
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 0bde8ce3334..5bf64c18f99 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -235,6 +235,9 @@ | |||
| 235 | (substitute-key-definition 'forward-sentence | 235 | (substitute-key-definition 'forward-sentence |
| 236 | 'python-nav-forward-block | 236 | 'python-nav-forward-block |
| 237 | map global-map) | 237 | map global-map) |
| 238 | (substitute-key-definition 'backward-up-list | ||
| 239 | 'python-nav-backward-up-list | ||
| 240 | map global-map) | ||
| 238 | (define-key map "\C-c\C-j" 'imenu) | 241 | (define-key map "\C-c\C-j" 'imenu) |
| 239 | ;; Indent specific | 242 | ;; Indent specific |
| 240 | (define-key map "\177" 'python-indent-dedent-line-backspace) | 243 | (define-key map "\177" 'python-indent-dedent-line-backspace) |
| @@ -1409,6 +1412,67 @@ move backward N times." | |||
| 1409 | (python-nav--backward-sexp) | 1412 | (python-nav--backward-sexp) |
| 1410 | (setq arg (1+ arg)))) | 1413 | (setq arg (1+ arg)))) |
| 1411 | 1414 | ||
| 1415 | (defun python-nav--up-list (&optional dir) | ||
| 1416 | "Internal implementation of `python-nav-up-list'. | ||
| 1417 | DIR is always 1 or -1 and comes sanitized from | ||
| 1418 | `python-nav-up-list' calls." | ||
| 1419 | (let ((context (python-syntax-context-type)) | ||
| 1420 | (forward-p (> dir 0))) | ||
| 1421 | (cond | ||
| 1422 | ((memq context '(string comment))) | ||
| 1423 | ((eq context 'paren) | ||
| 1424 | (let ((forward-sexp-function)) | ||
| 1425 | (up-list dir))) | ||
| 1426 | ((and forward-p (python-info-end-of-block-p)) | ||
| 1427 | (let ((parent-end-pos | ||
| 1428 | (save-excursion | ||
| 1429 | (let ((indentation (and | ||
| 1430 | (python-nav-beginning-of-block) | ||
| 1431 | (current-indentation)))) | ||
| 1432 | (while (and indentation | ||
| 1433 | (> indentation 0) | ||
| 1434 | (>= (current-indentation) indentation) | ||
| 1435 | (python-nav-backward-block))) | ||
| 1436 | (python-nav-end-of-block))))) | ||
| 1437 | (and (> (or parent-end-pos (point)) (point)) | ||
| 1438 | (goto-char parent-end-pos)))) | ||
| 1439 | (forward-p (python-nav-end-of-block)) | ||
| 1440 | ((and (not forward-p) | ||
| 1441 | (> (current-indentation) 0) | ||
| 1442 | (python-info-beginning-of-block-p)) | ||
| 1443 | (let ((prev-block-pos | ||
| 1444 | (save-excursion | ||
| 1445 | (let ((indentation (current-indentation))) | ||
| 1446 | (while (and (python-nav-backward-block) | ||
| 1447 | (> (current-indentation) indentation)))) | ||
| 1448 | (point)))) | ||
| 1449 | (and (> (point) prev-block-pos) | ||
| 1450 | (goto-char prev-block-pos)))) | ||
| 1451 | ((not forward-p) (python-nav-beginning-of-block))))) | ||
| 1452 | |||
| 1453 | (defun python-nav-up-list (&optional arg) | ||
| 1454 | "Move forward out of one level of parentheses (or blocks). | ||
| 1455 | With ARG, do this that many times. | ||
| 1456 | A negative argument means move backward but still to a less deep spot. | ||
| 1457 | This command assumes point is not in a string or comment." | ||
| 1458 | (interactive "^p") | ||
| 1459 | (or arg (setq arg 1)) | ||
| 1460 | (while (> arg 0) | ||
| 1461 | (python-nav--up-list 1) | ||
| 1462 | (setq arg (1- arg))) | ||
| 1463 | (while (< arg 0) | ||
| 1464 | (python-nav--up-list -1) | ||
| 1465 | (setq arg (1+ arg)))) | ||
| 1466 | |||
| 1467 | (defun python-nav-backward-up-list (&optional arg) | ||
| 1468 | "Move backward out of one level of parentheses (or blocks). | ||
| 1469 | With ARG, do this that many times. | ||
| 1470 | A negative argument means move backward but still to a less deep spot. | ||
| 1471 | This command assumes point is not in a string or comment." | ||
| 1472 | (interactive "^p") | ||
| 1473 | (or arg (setq arg 1)) | ||
| 1474 | (python-nav-up-list (- arg))) | ||
| 1475 | |||
| 1412 | 1476 | ||
| 1413 | ;;; Shell integration | 1477 | ;;; Shell integration |
| 1414 | 1478 | ||