Skip to content

Commit 4e709df

Browse files
committed
feat(font): fontify arrow fn arguments (wip)
1 parent 83bf47e commit 4e709df

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

typescript-mode.el

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ lines."
10151015
(progn
10161016
(forward-comment most-positive-fixnum)
10171017
(memq (char-after) '(?\, ?\; ?\] ?\) ?\}))))
1018-
do (forward-sexp)))
1018+
do (forward-sexp)))
10191019
while (and (eq (char-after) ?\n)
10201020
(save-excursion
10211021
(forward-char)
@@ -1686,6 +1686,33 @@ point of view of font-lock. It applies highlighting directly with
16861686
;; Matcher always "fails"
16871687
nil)
16881688

1689+
(defun typescript--function-argument-matcher (limit)
1690+
(condition-case nil
1691+
(save-restriction
1692+
(widen)
1693+
(narrow-to-region (point-min) limit)
1694+
(while (re-search-forward (rx (group (regexp typescript--name-re))
1695+
(* whitespace)
1696+
(group (or "," ":" ")")))
1697+
nil t)
1698+
(font-lock-apply-highlight '(1 font-lock-variable-name-face t))
1699+
1700+
(let ((ender (match-string 2)))
1701+
;; we need to skip the type specification
1702+
(when (equal ender ":")
1703+
(when (re-search-forward (rx (or (and "," eol)
1704+
(and ")")
1705+
(and ","
1706+
(* whitespace)
1707+
(regexp typescript--name-re)
1708+
(group (or ":" ")")))))
1709+
nil t)
1710+
(goto-char (match-beginning 0)))))))
1711+
;; Conditions to handle
1712+
(scan-error nil)
1713+
(end-of-buffer nil))
1714+
nil)
1715+
16891716
(defun typescript--in-documentation-comment-p ()
16901717
"Reports whether point is inside a documentation comment."
16911718
(let ((parse (syntax-ppss)))
@@ -1864,7 +1891,27 @@ and searches for the next token to be highlighted."
18641891
(prog1 (save-excursion (re-search-forward ")" nil t))
18651892
(backward-char))
18661893
nil
1867-
(1 font-lock-variable-name-face))))
1894+
(1 font-lock-variable-name-face)))
1895+
1896+
;; formal parameters in arrow function
1897+
,(list
1898+
(rx (group "=>") (* whitespace) (? eol) (* whitespace) "{")
1899+
'(1 font-lock-keyword-face)
1900+
`(;; ,(rx (group (regexp typescript--name-re))
1901+
;; (* whitespace)
1902+
;; (? ":" (* whitespace) (regexp typescript--name-re) (* whitespace))
1903+
;; (or "," ")" eol))
1904+
typescript--function-argument-matcher
1905+
(prog1 (progn
1906+
(backward-char)
1907+
(typescript--backward-to-parameter-list)
1908+
(point))
1909+
(backward-sexp))
1910+
(re-search-forward "{" nil t)
1911+
nil
1912+
;; (1 font-lock-variable-name-face t t)
1913+
))
1914+
)
18681915
"Level three font lock for `typescript-mode'.")
18691916

18701917
(defun typescript--flyspell-mode-predicate ()

0 commit comments

Comments
 (0)