unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#34656: 27.0.50; Directional window swap states
@ 2019-02-25 20:51 Juri Linkov
  2019-02-26  9:10 ` martin rudalics
  0 siblings, 1 reply; 3+ messages in thread
From: Juri Linkov @ 2019-02-25 20:51 UTC (permalink / raw)
  To: 34656

[-- Attachment #1: Type: text/plain, Size: 1076 bytes --]

Tags: patch
Severity: wishlist

Now we have a useful command ‘window-swap-states’ whose only drawback is that
it operates on a random window, i.e. a next window in some mystic cyclic ordering
whose logic I've never been able to understand.

To simplify its logic, windmove could be extended to support directional swapping
where the user can point at the window whose state should be swapped
with the selected window.

As a funny effect, when windows are arranged as 4x4 square tiles, e.g.

(window-state-put
 '(()
   hc
   (vc
    (leaf (buffer "1"))
    (leaf (buffer "5"))
    (leaf (buffer "9"))
    (leaf (buffer "13")))
   (vc
    (leaf (buffer "2"))
    (leaf (buffer "6"))
    (leaf (buffer "10"))
    (leaf (buffer "14")))
   (vc
    (leaf (buffer "3"))
    (leaf (buffer "7"))
    (leaf (buffer "11"))
    (leaf (buffer "15")))
   (vc
    (leaf (buffer "4"))
    (leaf (buffer "8"))
    (leaf (buffer "12"))
    (leaf (buffer " "))))
 (frame-root-window))

sliding them has the same feeling like solving the 15 puzzle :)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: windmove-swap-states.patch --]
[-- Type: text/x-diff, Size: 2631 bytes --]

diff --git a/lisp/windmove.el b/lisp/windmove.el
index 65270d9bbe..e2422a7df4 100644
--- a/lisp/windmove.el
+++ b/lisp/windmove.el
@@ -750,6 +752,60 @@ windmove-delete-default-keybindings
   (global-set-key (vector prefix (append modifiers '(up)))    'windmove-delete-up)
   (global-set-key (vector prefix (append modifiers '(down)))  'windmove-delete-down))
 
+\f
+;;; Directional window swap states
+
+(defun windmove-swap-states-in-direction (dir)
+  "Swap the states of the selected window and the window at direction DIR.
+When `windmove-wrap-around' is non-nil, takes the window
+from the opposite side of the frame."
+  (let ((other-window (window-in-direction dir nil nil nil
+                                           windmove-wrap-around t)))
+    (cond ((null other-window)
+           (user-error "No window %s from selected window" dir))
+          (t
+           (window-swap-states nil other-window)))))
+
+;;;###autoload
+(defun windmove-swap-states-left ()
+  "Swap the states with the window on the left from the current one."
+  (interactive)
+  (windmove-swap-states-in-direction 'left))
+
+;;;###autoload
+(defun windmove-swap-states-up ()
+  "Swap the states with the window above from the current one."
+  (interactive)
+  (windmove-swap-states-in-direction 'up))
+
+;;;###autoload
+(defun windmove-swap-states-down ()
+  "Swap the states with the window below from the current one."
+  (interactive)
+  (windmove-swap-states-in-direction 'down))
+
+;;;###autoload
+(defun windmove-swap-states-right ()
+  "Swap the states with the window on the right from the current one."
+  (interactive)
+  (windmove-swap-states-in-direction 'right))
+
+;;;###autoload
+(defun windmove-swap-states-default-keybindings (&optional modifiers)
+  "Set up keybindings for directional window swap states.
+Keys are bound to commands that swap the states of the selected window
+with the window in the specified direction.  Keybindings are of the form
+MODIFIERS-{left,right,up,down}, where MODIFIERS is either a list of modifiers
+or a single modifier.  Default value of MODIFIERS is `shift-super'."
+  (interactive)
+  (unless modifiers (setq modifiers '(shift super)))
+  (unless (listp modifiers) (setq modifiers (list modifiers)))
+  (global-set-key (vector (append modifiers '(left)))  'windmove-swap-states-left)
+  (global-set-key (vector (append modifiers '(right))) 'windmove-swap-states-right)
+  (global-set-key (vector (append modifiers '(up)))    'windmove-swap-states-up)
+  (global-set-key (vector (append modifiers '(down)))  'windmove-swap-states-down))
+
+\f
 (provide 'windmove)
 
 ;;; windmove.el ends here

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-02-27 21:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-25 20:51 bug#34656: 27.0.50; Directional window swap states Juri Linkov
2019-02-26  9:10 ` martin rudalics
2019-02-27 21:12   ` Juri Linkov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).