|
6 | 6 | ;; 1992-1994 Tim Peters <[email protected]> |
7 | 7 | |
8 | 8 | ;; Created: Feb 1992 |
9 | | -;; Version: 2.11 |
10 | | -;; Last Modified: 1995/03/14 18:32:54 |
| 9 | +;; Version: 2.12 |
| 10 | +;; Last Modified: 1995/03/14 20:53:08 |
11 | 11 | ;; Keywords: python editing language major-mode |
12 | 12 |
|
13 | 13 | ;; This software is provided as-is, without express or implied |
|
68 | 68 | ;; LCD Archive Entry: |
69 | 69 | ;; python-mode|Barry A. Warsaw|[email protected] |
70 | 70 | ;; |Major mode for editing Python programs |
71 | | -;; |1995/03/14 18:32:54|2.11| |
| 71 | +;; |1995/03/14 20:53:08|2.12| |
72 | 72 |
|
73 | 73 | ;;; Code: |
74 | 74 |
|
@@ -310,13 +310,25 @@ Currently-active file is at the head of the list.") |
310 | 310 | (defconst py-outdent-re |
311 | 311 | (concat "\\(" (mapconcat 'identity |
312 | 312 | '("else:" |
313 | | - "except\\s +.*:" |
| 313 | + "except\\(\\s +.*\\)?:" |
314 | 314 | "finally:" |
315 | 315 | "elif\\s +.*:") |
316 | 316 | "\\|") |
317 | 317 | "\\)") |
318 | 318 | "Regexp matching clauses to be outdented one level.") |
319 | 319 |
|
| 320 | +(defconst py-no-outdent-re |
| 321 | + (concat "\\(" (mapconcat 'identity |
| 322 | + '("try\\s +.*:" |
| 323 | + "except\\(\\s +.*\\)?:" |
| 324 | + "while\\s +.*:" |
| 325 | + "for\\s +.*:" |
| 326 | + "if\\s +.*:" |
| 327 | + "elif\\s +.*:") |
| 328 | + "\\|") |
| 329 | + "\\)") |
| 330 | + "Regexp matching lines to not outdent after.") |
| 331 | + |
320 | 332 |
|
321 | 333 | ;;;###autoload |
322 | 334 | (defun python-mode () |
@@ -397,20 +409,27 @@ In certain cases the line is outdented appropriately. If a numeric |
397 | 409 | argument is provided, that many colons are inserted non-electrically." |
398 | 410 | (interactive "P") |
399 | 411 | (self-insert-command (prefix-numeric-value arg)) |
400 | | - (let (this-indent) |
401 | | - (if (and (not arg) |
402 | | - (save-excursion |
403 | | - (back-to-indentation) |
404 | | - (looking-at py-outdent-re)) |
405 | | - (= (setq this-indent (py-compute-indentation)) |
406 | | - (save-excursion |
407 | | - (forward-line -1) |
408 | | - (py-compute-indentation))) |
409 | | - ) |
410 | | - (save-excursion |
411 | | - (beginning-of-line) |
412 | | - (delete-horizontal-space) |
413 | | - (indent-to (- this-indent py-indent-offset))) |
| 412 | + (save-excursion |
| 413 | + (let ((here (point)) |
| 414 | + (outdent 0) |
| 415 | + (indent (py-compute-indentation))) |
| 416 | + (if (and (not arg) |
| 417 | + (progn |
| 418 | + (back-to-indentation) |
| 419 | + (looking-at py-outdent-re)) |
| 420 | + (prog2 |
| 421 | + (backward-to-indentation 1) |
| 422 | + (not (looking-at py-no-outdent-re)) |
| 423 | + (goto-char here)) |
| 424 | + (= indent (progn |
| 425 | + (forward-line -1) |
| 426 | + (py-compute-indentation))) |
| 427 | + ) |
| 428 | + (setq outdent py-indent-offset)) |
| 429 | + (goto-char here) |
| 430 | + (beginning-of-line) |
| 431 | + (delete-horizontal-space) |
| 432 | + (indent-to (- indent outdent)) |
414 | 433 | ))) |
415 | 434 |
|
416 | 435 |
|
@@ -630,10 +649,12 @@ needed so that only a single column position is deleted." |
630 | 649 | (let* ((ci (current-indentation)) |
631 | 650 | (move-to-indentation-p (<= (current-column) ci)) |
632 | 651 | (need (py-compute-indentation))) |
633 | | - ;; watch for outdents |
| 652 | + ;; see if we need to outdent |
634 | 653 | (if (save-excursion |
635 | | - (back-to-indentation) |
636 | | - (looking-at py-outdent-re)) |
| 654 | + (and (progn (back-to-indentation) |
| 655 | + (looking-at py-outdent-re)) |
| 656 | + (progn (backward-to-indentation 1) |
| 657 | + (not (looking-at py-no-outdent-re))))) |
637 | 658 | (setq need (- need py-indent-offset))) |
638 | 659 | (if (/= ci need) |
639 | 660 | (save-excursion |
@@ -1839,7 +1860,7 @@ local bindings to py-newline-and-indent.")) |
1839 | 1860 | (setq zmacs-region-stays t))) |
1840 | 1861 |
|
1841 | 1862 |
|
1842 | | -(defconst py-version "2.11" |
| 1863 | +(defconst py-version "2.12" |
1843 | 1864 | "`python-mode' version number.") |
1844 | 1865 | ( defconst py-help-address "[email protected]" |
1845 | 1866 | "Address accepting submission of bug reports.") |
|
0 commit comments