el/dot-emacs.el: Highlight Python builtins.
[profile] / el / dot-emacs.el
index ac57d78..7c58433 100644 (file)
@@ -62,7 +62,7 @@ This may be at the expense of cool features.")
   "Turn a LIST of strings into a single regular expression at compile-time."
   (declare (indent nil)
           (debug 0))
-  `',(make-regexp list))
+  `',(make-regexp (sort (copy-list list) #'string<)))
 
 (defun mdw-wrong ()
   "This is not the key sequence you're looking for."
@@ -3440,7 +3440,7 @@ strip numbers instead."
              python-indent-offset 2
              python-fill-docstring-style 'symmetric)
 
-(defun mdw-fontify-pythonic (keywords)
+(defun mdw-fontify-pythonic (keywords builtins)
 
   ;; Miscellaneous fiddling.
   (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
@@ -3455,6 +3455,10 @@ strip numbers instead."
           ;; Set up the keywords defined above.
           (list (concat "\\_<\\(" keywords "\\)\\_>")
                 '(0 font-lock-keyword-face))
+          (list (concat "\\(^\\|[^.]\\)\\_<\\(" builtins "\\)\\_>")
+                '(2 font-lock-variable-name-face))
+          (list (concat "\\_<\\(__\\(\\sw+\\|\\s_+\\)+__\\)\\_>")
+                '(0 font-lock-variable-name-face))
 
           ;; At least numbers are simpler than C.
           (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO]?[0-7]+\\|[bB][01]+\\)\\|"
@@ -3470,11 +3474,104 @@ strip numbers instead."
 
 (defun mdw-fontify-python ()
   (mdw-fontify-pythonic
-   (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
-               "del" "elif" "else" "except" "exec" "finally" "for"
-               "from" "global" "if" "import" "in" "is" "lambda"
-               "not" "or" "pass" "print" "raise" "return" "try"
-               "while" "with" "yield")))
+   (mdw-regexps "and" "as" "assert"
+               "break"
+               "class" "continue"
+               "def" "del"
+               "elif" "else" "except" "exec"
+               "finally" "for" "from"
+               "global"
+               "if" "import" "in" "is"
+               "lambda"
+               "not"
+               "or"
+               "pass" "print"
+               "raise" "return"
+               "try"
+               "while" "with"
+               "yield")
+
+   (mdw-regexps "Ellipsis"
+               "False"
+               "None" "NotImplemented"
+               "True"
+               "__debug__"
+
+               "BaseException"
+                 "Exception"
+                   "StandardError"
+                     "ArithmeticError"
+                       "FloatingPointError"
+                       "OverflowError"
+                       "ZeroDivisionError"
+                     "AssertionError"
+                     "AttributeError"
+                     "BufferError"
+                     "EnvironmentError"
+                       "IOError"
+                       "OSError"
+                     "EOFError"
+                     "ImportError"
+                     "LookupError"
+                       "IndexError"
+                       "KeyError"
+                     "MemoryError"
+                     "NameError"
+                       "UnboundLocalError"
+                     "ReferenceError"
+                     "RuntimeError"
+                       "NotImplementedError"
+                     "SyntaxError"
+                       "IndentationError"
+                         "TabError"
+                     "SystemError"
+                     "TypeError"
+                     "ValueError"
+                       "UnicodeError"
+                         "UnicodeDecodeError"
+                         "UnicodeEncodeError"
+                         "UnicodeTranslateError"
+                   "StopIteration"
+                   "Warning"
+                     "BytesWarning"
+                     "DeprecationWarning"
+                     "FutureWarning"
+                     "ImportWarning"
+                     "PendingDeprecationWarning"
+                     "RuntimeWarning"
+                     "SyntaxWarning"
+                     "UnicodeWarning"
+                     "UserWarning"
+                 "GeneratorExit"
+                 "KeyboardInterrupt"
+                 "SystemExit"
+
+               "abs" "absolute_import" "all" "any" "apply"
+               "basestring" "bin" "bool" "buffer" "bytearray"
+               "callable" "coerce" "chr" "classmethod"
+                 "cmp" "compile" "complex"
+               "delattr" "dict" "dir" "divmod"
+               "enumerate" "eval" "execfile"
+               "file" "filter" "float" "format" "frozenset"
+               "getattr" "globals"
+               "hasattr" "hash" "help" "hex"
+               "id" "input" "int" "intern"
+                 "isinstance" "issubclass" "iter"
+               "len" "list" "locals" "long"
+               "map" "max" "memoryview" "min"
+               "next"
+               "object" "oct" "open" "ord"
+               "pow" "print" "property"
+               "range" "raw_input" "reduce" "reload"
+                 "repr" "reversed" "round"
+               "set" "setattr" "slice" "sorted"
+                 "staticmethod" "str" "sum" "super"
+               "tuple" "type"
+               "unichr" "unicode"
+               "vars"
+               "xrange"
+               "zip"
+               "__import__")))
 
 (defun mdw-fontify-pyrex ()
   (mdw-fontify-pythonic
@@ -3483,7 +3580,8 @@ strip numbers instead."
                "extern" "finally" "for" "from" "global" "if"
                "import" "in" "is" "lambda" "not" "or" "pass" "print"
                "property" "raise" "return" "struct" "try" "while" "with"
-               "yield")))
+               "yield")
+   ""))
 
 (define-derived-mode pyrex-mode python-mode "Pyrex"
   "Major mode for editing Pyrex source code")