I want to redefine keybindings for the commandline of a lisp dialect. The commandline is actually modeled after Vi and implemented with tput/terminfo. I want an alternative version with Emacs keybindings, and I would like to give it a try without using gnu readline or so.
A typical key assignment looks like this:
(setq *XtF1 (in '("tput" "kf1") (line T)) ...
This question is about the
("tput" "kf1")
part, ignore the rest.
Now, "kf1" is easy to find in the terminfo man-page:
key_f1 kf1 k1 F1 function key
I find there 3 entries for "meta" too:
has_meta_key km km Has a meta key
(i.e., sets 8th-bit)
meta_off rmm mo turn off meta mode
meta_on smm mm turn on meta mode
(8th-bit on)
But how can I use this info to define typical Emacs keybindings like e.g. M-f, M-b, M-d etc. with tput?
Best Answer
terminfo is probably not going to help you much. In most terminal emulators, you can configure with
M-x
sends<Esc>x
orx
with the 8th bit set, and the terminfo entry won't magically be updated when the user does so.Also, most character sets are 8bits now, so it doesn't make much sense nowadays to use that 8th bit for Meta.
I would just hardcode
M-x
==<Esc>x
(the sequence of two characters\033
andx
). This way, even if the terminal doesn't support that mode, the user can still type Esc, x in sequence.