auto setup scripts for perspectives

This commit is contained in:
Levi 2024-09-20 09:13:30 +02:00
parent f46f2abee0
commit 8495ffe10d
4 changed files with 50 additions and 0 deletions

View File

@ -9,6 +9,7 @@
(require 'module-projectile)
(require 'module-perspective)
(require 'module-work-projects)
(provide 'feature-project)
;;; feature-project.el ends here.

View File

@ -47,5 +47,9 @@
(load-theme 'misterioso)
(require 'server)
(if (not (server-running-p))
(server-start))
(provide 'init)
;;; init.el ends here

View File

@ -20,6 +20,17 @@
(defun my-persp-load ()
(persp-state-load "~/.config/emacs/perspectives"))
(defun create-perspectives-for-projects (root-dir)
"Create perspectives for each subdirectory in ROOT-DIR."
(interactive "DSelect root directory: ")
(let ((subdirs (directory-files root-dir t directory-files-no-dot-files-regexp)))
(dolist (dir subdirs)
(when (file-directory-p dir)
(let ((project-name (file-name-nondirectory dir)))
(persp-switch project-name)
(dired dir)
(persp-add-buffer (current-buffer)))))))
(global-set-key (kbd "C-x k") 'persp-kill-buffer*)
(global-set-key (kbd "C-x x s") 'persp-switch)
@ -38,6 +49,20 @@
(add-hook 'kill-emacs-hook 'my-persp-save)
(add-hook 'after-init-hook 'my-persp-load)
;; setup emacs perspective
(persp-switch "emacs")
(dired "~/.config/emacs")
(persp-add-buffer current-buffer)
;; go back to main perspective
(persp-switch "main")
;; Call this function when Emacs starts
(add-hook 'after-init-hook #'auto-create-work-project-perspectives)
(provide 'module-perspective)
;;; module-projectile.el ends here.

View File

@ -0,0 +1,20 @@
;;; module-work-projects.el --- autoload work perspectives
;;;
;;; Commentary:
;;;
;;; Autoload work projects into perspectives.
;;;
;;; Code:
(require 'module-perspective)
(defun auto-create-work-project-perspectives ()
"Automatically create perspectives for projects if the directory exists."
(let ((projects-dir "~/src/pascom/"))
(when (file-directory-p projects-dir)
(create-perspectives-for-projects projects-dir))))
;; Call this function when Emacs starts
(add-hook 'after-init-hook #'auto-create-work-project-perspectives)
;;; module-work-projects.el ends here.