[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/go-mode 6b77ff1 065/495: allow disabling fontification for
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/go-mode 6b77ff1 065/495: allow disabling fontification for function/method calls |
Date: |
Sat, 7 Aug 2021 09:04:44 -0400 (EDT) |
branch: elpa/go-mode
commit 6b77ff1916168d764e3e95fa4eb8ebe21a81eeeb
Author: Dominik Honnef <dominikh@fork-bomb.org>
Commit: Dominik Honnef <dominikh@fork-bomb.org>
allow disabling fontification for function/method calls
Fontifying function and method calls is unusual for emacs modes.
Personally I think it improves readability, others disagree, so it's
customizable now.
Closes gh-17
---
go-mode.el | 77 ++++++++++++++++++++++++++++++++++----------------------------
1 file changed, 42 insertions(+), 35 deletions(-)
diff --git a/go-mode.el b/go-mode.el
index d345750..e4be8de 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -19,7 +19,16 @@
(defconst go-identifier-regexp "[[:word:][:multibyte:]_]+")
(defconst go-type-regexp "[[:word:][:multibyte:]_*]+")
(defconst go-func-regexp (concat "\\<func\\>\\s *\\(" go-identifier-regexp
"\\)"))
-(defconst go-func-meth-regexp (concat "\\<func\\>\\s *\\((\\s *"
go-identifier-regexp "\\s +" go-type-regexp "\\s *)\\s *\\)?\\("
go-identifier-regexp "\\)("))
+(defconst go-func-meth-regexp (concat "\\<func\\>\\s *\\(?:(\\s *"
go-identifier-regexp "\\s +" go-type-regexp "\\s *)\\s *\\)?\\("
go-identifier-regexp "\\)("))
+(defconst go-builtins '("append" "cap" "close" "complex" "copy" "delete"
"imag" "len" "make" "new" "panic" "print" "println" "real" "recover"))
+(defconst go-constants '("nil" "true" "false" "iota"))
+(defconst go-type-name-regexp "\\(?:[*(]\\)*\\(?:\\w+\\.\\)?\\(\\w+\\)") ;;
TODO replace this with something sane
+
+
+(defcustom go-fontify-function-calls t
+ "Fontify function and method calls if this is non-nil."
+ :type 'boolean
+ :group 'go)
(defvar go-mode-syntax-table
(let ((st (make-syntax-table)))
@@ -55,39 +64,37 @@
some syntax analysis.")
-(defvar go-mode-font-lock-keywords
- (let ((builtins '("append" "cap" "close" "complex" "copy" "delete" "imag"
"len"
- "make" "new" "panic" "print" "println" "real" "recover"))
- (constants '("nil" "true" "false" "iota"))
- (type-name "\\(?:[*(]\\)*\\(?:\\w+\\.\\)?\\(\\w+\\)") ;; XXX wtf? and
what about unicode? and is this an identifier or wtf is it?
- )
- `((,(regexp-opt go-mode-keywords 'words) . font-lock-keyword-face)
- (,(regexp-opt builtins 'words) . font-lock-builtin-face)
- (,(regexp-opt constants 'words) . font-lock-constant-face)
- (,go-func-regexp 1 font-lock-function-name-face) ;; function (not
method) name
- (,(concat "\\(" go-identifier-regexp "\\)\\s *(") 1
font-lock-function-name-face) ;; function call/method name
- (,(concat "(\\(" go-identifier-regexp "\\))\\s *(") 1
font-lock-function-name-face) ;; bracketed function call
- ("\\<type\\>\\s *\\(\\S +\\)" 1 font-lock-type-face) ;; types
- (,(concat "\\<type\\>\\s *" go-identifier-regexp "\\s *" type-name) 1
font-lock-type-face) ;; types
- (,(concat
"\\(?:[[:space:]]+\\|\\]\\)\\[\\([[:digit:]]+\\|\\.\\.\\.\\)?\\]" type-name) 2
font-lock-type-face) ;; Arrays/slices
- (,(concat "map\\[[^]]+\\]" type-name) 1 font-lock-type-face) ;; map
value type
-
- (,(concat "\\(" go-identifier-regexp "\\)" "{") 1 font-lock-type-face)
-
- (,(concat "\\<map\\[" type-name) 1 font-lock-type-face) ;; map key type
- (,(concat "\\<chan\\>\\s *\\(?:<-\\)?" type-name) 1 font-lock-type-face)
;; channel type
- (,(concat "\\<\\(?:new\\|make\\)\\>\\(?:\\s \\|)\\)*(" type-name) 1
font-lock-type-face) ;; new/make type
- ;; TODO do we actually need this one or isn't it just a function call?
- (,(concat "\\.\\s *(" type-name) 1 font-lock-type-face) ;; Type
conversion
- (,(concat "\\<func\\>\\s +(" go-identifier-regexp "\\s +" type-name ")")
1 font-lock-type-face) ;; Method receiver
- ;; Like the original go-mode this also marks compound literal
- ;; fields. There, it was marked as to fix, but I grew quite
- ;; accustomed to it, so it'll stay for now.
- ("^\\s *\\(\\w+\\)\\s *:\\(\\S.\\|$\\)" 1 font-lock-constant-face) ;;
Labels and compound literal fields
- ("\\<\\(goto\\|break\\|continue\\)\\>\\s *\\(\\w+\\)" 2
font-lock-constant-face))) ;; labels in goto/break/continue
- "Basic font lock keywords for Go mode. Highlights keywords,
-built-ins, functions, and some types.")
-
+(defun go--build-font-lock-keywords ()
+ (message "%s" "Builting keywords...")
+ (append
+ `((,(regexp-opt go-mode-keywords 'words) . font-lock-keyword-face)
+ (,(regexp-opt go-builtins 'words) . font-lock-builtin-face)
+ (,(regexp-opt go-constants 'words) . font-lock-constant-face)
+ (,go-func-regexp 1 font-lock-function-name-face) ;; function (not method)
name
+ )
+
+ (if go-fontify-function-calls
+ `((,(concat "\\(" go-identifier-regexp "\\)\\s *(") 1
font-lock-function-name-face) ;; function call/method name
+ (,(concat "(\\(" go-identifier-regexp "\\))\\s *(") 1
font-lock-function-name-face)) ;; bracketed function call
+ `((,go-func-meth-regexp 1 font-lock-function-name-face))) ;; method name
+
+ `(
+ ("\\<type\\>\\s *\\(\\S +\\)" 1 font-lock-type-face) ;; types
+ (,(concat "\\<type\\>\\s *" go-identifier-regexp "\\s *"
go-type-name-regexp) 1 font-lock-type-face) ;; types
+ (,(concat
"\\(?:[[:space:]]+\\|\\]\\)\\[\\([[:digit:]]+\\|\\.\\.\\.\\)?\\]"
go-type-name-regexp) 2 font-lock-type-face) ;; Arrays/slices
+ (,(concat "map\\[[^]]+\\]" go-type-name-regexp) 1 font-lock-type-face) ;;
map value type
+ (,(concat "\\(" go-identifier-regexp "\\)" "{") 1 font-lock-type-face)
+ (,(concat "\\<map\\[" go-type-name-regexp) 1 font-lock-type-face) ;; map
key type
+ (,(concat "\\<chan\\>\\s *\\(?:<-\\)?" go-type-name-regexp) 1
font-lock-type-face) ;; channel type
+ (,(concat "\\<\\(?:new\\|make\\)\\>\\(?:\\s \\|)\\)*("
go-type-name-regexp) 1 font-lock-type-face) ;; new/make type
+ ;; TODO do we actually need this one or isn't it just a function call?
+ (,(concat "\\.\\s *(" go-type-name-regexp) 1 font-lock-type-face) ;; Type
conversion
+ (,(concat "\\<func\\>\\s +(" go-identifier-regexp "\\s +"
go-type-name-regexp ")") 1 font-lock-type-face) ;; Method receiver
+ ;; Like the original go-mode this also marks compound literal
+ ;; fields. There, it was marked as to fix, but I grew quite
+ ;; accustomed to it, so it'll stay for now.
+ ("^\\s *\\(\\w+\\)\\s *:\\(\\S.\\|$\\)" 1 font-lock-constant-face) ;;
Labels and compound literal fields
+ ("\\<\\(goto\\|break\\|continue\\)\\>\\s *\\(\\w+\\)" 2
font-lock-constant-face)))) ;; labels in goto/break/continue
(defvar go-mode-map
(let ((m (make-sparse-keymap)))
@@ -259,7 +266,7 @@ functions, and some types. It also provides indentation
that is
;; Font lock
(set (make-local-variable 'font-lock-defaults)
- '(go-mode-font-lock-keywords))
+ '(go--build-font-lock-keywords))
;; Indentation
(set (make-local-variable 'indent-line-function) 'go-mode-indent-line)
- [nongnu] elpa/go-mode c2366b2 084/495: formatting, (continued)
- [nongnu] elpa/go-mode c2366b2 084/495: formatting, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode fb9ab02 087/495: buffer-file-truename is an *abbreviated* truename, so use file-truename instead., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 745c437 092/495: style fixes, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode c833b77 094/495: Fix cache invalidation for dangling operator cache, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 87c8b6e 096/495: do not use dangling op cache when buffer is narrowed, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 8e19ae5 097/495: add some documentation, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode b5960fe 099/495: nicer messages in gofmt, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 939d630 100/495: style fixes, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 47b3928 102/495: disable read-only on error buffer before trying to write to it, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode c94ca2e 064/495: refactor, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 6b77ff1 065/495: allow disabling fontification for function/method calls,
ELPA Syncer <=
- [nongnu] elpa/go-mode 02d44df 067/495: add function for downloading playgrounds into emacs, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode ec6fef4 066/495: Define a customization group for go-mode, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 856eff3 105/495: Instead of relying on gofmt's -d flag, use diff -n directly. This, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode d5839a0 106/495: use kill-whole-line directly, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode e1bb58a 109/495: Update README because go-mode.el is now upstream, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode b1bb0e0 111/495: replace shell-command-on-region with call-process-region, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 9f1f94e 113/495: use own implementation of go--string-prefix-p because it has been added in Emacs 24 and people are still using Emacs 23, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 22192f7 121/495: use featurep instead of version string to check for xemacs, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 3b0efdd 132/495: docstrings, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 7ab928a 146/495: Add support for methods that have no name for the receiver, ELPA Syncer, 2021/08/07