diff options
| author | Constantine Vetoshev <gepardcv@gmail.com> | 2021-08-18 22:34:54 -0700 |
|---|---|---|
| committer | Constantine Vetoshev <gepardcv@gmail.com> | 2021-08-18 22:39:07 -0700 |
| commit | 0b693bdfdc135128c37bdcfaad0d57cc613564f4 (patch) | |
| tree | 7c32571881f455c25143f1ab9ad08def64a36270 | |
| parent | bf3f4c8cc9ae26573f39be026e8c5e994c14da63 (diff) | |
Improve Helm integration.
| -rw-r--r-- | README.md | 6 | ||||
| -rw-r--r-- | perspective.el | 55 |
2 files changed, 58 insertions, 3 deletions
@@ -235,7 +235,11 @@ listing buffers, so they did not require this advice; see [`this Helm commit`](https://github.com/emacs-helm/helm/commit/f7fa3a9e0ef1f69c42e0c513d02c9f76ea9a4344) and [`this Perspective commit`](https://github.com/nex3/perspective-el/commit/c2d3542418967b55f05d5b5ba71c9fbfe4cd3d4f) -for details.) +for details.) If `helm-buffers-list` is called with a prefix argument, it will +show buffers in all perspectives. In addition, Perspective adds actions to +`helm-buffers-list` to add buffers to the current perspective (mainly relevant +to the prefix-argument version) and to remove buffers from the current +perspective. **Ivy / Counsel**: Perspective provides two commands for listing buffers using Ivy and Counsel: `persp-ivy-switch-buffer` and `persp-counsel-switch-buffer`. diff --git a/perspective.el b/perspective.el index 038176d..113a6b9 100644 --- a/perspective.el +++ b/perspective.el @@ -1085,7 +1085,7 @@ named collections of buffers and window configurations." (ad-activate 'switch-to-prev-buffer) (ad-activate 'recursive-edit) (ad-activate 'exit-recursive-edit) - (advice-add 'helm-buffer-list-1 :filter-return #'persp-buffer-list-filter) + (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) @@ -1093,7 +1093,7 @@ named collections of buffers and window configurations." (mapc 'persp-init-frame (frame-list)) (setf (persp-current-buffers) (buffer-list)) (run-hooks 'persp-mode-hook)) - (advice-remove 'helm-buffer-list-1 #'persp-buffer-list-filter) + (persp--helm-disable) (ad-deactivate-regexp "^persp-.*") (remove-hook 'delete-frame-functions 'persp-delete-frame) (remove-hook 'after-make-frame-functions 'persp-init-frame) @@ -1384,6 +1384,57 @@ PERSP-SET-IDO-BUFFERS)." (persp--switch-buffer-ivy-counsel-helper arg #'counsel-switch-buffer)) +;;; --- Helm integration + +(defun persp--helm-buffer-list-filter (bufs) + (if current-prefix-arg + bufs + (persp-buffer-list-filter bufs))) + +(defun persp--helm-remove-buffers-from-perspective (_arg) + (interactive) + (declare-function helm-marked-candidates "helm.el") + (cl-loop for candidate in (helm-marked-candidates) do + (persp-remove-buffer candidate))) + +(defun persp--helm-add-buffers-to-perspective (_arg) + (declare-function helm-marked-candidates "helm.el") + (cl-loop for candidate in (helm-marked-candidates) do + (persp-add-buffer candidate))) + +(defun persp--helm-activate (&rest _args) + (defvar helm-source-buffers-list) + (declare-function helm-add-action-to-source "helm.el") + (advice-add 'helm-buffer-list-1 :filter-return #'persp--helm-buffer-list-filter) + (helm-add-action-to-source + "Perspective: Add buffer to current perspective" + #'persp--helm-add-buffers-to-perspective helm-source-buffers-list) + (helm-add-action-to-source + "Perspective: Remove buffer from current perspective" + #'persp--helm-remove-buffers-from-perspective helm-source-buffers-list) + ;; remove persp--helm-activate advice once it has run + (advice-remove 'helm-initial-setup #'persp--helm-activate)) + +(defun persp--helm-enable () + ;; We do not know if Helm has been loaded before Perspective is activated, so + ;; we need a way to activate Perspective-Helm integration once we know for + ;; certain that Helm is ready. An advice functino should do the trick, which + ;; will remove itself once it does its job. + (advice-add 'helm-initial-setup :before #'persp--helm-activate)) + +(defun persp--helm-disable () + (defvar helm-source-buffers-list) + (declare-function helm-delete-action-from-source "helm.el") + (if (not (featurep 'helm)) + (advice-remove 'helm-initial-setup #'persp--helm-activate) + ;; actual cleanup if Helm-perspective integration has loaded: + (helm-delete-action-from-source + #'persp--helm-remove-buffers-from-perspective helm-source-buffers-list) + (helm-delete-action-from-source + #'persp--helm-add-buffers-to-perspective helm-source-buffers-list) + (advice-remove 'helm-buffer-list-1 #'persp--helm-buffer-list-filter))) + + ;;; --- durability implementation (persp-state-save and persp-state-load) ;; Symbols namespaced by persp--state (internal) and persp-state (user |
