swift-emacs / swift-mode

Emacs support for Apple's Swift programming language.
GNU General Public License v3.0
363 stars 47 forks source link

Add support for font-lock-negation-char-face #170

Closed danielmartin closed 3 years ago

danielmartin commented 3 years ago

Emacs can show negation characters using a specific face in font-lock. This commit adds support for it in swift-mode.

Screen Shot 2020-11-21 at 10 08 07 PM
taku0 commented 3 years ago

It's very attractive. I see some minor cases are missing:

// should be highlighted; OK
if !foo {}
if !!!!!foo {}
if !!!!!(foo) {}
if (!foo) {}
let x = [!a,!b]
let x = [a:!b]

// should not be highlighted; Some cases are missing
try! foo
foo as! Foo
foo != bar
foo !== bar
a.b.c!
a.b.c_!
a.b.aあ!
init! {}
let foo: Foo! = bar
let x = foo()! // NG
let x = foo[0]! // NG

// identifiers can be quoted
a.b.`c`! // NG

// custom operator
foo +!+!+!+!+ bbb // NG

How about "\\(?:^\\|\\s-\\|\\s(\\|\\s>\\|[,:;]\\)\\(!+\\)[^=]"? That is:

danielmartin commented 3 years ago

@taku0 Thanks for the feedback, I've applied your suggestion. I've also added some font-lock tests to avoid regressions.

taku0 commented 3 years ago

Tests for font-locking is a long-awaited feature. It works perfectly on all versions non-interactively and interactively. Thank you.