summaryrefslogtreecommitdiffstats
path: root/lisp/init-project.el
blob: 944db7c109747ec0894b732a4ea7c5fb182d95fa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
;;; init-project.el --- configure project integration  -*- lexical-binding:t -*-
;;; Commentary:
;;; Code:

(defun mpolden/project-try-go (dir)
  "Find root directory of a nested modules-based Go project from DIR."
  ;; this speeds up working with a go project nested inside a large repository
  (let* ((module-root (locate-dominating-file dir "go.mod"))
         (is-vc-root (file-directory-p (expand-file-name ".git" module-root))))
    (when (and module-root (not is-vc-root))
      (cons 'transient module-root))))

(use-package project
  :init
  ;; commands to show when switching projects
  (setq project-switch-commands '((project-find-file "Find file" ?f)
                                  (project-dired "Dired" ?d)
                                  (mpolden/grep "Grep" ?g)
                                  (magit-project-status "Magit" ?m)
                                  (mpolden/eshell-other-window "Eshell" ?e)))
  ;; configure how projects are detected
  (setq project-find-functions '(mpolden/project-try-go project-try-vc))
  :bind (;; C-x f finds file in project
         ("C-x f" . project-find-file)
         ;; C-c p switches project
         ("C-c p" . project-switch-project)))

(provide 'init-project)

;;; init-project.el ends here