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

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

[nongnu] elpa/go-mode 85a20da 482/495: Only fontify ident keys in compos


From: ELPA Syncer
Subject: [nongnu] elpa/go-mode 85a20da 482/495: Only fontify ident keys in composite literals
Date: Sat, 7 Aug 2021 09:06:13 -0400 (EDT)

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

    Only fontify ident keys in composite literals
    
    Previously we were fontifying things like selectors and binary
    expressions in composite literals. For example, we fontified "baz" in:
    
    foo{
      bar.baz: 123,
      bar + baz: 123,
    }
    
    Now we are more careful to only fontify composite literal key
    identifiers preceded by "," or "{".
    
    Closes: #337 [via git-merge-pr]
---
 go-mode.el                | 28 ++++++++++++++++------------
 test/go-font-lock-test.el |  8 +++++++-
 2 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/go-mode.el b/go-mode.el
index a3fc9c0..e0ba615 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -1629,18 +1629,22 @@ We are looking for the right-hand-side of the type 
alias"
             (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)))))
+      (save-excursion
+        (goto-char (match-beginning 1))
+        (skip-syntax-backward " ")
+
+        (setq found-match (or
+                           ;; We are a label/field name if we are at the
+                           ;; beginning of the line.
+                           (bolp)
+
+                           ;; Composite literal field names, e.g. "Foo{Bar:". 
Note
+                           ;; that this gives false positives for literal maps,
+                           ;; arrays, and slices.
+                           (and
+                            (or (eq (char-before) ?,) (eq (char-before) ?{))
+                            (go--in-composite-literal-p))))))
+
     found-match))
 
 (defun go--parameter-list-type (end)
diff --git a/test/go-font-lock-test.el b/test/go-font-lock-test.el
index b38bd00..e2498ee 100644
--- a/test/go-font-lock-test.el
+++ b/test/go-font-lock-test.el
@@ -106,7 +106,13 @@ CbarC: baz,
 CbarC: baz,
 }, {
 CbarC: baz,
-}}"))
+}}")
+
+  (go--should-fontify "TsomeMapT{
+foo.Zar: baz,
+a + b: 3,
+a-b: 4,
+}"))
 
 (ert-deftest go--fontify-slices-arrays-maps ()
   (go--should-fontify "[]TfooT")



reply via email to

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