# HG changeset patch
# User Kwankyu Lee <ekwankyu@gmail.com>
# Date 1370400844 -32400
# Node ID d85b9c16f8754c908da46af835bf1a7993a06789
# Parent 9b3e6b467313a8df84543e4cbc882580a9fc0678
Trac #14687: fixes the broken readline extra commands
diff --git a/sage/misc/all.py b/sage/misc/all.py
a
|
b
|
|
178 | 178 | |
179 | 179 | from unknown import Unknown |
180 | 180 | |
181 | | from readline_extra_commands import * |
182 | 181 | ########################################################################## |
183 | 182 | def benchmark(n=-1): |
184 | 183 | """ |
diff --git a/sage/misc/readline_extra_commands.pyx b/sage/misc/readline_extra_commands.pyx
a
|
b
|
|
12 | 12 | |
13 | 13 | The ``history-search-backward-and-save`` command searches backward in the history |
14 | 14 | for the string of characters from the start of the input line to the current cursor |
15 | | position, and fetches the line found. If the cursor is at the start of the line, the previous line |
16 | | is fetched. The position of the fetched line is saved internally. |
| 15 | position, and fetches the first line found. If the cursor is at the start of the line, the previous line |
| 16 | is fetched. The position of the fetched line is saved internally, and the next search begins at the |
| 17 | saved position. |
17 | 18 | |
18 | | The ``history-search-forward-and-save`` command behaves similarly but forward. This |
19 | | command is useful to fetch a block of lines from the history by first searching the first |
20 | | line of the block and then issuing this command as many times as needed. |
| 19 | The ``history-search-forward-and-save`` command behaves similarly but forward. |
21 | 20 | |
22 | | The previous two commands is best used in tandem. They are intended to replace the |
23 | | ``history-search-backward`` command and the ``history-search-forward`` command provided by |
24 | | the GNU readline library used in Sage. |
| 21 | The previous two commands is best used in tandem to fetch a block of lines from the history, |
| 22 | by searching backward the first line of the block and then issuing the forward command as many times as needed. |
| 23 | They are intended to replace the ``history-search-backward`` command and the ``history-search-forward`` command |
| 24 | provided by the GNU readline library used in Sage. |
25 | 25 | |
26 | | To bind these commands with keys, insert the relevant lines into the ``$DOT_SAGE/ipython/ipythonrc`` |
27 | | file. Note that ``$DOT_SAGE`` is ``$HOME/.sage`` by default. For example, |
28 | | |
| 26 | To bind these commands with keys, insert the relevant lines into the IPython configuration file |
| 27 | ``$DOT_SAGE/ipython-0.12/profile_sage/ipython_config.py``. Note that ``$DOT_SAGE`` is ``$HOME/.sage`` |
| 28 | by default. For example, |
29 | 29 | :: |
30 | 30 | |
31 | | readline_parse_and_bind "\C-o": operate-and-get-next |
32 | | readline_parse_and_bind "\e[A": history-search-backward-and-save |
33 | | readline_parse_and_bind "\e[B": history-search-forward-and-save |
| 31 | c = get_config() |
| 32 | |
| 33 | c.InteractiveShell.readline_parse_and_bind = [ |
| 34 | '"\C-o": operate-and-get-next', |
| 35 | '"\e[A": history-search-backward-and-save', |
| 36 | '"\e[B": history-search-forward-and-save' |
| 37 | ] |
34 | 38 | |
35 | 39 | binds the three commands with the control-o key, the up arrow key, and the down arrow key, |
36 | | respectively. Warning: Sometimes, these keys may be bound to do other actions by the terminal and does not |
| 40 | respectively. *Warning:* Sometimes, these keys may be bound to do other actions by the terminal and does not |
37 | 41 | reach to the readline properly (check this by running ``stty -a`` and reading the ``cchars`` section). Then |
38 | 42 | you may need to turn off these bindings before the new readline commands work fine . A prominent case is when |
39 | | control-o is bound to discard by the terminal. You can turn this off by running ``stty discard undef``. |
| 43 | control-o is bound to ``discard`` by the terminal. You can turn this off by running ``stty discard undef``. |
40 | 44 | |
41 | 45 | AUTHORS: |
42 | 46 | |
43 | 47 | - Kwankyu Lee (2010-11-23): initial version |
| 48 | - Kwankyu Lee (2013-06-05): updated for the new IPython configuration format. |
44 | 49 | """ |
45 | 50 | |
46 | 51 | #***************************************************************************** |
… |
… |
|
254 | 259 | rl_add_defun("operate-and-get-next", &operate_and_get_next, -1) |
255 | 260 | rl_add_defun("history-search-backward-and-save", &history_search_backward_and_save, -1) |
256 | 261 | rl_add_defun("history-search-forward-and-save", &history_search_forward_and_save, -1) |
| 262 | |