aboutsummaryrefslogtreecommitdiff
path: root/perspective.el
diff options
context:
space:
mode:
authorThibaut Meyer <thibaut.meyer@posteo.eu>2022-07-19 23:50:15 +0200
committerThibaut Meyer <thibaut.meyer@posteo.eu>2022-07-19 23:50:15 +0200
commit7a5e8a14c013f0d0919a1fb8aa86ad1a36934aef (patch)
treefa3d981b98006bb380f2538a3b5f3e1f2730e8b1 /perspective.el
parente994fb3067d343732f9fc0ae209cecd5a6192237 (diff)
persp-purge-initial-persp-on-save: purges the inital persp upon save
Diffstat (limited to 'perspective.el')
-rw-r--r--perspective.el21
1 files changed, 21 insertions, 0 deletions
diff --git a/perspective.el b/perspective.el
index 28bb4e7..f91aa52 100644
--- a/perspective.el
+++ b/perspective.el
@@ -143,6 +143,20 @@ TODO: Eventually eliminate this setting?"
(defalias 'persp-avoid-killing-last-buffer-in-perspective
'persp-feature-flag-prevent-killing-last-buffer-in-perspective)
+(defcustom persp-purge-initial-persp-on-save nil
+ "When non-nil, kills all the buffers in the initial perspective upon state save.
+
+When calling `persp-state-save`, all the buffers in the initial perspective (\"main\" by default)
+are killed, expect the buffers whose name match the regex blabla"
+ :group 'perspective-mode
+ :type 'boolean)
+
+(defcustom persp-purge-initial-persp-on-save-exceptions nil
+ "Buffer whose name match with any regexp of this list
+won't be killed upon state save if persp-purge-initial-persp-on-save is t"
+ :group 'perspective-mode
+ :type '(repeat regexp))
+
;;; --- implementation
@@ -1930,6 +1944,11 @@ to the perspective's *scratch* buffer."
:order persp-names-in-order
:merge-list (frame-parameter nil 'persp-merge-list))))))
+(defun persp-purge-exception-p (buffer)
+ (let (result)
+ (dolist (exception persp-purge-initial-persp-on-save-exceptions result)
+ (setq result (or result (string-match-p exception (buffer-name buffer)))))))
+
;;;###autoload
(cl-defun persp-state-save (&optional file interactive?)
"Save the current perspective state to FILE.
@@ -1986,6 +2005,8 @@ visible in a perspective as windows, they will be saved as
(user-error "Cancelled persp-state-save"))
;; before hook
(run-hooks 'persp-state-before-save-hook)
+ (when persp-purge-initial-persp-on-save
+ (mapc 'kill-buffer (cl-remove-if #'persp-purge-exception-p (persp-all-get persp-initial-frame-name nil))))
;; actually save
(persp-save)
(let ((state-complete (make-persp--state-complete