Skip to content

Commit 6f3b8b4

Browse files
committed
Misc minor issues
* typescript-mode.el: Activate `lexical-binding`. (typescript--font-lock-keywords-2): Use backquote. Quote face names so as not to rely on obsolete `font-lock-*-face` variables. (typescript--re-search-forward, typescript--re-search-backward): Use `funcall` instead of `eval` to save kittens and be compatible with `lexical-binding`. (typescript--font-lock-keywords-3): Quote face names as above. (typescript--font-lock-keywords-4): Fix "\[\]" to "\\[\\]". Quote face names as above. * .gitignore: Add ELPA-generated files.
1 parent 769c1f9 commit 6f3b8b4

File tree

2 files changed

+48
-44
lines changed

2 files changed

+48
-44
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,7 @@ $RECYCLE.BIN/
8484
*.lnk
8585

8686
# End of https://www.gitignore.io/api/emacs,windows,linux
87+
88+
# ELPA-generated files.
89+
/typescript-mode-autoloads.el
90+
/typescript-mode-pkg.el

typescript-mode.el

+44-44
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
;;; typescript-mode.el --- Major mode for editing typescript
1+
;;; typescript-mode.el --- Major mode for editing typescript -*- lexical-binding: t -*-
22

33
;; -----------------------------------------------------------------------------------
44
;; TypeScript support for Emacs
55
;; Unmodified original sourve available at http://www.karllandstrom.se/downloads/emacs/javascript.el
6-
;; Copyright (c) 2008 Free Software Foundation
6+
;; Copyright (c) 2008-2025 Free Software Foundation
77
;; Portions Copyright (C) Microsoft Open Technologies, Inc. All rights reserved.
88
;;
99
;; This program is free software: you can redistribute it and/or modify
@@ -312,13 +312,13 @@ Match group 1 is MUMBLE.")
312312

313313
(defconst typescript--font-lock-keywords-2
314314
(append typescript--font-lock-keywords-1
315-
(list (cons typescript--constant-re font-lock-constant-face)
316-
(cons typescript--basic-type-re font-lock-type-face)
317-
(list typescript--keyword-re 1 font-lock-keyword-face)
318-
(list "\\_<for\\_>"
319-
"\\s-+\\(each\\)\\_>" nil nil
320-
(list 1 'font-lock-keyword-face))
321-
(cons "\\_<yield\\(\\*\\|\\_>\\)" 'font-lock-keyword-face)))
315+
`((,typescript--constant-re (0 'font-lock-constant-face))
316+
(,typescript--basic-type-re (0 'font-lock-type-face))
317+
(,typescript--keyword-re (1 'font-lock-keyword-face))
318+
("\\_<for\\_>"
319+
("\\s-+\\(each\\)\\_>" nil nil
320+
(1 'font-lock-keyword-face)))
321+
("\\_<yield\\(\\*\\|\\_>\\)" (0 'font-lock-keyword-face))))
322322
"Level two font lock keywords for `typescript-mode'.")
323323

324324
;; typescript--pitem is the basic building block of the lexical
@@ -935,15 +935,16 @@ point at BOB."
935935
This function invokes `re-search-forward', but treats the buffer
936936
as if strings and comments have been removed."
937937
(let ((saved-point (point))
938-
(search-expr
938+
(search-fun
939939
(cond ((null count)
940-
'(typescript--re-search-forward-inner regexp bound 1))
940+
(lambda () (typescript--re-search-forward-inner regexp bound 1)))
941941
((< count 0)
942-
'(typescript--re-search-backward-inner regexp bound (- count)))
942+
(lambda () (typescript--re-search-backward-inner regexp bound (- count))))
943943
((> count 0)
944-
'(typescript--re-search-forward-inner regexp bound count)))))
944+
(lambda () (typescript--re-search-forward-inner regexp bound count)))
945+
(t #'ignore))))
945946
(condition-case err
946-
(eval search-expr)
947+
(funcall search-fun)
947948
(search-failed
948949
(goto-char saved-point)
949950
(unless noerror
@@ -990,15 +991,16 @@ If the point is in the last line, searching back for \"\\n\" will
990991
skip over the line with \"let b\". The newline found will be the
991992
one at the end of the line with \"let a\"."
992993
(let ((saved-point (point))
993-
(search-expr
994+
(search-fun
994995
(cond ((null count)
995-
`(typescript--re-search-backward-inner ,regexp ,bound 1))
996+
(lambda () (typescript--re-search-backward-inner regexp bound 1)))
996997
((< count 0)
997-
`(typescript--re-search-forward-inner ,regexp ,bound (- ,count)))
998+
(lambda () (typescript--re-search-forward-inner regexp bound (- count))))
998999
((> count 0)
999-
`(typescript--re-search-backward-inner ,regexp ,bound ,count)))))
1000+
(lambda () (typescript--re-search-backward-inner regexp bound count)))
1001+
(t #'ignore))))
10001002
(condition-case err
1001-
(eval search-expr)
1003+
(funcall search-fun)
10021004
(search-failed
10031005
(goto-char saved-point)
10041006
(unless noerror
@@ -1839,35 +1841,35 @@ and searches for the next token to be highlighted."
18391841
(0 'typescript-jsdoc-value t))
18401842

18411843
(typescript--tslint-flag-matcher
1842-
(1 font-lock-preprocessor-face t))
1844+
(1 'font-lock-preprocessor-face t))
18431845

18441846
("\\.\\(prototype\\)\\_>"
1845-
(1 font-lock-constant-face))
1847+
(1 'font-lock-constant-face))
18461848

18471849
(,(rx symbol-start "class" (+ space) (group (+ (or (syntax word) (syntax symbol)))))
1848-
(1 font-lock-type-face))
1850+
(1 'font-lock-type-face))
18491851

18501852
(,(rx symbol-start "extends" (+ space) (group (+ (or (syntax word) (syntax symbol)))))
1851-
(1 font-lock-type-face))
1853+
(1 'font-lock-type-face))
18521854

18531855
(,(rx symbol-start "implements" (+ space))
1854-
(,(rx symbol-start (+ (syntax word))) nil nil (0 font-lock-type-face)))
1856+
(,(rx symbol-start (+ (syntax word))) nil nil (0 'font-lock-type-face)))
18551857

18561858
(,(rx symbol-start "interface" (+ space) (group (+ (or (syntax word) (syntax symbol)))))
1857-
(1 font-lock-type-face))
1859+
(1 'font-lock-type-face))
18581860

18591861
(,(rx symbol-start "type" (+ space) (group (+ (or (syntax word) (syntax symbol)))))
1860-
(1 font-lock-type-face))
1862+
(1 'font-lock-type-face))
18611863

18621864
(,(rx symbol-start "enum" (+ space) (group (+ (or (syntax word) (syntax symbol)))))
1863-
(1 font-lock-type-face))
1865+
(1 'font-lock-type-face))
18641866

18651867
;; Highlights class being declared, in parts
18661868
(typescript--class-decl-matcher
18671869
,(concat "\\(" typescript--name-re "\\)\\(?:\\.\\|.*$\\)")
18681870
(goto-char (match-beginning 1))
18691871
nil
1870-
(1 font-lock-type-face))
1872+
(1 'font-lock-type-face))
18711873

18721874
;; Highlights parent class, in parts, if available
18731875
(typescript--class-decl-matcher
@@ -1884,20 +1886,20 @@ and searches for the next token to be highlighted."
18841886
(save-excursion
18851887
(goto-char typescript--tmp-location)
18861888
(delete-char 1)))
1887-
(1 font-lock-type-face))
1889+
(1 'font-lock-type-face))
18881890

18891891
;; Highlights parent class
18901892
(typescript--class-decl-matcher
1891-
(2 font-lock-type-face nil t))
1893+
(2 'font-lock-type-face nil t))
18921894

18931895
;; Dojo needs its own matcher to override the string highlighting
18941896
(,(typescript--make-framework-matcher
18951897
'dojo
18961898
"^\\s-*dojo\\.declare\\s-*(\""
18971899
"\\(" typescript--dotted-name-re "\\)"
18981900
"\\(?:\"\\s-*,\\s-*\\(" typescript--dotted-name-re "\\)\\)?")
1899-
(1 font-lock-type-face t)
1900-
(2 font-lock-type-face nil t))
1901+
(1 'font-lock-type-face t)
1902+
(2 'font-lock-type-face nil t))
19011903

19021904
;; Match Dojo base classes. Of course Mojo has to be different
19031905
;; from everything else under the sun...
@@ -1909,7 +1911,7 @@ and searches for the next token to be highlighted."
19091911
"\\(?:\\].*$\\)?")
19101912
(backward-char)
19111913
(end-of-line)
1912-
(1 font-lock-type-face))
1914+
(1 'font-lock-type-face))
19131915

19141916
;; continued Dojo base-class list
19151917
(,(typescript--make-framework-matcher
@@ -1922,22 +1924,20 @@ and searches for the next token to be highlighted."
19221924
(forward-symbol -1)
19231925
(end-of-line))
19241926
(end-of-line)
1925-
(1 font-lock-type-face))
1927+
(1 'font-lock-type-face))
19261928

19271929
;; variable declarations
19281930
,(list
19291931
(concat "\\_<\\(const\\|var\\|let\\)\\_>\\|" typescript--basic-type-re)
19301932
(list #'typescript--variable-decl-matcher nil nil nil))
19311933

19321934
;; class instantiation
1933-
,(list
1934-
(concat "\\_<new\\_>\\s-+\\(" typescript--dotted-name-re "\\)")
1935-
(list 1 'font-lock-type-face))
1935+
(,(concat "\\_<new\\_>\\s-+\\(" typescript--dotted-name-re "\\)")
1936+
(1 'font-lock-type-face))
19361937

19371938
;; instanceof
1938-
,(list
1939-
(concat "\\_<instanceof\\_>\\s-+\\(" typescript--dotted-name-re "\\)")
1940-
(list 1 'font-lock-type-face))
1939+
(,(concat "\\_<instanceof\\_>\\s-+\\(" typescript--dotted-name-re "\\)")
1940+
(1 'font-lock-type-face))
19411941

19421942
;; formal parameters in "function" function call
19431943
;; function helloWorld(a: number, b: Promise<number>): void { }
@@ -2162,7 +2162,7 @@ This performs fontification according to `typescript--class-styles'."
21622162
;; - () => SomeType
21632163
;; TODO: namespaced classes!
21642164
,(list
2165-
(concat "\\(?::\\|=>\\)\\s-\\(?:\\s-*\\(" typescript--name-re "\\)\\s-*\\(is\\)\\s-*\\)?" "\\(" typescript--type-name-re "\\)\\(<" typescript--type-name-re ">\\)?\\(\[\]\\)?\\([,;]\\)?\\s-*{?")
2165+
(concat "\\(?::\\|=>\\)\\s-\\(?:\\s-*\\(" typescript--name-re "\\)\\s-*\\(is\\)\\s-*\\)?" "\\(" typescript--type-name-re "\\)\\(<" typescript--type-name-re ">\\)?\\(\\[\\]\\)?\\([,;]\\)?\\s-*{?")
21662166
'(1 'font-lock-variable-name-face nil t)
21672167
'(2 'font-lock-keyword-face nil t)
21682168
'(3 'font-lock-type-face))
@@ -2179,12 +2179,12 @@ This performs fontification according to `typescript--class-styles'."
21792179
(,typescript--decorator-re (1 'font-lock-function-call-face))
21802180
(,typescript--function-call-re (1 (typescript--function-face)))
21812181
(,(concat "\\(?:\\.\\s-*\\)" typescript--function-call-re)
2182-
(1 font-lock-function-call-face t))
2183-
(,typescript--builtin-re (1 font-lock-type-face))
2182+
(1 'font-lock-function-call-face t))
2183+
(,typescript--builtin-re (1 'font-lock-type-face))
21842184

21852185
;; arrow function
21862186
("\\(=>\\)"
2187-
(1 font-lock-keyword-face))
2187+
(1 'font-lock-keyword-face))
21882188

21892189
(typescript--match-subst-in-quotes
21902190
(1 'font-lock-keyword-face t)

0 commit comments

Comments
 (0)