[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/dart-mode 735868e 154/192: Copy/paste multiline string syn
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/dart-mode 735868e 154/192: Copy/paste multiline string syntax-propertize from python.el |
Date: |
Sun, 29 Aug 2021 11:02:08 -0400 (EDT) |
branch: elpa/dart-mode
commit 735868e0f72eebfd03fd72578f8cf7b53dc87b7f
Author: Brady Trainor <mail@bradyt.com>
Commit: Brady Trainor <mail@bradyt.com>
Copy/paste multiline string syntax-propertize from python.el
This provides correct fontification of for example,
String advice = ''' Don't do that ''';
The code is copied from python.el, as of commit:
<https://github.com/emacs-mirror/emacs/commit/05345babc988060cca540770599282102c34f2a7>
---
dart-mode.el | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
diff --git a/dart-mode.el b/dart-mode.el
index 9d4bac8..c40ea01 100644
--- a/dart-mode.el
+++ b/dart-mode.el
@@ -517,6 +517,66 @@ Returns nil if `dart-sdk-path' is nil."
nil
(0 font-lock-variable-name-face))))))
+(setq dart-string-delimiter (rx (and
+ ;; Match even number of backslashes.
+ (or (not (any ?\\ ?\' ?\")) point
+ ;; Quotes might be preceded by an escaped
quote.
+ (and (or (not (any ?\\)) point) ?\\
+ (* ?\\ ?\\) (any ?\' ?\")))
+ (* ?\\ ?\\)
+ ;; Match single or triple quotes of any kind.
+ (group (or "\"" "\"\"\"" "'" "'''")))))
+
+(defconst dart-syntax-propertize-function
+ (syntax-propertize-rules
+ (dart-string-delimiter
+ (0 (ignore (dart-syntax-stringify))))))
+
+(defsubst dart-syntax-count-quotes (quote-char &optional point limit)
+ "Count number of quotes around point (max is 3).
+QUOTE-CHAR is the quote char to count. Optional argument POINT is
+the point where scan starts (defaults to current point), and LIMIT
+is used to limit the scan."
+ (let ((i 0))
+ (while (and (< i 3)
+ (or (not limit) (< (+ point i) limit))
+ (eq (char-after (+ point i)) quote-char))
+ (setq i (1+ i)))
+ i))
+
+(defun dart-syntax-stringify ()
+ "Put `syntax-table' property correctly on single/triple quotes."
+ (let* ((num-quotes (length (match-string-no-properties 1)))
+ (ppss (prog2
+ (backward-char num-quotes)
+ (syntax-ppss)
+ (forward-char num-quotes)))
+ (string-start (and (not (nth 4 ppss)) (nth 8 ppss)))
+ (quote-starting-pos (- (point) num-quotes))
+ (quote-ending-pos (point))
+ (num-closing-quotes
+ (and string-start
+ (dart-syntax-count-quotes
+ (char-before) string-start quote-starting-pos))))
+ (cond ((and string-start (= num-closing-quotes 0))
+ ;; This set of quotes doesn't match the string starting
+ ;; kind. Do nothing.
+ nil)
+ ((not string-start)
+ ;; This set of quotes delimit the start of a string.
+ (put-text-property quote-starting-pos (1+ quote-starting-pos)
+ 'syntax-table (string-to-syntax "|")))
+ ((= num-quotes num-closing-quotes)
+ ;; This set of quotes delimit the end of a string.
+ (put-text-property (1- quote-ending-pos) quote-ending-pos
+ 'syntax-table (string-to-syntax "|")))
+ ((> num-quotes num-closing-quotes)
+ ;; This may only happen whenever a triple quote is closing
+ ;; a single quoted string. Add string delimiter syntax to
+ ;; all three quotes.
+ (put-text-property quote-starting-pos quote-ending-pos
+ 'syntax-table (string-to-syntax "|"))))))
+
(defun dart-fontify-region (beg end)
"Use fontify the region between BEG and END as Dart.
@@ -1718,6 +1778,7 @@ Key bindings:
(setq indent-line-function 'dart-indent-line-function)
(setq indent-tabs-mode nil)
(setq tab-width 2)
+ (setq-local syntax-propertize-function dart-syntax-propertize-function)
(when dart-enable-analysis-server
(if (null dart-sdk-path)
(dart-log
- [nongnu] elpa/dart-mode 7c28c58 131/192: Add Travis-CI and Cask, (continued)
- [nongnu] elpa/dart-mode 7c28c58 131/192: Add Travis-CI and Cask, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode adef2a5 118/192: Be more resilient to server crashes, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 61f334c 149/192: Improves indentation, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 47dc5a0 146/192: Fixes flycheck in Windows, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 6e1c42f 156/192: Fontify string interpolation, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode d78c5c7 142/192: Bump version to 1.0.4, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 1031016 141/192: Edit README to melpa rather than marmalade, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode d3d3d7e 188/192: Add indentation tests, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode e94acb5 168/192: Fontify SCREAMING_CAPS words of length greater than two as constant, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode c51e750 163/192: Stop testing 24.3 on travis, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 735868e 154/192: Copy/paste multiline string syntax-propertize from python.el,
ELPA Syncer <=
- [nongnu] elpa/dart-mode 9ad52e8 158/192: Search for sdk from flutter if no dart on path, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode c568118 175/192: Move dart server code to a separate repo, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode ae8a28b 161/192: Follow conventions in font-lock levels, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 327b9aa 167/192: Use conventions in commentary, docstrings, defvar vs setq, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 31861e8 173/192: Add mixin keyword, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 28ebbaf 176/192: Update tests, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode ea60ffd 178/192: Move README back to markdown, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode bbeadaa 181/192: Reorganize some keyword fontification, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode d6afa8c 153/192: Fontify identifiers following declared identifiers, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 9b65aae 187/192: Add failing tests for fontification of factories and generic methods, ELPA Syncer, 2021/08/29