[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/swift-mode abf3426 392/496: Add support for highlighting f
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/swift-mode abf3426 392/496: Add support for highlighting function calls / properties / enum cases |
Date: |
Sun, 29 Aug 2021 11:34:13 -0400 (EDT) |
branch: elpa/swift-mode
commit abf34260ef0bb98a54c15e1a834d3ce56bfdb6ef
Author: Michael Sanders <michael.sanders@fastmail.com>
Commit: taku0 <mxxouy6x3m_github@tatapa.org>
Add support for highlighting function calls / properties / enum cases
---
swift-mode-font-lock.el | 58 ++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 48 insertions(+), 10 deletions(-)
diff --git a/swift-mode-font-lock.el b/swift-mode-font-lock.el
index 4beea33..2f37be8 100644
--- a/swift-mode-font-lock.el
+++ b/swift-mode-font-lock.el
@@ -32,14 +32,42 @@
;;; Code:
-(defun swift-mode:function-name-pos-p (pos)
- "Return t if POS is at just before function name."
+(defun swift-mode:expr-pos-p (pos expr)
+ "Return t if POS is just before the given expression."
(save-excursion
(save-match-data
(goto-char pos)
(forward-comment (- (point)))
(skip-syntax-backward "w_")
- (looking-at
"\\<\\(func\\|enum\\|struct\\|class\\|protocol\\|extension\\)\\>"))))
+ (funcall expr))))
+
+(defun swift-mode:function-name-pos-p (pos)
+ "Return t if POS is just before a function name."
+ (swift-mode:expr-pos-p
+ pos
+ (lambda ()
+ (progn
+ (skip-syntax-backward "w_")
+ (looking-at
"\\<\\(func\\|enum\\|struct\\|class\\|protocol\\|extension\\)\\>")))))
+
+(defun swift-mode:property-call-pos-p (pos)
+ "Return t if POS is just before a property call."
+ (swift-mode:expr-pos-p
+ pos
+ (lambda ()
+ (progn
+ (skip-syntax-backward "w_")
+ (skip-syntax-backward ".")
+ (looking-at
"\\.\\s-*\\(\\<[^[:digit:]][_[:alnum:]]*?\\)\\b\\s-*[^(]")))))
+
+(defun swift-mode:font-lock-match-expr (limit fn)
+ "Return t if POS is just before the given keyword expression."
+ (and
+ (< (point) limit)
+ (re-search-forward "\\<\\(\\sw\\|\\s_\\)+\\>" limit t)
+ (or
+ (funcall fn (match-beginning 0))
+ (swift-mode:font-lock-match-expr limit fn))))
(defun swift-mode:font-lock-match-function-names (limit)
"Move the cursor just after a function name or others.
@@ -47,12 +75,11 @@
Others includes enum, struct, class, protocol name.
Set `match-data', and return t if a function name found before position LIMIT.
Return nil otherwise."
- (and
- (< (point) limit)
- (re-search-forward "\\<\\(\\sw\\|\\s_\\)+\\>" limit t)
- (or
- (swift-mode:function-name-pos-p (match-beginning 0))
- (swift-mode:font-lock-match-function-names limit))))
+ (swift-mode:font-lock-match-expr limit #'swift-mode:function-name-pos-p))
+
+(defun swift-mode:font-lock-match-property-calls (limit)
+ "Move the cursor just after a property call."
+ (swift-mode:font-lock-match-expr limit #'swift-mode:property-call-pos-p))
;; Keywords
;;
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/LexicalStructure.html#//apple_ref/doc/uid/TP40014097-CH30-ID410
@@ -382,7 +409,18 @@ between these and the properties")
.
font-lock-builtin-face)
- (swift-mode:font-lock-match-function-names . font-lock-function-name-face))
+ ;; Method/function calls
+ (
+ "\\b\\(\\<[^[:digit:]][_[:alnum:]]*?\\)\\b\\s-*\\??\\s-*("
+ 1
+ font-lock-function-name-face
+ )
+
+ ;; Function declarations
+ (swift-mode:font-lock-match-function-names . font-lock-function-name-face)
+
+ ;; Property calls
+ (swift-mode:font-lock-match-property-calls . font-lock-variable-name-face))
"Swift mode keywords for Font Lock.")
- [nongnu] elpa/swift-mode 2cd111f 351/496: Fix indentation of multiline strings, (continued)
- [nongnu] elpa/swift-mode 2cd111f 351/496: Fix indentation of multiline strings, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 3bcdf32 353/496: Add more keywords with number sign, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 030b1b8 356/496: Update documentations and wordings, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode d68af3c 365/496: Update copyright, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 359efc0 379/496: Fix indentation of function parameter clauses, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 25944c2 378/496: Add test for beginning/end-of-defun, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode ea029a0 370/496: Suppress implicit semicolons inside interpolated expressions, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode b5602c1 375/496: Add beginning/end-of-sentence to README.md, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 18c3dc4 376/496: Bump version to 4.0.0, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 27e959e 385/496: Handle unmatched parens correctly, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode abf3426 392/496: Add support for highlighting function calls / properties / enum cases,
ELPA Syncer <=
- [nongnu] elpa/swift-mode 560242d 393/496: Add support for choosing scheme when building/running iOS projects, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode c56f43c 395/496: Make faces customizable, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 6d4fab5 396/496: Move customizations for REPL to their own group, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 604610d 399/496: Fix LLDB breakpoint option, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 6fdb3cd 403/496: Fix `swift-mode:debug-swift-module`, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode d2f2f1d 410/496: Bump version to 6.0.0, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode f847923 419/496: Highlight more compiler directives, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 0b1e5e8 420/496: Support raw texts, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 348e153 422/496: Change buffer name of REPL, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 0eca818 431/496: Add test for Imenu, ELPA Syncer, 2021/08/29