Skip to content

Commit 7a5c74d

Browse files
authored
Merge pull request #72 from Wilfred/remove_cpp
Remove logic handling preprocessor macros
2 parents a09e9c7 + 4e3850d commit 7a5c74d

File tree

1 file changed

+10
-90
lines changed

1 file changed

+10
-90
lines changed

typescript-mode.el

Lines changed: 10 additions & 90 deletions
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:
@@ -77,15 +77,6 @@
7777
(concat typescript--name-re "\\(?:\\." typescript--name-re "\\)*")
7878
"Regexp matching a dot-separated sequence of typescript names.")
7979

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-
8980
(defconst typescript--plain-method-re
9081
(concat "^\\s-*?\\(" typescript--dotted-name-re "\\)\\.prototype"
9182
"\\.\\(" typescript--name-re "\\)\\s-*?=\\s-*?\\(function\\)\\_>")
@@ -266,11 +257,6 @@ Match group 1 is the name of the function.")
266257
"Regexp matching a line in the typescript form \"var MUMBLE = function\".
267258
Match group 1 is MUMBLE.")
268259

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-
274260
(defun typescript--regexp-opt-symbol (list)
275261
"Like `regexp-opt', but surround the result with `\\\\_<' and `\\\\_>'."
276262
(concat "\\_<" (regexp-opt list t) "\\_>"))
@@ -864,11 +850,7 @@ point at BOB."
864850
(defun typescript--re-search-forward-inner (regexp &optional bound count)
865851
"Helper function for `typescript--re-search-forward'."
866852
(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)
872854
(while (> count 0)
873855
(re-search-forward regexp bound)
874856
(setq parse (syntax-ppss))
@@ -883,22 +865,15 @@ point at BOB."
883865
((or (nth 4 parse)
884866
(and (eq (char-before) ?\/) (eq (char-after) ?\*)))
885867
(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))
890868
(t
891869
(setq count (1- count))))))
892870
(point))
893871

894872

895873
(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.
897875
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."
902877
(let ((saved-point (point))
903878
(search-expr
904879
(cond ((null count)
@@ -917,11 +892,7 @@ macro as normal text."
917892

918893
(defun typescript--re-search-backward-inner (regexp &optional bound count)
919894
"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))
925896
(while (> count 0)
926897
(re-search-backward regexp bound)
927898
(when (and (> (point) (point-min))
@@ -935,22 +906,16 @@ macro as normal text."
935906
(goto-char (nth 8 parse)))
936907
((and (eq (char-before) ?/) (eq (char-after) ?*))
937908
(re-search-backward "/\\*"))
938-
((and (not (and orig-macro-start
939-
(>= (point) orig-macro-start)))
940-
(typescript--beginning-of-macro)))
941909
(t
942910
(setq count (1- count))))))
943911
(point))
944912

945913

946914
(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.
948916
949917
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.
954919
955920
IMPORTANT NOTE: searching for \"\\n\" with this function to find
956921
line breaks will generally not work, because the final newline of
@@ -1340,21 +1305,6 @@ LIMIT defaults to point."
13401305
name
13411306
(typescript--split-name name))))
13421307

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-
13581308
;; "Prototype function" declaration
13591309
((looking-at typescript--plain-method-re)
13601310
(goto-char (match-beginning 3))
@@ -1465,30 +1415,13 @@ LIMIT defaults to point."
14651415

14661416
(t (typescript--end-of-defun-nested)))))))
14671417

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-
14821418
(defun typescript--backward-syntactic-ws (&optional lim)
14831419
"Simple implementation of `c-backward-syntactic-ws' for `typescript-mode'."
14841420
(save-restriction
14851421
(when lim (narrow-to-region lim (point-max)))
14861422

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)
14921425
(/= (point)
14931426
(prog1
14941427
pos
@@ -1501,8 +1434,6 @@ LIMIT defaults to point."
15011434
(let ((pos (point)))
15021435
(while (progn
15031436
(forward-comment most-positive-fixnum)
1504-
(when (eq (char-after) ?#)
1505-
(c-end-of-macro))
15061437
(/= (point)
15071438
(prog1
15081439
pos
@@ -1746,13 +1677,6 @@ and searches for the next token to be highlighted."
17461677

17471678
(defconst typescript--font-lock-keywords-3
17481679
`(
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-
17561680
,@typescript--font-lock-keywords-2
17571681

17581682
(typescript--jsdoc-param-matcher (1 'typescript-jsdoc-tag t t)
@@ -2331,7 +2255,6 @@ moved on success."
23312255
((nth 8 parse-status) 0) ; inside string
23322256
((typescript--ctrl-statement-indentation))
23332257
((eq (char-after) ?#) 0)
2334-
((save-excursion (typescript--beginning-of-macro)) 4)
23352258
((nth 1 parse-status)
23362259
(let ((same-indent-p (looking-at "[]})]"))
23372260
(switch-keyword-p (looking-at "\\_<default\\_>\\|\\_<case\\_>[^:]"))
@@ -2407,10 +2330,7 @@ moved on success."
24072330
(typescript--forward-syntactic-ws limit)))
24082331
((symbol-function 'c-backward-sws)
24092332
(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))))
24142334
(let ((fill-paragraph-function 'c-fill-paragraph))
24152335
(c-fill-paragraph justify))))
24162336

0 commit comments

Comments
 (0)