Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!bbn!jr@bbn.com From: jr@bbn.com (John Robinson) Newsgroups: comp.emacs Subject: Re: How to define VT2xx or VT3xx function keys in .emacs file? Message-ID: <36802@bbn.COM> Date: 6 Mar 89 16:23:58 GMT References: <36761@bbn.COM> Sender: news@bbn.COM Reply-To: jr@bbn.com (John Robinson) Organization: BBN Systems and Technologies Corporation, Cambridge MA Lines: 82 In-reply-to: DHASKIN@CLARKU.BITNET In article <36761@bbn.COM>, DHASKIN@CLARKU writes: >Okay, I *know* this can be done, and I'm apparently missing something >obvious. I would like Emacs to start up with the Do key define as M-x >and Insert Here defined as yank. I have no problem doing it once I'm >*in* Emacs, with either global-set-key or: > > (define-key esc-map "[26~" 'execute-extended-command) > >but when I put the above line in my .emacs file, I get an "Error in Init >File" or some such thing when Emacs starts up. (BTW, I know that [26~ may >not be *quite* the sequence, but y'know what I mean). > >Is this the right direction? Or does it involve the CSI-map? I feel sort of >foolish, it should be easy. But then again, I do recall a discussion a >few months ago about what one could and couldn't do in a .emacs file. I believe this is because the key bindings at the time your .emacs file is executed are simply the defaults. ESC-[ starts off bound to backward-paragraph, and so can't be the prefix of a longer command string. After it has finished you .emacs, emacs reads terminal-specific initialization from the file ..emacs/lisp/term/vt200.el (assuming your TERM variable is "vt200"), which will set things so that ESC-[ is a prefix. Here's how that happens: (global-set-key "\e[" CSI-map) Once ESC-[ is bound to a keymap, things are fine. This won't happen until you call the function (enable-arrow-keys). Look in vt200.el for more information on what happens at startup. Now, since vt200.el is normally read *after* your .emacs, you can't modify bindings that depend on its keymap settings. However, there is a way: term-setup-hook's value is nil Documentation: Function to be called after loading terminal-specific lisp code. It is called with no arguments. You can use this to override the definitions made by the terminal-specific file. You could do something like this in your .emacs: (defun my-vt200-init () "Enable the VT200 function keys and bind the Do key" (enable-arrow-keys) (define-key esc-map "[26~" 'execute-extended-command)) (setq term-setup-hook 'my-vt200-init) [Programming style aside: this ought to be careful not to trample an existing term-setup-hook; to be really cute it should append to the hook, avoiding signing itself up twice by scanning the list first. There oughta be a package to help with this...any volunteers?] Rather than define-key, you should use global-set-key: (global-set-key "\e[26~" 'execute-extended-command) This avoids having to know the name of esc-map, which just could change under you some day. Having said all this, there is another way that ought to work in your .emacs file: (require 'keypad) (keypad-default "x" 'execute-etended-command) The beauty of this is that it will work across all terminals that have a "Do" key, and avoids the hassle of the term-setup-hook. Details in lisp/keypad.el. Let me also echo the complaints about the un-help-ful-ness [that's kind-er-and-gen-tle-er speak] of "Error in Init file"! p.s. to Kyle Jones: another one for the frequent questions file? -- /jr jr@bbn.com or bbn!jr