[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/go-mode 7248358 462/495: Fontify type names in type switch
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/go-mode 7248358 462/495: Fontify type names in type switch statements |
Date: |
Sat, 7 Aug 2021 09:06:09 -0400 (EDT) |
branch: elpa/go-mode
commit 7248358f987965070b1a15143fa4e2965a2128ad
Author: Muir Manders <muir@mnd.rs>
Commit: Peter Sanford <psanford@sanford.io>
Fontify type names in type switch statements
Now we fontify type names in the "case" clauses of type switch
statements.
---
go-mode.el | 43 +++++++++++++++++++++++++++++++++++++++++++
test/go-font-lock-test.el | 13 +++++++++++++
2 files changed, 56 insertions(+)
diff --git a/go-mode.el b/go-mode.el
index 14fa2d4..a58c091 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -425,6 +425,10 @@ For mode=set, all covered lines will have this weight."
,@(mapcar (lambda (x) `(,x font-lock-type-face))
(number-sequence 1 go--font-lock-func-param-num-groups)))
+ (go--match-type-switch-case
+ ,@(mapcar (lambda (x) `(,x font-lock-type-face))
+ (number-sequence 1 go--font-lock-func-param-num-groups)))
+
;; Fontify types in e.g. "var foo string".
(go--match-ident-type-pair 1 font-lock-type-face)
@@ -676,6 +680,18 @@ case keyword. It returns nil for the case line itself."
(skip-syntax-backward " ")
(looking-back "interface" (- (point) 9)))))
+(defun go--in-type-switch-p ()
+ "Return non-nil if point is inside a type switch statement."
+ (save-excursion
+ (and
+ ;; inside curlies
+ (go-goto-opening-parenthesis)
+ (eq (char-after) ?{)
+
+ ;; ".(type)" appears before opening curly
+ (progn (skip-syntax-backward " ") t)
+ (looking-back "\\.(type)" (- (point) 7)))))
+
(defun go--fill-prefix ()
"Return fill prefix for following comment paragraph."
(save-excursion
@@ -1323,6 +1339,33 @@ declaration. Return non-nil if search succeeds."
found-match))
+(defun go--match-type-switch-case (end)
+ "Search for \"case\" clauses of type switch statements.
+
+In type switch statements, each case contains one or more type
+names. Here we find the next case clause and turn its items into
+the corresponding match data. Return non-nil if search succeeds."
+ (let (found-match)
+ (while (and
+ (not found-match)
+
+ ;; Search for "case" statements.
+ (re-search-forward "^[[:space:]]*case " end t))
+
+ ;; Make sure we are in a type switch statement.
+ (when (go--in-type-switch-p)
+ (let (type-names)
+ ;; Loop over each comma separated item in the case.
+ (while (looking-at (concat "[[:space:]\n]*" go-type-name-regexp
"[[:space:]]*,?"))
+ (setq type-names (nconc type-names (list (match-beginning 1)
(match-end 1))))
+ (goto-char (match-end 0)))
+
+ (setq type-names (go--filter-match-data type-names end))
+ (when type-names
+ (set-match-data (go--make-match-data type-names))
+ (setq found-match t)))))
+ found-match))
+
(defun go--match-ident-type-pair (end)
"Search for identifier + type-name pairs.
diff --git a/test/go-font-lock-test.el b/test/go-font-lock-test.el
index 1423e65..ecbba92 100644
--- a/test/go-font-lock-test.el
+++ b/test/go-font-lock-test.el
@@ -66,6 +66,19 @@ KmapK[TstringT]KinterfaceK{}{
S`foo`S: foo.FbarF(baz),
}"))
+
+(ert-deftest go--fontify-type-switch ()
+ (should-fontify "
+KswitchK foo.(KtypeK) {
+KcaseK TstringT, *Tfoo.ZebraT, [2]TbyteT:
+}")
+
+ (should-fontify "
+KswitchK 123 {
+KcaseK string:
+}"))
+
+
(defun should-fontify (contents)
"Verify fontification.
- [nongnu] elpa/go-mode fdc1545 436/495: Fix indent for case statement comments, (continued)
- [nongnu] elpa/go-mode fdc1545 436/495: Fix indent for case statement comments, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode d387378 438/495: indent: handle comments after multiline case lists, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode fbf2544 444/495: Improve fill-paragraph for comment blocks., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode e7e0157 447/495: indent: fix indent at top level of file, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 3bc7479 450/495: Fix infinite loop in fill-region, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 88ffc9e 452/495: Add github action yaml file to run ert tests, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 4f15abf 449/495: Fix fill-paragraph for certain block comments., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode a13b814 448/495: Add option to reuse a single buffer for godoc, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode a82369b 453/495: Readme: add basic information about gopls., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 839190b 455/495: Run all tests in GH CI, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 7248358 462/495: Fontify type names in type switch statements,
ELPA Syncer <=
- [nongnu] elpa/go-mode 4fabba6 464/495: Small fix for fontification of array types, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 656590a 463/495: Fontify qualified composite literal types., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode d304565 474/495: Fix signature fontification after comments., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode e9b9c0e 473/495: Add some fontification faces for go-dot-mod-mode., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 4acf733 468/495: Fully fontify type and const decls., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode dac200f 469/495: Fix font locking in nested signatures., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode fa2162b 475/495: Fix "nil" fontification in type switch clause., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 7ce031c 481/495: Allow disabling variable font locking., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode e10d677 478/495: indent: fix func literals in dangling lines, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode c9f5e92 483/495: Fix indentation of chained dangling selectors., ELPA Syncer, 2021/08/07