diff options
| author | Fabián Ezequiel Gallina | 2013-02-13 21:42:11 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina | 2013-02-13 21:42:11 -0300 |
| commit | ea5f4192b9954301c0c65804586ed7daf3a98c16 (patch) | |
| tree | 885746cf9a817ef04534f22318a948157c279922 /lisp/progmodes/python.el | |
| parent | 5cd3d1e56e3e6c7dfefc77bc78280173d4bc32d2 (diff) | |
| download | emacs-ea5f4192b9954301c0c65804586ed7daf3a98c16.tar.gz emacs-ea5f4192b9954301c0c65804586ed7daf3a98c16.zip | |
* progmodes/python.el: Explain how to restore "cc-mode"-like
forward-sexp movement in header documentation.
(python-nav--forward-sexp): Behave like emacs-lisp-mode in
comments and strings (GH bug 114).
Fixes: debbugs:13642
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index e611864e0c1..92f86ce1231 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. |
| @@ -1339,13 +1344,10 @@ backwards." | |||
| 1339 | 're-search-backward)) | 1344 | 're-search-backward)) |
| 1340 | (context-type (python-syntax-context-type))) | 1345 | (context-type (python-syntax-context-type))) |
| 1341 | (cond | 1346 | (cond |
| 1342 | ((eq context-type 'string) | 1347 | ((memq context-type '(string comment)) |
| 1343 | ;; Inside of a string, get out of it. | 1348 | ;; Inside of a string, get out of it. |
| 1344 | (while (and (funcall re-search-fn "[\"']" nil t) | 1349 | (let ((forward-sexp-function)) |
| 1345 | (python-syntax-context 'string)))) | 1350 | (forward-sexp dir))) |
| 1346 | ((eq context-type 'comment) | ||
| 1347 | ;; Inside of a comment, just move forward. | ||
| 1348 | (python-util-forward-comment dir)) | ||
| 1349 | ((or (eq context-type 'paren) | 1351 | ((or (eq context-type 'paren) |
| 1350 | (and forward-p (looking-at (python-rx open-paren))) | 1352 | (and forward-p (looking-at (python-rx open-paren))) |
| 1351 | (and (not forward-p) | 1353 | (and (not forward-p) |
| @@ -1368,16 +1370,16 @@ backwards." | |||
| 1368 | (save-excursion | 1370 | (save-excursion |
| 1369 | (python-nav-lisp-forward-sexp-safe dir) | 1371 | (python-nav-lisp-forward-sexp-safe dir) |
| 1370 | (point))) | 1372 | (point))) |
| 1371 | (next-sexp-context | 1373 | (next-sexp-context |
| 1372 | (save-excursion | 1374 | (save-excursion |
| 1373 | (goto-char next-sexp-pos) | 1375 | (goto-char next-sexp-pos) |
| 1374 | (cond | 1376 | (cond |
| 1375 | ((python-info-beginning-of-block-p) 'block-start) | 1377 | ((python-info-beginning-of-block-p) 'block-start) |
| 1376 | ((python-info-end-of-block-p) 'block-end) | 1378 | ((python-info-end-of-block-p) 'block-end) |
| 1377 | ((python-info-beginning-of-statement-p) 'statement-start) | 1379 | ((python-info-beginning-of-statement-p) 'statement-start) |
| 1378 | ((python-info-end-of-statement-p) 'statement-end) | 1380 | ((python-info-end-of-statement-p) 'statement-end) |
| 1379 | ((python-info-statement-starts-block-p) 'starts-block) | 1381 | ((python-info-statement-starts-block-p) 'starts-block) |
| 1380 | ((python-info-statement-ends-block-p) 'ends-block))))) | 1382 | ((python-info-statement-ends-block-p) 'ends-block))))) |
| 1381 | (if forward-p | 1383 | (if forward-p |
| 1382 | (cond ((and (not (eobp)) | 1384 | (cond ((and (not (eobp)) |
| 1383 | (python-info-current-line-empty-p)) | 1385 | (python-info-current-line-empty-p)) |
| @@ -1401,8 +1403,8 @@ backwards." | |||
| 1401 | (t (goto-char next-sexp-pos))) | 1403 | (t (goto-char next-sexp-pos))) |
| 1402 | (cond ((and (not (bobp)) | 1404 | (cond ((and (not (bobp)) |
| 1403 | (python-info-current-line-empty-p)) | 1405 | (python-info-current-line-empty-p)) |
| 1404 | (python-util-forward-comment dir) | 1406 | (python-util-forward-comment dir) |
| 1405 | (python-nav--forward-sexp dir)) | 1407 | (python-nav--forward-sexp dir)) |
| 1406 | ((eq context 'block-end) | 1408 | ((eq context 'block-end) |
| 1407 | (python-nav-beginning-of-block)) | 1409 | (python-nav-beginning-of-block)) |
| 1408 | ((eq context 'statement-end) | 1410 | ((eq context 'statement-end) |