From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.bugs Subject: bug#41438: [PATCH] Allow windmove keys to be bound without prefix or modifiers Date: Sat, 22 May 2021 20:29:50 +0000 Message-ID: <871r9yjyv5.fsf@posteo.net> References: <87imgpw7k3.fsf@warpmail.net> <87mu36enhl.fsf@posteo.net> <8735uru1py.fsf@gnus.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33533"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 41438@debbugs.gnu.org, Juri Linkov To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat May 22 22:31:09 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 1lkYH7-0008WV-Q8 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 22 May 2021 22:31:09 +0200 Original-Received: from localhost ([::1]:42538 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lkYH6-000578-St for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 22 May 2021 16:31:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36204) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lkYH0-00056j-BF for bug-gnu-emacs@gnu.org; Sat, 22 May 2021 16:31:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:56805) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lkYH0-0000sK-3x for bug-gnu-emacs@gnu.org; Sat, 22 May 2021 16:31:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lkYH0-0002X0-11 for bug-gnu-emacs@gnu.org; Sat, 22 May 2021 16:31:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 22 May 2021 20:31: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.16217154049596 (code B ref 41438); Sat, 22 May 2021 20:31:01 +0000 Original-Received: (at 41438) by debbugs.gnu.org; 22 May 2021 20:30:04 +0000 Original-Received: from localhost ([127.0.0.1]:40118 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lkYG3-0002Ui-Rf for submit@debbugs.gnu.org; Sat, 22 May 2021 16:30:04 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:50811) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lkYG0-0002Tj-Er for 41438@debbugs.gnu.org; Sat, 22 May 2021 16:30:02 -0400 Original-Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id DC474240028 for <41438@debbugs.gnu.org>; Sat, 22 May 2021 22:29:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1621715392; bh=YewDmnnCOriKNPUAUY77pU2WvA3Fq1SRJsVC0tXj7tw=; h=From:To:Cc:Subject:Autocrypt:Date:From; b=BUVjFp6U2fsziifFKYFqbvl+EcbqFOXK3GumWjP4wErM7xF0rmgQimovTOcMW+OKG hFsLTQD+2edAUUEsR4Ns6XoDKH38Zpm2kVyLdGztl5R5pDx+iBBSQBKRPZQpB5kCrQ OjllYv06XyYfzC+l1x9IZOdKGJsbzzoV9Ft1XcaAJ7QQPBcqzgytvW0hRKL+eCHcWr nSt/mcmeuqnssiYFEIF2Gj+PBSuKggQT5E7ZNSZtEHhdHd0oq6nQiMD4elVE8IEENX UGKe3W7f7VtQu6VEqHMYj0yHgycy1ncsTLosSGutQ6qEeOpQeI0wPvxl2dwbPzuPlB 0109kEryj6FgQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4FnZpR5FyTz6tm5; Sat, 22 May 2021 22:29:51 +0200 (CEST) Autocrypt: addr=philipk@posteo.net; prefer-encrypt=mutual; keydata= mDMEYHHqUhYJKwYBBAHaRw8BAQdAp3GdmYJ6tm5McweY6dEvIYIiry+Oz9rU4MH6NHWK0Ee0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiQBBMWCAA4FiEEDM2H44ZoPt9Ms0eHtVrAHPRh1FwFAmBx6lICGwMFCwkIBwIGFQoJ CAsCBBYCAwECHgECF4AACgkQtVrAHPRh1FyTkgEAjlbGPxFchvMbxzAES3r8QLuZgCxeAXunM9gh io0ePtUBALVhh9G6wIoZhl0gUCbQpoN/UJHI08Gm1qDob5zDxnIHuDgEYHHqUhIKKwYBBAGXVQEF AQEHQNcRB+MUimTMqoxxMMUERpOR+Q4b1KgncDZkhrO2ql1tAwEIB4h4BBgWCAAgFiEEDM2H44Zo Pt9Ms0eHtVrAHPRh1FwFAmBx6lICGwwACgkQtVrAHPRh1Fw1JwD/Qo7kvtib8jy7puyWrSv0MeTS g8qIxgoRWJE/KKdkCLEA/jb9b9/g8nnX+UcwHf/4VfKsjExlnND3FrBviXUW6NcB In-Reply-To: <8735uru1py.fsf@gnus.org> (Lars Ingebrigtsen's message of "Wed, 12 May 2021 22:38:33 +0200") 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:207062 Archived-At: --=-=-= Content-Type: text/plain Lars Ingebrigtsen writes: > "Philip K." writes: > >> These are the only edge-cases I found, but I didn't fix them yet, as I'm >> not sure what would be preferred. So the patches should not be applies yet. > > Have you done any further work on this? I have been thinking about this a bit more, and tried a different approach. The implementation is not prefect, but basically I am playing with emulation-mode-map-alists to bind the keys, instead of using the global map. The should solve the two issues I brought up, because I do not have to worry about restoring the previous keys, and some edge-cases are avoided, where e.g. doc-view would override up and down breaking the expected behaviour when setting the prefix to 'none. 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? -- Philip K. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Allow-windmove-keys-to-be-bound-without-prefix-or-mo.patch >From eba161853d50c2a6ce27af5907efdae4f6ab81eb Mon Sep 17 00:00:00 2001 From: Philip K Date: Sat, 22 May 2021 22:03:22 +0200 Subject: [PATCH] Allow windmove keys to be bound without prefix or modifiers --- lisp/windmove.el | 91 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 70 insertions(+), 21 deletions(-) diff --git a/lisp/windmove.el b/lisp/windmove.el index e4ea8e0f69..acd9cb41fc 100644 --- a/lisp/windmove.el +++ b/lisp/windmove.el @@ -426,19 +426,35 @@ 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-map (make-sparse-keymap) + "Keymap to bind windmove keys to.") + +(add-to-list 'emulation-mode-map-alists + (list (cons t windmove-map))) + ;;;###autoload (defun windmove-default-keybindings (&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)) + (dolist (bind '((windmove-left left) + (windmove-right right) + (windmove-up up) + (windmove-down down))) + (when (or (memq (cadr bind) '(left right up down)) + (not (null modifiers))) + (dolist (old (where-is-internal (car bind) windmove-map)) + (define-key windmove-map old nil)) + (define-key windmove-map + (vector (append modifiers (cdr bind))) + (car bind))))) ;;; Directional window display and selection @@ -546,17 +562,27 @@ 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)) + (dolist (bind '((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))) + (when (or (memq (cadr bind) '(left right up down)) + (not (null modifiers))) + (dolist (old (where-is-internal (car bind) windmove-map)) + (define-key windmove-map old nil)) + (define-key windmove-map + (vector (append modifiers (cdr bind))) + (car bind))))) ;;; Directional window deletion @@ -618,16 +644,28 @@ 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)) + (dolist (bind '((windmove-delete-left left) + (windmove-delete-right right) + (windmove-delete-up up) + (windmove-delete-down down))) + (when (or (memq (cadr bind) '(left right up down)) + (not (null modifiers))) + (dolist (old (where-is-internal (car bind) windmove-map)) + (define-key windmove-map old nil)) + (define-key windmove-map + (vector (append modifiers (cdr bind))) + (car bind))))) ;;; Directional window swap states @@ -673,14 +711,25 @@ 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)) + (dolist (bind '((windmove-swap-states-left left) + (windmove-swap-states-right right) + (windmove-swap-states-up up) + (windmove-swap-states-down down))) + (when (or (memq (cadr bind) '(left right up down)) + (not (null modifiers))) + (dolist (old (where-is-internal (car bind) windmove-map)) + (define-key windmove-map old nil)) + (define-key windmove-map + (vector (append modifiers (cdr bind))) + (car bind))))) (provide 'windmove) -- 2.30.2 --=-=-=--