Skip to content

Commit 5532b19

Browse files
committed
font-lock: highlight "foreign import" if no further text
Prior to this commit a valid code like foreign import foo wasn't getting correctly highlighted. This fixes it. While doing so, we also remove all the ccall/stdcall/etc stuff, which is a legacy from haskell-mode and doesn't exist in purescript.
1 parent 817083f commit 5532b19

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

purescript-font-lock.el

+3-6
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,10 @@ Returns keywords suitable for `font-lock-keywords'."
223223
(4 (symbol-value 'purescript-keyword-face) nil lax))
224224

225225
(,reservedsym 1 (symbol-value 'purescript-operator-face))
226-
;; Special case for `foreign import'
227-
;; keywords in foreign import statements but are not otherwise reserved.
228-
("\\<\\(foreign\\)[ \t]+\\(import\\)[ \t]+\\(?:\\(ccall\\|stdcall\\|cplusplus\\|jvm\\|dotnet\\)[ \t]+\\)?\\(?:\\(safe\\|unsafe\\|interruptible\\)[ \t]+\\)?"
226+
;; Case for `foreign import'
227+
("\\<\\(foreign\\)[ \t]+\\(import\\>\\)"
229228
(1 (symbol-value 'purescript-keyword-face) nil lax)
230-
(2 (symbol-value 'purescript-keyword-face) nil lax)
231-
(3 (symbol-value 'purescript-keyword-face) nil lax)
232-
(4 (symbol-value 'purescript-keyword-face) nil lax))
229+
(2 (symbol-value 'purescript-keyword-face) nil lax))
233230

234231
(,reservedsym 1 (symbol-value 'purescript-operator-face))
235232
;; Special case for `foreign export'

tests/purescript-font-lock-tests.el

+46
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,49 @@ derive newtype instance foldableNonEmptyList :: Foldable NonEmptyList
303303
(449 450 font-lock-variable-name-face) (451 451 nil)
304304
(452 459 font-lock-type-face) (460 460 nil)
305305
(461 472 font-lock-type-face) (473 473 nil))))
306+
307+
(ert-deftest foreign-imports ()
308+
(purescript-test-ranges
309+
"foreign import func2 :: Effect Int
310+
foreign import func3
311+
:: Effect Int
312+
foreign import
313+
func4 :: Effect Int
314+
foreign import func5 -- invalid indentation, but allowed in other context
315+
"
316+
'((1 7 font-lock-keyword-face)
317+
(8 8 nil)
318+
(9 14 font-lock-keyword-face)
319+
(15 21 nil)
320+
(22 23 font-lock-variable-name-face)
321+
(24 24 nil)
322+
(25 30 font-lock-type-face)
323+
(31 31 nil)
324+
(32 34 font-lock-type-face)
325+
(35 35 nil)
326+
(36 42 font-lock-keyword-face)
327+
(43 43 nil)
328+
(44 49 font-lock-keyword-face)
329+
(50 58 nil)
330+
(59 60 font-lock-variable-name-face)
331+
(61 61 nil)
332+
(62 67 font-lock-type-face)
333+
(68 68 nil)
334+
(69 71 font-lock-type-face)
335+
(72 72 nil)
336+
(73 79 font-lock-keyword-face)
337+
(80 80 nil)
338+
(81 86 font-lock-keyword-face)
339+
(87 95 nil)
340+
(96 97 font-lock-variable-name-face)
341+
(98 98 nil)
342+
(99 104 font-lock-type-face)
343+
(105 105 nil)
344+
(106 108 font-lock-type-face)
345+
(109 111 nil)
346+
(112 118 font-lock-keyword-face)
347+
(119 119 nil)
348+
(120 125 font-lock-keyword-face)
349+
(126 132 nil)
350+
(133 135 font-lock-comment-delimiter-face)
351+
(136 185 font-lock-comment-face))))

0 commit comments

Comments
 (0)