]> granicus.if.org Git - python/commitdiff
(python-font-lock-keywords): Pick up block introducing keywords with
authorBarry Warsaw <barry@python.org>
Thu, 6 Nov 1997 14:35:15 +0000 (14:35 +0000)
committerBarry Warsaw <barry@python.org>
Thu, 6 Nov 1997 14:35:15 +0000 (14:35 +0000)
immediately following colons.  Sjoerd noticed this one too.  Here's a
nonsense.py file that flexes all the font-lock keyword combinations.

class A:
    class B(A):
pass
    def __init__(self):
if i == 2 and j == 3 or k == 4:
    import stuff
    from otherstuff import cool
    for i in range(cool.count):
if i == j:
    break
elif j == 1:
    continue
print i
    else:
return not i
elif q is not i:
    return lambda x: x + 1
else:
    try:
try:
    raise stuff.error
except stuff.error, v:
    print v
except:
    global q
    finally:
while q > 0:
    q = q - 1
assert q == 0

def make():
    a = A()
    exec "nonsense"
    del a

Misc/python-mode.el

index ebcb1397a047523b0505969e1609975d7384f601..d598bc662b49fef9c7ba1421d290bcbb585e7b4f 100644 (file)
@@ -246,19 +246,26 @@ There are many flavors of Emacs out there, each with different
 features supporting those needed by CC Mode.")
 
 (defvar python-font-lock-keywords
-  (let* ((keywords '("and"        "assert"     "break"      "class"
-                    "continue"   "def"        "del"        "elif"
-                    "else:"      "except"     "except:"    "exec"
-                    "finally:"   "for"        "from"       "global"
-                    "if"         "import"     "in"         "is"
-                    "lambda"     "not"        "or"         "pass"
-                    "print"      "raise"      "return"     "try:"
-                    "while"
-                    ))
-        (kwregex (mapconcat 'identity keywords "\\|")))
+  (let ((kw1 (mapconcat 'identity
+                       '("and"      "assert"   "break"   "class"
+                         "continue" "def"      "del"     "elif"
+                         "else"     "except"   "exec"    "for"
+                         "from"     "global"   "if"      "import"
+                         "in"       "is"       "lambda"  "not"
+                         "or"       "pass"     "print"   "raise"
+                         "return"   "while"
+                         )
+                       "\\|"))
+       (kw2 (mapconcat 'identity
+                       '("else:" "except:" "finally:" "try:")
+                       "\\|"))
+       )
     (list
      ;; keywords
-     (cons (concat "\\b\\(" kwregex "\\)\\b[ \n\t(]") 1)
+     (cons (concat "\\b\\(" kw1 "\\)\\b[ \n\t(]") 1)
+     ;; block introducing keywords with immediately following colons.
+     ;; Yes "except" is in both lists.
+     (cons (concat "\\b\\(" kw2 "\\)[ \n\t(]") 1)
      ;; classes
      '("\\bclass[ \t]+\\([a-zA-Z_]+[a-zA-Z0-9_]*\\)"
        1 font-lock-type-face)