[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)
- [nongnu] elpa/swift-mode e90cf5e 012/496: Set comment vars, (continued)
- [nongnu] elpa/swift-mode e90cf5e 012/496: Set comment vars, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode f39c05b 013/496: Tweak comment syntax, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 592a33f 021/496: Copy syntax table from rust-mode., ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 142c7db 023/496: Merge pull request #7 from syohex/fix-for-older-emacs, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 90802b5 041/496: Use lexical scoping, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 8641ebc 048/496: Mention old-school installation method, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 8e72839 004/496: Add basic syntax table, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 5274877 010/496: Add single-line comments to syntax table, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode d110515 011/496: Font lock tweaks, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 272473b 005/496: Remove currently unused mode map, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode cbb19f2 003/496: Add basic font-locking,
ELPA Syncer <=
- [nongnu] elpa/swift-mode 7df8b6d 037/496: Remove dash.el dependency., ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 09b50fa 042/496: [Fix #12] Merge mode code in a single file, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode c882c70 053/496: Replace `if` exprs with `when` exprs, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode d136303 076/496: Adding support for Swift REPL via comint-mode, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 286c4b8 077/496: Merge pull request #21 from ap4y/feature_repl, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode e0fba71 083/496: repl -> REPL, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 48cbf55 088/496: Extend a bit installation instructions for package.el, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 7e77211 087/496: Remove redundant autoload, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode a092adc 091/496: Return default paragraph definitions., ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode c9c1271 089/496: Make flycheck work with multiple sources, ELPA Syncer, 2021/08/29