emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/swift-mode cbb19f2 003/496: Add basic font-locking


From: ELPA Syncer
Subject: [nongnu] elpa/swift-mode cbb19f2 003/496: Add basic font-locking
Date: Sun, 29 Aug 2021 11:32:56 -0400 (EDT)

branch: elpa/swift-mode
commit cbb19f29dcdacfceef802391f1147d4f581e5798
Author: Chris Barrett <chris.d.barrett@me.com>
Commit: Chris Barrett <chris.d.barrett@me.com>

    Add basic font-locking
---
 swift-mode.el | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/swift-mode.el b/swift-mode.el
index 7afe58b..40de349 100644
--- a/swift-mode.el
+++ b/swift-mode.el
@@ -26,7 +26,80 @@
 
 ;;; Code:
 
+(require 'dash)
+(require 'rx)
 
+;; Font lock.
+
+(defvar swift-mode--declaration-keywords
+  '("class" "deinit" "enum" "extension" "func" "import" "init" "let"
+    "protocol" "static" "struct" "subscript" "typealias" "var"))
+
+(defvar swift-mode--statment-keywords
+  '("break" "case" "continue" "default" "do" "else" "fallthrough"
+    "if" "in" "for" "return" "switch" "where" "while"))
+
+(defvar swift-mode--expression-keywords
+  '("as" "dynamicType" "is" "new" "super" "self" "Self" "Type"
+    "__COLUMN__" "__FILE__" "__FUNCTION__" "__LINE__"))
+
+(defvar swift-mode--contextual-keywords
+  '("associativity" "didSet" "get" "infix" "inout" "left" "mutating" "none"
+    "nonmutating" "operator" "override" "postfix" "precedence" "prefix" "right"
+    "set" "unowned" "unowned(safe)" "unowned(unsafe)" "weak" "willSet"))
+
+(defvar swift-mode--keywords
+  (-flatten (list swift-mode--declaration-keywords
+                  swift-mode--statment-keywords
+                  swift-mode--expression-keywords
+                  swift-mode--contextual-keywords))
+  "Keywords used in the Swift language.")
+
+(defvar swift-mode--font-lock-defaults
+  (list
+   (list
+
+    ;; Keywords
+    ;;
+    ;; Swift allows reserved words to be used as identifiers when enclosed
+    ;; with backticks, in which case they should be highlighted as
+    ;; identifiers, not keywords.
+    (cons
+     (rx-to-string `(and (or bol (not (any "`"))) bow
+                         (group (or ,@swift-mode--keywords))
+                         eow)
+                   t)
+     1)
+
+    ;; Types
+    ;;
+    ;; Any token beginning with an uppercase character is highlighted as a
+    ;; type.
+    (cons (rx bow upper (+ word) eow)
+          font-lock-type-face)
+
+    ;; Function names
+    ;;
+    ;; Any string beginning after the `func' keyword is highlighted as a
+    ;; function name.
+    (cons (rx bow "func" eow (+ space) (group bow (+ word) eow))
+          (list 1 font-lock-function-name-face)))
+   )
+  "Font lock values for `swift-mode'.")
+
+;; Mode definition.
+
+(defvar swift-mode-map
+  (let ((map (make-sparse-keymap)))
+    map)
+  "Keymap used in `swift-mode'.")
+
+(define-derived-mode swift-mode prog-mode "Swift"
+  "Major mode for Apple's Swift programming language.
+
+\\<swift-mode-map>"
+  :group 'swift
+  (setq-local font-lock-defaults swift-mode--font-lock-defaults))
 
 (provide 'swift-mode)
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]