aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el95
1 files changed, 63 insertions, 32 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index e39ff08739b..c55b69e33ec 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -526,9 +526,19 @@ The type returned can be `comment', `string' or `paren'."
526 font-lock-string-face) 526 font-lock-string-face)
527 font-lock-comment-face)) 527 font-lock-comment-face))
528 528
529(defvar python-font-lock-keywords 529(defvar python-font-lock-keywords-level-1
530 ;; Keywords 530 `((,(rx symbol-start "def" (1+ space) (group (1+ (or word ?_))))
531 `(,(rx symbol-start 531 (1 font-lock-function-name-face))
532 (,(rx symbol-start "class" (1+ space) (group (1+ (or word ?_))))
533 (1 font-lock-type-face)))
534 "Font lock keywords to use in python-mode for level 1 decoration.
535
536This is the minimum decoration level, including function and
537class declarations.")
538
539(defvar python-font-lock-keywords-level-2
540 `(,@python-font-lock-keywords-level-1
541 ,(rx symbol-start
532 (or 542 (or
533 "and" "del" "from" "not" "while" "as" "elif" "global" "or" "with" 543 "and" "del" "from" "not" "while" "as" "elif" "global" "or" "with"
534 "assert" "else" "if" "pass" "yield" "break" "except" "import" "class" 544 "assert" "else" "if" "pass" "yield" "break" "except" "import" "class"
@@ -548,12 +558,35 @@ The type returned can be `comment', `string' or `paren'."
548 ;; Extra: 558 ;; Extra:
549 "self") 559 "self")
550 symbol-end) 560 symbol-end)
551 ;; functions 561 ;; Builtins
552 (,(rx symbol-start "def" (1+ space) (group (1+ (or word ?_)))) 562 (,(rx symbol-start
553 (1 font-lock-function-name-face)) 563 (or
554 ;; classes 564 "abs" "all" "any" "bin" "bool" "callable" "chr" "classmethod"
555 (,(rx symbol-start "class" (1+ space) (group (1+ (or word ?_)))) 565 "compile" "complex" "delattr" "dict" "dir" "divmod" "enumerate"
556 (1 font-lock-type-face)) 566 "eval" "filter" "float" "format" "frozenset" "getattr" "globals"
567 "hasattr" "hash" "help" "hex" "id" "input" "int" "isinstance"
568 "issubclass" "iter" "len" "list" "locals" "map" "max" "memoryview"
569 "min" "next" "object" "oct" "open" "ord" "pow" "print" "property"
570 "range" "repr" "reversed" "round" "set" "setattr" "slice" "sorted"
571 "staticmethod" "str" "sum" "super" "tuple" "type" "vars" "zip"
572 "__import__"
573 ;; Python 2:
574 "basestring" "cmp" "execfile" "file" "long" "raw_input" "reduce"
575 "reload" "unichr" "unicode" "xrange" "apply" "buffer" "coerce"
576 "intern"
577 ;; Python 3:
578 "ascii" "bytearray" "bytes" "exec"
579 ;; Extra:
580 "__all__" "__doc__" "__name__" "__package__")
581 symbol-end) . font-lock-builtin-face))
582 "Font lock keywords to use in python-mode for level 2 decoration.
583
584This is the medium decoration level, including everything in
585`python-font-lock-keywords-level-1', as well as keywords and
586builtins.")
587
588(defvar python-font-lock-keywords-maximum-decoration
589 `(,@python-font-lock-keywords-level-2
557 ;; Constants 590 ;; Constants
558 (,(rx symbol-start 591 (,(rx symbol-start
559 (or 592 (or
@@ -596,27 +629,6 @@ The type returned can be `comment', `string' or `paren'."
596 "VMSError" "WindowsError" 629 "VMSError" "WindowsError"
597 ) 630 )
598 symbol-end) . font-lock-type-face) 631 symbol-end) . font-lock-type-face)
599 ;; Builtins
600 (,(rx symbol-start
601 (or
602 "abs" "all" "any" "bin" "bool" "callable" "chr" "classmethod"
603 "compile" "complex" "delattr" "dict" "dir" "divmod" "enumerate"
604 "eval" "filter" "float" "format" "frozenset" "getattr" "globals"
605 "hasattr" "hash" "help" "hex" "id" "input" "int" "isinstance"
606 "issubclass" "iter" "len" "list" "locals" "map" "max" "memoryview"
607 "min" "next" "object" "oct" "open" "ord" "pow" "print" "property"
608 "range" "repr" "reversed" "round" "set" "setattr" "slice" "sorted"
609 "staticmethod" "str" "sum" "super" "tuple" "type" "vars" "zip"
610 "__import__"
611 ;; Python 2:
612 "basestring" "cmp" "execfile" "file" "long" "raw_input" "reduce"
613 "reload" "unichr" "unicode" "xrange" "apply" "buffer" "coerce"
614 "intern"
615 ;; Python 3:
616 "ascii" "bytearray" "bytes" "exec"
617 ;; Extra:
618 "__all__" "__doc__" "__name__" "__package__")
619 symbol-end) . font-lock-builtin-face)
620 ;; assignments 632 ;; assignments
621 ;; support for a = b = c = 5 633 ;; support for a = b = c = 5
622 (,(lambda (limit) 634 (,(lambda (limit)
@@ -640,7 +652,26 @@ The type returned can be `comment', `string' or `paren'."
640 (goto-char (match-end 1)) 652 (goto-char (match-end 1))
641 (python-syntax-context 'paren))) 653 (python-syntax-context 'paren)))
642 res)) 654 res))
643 (1 font-lock-variable-name-face nil nil)))) 655 (1 font-lock-variable-name-face nil nil)))
656 "Font lock keywords to use in python-mode for maximum decoration.
657
658This decoration level includes everything in
659`python-font-lock-keywords-level-2', as well as constants,
660decorators, exceptions, and assignments.")
661
662(defvar python-font-lock-keywords
663 '(python-font-lock-keywords-level-1 ; When `font-lock-maximum-decoration' is nil.
664 python-font-lock-keywords-level-1 ; When `font-lock-maximum-decoration' is 1.
665 python-font-lock-keywords-level-2 ; When `font-lock-maximum-decoration' is 2.
666 python-font-lock-keywords-maximum-decoration ; When `font-lock-maximum-decoration'
667 ; is more than 1, or t (which it is,
668 ; by default).
669 )
670 "List of font lock keyword specifications to use in python-mode.
671
672Which one will be chosen depends on the value of
673`font-lock-maximum-decoration'.")
674
644 675
645(defconst python-syntax-propertize-function 676(defconst python-syntax-propertize-function
646 (syntax-propertize-rules 677 (syntax-propertize-rules
@@ -5325,7 +5356,7 @@ REPORT-FN is Flymake's callback function."
5325 'python-nav-forward-sexp) 5356 'python-nav-forward-sexp)
5326 5357
5327 (set (make-local-variable 'font-lock-defaults) 5358 (set (make-local-variable 'font-lock-defaults)
5328 '(python-font-lock-keywords 5359 `(,python-font-lock-keywords
5329 nil nil nil nil 5360 nil nil nil nil
5330 (font-lock-syntactic-face-function 5361 (font-lock-syntactic-face-function
5331 . python-font-lock-syntactic-face-function))) 5362 . python-font-lock-syntactic-face-function)))