mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-04-27 08:43:40 -07:00
* lisp/progmodes/python.el: Recognize docstrings.
(python-docstring-at-p, python-font-lock-syntactic-face-function): New functions. (python-mode): Use them.
This commit is contained in:
parent
f3a685812a
commit
9dfa949c0d
2 changed files with 31 additions and 5 deletions
|
|
@ -459,6 +459,23 @@ The type returned can be `comment', `string' or `paren'."
|
|||
'python-info-ppss-comment-or-string-p
|
||||
#'python-syntax-comment-or-string-p "24.3")
|
||||
|
||||
(defun python-docstring-at-p (pos)
|
||||
"Check to see if there is a docstring at POS."
|
||||
(save-excursion
|
||||
(goto-char pos)
|
||||
(if (looking-at-p "'''\\|\"\"\"")
|
||||
(progn
|
||||
(python-nav-backward-statement)
|
||||
(looking-at "\\`\\|class \\|def "))
|
||||
nil)))
|
||||
|
||||
(defun python-font-lock-syntactic-face-function (state)
|
||||
(if (nth 3 state)
|
||||
(if (python-docstring-at-p (nth 8 state))
|
||||
font-lock-doc-face
|
||||
font-lock-string-face)
|
||||
font-lock-comment-face))
|
||||
|
||||
(defvar python-font-lock-keywords
|
||||
;; Keywords
|
||||
`(,(rx symbol-start
|
||||
|
|
@ -4312,7 +4329,10 @@ Arguments START and END narrow the buffer region to work on."
|
|||
'python-nav-forward-sexp)
|
||||
|
||||
(set (make-local-variable 'font-lock-defaults)
|
||||
'(python-font-lock-keywords nil nil nil nil))
|
||||
'(python-font-lock-keywords
|
||||
nil nil nil nil
|
||||
(font-lock-syntactic-face-function
|
||||
. python-font-lock-syntactic-face-function)))
|
||||
|
||||
(set (make-local-variable 'syntax-propertize-function)
|
||||
python-syntax-propertize-function)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue