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

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

[nongnu] elpa/dart-mode d9a12e1 151/192: Fontifies function declarations


From: ELPA Syncer
Subject: [nongnu] elpa/dart-mode d9a12e1 151/192: Fontifies function declarations
Date: Sun, 29 Aug 2021 11:02:08 -0400 (EDT)

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

    Fontifies function declarations
    
    This commit adds a function to match function declarations.
    
    We search forward for a lower camel case identifier followed by an
    opening paren, then jump to closing paren, and check for either an async
    keyword, or an opening of a block statement, or an arrow.
    
    The docstring of `font-lock-keywords` specifies how a matcher function
    must work.
    
    Function takes an argument `limit`, searches from point, and if no
    match found returns nil, otherwise, sets match data, sets point for
    next search, and returns non-nil.
---
 dart-mode.el | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/dart-mode.el b/dart-mode.el
index 575f95e..edea013 100644
--- a/dart-mode.el
+++ b/dart-mode.el
@@ -407,6 +407,25 @@ Returns nil if `dart-sdk-path' is nil."
 
 (setq dart--types-re (rx (eval (dart--identifier 'upper))))
 
+(defun dart--function-declaration-func (limit)
+  (catch 'result
+    (let (beg end)
+      (while (re-search-forward
+              (rx (group (eval (dart--identifier 'lower))) ?\() limit t)
+        (setq beg (match-beginning 1))
+        (setq end (match-end 1))
+        (condition-case nil
+            (progn
+              (up-list)
+              (when (looking-at (rx (one-or-more space)
+                                    (or "async" "async*" "sync*" "{" "=>")))
+                (set-match-data (list beg end))
+                (goto-char end)
+                (throw 'result t)))
+          (scan-error nil))
+        (goto-char end))
+      (throw 'result nil))))
+
 (setq dart-font-lock-defaults
       `((,dart--async-keywords-re
          ,(regexp-opt dart--keywords 'words)
@@ -416,7 +435,8 @@ Returns nil if `dart-sdk-path' is nil."
          (,dart--number-re                     . (1 font-lock-constant-face))
          (,dart--metadata-re                   . font-lock-constant-face)
          (,(regexp-opt dart--types 'words)     . font-lock-type-face)
-         (,dart--types-re                      . font-lock-type-face))))
+         (,dart--types-re                      . font-lock-type-face)
+         (dart--function-declaration-func      . 
font-lock-function-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]