diff options
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 835d633f292..1e063d2f728 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -103,7 +103,9 @@ | |||
| 103 | (defconst python-font-lock-syntactic-keywords | 103 | (defconst python-font-lock-syntactic-keywords |
| 104 | ;; Make outer chars of matching triple-quote sequences into generic | 104 | ;; Make outer chars of matching triple-quote sequences into generic |
| 105 | ;; string delimiters. Fixme: Is there a better way? | 105 | ;; string delimiters. Fixme: Is there a better way? |
| 106 | `((,(rx (and (group (optional (any "uUrR"))) ; prefix gets syntax property | 106 | `((,(rx (and (or buffer-start (not (syntax escape))) ; avoid escaped |
| 107 | ; leading quote | ||
| 108 | (group (optional (any "uUrR"))) ; prefix gets syntax property | ||
| 107 | (optional (any "rR")) ; possible second prefix | 109 | (optional (any "rR")) ; possible second prefix |
| 108 | (group (syntax string-quote)) ; maybe gets property | 110 | (group (syntax string-quote)) ; maybe gets property |
| 109 | (backref 2) ; per first quote | 111 | (backref 2) ; per first quote |
| @@ -130,32 +132,31 @@ Used for syntactic keywords. N is the match number (1, 2 or 3)." | |||
| 130 | ;; ur"""ar""" x='"' # """ | 132 | ;; ur"""ar""" x='"' # """ |
| 131 | ;; x = ''' """ ' a | 133 | ;; x = ''' """ ' a |
| 132 | ;; ''' | 134 | ;; ''' |
| 133 | ;; x '"""' x | 135 | ;; x '"""' x """ \"""" x |
| 134 | (save-excursion | 136 | (save-excursion |
| 135 | (goto-char (match-beginning 0)) | 137 | (goto-char (match-beginning 0)) |
| 136 | (unless (eq ?\\ (char-before)) | 138 | (cond |
| 137 | (cond | 139 | ;; Consider property for the last char if in a fenced string. |
| 138 | ;; Consider property for the last char if in a fenced string. | 140 | ((= n 3) |
| 139 | ((= n 3) | 141 | (let ((syntax (syntax-ppss))) |
| 140 | (let ((syntax (syntax-ppss))) | 142 | (when (eq t (nth 3 syntax)) ; after unclosed fence |
| 141 | (when (eq t (nth 3 syntax)) ; after unclosed fence | 143 | (goto-char (nth 8 syntax)) ; fence position |
| 142 | (goto-char (nth 8 syntax)) ; fence position | 144 | ;; Skip any prefix. |
| 143 | ;; Skip any prefix. | 145 | (if (memq (char-after) '(?u ?U ?R ?r)) |
| 144 | (if (memq (char-after) '(?u ?U ?R ?r)) | 146 | (skip-chars-forward "uUrR")) |
| 145 | (skip-chars-forward "uUrR")) | 147 | ;; Is it a matching sequence? |
| 146 | ;; Is it a matching sequence? | 148 | (if (eq (char-after) (char-after (match-beginning 2))) |
| 147 | (if (eq (char-after) (char-after (match-beginning 2))) | 149 | (eval-when-compile (string-to-syntax "|")))))) |
| 148 | (eval-when-compile (string-to-syntax "|")))))) | 150 | ;; Consider property for initial char, accounting for prefixes. |
| 149 | ;; Consider property for initial char, accounting for prefixes. | 151 | ((or (and (= n 2) ; not prefix |
| 150 | ((or (and (= n 2) ; not prefix | 152 | (= (match-beginning 1) (match-end 1))) ; prefix is null |
| 151 | (= (match-beginning 1) (match-end 1))) ; prefix is null | 153 | (and (= n 1) ; prefix |
| 152 | (and (= n 1) ; prefix | 154 | (/= (match-beginning 1) (match-end 1)))) ; non-empty |
| 153 | (/= (match-beginning 1) (match-end 1)))) ; non-empty | 155 | (unless (eq 'string (syntax-ppss-context (syntax-ppss))) |
| 154 | (unless (eq 'string (syntax-ppss-context (syntax-ppss))) | 156 | (eval-when-compile (string-to-syntax "|")))) |
| 155 | (eval-when-compile (string-to-syntax "|"))))) | 157 | ;; Otherwise (we're in a non-matching string) the property is |
| 156 | ;; Otherwise (we're in a non-matching string) the property is | 158 | ;; nil, which is OK. |
| 157 | ;; nil, which is OK. | 159 | ))) |
| 158 | ))) | ||
| 159 | 160 | ||
| 160 | ;; This isn't currently in `font-lock-defaults' as probably not worth | 161 | ;; This isn't currently in `font-lock-defaults' as probably not worth |
| 161 | ;; it -- we basically only mess with a few normally-symbol characters. | 162 | ;; it -- we basically only mess with a few normally-symbol characters. |