HOWTO: Mouse editing with readline in xterm

HOWTO: Mouse editing with readline in xterm

am 16.11.2005 01:08:07 von Ilya Zakharevich

Several years ago I sent a message with the same subject;

http://groups.google.com/group/comp.unix.shell/msg/e538d04a1 18174d3

Updates:

a) With newer xterms, this compile-time option is enabled with
--enable-mouse-readline
given to ./configure. With older xterms, you may use the side
effect of
--enable-paste64
enabling this option too.

b) Here is the relevant part of my .tcshrc (with literal ESC
replaced by \e for the purpose of posting):

if ( ! $?MOUSE_READLINE_ON ) setenv MOUSE_READLINE_ON
if ($term =~ xterm*) then
setenv MOUSE_READLINE_ON '\e[?2001;2002;2003;2004;2005;2006s\e[?2001;2002;2003h'
setenv MOUSE_GNU_READLINE_ON '\e[?2001;2002;2003;2004;2005;2006s\e[?2001;2002;2003;2004;2 005;2006h'
setenv MOUSE_READLINE_OFF '\e[?2001;2002;2003;2004;2005;2006r'
endif
set prompt = "%{^[]0;$user_in_prompt%m: %~/^G%}%U%m%u%B:%b%U%~%u%B%{$MOUSE_READLINE_ON%}->%b"

# Better do chomp, but some HPUXes have perl4 only
# Similarly, can't use s///s
alias post_cmd 'perl -we '"'"'$_ = shift; s/[;\x07\n][^\n]*/.../; s~^~\e]0;$ARGV[1]:$ARGV[0]/> ~; s/$/\x07/; s/\Q$ENV{HOME}/~/g; print $ENV{MOUSE_READLINE_OFF} if exists $ENV{MOUSE_READLINE_OFF}; print'"'"' "\!#:q" $cwd $user_in_title$__hostname'
sched +0:00 alias postcmd post_cmd

The important here part of post_cmd is to emit MOUSE_READLINE_OFF
(the _ON part is emited during the prompt showing). Currently,
for GNU readline applications one needs to manually emit
MOUSE_GNU_READLINE_ON before the start, _OFF after the end.

Hope this helps,
Ilya

P.S. I'm sitting on patches to xterm which make mouse editing yet
much more pleasant (allow correct treatement of prefix
arguments, undo etc; some support of embedded LF too).
Unfortunately, can't convince Thomas to include them...