diff options
author | David Morgan <djm_uk@protonmail.com> | 2021-09-20 16:05:22 +0100 |
---|---|---|
committer | David Morgan <djm_uk@protonmail.com> | 2021-09-20 16:05:22 +0100 |
commit | b522e1aea3f6a34afc5ef0e4bdebc1d73f706b07 (patch) | |
tree | 42dc714512c4e6d987656d9dbafe3e2c692d5eab | |
parent | c5d9f299b61c856d62d0d86fa103526ea3b6ba96 (diff) | |
download | dotfiles-b522e1aea3f6a34afc5ef0e4bdebc1d73f706b07.tar.gz |
Kill empty perspective created by aborted project switching
-rw-r--r-- | .emacs.d/lisp/init-project.el | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/.emacs.d/lisp/init-project.el b/.emacs.d/lisp/init-project.el index 71c1694..a8dd2eb 100644 --- a/.emacs.d/lisp/init-project.el +++ b/.emacs.d/lisp/init-project.el @@ -90,11 +90,20 @@ (let* ((persp-name (file-name-nondirectory (directory-file-name proj))) (persp (gethash persp-name (perspectives-hash)))) (unless (equal persp (persp-curr)) - ;; Create or switch to a perspective named after the project - (persp-switch persp-name) - ;; If the perspective did not exist, switch to the project - (when (not persp) - (project-switch-project proj))))) + (unwind-protect + (progn + ;; Create or switch to a perspective named after the project + (persp-switch persp-name) + ;; If the perspective did not exist, switch to the project + (when (not persp) + (project-switch-project proj))) + ;; If the only buffer is the persp scratch buffer, it's safe to kill the perspective if switching project was cancelled + (when (seq-empty-p + (seq-filter + (lambda (b) (not (equal (buffer-name b) (persp-scratch-buffer)))) + (persp-buffers (persp-curr)))) + (persp-kill persp-name)))))) + :bind ("C-x p p" . switch-project) ("C-x C-b" . persp-previous-buffer-same-mode) |