emacs-elpa-diffs
[Top][All Lists]
Advanced

[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:
 }")
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]