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: Thu, 27 May 2021 11:09:14 +0000 Message-ID: <87zgwg302t.fsf@icterid> References: <87imgpw7k3.fsf@warpmail.net> <87mu36enhl.fsf@posteo.net> <8735uru1py.fsf@gnus.org> <871r9yjyv5.fsf@posteo.net> <87h7irqtvf.fsf@gnus.org> <87im37p2b4.fsf@icterid> <875yz68yoq.fsf@mail.linkov.net> <87r1hucws6.fsf@icterid> <87k0nl420l.fsf@mail.linkov.net> 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="8785"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 41438@debbugs.gnu.org, Lars Ingebrigtsen To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu May 27 13:14:01 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 1lmDxg-00025q-VI for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 27 May 2021 13:14:01 +0200 Original-Received: from localhost ([::1]:37390 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmDxf-0004G5-Np for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 27 May 2021 07:13:59 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41316) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmDtq-0002vC-Gq for bug-gnu-emacs@gnu.org; Thu, 27 May 2021 07:10:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:39182) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lmDtp-0005rO-SP for bug-gnu-emacs@gnu.org; Thu, 27 May 2021 07:10:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lmDtp-0001pb-M0 for bug-gnu-emacs@gnu.org; Thu, 27 May 2021 07:10:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 27 May 2021 11:10: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.16221137676990 (code B ref 41438); Thu, 27 May 2021 11:10:01 +0000 Original-Received: (at 41438) by debbugs.gnu.org; 27 May 2021 11:09:27 +0000 Original-Received: from localhost ([127.0.0.1]:50728 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lmDtG-0001of-Sy for submit@debbugs.gnu.org; Thu, 27 May 2021 07:09:27 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:60311) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lmDtD-0001oP-KV for 41438@debbugs.gnu.org; Thu, 27 May 2021 07:09:25 -0400 Original-Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 1F85B2400FE for <41438@debbugs.gnu.org>; Thu, 27 May 2021 13:09:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1622113757; bh=CrGL/Evz5DBNzJMtA2+wMqI560LNcZQFQl5SPblUVDo=; h=From:To:Cc:Subject:Autocrypt:Date:From; b=JWuCh4/d8QUYKCWZSeNcgCcCbO6wo7Ktfnbz87JqwCCY6j6Paz25fsr4R2ES+1tko jR3p3eqS61UUlhVs227lXuDKuet4iyhQgNaou7reP2kakPT9Oe7hMACTKSiUj3bn4n 8tzoxKbvO5TcRJt9JSiwH/3dk9xXy3XPWQu1CN0uMw4kyK10lDSvYS7UcDrMvNfjqU ajZGahOouUhxRTnO7Q39I8/BT4B+2Ov49HlZSSME7UbJqLCcisi9nV+9dQfIl9Caa6 8kkyqzAyBOE341CZOenCC3WmxTZXR5JgfuoBEvflTqYdfza9ZQRGXG4/+SGiF8d725 XA1MApvRKiHEg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4FrQ7H14drz9rxH; Thu, 27 May 2021 13:09:14 +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: <87k0nl420l.fsf@mail.linkov.net> (Juri Linkov's message of "Thu, 27 May 2021 00:35:46 +0300") 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:207367 Archived-At: --=-=-= Content-Type: text/plain Juri Linkov writes: >> What I don't really like is that only >> windmove-delete-default-keybindings can make use of prefixes, while all >> commands only use modifiers. Could it make sense to deprecate these >> functions in favour of either new functions or user-options? > > Maybe it's possible to add new user options without deprecating the > existing functions? Then for users an alternative way would be to > customize these options, and enable windmove-mode in the init file. Of course, why not? The patches below should implement that. > Or maybe there will be a need to create separate modes for every > keymap, e.g. windmove-display-mode, windmove-delete-mode? I don't see why that should be necessary, as the proposed windmove-mode doesn't even have the interest the user. -- Philip K. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Improve-windmove-default-keybindings-fuctions.patch >From 42a66e87af83817b9e989624fdbf9c7ee7c347c7 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Tue, 25 May 2021 11:47:51 +0200 Subject: [PATCH 1/2] Improve windmove-*-default-keybindings fuctions * windmove.el (windmove-mode-map): Add special map for windmove commands (windmove-mode): Add minor mode for activating windmove-mode-map (windmove-install-defaults): Add general function for manipulating windmove-mode-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 | 91 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 70 insertions(+), 21 deletions(-) diff --git a/lisp/windmove.el b/lisp/windmove.el index e4ea8e0f69..cd8592f341 100644 --- a/lisp/windmove.el +++ b/lisp/windmove.el @@ -426,19 +426,53 @@ 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-mode-map (make-sparse-keymap) + "Map used by `windmove-install-defaults'.") + +(define-minor-mode windmove-mode + "Global minor mode for default windmove commands." + :keymap windmove-mode-map + :init-value t + :global t) + +(defun windmove-install-defaults (prefix modifiers alist &optional uninstall) + "Install keys as specified by ALIST. +Every element of ALIST has the form (FN KEY), where KEY is +appended to MODIFIERS, adding PREFIX to the beginning, before +installing the key. Previous bindings of FN are unbound. +If UNINSTALL is non-nil, just remove the keys from ALIST." + (dolist (bind alist) + (dolist (old (where-is-internal (car bind) windmove-mode-map)) + (define-key windmove-mode-map old nil)) + (unless uninstall + (let ((key (vconcat (if (or (equal prefix [ignore]) + (eq prefix 'none)) + nil prefix) + (list (append modifiers (cdr bind)))))) + (when (eq (key-binding key) #'self-insert-command) + (warn "Command %S is shadowing self-insert-key" (car bind))) + (let ((old-fn (lookup-key windmove-mode-map key))) + (when old-fn + (warn "Overriding %S with %S" old-fn (car bind)))) + (define-key windmove-mode-map key (car bind)))))) + ;;;###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)) + (windmove-install-defaults nil modifiers + '((windmove-left left) + (windmove-right right) + (windmove-up up) + (windmove-down down)))) ;;; Directional window display and selection @@ -546,17 +580,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 nil 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 +656,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 prefix modifiers + '((windmove-delete-left left) + (windmove-delete-right right) + (windmove-delete-up up) + (windmove-delete-down down)))) ;;; Directional window swap states @@ -673,14 +717,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 nil modifiers + '((windmove-swap-states-left left) + (windmove-swap-states-right right) + (windmove-swap-states-up up) + (windmove-swap-states-down down)))) (provide 'windmove) -- 2.30.2 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0002-Add-user-options-for-default-windmove-commands.patch >From 21a8a8854249d24d62d4dd8e17c1f1d20de04fd6 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Thu, 27 May 2021 12:24:42 +0200 Subject: [PATCH 2/2] Add user options for default windmove commands * windmove.el (windmove--default-keybindings-type): Add type (windmove-default-keybindings): Add user option (windmove-display-default-keybindings): Add user option (windmove-delete-default-keybindings): Add user option (windmove-swap-states-default-keybindings): Add user option --- lisp/windmove.el | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/lisp/windmove.el b/lisp/windmove.el index cd8592f341..488962c063 100644 --- a/lisp/windmove.el +++ b/lisp/windmove.el @@ -731,6 +731,86 @@ windmove-swap-states-default-keybindings (windmove-swap-states-up up) (windmove-swap-states-down down)))) + + +(defconst windmove--default-keybindings-type + `(choice (const :tag "Don't bind" nil) + (cons :tag "Bind using" + (key-sequence :tag "Prefix") + (set :tag "Modifier" + :greedy t + ;; See `(elisp) Keyboard Events' + (const :tag "Meta" meta) + (const :tag "Control" control) + (const :tag "Shift" shift) + (const :tag "Hyper" hyper) + (const :tag "Super" super) + (const :tag "Alt" alt)))) + "Customisation type for windmove modifiers.") + +(defcustom windmove-default-keybindings nil + "Default bindings for regular windmove commands." + :set (lambda (sym val) + (windmove-install-defaults + (car val) (cdr val) + '((windmove-left left) + (windmove-right right) + (windmove-up up) + (windmove-down down)) + (null val)) + (set-default sym val)) + :type windmove--default-keybindings-type + :version "28.1" + :group 'windmove) + +(defcustom windmove-display-default-keybindings nil + "Default bindings for display windmove commands." + :set (lambda (sym val) + (windmove-install-defaults + (car val) (cdr val) + '((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)) + (null val)) + (set-default sym val)) + :type windmove--default-keybindings-type + :version "28.1" + :group 'windmove) + +(defcustom windmove-delete-default-keybindings nil + "Default bindings for delete windmove commands." + :set (lambda (sym val) + (windmove-install-defaults + (car val) (cdr val) + '((windmove-delete-left left) + (windmove-delete-right right) + (windmove-delete-up up) + (windmove-delete-down down)) + (null val)) + (set-default sym val)) + :type windmove--default-keybindings-type + :version "28.1" + :group 'windmove) + +(defcustom windmove-swap-states-default-keybindings nil + "Default bindings for swap-state windmove commands." + :set (lambda (sym val) + (windmove-install-defaults + (car val) (cdr val) + '((windmove-swap-states-left left) + (windmove-swap-states-right right) + (windmove-swap-states-up up) + (windmove-swap-states-down down)) + (null val)) + (set-default sym val)) + :type windmove--default-keybindings-type + :version "28.1" + :group 'windmove) + (provide 'windmove) -- 2.30.2 --=-=-=--