From 52cd0dbdc2ee01e9f0825790e8007ae3d163eab3 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sat, 17 Feb 2024 14:38:31 +0000 Subject: [PATCH] el/dot-emacs.el: Highlight Python builtins. Also special method names. --- el/dot-emacs.el | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 3 deletions(-) diff --git a/el/dot-emacs.el b/el/dot-emacs.el index 7fe8757..7c58433 100644 --- a/el/dot-emacs.el +++ b/el/dot-emacs.el @@ -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]+\\)\\|" @@ -3485,7 +3489,89 @@ strip numbers instead." "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 @@ -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" - "yield"))) + "yield") + "")) (define-derived-mode pyrex-mode python-mode "Pyrex" "Major mode for editing Pyrex source code") -- 2.11.0