From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lennart Borgman Newsgroups: gmane.emacs.devel Subject: Re: Function for deleting a key binding in a sparse keymap Date: Wed, 07 Dec 2005 15:33:32 +0100 Message-ID: <4396F2BC.5070605@student.lu.se> References: <439382B9.7020802@student.lu.se> <439470ED.9010809@student.lu.se> <4395C4BA.4070707@student.lu.se> <43960E3F.1060105@student.lu.se> <4396184A.60606@student.lu.se> <87pso97k0r.fsf-monnier+emacs@gnu.org> <4396B5B1.10501@student.lu.se> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1133975868 4656 80.91.229.2 (7 Dec 2005 17:17:48 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 7 Dec 2005 17:17:48 +0000 (UTC) Cc: emacs-devel@gnu.org, Stefan Monnier , rms@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Dec 07 18:17:39 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Ek2tg-0006ct-NW for ged-emacs-devel@m.gmane.org; Wed, 07 Dec 2005 18:16:05 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ek2tv-00063K-LU for ged-emacs-devel@m.gmane.org; Wed, 07 Dec 2005 12:16:19 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ek0Mu-00071g-Bk for emacs-devel@gnu.org; Wed, 07 Dec 2005 09:34:04 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Ek0Ms-00071J-Su for emacs-devel@gnu.org; Wed, 07 Dec 2005 09:34:03 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ek0Ms-00071D-86 for emacs-devel@gnu.org; Wed, 07 Dec 2005 09:34:02 -0500 Original-Received: from [81.228.11.98] (helo=pne-smtpout1-sn1.fre.skanova.net) by monty-python.gnu.org with esmtp (Exim 4.34) id 1Ek0Ne-0006Zj-Dl; Wed, 07 Dec 2005 09:34:50 -0500 Original-Received: from [192.168.123.121] (83.249.218.244) by pne-smtpout1-sn1.fre.skanova.net (7.2.060.1) id 4396EEA400001B3A; Wed, 7 Dec 2005 15:33:33 +0100 User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923) X-Accept-Language: en-us, en Original-To: Lennart Borgman In-Reply-To: <4396B5B1.10501@student.lu.se> X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:47115 Archived-At: Lennart Borgman wrote: > Stefan Monnier wrote: > >>> I set the "help keys" to nil so that the help is still available during >>> resizing. Those are the keys I want to remove afterwards. The >>> default value >>> in the sparse keymap bw-keymap is: >>> >> >> >> >> >>> (define-key bw-keymap [t] 'bw-exit-resize-mode) >>> >> >> >> I see. Coming from a functional programming background, I'd use anoter >> approach based on the idea of reusing the original value rather than >> using >> side-effects to try and coerce it back to the same shape it had >> originally: >> >> (defvar bw-keymap >> (let ((map (make-sparse-keymap))) >> (define-key map [t] 'bw-exit-resize-mode) >> map)) >> >> then when adding help-event-list bindings: >> >> (setq bw-keymap (let ((map (make-sparse-keymap))) >> (set-keymap-parent map bw-keymap) >> map)) >> ;; dolist is more efficient than mapc. >> (dolist (key help-event-list) >> (define-key bw-keymap (vector key) nil)) >> >> and when you want to remove those keys, just do >> >> (setq bw-keymap (keymap-parent bw-keymap)) >> >> Of course, you can use variants of it, e.g. introduce a "bw-basic-map" >> variable to keep the original map, rather than rely on (keymap-parent >> bw-keymap) holding that original map. >> >> > I wrote too early. For some reason this does not work. It seems like > the help keys just runs the default function (ie > 'bw-exit-resize-mode). Here is the output from (describe-variable > 'bw-keymap (get-buffer-create "*Help*")): I wrote too early once again. I was adding the old bw-keymap to emulation-mode-map-alist, not the new one. When I changed this the above procedures work nicely. Sorry for the unnecessary noise.