From 0b02e02e8eebad2935e4855e793c01543841f3c1 Mon Sep 17 00:00:00 2001 From: Vasilij Schneidermann Date: Tue, 2 Sep 2014 10:15:21 +0200 Subject: [PATCH] Turn window configuration switcher into command While it is possible to use `eyebrowse-next-window-config` with a numerical prefix to switch to an arbitrary window configuration, it's better to offer a completing interface that can be extended to display tags as well. I intend to offer `completing-read`, `ido-completing-read` and helm soon to have a basic, a less basic, but built-in with flexible matching and a fully-featured selection interface that is able to display meta data, too. At the moment only `completing-read` is used which isn't too bad for an option considering both ido and helm are able to use it for the most basic selection tasks. No matter what, helm will stay an "optional" dependency. --- eyebrowse.el | 54 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/eyebrowse.el b/eyebrowse.el index 82adfaa..17d6af0 100644 --- a/eyebrowse.el +++ b/eyebrowse.el @@ -233,27 +233,6 @@ This function keeps the sortedness intact." (eyebrowse-set 'window-configs (remove (assq slot window-configs) window-configs)))) -(defun eyebrowse-switch-to-window-config (slot) - "Switch to the window config SLOT. -This will save the current window config to -`eyebrowse-current-slot' first, then switch. If -`eyebrowse-switch-back-and-forth-p' is t and -`eyebrowse-current-slot' equals SLOT, this will switch to the -last window config." - (let ((current-slot (eyebrowse-get 'current-slot)) - (last-slot (eyebrowse-get 'last-slot))) - (when (and eyebrowse-switch-back-and-forth-p (= current-slot slot)) - (setq slot last-slot)) - (when (/= current-slot slot) - (run-hooks 'eyebrowse-pre-window-switch-hook) - (eyebrowse-save-window-config current-slot) - (eyebrowse-load-window-config slot) - (eyebrowse-set 'last-slot current-slot) - (eyebrowse-set 'current-slot slot) - (eyebrowse-save-window-config slot) - (eyebrowse-load-window-config slot) - (run-hooks 'eyebrowse-post-window-switch-hook)))) - (defun eyebrowse-update-mode-line () "Return a string representation of the window configurations." (let* ((left-delimiter (propertize eyebrowse-mode-line-left-delimiter @@ -282,6 +261,16 @@ last window config." right-delimiter) ""))) +(defun eyebrowse-read-slot () + (let* ((candidates (--map (number-to-string (car it)) + (eyebrowse-get 'window-configs))) + (last-slot (number-to-string (eyebrowse-get 'last-slot))) + (selection (completing-read "Enter slot: " candidates + nil nil last-slot)) + (slot (string-to-number selection))) + (unless (and (= slot 0) (not (string= selection "0"))) + slot))) + ;; --- public functions ------------------------------------------------------ (defun eyebrowse-init (&optional frame) @@ -289,6 +278,29 @@ last window config." (eyebrowse-set 'last-slot 1 frame) (eyebrowse-set 'current-slot 1 frame)) +(defun eyebrowse-switch-to-window-config (slot) + "Switch to the window config SLOT. +This will save the current window config to +`eyebrowse-current-slot' first, then switch. If +`eyebrowse-switch-back-and-forth-p' is t and +`eyebrowse-current-slot' equals SLOT, this will switch to the +last window config." + (interactive (list (eyebrowse-read-slot))) + (when slot + (let ((current-slot (eyebrowse-get 'current-slot)) + (last-slot (eyebrowse-get 'last-slot))) + (when (and eyebrowse-switch-back-and-forth-p (= current-slot slot)) + (setq slot last-slot)) + (when (/= current-slot slot) + (run-hooks 'eyebrowse-pre-window-switch-hook) + (eyebrowse-save-window-config current-slot) + (eyebrowse-load-window-config slot) + (eyebrowse-set 'last-slot current-slot) + (eyebrowse-set 'current-slot slot) + (eyebrowse-save-window-config slot) + (eyebrowse-load-window-config slot) + (run-hooks 'eyebrowse-post-window-switch-hook))))) + (defun eyebrowse-next-window-config (count) "Switch to the next available window config. If `eyebrowse-wrap-around-p' is t, this will switch from the last