|
32 | 32 |
|
33 | 33 | ;;; Code: |
34 | 34 |
|
35 | | -(defun swift-mode:function-name-pos-p (pos) |
36 | | - "Return t if POS is at just before function name." |
| 35 | +(defun swift-mode:expr-pos-p (pos expr) |
| 36 | + "Return t if POS is just before the given expression." |
37 | 37 | (save-excursion |
38 | 38 | (save-match-data |
39 | 39 | (goto-char pos) |
40 | 40 | (forward-comment (- (point))) |
41 | 41 | (skip-syntax-backward "w_") |
42 | | - (looking-at "\\<\\(func\\|enum\\|struct\\|class\\|protocol\\|extension\\)\\>")))) |
| 42 | + (funcall expr)))) |
| 43 | + |
| 44 | +(defun swift-mode:function-name-pos-p (pos) |
| 45 | + "Return t if POS is just before a function name." |
| 46 | + (swift-mode:expr-pos-p |
| 47 | + pos |
| 48 | + (lambda () |
| 49 | + (progn |
| 50 | + (skip-syntax-backward "w_") |
| 51 | + (looking-at "\\<\\(func\\|enum\\|struct\\|class\\|protocol\\|extension\\)\\>"))))) |
| 52 | + |
| 53 | +(defun swift-mode:property-call-pos-p (pos) |
| 54 | + "Return t if POS is just before a property call." |
| 55 | + (swift-mode:expr-pos-p |
| 56 | + pos |
| 57 | + (lambda () |
| 58 | + (progn |
| 59 | + (skip-syntax-backward "w_") |
| 60 | + (skip-syntax-backward ".") |
| 61 | + (looking-at "\\.\\s-*\\(\\<[^[:digit:]][_[:alnum:]]*?\\)\\b\\s-*[^(]"))))) |
| 62 | + |
| 63 | +(defun swift-mode:font-lock-match-expr (limit fn) |
| 64 | + "Return t if POS is just before the given keyword expression." |
| 65 | + (and |
| 66 | + (< (point) limit) |
| 67 | + (re-search-forward "\\<\\(\\sw\\|\\s_\\)+\\>" limit t) |
| 68 | + (or |
| 69 | + (funcall fn (match-beginning 0)) |
| 70 | + (swift-mode:font-lock-match-expr limit fn)))) |
43 | 71 |
|
44 | 72 | (defun swift-mode:font-lock-match-function-names (limit) |
45 | 73 | "Move the cursor just after a function name or others. |
46 | 74 |
|
47 | 75 | Others includes enum, struct, class, protocol name. |
48 | 76 | Set `match-data', and return t if a function name found before position LIMIT. |
49 | 77 | Return nil otherwise." |
50 | | - (and |
51 | | - (< (point) limit) |
52 | | - (re-search-forward "\\<\\(\\sw\\|\\s_\\)+\\>" limit t) |
53 | | - (or |
54 | | - (swift-mode:function-name-pos-p (match-beginning 0)) |
55 | | - (swift-mode:font-lock-match-function-names limit)))) |
| 78 | + (swift-mode:font-lock-match-expr limit #'swift-mode:function-name-pos-p)) |
| 79 | + |
| 80 | +(defun swift-mode:font-lock-match-property-calls (limit) |
| 81 | + "Move the cursor just after a property call." |
| 82 | + (swift-mode:font-lock-match-expr limit #'swift-mode:property-call-pos-p)) |
56 | 83 |
|
57 | 84 | ;; Keywords |
58 | 85 | ;; 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") |
382 | 409 | . |
383 | 410 | font-lock-builtin-face) |
384 | 411 |
|
385 | | - (swift-mode:font-lock-match-function-names . font-lock-function-name-face)) |
| 412 | + ;; Method/function calls |
| 413 | + ( |
| 414 | + "\\b\\(\\<[^[:digit:]][_[:alnum:]]*?\\)\\b\\s-*(" |
| 415 | + 1 |
| 416 | + font-lock-function-name-face |
| 417 | + ) |
| 418 | + |
| 419 | + ;; Function declarations |
| 420 | + (swift-mode:font-lock-match-function-names . font-lock-function-name-face) |
| 421 | + |
| 422 | + ;; Property calls |
| 423 | + (swift-mode:font-lock-match-property-calls . font-lock-variable-name-face)) |
386 | 424 | "Swift mode keywords for Font Lock.") |
387 | 425 |
|
388 | 426 |
|
|
0 commit comments