exoni/packages/app-editors/emacs/files/emacs-python-docstrings.patch

41 lines
1.3 KiB
Diff
Raw Normal View History

2013-05-13 17:34:23 +02:00
diff --git a/python.el b/python.el
index 54a657a..f01360c 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -405,6 +405,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-doc-string-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-doc-string-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
@@ -3226,7 +3243,10 @@ if that value is non-nil."
'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)