[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-readline] functions for multi-line [patch]
From: |
erlk ozlr |
Subject: |
[Bug-readline] functions for multi-line [patch] |
Date: |
Sun, 26 Aug 2007 11:40:54 +0200 |
Hi,
in IPython (a Python interpreter which uses Readline), there is
sometimes a kind of multi-line (I don't know very much about Readline)
(when you type a function and go back on it with the history), and the
"beginning-of-line", "end-of-line" don't work as their names intend :
they go to the beginning (or end) of *all* lines.
So here is a patch that adds 2 new function with better behavior, I
preferred not to modify the old behavior since I'm noob and don't want
to break things :-) .
Maybe other functions need to be modified, maybe this code is stupid,
maybe anything, please give feedback.
===
diff -ruN readline-orig/funmap.c readline5-5.2/funmap.c
--- readline-orig/funmap.c 2005-03-26 01:23:38.000000000 +0100
+++ readline5-5.2/funmap.c 2007-08-26 10:34:37.000000000 +0200
@@ -68,6 +68,10 @@
{ "backward-word", rl_backward_word },
{ "beginning-of-history", rl_beginning_of_history },
{ "beginning-of-line", rl_beg_of_line },
+ { "beginning-of-multi-line", rl_beg_of_line }, /* beginning-of-line
isn't what it does, but
+ not to break compatibility,
+ make an alias */
+ { "beginning-of-single-line", rl_beg_of_1_line }, /* new function */
{ "call-last-kbd-macro", rl_call_last_kbd_macro },
{ "capitalize-word", rl_capitalize_word },
{ "character-search", rl_char_search },
@@ -90,6 +94,8 @@
{ "end-kbd-macro", rl_end_kbd_macro },
{ "end-of-history", rl_end_of_history },
{ "end-of-line", rl_end_of_line },
+ { "end-of-multi-line", rl_end_of_line }, /* same as
beginning-of-multi-line */
+ { "end-of-single-line", rl_end_of_1_line },
{ "exchange-point-and-mark", rl_exchange_point_and_mark },
{ "forward-backward-delete-char", rl_rubout_or_delete },
{ "forward-byte", rl_forward_byte },
diff -ruN readline-orig/readline.h readline5-5.2/readline.h
--- readline-orig/readline.h 2006-08-16 21:16:59.000000000 +0200
+++ readline5-5.2/readline.h 2007-08-26 10:20:49.000000000 +0200
@@ -92,6 +92,8 @@
extern int rl_backward PARAMS((int, int));
extern int rl_beg_of_line PARAMS((int, int));
extern int rl_end_of_line PARAMS((int, int));
+extern int rl_beg_of_1_line PARAMS((int, int));
+extern int rl_end_of_1_line PARAMS((int, int));
extern int rl_forward_word PARAMS((int, int));
extern int rl_backward_word PARAMS((int, int));
extern int rl_refresh_line PARAMS((int, int));
diff -ruN readline-orig/text.c readline5-5.2/text.c
--- readline-orig/text.c 2006-07-28 17:55:27.000000000 +0200
+++ readline5-5.2/text.c 2007-08-26 10:43:03.000000000 +0200
@@ -407,7 +407,7 @@
return (rl_backward_char (count, key));
}
-/* Move to the beginning of the line. */
+/* Move to the beginning of the line or text (if multiple lines). */
int
rl_beg_of_line (count, key)
int count, key;
@@ -416,7 +416,36 @@
return 0;
}
-/* Move to the end of the line. */
+/* Move to the beginning of a single line. If already at beginning, move to
+ beginning of previous line. */
+int
+rl_beg_of_1_line (count, key)
+ int count, key;
+{
+ int c;
+
+ if (rl_point)
+ {
+ rl_point = MB_PREVCHAR (rl_line_buffer, rl_point, MB_FIND_NONZERO);
+ }
+
+ while (rl_point)
+ {
+ rl_point = MB_PREVCHAR (rl_line_buffer, rl_point, MB_FIND_NONZERO);
+
+ c = _rl_char_value (rl_line_buffer, rl_point);
+ /* FIXME newline and cygwin ? */
+ if (isascii (c) && c == '\n')
+ {
+ rl_point = MB_NEXTCHAR (rl_line_buffer, rl_point, 1,
MB_FIND_NONZERO);
+ break;
+ }
+
+ }
+ return 0;
+}
+
+/* Move to the end of the line or text (if multiple lines). */
int
rl_end_of_line (count, key)
int count, key;
@@ -425,6 +454,29 @@
return 0;
}
+/* Move to the end of a single line. If already at end of line, move to end of
+ next line. */
+int
+rl_end_of_1_line (count, key)
+ int count, key;
+{
+ int c;
+
+ while (rl_point < rl_end)
+ {
+ rl_point = MB_NEXTCHAR (rl_line_buffer, rl_point, 1, MB_FIND_NONZERO);
+
+ c = _rl_char_value (rl_line_buffer, rl_point);
+ /* FIXME newline and cygwin ? */
+ if (isascii (c) && c == '\n')
+ {
+ break;
+ }
+
+ }
+ return 0;
+}
+
/* Move forward a word. We do what Emacs does. Handles multibyte chars. */
int
rl_forward_word (count, key)
===
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Bug-readline] functions for multi-line [patch],
erlk ozlr <=