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:
82
82
(concat typescript--name-re " \\ (?:\\ ." typescript--name-re " \\ )*" )
83
83
" Regexp matching a dot-separated sequence of typescript names." )
84
84
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
-
94
85
(defconst typescript--plain-method-re
95
86
(concat " ^\\ s-*?\\ (" typescript--dotted-name-re " \\ )\\ .prototype"
96
87
" \\ .\\ (" typescript--name-re " \\ )\\ s-*?=\\ s-*?\\ (function\\ )\\ _>" )
@@ -271,11 +262,6 @@ Match group 1 is the name of the function.")
271
262
" Regexp matching a line in the typescript form \" var MUMBLE = function\" .
272
263
Match group 1 is MUMBLE." )
273
264
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
-
279
265
(defun typescript--regexp-opt-symbol (list )
280
266
" Like `regexp-opt' , but surround the result with `\\\\_<' and `\\\\_>' ."
281
267
(concat " \\ _<" (regexp-opt list t ) " \\ _>" ))
@@ -869,11 +855,7 @@ point at BOB."
869
855
(defun typescript--re-search-forward-inner (regexp &optional bound count )
870
856
" Helper function for `typescript--re-search-forward' ."
871
857
(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)
877
859
(while (> count 0 )
878
860
(re-search-forward regexp bound)
879
861
(setq parse (syntax-ppss ))
@@ -888,22 +870,15 @@ point at BOB."
888
870
((or (nth 4 parse)
889
871
(and (eq (char-before ) ?\/ ) (eq (char-after ) ?\* )))
890
872
(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 ))
895
873
(t
896
874
(setq count (1- count))))))
897
875
(point ))
898
876
899
877
900
878
(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.
902
880
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."
907
882
(let ((saved-point (point ))
908
883
(search-expr
909
884
(cond ((null count)
@@ -922,11 +897,7 @@ macro as normal text."
922
897
923
898
(defun typescript--re-search-backward-inner (regexp &optional bound count )
924
899
" 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))
930
901
(while (> count 0 )
931
902
(re-search-backward regexp bound)
932
903
(when (and (> (point ) (point-min ))
@@ -940,22 +911,16 @@ macro as normal text."
940
911
(goto-char (nth 8 parse)))
941
912
((and (eq (char-before ) ?/ ) (eq (char-after ) ?* ))
942
913
(re-search-backward " /\\ *" ))
943
- ((and (not (and orig-macro-start
944
- (>= (point ) orig-macro-start)))
945
- (typescript--beginning-of-macro)))
946
914
(t
947
915
(setq count (1- count))))))
948
916
(point ))
949
917
950
918
951
919
(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.
953
921
954
922
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.
959
924
960
925
IMPORTANT NOTE: searching for \" \\ n\" with this function to find
961
926
line breaks will generally not work, because the final newline of
@@ -1345,21 +1310,6 @@ LIMIT defaults to point."
1345
1310
name
1346
1311
(typescript--split-name name))))
1347
1312
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
-
1363
1313
; ; "Prototype function" declaration
1364
1314
((looking-at typescript--plain-method-re)
1365
1315
(goto-char (match-beginning 3 ))
@@ -1470,30 +1420,13 @@ LIMIT defaults to point."
1470
1420
1471
1421
(t (typescript--end-of-defun-nested)))))))
1472
1422
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
-
1487
1423
(defun typescript--backward-syntactic-ws (&optional lim )
1488
1424
" Simple implementation of `c-backward-syntactic-ws' for `typescript-mode' ."
1489
1425
(save-restriction
1490
1426
(when lim (narrow-to-region lim (point-max )))
1491
1427
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)
1497
1430
(/= (point )
1498
1431
(prog1
1499
1432
pos
@@ -1506,8 +1439,6 @@ LIMIT defaults to point."
1506
1439
(let ((pos (point )))
1507
1440
(while (progn
1508
1441
(forward-comment most-positive-fixnum)
1509
- (when (eq (char-after ) ?# )
1510
- (c-end-of-macro ))
1511
1442
(/= (point )
1512
1443
(prog1
1513
1444
pos
@@ -1751,13 +1682,6 @@ and searches for the next token to be highlighted."
1751
1682
1752
1683
(defconst typescript--font-lock-keywords-3
1753
1684
`(
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
-
1761
1685
,@typescript--font-lock-keywords-2
1762
1686
1763
1687
(typescript--jsdoc-param-matcher (1 'typescript-jsdoc-tag t t )
@@ -2318,7 +2242,6 @@ moved on success."
2318
2242
((nth 8 parse-status) 0 ) ; inside string
2319
2243
((typescript--ctrl-statement-indentation))
2320
2244
((eq (char-after ) ?# ) 0 )
2321
- ((save-excursion (typescript--beginning-of-macro)) 4 )
2322
2245
((nth 1 parse-status)
2323
2246
(let ((same-indent-p (looking-at " []})]" ))
2324
2247
(switch-keyword-p (looking-at " \\ _<default\\ _>\\ |\\ _<case\\ _>[^:]" ))
@@ -2394,10 +2317,7 @@ moved on success."
2394
2317
(typescript--forward-syntactic-ws limit)))
2395
2318
((symbol-function 'c-backward-sws )
2396
2319
(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))))
2401
2321
(let ((fill-paragraph-function 'c-fill-paragraph ))
2402
2322
(c-fill-paragraph justify))))
2403
2323
0 commit comments