[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master e777570 04/14: Allow to change window action midway
From: |
Oleh Krehel |
Subject: |
[elpa] master e777570 04/14: Allow to change window action midway |
Date: |
Thu, 04 Jun 2015 17:05:15 +0000 |
branch: master
commit e777570a5c73ff89d4251aac5f1f66cdd3dad715
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Allow to change window action midway
* ace-window.el (aw--done): Update.
(aw-dispatch-function): New defvar. Set this to customize the midway
switch behavior.
(aw-action): New defvar. Midway switch will change this variable.
(aw-set-mode-line): New defun.
(aw-dispatch-default): New defun. Catch a char not in `aw-keys' and
perform an action depending on it.
(aw-select): Set `aw-action' to the ACTION arg, and call it in the
end. It can be changed during the selection.
(aw-split-window-vert): New command.
(aw-split-window-horz): New command.
Fixes #44
---
ace-window.el | 73 +++++++++++++++++++++++++++++++++++++++++---------------
1 files changed, 53 insertions(+), 20 deletions(-)
diff --git a/ace-window.el b/ace-window.el
index b0a4344..73808fd 100644
--- a/ace-window.el
+++ b/ace-window.el
@@ -162,8 +162,7 @@ Use M-0 `ace-window' to toggle this value."
(defun aw--done ()
"Clean up mode line and overlays."
;; mode line
- (setq ace-window-mode nil)
- (force-mode-line-update)
+ (aw-set-mode-line nil)
;; background
(mapc #'delete-overlay aw-overlays-back)
(setq aw-overlays-back nil)
@@ -226,9 +225,40 @@ LEAF is (PT . WND)."
(setq aw--flip-keys
(mapcar (lambda (x) (aref (kbd x) 0)) val))))
+(defvar aw-dispatch-function 'aw-dispatch-default
+ "Function to call when a character not in `aw-keys' is pressed.")
+
+(defvar aw-action nil
+ "Function to call at the end of `aw-select'.")
+
+(defun aw-set-mode-line (str)
+ "Set mode line indicator to STR."
+ (setq ace-window-mode str)
+ (force-mode-line-update))
+
+(defun aw-dispatch-default (char)
+ (cond ((eq char ?x)
+ (setq aw-action #'aw-delete-window)
+ (aw-set-mode-line " Ace - Delete Window"))
+ ((eq char ?m)
+ (setq aw-action #'aw-swap-window)
+ (aw-set-mode-line " Ace - Swap Window"))
+ ((memq char aw--flip-keys)
+ (aw-flip-window)
+ (throw 'done 'exit))
+ ((eq char ?v)
+ (setq aw-action #'aw-split-window-vert)
+ (aw-set-mode-line " Ace - Split Vert Window"))
+ ((eq char ?b)
+ (setq aw-action #'aw-split-window-horz)
+ (aw-set-mode-line " Ace - Split Horz Window"))
+ (t
+ (avy-handler-default char))))
+
(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."
+ (setq aw-action action)
(let ((start-window (selected-window))
(next-window-scope (cl-case aw-scope
('global 'visible)
@@ -257,28 +287,21 @@ Amend MODE-LINE to the mode line for the duration of the
selection."
(cons (aw-offset wnd) wnd))
wnd-list)))
(aw--make-backgrounds wnd-list)
- (setq ace-window-mode mode-line)
- (force-mode-line-update)
+ (aw-set-mode-line mode-line)
;; 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)))))
+ (let* ((avy-handler-function aw-dispatch-function)
+ (res (avy-read (avy-tree candidate-list aw-keys)
+ #'aw--lead-overlay
+ #'avy--remove-leading-chars)))
+ (if (eq res 'exit)
+ (setq aw-action nil)
+ (or (cdr res)
+ start-window)))
(aw--done))))))
- (if action
- (funcall action window)
+ (if aw-action
+ (funcall aw-action window)
window)))
;;* Interactive
@@ -423,6 +446,16 @@ Windows are numbered top down, left to right."
(aw--push-window this-window)
(swap-windows this-window window)))))
+(defun aw-split-window-vert (window)
+ "Split WINDOW vertically."
+ (select-window window)
+ (split-window-vertically))
+
+(defun aw-split-window-horz (window)
+ "Split WINDOW horizontally."
+ (select-window window)
+ (split-window-horizontally))
+
(defun aw-offset (window)
"Return point in WINDOW that's closest to top left corner.
The point is writable, i.e. it's not part of space after newline."
- [elpa] master updated (77c062f -> a4ab5a4), Oleh Krehel, 2015/06/04
- [elpa] master 4357c90 02/14: Add a require, Oleh Krehel, 2015/06/04
- [elpa] master cf91510 05/14: README.md: Add a section on midway switch, Oleh Krehel, 2015/06/04
- [elpa] master e777570 04/14: Allow to change window action midway,
Oleh Krehel <=
- [elpa] master 1487ae1 07/14: Update README.md, Oleh Krehel, 2015/06/04
- [elpa] master eef897e 08/14: Update README.md, Oleh Krehel, 2015/06/04
- [elpa] master dd84ff6 09/14: Fix aw-ignore-current for 3 windows, Oleh Krehel, 2015/06/04
- [elpa] master 56ef753 06/14: Allow to midway switch from less than 3 windows, Oleh Krehel, 2015/06/04
- [elpa] master c82d439 03/14: Update requires, Oleh Krehel, 2015/06/04
- [elpa] master 155b6c6 11/14: ace-window.el: Bump version, Oleh Krehel, 2015/06/04
- [elpa] master 4546f20 01/14: Allow to switch the action in the middle of ace-window, Oleh Krehel, 2015/06/04
- [elpa] master e5638b1 12/14: ace-window.el (aw-swap-invert): New defcustom, Oleh Krehel, 2015/06/04
- [elpa] master 243ee46 10/14: Allow to switch to all empty buffers (read-only as well), Oleh Krehel, 2015/06/04
- [elpa] master 97a2f93 13/14: Small changes to README, Oleh Krehel, 2015/06/04