[gnu.bash.bug] Novice question on binding keys

mpf@triplea.cs.umd.edu (Martin Farach) (09/10/89)

Sorry for posting this message on a newsgroup that is set up for bug
reporting but I didn't know where else to post.

I use tcsh and have my arrow keys set to do the expected things.  I
just started using bash and I tried getting the same behaviour.  I
tried the following .inputrc:

M-O: prefix-meta
M-A: previous-history
M-B: next-history
M-C: forward-char
M-D: backward-char


as well as :

M-OA: previous-history
M-OB: next-history
etc.

and 

M-O-A: previous-history

and every other combination I could think of.  The weird thing is that
if I type ESC-O-A manually, I get the behaviour I want.  If I hit the
up-arrow key, I get an A inserted into the line.  Is there a way to
get the desired behaviour?  (bash-1.03, bison, gcc, sun3, vt100
terminal).

Also, can user defined functions be bound to keys?  Finally, can key
bindings be changed on the fly rather than by changing .inputrc and
then starting up a new bash?

Thanks for you help.


*******************************************************************************
* Martin Farach				|                                     *
* University of Maryland		|                                     *
* Department of Computer Science	|                                     *
* College Park, Maryland 20742		|                                     *
*					|                                     *
* also know as:				|                                     *
* mpf@brillig.umd.edu			|                                     *
*******************************************************************************
--

*******************************************************************************
* Martin Farach				|                                     *
* University of Maryland		|                                     *
* Department of Computer Science	|                                     *
* College Park, Maryland 20742		|                                     *
*					|                                     *
* also know as:				|                                     *
* mpf@brillig.umd.edu			|                                     *
*******************************************************************************

nickson@comp.vuw.ac.nz (Ray Nickson) (09/13/89)

   From:  Martin Farach <mpf@MIMSY.UMD.EDU>
   Date:  9 Sep 89 18:01:00 GMT

   
   Sorry for posting this message on a newsgroup that is set up for bug
   reporting but I didn't know where else to post.
Hey, don't worry, the rest of us do it all the time.

   I use tcsh and have my arrow keys set to do the expected things. 
   [ ... ]  Is there a way to get the desired behaviour? [ ... ]
No, not with the current version.

   Also, can user defined functions be bound to keys?  Finally, can key
   bindings be changed on the fly rather than by changing .inputrc and
   then starting up a new bash?
Ditto.

However, I've been doing some hacking... :-)

The version I'm using has hacks in it to do the following:

- readline reads .keymaprc in $HOME (or file specified in KEYMAPRC);
  this contains lines of the form
    bind <keyseq> <readline_function>
    unbind <keyseq>
    mbind <keyseq> <macro>
    clear
    include <file>
  <keyseq> is a sequence of characters, with the following special
    interpretations: 
      \C-   control
      \M-   meta
      \F-   lookup termcap; eg. \F-ku represents the up-arrow key
  <readline-function> is the name of a function (previous-line etc)
  <macro> is a sequence of characters to dispatch on
  <file> is the name of a file to include
- bind, unbind are new shell builtins, for changing bindings on the fly
- extra readline functions: 
   signal-{stop, quit, interrupt}  - send signals
   redraw-line                     - tidy up messy displays
   yank-previous-nth-arg           - pull words down from history

I have sent my readline hacks to Brian.  The code I have written works
in the limited environments I have tried it, but is not at all
well-written, and is certainly not portable, so I'd rather not
generally distribute it.  I also haven't got around to slotting it
into 1.03, so it still exists only as 1.02 patches.  Anyone care to
comment on the value of these ideas?

/* readline.c -- a general facility for reading lines of input
   with emacs style editing and completion. */

/* 
 * This version of readline has been massively modified by rgn, Ray
 * Nickson, nickson@comp.vuw.ac.nz.  It is based on the version of
 * readline distributed with bash-1.02.  It differs from standard readline
 * in the following ways:
 *  1. I allow keymaps within keymaps; for example, the keymap entry for
 *     control-X can itself be a keymap, so the user can bind a function
 *     to control-X control-A.
 *  2. I think we should give readline complete control of  the
 *     keyboard.  To this end, I save the UNIX terminal driver special
 *     characters (the tchars, like ERASE, SUSP etc) before going into
 *     readline, remove their special meaning, and then restore tham
 *     on exit.  To achieve the old behaviour, I supply the readline
 *     functions `signal-interrupt', `signal-stop' and `signal-quit',
 *     which the user binds to the keys of her choice.
 *  3. I've massively changed the format of (and renamed) the startup
 *     file (was ~/.inputrc).  Read the comment before the
 *     `rl_read_init_file' for details.  I'll supply an
 *     emacs-lisp program to convert an inputrc to a keymaprc.
 *     Important extensions allow binding to key sequences (instead of
 *     just single keystrokes), and the use of termcap names for
 *     function keys. 
 *  4. I advertise a function to allow readline's caller to
 *     interactively change bindings, without knowing about readline's
 *     internal structure.
 *  5. Limited `macro' facility; `mbind keyseq string' in the keymaprc
 *     causes readline to dispatch on the characters in string when
 *     keyseq is typed.  I advertise a function to the caller for
 *     interactively doing macro binds.
 *  6. It should be possible to add a facility for binding to things
 *     that have meaning to readline's caller, but not to readline
 *     itself (such as shell functions) more easily than is the case
 *     with standard readline. 
 *  7. I haven't done vi mode; I don't think it would be excessively
 *     hard to do.
 *  8. I haven't tried to make it work with terminfo; what I have
 *     done has been tried only on systems with termcap or termcap
 *     emulation. 
 */

--
Ray Nickson, Dept. Comp. Sci., Victoria University of Wellington, New Zealand.
nickson@comp.vuw.ac.nz       ...!uunet!vuwcomp!nickson      + 64 4 721000x8593

bfox@AUREL.CALTECH.EDU (Brian Fox) (09/13/89)

   Date: Wed, 13 Sep 89 16:36:28 +1200
   From: Ray Nickson <nickson@comp.vuw.ac.nz>

      From:  Martin Farach <mpf@MIMSY.UMD.EDU>
      Date:  9 Sep 89 18:01:00 GMT

   - readline reads .keymaprc in $HOME (or file specified in KEYMAPRC);
     this contains lines of the form
       bind <keyseq> <readline_function>
       unbind <keyseq>
       mbind <keyseq> <macro>
       clear
       include <file>
     <keyseq> is a sequence of characters, with the following special
       interpretations: 
	 \C-   control
	 \M-   meta
	 \F-   lookup termcap; eg. \F-ku represents the up-arrow key
     <readline-function> is the name of a function (previous-line etc)
     <macro> is a sequence of characters to dispatch on
     <file> is the name of a file to include
   - bind, unbind are new shell builtins, for changing bindings on the fly
   - extra readline functions: 
      signal-{stop, quit, interrupt}  - send signals
      redraw-line                     - tidy up messy displays
      yank-previous-nth-arg           - pull words down from history

   I have sent my readline hacks to Brian.  The code I have written works
   in the limited environments I have tried it, but is not at all
   well-written, and is certainly not portable, so I'd rather not
   generally distribute it.  I also haven't got around to slotting it
   into 1.03, so it still exists only as 1.02 patches.  Anyone care to
   comment on the value of these ideas?

Whoa, slow down there big guy!  I have rewritten the way keymaps in
readline work (this last day) which should allow us to use multiple key
bindings.  I have added a new command called load-bindings, so you can
re-read your .inoputrc file on the fly.  I plan to merge your F- (lookup
terminal string) stuff into readline because I think that it is a really
good idea.  I had planned to do yank-previous-nth-arg, but if your
implementation is clean, I will be glad to use it instead!

SUSP (C-z) and INTR (C-c) are not available for binding in my version of
readline.  STOPC (C-s) is.  If you have turned off flow-control, then
so is STARTC (C-q).  Otherwise, it is automatically bound to
restart-ouput-flow.

In 1.03 (and later versions) a numeric arg to clear-screen (C-l) says to
only redraw the current line instead of clearing the whole screen.  This
can be called as a separate function, so you could bind C-l to it
instead.

Next:  Marks within a line for region hacking.

Brian

bfox@AUREL.CALTECH.EDU (Brian Fox) (09/14/89)

   Date: Wed, 13 Sep 89 16:36:28 +1200
   From: Ray Nickson <nickson@comp.vuw.ac.nz>

      From:  Martin Farach <mpf@MIMSY.UMD.EDU>
      Date:  9 Sep 89 18:01:00 GMT


   I have sent my readline hacks to Brian.

I can't seem to find your version of readline.  Could you send me
readline.c please?

Brian