[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master a3d4817 63/68: Allow switching to the previous window
From: |
Oleh Krehel |
Subject: |
[elpa] master a3d4817 63/68: Allow switching to the previous window |
Date: |
Sat, 21 Mar 2015 19:07:10 +0000 |
branch: master
commit a3d48170a40a7dbd94ae144c7683f50509d8193b
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Allow switching to the previous window
* ace-window.el (aw--flip-keys): New defvar.
(aw-flip-keys): New defcustom. If one of the keys on this list is
pressed, when `aw-keys' are expected, instead of giving an error, select
the previously visited window.
(aw-select): Update.
(aw--window-ring): New defvar. Store the last 10 selected windows.
(aw--push-window): Remember window into `aw--window-ring'.
(aw--pop-window): Pop window from `aw--window-ring'.
(aw-switch-to-window): Insert the window into `aw--window-ring'.
(aw-swap-window): Insert the window into `aw--window-ring'.
(aw-flip-window): New defun, do the flipping action without having to go
though the `ace-select-window' dispatch.
Fixes #23.
---
ace-window.el | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 50 insertions(+), 5 deletions(-)
diff --git a/ace-window.el b/ace-window.el
index 86f910c..b688a0e 100644
--- a/ace-window.el
+++ b/ace-window.el
@@ -205,6 +205,16 @@ LEAF is (PT . WND)."
ol))
wnd-list))))
+(defvar aw--flip-keys nil
+ "Pre-processed `aw-flip-keys'.")
+
+(defcustom aw-flip-keys '("n")
+ "Keys which should select the last window."
+ :set (lambda (sym val)
+ (set sym val)
+ (setq aw--flip-keys
+ (mapcar (lambda (x) (aref (kbd x) 0)) val))))
+
(defun aw-select (mode-line)
"Return a selected other window.
Amend MODE-LINE to the mode line for the duration of the selection."
@@ -239,10 +249,16 @@ Amend MODE-LINE to the mode line for the duration of the
selection."
(force-mode-line-update)
;; turn off helm transient map
(remove-hook 'post-command-hook 'helm--maybe-update-keymap)
- (unwind-protect (or (cdr (avy-read (avy-tree candidate-list aw-keys)
- #'aw--lead-overlay
- #'aw--remove-leading-chars))
- start-window)
+ (unwind-protect
+ (condition-case err
+ (or (cdr (avy-read (avy-tree candidate-list aw-keys)
+ #'aw--lead-overlay
+ #'aw--remove-leading-chars))
+ start-window)
+ (error
+ (if (memq (caddr err) aw--flip-keys)
+ (aw--pop-window)
+ (signal (car err) (cdr err)))))
(aw--done)))))))
;;* Interactive
@@ -318,6 +334,27 @@ Windows are numbered top down, left to right."
((< (cadr e1) (cadr e2))
t))))
+(defvar aw--window-ring (make-ring 10)
+ "Hold the window switching history.")
+
+(defun aw--push-window (window)
+ "Store WINDOW to `aw--window-ring'."
+ (when (or (zerop (ring-length aw--window-ring))
+ (not (equal
+ (ring-ref aw--window-ring 0)
+ window)))
+ (ring-insert aw--window-ring (selected-window))))
+
+(defun aw--pop-window ()
+ "Return the removed top of `aw--window-ring'."
+ (let (res)
+ (condition-case nil
+ (while (not (window-live-p
+ (setq res (ring-remove aw--window-ring 0)))))
+ (error
+ (error "No previous windows stored")))
+ res))
+
(defun aw-switch-to-window (window)
"Switch to the window WINDOW."
(let ((frame (window-frame window)))
@@ -325,9 +362,16 @@ Windows are numbered top down, left to right."
(not (eq frame (selected-frame))))
(select-frame-set-input-focus frame))
(if (window-live-p window)
- (select-window window)
+ (progn
+ (aw--push-window (selected-window))
+ (select-window window))
(error "Got a dead window %S" window))))
+(defun aw-flip-window ()
+ "Switch to the window you were previously in."
+ (interactive)
+ (aw-switch-to-window (aw--pop-window)))
+
(defun aw-delete-window (window)
"Delete window WINDOW."
(let ((frame (window-frame window)))
@@ -356,6 +400,7 @@ Windows are numbered top down, left to right."
(select-frame-set-input-focus (window-frame window)))
(when (and (window-live-p window)
(not (eq window this-window)))
+ (aw--push-window this-window)
(swap-windows this-window window)))))
(defun aw-offset (window)
- [elpa] master c897759 55/68: Update avy interface, (continued)
- [elpa] master c897759 55/68: Update avy interface, Oleh Krehel, 2015/03/21
- [elpa] master 574b3bd 57/68: Add `aw-leading-char-style' extra-awesome custom var, Oleh Krehel, 2015/03/21
- [elpa] master 8b5f10a 53/68: Update outlines, Oleh Krehel, 2015/03/21
- [elpa] master d7cafcb 56/68: avy-jump.el: add example commands using avy, Oleh Krehel, 2015/03/21
- [elpa] master fcc64ab 59/68: avy-jump.el (avi--regex-candidates): Add optional bounds, Oleh Krehel, 2015/03/21
- [elpa] master d932090 60/68: avy-jump.el (avi--overlay): Fix bug, Oleh Krehel, 2015/03/21
- [elpa] master f0050fb 62/68: avy.el (avy-read): Give a more precise error, Oleh Krehel, 2015/03/21
- [elpa] master 4e5ca87 58/68: avy-jump.el: Major update, Oleh Krehel, 2015/03/21
- [elpa] master ee0fa60 64/68: Add show keys on mode line feature., Oleh Krehel, 2015/03/21
- [elpa] master 30abc92 61/68: avy-jump.el (avi-goto-word-0): Simplify, Oleh Krehel, 2015/03/21
- [elpa] master a3d4817 63/68: Allow switching to the previous window,
Oleh Krehel <=
- [elpa] master b83b941 65/68: Add `ace-window-display-mode' minor mode, Oleh Krehel, 2015/03/21
- [elpa] master d81f079 54/68: Remove dependency on ace-jump-mode, Oleh Krehel, 2015/03/21
- [elpa] master 2580bf9 67/68: ace-window.el (aw-mode-line-face): Inherit from mode-line-buffer-id, Oleh Krehel, 2015/03/21
- [elpa] master 22a3145 66/68: Make sure not to extend `mode-line-format' twice, Oleh Krehel, 2015/03/21
- [elpa] master b11606c 68/68: Add 'packages/ace-window/' from commit '2580bf9bd7f66ed4e923a125ee8efcc4b6a043e0', Oleh Krehel, 2015/03/21