emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

23.0.60; python-mode indents try...except...finally incorrectly


From: Phil Sung
Subject: 23.0.60; python-mode indents try...except...finally incorrectly
Date: Sun, 23 Mar 2008 17:33:25 -0400

In GNU Emacs 23.0.60.1 (i486-pc-linux-gnu, GTK+ Version 2.12.8)
 of 2008-03-01 on palmer, modified by Debian
 (emacs-snapshot package, version 1:20080228-1ubuntu1)
configured using `configure  '--build' 'i486-linux-gnu' '--host'
'i486-linux-gnu' '--prefix=/usr' '--sharedstatedir=/var/lib'
'--libexecdir=/usr/lib' '--localstatedir=/var'
'--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-pop=yes'
'--enable-locallisppath=/etc/emacs-snapshot:/etc/emacs:/usr/local/share/emacs/23.0.60/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/23.0.60/site-lisp:/usr/share/emacs/site-lisp:/usr/share/emacs/23.0.60/leim'
'--with-x=yes' '--with-x-toolkit=gtk' '--enable-font-backend'
'build_alias=i486-linux-gnu' 'host_alias=i486-linux-gnu'
'CFLAGS=-DDEBIAN -DSITELOAD_PURESIZE_EXTRA=5000 -g -O2' 'LDFLAGS=-g
-Wl,--as-needed' 'CPPFLAGS=''


In python-mode, if you attempt to type the following...

def f():
    try:
        foo
    except:
        bar
    finally:
        baz

it gets incorrectly indented as shown below. Emacs tries to put
"finally:" in the first column.

def f():
    try:
        foo
    except:
        bar
finally:
    baz

"finally:" is allowed after an "except:" at the same level in Python
2.5 and later. The patch below fixes python.el to allow that
construct.

--Phil


    progmodes/python.el (python-block-pairs): Allow "finally:" at the same
    level as, and following, an "except:". (try... except... finally blocks are
    allowed in Python 2.5 and later.)

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index e9f3daf..cca0bb0 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -749,7 +749,7 @@ Set `python-indent' locally to the value guessed."
   '(("else" "if" "elif" "while" "for" "try" "except")
     ("elif" "if" "elif")
     ("except" "try" "except")
-    ("finally" "try"))
+    ("finally" "try" "except"))
   "Alist of keyword matches.
 The car of an element is a keyword introducing a statement which
 can close a block opened by a keyword in the cdr.")




reply via email to

[Prev in Thread] Current Thread [Next in Thread]