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 (was: Re: [CVS] f7, f8 bound..) Date: Tue, 03 Sep 2002 14:27:18 +0200 Organization: The Church of Emacs Sender: emacs-devel-admin@gnu.org Message-ID: References: <200208271621.g7RGLNm30516@rum.cs.yale.edu> <5xhehfe3aj.fsf@kfs2.cua.dk> <874rdfaytt.fsf@pot.cnuce.cnr.it> <5xvg5sh06u.fsf@kfs2.cua.dk> <20020830235528.GA13207@gnu.org> <87ofbji88u.fsf@emacswiki.org> <87sn0scb0b.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 1031056038 29570 127.0.0.1 (3 Sep 2002 12:27:18 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Tue, 3 Sep 2002 12:27:18 +0000 (UTC) Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 17mCm5-0007go-00 for ; Tue, 03 Sep 2002 14:27:17 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 17mDKm-0005qc-00 for ; Tue, 03 Sep 2002 15:03:08 +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 17mCnc-0002zo-00; Tue, 03 Sep 2002 08:28:52 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 17mCmF-0002vA-00 for emacs-devel@gnu.org; Tue, 03 Sep 2002 08:27:27 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 17mCmC-0002tk-00 for emacs-devel@gnu.org; Tue, 03 Sep 2002 08:27:26 -0400 Original-Received: from sheridan.dina.kvl.dk ([130.225.40.227]) by monty-python.gnu.org with esmtp (Exim 4.10) id 17mCmB-0002tR-00 for emacs-devel@gnu.org; Tue, 03 Sep 2002 08:27:23 -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 OAA31837 for ; Tue, 3 Sep 2002 14:27:22 +0200 Original-Received: (from abraham@localhost) by zuse.dina.kvl.dk (8.9.3+Sun/8.9.3) id OAA10289; Tue, 3 Sep 2002 14:27:18 +0200 (MEST) X-Authentication-Warning: zuse.dina.kvl.dk: abraham set sender to abraham@dina.kvl.dk using -f Original-To: emacs-devel@gnu.org X-Face: +kRV2]2q}lixHkE{U)mY#+6]{AH=yN~S9@IFiOa@X6?GM|8MBp/ In-Reply-To: <87sn0scb0b.fsf@emacswiki.org> (Alex Schroeder's message of "Mon, 02 Sep 2002 23:55:16 +0200") Original-Lines: 123 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:7370 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:7370 Alex Schroeder writes: > How about this addition. A big help. I don't think C-q should be rebound globally, the user may want to enter literal control characters in string values for other variables. So I made it specific to the field, end encapsulated it into a new 'key-sequence' widget. I also added a [Key sequence] button, and a new 'command' widget. > A side note: Why is the default value for function types the string > "ignore"? I don't know. It is supposed to be the symbol `ignore'. Using the widget package directly with (widget-create 'function) works, so I guess somehow customize convert the value twice. Somehow, now it just ignores the default value, and use nil. Strange. ;;; cus-key.el -- Customize support for changing key bindings. (require 'wid-edit) (defvar custom-global-keymap (let ((map (make-sparse-keymap))) (set-keymap-parent map global-map) map) "Global keymap for use by Customize. This is automatically generated from `global-key-bindings', you should never change this manually. Instead, change either `global-map' from Lisp or `global-key-bindings' from Customize.") (defun quoted-key-insert (key) "Insert a string representation of the next key typed. The string representation is a representation understood by `read-kbd-macro'." (interactive "KPress a key: ") (insert (edmacro-format-keys key))) (defvar key-sequence-widget-map (let ((map (make-sparse-keymap))) (set-keymap-parent map widget-field-keymap) (define-key map (kbd "C-q") 'quoted-key-insert) map) "Keymap for the `key-sequence' widget.") (define-widget 'key-sequence-field 'string "Field for entering key bindings." :tag "Key sequence" :keymap key-sequence-widget-map) (define-widget 'key-sequence-button 'push-button "Button for entering key bindings." :tag "Key sequence" :action 'key-sequence-button-action) (defun key-sequence-button-action (widget &optional event) (let ((key (read-key-sequence "Press key sequence: "))) (widget-value-set (widget-get widget :parent) (edmacro-format-keys key)) (widget-setup))) (define-widget 'key-sequence 'group "Widget for entering key bindings." :tag "Read key sequence" :value "" :value-create 'key-sequence-value-create :value-delete 'widget-children-value-delete :value-get 'widget-choice-value-get) (defun key-sequence-value-create (widget) (let ((button (widget-create-child widget '(key-sequence-button))) (field (widget-create-child-value widget '(key-sequence-field :format " %v") (widget-get widget :value)))) (widget-put widget :children (list field)) (widget-put widget :buttons (list button)))) (define-widget 'command 'function "An interactive Lisp function." :complete-function (lambda () (interactive) (lisp-complete-symbol 'commandp)) :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") (defcustom global-key-bindings nil "Global keybindings defined through customize. While entering the name of a key, you can either type keys yourself just as they appear in the manual, as in C-c a. You must use angle brackets for function keys, as in . You can also hit C-q and type the key. C-q will insert the correct string representation for you. For longer sequences, you can also invoke the [Key sequence] button, and type the entire key sequence directly. While entering the name of a command, you can use M-TAB to comlete the function name." ;; Note that we cannot use \\[quoted-key-insert] because the keymap ;; is not the same. :type '(repeat (group key-sequence command)) :set (lambda (sym val) (set-default sym val) (setq custom-global-keymap (make-sparse-keymap)) (set-keymap-parent custom-global-keymap global-map) (mapc (lambda (bind) (define-key custom-global-keymap (read-kbd-macro (car bind)) (cadr bind))) val) (use-global-map custom-global-keymap) val)) (provide 'cus-key) ;;; cus-key.el ends here