diff options
| author | Tom Willemse | 2014-12-07 11:24:35 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2014-12-07 11:24:35 -0500 |
| commit | 9dfa949c0d24b8b74104e5cd1ac2fc0bdaa37341 (patch) | |
| tree | 6919ef1099c33e89985fc2399b36bbbb055cbab6 /lisp/progmodes/python.el | |
| parent | f3a685812a408968a24dd8ca97fdfae8ef266037 (diff) | |
| download | emacs-9dfa949c0d24b8b74104e5cd1ac2fc0bdaa37341.tar.gz emacs-9dfa949c0d24b8b74104e5cd1ac2fc0bdaa37341.zip | |
* lisp/progmodes/python.el: Recognize docstrings.
(python-docstring-at-p, python-font-lock-syntactic-face-function):
New functions.
(python-mode): Use them.
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 9f9db6c6046..33c822a37d5 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -459,6 +459,23 @@ The type returned can be `comment', `string' or `paren'." | |||
| 459 | 'python-info-ppss-comment-or-string-p | 459 | 'python-info-ppss-comment-or-string-p |
| 460 | #'python-syntax-comment-or-string-p "24.3") | 460 | #'python-syntax-comment-or-string-p "24.3") |
| 461 | 461 | ||
| 462 | (defun python-docstring-at-p (pos) | ||
| 463 | "Check to see if there is a docstring at POS." | ||
| 464 | (save-excursion | ||
| 465 | (goto-char pos) | ||
| 466 | (if (looking-at-p "'''\\|\"\"\"") | ||
| 467 | (progn | ||
| 468 | (python-nav-backward-statement) | ||
| 469 | (looking-at "\\`\\|class \\|def ")) | ||
| 470 | nil))) | ||
| 471 | |||
| 472 | (defun python-font-lock-syntactic-face-function (state) | ||
| 473 | (if (nth 3 state) | ||
| 474 | (if (python-docstring-at-p (nth 8 state)) | ||
| 475 | font-lock-doc-face | ||
| 476 | font-lock-string-face) | ||
| 477 | font-lock-comment-face)) | ||
| 478 | |||
| 462 | (defvar python-font-lock-keywords | 479 | (defvar python-font-lock-keywords |
| 463 | ;; Keywords | 480 | ;; Keywords |
| 464 | `(,(rx symbol-start | 481 | `(,(rx symbol-start |
| @@ -4312,7 +4329,10 @@ Arguments START and END narrow the buffer region to work on." | |||
| 4312 | 'python-nav-forward-sexp) | 4329 | 'python-nav-forward-sexp) |
| 4313 | 4330 | ||
| 4314 | (set (make-local-variable 'font-lock-defaults) | 4331 | (set (make-local-variable 'font-lock-defaults) |
| 4315 | '(python-font-lock-keywords nil nil nil nil)) | 4332 | '(python-font-lock-keywords |
| 4333 | nil nil nil nil | ||
| 4334 | (font-lock-syntactic-face-function | ||
| 4335 | . python-font-lock-syntactic-face-function))) | ||
| 4316 | 4336 | ||
| 4317 | (set (make-local-variable 'syntax-propertize-function) | 4337 | (set (make-local-variable 'syntax-propertize-function) |
| 4318 | python-syntax-propertize-function) | 4338 | python-syntax-propertize-function) |