From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: philip@warpmail.net (Philip K.) Newsgroups: gmane.emacs.bugs Subject: bug#41438: [PATCH] Allow windmove keys to be bound without prefix or modifiers Date: Fri, 22 May 2020 20:26:07 +0200 Message-ID: <87v9kn7rnk.fsf__13454.8490563006$1590172036$gmane$org@bulbul> References: <87imgpw7k3.fsf@warpmail.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="130375"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 41438@debbugs.gnu.org, emacs-devel@gnu.org To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri May 22 20:27:11 2020 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 1jcCNz-000XnB-Ar for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 22 May 2020 20:27:11 +0200 Original-Received: from localhost ([::1]:37382 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcCNy-0000zZ-DX for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 22 May 2020 14:27:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54052) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcCNq-0000y1-WB for bug-gnu-emacs@gnu.org; Fri, 22 May 2020 14:27:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48814) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jcCNq-0005ef-Lm for bug-gnu-emacs@gnu.org; Fri, 22 May 2020 14:27:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jcCNq-0003J8-I0 for bug-gnu-emacs@gnu.org; Fri, 22 May 2020 14:27:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: philip@warpmail.net (Philip K.) Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 22 May 2020 18:27:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41438 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 41438-submit@debbugs.gnu.org id=B41438.159017198012654 (code B ref 41438); Fri, 22 May 2020 18:27:02 +0000 Original-Received: (at 41438) by debbugs.gnu.org; 22 May 2020 18:26:20 +0000 Original-Received: from localhost ([127.0.0.1]:60360 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jcCN9-0003I1-Be for submit@debbugs.gnu.org; Fri, 22 May 2020 14:26:19 -0400 Original-Received: from wout1-smtp.messagingengine.com ([64.147.123.24]:42001) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jcCN7-0003Hn-9l for 41438@debbugs.gnu.org; Fri, 22 May 2020 14:26:17 -0400 Original-Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 2D220A21; Fri, 22 May 2020 14:26:11 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Fri, 22 May 2020 14:26:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=warpmail.net; h= from:to:cc:subject:in-reply-to:date:message-id:mime-version :content-type; s=fm3; bh=7s5KkJhH9MWW4tyxcvGWmRtv4GpogGS7Fs9OmIH PGAA=; b=eZ3jkOHW0Y+bq7CzF5QxT/D3Rne1t3ZaJ5gG7MTu5AkHAEL2UHW4+pS tr5i5CkftH36gMe9a+u86XF9fE4K0FMFIE8yCLiLmimV1qGMXx10578vHtJMEXHf C0YktMqUgWgShMhOV6akzE1PSMM/j8ct9F7L9j+CihzRTQ+bnXAJf6Yepj5c7tfp PXxZZAYYHO7J5CN2d6v7aQ3rgdlsnMbjmvgO04iuIszMqunOJxd9e0mlhTwNgt6O +bWL+m539CKzvBprXRNyuM0dXCJQZsW0v4LscMKv98ZXjNNkSclsXUgiLWGJz3yX /okfXueKhGXuvQxCCKqYLRyAzcNfAYQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=7s5KkJhH9MWW4tyxc vGWmRtv4GpogGS7Fs9OmIHPGAA=; b=d7ZkM5IDZfACzPIXN3rpWcPiCR3qvhER9 qcguhBnGVSj3q3Q+eDT+Zd67ryeWa5YflImK1t05o5SyzpA9tE2KIuxrjLYj4Ony txVCxNzxSeLAoWBmeWTirPkcsjj0nG5LjqZKwoN6rjEWApwsNeGKfJD5xqitfFJ2 sWb8eMA4Fs/YuS5H/SrMsexxLVnScxU7kwgc7DXgtjJu0xmZN1mKVZADU/c0T/FV R4y5SqxLrT1yHVJQX1mNZDjCFs4EWDQMqy3w7mDPn8POJ2GQOLIlZcBaROYjH3ie HjdGVRsyx8ks7LkAocinw+C1xuYeOTk3+MNil9J1gqAgkPcBF41cA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedruddufedguddvfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvffujgffkfggtgesmhdtreertddttdenucfhrhhomhepphhhihhlihhp seifrghrphhmrghilhdrnhgvthculdfrhhhilhhiphcumfdrmdenucggtffrrghtthgvrh hnpeegfeffieeljedujeekudduffehhefhhfejvdefvdffgfejtddtvdeuffeutdetteen ucfkphepjeelrddvudelrdduleelrdegjeenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehphhhilhhiphesfigrrhhpmhgrihhlrdhnvght X-ME-Proxy: Original-Received: from localhost (p4fdbc72f.dip0.t-ipconnect.de [79.219.199.47]) by mail.messagingengine.com (Postfix) with ESMTPA id 4DB653280059; Fri, 22 May 2020 14:26:10 -0400 (EDT) In-Reply-To: <874ks9rkyd.fsf@mail.linkov.net> (message from Juri Linkov on Fri, 22 May 2020 01:18:18 +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:180777 Archived-At: --=-=-= Content-Type: text/plain Juri Linkov writes: >> Another question I'd like to ask before trying it out: Would there be >> any interest in adding user options for the "default" modifiers that >> windmove should use? If yes, one could add a :set function that >> automatically calls the apropriate bindings function, when it's value >> is non-nil. I have a very customize-centric configuration, where something >> this would fit in very well. > > I think that adding defcustoms (including a new const `none') > would be the most natural way to customize windmove modifiers > (provided that the existing functions should remain). I made a first concept, but it doesn't work unless windmove is explicity required (see below). As far as I know, autoloading variables isn't good style, so is there any other way to invoke the :set property of a user option? -- Philip K. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Implement-user-options-for-windmove-modifiers-and-pr.patch >From b35173936e681e170172eb3d4548a2f91f70dad3 Mon Sep 17 00:00:00 2001 From: Philip K Date: Fri, 22 May 2020 20:21:59 +0200 Subject: [PATCH] Implement user options for windmove modifiers and prefixes --- lisp/windmove.el | 103 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 95 insertions(+), 8 deletions(-) diff --git a/lisp/windmove.el b/lisp/windmove.el index 3d7f86b9af..95f74bfb81 100644 --- a/lisp/windmove.el +++ b/lisp/windmove.el @@ -162,6 +162,19 @@ windmove-window-distance-delta (make-obsolete-variable 'windmove-window-distance-delta "no longer used." "27.1") +(defconst windmove-modifier-type + '(choice (set :tag "Modifier Symbols" + :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)) + (const :tag "No modifier" none)) + "Customisation type for windmove modifiers") + ;; Note: ;; @@ -419,6 +432,7 @@ windmove-down (interactive "P") (windmove-do-window-select 'down (and arg (prefix-numeric-value arg)))) +(defvar windmove-modifiers) ;;; set up keybindings ;; Idea for this function is from iswitchb.el, by Stephen Eglen @@ -433,9 +447,10 @@ windmove-default-keybindings 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'." +Default value of MODIFIERS is stored in `windmove-modifiers'." (interactive) - (unless modifiers (setq modifiers 'shift)) + (unless modifiers + (setq modifiers windmove-modifiers)) (when (eq modifiers 'none) (setq modifiers nil)) (unless (listp modifiers) (setq modifiers (list modifiers))) (global-set-key (vector (append modifiers '(left))) 'windmove-left) @@ -443,6 +458,25 @@ windmove-default-keybindings (global-set-key (vector (append modifiers '(up))) 'windmove-up) (global-set-key (vector (append modifiers '(down))) 'windmove-down)) +;; has to be declared AFTER windmove-default-keybindings, or else +;; windmove is recursivly loaded +;;;###autoload +(defcustom windmove-modifiers '(shift super) + "Modifiers for `windmove-default-keybindings'. +Can either be a symbol or list of modifier symbols, +i.e. `meta',`control', `shift', `hyper', `super', or `alt' +representing modifier keys to use with the arrow keys. + +If the value is just `none', the arrow keys will be directly +bound to the windmove functions." + :type windmove-modifier-type + :require 'windmove + :initialize #'custom-initialize-changed + :set (lambda (sym val) + (when val + (windmove-swap-states-default-keybindings val)) + (set-default sym val))) + ;;; Directional window display and selection @@ -565,6 +599,8 @@ windmove-display-new-tab (interactive "P") (windmove-display-in-direction 'new-tab arg)) +(defvar windmove-display-modifiers) + ;;;###autoload (defun windmove-display-default-keybindings (&optional modifiers) "Set up keybindings for directional buffer display. @@ -573,7 +609,7 @@ windmove-display-default-keybindings 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'." +Default value of MODIFIERS is stored in `windmove-display-modifiers'." (interactive) (unless modifiers (setq modifiers '(shift meta))) (when (eq modifiers 'none) (setq modifiers nil)) @@ -586,6 +622,17 @@ windmove-display-default-keybindings (global-set-key (vector (append modifiers '(?f))) 'windmove-display-new-frame) (global-set-key (vector (append modifiers '(?t))) 'windmove-display-new-tab)) +(defcustom windmove-display-modifiers '(shift meta) + "Modifiers for `windmove-display-default-keybindings'. +Analogous to `windmove-modifiers'." + :type windmove-modifier-type + :require 'windmove + :initialize #'custom-initialize-changed + :set (lambda (sym val) + (when val + (windmove-display-default-keybindings val)) + (set-default sym val))) + ;;; Directional window deletion @@ -640,6 +687,9 @@ windmove-delete-down (interactive "P") (windmove-delete-in-direction 'down arg)) +(defvar windmove-delete-prefix) +(defvar windmove-delete-modifiers) + ;;;###autoload (defun windmove-delete-default-keybindings (&optional prefix modifiers) "Set up keybindings for directional window deletion. @@ -649,12 +699,13 @@ windmove-delete-default-keybindings 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'." +The default values for PREFIX and MODIFIERS are stored in `windmove-delete-prefix' +and `windmove-delete-modifiers' respectively." (interactive) - (unless prefix (setq prefix '(?\C-x))) + (unless prefix (setq prefix (list windmove-delete-prefix))) (when (eq prefix 'none) (setq prefix nil)) (unless (listp prefix) (setq prefix (list prefix))) - (unless modifiers (setq modifiers '(shift))) + (unless modifiers (setq modifiers windmove-delete-modifiers)) (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) @@ -662,6 +713,28 @@ 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)) +(defcustom windmove-delete-prefix (kbd "C-x") + "Prefix for `windmove-delete-default-keybindings'." + :type 'key-sequence + :require 'windmove + :initialize #'custom-initialize-changed + :set (lambda (sym val) + (windmove-delete-default-keybindings + val windmove-delete-modifiers) + (set-default sym val))) + +(defcustom windmove-delete-modifiers '(shift) + "Modifiers for `windmove-delete-default-keybindings'. +See `windmove-modifiers' for more details" + :type windmove-modifier-type + :require 'windmove + :initialize #'custom-initialize-changed + :set (lambda (sym val) + (when val + (windmove-delete-default-keybindings + windmove-delete-prefix val)) + (set-default sym val))) + ;;; Directional window swap states @@ -700,6 +773,8 @@ windmove-swap-states-right (interactive) (windmove-swap-states-in-direction 'right)) +(defvar windmove-swap-states-modifiers) + ;;;###autoload (defun windmove-swap-states-default-keybindings (&optional modifiers) "Set up keybindings for directional window swap states. @@ -709,9 +784,10 @@ windmove-swap-states-default-keybindings 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'." +Default value of MODIFIERS is stored in `windmove-swap-states-modifiers'." (interactive) - (unless modifiers (setq modifiers '(shift super))) + (unless modifiers + (setq modifiers windmove-swap-states-modifiers)) (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) @@ -719,6 +795,17 @@ windmove-swap-states-default-keybindings (global-set-key (vector (append modifiers '(up))) 'windmove-swap-states-up) (global-set-key (vector (append modifiers '(down))) 'windmove-swap-states-down)) +(defcustom windmove-swap-states-modifiers + '(shift super) + "Modifiers for `windmove-swap-states-default-keybindings'. +Analogous to `windmove-modifiers'." + :type windmove-modifier-type + :require 'windmove + :initialize #'custom-initialize-changed + :set (lambda (sym val) + (windmove-swap-states-default-keybindings val) + (set-default sym val))) + (provide 'windmove) -- 2.20.1 --=-=-=--