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.el96
1 files changed, 48 insertions, 48 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 2f65ffa1e17..10e852223ce 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -166,29 +166,32 @@
166 symbol-end) 166 symbol-end)
167 . font-lock-builtin-face))) 167 . font-lock-builtin-face)))
168 168
169(defconst python-font-lock-syntactic-keywords 169(defconst python-syntax-propertize-function
170 ;; Make outer chars of matching triple-quote sequences into generic 170 ;; Make outer chars of matching triple-quote sequences into generic
171 ;; string delimiters. Fixme: Is there a better way? 171 ;; string delimiters. Fixme: Is there a better way?
172 ;; First avoid a sequence preceded by an odd number of backslashes. 172 ;; First avoid a sequence preceded by an odd number of backslashes.
173 `((,(rx (not (any ?\\)) 173 (syntax-propertize-rules
174 ?\\ (* (and ?\\ ?\\)) 174 (;; (rx (not (any ?\\))
175 (group (syntax string-quote)) 175 ;; ?\\ (* (and ?\\ ?\\))
176 (backref 1) 176 ;; (group (syntax string-quote))
177 (group (backref 1))) 177 ;; (backref 1)
178 (2 ,(string-to-syntax "\""))) ; dummy 178 ;; (group (backref 1)))
179 (,(rx (group (optional (any "uUrR"))) ; prefix gets syntax property 179 ;; ĦBackrefs don't work in syntax-propertize-rules!
180 (optional (any "rR")) ; possible second prefix 180 "[^\\]\\\\\\(\\\\\\\\\\)*\\(?:''\\('\\)\\|\"\"\\(?2:\"\\)\\)"
181 (group (syntax string-quote)) ; maybe gets property 181 (2 "\"")) ; dummy
182 (backref 2) ; per first quote 182 (;; (rx (optional (group (any "uUrR"))) ; prefix gets syntax property
183 (group (backref 2))) ; maybe gets property 183 ;; (optional (any "rR")) ; possible second prefix
184 (1 (python-quote-syntax 1)) 184 ;; (group (syntax string-quote)) ; maybe gets property
185 (2 (python-quote-syntax 2)) 185 ;; (backref 2) ; per first quote
186 (3 (python-quote-syntax 3))) 186 ;; (group (backref 2))) ; maybe gets property
187 ;; This doesn't really help. 187 ;; ĦBackrefs don't work in syntax-propertize-rules!
188;;; (,(rx (and ?\\ (group ?\n))) (1 " ")) 188 "\\([RUru]\\)?[Rr]?\\(?:\\('\\)'\\('\\)\\|\\(?2:\"\\)\"\\(?3:\"\\)\\)"
189 )) 189 (3 (ignore (python-quote-syntax))))
190 190 ;; This doesn't really help.
191(defun python-quote-syntax (n) 191 ;;((rx (and ?\\ (group ?\n))) (1 " "))
192 ))
193
194(defun python-quote-syntax ()
192 "Put `syntax-table' property correctly on triple quote. 195 "Put `syntax-table' property correctly on triple quote.
193Used for syntactic keywords. N is the match number (1, 2 or 3)." 196Used for syntactic keywords. N is the match number (1, 2 or 3)."
194 ;; Given a triple quote, we have to check the context to know 197 ;; Given a triple quote, we have to check the context to know
@@ -206,28 +209,25 @@ Used for syntactic keywords. N is the match number (1, 2 or 3)."
206 ;; x '"""' x """ \"""" x 209 ;; x '"""' x """ \"""" x
207 (save-excursion 210 (save-excursion
208 (goto-char (match-beginning 0)) 211 (goto-char (match-beginning 0))
209 (cond 212 (let ((syntax (save-match-data (syntax-ppss))))
210 ;; Consider property for the last char if in a fenced string. 213 (cond
211 ((= n 3) 214 ((eq t (nth 3 syntax)) ; after unclosed fence
212 (let* ((font-lock-syntactic-keywords nil) 215 ;; Consider property for the last char if in a fenced string.
213 (syntax (syntax-ppss))) 216 (goto-char (nth 8 syntax)) ; fence position
214 (when (eq t (nth 3 syntax)) ; after unclosed fence 217 (skip-chars-forward "uUrR") ; skip any prefix
215 (goto-char (nth 8 syntax)) ; fence position 218 ;; Is it a matching sequence?
216 (skip-chars-forward "uUrR") ; skip any prefix 219 (if (eq (char-after) (char-after (match-beginning 2)))
217 ;; Is it a matching sequence? 220 (put-text-property (match-beginning 3) (match-end 3)
218 (if (eq (char-after) (char-after (match-beginning 2))) 221 'syntax-table (string-to-syntax "|"))))
219 (eval-when-compile (string-to-syntax "|")))))) 222 ((match-end 1)
220 ;; Consider property for initial char, accounting for prefixes. 223 ;; Consider property for initial char, accounting for prefixes.
221 ((or (and (= n 2) ; leading quote (not prefix) 224 (put-text-property (match-beginning 1) (match-end 1)
222 (= (match-beginning 1) (match-end 1))) ; prefix is null 225 'syntax-table (string-to-syntax "|")))
223 (and (= n 1) ; prefix 226 (t
224 (/= (match-beginning 1) (match-end 1)))) ; non-empty 227 ;; Consider property for initial char, accounting for prefixes.
225 (let ((font-lock-syntactic-keywords nil)) 228 (put-text-property (match-beginning 2) (match-end 2)
226 (unless (eq 'string (syntax-ppss-context (syntax-ppss))) 229 'syntax-table (string-to-syntax "|"))))
227 (eval-when-compile (string-to-syntax "|"))))) 230 )))
228 ;; Otherwise (we're in a non-matching string) the property is
229 ;; nil, which is OK.
230 )))
231 231
232;; This isn't currently in `font-lock-defaults' as probably not worth 232;; This isn't currently in `font-lock-defaults' as probably not worth
233;; it -- we basically only mess with a few normally-symbol characters. 233;; it -- we basically only mess with a few normally-symbol characters.
@@ -2495,12 +2495,12 @@ with skeleton expansions for compound statement templates.
2495 :group 'python 2495 :group 'python
2496 (set (make-local-variable 'font-lock-defaults) 2496 (set (make-local-variable 'font-lock-defaults)
2497 '(python-font-lock-keywords nil nil nil nil 2497 '(python-font-lock-keywords nil nil nil nil
2498 (font-lock-syntactic-keywords 2498 ;; This probably isn't worth it.
2499 . python-font-lock-syntactic-keywords) 2499 ;; (font-lock-syntactic-face-function
2500 ;; This probably isn't worth it. 2500 ;; . python-font-lock-syntactic-face-function)
2501 ;; (font-lock-syntactic-face-function 2501 ))
2502 ;; . python-font-lock-syntactic-face-function) 2502 (set (make-local-variable 'syntax-propertize-function)
2503 )) 2503 python-syntax-propertize-function)
2504 (set (make-local-variable 'parse-sexp-lookup-properties) t) 2504 (set (make-local-variable 'parse-sexp-lookup-properties) t)
2505 (set (make-local-variable 'parse-sexp-ignore-comments) t) 2505 (set (make-local-variable 'parse-sexp-ignore-comments) t)
2506 (set (make-local-variable 'comment-start) "# ") 2506 (set (make-local-variable 'comment-start) "# ")