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

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

[nongnu] elpa/typescript-mode 1bafd279cf 148/222: Enable more colors (#1


From: ELPA Syncer
Subject: [nongnu] elpa/typescript-mode 1bafd279cf 148/222: Enable more colors (#110)
Date: Sun, 6 Feb 2022 16:59:28 -0500 (EST)

branch: elpa/typescript-mode
commit 1bafd279cf5161476aa540267ea0a45684749cbd
Author: Ari Miller <arimiller92@gmail.com>
Commit: Jostein Kjønigsen <jostein@kjonigsen.net>

    Enable more colors (#110)
    
    
    * primitive function call highlighting
    * arrow function parameters
    * better type hint
    * generics and decorator
    * extend function call regexp for generics
    
    This closes #79.
---
 typescript-mode.el | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 71 insertions(+), 3 deletions(-)

diff --git a/typescript-mode.el b/typescript-mode.el
index 178e4283c8..4a91d5f313 100644
--- a/typescript-mode.el
+++ b/typescript-mode.el
@@ -270,7 +270,7 @@ Match group 1 is MUMBLE.")
      "private" "protected" "public" "readonly" "return" "set" "static" "string"
      "super" "switch"  "this" "throw" "true"
      "try" "type" "typeof" "unknown" "var" "void"
-     "while"))                  ; yield is handled separately
+     "while")) ; yield is handled separately
   "Regexp matching any typescript keyword.")
 
 (defconst typescript--basic-type-re
@@ -278,12 +278,35 @@ Match group 1 is MUMBLE.")
    '("any" "bool" "boolean" "bigint" "never" "number" "string" "unknown" 
"void"))
   "Regular expression matching any predefined type in typescript.")
 
+(defconst typescript--access-modifier-re
+  (typescript--regexp-opt-symbol
+   '("private" "protected" "public" "readonly" "static" "extends" 
"implements"))
+  "Regular expression matching access modifiers.")
+
+(defconst typescript--generic-type-re
+  "<\\(.*\\)>"
+   "Regular expression matching generic types.")
+
+(defconst typescript--generic-type-extended-re
+  (concat "<\\(.*\\)extends\\(.*\\)>")
+   "Regular expression matching generic types with extension.")
+
+(defconst typescript--decorator-re
+  (concat "\\(@" typescript--name-re "\\)"))
+
 (defconst typescript--constant-re
   (typescript--regexp-opt-symbol '("false" "null" "undefined"
                                  "Infinity" "NaN"
                                  "true" "arguments" "this"))
   "Regular expression matching any future reserved words in typescript.")
 
+(defconst typescript--builtin-re
+  (typescript--regexp-opt-symbol
+   '("console"))
+  "Regular expression matching builtins.")
+
+(defconst typescript--function-call-re "\\(\\w+\\)\\(<.+>\\)?\s*("
+  "Regular expression matching function calls.")
 
 (defconst typescript--font-lock-keywords-1
   (list
@@ -592,6 +615,21 @@ Match group 1 is MUMBLE.")
   "Face used to highlight tag values in jsdoc comments."
   :group 'typescript)
 
+(defface typescript-access-modifier-face
+  '((t (:inherit font-lock-keyword-face)))
+  "Face used to highlight access modifiers."
+  :group 'typescript)
+
+(defface typescript-this-face
+  '((t (:inherit font-lock-keyword-face)))
+  "Face used to highlight 'this' keyword."
+  :group 'typescript)
+
+(defface typescript-primitive-face
+  '((t (:inherit font-lock-keyword-face)))
+  "Face used to highlight builtin types."
+  :group 'typescript)
+
 ;;; User Customization
 
 (defgroup typescript nil
@@ -1966,10 +2004,40 @@ This performs fontification according to 
`typescript--class-styles'."
         return t
         else do (goto-char orig-end)))
 
+(defconst typescript--font-lock-keywords-4
+  `(
+    ;; highlights that override previous levels
+    ;;
+
+    ;; special highlight for `this' keyword
+    ("\\(this\\)\\."
+     (1 'typescript-this-face))
+
+    (,typescript--access-modifier-re (1 'typescript-access-modifier-face))
+    (,typescript--basic-type-re (1 'typescript-primitive-face))
+
+    ;; highlights that append to previous levels
+    ;;
+    ,@typescript--font-lock-keywords-3
+
+    (,typescript--decorator-re (1 font-lock-function-name-face))
+    (,typescript--function-call-re (1 font-lock-function-name-face))
+    (,typescript--builtin-re (1 font-lock-type-face))
+
+    (,typescript--generic-type-re (1 font-lock-type-face))
+    (,typescript--generic-type-extended-re (1 font-lock-type-face))
+
+    ;; arrow function
+    ("\\(=>\\)"
+     (1 font-lock-keyword-face))
+    )
+  "Level four font lock for `typescript-mode'.")
+
 (defconst typescript--font-lock-keywords
-  '(typescript--font-lock-keywords-3 typescript--font-lock-keywords-1
+  '(typescript--font-lock-keywords-4 typescript--font-lock-keywords-1
                                    typescript--font-lock-keywords-2
-                                   typescript--font-lock-keywords-3)
+                                   typescript--font-lock-keywords-3
+                                   typescript--font-lock-keywords-4)
   "Font lock keywords for `typescript-mode'.  See `font-lock-keywords'.")
 
 ;;; Propertize



reply via email to

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