From 26c7418e33fd7508d0acf91f261be22ed61b568c Mon Sep 17 00:00:00 2001 From: BirDt_ Date: Wed, 20 Aug 2025 18:10:00 +0800 Subject: [PATCH] Projects --- init.el | 9 ++++--- screens/dashboard.el | 4 +-- userland/projects.el | 60 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 userland/projects.el diff --git a/init.el b/init.el index 8b5e6f0..d86cad3 100644 --- a/init.el +++ b/init.el @@ -63,6 +63,11 @@ (load (concat user-emacs-directory "shared-packages.el")) ;; UI and display related packages (load (concat user-emacs-directory "ui.el")) + +;; Use a custom file instead of putting customisations in init.el +(setq custom-file (concat user-emacs-directory "custom.el")) +(when (file-exists-p custom-file) (load custom-file)) + ;; Writing behavior and packages (load (concat user-emacs-directory "writing.el")) ;; Navigation behavior and packages @@ -75,7 +80,3 @@ (load-directory (concat user-emacs-directory "workflows")) ;; Custom screens (load-directory (concat user-emacs-directory "screens")) - -;; Use a custom file instead of putting customisations in init.el -(setq custom-file (concat user-emacs-directory "custom.el")) -(when (file-exists-p custom-file) (load custom-file)) diff --git a/screens/dashboard.el b/screens/dashboard.el index 9cc57f2..ab4341f 100644 --- a/screens/dashboard.el +++ b/screens/dashboard.el @@ -115,8 +115,8 @@ (grid-get-box `(:content ,(concat (enlight-menu '(("Projects" - ("Open" open-project "o") - ("Project List" open-inbox "p"))))) + ("Switch To" theurgy-open-project "p") + ("Project List" theurgy-edit-projects-list "l"))))) :align center :width 20)) (grid-get-box `(:content ,(concat diff --git a/userland/projects.el b/userland/projects.el new file mode 100644 index 0000000..79e1e28 --- /dev/null +++ b/userland/projects.el @@ -0,0 +1,60 @@ +;;; 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)) + (neotree-dir dir)))) + +(defun theurgy-edit-projects-list () + "Open list of projects in customize." + (interactive) + (customize-group 'whaler)) + +(provide 'projects) + +;;; projects.el ends here