From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#34656: 27.0.50; Directional window swap states Date: Mon, 25 Feb 2019 22:51:06 +0200 Organization: LINKOV.NET Message-ID: <87imx7egn9.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="259998"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu) To: 34656@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Feb 25 22:14:25 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gyNZx-0015RN-6f for geb-bug-gnu-emacs@m.gmane.org; Mon, 25 Feb 2019 22:14:25 +0100 Original-Received: from localhost ([127.0.0.1]:44397 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyNZw-0002gJ-4n for geb-bug-gnu-emacs@m.gmane.org; Mon, 25 Feb 2019 16:14:24 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:36591) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyNZk-0002dX-O5 for bug-gnu-emacs@gnu.org; Mon, 25 Feb 2019 16:14:13 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyNZf-0003Xb-4m for bug-gnu-emacs@gnu.org; Mon, 25 Feb 2019 16:14:10 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:38262) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gyNZb-0003Rf-KB for bug-gnu-emacs@gnu.org; Mon, 25 Feb 2019 16:14:06 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gyNZb-0005Aa-Ez for bug-gnu-emacs@gnu.org; Mon, 25 Feb 2019 16:14:03 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 25 Feb 2019 21:14:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 34656 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.155112924219854 (code B ref -1); Mon, 25 Feb 2019 21:14:03 +0000 Original-Received: (at submit) by debbugs.gnu.org; 25 Feb 2019 21:14:02 +0000 Original-Received: from localhost ([127.0.0.1]:51802 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gyNZZ-0005A7-Ro for submit@debbugs.gnu.org; Mon, 25 Feb 2019 16:14:02 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:50341) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gyNZY-00059e-NK for submit@debbugs.gnu.org; Mon, 25 Feb 2019 16:14:01 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:58157) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gyNZN-000348-GX for submit@debbugs.gnu.org; Mon, 25 Feb 2019 16:13:51 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:36466) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyNZM-0002by-9k for bug-gnu-emacs@gnu.org; Mon, 25 Feb 2019 16:13:49 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyNZH-0002sJ-Ca for bug-gnu-emacs@gnu.org; Mon, 25 Feb 2019 16:13:47 -0500 Original-Received: from bisque.maple.relay.mailchannels.net ([23.83.214.18]:53315) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gyNZ7-0001tg-Nz for bug-gnu-emacs@gnu.org; Mon, 25 Feb 2019 16:13:38 -0500 X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 3B89E50267E for ; Mon, 25 Feb 2019 21:13:11 +0000 (UTC) Original-Received: from pdx1-sub0-mail-a54.g.dreamhost.com (unknown [100.96.28.213]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id F03FA50327C for ; Mon, 25 Feb 2019 21:13:10 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from pdx1-sub0-mail-a54.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.16.3); Mon, 25 Feb 2019 21:13:11 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|jurta@jurta.org X-MailChannels-Auth-Id: dreamhost X-Lonely-Stop: 173a8d4374906e10_1551129191111_1695841162 X-MC-Loop-Signature: 1551129191111:2871958990 X-MC-Ingress-Time: 1551129191111 Original-Received: from pdx1-sub0-mail-a54.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a54.g.dreamhost.com (Postfix) with ESMTP id 8C6E381A6A for ; Mon, 25 Feb 2019 13:13:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=linkov.net; h=from:to :subject:date:message-id:mime-version:content-type; s= linkov.net; bh=1kcWpQyjK6OA6V3rQ3nX5N48Vlg=; b=ocBWcYbwNYYsUCbaa MCrMiRpWnq9ZWCwLrJfrALEaBC54866OjnZPGvAvWgGiUJJ9GGQFcHmbp3ZbCRR5 LIs1JkMD3DyqKWjkawV6c2JUJs+dKdQgd2MSLUpmBh2qTOOd+xYWmg4lWreUvkL6 ESjOvWU6vvpEC8VNCyPCXcn/hQ= Original-Received: from mail.jurta.org (m91-129-98-103.cust.tele2.ee [91.129.98.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: jurta@jurta.org) by pdx1-sub0-mail-a54.g.dreamhost.com (Postfix) with ESMTPSA id 3E8A881A6B for ; Mon, 25 Feb 2019 13:13:08 -0800 (PST) X-DH-BACKEND: pdx1-sub0-mail-a54 X-VR-OUT-STATUS: OK X-VR-OUT-SCORE: 0 X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedutddrudejgddugeekucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuggftfghnshhusghstghrihgsvgdpffftgfetoffjqffuvfenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvffuohffkfgfgggtsehmtderredtreejnecuhfhrohhmpefluhhrihcunfhinhhkohhvuceojhhurhhisehlihhnkhhovhdrnhgvtheqnecukfhppeeluddruddvledrleekrddutdefnecurfgrrhgrmhepmhhouggvpehsmhhtphdphhgvlhhopehmrghilhdrjhhurhhtrgdrohhrghdpihhnvghtpeeluddruddvledrleekrddutdefpdhrvghtuhhrnhdqphgrthhhpefluhhrihcunfhinhhkohhvuceojhhurhhisehlihhnkhhovhdrnhgvtheqpdhmrghilhhfrhhomhepjhhurhhisehlihhnkhhovhdrnhgvthdpnhhrtghpthhtohepsghughdqghhnuhdqvghmrggtshesghhnuhdrohhrghenucevlhhushhtvghrufhiiigvpedt X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:155782 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Tags: patch Severity: wishlist Now we have a useful command =E2=80=98window-swap-states=E2=80=99 whose o= nly 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 :) --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=windmove-swap-states.patch 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)) + +;;; 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)) + + (provide 'windmove) ;;; windmove.el ends here --=-=-=--