diff options
| author | Fabián Ezequiel Gallina | 2012-05-17 00:03:42 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina | 2012-05-17 00:03:42 -0300 |
| commit | cd7ab092997474f7abba8bff2e0c5df888011ed7 (patch) | |
| tree | 358ede1f9dfdf1d41382c310616ac14d0a9fc0d2 /lisp/progmodes/python.el | |
| parent | 5eae76aed18a165854f55911ab8a5ac2bd83feed (diff) | |
| download | emacs-cd7ab092997474f7abba8bff2e0c5df888011ed7.tar.gz emacs-cd7ab092997474f7abba8bff2e0c5df888011ed7.zip | |
Enhanced closing block notification when line is indented or a colon is inserted.
`python-indent-line' and `python-indent-electric-colon' now uses the
new `python-info-closing-block-message' function that takes care of
messaging the block the current line is closing (if applicable).
New Functions:
+ `python-info-closing-block-message'
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 47e6fc0380d..e549c477233 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -869,15 +869,7 @@ to (`nth' `python-indent-current-level' `python-indent-levels')" | |||
| 869 | (beginning-of-line) | 869 | (beginning-of-line) |
| 870 | (delete-horizontal-space) | 870 | (delete-horizontal-space) |
| 871 | (indent-to (nth python-indent-current-level python-indent-levels)) | 871 | (indent-to (nth python-indent-current-level python-indent-levels)) |
| 872 | (save-restriction | 872 | (python-info-closing-block-message)) |
| 873 | (widen) | ||
| 874 | (let ((closing-block-point (python-info-closing-block))) | ||
| 875 | (when closing-block-point | ||
| 876 | (message "Closes %s" (buffer-substring | ||
| 877 | closing-block-point | ||
| 878 | (save-excursion | ||
| 879 | (goto-char closing-block-point) | ||
| 880 | (line-end-position)))))))) | ||
| 881 | 873 | ||
| 882 | (defun python-indent-line-function () | 874 | (defun python-indent-line-function () |
| 883 | "`indent-line-function' for Python mode. | 875 | "`indent-line-function' for Python mode. |
| @@ -983,10 +975,11 @@ With numeric ARG, just insert that many colons. With | |||
| 983 | (python-info-ppss-context 'comment)))) | 975 | (python-info-ppss-context 'comment)))) |
| 984 | (let ((indentation (current-indentation)) | 976 | (let ((indentation (current-indentation)) |
| 985 | (calculated-indentation (python-indent-calculate-indentation))) | 977 | (calculated-indentation (python-indent-calculate-indentation))) |
| 978 | (python-info-closing-block-message) | ||
| 986 | (when (> indentation calculated-indentation) | 979 | (when (> indentation calculated-indentation) |
| 987 | (save-excursion | 980 | (save-excursion |
| 988 | (indent-line-to calculated-indentation) | 981 | (indent-line-to calculated-indentation) |
| 989 | (when (not (python-info-closing-block)) | 982 | (when (not (python-info-closing-block-message)) |
| 990 | (indent-line-to indentation))))))) | 983 | (indent-line-to indentation))))))) |
| 991 | (put 'python-indent-electric-colon 'delete-selection t) | 984 | (put 'python-indent-electric-colon 'delete-selection t) |
| 992 | 985 | ||
| @@ -2600,6 +2593,20 @@ not inside a defun." | |||
| 2600 | (when (member (current-word) '("except" "else")) | 2593 | (when (member (current-word) '("except" "else")) |
| 2601 | (point-marker)))))))) | 2594 | (point-marker)))))))) |
| 2602 | 2595 | ||
| 2596 | (defun python-info-closing-block-message (&optional closing-block-point) | ||
| 2597 | "Message the contents of the block the current line closes. | ||
| 2598 | With optional argument CLOSING-BLOCK-POINT use that instead of | ||
| 2599 | recalculating it calling `python-info-closing-block'." | ||
| 2600 | (let ((point (or closing-block-point (python-info-closing-block)))) | ||
| 2601 | (when point | ||
| 2602 | (save-restriction | ||
| 2603 | (widen) | ||
| 2604 | (message "Closes %s" (save-excursion | ||
| 2605 | (goto-char point) | ||
| 2606 | (back-to-indentation) | ||
| 2607 | (buffer-substring | ||
| 2608 | (point) (line-end-position)))))))) | ||
| 2609 | |||
| 2603 | (defun python-info-line-ends-backslash-p (&optional line-number) | 2610 | (defun python-info-line-ends-backslash-p (&optional line-number) |
| 2604 | "Return non-nil if current line ends with backslash. | 2611 | "Return non-nil if current line ends with backslash. |
| 2605 | With optional argument LINE-NUMBER, check that line instead." | 2612 | With optional argument LINE-NUMBER, check that line instead." |