Skip to content

Commit 4e3850d

Browse files
committed
Remove logic handling preprocessor macros
TypeScript does not have preprocessor macros. It was proposed in microsoft/TypeScript#4691 but never added to the language.
1 parent 5350c45 commit 4e3850d

File tree

1 file changed

+10
-90
lines changed

1 file changed

+10
-90
lines changed

typescript-mode.el

+10-90
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
;; The main features of this typescript mode are syntactic
3939
;; highlighting (enabled with `font-lock-mode' or
4040
;; `global-font-lock-mode'), automatic indentation and filling of
41-
;; comments and C preprocessor fontification
41+
;; comments.
4242
;;
4343
;;
4444
;; General Remarks:
@@ -82,15 +82,6 @@
8282
(concat typescript--name-re "\\(?:\\." typescript--name-re "\\)*")
8383
"Regexp matching a dot-separated sequence of typescript names.")
8484

85-
(defconst typescript--cpp-name-re typescript--name-re
86-
"Regexp matching a C preprocessor name.")
87-
88-
(defconst typescript--opt-cpp-start "^\\s-*#\\s-*\\([[:alnum:]]+\\)"
89-
"Regexp matching the prefix of a cpp directive.
90-
This includes the directive name, or nil in languages without
91-
preprocessor support. The first submatch surrounds the directive
92-
name.")
93-
9485
(defconst typescript--plain-method-re
9586
(concat "^\\s-*?\\(" typescript--dotted-name-re "\\)\\.prototype"
9687
"\\.\\(" typescript--name-re "\\)\\s-*?=\\s-*?\\(function\\)\\_>")
@@ -271,11 +262,6 @@ Match group 1 is the name of the function.")
271262
"Regexp matching a line in the typescript form \"var MUMBLE = function\".
272263
Match group 1 is MUMBLE.")
273264

274-
(defconst typescript--macro-decl-re
275-
(concat "^\\s-*#\\s-*define\\s-+\\(" typescript--cpp-name-re "\\)\\s-*(")
276-
"Regexp matching a CPP macro definition, up to the opening parenthesis.
277-
Match group 1 is the name of the macro.")
278-
279265
(defun typescript--regexp-opt-symbol (list)
280266
"Like `regexp-opt', but surround the result with `\\\\_<' and `\\\\_>'."
281267
(concat "\\_<" (regexp-opt list t) "\\_>"))
@@ -869,11 +855,7 @@ point at BOB."
869855
(defun typescript--re-search-forward-inner (regexp &optional bound count)
870856
"Helper function for `typescript--re-search-forward'."
871857
(let ((parse)
872-
str-terminator
873-
(orig-macro-end (save-excursion
874-
(when (typescript--beginning-of-macro)
875-
(c-end-of-macro)
876-
(point)))))
858+
str-terminator)
877859
(while (> count 0)
878860
(re-search-forward regexp bound)
879861
(setq parse (syntax-ppss))
@@ -888,22 +870,15 @@ point at BOB."
888870
((or (nth 4 parse)
889871
(and (eq (char-before) ?\/) (eq (char-after) ?\*)))
890872
(re-search-forward "\\*/"))
891-
((and (not (and orig-macro-end
892-
(<= (point) orig-macro-end)))
893-
(typescript--beginning-of-macro))
894-
(c-end-of-macro))
895873
(t
896874
(setq count (1- count))))))
897875
(point))
898876

899877

900878
(defun typescript--re-search-forward (regexp &optional bound noerror count)
901-
"Search forward, ignoring strings, cpp macros, and comments.
879+
"Search forward, ignoring strings and comments.
902880
This function invokes `re-search-forward', but treats the buffer
903-
as if strings, cpp macros, and comments have been removed.
904-
905-
If invoked while inside a macro, it treats the contents of the
906-
macro as normal text."
881+
as if strings and comments have been removed."
907882
(let ((saved-point (point))
908883
(search-expr
909884
(cond ((null count)
@@ -922,11 +897,7 @@ macro as normal text."
922897

923898
(defun typescript--re-search-backward-inner (regexp &optional bound count)
924899
"Auxiliary function for `typescript--re-search-backward'."
925-
(let ((parse)
926-
(orig-macro-start
927-
(save-excursion
928-
(and (typescript--beginning-of-macro)
929-
(point)))))
900+
(let ((parse))
930901
(while (> count 0)
931902
(re-search-backward regexp bound)
932903
(when (and (> (point) (point-min))
@@ -940,22 +911,16 @@ macro as normal text."
940911
(goto-char (nth 8 parse)))
941912
((and (eq (char-before) ?/) (eq (char-after) ?*))
942913
(re-search-backward "/\\*"))
943-
((and (not (and orig-macro-start
944-
(>= (point) orig-macro-start)))
945-
(typescript--beginning-of-macro)))
946914
(t
947915
(setq count (1- count))))))
948916
(point))
949917

950918

951919
(defun typescript--re-search-backward (regexp &optional bound noerror count)
952-
"Search backward, ignoring strings, preprocessor macros, and comments.
920+
"Search backward, ignoring strings, and comments.
953921
954922
This function invokes `re-search-backward' but treats the buffer
955-
as if strings, preprocessor macros, and comments have been
956-
removed.
957-
958-
If invoked while inside a macro, treat the macro as normal text.
923+
as if strings and comments have been removed.
959924
960925
IMPORTANT NOTE: searching for \"\\n\" with this function to find
961926
line breaks will generally not work, because the final newline of
@@ -1345,21 +1310,6 @@ LIMIT defaults to point."
13451310
name
13461311
(typescript--split-name name))))
13471312

1348-
;; Macro
1349-
((looking-at typescript--macro-decl-re)
1350-
1351-
;; Macros often contain unbalanced parentheses.
1352-
;; Make sure that h-end is at the textual end of
1353-
;; the macro no matter what the parenthesis say.
1354-
(c-end-of-macro)
1355-
(typescript--ensure-cache--update-parse)
1356-
1357-
(make-typescript--pitem
1358-
:paren-depth (nth 0 parse)
1359-
:h-begin orig-match-start
1360-
:type 'macro
1361-
:name (list (match-string-no-properties 1))))
1362-
13631313
;; "Prototype function" declaration
13641314
((looking-at typescript--plain-method-re)
13651315
(goto-char (match-beginning 3))
@@ -1470,30 +1420,13 @@ LIMIT defaults to point."
14701420

14711421
(t (typescript--end-of-defun-nested)))))))
14721422

1473-
(defun typescript--beginning-of-macro (&optional lim)
1474-
(let ((here (point)))
1475-
(save-restriction
1476-
(if lim (narrow-to-region lim (point-max)))
1477-
(beginning-of-line)
1478-
(while (eq (char-before (1- (point))) ?\\)
1479-
(forward-line -1))
1480-
(back-to-indentation)
1481-
(if (and (<= (point) here)
1482-
(looking-at typescript--opt-cpp-start))
1483-
t
1484-
(goto-char here)
1485-
nil))))
1486-
14871423
(defun typescript--backward-syntactic-ws (&optional lim)
14881424
"Simple implementation of `c-backward-syntactic-ws' for `typescript-mode'."
14891425
(save-restriction
14901426
(when lim (narrow-to-region lim (point-max)))
14911427

1492-
(let ((in-macro (save-excursion (typescript--beginning-of-macro)))
1493-
(pos (point)))
1494-
1495-
(while (progn (unless in-macro (typescript--beginning-of-macro))
1496-
(forward-comment most-negative-fixnum)
1428+
(let ((pos (point)))
1429+
(while (progn (forward-comment most-negative-fixnum)
14971430
(/= (point)
14981431
(prog1
14991432
pos
@@ -1506,8 +1439,6 @@ LIMIT defaults to point."
15061439
(let ((pos (point)))
15071440
(while (progn
15081441
(forward-comment most-positive-fixnum)
1509-
(when (eq (char-after) ?#)
1510-
(c-end-of-macro))
15111442
(/= (point)
15121443
(prog1
15131444
pos
@@ -1751,13 +1682,6 @@ and searches for the next token to be highlighted."
17511682

17521683
(defconst typescript--font-lock-keywords-3
17531684
`(
1754-
;; This goes before keywords-2 so it gets used preferentially
1755-
;; instead of the keywords in keywords-2. Don't use override
1756-
;; because that will override syntactic fontification too, which
1757-
;; will fontify commented-out directives as if they weren't
1758-
;; commented out.
1759-
,@cpp-font-lock-keywords ; from font-lock.el
1760-
17611685
,@typescript--font-lock-keywords-2
17621686

17631687
(typescript--jsdoc-param-matcher (1 'typescript-jsdoc-tag t t)
@@ -2318,7 +2242,6 @@ moved on success."
23182242
((nth 8 parse-status) 0) ; inside string
23192243
((typescript--ctrl-statement-indentation))
23202244
((eq (char-after) ?#) 0)
2321-
((save-excursion (typescript--beginning-of-macro)) 4)
23222245
((nth 1 parse-status)
23232246
(let ((same-indent-p (looking-at "[]})]"))
23242247
(switch-keyword-p (looking-at "\\_<default\\_>\\|\\_<case\\_>[^:]"))
@@ -2394,10 +2317,7 @@ moved on success."
23942317
(typescript--forward-syntactic-ws limit)))
23952318
((symbol-function 'c-backward-sws)
23962319
(lambda (&optional limit)
2397-
(typescript--backward-syntactic-ws limit)))
2398-
((symbol-function 'c-beginning-of-macro)
2399-
(lambda (&optional limit)
2400-
(typescript--beginning-of-macro limit))))
2320+
(typescript--backward-syntactic-ws limit))))
24012321
(let ((fill-paragraph-function 'c-fill-paragraph))
24022322
(c-fill-paragraph justify))))
24032323

0 commit comments

Comments
 (0)