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.
This commit is contained in:
Vasilij Schneidermann
2014-09-02 10:15:21 +02:00
parent 89a46fb2df
commit 0b02e02e8e

View File

@ -233,27 +233,6 @@ This function keeps the sortedness intact."
(eyebrowse-set 'window-configs (eyebrowse-set 'window-configs
(remove (assq slot window-configs) 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 () (defun eyebrowse-update-mode-line ()
"Return a string representation of the window configurations." "Return a string representation of the window configurations."
(let* ((left-delimiter (propertize eyebrowse-mode-line-left-delimiter (let* ((left-delimiter (propertize eyebrowse-mode-line-left-delimiter
@ -282,6 +261,16 @@ last window config."
right-delimiter) 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 ------------------------------------------------------ ;; --- public functions ------------------------------------------------------
(defun eyebrowse-init (&optional frame) (defun eyebrowse-init (&optional frame)
@ -289,6 +278,29 @@ last window config."
(eyebrowse-set 'last-slot 1 frame) (eyebrowse-set 'last-slot 1 frame)
(eyebrowse-set 'current-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) (defun eyebrowse-next-window-config (count)
"Switch to the next available window config. "Switch to the next available window config.
If `eyebrowse-wrap-around-p' is t, this will switch from the last If `eyebrowse-wrap-around-p' is t, this will switch from the last