summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2025-10-20 14:40:42 -0500
committerCraig Jennings <c@cjennings.net>2025-10-20 14:40:42 -0500
commit423a36249821ee9a5df411b3ea2dfe63188d3c12 (patch)
tree901f0aa1c08cda42b797898b486830b134e8ef3a
parent04b7574bf620eb4a6f31e4a25a24ada3f94fb501 (diff)
feat: prog-go: Enhance Go configuration with go-ts-mode
Add go-ts-mode configuration using tree-sitter for Go programming. Introduce `go-bin-path` for managing Go tool binaries and implement `cj/go-staticcheck` for running static analysis. Update key bindings to use staticcheck instead of golint.
-rw-r--r--modules/prog-go.el57
1 files changed, 39 insertions, 18 deletions
diff --git a/modules/prog-go.el b/modules/prog-go.el
index cf12cb6f..0e56e5d0 100644
--- a/modules/prog-go.el
+++ b/modules/prog-go.el
@@ -2,39 +2,60 @@
;; author Craig Jennings <c@cjennings.net>
;;; Commentary:
+;; Configuration for Go programming using go-ts-mode (tree-sitter based).
+;; Requires go-mode package for gofmt and related commands.
+;;
+;; Tools installation:
+;; go install golang.org/x/tools/cmd/goimports@latest
+;; go install honnef.co/go/tools/cmd/staticcheck@latest
;;; Code:
+(defvar go-bin-path (expand-file-name "~/go/bin")
+ "Path to Go binaries directory.
+This is where tools like goimports and staticcheck are installed.")
+
+(defvar go-ts-mode-map)
+(defvar go-mod-ts-mode-map)
+
;; ---------------------------------- Go Setup ---------------------------------
-;; golang preferences
+;; golang preferences following Go community standards
(defun cj/go-setup ()
- "My default code preferences for Golang."
- (require 'tree-sitter)
- (require 'tree-sitter-langs)
- (require 'tree-sitter-hl)
- (tree-sitter-hl-mode)
- (hs-minor-mode)
+ "Default code preferences for Golang following Go conventions."
(company-mode)
- (setq-default tab-width 4) ;; set the tab width to 4 spaces
- (setq-default standard-indent 4) ;; indent 4 spaces
- (setq-default indent-tabs-mode nil) ;; disable tab characters
+ (setq-local tab-width 4) ;; Go standard tab width
+ (setq-local standard-indent 4) ;; indent 4 spaces per level
+ (setq-local indent-tabs-mode t) ;; use real tabs (Go convention)
(electric-pair-mode t)) ;; match delimiters automatically
-(add-hook 'go-mode-hook 'cj/go-setup)
+
+(defun cj/go-staticcheck ()
+ "Run staticcheck on the current Go package."
+ (interactive)
+ (let* ((staticcheck-bin (expand-file-name "staticcheck" go-bin-path))
+ (default-directory (if buffer-file-name
+ (file-name-directory buffer-file-name)
+ default-directory)))
+ (if (file-executable-p staticcheck-bin)
+ (compile (format "%s ./..." staticcheck-bin))
+ (message "staticcheck not found at %s. Install with: go install honnef.co/go/tools/cmd/staticcheck@latest"
+ staticcheck-bin))))
;; ---------------------------------- Go Mode ----------------------------------
-;; go mode configuration
+;; go-ts-mode configuration (treesit-based Go editing)
(use-package go-mode
- :bind (:map go-mode-map
+ :hook (go-ts-mode . cj/go-setup)
+ :bind (:map go-ts-mode-map
("<f6>" . gofmt)
("C-c 6" . gofmt)
- ("<f4>" . golint)
- ("C-c 4" . golint))
+ ("<f4>" . cj/go-staticcheck)
+ ("C-c 4" . cj/go-staticcheck))
+ :mode (("\\.go\\'" . go-ts-mode) ;; .go files use go-ts-mode
+ ("go\\.mod\\'" . go-mod-ts-mode)) ;; go.mod uses go-mod-ts-mode
:config
- (add-to-list 'exec-path "~/go/bin")
- ;; allow adding/removing fmt lines; install with:
- ;; go install golang.org/x/tools/cmd/goimports@latest
+ (add-to-list 'exec-path go-bin-path)
+ ;; Use goimports for formatting (adds/removes imports automatically)
(setq gofmt-command "goimports"))
(provide 'prog-go)