infos:
tested rl version: 5.2, 6
OS: Ubuntu Hardy, Debian Sid

key sequence matching in callback functions fails when a 2-letters-shorter
key seq is defined
the attached "rltest.c" demostrates it.

I think it's a bug in rl_dispatch_callback and hacked it (only one line
though).
the patch is attached, hope that it helps. It's a great library :)

--------------
another things which i consider a bug is that while user hava an .inputrc
setting editing mode to vi,
readline automatically sets the working keymap to vi_insertion_keymap in the
initialization sequence.
 here's the backtracking:

#0  rl_vi_insertion_mode (count=1, key=105) at vi_mode.c:664
#1  0x08049671 in rl_vi_start_inserting (key=105, repeat=1, sign=1) at
vi_mode.c:167
#2  0x08049699 in rl_vi_insert_mode (count=1, key=105) at vi_mode.c:672
#3  0x08049233 in readline_internal_setup () at readline.c:395
#4  0x08059cdd in _rl_callback_newline () at callback.c:89
#5  0x08059fe4 in rl_callback_handler_install (prompt=0x80cae1f "",
linefunc=0x80481f0 <parse>) at callback.c:102
#6  0x0804837c in main () at rltest.c:57

with a little difference between version 5.x and 6, they both eventually
change the working keymap
which is called after the startup hook has been called. so the only way my
program ensures using custom
keymap is to set the pre_input_hook. Is this an appropriate behavior of
readline ?

English is not my native language, but I'd be willing to help if any further
information is needed.

-- 
Cheers,
freehaha.
#include <stdio.h>
#include <stdlib.h>
#include <readline/history.h>
#include <readline/readline.h>

static Keymap kmap;

/* line handler */
void parse(char *input)
{
	if(!input)
	{
		rl_callback_handler_remove();
		rl_discard_keymap(kmap);
		exit(1);
	}

	free(input);
}

/* ESC handler*/
int hit1(int count, int key)
{
	fprintf(stderr, "hit!\n");	
	return 0;
}

/* PageDown handler */
int hit2(int count, int key)
{
	fprintf(stderr, "hit seq!\n");	
	return 0;
}

int preinput()
{
	rl_set_keymap(kmap);
	return 0;
}

int main(int argc, char **argv)
{
	char *buf;

	kmap = rl_make_keymap();
	rl_bind_key_in_map(10, rl_newline, kmap);
	rl_bind_key_in_map(13, rl_newline, kmap);
	rl_bind_key_in_map(4, rl_delete, kmap);
	rl_bind_keyseq_in_map("\e", hit1, kmap); /* happens when using vi-mode */
	rl_bind_keyseq_in_map("\e[6~", hit2, kmap); /* page down */
#if 0
	rl_bind_keyseq_in_map("\e[6", hit2, kmap); /* this work, but it's not pagedown ..  */
#endif

	rl_pre_input_hook = preinput; /* ensure kmap is used regardless of .inputrc */
	rl_callback_handler_install("", parse);
	while(1)
	{
		rl_callback_read_char();
	}
	return 0;
}


diff -ruN readline-6.0/readline.c readline-6.0.1/readline.c
--- readline-6.0/readline.c 2009-01-26 10:33:34.000000000 +0800
+++ readline-6.0.1/readline.c	2009-08-04 17:10:30.000000000 +0800
@@ -686,7 +686,8 @@
     r = cxt->childval;
 
   /* For now */
-  r = _rl_subseq_result (r, cxt->oldmap, cxt->okey, (cxt->flags & KSEQ_SUBSEQ));
+  if(r != -3 ) /* unless there's not going to be any other matches */
+   r = _rl_subseq_result (r, cxt->oldmap, cxt->okey, (cxt->flags & KSEQ_SUBSEQ));
 
   RL_CHECK_SIGNALS ();
   if (r == 0)		/* success! */

_______________________________________________
Bug-readline mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-readline

Reply via email to