home

My NixOS systems configurations.
Log | Files | Refs | LICENSE

commit e1559d53bcd0373a926fbe7d3bbd5e800349b337
parent af1fe0037b666068ff82fd7654218ef240f2cda7
Author: Vincent Demeester <vincent@sbr.pm>
Date:   Tue,  9 Jul 2024 18:19:46 +0200

tools/emacs: add run-command go recipes…

it is not complete, but it is a start.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>

Diffstat:
Mtools/emacs/config/programming-go.el | 57++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 56 insertions(+), 1 deletion(-)

diff --git a/tools/emacs/config/programming-go.el b/tools/emacs/config/programming-go.el @@ -3,15 +3,19 @@ ;;; Go programming language configuration ;;; Code: +(declare-function project-root "project") +(declare-function project-current "project") +(declare-function vde-project--project-root-or-default-directory "proj-func") (use-package gotest :commands (my-gotest-maybe-ts-run go-test--get-current-test-info) - :after go-mode + :after go-ts-mode :custom (go-test-verbose t) :hook (go-test-mode . (lambda () (pop-to-buffer (get-buffer "*Go Test*")))) (go-mode . (lambda ()(interactive) (setq go-run-args "-v"))) + (go-ts-mode . (lambda ()(interactive) (setq go-run-args "-v"))) :config (defun my-go-test-current-project() (interactive) @@ -30,6 +34,57 @@ (replace-regexp-in-string " " "_" testrunname))))) (go-test--go-test (concat "-run " gotest "\\$ ."))))) +(defun go-mode-p () + "Return non-nil value when the major mode is `go-mode' or `go-ts-mode'." + (memq major-mode '(go-ts-mode go-mode))) + +;; TODO (defun run-command-recipe-ko ()) + +(defun run-command-recipe-go () + "Go `run-command' recipes." + (let ((dir (vde-project--project-root-or-default-directory))) + (when (or (go-mode-p) (file-exists-p (expand-file-name "go.mod" dir))) + (append + (and (buffer-file-name) (go-mode-p) + (list + (list :command-name "gofumpt" + :command-line (concat "gofumpt -extra -w " (buffer-file-name)) + :working-dir dir + :display "gofumpt (reformat) file") + (list :command-name "go-fmt" + :command-line (concat "go fmt " (buffer-file-name)) + :working-dir dir + :display "gofmt (reformat) file") + (list :command-name "go-run" + :command-line (concat "go run " (buffer-file-name)) + :working-dir dir + :display "Compile, execute file"))) + (and (string-suffix-p "_test.go" buffer-file-name) (go-mode-p) + (list + ;; go-test--get-current-file-tests + (let ((runArgs (go-test--get-current-file-tests)) + (package (file-name-directory (concat "./"(file-relative-name (buffer-file-name) dir))))) + (list :command-name "go-test-file" + :command-line (concat "go test -v " package " -run " (shell-quote-argument runArgs)) + :working-dir dir + :display (concat "Test file " (concat "./"(file-relative-name (buffer-file-name) dir))) + :runner 'run-command-runner-compile)))) + ;; TODO: handle test file as well + (list + (list :command-name "go-build-project" + :command-line "go build -v ./..." + :working-dir dir + :display "compile package and dependencies" + :runner 'run-command-runner-compile) + (list :command-name "go-test-project" + :command-line "go test ./..." + :working-dir dir + :display "test all" + :runner 'run-command-runner-compile)))))) + +(with-eval-after-load 'run-command + (add-to-list 'run-command-recipes 'run-command-recipe-go)) + (use-package go-ts-mode :mode (("\\.go$" . go-ts-mode) ("\\.go" . go-ts-mode)