Skip to content

Commit c56f43c

Browse files
committed
Make faces customizable
1 parent dba539e commit c56f43c

File tree

1 file changed

+124
-22
lines changed

1 file changed

+124
-22
lines changed

swift-mode-font-lock.el

Lines changed: 124 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,95 @@
3232

3333
;;; Code:
3434

35+
;;; Customizations
36+
37+
;;;###autoload
38+
(defgroup swift-mode:faces nil
39+
"Font faces."
40+
:group 'swift)
41+
42+
(defface swift-mode:constant-keyword-face
43+
'((t . (:inherit font-lock-constant-face)))
44+
"Face for highlighting constant keywords
45+
46+
That is, true, false, and nil."
47+
:group 'swift-mode:faces)
48+
49+
(defface swift-mode:preprocessor-keyword-face
50+
'((t . (:inherit font-lock-preprocessor-face)))
51+
"Face for highlighting preprocessor keywords.
52+
53+
Exmpale: #if, #endif, and #selector."
54+
:group 'swift-mode:faces)
55+
56+
(defface swift-mode:keyword-face
57+
'((t . (:inherit font-lock-keyword-face)))
58+
"Face for highlighting keywords."
59+
:group 'swift-mode:faces)
60+
61+
(defface swift-mode:builtin-method-trailing-closure-face
62+
'((t . (:inherit font-lock-builtin-face)))
63+
"Face for highlighting builtin methods with trailing closure."
64+
:group 'swift-mode:faces)
65+
66+
(defface swift-mode:builtin-method-face
67+
'((t . (:inherit font-lock-builtin-face)))
68+
"Face for highlighting builtin methods."
69+
:group 'swift-mode:faces)
70+
71+
(defface swift-mode:builtin-function-trailing-closure-face
72+
'((t . (:inherit font-lock-builtin-face)))
73+
"Face for highlighting builtin functions with trailing closure."
74+
:group 'swift-mode:faces)
75+
76+
(defface swift-mode:builtin-function-face
77+
'((t . (:inherit font-lock-builtin-face)))
78+
"Face for highlighting builtin functions."
79+
:group 'swift-mode:faces)
80+
81+
(defface swift-mode:builtin-propertie-face
82+
'((t . (:inherit font-lock-builtin-face)))
83+
"Face for highlighting builtin properties."
84+
:group 'swift-mode:faces)
85+
86+
(defface swift-mode:builtin-enum-case-face
87+
'((t . (:inherit font-lock-builtin-face)))
88+
"Face for highlighting builtin enum cases."
89+
:group 'swift-mode:faces)
90+
91+
(defface swift-mode:build-config-keyword-face
92+
'((t . (:inherit font-lock-builtin-face)))
93+
"Face for highlighting build configuration keywords."
94+
:group 'swift-mode:faces)
95+
96+
(defface swift-mode:builtin-type-face
97+
'((t . (:inherit font-lock-builtin-face)))
98+
"Face for highlighting builtin types."
99+
:group 'swift-mode:faces)
100+
101+
(defface swift-mode:builtin-precedence-group-face
102+
'((t . (:inherit font-lock-builtin-face)))
103+
"Face for highlighting builtin precedence groups."
104+
:group 'swift-mode:faces)
105+
106+
(defface swift-mode:function-call-face
107+
'((t . (:inherit font-lock-function-name-face)))
108+
"Face for highlighting function calls."
109+
:group 'swift-mode:faces)
110+
111+
(defface swift-mode:function-name-face
112+
'((t . (:inherit font-lock-function-name-face)))
113+
"Face for highlighting function names."
114+
:group 'swift-mode:faces)
115+
116+
(defface swift-mode:property-access-face
117+
'((t . (:inherit font-lock-variable-name-face)))
118+
"Face for highlighting property accesses."
119+
:group 'swift-mode:faces)
120+
121+
122+
;;; Supporting functions
123+
35124
(defun swift-mode:function-name-pos-p (pos limit)
36125
"Return t if POS is just before the name of a function declaration.
37126
@@ -118,6 +207,8 @@ Set `match-data', and return t if a property access found before position LIMIT.
118207
Return nil otherwise."
119208
(swift-mode:font-lock-match-expr limit #'swift-mode:property-access-pos-p))
120209

210+
;;; Keywords and standard identifiers
211+
121212
;; Keywords
122213
;; https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/LexicalStructure.html#//apple_ref/doc/uid/TP40014097-CH30-ID410
123214

@@ -387,55 +478,64 @@ Excludes true, false, and keywords begin with a number sign.")
387478
"arm64" "iOSApplicationExtension" "OSXApplicationExtension")
388479
"Keywords for build configuration statements.")
389480

481+
;;; font-lock definition
482+
390483
(defconst swift-mode:font-lock-keywords
391484
`(
392485
;; Attributes
393486
"@\\(\\sw\\|\\s_\\)*"
394487

395488
(,(regexp-opt swift-mode:constant-keywords 'words)
396489
.
397-
font-lock-constant-face)
490+
'swift-mode:constant-keyword-face)
398491

399492
(,(regexp-opt swift-mode:preprocessor-keywords 'symbols)
400493
.
401-
font-lock-preprocessor-face)
494+
'swift-mode:preprocessor-keyword-face)
402495

403-
,(regexp-opt (append swift-mode:declaration-keywords
404-
swift-mode:statement-keywords
405-
swift-mode:expression-keywords
406-
swift-mode:context-keywords)
407-
'words)
496+
(,(regexp-opt (append swift-mode:declaration-keywords
497+
swift-mode:statement-keywords
498+
swift-mode:expression-keywords
499+
swift-mode:context-keywords)
500+
'words)
501+
.
502+
'swift-mode:keyword-face)
408503

409504
(,(concat "\\."
410505
(regexp-opt swift-mode:member-functions-trailing-closure 'words)
411506
"\\s-*[({]")
412507
1
413-
font-lock-builtin-face)
508+
'swift-mode:builtin-method-trailing-closure-face)
414509

415510
(,(concat "\\."
416511
(regexp-opt swift-mode:member-functions 'words)
417512
"\\s-*(")
418513
1
419-
font-lock-builtin-face)
514+
'swift-mode:builtin-method-face)
420515

421516
(,(concat (regexp-opt swift-mode:global-functions-trailing-closure 'words)
422517
"\\s-*[({]")
423518
1
424-
font-lock-builtin-face)
519+
'swift-mode:builtin-function-trailing-closure-face)
425520

426521
(,(concat (regexp-opt swift-mode:global-functions 'words)
427522
"\\s-*(")
428523
1
429-
font-lock-builtin-face)
524+
'swift-mode:builtin-function-face)
430525

431-
(,(concat "\\." (regexp-opt (append swift-mode:properties
432-
swift-mode:enum-cases)
433-
'words))
526+
(,(concat "\\." (regexp-opt swift-mode:properties 'words))
434527
1
435-
font-lock-builtin-face)
528+
'swift-mode:builtin-propertie-face)
436529

437-
(,(regexp-opt (append swift-mode:build-config-keywords
438-
swift-mode:class-types
530+
(,(concat "\\." (regexp-opt swift-mode:enum-cases 'words))
531+
1
532+
'swift-mode:builtin-enum-case-face)
533+
534+
(,(regexp-opt swift-mode:build-config-keywords 'words)
535+
.
536+
'swift-mode:build-config-keyword-face)
537+
538+
(,(regexp-opt (append swift-mode:class-types
439539
swift-mode:enum-types
440540
swift-mode:foundation-protocols
441541
swift-mode:foundation-structs
@@ -444,26 +544,28 @@ Excludes true, false, and keywords begin with a number sign.")
444544
swift-mode:typealiases)
445545
'words)
446546
.
447-
font-lock-builtin-face)
547+
'swift-mode:builtin-type-face)
448548

449549
(,(concat "\\<"
450550
(regexp-opt swift-mode:precedence-groups 'non-nil)
451551
"Precedence\\>")
452552
.
453-
font-lock-builtin-face)
553+
'swift-mode:builtin-precedence-group-face)
454554

455555
;; Method/function calls
456556
("\\<\\(\\(\\sw\\|\\s_\\)+\\)\\>\\??\\s-*("
457557
1
458-
font-lock-function-name-face)
558+
'swift-mode:function-call-face)
459559

460560
;; Function declarations
461-
(swift-mode:font-lock-match-function-names . font-lock-function-name-face)
561+
(swift-mode:font-lock-match-function-names
562+
.
563+
'swift-mode:function-name-face)
462564

463565
;; Property accesses
464566
(swift-mode:font-lock-match-property-accesss
465567
.
466-
font-lock-variable-name-face))
568+
'swift-mode:property-access-face))
467569
"Swift mode keywords for Font Lock.")
468570

469571

0 commit comments

Comments
 (0)