38
38
; ; The main features of this typescript mode are syntactic
39
39
; ; highlighting (enabled with `font-lock-mode' or
40
40
; ; `global-font-lock-mode' ), automatic indentation and filling of
41
- ; ; comments and C preprocessor fontification
41
+ ; ; comments.
42
42
; ;
43
43
; ;
44
44
; ; General Remarks:
77
77
(concat typescript--name-re " \\ (?:\\ ." typescript--name-re " \\ )*" )
78
78
" Regexp matching a dot-separated sequence of typescript names." )
79
79
80
- (defconst typescript--cpp-name-re typescript--name-re
81
- " Regexp matching a C preprocessor name." )
82
-
83
- (defconst typescript--opt-cpp-start " ^\\ s-*#\\ s-*\\ ([[:alnum:]]+\\ )"
84
- " Regexp matching the prefix of a cpp directive.
85
- This includes the directive name, or nil in languages without
86
- preprocessor support. The first submatch surrounds the directive
87
- name." )
88
-
89
80
(defconst typescript--plain-method-re
90
81
(concat " ^\\ s-*?\\ (" typescript--dotted-name-re " \\ )\\ .prototype"
91
82
" \\ .\\ (" typescript--name-re " \\ )\\ s-*?=\\ s-*?\\ (function\\ )\\ _>" )
@@ -266,11 +257,6 @@ Match group 1 is the name of the function.")
266
257
" Regexp matching a line in the typescript form \" var MUMBLE = function\" .
267
258
Match group 1 is MUMBLE." )
268
259
269
- (defconst typescript--macro-decl-re
270
- (concat " ^\\ s-*#\\ s-*define\\ s-+\\ (" typescript--cpp-name-re " \\ )\\ s-*(" )
271
- " Regexp matching a CPP macro definition, up to the opening parenthesis.
272
- Match group 1 is the name of the macro." )
273
-
274
260
(defun typescript--regexp-opt-symbol (list )
275
261
" Like `regexp-opt' , but surround the result with `\\\\_<' and `\\\\_>' ."
276
262
(concat " \\ _<" (regexp-opt list t ) " \\ _>" ))
@@ -864,11 +850,7 @@ point at BOB."
864
850
(defun typescript--re-search-forward-inner (regexp &optional bound count )
865
851
" Helper function for `typescript--re-search-forward' ."
866
852
(let ((parse)
867
- str-terminator
868
- (orig-macro-end (save-excursion
869
- (when (typescript--beginning-of-macro)
870
- (c-end-of-macro )
871
- (point )))))
853
+ str-terminator)
872
854
(while (> count 0 )
873
855
(re-search-forward regexp bound)
874
856
(setq parse (syntax-ppss ))
@@ -883,22 +865,15 @@ point at BOB."
883
865
((or (nth 4 parse)
884
866
(and (eq (char-before ) ?\/ ) (eq (char-after ) ?\* )))
885
867
(re-search-forward " \\ */" ))
886
- ((and (not (and orig-macro-end
887
- (<= (point ) orig-macro-end)))
888
- (typescript--beginning-of-macro))
889
- (c-end-of-macro ))
890
868
(t
891
869
(setq count (1- count))))))
892
870
(point ))
893
871
894
872
895
873
(defun typescript--re-search-forward (regexp &optional bound noerror count )
896
- " Search forward, ignoring strings, cpp macros, and comments.
874
+ " Search forward, ignoring strings and comments.
897
875
This function invokes `re-search-forward' , but treats the buffer
898
- as if strings, cpp macros, and comments have been removed.
899
-
900
- If invoked while inside a macro, it treats the contents of the
901
- macro as normal text."
876
+ as if strings and comments have been removed."
902
877
(let ((saved-point (point ))
903
878
(search-expr
904
879
(cond ((null count)
@@ -917,11 +892,7 @@ macro as normal text."
917
892
918
893
(defun typescript--re-search-backward-inner (regexp &optional bound count )
919
894
" Auxiliary function for `typescript--re-search-backward' ."
920
- (let ((parse)
921
- (orig-macro-start
922
- (save-excursion
923
- (and (typescript--beginning-of-macro)
924
- (point )))))
895
+ (let ((parse))
925
896
(while (> count 0 )
926
897
(re-search-backward regexp bound)
927
898
(when (and (> (point ) (point-min ))
@@ -935,22 +906,16 @@ macro as normal text."
935
906
(goto-char (nth 8 parse)))
936
907
((and (eq (char-before ) ?/ ) (eq (char-after ) ?* ))
937
908
(re-search-backward " /\\ *" ))
938
- ((and (not (and orig-macro-start
939
- (>= (point ) orig-macro-start)))
940
- (typescript--beginning-of-macro)))
941
909
(t
942
910
(setq count (1- count))))))
943
911
(point ))
944
912
945
913
946
914
(defun typescript--re-search-backward (regexp &optional bound noerror count )
947
- " Search backward, ignoring strings, preprocessor macros, and comments.
915
+ " Search backward, ignoring strings, and comments.
948
916
949
917
This function invokes `re-search-backward' but treats the buffer
950
- as if strings, preprocessor macros, and comments have been
951
- removed.
952
-
953
- If invoked while inside a macro, treat the macro as normal text.
918
+ as if strings and comments have been removed.
954
919
955
920
IMPORTANT NOTE: searching for \" \\ n\" with this function to find
956
921
line breaks will generally not work, because the final newline of
@@ -1340,21 +1305,6 @@ LIMIT defaults to point."
1340
1305
name
1341
1306
(typescript--split-name name))))
1342
1307
1343
- ; ; Macro
1344
- ((looking-at typescript--macro-decl-re)
1345
-
1346
- ; ; Macros often contain unbalanced parentheses.
1347
- ; ; Make sure that h-end is at the textual end of
1348
- ; ; the macro no matter what the parenthesis say.
1349
- (c-end-of-macro )
1350
- (typescript--ensure-cache--update-parse)
1351
-
1352
- (make-typescript--pitem
1353
- :paren-depth (nth 0 parse)
1354
- :h-begin orig-match-start
1355
- :type 'macro
1356
- :name (list (match-string-no-properties 1 ))))
1357
-
1358
1308
; ; "Prototype function" declaration
1359
1309
((looking-at typescript--plain-method-re)
1360
1310
(goto-char (match-beginning 3 ))
@@ -1465,30 +1415,13 @@ LIMIT defaults to point."
1465
1415
1466
1416
(t (typescript--end-of-defun-nested)))))))
1467
1417
1468
- (defun typescript--beginning-of-macro (&optional lim )
1469
- (let ((here (point )))
1470
- (save-restriction
1471
- (if lim (narrow-to-region lim (point-max )))
1472
- (beginning-of-line )
1473
- (while (eq (char-before (1- (point ))) ?\\ )
1474
- (forward-line -1 ))
1475
- (back-to-indentation )
1476
- (if (and (<= (point ) here)
1477
- (looking-at typescript--opt-cpp-start))
1478
- t
1479
- (goto-char here)
1480
- nil ))))
1481
-
1482
1418
(defun typescript--backward-syntactic-ws (&optional lim )
1483
1419
" Simple implementation of `c-backward-syntactic-ws' for `typescript-mode' ."
1484
1420
(save-restriction
1485
1421
(when lim (narrow-to-region lim (point-max )))
1486
1422
1487
- (let ((in-macro (save-excursion (typescript--beginning-of-macro)))
1488
- (pos (point )))
1489
-
1490
- (while (progn (unless in-macro (typescript--beginning-of-macro))
1491
- (forward-comment most-negative-fixnum)
1423
+ (let ((pos (point )))
1424
+ (while (progn (forward-comment most-negative-fixnum)
1492
1425
(/= (point )
1493
1426
(prog1
1494
1427
pos
@@ -1501,8 +1434,6 @@ LIMIT defaults to point."
1501
1434
(let ((pos (point )))
1502
1435
(while (progn
1503
1436
(forward-comment most-positive-fixnum)
1504
- (when (eq (char-after ) ?# )
1505
- (c-end-of-macro ))
1506
1437
(/= (point )
1507
1438
(prog1
1508
1439
pos
@@ -1746,13 +1677,6 @@ and searches for the next token to be highlighted."
1746
1677
1747
1678
(defconst typescript--font-lock-keywords-3
1748
1679
`(
1749
- ; ; This goes before keywords-2 so it gets used preferentially
1750
- ; ; instead of the keywords in keywords-2. Don't use override
1751
- ; ; because that will override syntactic fontification too, which
1752
- ; ; will fontify commented-out directives as if they weren't
1753
- ; ; commented out.
1754
- ,@cpp-font-lock-keywords ; from font-lock.el
1755
-
1756
1680
,@typescript--font-lock-keywords-2
1757
1681
1758
1682
(typescript--jsdoc-param-matcher (1 'typescript-jsdoc-tag t t )
@@ -2331,7 +2255,6 @@ moved on success."
2331
2255
((nth 8 parse-status) 0 ) ; inside string
2332
2256
((typescript--ctrl-statement-indentation))
2333
2257
((eq (char-after ) ?# ) 0 )
2334
- ((save-excursion (typescript--beginning-of-macro)) 4 )
2335
2258
((nth 1 parse-status)
2336
2259
(let ((same-indent-p (looking-at " []})]" ))
2337
2260
(switch-keyword-p (looking-at " \\ _<default\\ _>\\ |\\ _<case\\ _>[^:]" ))
@@ -2407,10 +2330,7 @@ moved on success."
2407
2330
(typescript--forward-syntactic-ws limit)))
2408
2331
((symbol-function 'c-backward-sws )
2409
2332
(lambda (&optional limit )
2410
- (typescript--backward-syntactic-ws limit)))
2411
- ((symbol-function 'c-beginning-of-macro )
2412
- (lambda (&optional limit )
2413
- (typescript--beginning-of-macro limit))))
2333
+ (typescript--backward-syntactic-ws limit))))
2414
2334
(let ((fill-paragraph-function 'c-fill-paragraph ))
2415
2335
(c-fill-paragraph justify))))
2416
2336
0 commit comments