;;; theurgy-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 . ;;; 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 (save-selected-window (neotree-dir dir))))) (defcustom theurgy-sticky-project-dir t "When true, this will persist any changes to the Neotree root when switching tabs." :type 'boolean :group 'theurgy :group 'theurgy-projects) (defun theurgy-change-tab-dir () "Change the tab directory to the one selected in neotree." (interactive) (tab-bar-change-tab-group (concat "project: " (save-selected-window (neotree) neo-buffer--start-node)))) (when theurgy-sticky-project-dir (advice-add 'neotree-change-root :after #'theurgy-change-tab-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 (and tab-group-name (string-match-p "^project:" tab-group-name)) (save-selected-window (neotree-dir (string-remove-prefix "project: " tab-group-name)))))) (defun theurgy-get-tab-project-dir () "Get the directory of the project in the current tab. This returns nil if no project is found." (let ((tab-group-name (tab-bar-tab-group-default (tab-bar--current-tab)))) (if (and tab-group-name (string-match-p "^project:" tab-group-name)) (string-remove-prefix "project: " tab-group-name) nil))) (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)) (defcustom apps-directory nil "Directory that contains apps within the current folder. Set this in .dir-locals.el." :type 'string :group 'theurgy :group 'theurgy-projects) (defcustom apps-commands nil "Commands to run on apps in the given directory. An alist of symbols, for example: '((start . \"npm run start\"))" :type 'alist :group 'theurgy :group 'theurgy-projects) (defun run-app-command () "Run a command from APPS-COMMANDS, in one of the subfolders of APPS-DIRECTORY." (interactive)) (provide 'theurgy-projects) ;;; theurgy-projects.el ends here