Skip to content

Commit 0d11408

Browse files
committed
Support the nullable pipe operator |?>
1 parent 91060a1 commit 0d11408

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

hack-mode.el

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,19 +238,22 @@ E.g. Foo<int> has a paired delimiter, 1 > 2 does not."
238238
(when (> pos (1+ (point-min)))
239239
(let* ((prev-prev-char (char-before (1- pos)))
240240
(prev-char (char-before pos))
241-
(next-char (or (char-after (1+ pos)) ""))
241+
(next-char (or (char-after (1+ pos)) ""))
242242

243243
;; We look at a small amount of context to decide what
244244
;; syntax we're looking at.
245-
(context-1-before (hack--join-chars prev-char ?>))
245+
(context-1-before (hack--join-chars prev-char ?>))
246246
(context-1-after (hack--join-chars ?> next-char))
247247
(context-1-around (hack--join-chars prev-char ?> next-char))
248+
(context-2-before (hack--join-chars prev-prev-char prev-char ?>))
248249
(context-2-before-1-after
249250
(hack--join-chars prev-prev-char prev-char ?> next-char)))
250251
(not
251252
(or
252-
;; foo() |> bar($$)
253-
(string= context-1-before "|>")
253+
;; foo() |> bar($$)
254+
(string= context-1-before "|>")
255+
;; foo() |?> bar ($$)
256+
(string= context-2-before "|?>")
254257
;; If there's a preceding space, we assume it's 1 > 2 rather
255258
;; than vec < int > with excess space.
256259
(string= context-1-around " > ")
@@ -1610,7 +1613,7 @@ Repeated parens on the same line are consider a single paren."
16101613
(or "*" "/" "%" "+" "-" "."
16111614
"<<" ">>" "<" "<=" ">" ">="
16121615
"==" "!=" "===" "!==" "<=>"
1613-
"&" "^" "|" "&&" "||" "?:" "??" "|>"
1616+
"&" "^" "|" "&&" "||" "?:" "??" "|>" "|?>"
16141617
"=" "+=" "-=" ".=" "*=" "/=" "%=" "<<=" ">>=" "&=" "^=" "|="
16151618
"is" "as" "?as")
16161619
(0+ space)
@@ -1713,7 +1716,8 @@ Preserves point position in the line where possible."
17131716
;; ->bar(); <- this line
17141717
(when (or (s-starts-with-p "->" current-line)
17151718
(s-starts-with-p "?->" current-line)
1716-
(s-starts-with-p "|>" current-line))
1719+
(s-starts-with-p "|>" current-line)
1720+
(s-starts-with-p "|?>" current-line))
17171721
(setq paren-depth (1+ paren-depth))))
17181722

17191723
;; Inside switch statements.

0 commit comments

Comments
 (0)