diff options
| author | David Edmondson <dme@dme.org> | 2020-01-31 00:27:35 +0000 |
|---|---|---|
| committer | David Edmondson <dme@dme.org> | 2020-02-04 17:28:08 +0000 |
| commit | 4a6c8fd226e0590b08dbfea1e10fa653843f4e93 (patch) | |
| tree | 3d62f29432df119d988de291aac35f6ec9d9fd46 | |
| parent | 0c721618a6cdf06c58aeb2c19f17febb3c4e51c2 (diff) | |
Add persp-ivy-switch-buffer.
Rewrite persp-counsel-switch-buffer to share code with the above.
Signed-off-by: David Edmondson <dme@dme.org>
| -rw-r--r-- | perspective.el | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/perspective.el b/perspective.el index 7576028..e32dc47 100644 --- a/perspective.el +++ b/perspective.el @@ -1080,32 +1080,48 @@ PERSP-SET-IDO-BUFFERS)." (ibuffer)) (ibuffer))) -;; Buffer switching integration: Ivy / Counsel. -;;;###autoload -(defun persp-counsel-switch-buffer (arg) - "Like COUNSEL-SWITCH-BUFFER, but Perspective-aware. -With a prefix arg, show buffers in all perspectives." - (interactive "P") - (unless (and (featurep 'ivy) (featurep 'counsel)) - (error "Ivy or Counsel not loaded")) +(defun persp--switch-buffer-ivy-counsel-helper (arg ivy-params fallback) + (unless (featurep 'ivy) + (error "Ivy not loaded")) (defvar ivy-switch-buffer-map) (declare-function ivy-read "ivy.el") (declare-function ivy--switch-buffer-matcher "ivy.el") (declare-function ivy--switch-buffer-action "ivy.el") + (if (and persp-mode (null arg)) + (apply #'ivy-read + (append + (list + (format "Switch to buffer (%s): " (persp-current-name)) + (cl-remove-if #'null (mapcar #'buffer-name (persp-current-buffers))) + :preselect (buffer-name (persp-other-buffer (current-buffer))) + :keymap ivy-switch-buffer-map + :action #'ivy--switch-buffer-action + :matcher #'ivy--switch-buffer-matcher) + ivy-params)) + (funcall fallback))) + +;; Buffer switching integration: Ivy. +;;;###autoload +(defun persp-ivy-switch-buffer (arg) + "A version of `ivy-switch-buffer' which respects perspectives." + (interactive "P") + (persp--switch-buffer-ivy-counsel-helper arg nil #'ivy-switch-buffer)) + +;; Buffer switching integration: Counsel. +;;;###autoload +(defun persp-counsel-switch-buffer (arg) + "A version of `counsel-switch-buffer' which respects perspectives." + (interactive "P") + (unless (featurep 'counsel) + (error "Counsel not loaded")) (declare-function counsel-switch-buffer "counsel.el") (declare-function counsel--switch-buffer-unwind "counsel.el") (declare-function counsel--switch-buffer-update-fn "counsel.el") - (if (and persp-mode (null arg)) - (ivy-read (format "Switch to buffer (%s): " (persp-current-name)) - (cl-remove-if #'null (mapcar #'buffer-name (persp-current-buffers))) - :preselect (buffer-name (persp-other-buffer (current-buffer))) - :keymap ivy-switch-buffer-map - :action #'ivy--switch-buffer-action - :matcher #'ivy--switch-buffer-matcher - :caller #'counsel-switch-buffer - :unwind #'counsel--switch-buffer-unwind - :update-fn #'counsel--switch-buffer-update-fn) - (counsel-switch-buffer))) + (persp--switch-buffer-ivy-counsel-helper arg + (list :caller #'counsel-switch-buffer + :unwind #'counsel--switch-buffer-unwind + :update-fn #'counsel--switch-buffer-update-fn) + #'counsel-switch-buffer)) ;; Symbols namespaced by persp--state (internal) and persp-state (user ;; functions) provide functionality which allows saving perspective state on |
