[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/dart-mode e41f41e 174/192: Fontify untyped parameters in a
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/dart-mode e41f41e 174/192: Fontify untyped parameters in anonymous functions |
Date: |
Sun, 29 Aug 2021 11:02:12 -0400 (EDT) |
branch: elpa/dart-mode
commit e41f41e09cfeb35f3733f07c06ee8037825fb5ab
Author: Brady Trainor <mail@bradyt.com>
Commit: Brady Trainor <mail@bradyt.net>
Fontify untyped parameters in anonymous functions
---
dart-mode.el | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
diff --git a/dart-mode.el b/dart-mode.el
index 596d2d2..ade34ad 100644
--- a/dart-mode.el
+++ b/dart-mode.el
@@ -671,6 +671,73 @@ fontify as declared variables. From ECMA-408,
;; Otherwise, return nil.
(t (throw 'result nil)))))))
+(defun dart--anonymous-function-matcher (limit)
+ "Font-lock matcher for start of anonymous functions.
+
+Looks for opening parenthesis, tries to jump to opening
+parenthesis, ensure it is not preceded by for, while, etc. Then
+tries to jump to closing parenthesis and check if followed by \"
+{\" or \" =>\".
+
+Used with `dart--untyped-parameter-anchored-matcher' to fontify
+untyped parameters. For example, in
+
+ (untypedParameter) => untypedParameter.length"
+ (catch 'result
+ (let (beg end)
+ (while (search-forward "(" limit t)
+ (setq beg (match-beginning 0))
+ (setq end (match-end 0))
+ (unless (looking-back (rx (or (and (or "do" "for" "if" "switch"
"while")
+ space)
+ "super")
+ ?\())
+ (condition-case nil
+ (up-list)
+ (scan-error (throw 'result nil)))
+ (when (looking-at (rx space (or ?\{ "=>")))
+ (set-match-data (list beg end))
+ (goto-char end)
+ (throw 'result t))
+ (goto-char end)))
+ (throw 'result nil))))
+
+(defun dart--untyped-parameter-anchored-matcher (limit)
+ "Font-lock anchored-matcher for untyped parameters.
+
+Searches forward for for lowercase idenitifer and ensures depth
+is still same.
+
+Used with `dart--anonymous-function-matcher' to fontify
+untyped parameters. For example, in
+
+ (untypedParameter) => untypedParameter.length"
+ (let (beg end)
+ (catch 'result
+ (if (equal (char-after) ?\))
+ (throw 'result nil))
+ (let ((depth (car (syntax-ppss))))
+ (while (re-search-forward
+ (rx (and (group (or (one-or-more (char ?_))
+ (eval (dart--identifier 'lower))))
+ (or ?, ?\)))))
+ (setq beg (match-beginning 1))
+ (setq end (match-end 1))
+ (goto-char end)
+ (if (or (> (point) limit)
+ (< (car (syntax-ppss)) depth))
+ (throw 'result nil)
+ (set-match-data (list beg end))
+ (throw 'result t))))
+ (throw 'result nil))))
+
+(defun dart--get-point-at-end-of-list ()
+ (let (pt)
+ (save-excursion
+ (up-list)
+ (setq pt (point)))
+ pt))
+
(defvar dart-font-lock-defaults
'((dart-font-lock-keywords-1 dart-font-lock-keywords-1
dart-font-lock-keywords-2
@@ -702,6 +769,11 @@ fontify as declared variables. From ECMA-408,
nil
nil
(0 font-lock-variable-name-face)))
+ (dart--anonymous-function-matcher
+ . (dart--untyped-parameter-anchored-matcher
+ (dart--get-point-at-end-of-list)
+ nil
+ (0 font-lock-variable-name-face)))
(dart--string-interpolation-id-func (0 font-lock-variable-name-face t))
(dart--string-interpolation-exp-func (0 font-lock-variable-name-face
t)))))
- [nongnu] elpa/dart-mode 57767bb 157/192: Makes current indentation logic more usable, (continued)
- [nongnu] elpa/dart-mode 57767bb 157/192: Makes current indentation logic more usable, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 90f1120 162/192: Require subr-x for string-empty-p, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 8983e17 186/192: Code in font-lock tests were copied from dart.dev site, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 07a9e76 189/192: Add failing font-lock test, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 3c089f3 183/192: Fix font lock for abstract method, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 40f6741 150/192: Fontifies more keywords, builtins, constants and types, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode d5776f1 172/192: Fixes fontification of small strings containing only backslashes, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 5989dca 180/192: Fontify operator declaration, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 1c2cbe5 179/192: Add faceup tests, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 04fcd64 190/192: Treat angle brackets as puncutation syntax instead of symbol syntax, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode e41f41e 174/192: Fontify untyped parameters in anonymous functions,
ELPA Syncer <=
- [nongnu] elpa/dart-mode 43975c9 192/192: Add syntax highlighting for keywords extension, late, required, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode ed80bc8 002/192: Set a bunch of CC-mode configuration vars., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 64eb399 003/192: Fix array literal indentation., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 91cc86c 005/192: Make "var" a typeless decl keyword., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 8098454 006/192: Initialize the syntax table., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 4e56274 013/192: Version 0.2., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 7e45699 018/192: Fix the Version header., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 2a66d38 020/192: Add more known bugs., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 51b9915 023/192: Fix optional argument fontification., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode f5097c0 027/192: Add a dart-mode-map., ELPA Syncer, 2021/08/29