aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgcv <gepardcv@gmail.com>2022-06-15 22:29:52 -0700
committergcv <gepardcv@gmail.com>2022-06-15 22:29:52 -0700
commitb6a13bf5ffc454df32f65eddf057b166a5b42048 (patch)
treeeb492a866378df6bc5aac42d25dadabc3ff1432a
parent794afdbc5188ef6f2d78d26302cd78903ce618fa (diff)
Avoid activating persp-mode when it is already active.
-rw-r--r--CHANGELOG.md1
-rw-r--r--perspective.el57
2 files changed, 32 insertions, 26 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 864e97e..f874f26 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -35,6 +35,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- `persp-activate`: force update the `current-buffer` to the current window's buffer due to `make-persp` saving/restoring the `current-buffer` when executing it's BODY. This properly updates the `current-buffer` to what should be the real current buffer when switching to a new perspective.
- `persp-add-buffer`: discard unexisting buffer as argument.
- Added a workaround for potential problems caused by recursive minibuffer use.
+- Made activating `persp-mode` repeatedly idempotent (should fix [interactive enable-theme invocation bug](https://github.com/nex3/perspective-el/issues/185)).
## [2.17] — 2021-09-18
diff --git a/perspective.el b/perspective.el
index 1254f60..c667037 100644
--- a/perspective.el
+++ b/perspective.el
@@ -1356,32 +1356,37 @@ named collections of buffers and window configurations."
:global t
:keymap persp-mode-map
(if persp-mode
- (persp-protect
- (when (bound-and-true-p server-process)
- (setq persp-started-after-server-mode t))
- ;; TODO: Convert to nadvice, which has been available since 24.4 and is
- ;; the earliest Emacs version Perspective supports.
- (ad-activate 'switch-to-buffer)
- (ad-activate 'display-buffer)
- (ad-activate 'set-window-buffer)
- (ad-activate 'switch-to-prev-buffer)
- (ad-activate 'recursive-edit)
- (ad-activate 'exit-recursive-edit)
- (persp--helm-enable)
- (add-hook 'after-make-frame-functions 'persp-init-frame)
- (add-hook 'delete-frame-functions 'persp-delete-frame)
- (add-hook 'ido-make-buffer-list-hook 'persp-set-ido-buffers)
- (when persp-feature-flag-prevent-killing-last-buffer-in-perspective
- (add-hook 'kill-buffer-query-functions 'persp-maybe-kill-buffer))
- (setq read-buffer-function 'persp-read-buffer)
- (mapc 'persp-init-frame (frame-list))
- (setf (persp-current-buffers) (buffer-list))
- (unless (or persp-mode-prefix-key persp-suppress-no-prefix-key-warning)
- (display-warning
- 'perspective
- (format-message "persp-mode-prefix-key is not set! If you see this warning, you are using Emacs 28 or later, and have not customized persp-mode-prefix-key. Please refer to the Perspective documentation for further information (https://github.com/nex3/perspective-el). To suppress this warning without choosing a prefix key, set persp-suppress-no-prefix-key-warning to `t'.")
- :warning))
- (run-hooks 'persp-mode-hook))
+ ;; activate persp-mode, preferably in an idempotent manner: the presence
+ ;; of a non-nil 'persp--hash parameter in (selected-frame) should be a
+ ;; good proxy for whether the mode is actually active...
+ (unless (frame-parameter nil 'persp--hash)
+ (persp-protect
+ (when (bound-and-true-p server-process)
+ (setq persp-started-after-server-mode t))
+ ;; TODO: Convert to nadvice, which has been available since 24.4 and is
+ ;; the earliest Emacs version Perspective supports.
+ (ad-activate 'switch-to-buffer)
+ (ad-activate 'display-buffer)
+ (ad-activate 'set-window-buffer)
+ (ad-activate 'switch-to-prev-buffer)
+ (ad-activate 'recursive-edit)
+ (ad-activate 'exit-recursive-edit)
+ (persp--helm-enable)
+ (add-hook 'after-make-frame-functions 'persp-init-frame)
+ (add-hook 'delete-frame-functions 'persp-delete-frame)
+ (add-hook 'ido-make-buffer-list-hook 'persp-set-ido-buffers)
+ (when persp-feature-flag-prevent-killing-last-buffer-in-perspective
+ (add-hook 'kill-buffer-query-functions 'persp-maybe-kill-buffer))
+ (setq read-buffer-function 'persp-read-buffer)
+ (mapc 'persp-init-frame (frame-list))
+ (setf (persp-current-buffers) (buffer-list))
+ (unless (or persp-mode-prefix-key persp-suppress-no-prefix-key-warning)
+ (display-warning
+ 'perspective
+ (format-message "persp-mode-prefix-key is not set! If you see this warning, you are using Emacs 28 or later, and have not customized persp-mode-prefix-key. Please refer to the Perspective documentation for further information (https://github.com/nex3/perspective-el). To suppress this warning without choosing a prefix key, set persp-suppress-no-prefix-key-warning to `t'.")
+ :warning))
+ (run-hooks 'persp-mode-hook)))
+ ;; deactivate persp-mode
(persp--helm-disable)
(ad-deactivate-regexp "^persp-.*")
(remove-hook 'delete-frame-functions 'persp-delete-frame)