70 lines
2.6 KiB
EmacsLisp
70 lines
2.6 KiB
EmacsLisp
;;; projects.el --- Project management configuration with whaler -*- lexical-binding: t -*-
|
|
|
|
;; This file is not part of GNU Emacs
|
|
|
|
;; This program is free software: you can redistribute it and/or modify
|
|
;; it under the terms of the GNU General Public License as published by
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
;; (at your option) any later version.
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
;; GNU General Public License for more details.
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;; commentary
|
|
|
|
;;; Code:
|
|
|
|
(require 'subr-x)
|
|
|
|
(defcustom theurgy-project-default-file-alist '(("~/.emacs.d" . "init.el"))
|
|
"This alist specifies which file (relative to the project root) to open in the main frame by default when opening a project."
|
|
:group 'theurgy
|
|
:group 'theurgy-projects
|
|
:group 'whaler)
|
|
|
|
(use-package whaler
|
|
:ensure t
|
|
:config
|
|
(whaler-populate-projects-directories)
|
|
)
|
|
|
|
(defun get-project-default-file (dir)
|
|
"Get the project default file for `DIR', regardless of whether either path is absolute or relative."
|
|
(let ((absolute-project-dir (expand-file-name (string-remove-suffix "/" dir)))
|
|
(absolute-project-default-file-alist (mapcar (lambda (x) `(,(string-remove-suffix "/" (expand-file-name (car x))) . ,(cdr x)))
|
|
theurgy-project-default-file-alist)))
|
|
(or (file-name-concat dir (cdr (assoc absolute-project-dir absolute-project-default-file-alist))) dir)))
|
|
|
|
(defun theurgy-open-project ()
|
|
"Select a project and update neotree to use it as root."
|
|
(interactive)
|
|
(whaler :action (lambda (dir)
|
|
(find-file (get-project-default-file dir))
|
|
(tab-rename (file-name-nondirectory (string-remove-suffix "/" dir)))
|
|
(tab-bar-change-tab-group (concat "project: " dir)) ;; We use the tab group name to store the project working directory
|
|
(neotree-dir dir))))
|
|
|
|
(defun theurgy-swap-to-tab-project ()
|
|
"Go to the project dir of the tab group."
|
|
(let ((tab-group-name (tab-bar-tab-group-default (tab-bar--current-tab))))
|
|
(when (string-match-p "^project:" tab-group-name)
|
|
(neotree-dir (string-remove-prefix "project: " tab-group-name)))))
|
|
|
|
(add-hook 'tab-bar-select-tab-hook #'theurgy-swap-to-tab-project)
|
|
|
|
(defun theurgy-edit-projects-list ()
|
|
"Open list of projects in customize."
|
|
(interactive)
|
|
(customize-group 'whaler))
|
|
|
|
(provide 'projects)
|
|
|
|
;;; projects.el ends here
|