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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/go-mode 1ef3e95 476/495: Fix fontification of single line


From: ELPA Syncer
Subject: [nongnu] elpa/go-mode 1ef3e95 476/495: Fix fontification of single line composite literal.
Date: Sat, 7 Aug 2021 09:06:12 -0400 (EDT)

branch: elpa/go-mode
commit 1ef3e9552413f787fcf84d7afda029d8821706f1
Author: Muir Manders <muir@mnd.rs>
Commit: Peter Sanford <psanford@sanford.io>

    Fix fontification of single line composite literal.
    
    We previously weren't fontifying "Foo" or "Bar" in:
    
    SomeStruct{Foo: 123, Bar: 456}
    
    Closes: #327 [via git-merge-pr]
---
 go-mode.el                | 29 ++++++++++++++++++++++++++---
 test/go-font-lock-test.el | 18 +++++++++++++++++-
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/go-mode.el b/go-mode.el
index ac71cb6..f2deb61 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -487,8 +487,8 @@ For mode=set, all covered lines will have this weight."
      ;; Type assertion
      (,(concat "\\.\\s *(" go-type-name-regexp) 1 font-lock-type-face)
 
-     ;; Labels and compound literal fields
-     (,(concat "^[[:space:]]*\\(" go-label-regexp 
"\\)[[:space:]]*:\\(\\S.\\|$\\)") 1 font-lock-constant-face)
+     ;; Composite literal field names and label definitions.
+     (go--match-ident-colon 1 font-lock-constant-face)
 
      ;; Labels in goto/break/continue
      (,(concat "\\_<\\(?:goto\\|break\\|continue\\)\\_>[[:space:]]*\\(" 
go-label-regexp "\\)") 1 font-lock-constant-face))))
@@ -684,7 +684,7 @@ case keyword. It returns nil for the case line itself."
       (looking-back "[,:]" (1- (point)))
 
       ;; If we made it to the beginning of line we are either a naked
-      ;; block or a composite literal with implict type name. If we
+      ;; block or a composite literal with implicit type name. If we
       ;; are the latter, we must be contained in another composite
       ;; literal.
       (and (bolp) (go--in-composite-literal-p))))))
@@ -1571,6 +1571,29 @@ We are looking for the right-hand-side of the type alias"
     found-match))
 
 
+(defconst go--label-re (concat "\\(" go-label-regexp "\\):"))
+
+(defun go--match-ident-colon (end)
+  "Search for composite literal field names and label definitions."
+  (let (found-match)
+    (while (and
+            (not found-match)
+            (re-search-forward go--label-re end t))
+
+      (setq found-match (or
+                         ;; Composite literal field names, e.g. "Foo{Bar:". 
Note
+                         ;; that this gives false positives for literal maps,
+                         ;; arrays, and slices.
+                         (go--in-composite-literal-p)
+
+                         ;; We are a label definition if we are at the 
beginning
+                         ;; of the line.
+                         (save-excursion
+                           (goto-char (match-beginning 1))
+                           (skip-syntax-backward " ")
+                           (bolp)))))
+    found-match))
+
 (defun go--parameter-list-type (end)
   "Return `present' if the parameter list has names, or `absent' if not.
 Assumes point is at the beginning of a parameter list, just
diff --git a/test/go-font-lock-test.el b/test/go-font-lock-test.el
index 6a8306f..5de75f8 100644
--- a/test/go-font-lock-test.el
+++ b/test/go-font-lock-test.el
@@ -94,7 +94,13 @@ KcaseK string:
   (go--should-fontify "TfooT{")
   (go--should-fontify "[]TfooT{")
   (go--should-fontify "Tfoo.ZarT{")
-  (go--should-fontify "[]Tfoo.ZarT{"))
+  (go--should-fontify "[]Tfoo.ZarT{")
+
+  (go--should-fontify "TfooT{CbarC:baz, CquxC: 123}")
+
+  (go--should-fontify "TfooT{
+CbarC: baz,
+}"))
 
 (ert-deftest go--fontify-slices-arrays-maps ()
   (go--should-fontify "[]TfooT")
@@ -163,6 +169,16 @@ KconstK (
   CaC, CbC TintT = 1, 2
 )"))
 
+(ert-deftest go--fontify-labels ()
+  (go--should-fontify "
+CfooC:
+KforK {
+  KcontinueK CfooC
+  KbreakK CfooC
+  KgotoK CfooC
+}
+"))
+
 (ert-deftest go--fontify-assign ()
   (go--should-fontify "VfooV := bar")
   (go--should-fontify "foo = bar D// DQ:=Q")



reply via email to

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