emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 4546f20 01/14: Allow to switch the action in the middle of


From: Oleh Krehel
Subject: [elpa] master 4546f20 01/14: Allow to switch the action in the middle of ace-window
Date: Thu, 04 Jun 2015 17:05:13 +0000

branch: master
commit 4546f20f441d28ca33a8717b2942810bf46b4492
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Allow to switch the action in the middle of ace-window
    
    * ace-window.el (aw-select): Add an optional arg ACTION. Call it on
      selected window. Set `avy-handler-function' to catch ?x and modify
      ACTION into 'aw-delete-window.
    (ace-select-window): Use callback-style.
    
    Re #44
---
 ace-window.el |   89 +++++++++++++++++++++++++++++++-------------------------
 1 files changed, 49 insertions(+), 40 deletions(-)

diff --git a/ace-window.el b/ace-window.el
index 791b34d..e1442a6 100644
--- a/ace-window.el
+++ b/ace-window.el
@@ -226,7 +226,7 @@ LEAF is (PT . WND)."
          (setq aw--flip-keys
                (mapcar (lambda (x) (aref (kbd x) 0)) val))))
 
-(defun aw-select (mode-line)
+(defun aw-select (mode-line &optional action)
   "Return a selected other window.
 Amend MODE-LINE to the mode line for the duration of the selection."
   (let ((start-window (selected-window))
@@ -234,51 +234,60 @@ Amend MODE-LINE to the mode line for the duration of the 
selection."
                              ('global 'visible)
                              ('frame 'frame)))
         (wnd-list (aw-window-list))
-        final-window)
-    (cl-case (length wnd-list)
-      (0
-       start-window)
-      (1
-       (car wnd-list))
-      (2
-       (setq final-window (next-window nil nil next-window-scope))
-       (while (and (aw-ignored-p final-window)
-                   (not (equal final-window start-window)))
-         (setq final-window (next-window final-window nil next-window-scope)))
-       final-window)
-      (t
-       (let ((candidate-list
-              (mapcar (lambda (wnd)
-                        ;; can't jump if the buffer is empty
-                        (with-current-buffer (window-buffer wnd)
-                          (when (= 0 (buffer-size))
-                            (insert " ")))
-                        (cons (aw-offset wnd) wnd))
-                      wnd-list)))
-         (aw--make-backgrounds wnd-list)
-         (setq ace-window-mode mode-line)
-         (force-mode-line-update)
-         ;; turn off helm transient map
-         (remove-hook 'post-command-hook 'helm--maybe-update-keymap)
-         (unwind-protect
-              (condition-case err
-                  (or (cdr (avy-read (avy-tree candidate-list aw-keys)
-                                     #'aw--lead-overlay
-                                     #'avy--remove-leading-chars))
-                      start-window)
-                (error
-                 (if (memq (nth 2 err) aw--flip-keys)
-                     (aw--pop-window)
-                   (signal (car err) (cdr err)))))
-           (aw--done)))))))
+        window)
+    (setq window
+          (cl-case (length wnd-list)
+            (0
+             start-window)
+            (1
+             (car wnd-list))
+            (2
+             (let ((wnd (next-window nil nil next-window-scope)))
+               (while (and (aw-ignored-p wnd)
+                           (not (equal wnd start-window)))
+                 (setq wnd (next-window wnd nil next-window-scope)))
+               wnd))
+            (t
+             (let ((candidate-list
+                    (mapcar (lambda (wnd)
+                              ;; can't jump if the buffer is empty
+                              (with-current-buffer (window-buffer wnd)
+                                (when (= 0 (buffer-size))
+                                  (insert " ")))
+                              (cons (aw-offset wnd) wnd))
+                            wnd-list)))
+               (aw--make-backgrounds wnd-list)
+               (setq ace-window-mode mode-line)
+               (force-mode-line-update)
+               ;; turn off helm transient map
+               (remove-hook 'post-command-hook 'helm--maybe-update-keymap)
+               (unwind-protect
+                    (condition-case err
+                        (let* ((avy-handler-function (lambda (char)
+                                                       (if (eq char ?x)
+                                                           (setq action 
#'aw-delete-window)
+                                                         (avy-handler-default 
char))))
+                               (res (avy-read (avy-tree candidate-list aw-keys)
+                                              #'aw--lead-overlay
+                                              #'avy--remove-leading-chars)))
+                          (or (cdr res)
+                              start-window))
+                      (error
+                       (if (memq (nth 2 err) aw--flip-keys)
+                           (aw--pop-window)
+                         (signal (car err) (cdr err)))))
+                 (aw--done))))))
+    (if action
+        (funcall action window)
+      window)))
 
 ;;* Interactive
 ;;;###autoload
 (defun ace-select-window ()
   "Ace select window."
   (interactive)
-  (aw-switch-to-window
-   (aw-select " Ace - Window")))
+  (aw-select " Ace - Window"
+             #'aw-switch-to-window))
 
 ;;;###autoload
 (defun ace-delete-window ()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]