From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Arthur Miller Newsgroups: gmane.emacs.bugs Subject: bug#41438: [PATCH] Allow windmove keys to be bound without prefix or modifiers Date: Tue, 25 May 2021 13:36:22 +0200 Message-ID: References: <87imgpw7k3.fsf@warpmail.net> <87mu36enhl.fsf@posteo.net> <8735uru1py.fsf@gnus.org> <871r9yjyv5.fsf@posteo.net> <87h7irqtvf.fsf@gnus.org> <87im37p2b4.fsf@icterid> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38824"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (windows-nt) Cc: 41438@debbugs.gnu.org, Lars Ingebrigtsen , Juri Linkov To: Philip Kaludercic Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue May 25 13:37:10 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1llVN0-0009tG-ES for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 25 May 2021 13:37:10 +0200 Original-Received: from localhost ([::1]:39258 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1llVMz-0001c2-Hc for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 25 May 2021 07:37:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33954) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llVMs-0001bc-5R for bug-gnu-emacs@gnu.org; Tue, 25 May 2021 07:37:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:33308) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1llVMr-0002Kw-UL for bug-gnu-emacs@gnu.org; Tue, 25 May 2021 07:37:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1llVMr-0001OE-Pb for bug-gnu-emacs@gnu.org; Tue, 25 May 2021 07:37:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Arthur Miller Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 25 May 2021 11:37:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41438 X-GNU-PR-Package: emacs Original-Received: via spool by 41438-submit@debbugs.gnu.org id=B41438.16219425955305 (code B ref 41438); Tue, 25 May 2021 11:37:01 +0000 Original-Received: (at 41438) by debbugs.gnu.org; 25 May 2021 11:36:35 +0000 Original-Received: from localhost ([127.0.0.1]:44854 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1llVMQ-0001NV-PF for submit@debbugs.gnu.org; Tue, 25 May 2021 07:36:35 -0400 Original-Received: from mail-db8eur06olkn2043.outbound.protection.outlook.com ([40.92.51.43]:51296 helo=EUR06-DB8-obe.outbound.protection.outlook.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1llVMN-0001NF-4v for 41438@debbugs.gnu.org; Tue, 25 May 2021 07:36:33 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bWFOIFbQWkpbq/IXTEWYO6fq7EXyy4xGXcHbGmPX0m1AA2+NS9fGqs76PQXxosVtJljiqWH64qoafwJqqBs3J3Vk8/aPVwHkFZy78C4iqqL4l5g8988l3UYX7SFPRs0N3uM9Of3wjvpsHg+xivR4Vzp1VUVF+In2yHKdSmRQv1orPJet8+tL5Oxwh8FAf1OuncUmOOO0g9CBcFB94e2Otd4vkWvPARclNNAGybgvg0ECc7BqIPxeYSVCucOONNwnCaOD4eQXfV65DuR9iU4W+GTqqAg1jj9L6YkIbqkmZR7ClO1UGeIxcUxPwLLY33nHCj8gX2bOojQPrWjmfVvPlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6hengJvTDhmbbE2Fj9rPFnw1lB0MURClMkU2m36Thiw=; b=lNJpDHwHcia63KT49XH7dgwQDvWhWf31YCrMQnCF5r/dt1ExsOjrc8181I3Mmf+J2F8kgXMS27dpkKLCIGKqHMfWBEgRSH3uKY5vNLyJyWm1bbxAsxST8zDxrrPt/+Q4pYE9joNLOzodCKYRRPnB6k7Ymeg63zRb2t0Km1Vep+0oyf4i+szMruWgyIxQ5+E+YqoV6grN0jWR5KKRIo5XQC50My9dSkepPqaIaseC9TIJedDIa/zZ+QbngL5IX94yFtgN53dBsZIcZEizVRkTgdxGh4aP9hvNWIp/mbN6d27Iu7TsfT22LWw0tDfODhMJsNDkSYvoCTkhvWcMUBUhZg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=live.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6hengJvTDhmbbE2Fj9rPFnw1lB0MURClMkU2m36Thiw=; b=gJAR/2EkRiAjAeIP8DG/j3eeKvSgv8z55SZoud3YQsaA1R5PQvPlwukR4Lgcck8THzHXw3/XPMZaHn3CN6s/Zr+KSI2gp93bGVHuJgCwOkAPUFLCRWpT2NxQBr8XOfYc7jg4MszMKgAInIJ4QNJOTkOC1nwvABSeyVfGqOV0M96A9kMKngycNIX5iPhEcliZaBWLp/+OFcP1t9Ml0YNag76POQpN/gsgnWZi6Ac2H/P7JmPWcMDCzoI3J21plRdMW2FIRIybt6VCGfc9QDtfGFhxtEHZsf8J61ddiAB68fjgUOwAs0HtMy5vwAqshuLJULP/QybgmGTcaR/Ewm1oBw== Original-Received: from AM7EUR06FT061.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc36::44) by AM7EUR06HT146.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc36::272) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.25; Tue, 25 May 2021 11:36:24 +0000 Original-Received: from AM9PR09MB4977.eurprd09.prod.outlook.com (2a01:111:e400:fc36::44) by AM7EUR06FT061.mail.protection.outlook.com (2a01:111:e400:fc36::95) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.25 via Frontend Transport; Tue, 25 May 2021 11:36:24 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:CB37B0564746345B64F3AE74241FDD9743D14843020C892A17B157A1C05F0A30; UpperCasedChecksum:973D12E0E1AA1793FFFB7A8762F4F2C5FF48E00F1CB708F11E91F4DB804C0C1F; SizeAsReceived:7634; Count:46 Original-Received: from AM9PR09MB4977.eurprd09.prod.outlook.com ([fe80::d1c1:2a0d:3b2b:4591]) by AM9PR09MB4977.eurprd09.prod.outlook.com ([fe80::d1c1:2a0d:3b2b:4591%7]) with mapi id 15.20.4173.020; Tue, 25 May 2021 11:36:23 +0000 In-Reply-To: <87im37p2b4.fsf@icterid> (Philip Kaludercic's message of "Tue, 25 May 2021 09:53:19 +0000") X-TMN: [g4dgrWknOIC8uCvOpvlAv+KbKxVu86du] X-ClientProxiedBy: AM6PR08CA0016.eurprd08.prod.outlook.com (2603:10a6:20b:b2::28) To AM9PR09MB4977.eurprd09.prod.outlook.com (2603:10a6:20b:304::20) X-Microsoft-Original-Message-ID: <82pmxfniyx.fsf@live.com> X-MS-Exchange-MessageSentRepresentingType: 1 Original-Received: from HP-Laptop.homepc (81.232.177.30) by AM6PR08CA0016.eurprd08.prod.outlook.com (2603:10a6:20b:b2::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.23 via Frontend Transport; Tue, 25 May 2021 11:36:23 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 46 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 6f292078-fbbc-4ecc-0fb1-08d91f715318 X-MS-TrafficTypeDiagnostic: AM7EUR06HT146: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: h8fKnjLJE0aLEUX4AzHc0wbkUdSM1t/GTGD35bBgmyHijEEswu9vqNFJzIxVNst/lKaVwnw4SDVxYQ5/jVGE6PS0VrRjOVfBUeICBcTrGccBxl6czxtgB/NwzhUF86OgFyz80p+ou1KXXhl2YxLZrVjg7eZWbmNtpp6952AHlPbkApPe+nhh0JMAjBVmkiIumEO+SWcve6fsfQAOiONk1dBs0YOiwtLrtst4FYSYrj08UEUOTKJHtl/mvJxyTxr3tfRxd0TR+nW7MKFSomNpMMUieVDujy1crKIsZ2G2W7xiK0ou+W16/DmLtlvgZakPkKNfjffUGpUodFDQGN30fYW26w4iYK3JgwP+qmAUee6VvpdbfVmd8ZnH/rnxVSwj7jTEOjgWMrrXA+Z/GBPtKg== X-MS-Exchange-AntiSpam-MessageData: 9yKzkfjoPrDjsSVd1CJjz+ztHvocDH2XcDqKjy+XAKxjCq+zKtin0n/q9zRBTfkjXhCj+tpTY3gZfz23+Mm9nuGSPZq54xT5v4cj/PaDfXBywFRwdcHLgpRe3JXP6Ds3MZBXagWDFE0o1N08+2e9SA== X-OriginatorOrg: live.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6f292078-fbbc-4ecc-0fb1-08d91f715318 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 May 2021 11:36:23.9429 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: AM7EUR06FT061.eop-eur06.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7EUR06HT146 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:207192 Archived-At: Philip Kaludercic writes: If you are already patching windmove.el, can you consider adding bindings for these funcitions too (defined in window.el): enlarge-window-horizontally shrink-window-horizontally As well as add these two wrappers for vertical operations: #+begin_src emacs-lisp ;;;###autoload (defun enlarge-window-vertically (delta) "Make selected window DELTA columns wider. Interactively, if no argument is given, make selected window one column wider." (interactive "p") (enlarge-window delta nil)) ;;;###autoload (defun shrink-window-vertically (delta) "Make selected window DELTA columns narrower. Interactively, if no argument is given, make selected window one column narrower." (interactive "p") (shrink-window delta nil)) #+end_src I have been using those for long time myself since I prefer to do everything from the keyboard. Maybe someone else finds them useful too; they have been in my config on GH for long time. > Lars Ingebrigtsen writes: > >> Philip Kaludercic writes: >> >>> The code should probably be refactored, moving more of the common >>> functionality into it's own function, but I am primarily wondering if >>> using emulation-mode-map-alists the way I am proposing it here is ok. Or >>> should I prefer minor-mode-map-alist? >> >> Making windmove into a regular (global) minor mode would be less >> surprising, I think, but I'm not really familiar with windmove, and >> whether that would be an easy rewrite? > > I have tried this out, and it seems somewhat elegant. From my testing, > it seems to behave the same way as the previous approach. > > -- > Philip K. > > From 2f7a8d89cdb5835cf875bc1f2bcfcb6755a0e0c0 Mon Sep 17 00:00:00 2001 > From: Philip Kaludercic > Date: Tue, 25 May 2021 11:47:51 +0200 > Subject: [PATCH] Improve windmove-*-default-keybindings fuctions > > * windmove.el (windmove-default-map): Add special map for windmove > commands > (windmove-mode): Add minor mode for activating windmove-default-map > (windmove-install-defaults): Add general function for manipulating > windmove-default-map > (windmove-default-keybindings): Use windmove-install-defaults > (windmove-display-default-keybindings): Use windmove-install-defaults > (windmove-delete-default-keybindings): Use windmove-install-defaults > (windmove-swap-states-default-keybindings): Use > windmove-install-defaults > --- > lisp/windmove.el | 84 ++++++++++++++++++++++++++++++++++++------------ > 1 file changed, 63 insertions(+), 21 deletions(-) > > diff --git a/lisp/windmove.el b/lisp/windmove.el > index e4ea8e0f69..5a81893bf9 100644 > --- a/lisp/windmove.el > +++ b/lisp/windmove.el > @@ -426,19 +426,46 @@ windmove-down > ;; I don't think these bindings will work on non-X terminals; you > ;; probably want to use different bindings in that case. > > +(defvar windmove-default-map (make-sparse-keymap) > + "Map used by `windmove-install-defaults'.") > + > +(define-minor-mode windmove-mode > + "Global minor mode for default windmove commands." > + :keymap windmove-default-map > + :init-value t > + :global t) > + > +(defun windmove-install-defaults (modifiers alist) > + "Install keys as specified by ALIST. > +Every element of ALIST has the form (FN KEY), where KEY is > +appended to MODIFIERS, before installing the key. Previous > +bindings of FN are unbound." > + (dolist (bind alist) > + (when (or (memq (cadr bind) '(left right up down)) > + (not (null modifiers))) > + (dolist (old (where-is-internal (car bind) windmove-default-map)) > + (define-key windmove-default-map old nil)) > + (define-key windmove-default-map > + (vector (append modifiers (cdr bind))) > + (car bind))))) > + > ;;;###autoload > (defun windmove-default-keybindingsq (&optional modifiers) > "Set up keybindings for `windmove'. > Keybindings are of the form MODIFIERS-{left,right,up,down}, > where MODIFIERS is either a list of modifiers or a single modifier. > +If MODIFIERS is `none', the keybindings will be directly bound to > +the arrow keys. > Default value of MODIFIERS is `shift'." > (interactive) > (unless modifiers (setq modifiers 'shift)) > + (when (eq modifiers 'none) (setq modifiers nil)) > (unless (listp modifiers) (setq modifiers (list modifiers))) > - (global-set-key (vector (append modifiers '(left))) 'windmove-left) > - (global-set-key (vector (append modifiers '(right))) 'windmove-right) > - (global-set-key (vector (append modifiers '(up))) 'windmove-up) > - (global-set-key (vector (append modifiers '(down))) 'windmove-down)) > + (windmove-install-defaults modifiers > + '((windmove-left left) > + (windmove-right right) > + (windmove-up up) > + (windmove-down down)))) > > > ;;; Directional window display and selection > @@ -546,17 +573,21 @@ windmove-display-default-keybindings > Keys are bound to commands that display the next buffer 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. > +If MODIFIERS is `none', the keybindings will be directly bound to > +the arrow keys. > Default value of MODIFIERS is `shift-meta'." > (interactive) > (unless modifiers (setq modifiers '(shift meta))) > + (when (eq modifiers 'none) (setq modifiers nil)) > (unless (listp modifiers) (setq modifiers (list modifiers))) > - (global-set-key (vector (append modifiers '(left))) 'windmove-display-left) > - (global-set-key (vector (append modifiers '(right))) 'windmove-display-right) > - (global-set-key (vector (append modifiers '(up))) 'windmove-display-up) > - (global-set-key (vector (append modifiers '(down))) 'windmove-display-down) > - (global-set-key (vector (append modifiers '(?0))) 'windmove-display-same-window) > - (global-set-key (vector (append modifiers '(?f))) 'windmove-display-new-frame) > - (global-set-key (vector (append modifiers '(?t))) 'windmove-display-new-tab)) > + (windmove-install-defaults modifiers > + '((windmove-display-left left) > + (windmove-display-right right) > + (windmove-display-up up) > + (windmove-display-down down) > + (windmove-display-same-window ?0) > + (windmove-display-new-frame ?f) > + (windmove-display-new-tab ?t)))) > > > ;;; Directional window deletion > @@ -618,16 +649,22 @@ windmove-delete-default-keybindings > Keys are bound to commands that delete windows in the specified > direction. Keybindings are of the form PREFIX MODIFIERS-{left,right,up,down}, > where PREFIX is a prefix key and MODIFIERS is either a list of modifiers or > -a single modifier. Default value of PREFIX is `C-x' and MODIFIERS is `shift'." > +a single modifier. > +If PREFIX is `none', no prefix is used. If MODIFIERS is `none', the keybindings > +are directly bound to the arrow keys. > +Default value of PREFIX is `C-x' and MODIFIERS is `shift'." > (interactive) > (unless prefix (setq prefix '(?\C-x))) > + (when (eq prefix 'none) (setq prefix nil)) > (unless (listp prefix) (setq prefix (list prefix))) > (unless modifiers (setq modifiers '(shift))) > + (when (eq modifiers 'none) (setq modifiers nil)) > (unless (listp modifiers) (setq modifiers (list modifiers))) > - (global-set-key (vector prefix (append modifiers '(left))) 'windmove-delete-left) > - (global-set-key (vector prefix (append modifiers '(right))) 'windmove-delete-right) > - (global-set-key (vector prefix (append modifiers '(up))) 'windmove-delete-up) > - (global-set-key (vector prefix (append modifiers '(down))) 'windmove-delete-down)) > + (windmove-install-defaults modifiers > + '((windmove-delete-left left) > + (windmove-delete-right right) > + (windmove-delete-up up) > + (windmove-delete-down down)))) > > > ;;; Directional window swap states > @@ -673,14 +710,19 @@ windmove-swap-states-default-keybindings > 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'." > +or a single modifier. > +If MODIFIERS is `none', the keybindings will be directly bound to the > +arrow keys. > +Default value of MODIFIERS is `shift-super'." > (interactive) > (unless modifiers (setq modifiers '(shift super))) > + (when (eq modifiers 'none) (setq modifiers nil)) > (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)) > + (windmove-install-defaults modifiers > + '((windmove-swap-states-left left) > + (windmove-swap-states-right right) > + (windmove-swap-states-up up) > + (windmove-swap-states-down down)))) > > > (provide 'windmove)