summary refs log tree commit diff
path: root/emacs/custom
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2022-06-03 15:38:51 -0700
committerFranck Cuny <franck@fcuny.net>2022-06-03 15:38:51 -0700
commit96d558b01e69b2dd7fef3146291b2a69b999dabb (patch)
treef385b0c5fabc7d1ba56d8b6941bc94a656ed3db4 /emacs/custom
parentfeat(eglot): use LSP to format go buffers instead of gofmt (diff)
downloademacs.d-96d558b01e69b2dd7fef3146291b2a69b999dabb.tar.gz
feat(project): add `go.mod' to the list of files that define a project
In a repository, I might have multiple `go.mod' files, and I want to
treat of of the directories as a project, even within the same
repository.

Change-Id: I09937d9961464bff0f9d673d1eb50484eb8ea10e
Diffstat (limited to 'emacs/custom')
-rw-r--r--emacs/custom/my-navigation.el14
1 files changed, 14 insertions, 0 deletions
diff --git a/emacs/custom/my-navigation.el b/emacs/custom/my-navigation.el
index c0726ac..28c1fa1 100644
--- a/emacs/custom/my-navigation.el
+++ b/emacs/custom/my-navigation.el
@@ -6,6 +6,8 @@
 
 (setq help-window-select t)
 
+(require 'project)
+
 (customize-set-variable 'project-switch-commands
                         '((?f "File" project-find-file)
                           (?d "Dired" project-dired)
@@ -14,6 +16,18 @@
                           (?m "Magit status" magit-project-status)
                           (?r "Search" rg-project)))
 
+
+(defun my/project-find-go-module (dir)
+  "Find the go.mod file in a DIR."
+  (when-let ((root (locate-dominating-file dir "go.mod")))
+    (cons 'go-module root)))
+
+(cl-defmethod project-root ((project (head go-module)))
+  "Set the project root for PROJECT."
+  (cdr project))
+
+(add-to-list 'project-find-functions #'my/project-find-go-module)
+
 (customize-set-variable 'bookmark-save-flag 1)
 
 (global-set-key (kbd "C-x C-b") 'ibuffer)