el/dot-emacs.el: Highlight Python builtins.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 17 Feb 2024 14:38:31 +0000 (14:38 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 17 Feb 2024 14:55:46 +0000 (14:55 +0000)
Also special method names.

el/dot-emacs.el

index 7fe8757..7c58433 100644 (file)
@@ -3440,7 +3440,7 @@ strip numbers instead."
              python-indent-offset 2
              python-fill-docstring-style 'symmetric)
 
              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]*\\)")
 
   ;; 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))
           ;; 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]+\\)\\|"
 
           ;; At least numbers are simpler than C.
           (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO]?[0-7]+\\|[bB][01]+\\)\\|"
@@ -3485,7 +3489,89 @@ strip numbers instead."
                "raise" "return"
                "try"
                "while" "with"
                "raise" "return"
                "try"
                "while" "with"
-               "yield")))
+               "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
 
 (defun mdw-fontify-pyrex ()
   (mdw-fontify-pythonic
@@ -3494,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"
                "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")
 
 (define-derived-mode pyrex-mode python-mode "Pyrex"
   "Major mode for editing Pyrex source code")