[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/go-mode e8eea7f 487/495: Fix fontification of multiline ty
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/go-mode e8eea7f 487/495: Fix fontification of multiline type switch clauses. |
Date: |
Sat, 7 Aug 2021 09:06:15 -0400 (EDT) |
branch: elpa/go-mode
commit e8eea7f251af35e10ea0bab129c60fb75aa8a61c
Author: Muir Manders <muir@mnd.rs>
Commit: Peter Sanford <psanford@sanford.io>
Fix fontification of multiline type switch clauses.
Now we properly fontify "foo" and "bar" in:
switch v.(type) {
case foo,
bar:
}
I also tried to be careful so comments don't mess things up.
Closes: #355 [via git-merge-pr]
---
go-mode.el | 22 ++++++++++++++++++++--
test/go-font-lock-test.el | 4 ++++
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/go-mode.el b/go-mode.el
index ff041cd..ff39281 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -410,6 +410,20 @@ For mode=set, all covered lines will have this weight."
(defvar go--default-face 'default
"A variable to refer to `default' face for use in font lock rules.")
+(defun go--fontify-type-switch-case-pre ()
+ "Move point to line following the end of case statement.
+
+This is used as an anchored font lock keyword PRE-MATCH-FORM. We
+expand the font lock region to include multiline type switch case
+statements."
+ (save-excursion
+ (beginning-of-line)
+ (while (or (looking-at "[[:space:]]*\\($\\|//\\)") (go--line-suffix-p ","))
+ (forward-line))
+ (when (go--line-suffix-p ":")
+ (forward-line))
+ (point)))
+
(defun go--build-font-lock-keywords ()
;; we cannot use 'symbols in regexp-opt because GNU Emacs <24
;; doesn't understand that
@@ -440,7 +454,11 @@ For mode=set, all covered lines will have this weight."
(go--match-ident-type-pair 2 font-lock-type-face)
;; An anchored matcher for type switch case clauses.
- (go--match-type-switch-case (go--fontify-type-switch-case nil nil (1
font-lock-type-face)))
+ (go--match-type-switch-case
+ (go--fontify-type-switch-case
+ (go--fontify-type-switch-case-pre)
+ nil
+ (1 font-lock-type-face)))
;; Match variable names in var decls, constant names in const
;; decls, and type names in type decls.
@@ -1467,7 +1485,7 @@ comma, it stops at it. Return non-nil if comma was found."
;; Loop until we find a match because we must skip types we don't
;; handle, such as "interface { foo() }".
(while (and (not found-match) (not done))
- (when (looking-at (concat "[[:space:]\n]*" go-type-name-regexp
"[[:space:]]*[,:]"))
+ (when (looking-at (concat "\\(?:[[:space:]]*\\|//.*\\|\n\\)*"
go-type-name-regexp "[[:space:]]*[,:]"))
(goto-char (match-end 1))
(unless (member (match-string 1) go-constants)
(setq found-match t)))
diff --git a/test/go-font-lock-test.el b/test/go-font-lock-test.el
index e2498ee..7f739c1 100644
--- a/test/go-font-lock-test.el
+++ b/test/go-font-lock-test.el
@@ -77,6 +77,10 @@ KmapK[TstringT]KinterfaceK{}{
KswitchK foo.(KtypeK) {
KcaseK TstringT, *Tfoo.ZebraT, [2]TbyteT:
KcaseK CnilC:
+KcaseK TfooT, TbarT, D// DQhi
+Q
+ D// DQthere
+Q TbazT, TquxT:
KdefaultK:
}")
- [nongnu] elpa/go-mode 656590a 463/495: Fontify qualified composite literal types., (continued)
- [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
- [nongnu] elpa/go-mode fdf46fe 492/495: Fix go.mod fontification., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode e8eea7f 487/495: Fix fontification of multiline type switch clauses.,
ELPA Syncer <=
- [nongnu] elpa/go-mode 2f2910c 223/495: fix end-of-defun for function with inline struct/interface arguments, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode f1adac0 230/495: switch versioning to semver, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode d9f0bee 232/495: add variable to customize godef command, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 3da268f 285/495: README: improve description of new functions, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 9047fcd 238/495: add a menu, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 466e188 239/495: add `go-play-browse-function', ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 8c13a82 240/495: match identifiers, not type names, when highlighting struct literal, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 775c77a 241/495: immediately store match data in go-unused-imports-lines, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode aaea941 242/495: bump version to 1.2.0, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode bf4a097 243/495: add Iwasaki Yudai to AUTHORS, ELPA Syncer, 2021/08/07