From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Per Abrahamsen Newsgroups: gmane.emacs.devel Subject: Re: Customizing key bindings Date: Tue, 10 Sep 2002 12:19:05 +0200 Organization: The Church of Emacs Sender: emacs-devel-admin@gnu.org Message-ID: References: <200208271621.g7RGLNm30516@rum.cs.yale.edu> <5xvg5sh06u.fsf@kfs2.cua.dk> <20020830235528.GA13207@gnu.org> <87ofbji88u.fsf@emacswiki.org> <87sn0scb0b.fsf@emacswiki.org> <87bs7ama8g.fsf@emacswiki.org> <87lm6dkjf8.fsf_-_@emacswiki.org> <871y827r80.fsf@emacswiki.org> <87ptvm6cdy.fsf@emacswiki.org> <87r8g2dbid.fsf@emacswiki.org> NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1031653302 26338 127.0.0.1 (10 Sep 2002 10:21:42 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Tue, 10 Sep 2002 10:21:42 +0000 (UTC) Cc: emacs-devel@gnu.org Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 17oi9N-0006qf-00 for ; Tue, 10 Sep 2002 12:21:41 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 17oijj-0007Rw-00 for ; Tue, 10 Sep 2002 12:59:16 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 17oi9O-0005ZB-00; Tue, 10 Sep 2002 06:21:42 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 17oi72-0005I8-00 for emacs-devel@gnu.org; Tue, 10 Sep 2002 06:19:16 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 17oi70-0005Hr-00 for emacs-devel@gnu.org; Tue, 10 Sep 2002 06:19:15 -0400 Original-Received: from sheridan.dina.kvl.dk ([130.225.40.227]) by monty-python.gnu.org with esmtp (Exim 4.10) id 17oi6z-0005Hj-00 for emacs-devel@gnu.org; Tue, 10 Sep 2002 06:19:13 -0400 Original-Received: from zuse.dina.kvl.dk (zuse.dina.kvl.dk [130.225.40.245]) by sheridan.dina.kvl.dk (8.9.3/8.9.3/Debian 8.9.3-21) with ESMTP id MAA27864; Tue, 10 Sep 2002 12:19:11 +0200 Original-Received: (from abraham@localhost) by zuse.dina.kvl.dk (8.9.3+Sun/8.9.3) id MAA28808; Tue, 10 Sep 2002 12:19:05 +0200 (MEST) X-Authentication-Warning: zuse.dina.kvl.dk: abraham set sender to abraham@dina.kvl.dk using -f Original-To: Alex Schroeder X-Face: +kRV2]2q}lixHkE{U)mY#+6]{AH=yN~S9@IFiOa@X6?GM|8MBp/ In-Reply-To: <87r8g2dbid.fsf@emacswiki.org> (Alex Schroeder's message of "Tue, 10 Sep 2002 00:49:30 +0200") Original-Lines: 152 User-Agent: Gnus/5.090007 (Oort Gnus v0.07) Emacs/21.1 (sparc-sun-solaris2.8) Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:7797 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:7797 Alex Schroeder writes: > * cus-key.el (key-sequence-field-validate): disallow "" as a > keybinding. We may also want to disallow the creation of prefix keys, alt least for now. For example, Try to define "X Y" from customize. Then remove the binding from customize. You will notice that "X" continues to be a prefix key, even though "X Y" is no longer bound. We should probably find a safe way to allow the user to create new prefix keys, but for now, let's disallow it. Actually, thinking about it, we _need_ to solve this, as otherwise the user will not be able to bind e.g. "C-c x" for a mode that have no C-c bindings already. > Except for the handling of nil, this seems "good enough" for me. :) The patch below implements "Remove definition", add a check for too long key bidnings in validate, and fix a bug with the notify function that (did not) update the "Old binding". *** cus-key2.el Tue Sep 10 11:58:40 2002 --- cus-key3.el Tue Sep 10 12:15:48 2002 *************** *** 26,39 **** :keymap key-sequence-widget-map) (defun key-sequence-field-validate (widget) ! (let ((value (widget-apply widget :value-get))) ! (condition-case nil ! (progn ! (when (string= value "") ! (error widget)) ! (read-kbd-macro value) ! nil) ! (error widget)))) (define-widget 'key-sequence-button 'push-button "Button for entering key bindings." --- 26,64 ---- :keymap key-sequence-widget-map) (defun key-sequence-field-validate (widget) ! (let* ((value (widget-apply widget :value-get)) ! (map1 (or (widget-ancestor-get widget :key-sequence-keymap) ! (current-global-map))) ! (map (if (symbolp map1) (symbol-value map1) map1)) ! (key (condition-case nil ! (read-kbd-macro value) ! nil)) ! (command (and key (lookup-key map key))))) ! (cond ((null key) ! ;; Unparsable. ! widget) ! ((string-equal key "") ! ;; Empty prefix. We can't rebind the entire keymap. ! widget) ! ((functionp command) ! ;; Normal binding, OK. ! nil) ! ((null command) ! ;; Unbound, OK. ! nil) ! ((numberp command) ! ;; We can't allow the creation of new prefix keys, as we have ! ;; no way to undo such a prefix ! widget) ! ((keymapp command) ! ;; This will turn a prefix key into an ordinary binding. A ! ;; bit drastic (as many bindings can be lost), but the user ! ;; asked for it. ! nil) ! (t ! ;; This is an impossible value according to the lookup-key doc ! ;; string. What to do? Let the user deside. ! nil))) (define-widget 'key-sequence-button 'push-button "Button for entering key bindings." *************** *** 115,124 **** (children (widget-get widget :buttons)) (field (car children)) (value (widget-value child)) ! (map (or (widget-ancestor-get widget :key-sequence-keymap) (current-global-map))) (command (condition-case nil ! (lookup-key map (read-kbd-macro value)) (error nil)))) (save-excursion (goto-char (widget-get binding :from)) --- 140,150 ---- (children (widget-get widget :buttons)) (field (car children)) (value (widget-value child)) ! (map1 (or (widget-ancestor-get widget :key-sequence-keymap) (current-global-map))) + (map (if (symbolp map1) (symbol-value map1) map1)) (command (condition-case nil ! (lookup-key map(read-kbd-macro value)) (error nil)))) (save-excursion (goto-char (widget-get binding :from)) *************** *** 134,152 **** :prompt-match 'commandp :match-alternatives '(commandp) :validate (lambda (widget) ! (unless (or (not (widget-value widget)) ! (commandp (widget-value widget))) (widget-put widget :error (format "Invalid function: %S" (widget-value widget))) widget)) :value 'ignore :tag "Command") (define-widget 'key-binding 'group "Bind a key sequence to a command." :value '("" ignore) :indent 0 ! :args '(key-sequence (command :tag "New binding"))) (defmacro defkeymap (symbol map doc &rest args) "Define SYMBOL to be a keymap with value MAP. --- 160,184 ---- :prompt-match 'commandp :match-alternatives '(commandp) :validate (lambda (widget) ! (unless (commandp (widget-value widget)) (widget-put widget :error (format "Invalid function: %S" (widget-value widget))) widget)) :value 'ignore :tag "Command") + (define-widget 'key-binding-value 'choice + "A valid key binding value for use by `define-key'. + This could be a command or nil." + :args '((const :tag "Remove definition" nil) ) + :value 'ignore + :tag "New binding") + (define-widget 'key-binding 'group "Bind a key sequence to a command." :value '("" ignore) :indent 0 ! :args '(key-sequence key-binding-value)) (defmacro defkeymap (symbol map doc &rest args) "Define SYMBOL to be a keymap with value MAP.