Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1c1fbf8

Browse files
committed
Barry's 2.12 -- fix some bugs in electric colon code
1 parent 1d5645d commit 1c1fbf8

1 file changed

Lines changed: 43 additions & 22 deletions

File tree

Misc/python-mode-old.el

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
;; 1992-1994 Tim Peters <[email protected]>
77
;; Maintainer: [email protected]
88
;; 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
1111
;; Keywords: python editing language major-mode
1212

1313
;; This software is provided as-is, without express or implied
@@ -68,7 +68,7 @@
6868
;; LCD Archive Entry:
6969
;; python-mode|Barry A. Warsaw|[email protected]
7070
;; |Major mode for editing Python programs
71-
;; |1995/03/14 18:32:54|2.11|
71+
;; |1995/03/14 20:53:08|2.12|
7272

7373
;;; Code:
7474

@@ -310,13 +310,25 @@ Currently-active file is at the head of the list.")
310310
(defconst py-outdent-re
311311
(concat "\\(" (mapconcat 'identity
312312
'("else:"
313-
"except\\s +.*:"
313+
"except\\(\\s +.*\\)?:"
314314
"finally:"
315315
"elif\\s +.*:")
316316
"\\|")
317317
"\\)")
318318
"Regexp matching clauses to be outdented one level.")
319319

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+
320332

321333
;;;###autoload
322334
(defun python-mode ()
@@ -397,20 +409,27 @@ In certain cases the line is outdented appropriately. If a numeric
397409
argument is provided, that many colons are inserted non-electrically."
398410
(interactive "P")
399411
(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))
414433
)))
415434

416435

@@ -630,10 +649,12 @@ needed so that only a single column position is deleted."
630649
(let* ((ci (current-indentation))
631650
(move-to-indentation-p (<= (current-column) ci))
632651
(need (py-compute-indentation)))
633-
;; watch for outdents
652+
;; see if we need to outdent
634653
(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)))))
637658
(setq need (- need py-indent-offset)))
638659
(if (/= ci need)
639660
(save-excursion
@@ -1839,7 +1860,7 @@ local bindings to py-newline-and-indent."))
18391860
(setq zmacs-region-stays t)))
18401861

18411862

1842-
(defconst py-version "2.11"
1863+
(defconst py-version "2.12"
18431864
"`python-mode' version number.")
18441865
(defconst py-help-address "[email protected]"
18451866
"Address accepting submission of bug reports.")

0 commit comments

Comments
 (0)