mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-23 22:20:24 -08:00
Add 'font-lock-maximum-decoration' levels for Python
* etc/NEWS: New entry under Python mode. * lisp/progmodes/python.el (python-font-lock-keywords-level-1) (python-font-lock-keywords-level-2) (python-font-lock-keywords-maximum-decoration): New variables based off the incumbent 'python-font-lock-keywords'. (python-font-lock-keywords): Change it to a list of the new symbols, for use in the 'car' of 'font-lock-defaults'. (python-mode): Set the 'car' of 'font-lock-defaults' to the value of 'python-font-lock-keywords', instead of the symbol 'python-font-lock-keywords'.
This commit is contained in:
parent
5934122c1f
commit
36b64e087e
2 changed files with 70 additions and 32 deletions
7
etc/NEWS
7
etc/NEWS
|
|
@ -384,6 +384,13 @@ bound to 'C-c C-f'.
|
||||||
when escaping text and in addition all numeric entities when
|
when escaping text and in addition all numeric entities when
|
||||||
unescaping text.
|
unescaping text.
|
||||||
|
|
||||||
|
** Python mode
|
||||||
|
|
||||||
|
---
|
||||||
|
*** Python mode supports three different font lock decoration levels.
|
||||||
|
The maximum level is used by default; customize
|
||||||
|
'font-lock-maximum-decoration' to tone down the decoration.
|
||||||
|
|
||||||
** Dired
|
** Dired
|
||||||
|
|
||||||
+++
|
+++
|
||||||
|
|
|
||||||
|
|
@ -526,9 +526,19 @@ The type returned can be `comment', `string' or `paren'."
|
||||||
font-lock-string-face)
|
font-lock-string-face)
|
||||||
font-lock-comment-face))
|
font-lock-comment-face))
|
||||||
|
|
||||||
(defvar python-font-lock-keywords
|
(defvar python-font-lock-keywords-level-1
|
||||||
;; Keywords
|
`((,(rx symbol-start "def" (1+ space) (group (1+ (or word ?_))))
|
||||||
`(,(rx symbol-start
|
(1 font-lock-function-name-face))
|
||||||
|
(,(rx symbol-start "class" (1+ space) (group (1+ (or word ?_))))
|
||||||
|
(1 font-lock-type-face)))
|
||||||
|
"Font lock keywords to use in python-mode for level 1 decoration.
|
||||||
|
|
||||||
|
This is the minimum decoration level, including function and
|
||||||
|
class declarations.")
|
||||||
|
|
||||||
|
(defvar python-font-lock-keywords-level-2
|
||||||
|
`(,@python-font-lock-keywords-level-1
|
||||||
|
,(rx symbol-start
|
||||||
(or
|
(or
|
||||||
"and" "del" "from" "not" "while" "as" "elif" "global" "or" "with"
|
"and" "del" "from" "not" "while" "as" "elif" "global" "or" "with"
|
||||||
"assert" "else" "if" "pass" "yield" "break" "except" "import" "class"
|
"assert" "else" "if" "pass" "yield" "break" "except" "import" "class"
|
||||||
|
|
@ -548,12 +558,35 @@ The type returned can be `comment', `string' or `paren'."
|
||||||
;; Extra:
|
;; Extra:
|
||||||
"self")
|
"self")
|
||||||
symbol-end)
|
symbol-end)
|
||||||
;; functions
|
;; Builtins
|
||||||
(,(rx symbol-start "def" (1+ space) (group (1+ (or word ?_))))
|
(,(rx symbol-start
|
||||||
(1 font-lock-function-name-face))
|
(or
|
||||||
;; classes
|
"abs" "all" "any" "bin" "bool" "callable" "chr" "classmethod"
|
||||||
(,(rx symbol-start "class" (1+ space) (group (1+ (or word ?_))))
|
"compile" "complex" "delattr" "dict" "dir" "divmod" "enumerate"
|
||||||
(1 font-lock-type-face))
|
"eval" "filter" "float" "format" "frozenset" "getattr" "globals"
|
||||||
|
"hasattr" "hash" "help" "hex" "id" "input" "int" "isinstance"
|
||||||
|
"issubclass" "iter" "len" "list" "locals" "map" "max" "memoryview"
|
||||||
|
"min" "next" "object" "oct" "open" "ord" "pow" "print" "property"
|
||||||
|
"range" "repr" "reversed" "round" "set" "setattr" "slice" "sorted"
|
||||||
|
"staticmethod" "str" "sum" "super" "tuple" "type" "vars" "zip"
|
||||||
|
"__import__"
|
||||||
|
;; Python 2:
|
||||||
|
"basestring" "cmp" "execfile" "file" "long" "raw_input" "reduce"
|
||||||
|
"reload" "unichr" "unicode" "xrange" "apply" "buffer" "coerce"
|
||||||
|
"intern"
|
||||||
|
;; Python 3:
|
||||||
|
"ascii" "bytearray" "bytes" "exec"
|
||||||
|
;; Extra:
|
||||||
|
"__all__" "__doc__" "__name__" "__package__")
|
||||||
|
symbol-end) . font-lock-builtin-face))
|
||||||
|
"Font lock keywords to use in python-mode for level 2 decoration.
|
||||||
|
|
||||||
|
This is the medium decoration level, including everything in
|
||||||
|
`python-font-lock-keywords-level-1', as well as keywords and
|
||||||
|
builtins.")
|
||||||
|
|
||||||
|
(defvar python-font-lock-keywords-maximum-decoration
|
||||||
|
`(,@python-font-lock-keywords-level-2
|
||||||
;; Constants
|
;; Constants
|
||||||
(,(rx symbol-start
|
(,(rx symbol-start
|
||||||
(or
|
(or
|
||||||
|
|
@ -596,27 +629,6 @@ The type returned can be `comment', `string' or `paren'."
|
||||||
"VMSError" "WindowsError"
|
"VMSError" "WindowsError"
|
||||||
)
|
)
|
||||||
symbol-end) . font-lock-type-face)
|
symbol-end) . font-lock-type-face)
|
||||||
;; Builtins
|
|
||||||
(,(rx symbol-start
|
|
||||||
(or
|
|
||||||
"abs" "all" "any" "bin" "bool" "callable" "chr" "classmethod"
|
|
||||||
"compile" "complex" "delattr" "dict" "dir" "divmod" "enumerate"
|
|
||||||
"eval" "filter" "float" "format" "frozenset" "getattr" "globals"
|
|
||||||
"hasattr" "hash" "help" "hex" "id" "input" "int" "isinstance"
|
|
||||||
"issubclass" "iter" "len" "list" "locals" "map" "max" "memoryview"
|
|
||||||
"min" "next" "object" "oct" "open" "ord" "pow" "print" "property"
|
|
||||||
"range" "repr" "reversed" "round" "set" "setattr" "slice" "sorted"
|
|
||||||
"staticmethod" "str" "sum" "super" "tuple" "type" "vars" "zip"
|
|
||||||
"__import__"
|
|
||||||
;; Python 2:
|
|
||||||
"basestring" "cmp" "execfile" "file" "long" "raw_input" "reduce"
|
|
||||||
"reload" "unichr" "unicode" "xrange" "apply" "buffer" "coerce"
|
|
||||||
"intern"
|
|
||||||
;; Python 3:
|
|
||||||
"ascii" "bytearray" "bytes" "exec"
|
|
||||||
;; Extra:
|
|
||||||
"__all__" "__doc__" "__name__" "__package__")
|
|
||||||
symbol-end) . font-lock-builtin-face)
|
|
||||||
;; assignments
|
;; assignments
|
||||||
;; support for a = b = c = 5
|
;; support for a = b = c = 5
|
||||||
(,(lambda (limit)
|
(,(lambda (limit)
|
||||||
|
|
@ -640,7 +652,26 @@ The type returned can be `comment', `string' or `paren'."
|
||||||
(goto-char (match-end 1))
|
(goto-char (match-end 1))
|
||||||
(python-syntax-context 'paren)))
|
(python-syntax-context 'paren)))
|
||||||
res))
|
res))
|
||||||
(1 font-lock-variable-name-face nil nil))))
|
(1 font-lock-variable-name-face nil nil)))
|
||||||
|
"Font lock keywords to use in python-mode for maximum decoration.
|
||||||
|
|
||||||
|
This decoration level includes everything in
|
||||||
|
`python-font-lock-keywords-level-2', as well as constants,
|
||||||
|
decorators, exceptions, and assignments.")
|
||||||
|
|
||||||
|
(defvar python-font-lock-keywords
|
||||||
|
'(python-font-lock-keywords-level-1 ; When `font-lock-maximum-decoration' is nil.
|
||||||
|
python-font-lock-keywords-level-1 ; When `font-lock-maximum-decoration' is 1.
|
||||||
|
python-font-lock-keywords-level-2 ; When `font-lock-maximum-decoration' is 2.
|
||||||
|
python-font-lock-keywords-maximum-decoration ; When `font-lock-maximum-decoration'
|
||||||
|
; is more than 1, or t (which it is,
|
||||||
|
; by default).
|
||||||
|
)
|
||||||
|
"List of font lock keyword specifications to use in python-mode.
|
||||||
|
|
||||||
|
Which one will be chosen depends on the value of
|
||||||
|
`font-lock-maximum-decoration'.")
|
||||||
|
|
||||||
|
|
||||||
(defconst python-syntax-propertize-function
|
(defconst python-syntax-propertize-function
|
||||||
(syntax-propertize-rules
|
(syntax-propertize-rules
|
||||||
|
|
@ -5325,7 +5356,7 @@ REPORT-FN is Flymake's callback function."
|
||||||
'python-nav-forward-sexp)
|
'python-nav-forward-sexp)
|
||||||
|
|
||||||
(set (make-local-variable 'font-lock-defaults)
|
(set (make-local-variable 'font-lock-defaults)
|
||||||
'(python-font-lock-keywords
|
`(,python-font-lock-keywords
|
||||||
nil nil nil nil
|
nil nil nil nil
|
||||||
(font-lock-syntactic-face-function
|
(font-lock-syntactic-face-function
|
||||||
. python-font-lock-syntactic-face-function)))
|
. python-font-lock-syntactic-face-function)))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue