Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/17/84 chuqui version 1.7 9/23/84; site nsc.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!ihnp4!pesnta!amd!nsc!glenn From: glenn@nsc.UUCP (Glenn Skinner) Newsgroups: net.emacs Subject: Re: a simple problem for 4.2 gosling-emacs Message-ID: <2685@nsc.UUCP> Date: Thu, 9-May-85 12:51:12 EDT Article-I.D.: nsc.2685 Posted: Thu May 9 12:51:12 1985 Date-Received: Sat, 11-May-85 01:42:52 EDT References: <271@sbcs.UUCP> Reply-To: glenn@nsc.UUCP (Glenn Skinner) Distribution: net Organization: National Semiconductor, Sunnyvale Lines: 55 Summary: keymaps to the rescue! In article <271@sbcs.UUCP> podar@sbcs.UUCP (Sunil Podar) wanted to write an MLisp function that used command completion to get a buffer name, but that supplied a default buffer name if the user simply typed CR as a response. The following function can be used to construct such a function. He suggested that someone send him a solution by mail, but since the technique used is nonobvious, I decided to post the solution. The basic idea is to use a local keymap that binds everything to self-insert-and-exit to obtain a single character. If this character is CR, we return the default buffer name. Otherwise, we push back the character obtained, restore keymaps and use get-tty-buffer to get the rest of the name. The function below assumes that you have the UniPress V2.00 version of gosmacs -- it uses current-local-keymap. If you have an older version, you'll have to kludge around it. (defun (get-defaulted-buffer-name default oldmap key buffer (setq default (arg 1 ": get-defaulted-buffer-name ")) (setq oldmap (current-local-keymap) (use-local-map "single-char-keymap") (setq key "") ; It's important to use error-occurred here. Otherwise we could ; end up with a keymap that leaves us totally helpless! (error-occurred (setq key (get-tty-string "")) ) (use-local-map oldmap) (if (!= key "") (progn (push-back-string key) (setq buffer (get-tty-buffer "")) ) (setq buffer default) ) buffer ) ) (progn i oldmap (define-keymap "single-char-keymap") (setq oldmap (current-local-keymap)) (use-local-map "single-char-keymap") (setq i 0) (while (< i 0200) (local-bind-to-key "self-insert-and-exit" i) (setq i (+ i 1)) ) (use-local-map oldmap) ) Caveat: I haven't actually tested this code. However, I've used code very similar to it for other purposes. -- Glenn Skinner National Semiconductor, Microcomputer Systems Division (408) 733-2600 x 335