Make switching forward and backward work like Vim.

This commit is contained in:
Vasilij Schneidermann
2014-03-31 12:04:58 +02:00
parent 8c38149446
commit fe04ba8e54

View File

@ -246,35 +246,41 @@ last window config."
;; --- public functions ------------------------------------------------------ ;; --- public functions ------------------------------------------------------
(defun eyebrowse-next-window-config () (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
to the first one." to the first one. When used with a numerical argument, switch to
(interactive) window config COUNT."
(interactive "P")
(let* ((match (assq eyebrowse-current-slot eyebrowse-window-configs)) (let* ((match (assq eyebrowse-current-slot eyebrowse-window-configs))
(index (-elem-index match eyebrowse-window-configs))) (index (-elem-index match eyebrowse-window-configs)))
(if count
(eyebrowse-switch-to-window-config count)
(when index (when index
(if (< (1+ index) (length eyebrowse-window-configs)) (if (< (1+ index) (length eyebrowse-window-configs))
(eyebrowse-switch-to-window-config (eyebrowse-switch-to-window-config
(car (nth (1+ index) eyebrowse-window-configs))) (car (nth (1+ index) eyebrowse-window-configs)))
(when eyebrowse-wrap-around-p (when eyebrowse-wrap-around-p
(eyebrowse-switch-to-window-config (eyebrowse-switch-to-window-config
(caar eyebrowse-window-configs))))))) (caar eyebrowse-window-configs))))))))
(defun eyebrowse-prev-window-config () (defun eyebrowse-prev-window-config (count)
"Switch to the previous available window config. "Switch to the previous available window config.
If `eyebrowse-wrap-around-p' is t, this will switch from the If `eyebrowse-wrap-around-p' is t, this will switch from the
first to the last one." first to the last one. When used with a numerical argument,
(interactive) switch COUNT window configs backwards and always wrap around."
(interactive "P")
(let* ((match (assq eyebrowse-current-slot eyebrowse-window-configs)) (let* ((match (assq eyebrowse-current-slot eyebrowse-window-configs))
(index (-elem-index match eyebrowse-window-configs))) (index (-elem-index match eyebrowse-window-configs)))
(if count
(eyebrowse-prev-window-config (when (> count 1) (eyebrowse-prev-window-config (1- count))))
(when index (when index
(if (> index 0) (if (> index 0)
(eyebrowse-switch-to-window-config (eyebrowse-switch-to-window-config
(car (nth (1- index) eyebrowse-window-configs))) (car (nth (1- index) eyebrowse-window-configs)))
(when eyebrowse-wrap-around-p (when eyebrowse-wrap-around-p
(eyebrowse-switch-to-window-config (eyebrowse-switch-to-window-config
(caar (last eyebrowse-window-configs)))))))) (caar (last eyebrowse-window-configs)))))))))
(defun eyebrowse-last-window-config () (defun eyebrowse-last-window-config ()
"Switch to the last window config." "Switch to the last window config."
@ -289,8 +295,8 @@ another appropriate window config."
(when (> (length eyebrowse-window-configs) 1) (when (> (length eyebrowse-window-configs) 1)
(if (equal (assq eyebrowse-current-slot eyebrowse-window-configs) (if (equal (assq eyebrowse-current-slot eyebrowse-window-configs)
(car (last eyebrowse-window-configs))) (car (last eyebrowse-window-configs)))
(eyebrowse-prev-window-config) (eyebrowse-prev-window-config nil)
(eyebrowse-next-window-config)) (eyebrowse-next-window-config nil))
(eyebrowse-delete-window-config eyebrowse-last-slot))) (eyebrowse-delete-window-config eyebrowse-last-slot)))
;;;###autoload ;;;###autoload