Here is how to enable mouse-editing of the command line in recent
xterm's (similar to how one uses mouse in Emacs):
a) After running xterm's ./configure, add -DOPT_READLINE to the
Makefile. [It is a bug in configure that one cannot do this easier ;-]
b) This enables the following new [undocumented :-(] control codes for
DECSET etc:
#define SET_BUTTON1_MOVE_POINT 2001 /* click1 emit Esc seq to move point*/
#define SET_BUTTON2_MOVE_POINT 2002 /* press2 emit Esc seq to move point*/
#define SET_DBUTTON3_DELETE 2003 /* Double click-3 deletes */
#define SET_PASTE_IN_BRACKET 2004 /* Surround paste by escapes */
#define SET_PASTE_QUOTE 2005 /* Quote each char during paste */
#define SET_PASTE_LITERAL_NL 2006 /* Paste "\n" as C-j */
The reasonable sequence to enable this feature in ReadLine applications is:
0) Decide which features are good for a given ReadLine library;
E.g., for tcsh it is reasonable to use 2001;2002;2003.
For bare GNU readline it is reasonable to use 2001;2002;2003;2005;2006.
For applications which redefine many "usual keys" to do shortcuts
(e.g., redefine "(" to insert a matched pair of parens) one could
enable 2005. If application redefines the quote-char, then
enabling 2004 may be an alternative: bind F200 and F201 to switch
off/on these bindings. 2004 is also useful for aplications which
want to treat pasting absolutely different than user keys (vi
editing mode?).
1) Before showing the prompt, emit CSI ? Pm s to save the settings,
then emit CSI ? Pm h to set new values. After the command line
editing is done, one should emit CSI ? Pm r to restore the old
values. Here Pm is the string discussed in (0), e.g.,
"2001;2002;2003" (without quotes).
2) If one has no such fine-grain control over the readline
application, the poor man solution is to emit these sequences
before and after running the application (instead of before and
after editing a line). However, in such cases xterm might
emulate presses of Left and Right in "wrong moments".
Here is the example for tcsh:
if ( $?SSH_CLIENT ) then
set user_in_prompt = '%n@'
set user_in_title = $LOGNAME'@'
else
set user_in_prompt = ''
set user_in_title = ''
endif
setenv MOUSE_READLINE_ON ' [?2001;2002;2003;2004;2005;2006s^[[?2001;2002;2003h'
setenv MOUSE_READLINE_OFF ' [?2001;2002;2003;2004;2005;2006r'
set prompt = "%{^[]0;$user_in_prompt%m: %~/^G%}%U%m%u%B:%b%U%~%u%B%{$MOUSE_READLINE_ON%}->%b"
alias post_cmd 'history -h 1 | perl -we '"'"'$_ = <STDIN>; chop; 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'"'"' $cwd $user_in_title$__hostname'
sched +0:00 alias postcmd post_cmd
set __hostname=`hostname`
Enjoy,
Ilya
P.S. Here is somewhat expanded explanation:
2001 on: click-1 "moves point"
2002 on: click-2 "moves point" before doing paste
2003 on: double-click-3 "moves point" to the end of selection, then
emits enough BackSpace characters to erase the selection
2004 on: Emits escape sequences for F200/F201 before/after doing paste
2005 on: When pasting, emit quote-char before any pasted char.
2006 on: When pasting, emit "\n" as C-j (usually emits C-m)
All the mouse bindings are active on the same line as the insertion
cursor only (including wrapped lines). "move point" means "emits
enough Left/Right keysequences to move the point in ReadLine applications".