|
From: | Lennart Borgman |
Subject: | Re: Function for deleting a key binding in a sparse keymap |
Date: | Wed, 07 Dec 2005 11:13:05 +0100 |
User-agent: | Mozilla Thunderbird 1.0.7 (Windows/20050923) |
Stefan Monnier wrote:
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*")):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.
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]
[Prev in Thread] | Current Thread | [Next in Thread] |