[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")
- [nongnu] elpa/go-mode 5c1c546 307/495: Don't fontify parenthesis of multi-line type declaration, (continued)
- [nongnu] elpa/go-mode 5c1c546 307/495: Don't fontify parenthesis of multi-line type declaration, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 99b06da 408/495: Describe gofmt-args in the readme and the gofmt docstring (also gofmt-command), ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 7c50c80 410/495: Always move back to same column after applying rcs patch, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode e20a54a 426/495: Speed up go-previous-line-has-dangling-op-p, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 1650ae5 434/495: Fix multiline case statement indent., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 1fcf76d 435/495: Fix indentation regexes to be case insensitive, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 8796ec6 446/495: indent: fix floating point literal with trailing point, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 1bbe1d0 451/495: update default go-packages-function to use go list, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 50e15c7 457/495: Add major mode for go.mod files: go-dot-mod-mode, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode a414da8 465/495: Fontify "font-lock-negation-char-face", ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 1ef3e95 476/495: Fix fontification of single line composite literal.,
ELPA Syncer <=
- [nongnu] elpa/go-mode db8284d 485/495: Handle godef "no object" error, ELPA Syncer, 2021/08/07