From a690c0eadbcd2df719e5c27e362a74b865076a00 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Sat, 10 Jan 2015 11:57:44 -0800 Subject: [PATCH] New `persp-pick-perspective-by-buffer`. --- dotfiles/emacs.d/init.el | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/dotfiles/emacs.d/init.el b/dotfiles/emacs.d/init.el index 019fc1ee..047b394c 100644 --- a/dotfiles/emacs.d/init.el +++ b/dotfiles/emacs.d/init.el @@ -1076,17 +1076,30 @@ marking if it still had that." collect (persp-name perspective))) (defun persp-pick-perspective-by-buffer (buffer) - "Select a buffer and go to the perspective to which that buffer belongs. If the buffer belongs to more than one perspective completion will be used to pick the perspective to switch to. Switch the focus to the window in which said buffer is displayed if such a window exists. Otherwise display the buffer in whatever window is active in the perspective." - (interactive (list (funcall persp-interactive-completion-function - "Buffer: " (mapcar 'buffer-name (buffer-list))))) - (let* ((perspectives (persp-get-perspectives-for-buffer (get-buffer buffer))) - (perspective (if (> (length perspectives) 1) - (funcall persp-interactive-completion-function perspectives) - (car perspectives)))) - (persp-switch perspective) - (if (get-buffer-window buffer) - (set-frame-selected-window nil (get-buffer-window buffer)) - (switch-to-buffer buffer)))) + "Select a buffer and go to the perspective to which that buffer +belongs. If the buffer belongs to more than one perspective +completion will be used to pick the perspective to switch to. +Switch the focus to the window in which said buffer is displayed +if such a window exists. Otherwise display the buffer in whatever +window is active in the perspective." + (interactive (list (funcall persp-interactive-completion-function + "Buffer: " (mapcar 'buffer-name (buffer-list))))) + (let* ((perspectives (persp-get-perspectives-for-buffer (get-buffer buffer))) + (perspective (if (> (length perspectives) 1) + (funcall persp-interactive-completion-function + (format "Select the perspective in which you would like to visit %s." + buffer) + perspectives) + (car perspectives)))) + (if (string= (persp-name persp-curr) perspective) + ;; This allows the opening of a single buffer in more than one window + ;; in a single perspective. + (switch-to-buffer buffer) + (progn + (persp-switch perspective) + (if (get-buffer-window buffer) + (set-frame-selected-window nil (get-buffer-window buffer)) + (switch-to-buffer buffer)))))) (defun persp-mode-switch-buffers (arg) (interactive "P")