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 11:13:05 +0100 Message-ID: <4396B5B1.10501@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> 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 1133961487 14961 80.91.229.2 (7 Dec 2005 13:18:07 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 7 Dec 2005 13:18:07 +0000 (UTC) Cc: rms@gnu.org, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Dec 07 14:18:05 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Ejz8r-0001JL-96 for ged-emacs-devel@m.gmane.org; Wed, 07 Dec 2005 14:15:29 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ejz94-0000G7-Tw for ged-emacs-devel@m.gmane.org; Wed, 07 Dec 2005 08:15:43 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1EjwRl-0000h2-Ot for emacs-devel@gnu.org; Wed, 07 Dec 2005 05:22:51 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1EjwOm-00008K-BM for emacs-devel@gnu.org; Wed, 07 Dec 2005 05:19:45 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EjwIj-0007pf-BM for emacs-devel@gnu.org; Wed, 07 Dec 2005 05:13:30 -0500 Original-Received: from [81.228.8.83] (helo=pne-smtpout1-sn2.hy.skanova.net) by monty-python.gnu.org with esmtp (Exim 4.34) id 1EjwJX-0000tU-Jp; Wed, 07 Dec 2005 05:14:19 -0500 Original-Received: from [192.168.123.121] (83.249.218.244) by pne-smtpout1-sn2.hy.skanova.net (7.2.060.1) id 4394B872000718E0; Wed, 7 Dec 2005 11:13:10 +0100 User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923) X-Accept-Language: en-us, en Original-To: Stefan Monnier In-Reply-To: <87pso97k0r.fsf-monnier+emacs@gnu.org> 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:47107 Archived-At: 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 to 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*")): bw-keymap is a variable defined in `c:/emacs-lisp/test/bwcvs.el'. Its value is shown below. Documentation: Keymap used by `bw-window-resize-mode'. Value: (keymap (f1) (help) keymap (right . bw-mode-resize-right) (left . bw-mode-resize-left) (down . bw-mode-resize-down) (up . bw-mode-resize-up) (102 . bw-shrink-windows-horizontally) (46 . bw-balance-siblings) (43 . bw-balance) (t . bw-exit-resize-mode) (menu-bar keymap (bw "&Resize" keymap (balance "Balance Windows" . bw-balance) (siblings "Balance Window Siblings" . bw-balance-siblings) (shrink "Shrink to Buffers" . bw-shrink-windows-horizontally) "second")) "Window Resizing") [back]