emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/dart-mode 21abd77 152/192: Fontifies declared identifiers


From: ELPA Syncer
Subject: [nongnu] elpa/dart-mode 21abd77 152/192: Fontifies declared identifiers
Date: Sun, 29 Aug 2021 11:02:08 -0400 (EDT)

branch: elpa/dart-mode
commit 21abd774a1e1a76a9d51b4b925d97a67b6890b83
Author: Brady Trainor <mail@bradyt.com>
Commit: Brady Trainor <mail@bradyt.com>

    Fontifies declared identifiers
    
    Declared identifiers are found in variable declarations and formal
    parameters.
    
    For example,
    
    ```
    var abc;
    String str;
    void main(Map<int, bool> str2, [int n]) {}
    bool get returnVal => this.x;
    ```
    
    So then this function will fontify `abc`, `str`, `str2`, `n`,
    `returnVal`.
    
    Prevent fontification of functions as variables
    
    If function fontification was turned off, functions were being
    fontified as variables. This makes sure there is not an opening paren
    after a variable.
---
 dart-mode.el | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/dart-mode.el b/dart-mode.el
index edea013..1f904e4 100644
--- a/dart-mode.el
+++ b/dart-mode.el
@@ -426,6 +426,33 @@ Returns nil if `dart-sdk-path' is nil."
         (goto-char end))
       (throw 'result nil))))
 
+(defun dart--declared-identifier-func (limit)
+  (catch 'result
+    (let (beg end)
+      (while (re-search-forward
+              (rx
+               (and (group (or (or "const" "final"
+                                   "bool" "double" "dynamic" "int" "num" "void"
+                                   "var"
+                                   "get" "set")
+                               (eval (dart--identifier 'upper)))
+                           (zero-or-one ?>))
+                    (one-or-more (or space ?\C-j))
+                    (group (eval (dart--identifier 'lower)))
+                    (not (any ?\( alnum ?$ ?_))))
+              limit t)
+        (setq beg (match-beginning 2))
+        (setq end (match-end 2))
+        (when (not (member (match-string 2)
+                           '("bool" "double" "dynamic" "int" "num" "void"
+                             "var"
+                             "get" "set")))
+          (set-match-data (list beg end))
+          (goto-char end)
+          (throw 'result t))
+        (goto-char (match-end 1)))
+      (throw 'result nil))))
+
 (setq dart-font-lock-defaults
       `((,dart--async-keywords-re
          ,(regexp-opt dart--keywords 'words)
@@ -436,7 +463,8 @@ Returns nil if `dart-sdk-path' is nil."
          (,dart--metadata-re                   . font-lock-constant-face)
          (,(regexp-opt dart--types 'words)     . font-lock-type-face)
          (,dart--types-re                      . font-lock-type-face)
-         (dart--function-declaration-func      . 
font-lock-function-name-face))))
+         (dart--function-declaration-func      . font-lock-function-name-face)
+         (dart--declared-identifier-func       . 
font-lock-variable-name-face))))
 
 (defun dart-fontify-region (beg end)
   "Use fontify the region between BEG and END as Dart.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]