comparison lisp/progmodes/python.el @ 109300:454cfd5e9cc0

Add some font-locking for Python 2.7. * lisp/progmodes/python.el (python-font-lock-keywords): Add Python 2.7 builtins (BufferError, BytesWarning, WindowsError; callables bin, bytearray, bytes, format, memoryview, next, print; __package__).
author Glenn Morris <rgm@gnu.org>
date Tue, 06 Jul 2010 21:46:58 -0700
parents 8953c1cd8568
children ba4a9b0e3879 fae81355c62c
comparison
equal deleted inserted replaced
109299:15fa65282ad3 109300:454cfd5e9cc0
91 91
92 ;;;; Font lock 92 ;;;; Font lock
93 93
94 (defvar python-font-lock-keywords 94 (defvar python-font-lock-keywords
95 `(,(rx symbol-start 95 `(,(rx symbol-start
96 ;; From v 2.5 reference, § keywords. 96 ;; From v 2.7 reference, § keywords.
97 ;; def and class dealt with separately below 97 ;; def and class dealt with separately below
98 (or "and" "as" "assert" "break" "continue" "del" "elif" "else" 98 (or "and" "as" "assert" "break" "continue" "del" "elif" "else"
99 "except" "exec" "finally" "for" "from" "global" "if" 99 "except" "exec" "finally" "for" "from" "global" "if"
100 "import" "in" "is" "lambda" "not" "or" "pass" "print" 100 "import" "in" "is" "lambda" "not" "or" "pass" "print"
101 "raise" "return" "try" "while" "with" "yield" 101 "raise" "return" "try" "while" "with" "yield"
102 ;; Not real keywords, but close enough to be fontified as such 102 ;; Not real keywords, but close enough to be fontified as such
103 "self" "True" "False") 103 "self" "True" "False")
104 symbol-end) 104 symbol-end)
105 (,(rx symbol-start "None" symbol-end) ; see § Keywords in 2.5 manual 105 (,(rx symbol-start "None" symbol-end) ; see § Keywords in 2.7 manual
106 . font-lock-constant-face) 106 . font-lock-constant-face)
107 ;; Definitions 107 ;; Definitions
108 (,(rx symbol-start (group "class") (1+ space) (group (1+ (or word ?_)))) 108 (,(rx symbol-start (group "class") (1+ space) (group (1+ (or word ?_))))
109 (1 font-lock-keyword-face) (2 font-lock-type-face)) 109 (1 font-lock-keyword-face) (2 font-lock-type-face))
110 (,(rx symbol-start (group "def") (1+ space) (group (1+ (or word ?_)))) 110 (,(rx symbol-start (group "def") (1+ space) (group (1+ (or word ?_))))
115 ;; Decorators. 115 ;; Decorators.
116 (,(rx line-start (* (any " \t")) (group "@" (1+ (or word ?_)) 116 (,(rx line-start (* (any " \t")) (group "@" (1+ (or word ?_))
117 (0+ "." (1+ (or word ?_))))) 117 (0+ "." (1+ (or word ?_)))))
118 (1 font-lock-type-face)) 118 (1 font-lock-type-face))
119 ;; Built-ins. (The next three blocks are from 119 ;; Built-ins. (The next three blocks are from
120 ;; `__builtin__.__dict__.keys()' in Python 2.5.1.) These patterns 120 ;; `__builtin__.__dict__.keys()' in Python 2.7) These patterns
121 ;; are debateable, but they at least help to spot possible 121 ;; are debateable, but they at least help to spot possible
122 ;; shadowing of builtins. 122 ;; shadowing of builtins.
123 (,(rx symbol-start (or 123 (,(rx symbol-start (or
124 ;; exceptions 124 ;; exceptions
125 "ArithmeticError" "AssertionError" "AttributeError" 125 "ArithmeticError" "AssertionError" "AttributeError"
133 "RuntimeError" "RuntimeWarning" "StandardError" 133 "RuntimeError" "RuntimeWarning" "StandardError"
134 "StopIteration" "SyntaxError" "SyntaxWarning" "SystemError" 134 "StopIteration" "SyntaxError" "SyntaxWarning" "SystemError"
135 "SystemExit" "TabError" "TypeError" "UnboundLocalError" 135 "SystemExit" "TabError" "TypeError" "UnboundLocalError"
136 "UnicodeDecodeError" "UnicodeEncodeError" "UnicodeError" 136 "UnicodeDecodeError" "UnicodeEncodeError" "UnicodeError"
137 "UnicodeTranslateError" "UnicodeWarning" "UserWarning" 137 "UnicodeTranslateError" "UnicodeWarning" "UserWarning"
138 "ValueError" "Warning" "ZeroDivisionError") symbol-end) 138 "ValueError" "Warning" "ZeroDivisionError"
139 ;; Python 2.7
140 "BufferError" "BytesWarning" "WindowsError") symbol-end)
139 . font-lock-type-face) 141 . font-lock-type-face)
140 (,(rx (or line-start (not (any ". \t"))) (* (any " \t")) symbol-start 142 (,(rx (or line-start (not (any ". \t"))) (* (any " \t")) symbol-start
141 (group (or 143 (group (or
142 ;; callable built-ins, fontified when not appearing as 144 ;; callable built-ins, fontified when not appearing as
143 ;; object attributes 145 ;; object attributes
150 "iter" "len" "license" "list" "locals" "long" "map" "max" 152 "iter" "len" "license" "list" "locals" "long" "map" "max"
151 "min" "object" "oct" "open" "ord" "pow" "property" "quit" 153 "min" "object" "oct" "open" "ord" "pow" "property" "quit"
152 "range" "raw_input" "reduce" "reload" "repr" "reversed" 154 "range" "raw_input" "reduce" "reload" "repr" "reversed"
153 "round" "set" "setattr" "slice" "sorted" "staticmethod" 155 "round" "set" "setattr" "slice" "sorted" "staticmethod"
154 "str" "sum" "super" "tuple" "type" "unichr" "unicode" "vars" 156 "str" "sum" "super" "tuple" "type" "unichr" "unicode" "vars"
155 "xrange" "zip")) symbol-end) 157 "xrange" "zip"
158 ;; Python 2.7.
159 "bin" "bytearray" "bytes" "format" "memoryview" "next" "print"
160 )) symbol-end)
156 (1 font-lock-builtin-face)) 161 (1 font-lock-builtin-face))
157 (,(rx symbol-start (or 162 (,(rx symbol-start (or
158 ;; other built-ins 163 ;; other built-ins
159 "True" "False" "None" "Ellipsis" 164 "True" "False" "None" "Ellipsis"
160 "_" "__debug__" "__doc__" "__import__" "__name__") symbol-end) 165 "_" "__debug__" "__doc__" "__import__" "__name__" "__package__")
166 symbol-end)
161 . font-lock-builtin-face))) 167 . font-lock-builtin-face)))
162 168
163 (defconst python-font-lock-syntactic-keywords 169 (defconst python-font-lock-syntactic-keywords
164 ;; Make outer chars of matching triple-quote sequences into generic 170 ;; Make outer chars of matching triple-quote sequences into generic
165 ;; string delimiters. Fixme: Is there a better way? 171 ;; string delimiters. Fixme: Is there a better way?