Mercurial > cpython-lru_cache-weakref
annotate Modules/readline.c @ 58925:eecf1bef052d 2.6
Merged revisions 78207 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line
#7930: fix stripid
........
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Tue, 16 Feb 2010 23:29:44 +0000 |
| parents | f108f6275855 |
| children | e38335d4df91 |
| rev | line source |
|---|---|
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1 /* This module makes GNU readline available to Python. It has ideas |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
2 * contributed by Lee Busby, LLNL, and William Magro, Cornell Theory |
|
34842
de121899d021
Be a bit more accurate.
Michael W. Hudson <mwh@python.net>
parents:
34841
diff
changeset
|
3 * Center. The completer interface was inspired by Lele Gaifax. More |
|
de121899d021
Be a bit more accurate.
Michael W. Hudson <mwh@python.net>
parents:
34841
diff
changeset
|
4 * recently, it was largely rewritten by Guido van Rossum. |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 */ |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
7 /* Standard definitions */ |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 #include "Python.h" |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 #include <setjmp.h> |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 #include <signal.h> |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
11 #include <errno.h> |
|
33686
1701dae6474e
This is Michiel de Hoon's patch, as attached to the bug report:
Michael W. Hudson <mwh@python.net>
parents:
33255
diff
changeset
|
12 #include <sys/time.h> |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 |
|
31504
2abc52c3d4c2
remove support for missing ANSI C header files (limits.h, stddef.h, etc).
Skip Montanaro <skip@pobox.com>
parents:
30910
diff
changeset
|
14 #if defined(HAVE_SETLOCALE) |
|
25684
c7d5801bbae8
GNU readline() mistakenly sets the LC_CTYPE locale.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
15 /* GNU readline() mistakenly sets the LC_CTYPE locale. |
|
c7d5801bbae8
GNU readline() mistakenly sets the LC_CTYPE locale.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
16 * This is evil. Only the user or the app's main() should do this! |
|
c7d5801bbae8
GNU readline() mistakenly sets the LC_CTYPE locale.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
17 * We must save and restore the locale around the rl_initialize() call. |
|
c7d5801bbae8
GNU readline() mistakenly sets the LC_CTYPE locale.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
18 */ |
|
c7d5801bbae8
GNU readline() mistakenly sets the LC_CTYPE locale.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
19 #define SAVE_LOCALE |
|
c7d5801bbae8
GNU readline() mistakenly sets the LC_CTYPE locale.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
20 #include <locale.h> |
|
c7d5801bbae8
GNU readline() mistakenly sets the LC_CTYPE locale.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
21 #endif |
|
c7d5801bbae8
GNU readline() mistakenly sets the LC_CTYPE locale.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
22 |
|
39098
50b0b54fb17d
Fix memory leaks in some conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
23 #ifdef SAVE_LOCALE |
|
50b0b54fb17d
Fix memory leaks in some conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
24 # define RESTORE_LOCALE(sl) { setlocale(LC_CTYPE, sl); free(sl); } |
|
50b0b54fb17d
Fix memory leaks in some conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
25 #else |
|
50b0b54fb17d
Fix memory leaks in some conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
26 # define RESTORE_LOCALE(sl) |
|
50b0b54fb17d
Fix memory leaks in some conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
27 #endif |
|
50b0b54fb17d
Fix memory leaks in some conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
28 |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
29 /* GNU readline definitions */ |
|
17506
55ee15c4eee6
Clean up the unsightly mess around the readline header files. We now
Guido van Rossum <guido@python.org>
parents:
15803
diff
changeset
|
30 #undef HAVE_CONFIG_H /* Else readline/chardefs.h includes strings.h */ |
|
8823
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8391
diff
changeset
|
31 #include <readline/readline.h> |
|
f2a4a2b60860
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
8391
diff
changeset
|
32 #include <readline/history.h> |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
7116
diff
changeset
|
33 |
|
18474
82a34932ea22
Backport of Guido's checkins of acconfig.h (1.50), configure.in (1.224) and
Thomas Wouters <thomas@python.org>
parents:
17506
diff
changeset
|
34 #ifdef HAVE_RL_COMPLETION_MATCHES |
| 27134 | 35 #define completion_matches(x, y) \ |
| 36 rl_completion_matches((x), ((rl_compentry_func_t *)(y))) | |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
39802
diff
changeset
|
37 #else |
|
49641
a529e3dc695a
Merged revisions 67098 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47527
diff
changeset
|
38 #if defined(_RL_FUNCTION_TYPEDEF) |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
39802
diff
changeset
|
39 extern char **completion_matches(char *, rl_compentry_func_t *); |
|
49641
a529e3dc695a
Merged revisions 67098 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47527
diff
changeset
|
40 #else |
|
58820
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
41 #if !defined(__APPLE__) |
|
49641
a529e3dc695a
Merged revisions 67098 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47527
diff
changeset
|
42 extern char **completion_matches(char *, CPFunction *); |
|
a529e3dc695a
Merged revisions 67098 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47527
diff
changeset
|
43 #endif |
|
18474
82a34932ea22
Backport of Guido's checkins of acconfig.h (1.50), configure.in (1.224) and
Thomas Wouters <thomas@python.org>
parents:
17506
diff
changeset
|
44 #endif |
|
58820
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
45 #endif |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
46 |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
47 #ifdef __APPLE__ |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
48 /* |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
49 * It is possible to link the readline module to the readline |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
50 * emulation library of editline/libedit. |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
51 * |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
52 * On OSX this emulation library is not 100% API compatible |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
53 * with the "real" readline and cannot be detected at compile-time, |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
54 * hence we use a runtime check to detect if we're using libedit |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
55 * |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
56 * Currently there is one know API incompatibility: |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
57 * - 'get_history' has a 1-based index with GNU readline, and a 0-based |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
58 * index with libedit's emulation. |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
59 * - Note that replace_history and remove_history use a 0-based index |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
60 * with both implementation. |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
61 */ |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
62 static int using_libedit_emulation = 0; |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
63 static const char libedit_version_tag[] = "EditLine wrapper"; |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
64 #endif /* __APPLE__ */ |
|
18474
82a34932ea22
Backport of Guido's checkins of acconfig.h (1.50), configure.in (1.224) and
Thomas Wouters <thomas@python.org>
parents:
17506
diff
changeset
|
65 |
|
43825
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
66 static void |
|
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
67 on_completion_display_matches_hook(char **matches, |
|
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
68 int num_matches, int max_length); |
|
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
69 |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
70 |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
71 /* Exported function to send one line to readline's init file parser */ |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
72 |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
73 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
74 parse_and_bind(PyObject *self, PyObject *args) |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
75 { |
|
9584
e66e88f52606
Bernard Herzog pointed out that rl_parse_and_bind modifies its
Guido van Rossum <guido@python.org>
parents:
8823
diff
changeset
|
76 char *s, *copy; |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11485
diff
changeset
|
77 if (!PyArg_ParseTuple(args, "s:parse_and_bind", &s)) |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
78 return NULL; |
|
9584
e66e88f52606
Bernard Herzog pointed out that rl_parse_and_bind modifies its
Guido van Rossum <guido@python.org>
parents:
8823
diff
changeset
|
79 /* Make a copy -- rl_parse_and_bind() modifies its argument */ |
|
e66e88f52606
Bernard Herzog pointed out that rl_parse_and_bind modifies its
Guido van Rossum <guido@python.org>
parents:
8823
diff
changeset
|
80 /* Bernard Herzog */ |
|
e66e88f52606
Bernard Herzog pointed out that rl_parse_and_bind modifies its
Guido van Rossum <guido@python.org>
parents:
8823
diff
changeset
|
81 copy = malloc(1 + strlen(s)); |
|
e66e88f52606
Bernard Herzog pointed out that rl_parse_and_bind modifies its
Guido van Rossum <guido@python.org>
parents:
8823
diff
changeset
|
82 if (copy == NULL) |
|
e66e88f52606
Bernard Herzog pointed out that rl_parse_and_bind modifies its
Guido van Rossum <guido@python.org>
parents:
8823
diff
changeset
|
83 return PyErr_NoMemory(); |
|
e66e88f52606
Bernard Herzog pointed out that rl_parse_and_bind modifies its
Guido van Rossum <guido@python.org>
parents:
8823
diff
changeset
|
84 strcpy(copy, s); |
|
e66e88f52606
Bernard Herzog pointed out that rl_parse_and_bind modifies its
Guido van Rossum <guido@python.org>
parents:
8823
diff
changeset
|
85 rl_parse_and_bind(copy); |
|
e66e88f52606
Bernard Herzog pointed out that rl_parse_and_bind modifies its
Guido van Rossum <guido@python.org>
parents:
8823
diff
changeset
|
86 free(copy); /* Free the copy */ |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
87 Py_RETURN_NONE; |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
88 } |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
89 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
90 PyDoc_STRVAR(doc_parse_and_bind, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
91 "parse_and_bind(string) -> None\n\ |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
92 Parse and execute single line of a readline init file."); |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
93 |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
94 |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
95 /* Exported function to parse a readline init file */ |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
96 |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
97 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
98 read_init_file(PyObject *self, PyObject *args) |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
99 { |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
100 char *s = NULL; |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11485
diff
changeset
|
101 if (!PyArg_ParseTuple(args, "|z:read_init_file", &s)) |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
102 return NULL; |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
103 errno = rl_read_init_file(s); |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
104 if (errno) |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
105 return PyErr_SetFromErrno(PyExc_IOError); |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
106 Py_RETURN_NONE; |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
107 } |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
108 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
109 PyDoc_STRVAR(doc_read_init_file, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
110 "read_init_file([filename]) -> None\n\ |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
111 Parse a readline initialization file.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
112 The default filename is the last filename used."); |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
113 |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
114 |
|
13387
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
115 /* Exported function to load a readline history file */ |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
116 |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
117 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
118 read_history_file(PyObject *self, PyObject *args) |
|
13387
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
119 { |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
120 char *s = NULL; |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
121 if (!PyArg_ParseTuple(args, "|z:read_history_file", &s)) |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
122 return NULL; |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
123 errno = read_history(s); |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
124 if (errno) |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
125 return PyErr_SetFromErrno(PyExc_IOError); |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
126 Py_RETURN_NONE; |
|
13387
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
127 } |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
128 |
|
34027
7e99b0680adf
Rename a static variable "history_length" to "_history_length".
Hye-Shik Chang <hyeshik@gmail.com>
parents:
33686
diff
changeset
|
129 static int _history_length = -1; /* do not truncate history by default */ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
130 PyDoc_STRVAR(doc_read_history_file, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
131 "read_history_file([filename]) -> None\n\ |
|
13387
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
132 Load a readline history file.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
133 The default filename is ~/.history."); |
|
13387
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
134 |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
135 |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
136 /* Exported function to save a readline history file */ |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
137 |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
138 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
139 write_history_file(PyObject *self, PyObject *args) |
|
13387
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
140 { |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
141 char *s = NULL; |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
142 if (!PyArg_ParseTuple(args, "|z:write_history_file", &s)) |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
143 return NULL; |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
144 errno = write_history(s); |
|
34027
7e99b0680adf
Rename a static variable "history_length" to "_history_length".
Hye-Shik Chang <hyeshik@gmail.com>
parents:
33686
diff
changeset
|
145 if (!errno && _history_length >= 0) |
|
7e99b0680adf
Rename a static variable "history_length" to "_history_length".
Hye-Shik Chang <hyeshik@gmail.com>
parents:
33686
diff
changeset
|
146 history_truncate_file(s, _history_length); |
|
13387
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
147 if (errno) |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
148 return PyErr_SetFromErrno(PyExc_IOError); |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
149 Py_RETURN_NONE; |
|
13387
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
150 } |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
151 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
152 PyDoc_STRVAR(doc_write_history_file, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
153 "write_history_file([filename]) -> None\n\ |
|
13387
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
154 Save a readline history file.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
155 The default filename is ~/.history."); |
|
13387
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
156 |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
157 |
| 27134 | 158 /* Set history length */ |
| 159 | |
| 160 static PyObject* | |
| 161 set_history_length(PyObject *self, PyObject *args) | |
| 162 { | |
|
34027
7e99b0680adf
Rename a static variable "history_length" to "_history_length".
Hye-Shik Chang <hyeshik@gmail.com>
parents:
33686
diff
changeset
|
163 int length = _history_length; |
| 27134 | 164 if (!PyArg_ParseTuple(args, "i:set_history_length", &length)) |
| 165 return NULL; | |
|
34027
7e99b0680adf
Rename a static variable "history_length" to "_history_length".
Hye-Shik Chang <hyeshik@gmail.com>
parents:
33686
diff
changeset
|
166 _history_length = length; |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
167 Py_RETURN_NONE; |
| 27134 | 168 } |
| 169 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
170 PyDoc_STRVAR(set_history_length_doc, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
171 "set_history_length(length) -> None\n\ |
|
13644
2d5aa212a322
added history file truncation based upon code from Johannes Zellner.
Skip Montanaro <skip@pobox.com>
parents:
13496
diff
changeset
|
172 set the maximal number of items which will be written to\n\ |
|
2d5aa212a322
added history file truncation based upon code from Johannes Zellner.
Skip Montanaro <skip@pobox.com>
parents:
13496
diff
changeset
|
173 the history file. A negative length is used to inhibit\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
174 history truncation."); |
|
13644
2d5aa212a322
added history file truncation based upon code from Johannes Zellner.
Skip Montanaro <skip@pobox.com>
parents:
13496
diff
changeset
|
175 |
|
2d5aa212a322
added history file truncation based upon code from Johannes Zellner.
Skip Montanaro <skip@pobox.com>
parents:
13496
diff
changeset
|
176 |
| 27134 | 177 /* Get history length */ |
|
13644
2d5aa212a322
added history file truncation based upon code from Johannes Zellner.
Skip Montanaro <skip@pobox.com>
parents:
13496
diff
changeset
|
178 |
|
2d5aa212a322
added history file truncation based upon code from Johannes Zellner.
Skip Montanaro <skip@pobox.com>
parents:
13496
diff
changeset
|
179 static PyObject* |
|
27531
d11223daaf61
I was in this module anyway, so I did some janitorial things.
Michael W. Hudson <mwh@python.net>
parents:
27530
diff
changeset
|
180 get_history_length(PyObject *self, PyObject *noarg) |
|
13644
2d5aa212a322
added history file truncation based upon code from Johannes Zellner.
Skip Montanaro <skip@pobox.com>
parents:
13496
diff
changeset
|
181 { |
|
34027
7e99b0680adf
Rename a static variable "history_length" to "_history_length".
Hye-Shik Chang <hyeshik@gmail.com>
parents:
33686
diff
changeset
|
182 return PyInt_FromLong(_history_length); |
|
13644
2d5aa212a322
added history file truncation based upon code from Johannes Zellner.
Skip Montanaro <skip@pobox.com>
parents:
13496
diff
changeset
|
183 } |
|
2d5aa212a322
added history file truncation based upon code from Johannes Zellner.
Skip Montanaro <skip@pobox.com>
parents:
13496
diff
changeset
|
184 |
| 27134 | 185 PyDoc_STRVAR(get_history_length_doc, |
| 186 "get_history_length() -> int\n\ | |
| 187 return the maximum number of items that will be written to\n\ | |
| 188 the history file."); | |
| 189 | |
| 190 | |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
191 /* Generic hook function setter */ |
|
13644
2d5aa212a322
added history file truncation based upon code from Johannes Zellner.
Skip Montanaro <skip@pobox.com>
parents:
13496
diff
changeset
|
192 |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
193 static PyObject * |
| 34843 | 194 set_hook(const char *funcname, PyObject **hook_var, PyObject *args) |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
195 { |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
196 PyObject *function = Py_None; |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
197 char buf[80]; |
|
21073
304b34023876
sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents:
21066
diff
changeset
|
198 PyOS_snprintf(buf, sizeof(buf), "|O:set_%.50s", funcname); |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
199 if (!PyArg_ParseTuple(args, buf, &function)) |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
200 return NULL; |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
201 if (function == Py_None) { |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
202 Py_XDECREF(*hook_var); |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
203 *hook_var = NULL; |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
204 } |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
205 else if (PyCallable_Check(function)) { |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
206 PyObject *tmp = *hook_var; |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
207 Py_INCREF(function); |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
208 *hook_var = function; |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
209 Py_XDECREF(tmp); |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
210 } |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
211 else { |
|
21073
304b34023876
sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents:
21066
diff
changeset
|
212 PyOS_snprintf(buf, sizeof(buf), |
|
304b34023876
sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents:
21066
diff
changeset
|
213 "set_%.50s(func): argument not callable", |
|
304b34023876
sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents:
21066
diff
changeset
|
214 funcname); |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
215 PyErr_SetString(PyExc_TypeError, buf); |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
216 return NULL; |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
217 } |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
218 Py_RETURN_NONE; |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
219 } |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
220 |
| 27134 | 221 |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
222 /* Exported functions to specify hook functions in Python */ |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
223 |
|
43228
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
224 static PyObject *completion_display_matches_hook = NULL; |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
225 static PyObject *startup_hook = NULL; |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
226 |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
227 #ifdef HAVE_RL_PRE_INPUT_HOOK |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
228 static PyObject *pre_input_hook = NULL; |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
229 #endif |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
230 |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
231 static PyObject * |
|
43228
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
232 set_completion_display_matches_hook(PyObject *self, PyObject *args) |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
233 { |
|
43825
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
234 PyObject *result = set_hook("completion_display_matches_hook", |
|
43228
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
235 &completion_display_matches_hook, args); |
|
43825
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
236 #ifdef HAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK |
|
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
237 /* We cannot set this hook globally, since it replaces the |
|
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
238 default completion display. */ |
|
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
239 rl_completion_display_matches_hook = |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
240 completion_display_matches_hook ? |
|
49641
a529e3dc695a
Merged revisions 67098 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47527
diff
changeset
|
241 #if defined(_RL_FUNCTION_TYPEDEF) |
|
43825
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
242 (rl_compdisp_func_t *)on_completion_display_matches_hook : 0; |
|
49641
a529e3dc695a
Merged revisions 67098 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47527
diff
changeset
|
243 #else |
|
a529e3dc695a
Merged revisions 67098 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47527
diff
changeset
|
244 (VFunction *)on_completion_display_matches_hook : 0; |
|
a529e3dc695a
Merged revisions 67098 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47527
diff
changeset
|
245 #endif |
|
43825
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
246 #endif |
|
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
247 return result; |
|
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
248 |
|
43228
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
249 } |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
250 |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
251 PyDoc_STRVAR(doc_set_completion_display_matches_hook, |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
252 "set_completion_display_matches_hook([function]) -> None\n\ |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
253 Set or remove the completion display function.\n\ |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
254 The function is called as\n\ |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
255 function(substitution, [matches], longest_match_length)\n\ |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
256 once each time matches need to be displayed."); |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
257 |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
258 static PyObject * |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
259 set_startup_hook(PyObject *self, PyObject *args) |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
260 { |
| 34843 | 261 return set_hook("startup_hook", &startup_hook, args); |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
262 } |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
263 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
264 PyDoc_STRVAR(doc_set_startup_hook, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
265 "set_startup_hook([function]) -> None\n\ |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
266 Set or remove the startup_hook function.\n\ |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
267 The function is called with no arguments just\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
268 before readline prints the first prompt."); |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
269 |
| 27134 | 270 |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
271 #ifdef HAVE_RL_PRE_INPUT_HOOK |
| 27134 | 272 |
| 273 /* Set pre-input hook */ | |
| 274 | |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
275 static PyObject * |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
276 set_pre_input_hook(PyObject *self, PyObject *args) |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
277 { |
| 34843 | 278 return set_hook("pre_input_hook", &pre_input_hook, args); |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
279 } |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
280 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
281 PyDoc_STRVAR(doc_set_pre_input_hook, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
282 "set_pre_input_hook([function]) -> None\n\ |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
283 Set or remove the pre_input_hook function.\n\ |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
284 The function is called with no arguments after the first prompt\n\ |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
285 has been printed and just before readline starts reading input\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
286 characters."); |
| 27134 | 287 |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
288 #endif |
|
13644
2d5aa212a322
added history file truncation based upon code from Johannes Zellner.
Skip Montanaro <skip@pobox.com>
parents:
13496
diff
changeset
|
289 |
| 27134 | 290 |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
291 /* Exported function to specify a word completer in Python */ |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
292 |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
293 static PyObject *completer = NULL; |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
294 |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
295 static PyObject *begidx = NULL; |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
296 static PyObject *endidx = NULL; |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
297 |
| 27134 | 298 |
|
43228
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
299 /* Get the completion type for the scope of the tab-completion */ |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
300 static PyObject * |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
301 get_completion_type(PyObject *self, PyObject *noarg) |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
302 { |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
303 return PyInt_FromLong(rl_completion_type); |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
304 } |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
305 |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
306 PyDoc_STRVAR(doc_get_completion_type, |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
307 "get_completion_type() -> int\n\ |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
308 Get the type of completion being attempted."); |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
309 |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
310 |
| 27134 | 311 /* Get the beginning index for the scope of the tab-completion */ |
| 312 | |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
313 static PyObject * |
|
27531
d11223daaf61
I was in this module anyway, so I did some janitorial things.
Michael W. Hudson <mwh@python.net>
parents:
27530
diff
changeset
|
314 get_begidx(PyObject *self, PyObject *noarg) |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
315 { |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
316 Py_INCREF(begidx); |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
317 return begidx; |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
318 } |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
319 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
320 PyDoc_STRVAR(doc_get_begidx, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
321 "get_begidx() -> int\n\ |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
322 get the beginning index of the readline tab-completion scope"); |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
323 |
| 27134 | 324 |
| 325 /* Get the ending index for the scope of the tab-completion */ | |
| 326 | |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
327 static PyObject * |
|
27531
d11223daaf61
I was in this module anyway, so I did some janitorial things.
Michael W. Hudson <mwh@python.net>
parents:
27530
diff
changeset
|
328 get_endidx(PyObject *self, PyObject *noarg) |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
329 { |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
330 Py_INCREF(endidx); |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
331 return endidx; |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
332 } |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
333 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
334 PyDoc_STRVAR(doc_get_endidx, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
335 "get_endidx() -> int\n\ |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
336 get the ending index of the readline tab-completion scope"); |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
337 |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
338 |
| 27134 | 339 /* Set the tab-completion word-delimiters that readline uses */ |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
340 |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
341 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
342 set_completer_delims(PyObject *self, PyObject *args) |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
343 { |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
344 char *break_chars; |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
345 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11485
diff
changeset
|
346 if(!PyArg_ParseTuple(args, "s:set_completer_delims", &break_chars)) { |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
347 return NULL; |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
348 } |
|
23204
6e568ee31a9c
#544265, Remove warnings for passing const to free()
Neal Norwitz <nnorwitz@gmail.com>
parents:
22714
diff
changeset
|
349 free((void*)rl_completer_word_break_characters); |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
350 rl_completer_word_break_characters = strdup(break_chars); |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
351 Py_RETURN_NONE; |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
352 } |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
353 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
354 PyDoc_STRVAR(doc_set_completer_delims, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
355 "set_completer_delims(string) -> None\n\ |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
356 set the readline word delimiters for tab-completion"); |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
357 |
|
33136
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
358 static PyObject * |
|
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
359 py_remove_history(PyObject *self, PyObject *args) |
|
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
360 { |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
361 int entry_number; |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
362 HIST_ENTRY *entry; |
|
33136
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
363 |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
364 if (!PyArg_ParseTuple(args, "i:remove_history", &entry_number)) |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
365 return NULL; |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
366 if (entry_number < 0) { |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
367 PyErr_SetString(PyExc_ValueError, |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
368 "History index cannot be negative"); |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
369 return NULL; |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
370 } |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
371 entry = remove_history(entry_number); |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
372 if (!entry) { |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
373 PyErr_Format(PyExc_ValueError, |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
374 "No history item at position %d", |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
375 entry_number); |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
376 return NULL; |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
377 } |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
378 /* free memory allocated for the history entry */ |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
379 if (entry->line) |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
380 free(entry->line); |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
381 if (entry->data) |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
382 free(entry->data); |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
383 free(entry); |
|
33136
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
384 |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
385 Py_RETURN_NONE; |
|
33136
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
386 } |
|
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
387 |
|
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
388 PyDoc_STRVAR(doc_remove_history, |
|
33153
4b5b6e861fcf
fix a couple problems with the last patch picked up by Michael Hudson
Skip Montanaro <skip@pobox.com>
parents:
33136
diff
changeset
|
389 "remove_history_item(pos) -> None\n\ |
|
33136
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
390 remove history item given by its position"); |
|
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
391 |
|
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
392 static PyObject * |
|
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
393 py_replace_history(PyObject *self, PyObject *args) |
|
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
394 { |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
395 int entry_number; |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
396 char *line; |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
397 HIST_ENTRY *old_entry; |
|
33136
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
398 |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
399 if (!PyArg_ParseTuple(args, "is:replace_history", &entry_number, |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
400 &line)) { |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
401 return NULL; |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
402 } |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
403 if (entry_number < 0) { |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
404 PyErr_SetString(PyExc_ValueError, |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
405 "History index cannot be negative"); |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
406 return NULL; |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
407 } |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
408 old_entry = replace_history_entry(entry_number, line, (void *)NULL); |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
409 if (!old_entry) { |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
410 PyErr_Format(PyExc_ValueError, |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
411 "No history item at position %d", |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
412 entry_number); |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
413 return NULL; |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
414 } |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
415 /* free memory allocated for the old history entry */ |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
416 if (old_entry->line) |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
417 free(old_entry->line); |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
418 if (old_entry->data) |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
419 free(old_entry->data); |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
420 free(old_entry); |
|
33136
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
421 |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
422 Py_RETURN_NONE; |
|
33136
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
423 } |
|
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
424 |
|
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
425 PyDoc_STRVAR(doc_replace_history, |
|
33153
4b5b6e861fcf
fix a couple problems with the last patch picked up by Michael Hudson
Skip Montanaro <skip@pobox.com>
parents:
33136
diff
changeset
|
426 "replace_history_item(pos, line) -> None\n\ |
|
33136
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
427 replaces history item given by its position with contents of line"); |
| 27134 | 428 |
| 429 /* Add a line to the history buffer */ | |
| 430 | |
|
20550
6a5a10a5b526
SF patch #443759: Add Interface to readline's add_history
Guido van Rossum <guido@python.org>
parents:
20188
diff
changeset
|
431 static PyObject * |
|
6a5a10a5b526
SF patch #443759: Add Interface to readline's add_history
Guido van Rossum <guido@python.org>
parents:
20188
diff
changeset
|
432 py_add_history(PyObject *self, PyObject *args) |
|
6a5a10a5b526
SF patch #443759: Add Interface to readline's add_history
Guido van Rossum <guido@python.org>
parents:
20188
diff
changeset
|
433 { |
|
6a5a10a5b526
SF patch #443759: Add Interface to readline's add_history
Guido van Rossum <guido@python.org>
parents:
20188
diff
changeset
|
434 char *line; |
|
6a5a10a5b526
SF patch #443759: Add Interface to readline's add_history
Guido van Rossum <guido@python.org>
parents:
20188
diff
changeset
|
435 |
|
6a5a10a5b526
SF patch #443759: Add Interface to readline's add_history
Guido van Rossum <guido@python.org>
parents:
20188
diff
changeset
|
436 if(!PyArg_ParseTuple(args, "s:add_history", &line)) { |
|
6a5a10a5b526
SF patch #443759: Add Interface to readline's add_history
Guido van Rossum <guido@python.org>
parents:
20188
diff
changeset
|
437 return NULL; |
|
6a5a10a5b526
SF patch #443759: Add Interface to readline's add_history
Guido van Rossum <guido@python.org>
parents:
20188
diff
changeset
|
438 } |
|
6a5a10a5b526
SF patch #443759: Add Interface to readline's add_history
Guido van Rossum <guido@python.org>
parents:
20188
diff
changeset
|
439 add_history(line); |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
440 Py_RETURN_NONE; |
|
20550
6a5a10a5b526
SF patch #443759: Add Interface to readline's add_history
Guido van Rossum <guido@python.org>
parents:
20188
diff
changeset
|
441 } |
|
6a5a10a5b526
SF patch #443759: Add Interface to readline's add_history
Guido van Rossum <guido@python.org>
parents:
20188
diff
changeset
|
442 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
443 PyDoc_STRVAR(doc_add_history, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
444 "add_history(string) -> None\n\ |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
445 add a line to the history buffer"); |
|
20550
6a5a10a5b526
SF patch #443759: Add Interface to readline's add_history
Guido van Rossum <guido@python.org>
parents:
20188
diff
changeset
|
446 |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
447 |
| 27134 | 448 /* Get the tab-completion word-delimiters that readline uses */ |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
449 |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
450 static PyObject * |
|
27531
d11223daaf61
I was in this module anyway, so I did some janitorial things.
Michael W. Hudson <mwh@python.net>
parents:
27530
diff
changeset
|
451 get_completer_delims(PyObject *self, PyObject *noarg) |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
452 { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
453 return PyString_FromString(rl_completer_word_break_characters); |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
454 } |
| 27134 | 455 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
456 PyDoc_STRVAR(doc_get_completer_delims, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
457 "get_completer_delims() -> string\n\ |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
458 get the readline word delimiters for tab-completion"); |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
459 |
| 27134 | 460 |
| 461 /* Set the completer function */ | |
| 462 | |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
463 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
464 set_completer(PyObject *self, PyObject *args) |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
465 { |
| 34843 | 466 return set_hook("completer", &completer, args); |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
467 } |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
468 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
469 PyDoc_STRVAR(doc_set_completer, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
470 "set_completer([function]) -> None\n\ |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
471 Set or remove the completer function.\n\ |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
472 The function is called as function(text, state),\n\ |
|
18932
dab95ca8acfc
Cleaned up the docstring for readline.set_completer().
Fred Drake <fdrake@acm.org>
parents:
18474
diff
changeset
|
473 for state in 0, 1, 2, ..., until it returns a non-string.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
474 It should return the next possible completion starting with 'text'."); |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
475 |
| 27134 | 476 |
|
27530
5765d524de71
Add the get_completer() function based on Michael Stone's patch in
Michael W. Hudson <mwh@python.net>
parents:
27136
diff
changeset
|
477 static PyObject * |
|
28122
39cb917b5f7a
get_completer() takes no args
Neal Norwitz <nnorwitz@gmail.com>
parents:
27995
diff
changeset
|
478 get_completer(PyObject *self, PyObject *noargs) |
|
27530
5765d524de71
Add the get_completer() function based on Michael Stone's patch in
Michael W. Hudson <mwh@python.net>
parents:
27136
diff
changeset
|
479 { |
|
5765d524de71
Add the get_completer() function based on Michael Stone's patch in
Michael W. Hudson <mwh@python.net>
parents:
27136
diff
changeset
|
480 if (completer == NULL) { |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
481 Py_RETURN_NONE; |
|
27530
5765d524de71
Add the get_completer() function based on Michael Stone's patch in
Michael W. Hudson <mwh@python.net>
parents:
27136
diff
changeset
|
482 } |
|
5765d524de71
Add the get_completer() function based on Michael Stone's patch in
Michael W. Hudson <mwh@python.net>
parents:
27136
diff
changeset
|
483 Py_INCREF(completer); |
|
5765d524de71
Add the get_completer() function based on Michael Stone's patch in
Michael W. Hudson <mwh@python.net>
parents:
27136
diff
changeset
|
484 return completer; |
|
5765d524de71
Add the get_completer() function based on Michael Stone's patch in
Michael W. Hudson <mwh@python.net>
parents:
27136
diff
changeset
|
485 } |
|
5765d524de71
Add the get_completer() function based on Michael Stone's patch in
Michael W. Hudson <mwh@python.net>
parents:
27136
diff
changeset
|
486 |
|
5765d524de71
Add the get_completer() function based on Michael Stone's patch in
Michael W. Hudson <mwh@python.net>
parents:
27136
diff
changeset
|
487 PyDoc_STRVAR(doc_get_completer, |
|
5765d524de71
Add the get_completer() function based on Michael Stone's patch in
Michael W. Hudson <mwh@python.net>
parents:
27136
diff
changeset
|
488 "get_completer() -> function\n\ |
|
5765d524de71
Add the get_completer() function based on Michael Stone's patch in
Michael W. Hudson <mwh@python.net>
parents:
27136
diff
changeset
|
489 \n\ |
|
5765d524de71
Add the get_completer() function based on Michael Stone's patch in
Michael W. Hudson <mwh@python.net>
parents:
27136
diff
changeset
|
490 Returns current completer function."); |
|
5765d524de71
Add the get_completer() function based on Michael Stone's patch in
Michael W. Hudson <mwh@python.net>
parents:
27136
diff
changeset
|
491 |
|
22488
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
492 /* Exported function to get any element of history */ |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
493 |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
494 static PyObject * |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
495 get_history_item(PyObject *self, PyObject *args) |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
496 { |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
497 int idx = 0; |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
498 HIST_ENTRY *hist_ent; |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
499 |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
500 if (!PyArg_ParseTuple(args, "i:index", &idx)) |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
501 return NULL; |
|
58820
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
502 #ifdef __APPLE__ |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
503 if (using_libedit_emulation) { |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
504 /* Libedit emulation uses 0-based indexes, |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
505 * the real one uses 1-based indexes, |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
506 * adjust the index to ensure that Python |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
507 * code doesn't have to worry about the |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
508 * difference. |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
509 */ |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
510 HISTORY_STATE *hist_st; |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
511 hist_st = history_get_history_state(); |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
512 |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
513 idx --; |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
514 |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
515 /* |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
516 * Apple's readline emulation crashes when |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
517 * the index is out of range, therefore |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
518 * test for that and fail gracefully. |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
519 */ |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
520 if (idx < 0 || idx >= hist_st->length) { |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
521 Py_RETURN_NONE; |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
522 } |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
523 } |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
524 #endif /* __APPLE__ */ |
|
22488
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
525 if ((hist_ent = history_get(idx))) |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
526 return PyString_FromString(hist_ent->line); |
|
22488
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
527 else { |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
528 Py_RETURN_NONE; |
|
22488
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
529 } |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
530 } |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
531 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
532 PyDoc_STRVAR(doc_get_history_item, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
533 "get_history_item() -> string\n\ |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
534 return the current contents of history item at index."); |
|
22488
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
535 |
| 27134 | 536 |
|
22488
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
537 /* Exported function to get current length of history */ |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
538 |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
539 static PyObject * |
|
27531
d11223daaf61
I was in this module anyway, so I did some janitorial things.
Michael W. Hudson <mwh@python.net>
parents:
27530
diff
changeset
|
540 get_current_history_length(PyObject *self, PyObject *noarg) |
|
22488
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
541 { |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
542 HISTORY_STATE *hist_st; |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
543 |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
544 hist_st = history_get_history_state(); |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
545 return PyInt_FromLong(hist_st ? (long) hist_st->length : (long) 0); |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
546 } |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
547 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
548 PyDoc_STRVAR(doc_get_current_history_length, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
549 "get_current_history_length() -> integer\n\ |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
550 return the current (not the maximum) length of history."); |
|
22488
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
551 |
| 27134 | 552 |
|
6429
14a711268c51
Add get_line_buffer() and insert_text(), suggested by Michael McLay.
Guido van Rossum <guido@python.org>
parents:
6338
diff
changeset
|
553 /* Exported function to read the current line buffer */ |
|
14a711268c51
Add get_line_buffer() and insert_text(), suggested by Michael McLay.
Guido van Rossum <guido@python.org>
parents:
6338
diff
changeset
|
554 |
|
14a711268c51
Add get_line_buffer() and insert_text(), suggested by Michael McLay.
Guido van Rossum <guido@python.org>
parents:
6338
diff
changeset
|
555 static PyObject * |
|
27531
d11223daaf61
I was in this module anyway, so I did some janitorial things.
Michael W. Hudson <mwh@python.net>
parents:
27530
diff
changeset
|
556 get_line_buffer(PyObject *self, PyObject *noarg) |
|
6429
14a711268c51
Add get_line_buffer() and insert_text(), suggested by Michael McLay.
Guido van Rossum <guido@python.org>
parents:
6338
diff
changeset
|
557 { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
558 return PyString_FromString(rl_line_buffer); |
|
6429
14a711268c51
Add get_line_buffer() and insert_text(), suggested by Michael McLay.
Guido van Rossum <guido@python.org>
parents:
6338
diff
changeset
|
559 } |
|
14a711268c51
Add get_line_buffer() and insert_text(), suggested by Michael McLay.
Guido van Rossum <guido@python.org>
parents:
6338
diff
changeset
|
560 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
561 PyDoc_STRVAR(doc_get_line_buffer, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
562 "get_line_buffer() -> string\n\ |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
563 return the current contents of the line buffer."); |
|
6429
14a711268c51
Add get_line_buffer() and insert_text(), suggested by Michael McLay.
Guido van Rossum <guido@python.org>
parents:
6338
diff
changeset
|
564 |
| 27134 | 565 |
|
30471
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
566 #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
567 |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
568 /* Exported function to clear the current history */ |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
569 |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
570 static PyObject * |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
571 py_clear_history(PyObject *self, PyObject *noarg) |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
572 { |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
573 clear_history(); |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
574 Py_RETURN_NONE; |
|
30471
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
575 } |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
576 |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
577 PyDoc_STRVAR(doc_clear_history, |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
578 "clear_history() -> None\n\ |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
579 Clear the current readline history."); |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
580 #endif |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
581 |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
582 |
|
6429
14a711268c51
Add get_line_buffer() and insert_text(), suggested by Michael McLay.
Guido van Rossum <guido@python.org>
parents:
6338
diff
changeset
|
583 /* Exported function to insert text into the line buffer */ |
|
14a711268c51
Add get_line_buffer() and insert_text(), suggested by Michael McLay.
Guido van Rossum <guido@python.org>
parents:
6338
diff
changeset
|
584 |
|
14a711268c51
Add get_line_buffer() and insert_text(), suggested by Michael McLay.
Guido van Rossum <guido@python.org>
parents:
6338
diff
changeset
|
585 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
586 insert_text(PyObject *self, PyObject *args) |
|
6429
14a711268c51
Add get_line_buffer() and insert_text(), suggested by Michael McLay.
Guido van Rossum <guido@python.org>
parents:
6338
diff
changeset
|
587 { |
|
14a711268c51
Add get_line_buffer() and insert_text(), suggested by Michael McLay.
Guido van Rossum <guido@python.org>
parents:
6338
diff
changeset
|
588 char *s; |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11485
diff
changeset
|
589 if (!PyArg_ParseTuple(args, "s:insert_text", &s)) |
|
6429
14a711268c51
Add get_line_buffer() and insert_text(), suggested by Michael McLay.
Guido van Rossum <guido@python.org>
parents:
6338
diff
changeset
|
590 return NULL; |
|
14a711268c51
Add get_line_buffer() and insert_text(), suggested by Michael McLay.
Guido van Rossum <guido@python.org>
parents:
6338
diff
changeset
|
591 rl_insert_text(s); |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
592 Py_RETURN_NONE; |
|
6429
14a711268c51
Add get_line_buffer() and insert_text(), suggested by Michael McLay.
Guido van Rossum <guido@python.org>
parents:
6338
diff
changeset
|
593 } |
|
14a711268c51
Add get_line_buffer() and insert_text(), suggested by Michael McLay.
Guido van Rossum <guido@python.org>
parents:
6338
diff
changeset
|
594 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
595 PyDoc_STRVAR(doc_insert_text, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
596 "insert_text(string) -> None\n\ |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
597 Insert text into the command line."); |
|
6429
14a711268c51
Add get_line_buffer() and insert_text(), suggested by Michael McLay.
Guido van Rossum <guido@python.org>
parents:
6338
diff
changeset
|
598 |
| 27134 | 599 |
| 600 /* Redisplay the line buffer */ | |
| 601 | |
|
22488
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
602 static PyObject * |
|
27531
d11223daaf61
I was in this module anyway, so I did some janitorial things.
Michael W. Hudson <mwh@python.net>
parents:
27530
diff
changeset
|
603 redisplay(PyObject *self, PyObject *noarg) |
|
22488
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
604 { |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
605 rl_redisplay(); |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
606 Py_RETURN_NONE; |
|
22488
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
607 } |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
608 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
609 PyDoc_STRVAR(doc_redisplay, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
610 "redisplay() -> None\n\ |
|
22488
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
611 Change what's displayed on the screen to reflect the current\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
612 contents of the line buffer."); |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
613 |
| 27134 | 614 |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
615 /* Table of functions exported by the module */ |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
616 |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
617 static struct PyMethodDef readline_methods[] = |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
618 { |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13676
diff
changeset
|
619 {"parse_and_bind", parse_and_bind, METH_VARARGS, doc_parse_and_bind}, |
|
27531
d11223daaf61
I was in this module anyway, so I did some janitorial things.
Michael W. Hudson <mwh@python.net>
parents:
27530
diff
changeset
|
620 {"get_line_buffer", get_line_buffer, METH_NOARGS, doc_get_line_buffer}, |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13676
diff
changeset
|
621 {"insert_text", insert_text, METH_VARARGS, doc_insert_text}, |
|
27531
d11223daaf61
I was in this module anyway, so I did some janitorial things.
Michael W. Hudson <mwh@python.net>
parents:
27530
diff
changeset
|
622 {"redisplay", redisplay, METH_NOARGS, doc_redisplay}, |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13676
diff
changeset
|
623 {"read_init_file", read_init_file, METH_VARARGS, doc_read_init_file}, |
| 27134 | 624 {"read_history_file", read_history_file, |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13676
diff
changeset
|
625 METH_VARARGS, doc_read_history_file}, |
| 27134 | 626 {"write_history_file", write_history_file, |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13676
diff
changeset
|
627 METH_VARARGS, doc_write_history_file}, |
|
22488
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
628 {"get_history_item", get_history_item, |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
629 METH_VARARGS, doc_get_history_item}, |
|
22714
ceca6cc44420
Get rid of warnings due to changing to METH_NOARGS
Neal Norwitz <nnorwitz@gmail.com>
parents:
22561
diff
changeset
|
630 {"get_current_history_length", (PyCFunction)get_current_history_length, |
|
22561
043ad7adc896
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
22488
diff
changeset
|
631 METH_NOARGS, doc_get_current_history_length}, |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
632 {"set_history_length", set_history_length, |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13676
diff
changeset
|
633 METH_VARARGS, set_history_length_doc}, |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
634 {"get_history_length", get_history_length, |
|
27531
d11223daaf61
I was in this module anyway, so I did some janitorial things.
Michael W. Hudson <mwh@python.net>
parents:
27530
diff
changeset
|
635 METH_NOARGS, get_history_length_doc}, |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13676
diff
changeset
|
636 {"set_completer", set_completer, METH_VARARGS, doc_set_completer}, |
|
27530
5765d524de71
Add the get_completer() function based on Michael Stone's patch in
Michael W. Hudson <mwh@python.net>
parents:
27136
diff
changeset
|
637 {"get_completer", get_completer, METH_NOARGS, doc_get_completer}, |
|
43228
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
638 {"get_completion_type", get_completion_type, |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
639 METH_NOARGS, doc_get_completion_type}, |
|
27531
d11223daaf61
I was in this module anyway, so I did some janitorial things.
Michael W. Hudson <mwh@python.net>
parents:
27530
diff
changeset
|
640 {"get_begidx", get_begidx, METH_NOARGS, doc_get_begidx}, |
|
d11223daaf61
I was in this module anyway, so I did some janitorial things.
Michael W. Hudson <mwh@python.net>
parents:
27530
diff
changeset
|
641 {"get_endidx", get_endidx, METH_NOARGS, doc_get_endidx}, |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
642 |
| 27134 | 643 {"set_completer_delims", set_completer_delims, |
|
13820
8bd82cf361aa
Use METH_OLDARGS instead of numeric constant 0 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13817
diff
changeset
|
644 METH_VARARGS, doc_set_completer_delims}, |
|
20550
6a5a10a5b526
SF patch #443759: Add Interface to readline's add_history
Guido van Rossum <guido@python.org>
parents:
20188
diff
changeset
|
645 {"add_history", py_add_history, METH_VARARGS, doc_add_history}, |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
646 {"remove_history_item", py_remove_history, METH_VARARGS, doc_remove_history}, |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
647 {"replace_history_item", py_replace_history, METH_VARARGS, doc_replace_history}, |
|
27531
d11223daaf61
I was in this module anyway, so I did some janitorial things.
Michael W. Hudson <mwh@python.net>
parents:
27530
diff
changeset
|
648 {"get_completer_delims", get_completer_delims, |
|
22561
043ad7adc896
Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
22488
diff
changeset
|
649 METH_NOARGS, doc_get_completer_delims}, |
| 27134 | 650 |
|
43228
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
651 {"set_completion_display_matches_hook", set_completion_display_matches_hook, |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
652 METH_VARARGS, doc_set_completion_display_matches_hook}, |
| 27134 | 653 {"set_startup_hook", set_startup_hook, |
| 654 METH_VARARGS, doc_set_startup_hook}, | |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
655 #ifdef HAVE_RL_PRE_INPUT_HOOK |
| 27134 | 656 {"set_pre_input_hook", set_pre_input_hook, |
| 657 METH_VARARGS, doc_set_pre_input_hook}, | |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
658 #endif |
|
30471
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
659 #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
660 {"clear_history", py_clear_history, METH_NOARGS, doc_clear_history}, |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
661 #endif |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
662 {0, 0} |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
663 }; |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
664 |
|
27135
c2663ca31d7d
A few more whitespace normalizations.
Guido van Rossum <guido@python.org>
parents:
27134
diff
changeset
|
665 |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
666 /* C function to call the Python hooks. */ |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
667 |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
668 static int |
| 34843 | 669 on_hook(PyObject *func) |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
670 { |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
671 int result = 0; |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
672 if (func != NULL) { |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
673 PyObject *r; |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
674 #ifdef WITH_THREAD |
| 34843 | 675 PyGILState_STATE gilstate = PyGILState_Ensure(); |
| 676 #endif | |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
677 r = PyObject_CallFunction(func, NULL); |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
678 if (r == NULL) |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
679 goto error; |
| 27134 | 680 if (r == Py_None) |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
681 result = 0; |
| 34843 | 682 else { |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
683 result = PyInt_AsLong(r); |
| 34843 | 684 if (result == -1 && PyErr_Occurred()) |
| 685 goto error; | |
| 686 } | |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
687 Py_DECREF(r); |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
688 goto done; |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
689 error: |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
690 PyErr_Clear(); |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
691 Py_XDECREF(r); |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
692 done: |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
693 #ifdef WITH_THREAD |
| 34843 | 694 PyGILState_Release(gilstate); |
| 695 #endif | |
|
35650
d33f4fc84d4a
Fix parse errors in readline module when compiling without threads.
Georg Brandl <georg@python.org>
parents:
34877
diff
changeset
|
696 return result; |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
697 } |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
698 return result; |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
699 } |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
700 |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
701 static int |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
702 on_startup_hook(void) |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
703 { |
| 34843 | 704 return on_hook(startup_hook); |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
705 } |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
706 |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
707 #ifdef HAVE_RL_PRE_INPUT_HOOK |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
708 static int |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
709 on_pre_input_hook(void) |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
710 { |
| 34843 | 711 return on_hook(pre_input_hook); |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
712 } |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
713 #endif |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
714 |
|
27135
c2663ca31d7d
A few more whitespace normalizations.
Guido van Rossum <guido@python.org>
parents:
27134
diff
changeset
|
715 |
|
43228
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
716 /* C function to call the Python completion_display_matches */ |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
717 |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
718 static void |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
719 on_completion_display_matches_hook(char **matches, |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
720 int num_matches, int max_length) |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
721 { |
|
43825
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
722 int i; |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
723 PyObject *m=NULL, *s=NULL, *r=NULL; |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
724 #ifdef WITH_THREAD |
|
43825
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
725 PyGILState_STATE gilstate = PyGILState_Ensure(); |
|
43228
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
726 #endif |
|
43825
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
727 m = PyList_New(num_matches); |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
728 if (m == NULL) |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
729 goto error; |
|
43825
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
730 for (i = 0; i < num_matches; i++) { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
731 s = PyString_FromString(matches[i+1]); |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
732 if (s == NULL) |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
733 goto error; |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
734 if (PyList_SetItem(m, i, s) == -1) |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
735 goto error; |
|
43825
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
736 } |
|
43228
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
737 |
|
43825
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
738 r = PyObject_CallFunction(completion_display_matches_hook, |
|
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
739 "sOi", matches[0], m, max_length); |
|
43228
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
740 |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
741 Py_DECREF(m), m=NULL; |
|
43825
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
742 |
|
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
743 if (r == NULL || |
|
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
744 (r != Py_None && PyInt_AsLong(r) == -1 && PyErr_Occurred())) { |
|
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
745 goto error; |
|
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
746 } |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
747 Py_XDECREF(r), r=NULL; |
|
43228
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
748 |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
749 if (0) { |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
750 error: |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
751 PyErr_Clear(); |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
752 Py_XDECREF(m); |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
753 Py_XDECREF(r); |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
754 } |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
755 #ifdef WITH_THREAD |
|
43825
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
756 PyGILState_Release(gilstate); |
|
43228
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
757 #endif |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
758 } |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
759 |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
760 |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
761 /* C function to call the Python completer. */ |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
762 |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
763 static char * |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
39802
diff
changeset
|
764 on_completion(const char *text, int state) |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
765 { |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
766 char *result = NULL; |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
767 if (completer != NULL) { |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
768 PyObject *r; |
| 34843 | 769 #ifdef WITH_THREAD |
| 770 PyGILState_STATE gilstate = PyGILState_Ensure(); | |
| 771 #endif | |
|
21940
32d0ef6f1955
Simon Budig's patch (posted by me):
Michael W. Hudson <mwh@python.net>
parents:
21712
diff
changeset
|
772 rl_attempted_completion_over = 1; |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
773 r = PyObject_CallFunction(completer, "si", text, state); |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
774 if (r == NULL) |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
775 goto error; |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
776 if (r == Py_None) { |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
777 result = NULL; |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
778 } |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
779 else { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
780 char *s = PyString_AsString(r); |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
781 if (s == NULL) |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
782 goto error; |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
783 result = strdup(s); |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
784 } |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
785 Py_DECREF(r); |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
786 goto done; |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
787 error: |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
788 PyErr_Clear(); |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
789 Py_XDECREF(r); |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
790 done: |
| 34843 | 791 #ifdef WITH_THREAD |
| 792 PyGILState_Release(gilstate); | |
| 793 #endif | |
|
35650
d33f4fc84d4a
Fix parse errors in readline module when compiling without threads.
Georg Brandl <georg@python.org>
parents:
34877
diff
changeset
|
794 return result; |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
795 } |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
796 return result; |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
797 } |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
798 |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
799 |
|
27136
3d2962b0249e
Fix from Michael Stone for SF bug #660476 and #513033 (bogus thread
Guido van Rossum <guido@python.org>
parents:
27135
diff
changeset
|
800 /* A more flexible constructor that saves the "begidx" and "endidx" |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
801 * before calling the normal completer */ |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
802 |
|
27995
e11a178bb453
flex_complete looks like a private (but callback) function, so make it static
Neal Norwitz <nnorwitz@gmail.com>
parents:
27531
diff
changeset
|
803 static char ** |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
804 flex_complete(char *text, int start, int end) |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
805 { |
|
56779
19a832b8464a
Merged revisions 75531,75725 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
49641
diff
changeset
|
806 #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER |
|
19a832b8464a
Merged revisions 75531,75725 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
49641
diff
changeset
|
807 rl_completion_append_character ='\0'; |
|
19a832b8464a
Merged revisions 75531,75725 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
49641
diff
changeset
|
808 #endif |
|
19a832b8464a
Merged revisions 75531,75725 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
49641
diff
changeset
|
809 #ifdef HAVE_RL_COMPLETION_SUPPRESS_APPEND |
|
19a832b8464a
Merged revisions 75531,75725 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
49641
diff
changeset
|
810 rl_completion_suppress_append = 0; |
|
19a832b8464a
Merged revisions 75531,75725 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
49641
diff
changeset
|
811 #endif |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
812 Py_XDECREF(begidx); |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
813 Py_XDECREF(endidx); |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
814 begidx = PyInt_FromLong((long) start); |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
815 endidx = PyInt_FromLong((long) end); |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
816 return completion_matches(text, *on_completion); |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
817 } |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
818 |
|
27135
c2663ca31d7d
A few more whitespace normalizations.
Guido van Rossum <guido@python.org>
parents:
27134
diff
changeset
|
819 |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
820 /* Helper to initialize GNU readline properly. */ |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
821 |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
822 static void |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13644
diff
changeset
|
823 setup_readline(void) |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
824 { |
|
25684
c7d5801bbae8
GNU readline() mistakenly sets the LC_CTYPE locale.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
825 #ifdef SAVE_LOCALE |
|
30910
a29a585b03d9
Patch #804543: strdup saved locales. Backported to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
30471
diff
changeset
|
826 char *saved_locale = strdup(setlocale(LC_CTYPE, NULL)); |
|
33206
69700687e30f
Fail fatally if strdup fails.
Martin v. Löwis <martin@v.loewis.de>
parents:
33177
diff
changeset
|
827 if (!saved_locale) |
|
69700687e30f
Fail fatally if strdup fails.
Martin v. Löwis <martin@v.loewis.de>
parents:
33177
diff
changeset
|
828 Py_FatalError("not enough memory to save locale"); |
|
25684
c7d5801bbae8
GNU readline() mistakenly sets the LC_CTYPE locale.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
829 #endif |
|
c7d5801bbae8
GNU readline() mistakenly sets the LC_CTYPE locale.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
830 |
|
23782
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
831 using_history(); |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
832 |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
833 rl_readline_name = "python"; |
|
22114
c454b76d51e7
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21940
diff
changeset
|
834 #if defined(PYOS_OS2) && defined(PYCC_GCC) |
|
c454b76d51e7
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21940
diff
changeset
|
835 /* Allow $if term= in .inputrc to work */ |
|
c454b76d51e7
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21940
diff
changeset
|
836 rl_terminal_name = getenv("TERM"); |
|
c454b76d51e7
OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
21940
diff
changeset
|
837 #endif |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
838 /* Force rebind of TAB to insert-tab */ |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
839 rl_bind_key('\t', rl_insert); |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
840 /* Bind both ESC-TAB and ESC-ESC to the completion function */ |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
841 rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap); |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
842 rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap); |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
843 /* Set our hook functions */ |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
844 rl_startup_hook = (Function *)on_startup_hook; |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
845 #ifdef HAVE_RL_PRE_INPUT_HOOK |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
846 rl_pre_input_hook = (Function *)on_pre_input_hook; |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
847 #endif |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
848 /* Set our completion function */ |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
849 rl_attempted_completion_function = (CPPFunction *)flex_complete; |
|
6338
4b076fc5ba40
Set the completer's word break characters appropriate for Python.
Guido van Rossum <guido@python.org>
parents:
6335
diff
changeset
|
850 /* Set Python word break characters */ |
|
4b076fc5ba40
Set the completer's word break characters appropriate for Python.
Guido van Rossum <guido@python.org>
parents:
6335
diff
changeset
|
851 rl_completer_word_break_characters = |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
852 strdup(" \t\n`~!@#$%^&*()-=+[{]}\\|;:'\",<>/?"); |
|
6338
4b076fc5ba40
Set the completer's word break characters appropriate for Python.
Guido van Rossum <guido@python.org>
parents:
6335
diff
changeset
|
853 /* All nonalphanums except '.' */ |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
854 |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
855 begidx = PyInt_FromLong(0L); |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
856 endidx = PyInt_FromLong(0L); |
|
10029
034b42ba68a6
setup_readline(): Added a comment about memory leak (reported by
Barry Warsaw <barry@python.org>
parents:
9970
diff
changeset
|
857 /* Initialize (allows .inputrc to override) |
|
034b42ba68a6
setup_readline(): Added a comment about memory leak (reported by
Barry Warsaw <barry@python.org>
parents:
9970
diff
changeset
|
858 * |
|
034b42ba68a6
setup_readline(): Added a comment about memory leak (reported by
Barry Warsaw <barry@python.org>
parents:
9970
diff
changeset
|
859 * XXX: A bug in the readline-2.2 library causes a memory leak |
|
034b42ba68a6
setup_readline(): Added a comment about memory leak (reported by
Barry Warsaw <barry@python.org>
parents:
9970
diff
changeset
|
860 * inside this function. Nothing we can do about it. |
|
034b42ba68a6
setup_readline(): Added a comment about memory leak (reported by
Barry Warsaw <barry@python.org>
parents:
9970
diff
changeset
|
861 */ |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
862 rl_initialize(); |
|
25684
c7d5801bbae8
GNU readline() mistakenly sets the LC_CTYPE locale.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
863 |
|
39098
50b0b54fb17d
Fix memory leaks in some conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
864 RESTORE_LOCALE(saved_locale) |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
865 } |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
866 |
| 32526 | 867 /* Wrapper around GNU readline that handles signals differently. */ |
| 868 | |
| 869 | |
| 870 #if defined(HAVE_RL_CALLBACK) && defined(HAVE_SELECT) | |
| 871 | |
| 872 static char *completed_input_string; | |
| 873 static void | |
| 874 rlhandler(char *text) | |
| 875 { | |
| 876 completed_input_string = text; | |
| 877 rl_callback_handler_remove(); | |
| 878 } | |
| 879 | |
| 880 extern PyThreadState* _PyOS_ReadlineTState; | |
| 881 | |
| 882 static char * | |
| 883 readline_until_enter_or_signal(char *prompt, int *signal) | |
| 884 { | |
| 885 char * not_done_reading = ""; | |
| 886 fd_set selectset; | |
| 887 | |
| 888 *signal = 0; | |
| 889 #ifdef HAVE_RL_CATCH_SIGNAL | |
| 890 rl_catch_signals = 0; | |
| 891 #endif | |
| 892 | |
| 893 rl_callback_handler_install (prompt, rlhandler); | |
| 894 FD_ZERO(&selectset); | |
| 895 | |
| 896 completed_input_string = not_done_reading; | |
| 897 | |
|
33686
1701dae6474e
This is Michiel de Hoon's patch, as attached to the bug report:
Michael W. Hudson <mwh@python.net>
parents:
33255
diff
changeset
|
898 while (completed_input_string == not_done_reading) { |
|
1701dae6474e
This is Michiel de Hoon's patch, as attached to the bug report:
Michael W. Hudson <mwh@python.net>
parents:
33255
diff
changeset
|
899 int has_input = 0; |
| 32526 | 900 |
|
33686
1701dae6474e
This is Michiel de Hoon's patch, as attached to the bug report:
Michael W. Hudson <mwh@python.net>
parents:
33255
diff
changeset
|
901 while (!has_input) |
|
1701dae6474e
This is Michiel de Hoon's patch, as attached to the bug report:
Michael W. Hudson <mwh@python.net>
parents:
33255
diff
changeset
|
902 { struct timeval timeout = {0, 100000}; /* 0.1 seconds */ |
|
39802
4e81974f7e14
[Bug #1552726] Avoid repeatedly polling in interactive mode -- only put a timeout on the select()
Andrew M. Kuchling <amk@amk.ca>
parents:
39098
diff
changeset
|
903 |
|
4e81974f7e14
[Bug #1552726] Avoid repeatedly polling in interactive mode -- only put a timeout on the select()
Andrew M. Kuchling <amk@amk.ca>
parents:
39098
diff
changeset
|
904 /* [Bug #1552726] Only limit the pause if an input hook has been |
|
4e81974f7e14
[Bug #1552726] Avoid repeatedly polling in interactive mode -- only put a timeout on the select()
Andrew M. Kuchling <amk@amk.ca>
parents:
39098
diff
changeset
|
905 defined. */ |
|
4e81974f7e14
[Bug #1552726] Avoid repeatedly polling in interactive mode -- only put a timeout on the select()
Andrew M. Kuchling <amk@amk.ca>
parents:
39098
diff
changeset
|
906 struct timeval *timeoutp = NULL; |
|
4e81974f7e14
[Bug #1552726] Avoid repeatedly polling in interactive mode -- only put a timeout on the select()
Andrew M. Kuchling <amk@amk.ca>
parents:
39098
diff
changeset
|
907 if (PyOS_InputHook) |
|
4e81974f7e14
[Bug #1552726] Avoid repeatedly polling in interactive mode -- only put a timeout on the select()
Andrew M. Kuchling <amk@amk.ca>
parents:
39098
diff
changeset
|
908 timeoutp = &timeout; |
|
33686
1701dae6474e
This is Michiel de Hoon's patch, as attached to the bug report:
Michael W. Hudson <mwh@python.net>
parents:
33255
diff
changeset
|
909 FD_SET(fileno(rl_instream), &selectset); |
|
1701dae6474e
This is Michiel de Hoon's patch, as attached to the bug report:
Michael W. Hudson <mwh@python.net>
parents:
33255
diff
changeset
|
910 /* select resets selectset if no input was available */ |
|
1701dae6474e
This is Michiel de Hoon's patch, as attached to the bug report:
Michael W. Hudson <mwh@python.net>
parents:
33255
diff
changeset
|
911 has_input = select(fileno(rl_instream) + 1, &selectset, |
|
39802
4e81974f7e14
[Bug #1552726] Avoid repeatedly polling in interactive mode -- only put a timeout on the select()
Andrew M. Kuchling <amk@amk.ca>
parents:
39098
diff
changeset
|
912 NULL, NULL, timeoutp); |
|
33686
1701dae6474e
This is Michiel de Hoon's patch, as attached to the bug report:
Michael W. Hudson <mwh@python.net>
parents:
33255
diff
changeset
|
913 if(PyOS_InputHook) PyOS_InputHook(); |
|
1701dae6474e
This is Michiel de Hoon's patch, as attached to the bug report:
Michael W. Hudson <mwh@python.net>
parents:
33255
diff
changeset
|
914 } |
|
1701dae6474e
This is Michiel de Hoon's patch, as attached to the bug report:
Michael W. Hudson <mwh@python.net>
parents:
33255
diff
changeset
|
915 |
| 32526 | 916 if(has_input > 0) { |
| 917 rl_callback_read_char(); | |
| 918 } | |
| 919 else if (errno == EINTR) { | |
| 920 int s; | |
|
34877
9a7f46c42773
In a threads-disabled build, typing Ctrl-C into a raw_input() crashed,
Michael W. Hudson <mwh@python.net>
parents:
34843
diff
changeset
|
921 #ifdef WITH_THREAD |
| 32526 | 922 PyEval_RestoreThread(_PyOS_ReadlineTState); |
|
34877
9a7f46c42773
In a threads-disabled build, typing Ctrl-C into a raw_input() crashed,
Michael W. Hudson <mwh@python.net>
parents:
34843
diff
changeset
|
923 #endif |
| 32526 | 924 s = PyErr_CheckSignals(); |
|
34877
9a7f46c42773
In a threads-disabled build, typing Ctrl-C into a raw_input() crashed,
Michael W. Hudson <mwh@python.net>
parents:
34843
diff
changeset
|
925 #ifdef WITH_THREAD |
|
32549
be1a12d0b895
PyThreadState_Swap(NULL) didn't do what I thought it did. Fixes
Michael W. Hudson <mwh@python.net>
parents:
32526
diff
changeset
|
926 PyEval_SaveThread(); |
|
34877
9a7f46c42773
In a threads-disabled build, typing Ctrl-C into a raw_input() crashed,
Michael W. Hudson <mwh@python.net>
parents:
34843
diff
changeset
|
927 #endif |
| 32526 | 928 if (s < 0) { |
| 929 rl_free_line_state(); | |
| 930 rl_cleanup_after_signal(); | |
| 931 rl_callback_handler_remove(); | |
| 932 *signal = 1; | |
| 933 completed_input_string = NULL; | |
| 934 } | |
| 935 } | |
| 936 } | |
| 937 | |
| 938 return completed_input_string; | |
| 939 } | |
| 940 | |
| 941 | |
| 942 #else | |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
943 |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
944 /* Interrupt handler */ |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
945 |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
946 static jmp_buf jbuf; |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
947 |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
948 /* ARGSUSED */ |
|
13676
5423b132bc97
Removed all instances of RETSIGTYPE from the source code: signal
Tim Peters <tim.peters@gmail.com>
parents:
13665
diff
changeset
|
949 static void |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
950 onintr(int sig) |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
951 { |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
952 longjmp(jbuf, 1); |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
953 } |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
954 |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
955 |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
956 static char * |
| 32526 | 957 readline_until_enter_or_signal(char *prompt, int *signal) |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
958 { |
|
14639
133624abc525
Use PyOS_setsig() instead of directly calling signal() or sigaction().
Guido van Rossum <guido@python.org>
parents:
14329
diff
changeset
|
959 PyOS_sighandler_t old_inthandler; |
| 32526 | 960 char *p; |
| 961 | |
| 962 *signal = 0; | |
| 27134 | 963 |
|
14639
133624abc525
Use PyOS_setsig() instead of directly calling signal() or sigaction().
Guido van Rossum <guido@python.org>
parents:
14329
diff
changeset
|
964 old_inthandler = PyOS_setsig(SIGINT, onintr); |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
965 if (setjmp(jbuf)) { |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
966 #ifdef HAVE_SIGRELSE |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
967 /* This seems necessary on SunOS 4.1 (Rasmus Hahn) */ |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
968 sigrelse(SIGINT); |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
969 #endif |
|
14639
133624abc525
Use PyOS_setsig() instead of directly calling signal() or sigaction().
Guido van Rossum <guido@python.org>
parents:
14329
diff
changeset
|
970 PyOS_setsig(SIGINT, old_inthandler); |
| 32526 | 971 *signal = 1; |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
972 return NULL; |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
973 } |
|
33686
1701dae6474e
This is Michiel de Hoon's patch, as attached to the bug report:
Michael W. Hudson <mwh@python.net>
parents:
33255
diff
changeset
|
974 rl_event_hook = PyOS_InputHook; |
| 32526 | 975 p = readline(prompt); |
| 976 PyOS_setsig(SIGINT, old_inthandler); | |
| 977 | |
| 978 return p; | |
| 979 } | |
| 980 #endif /*defined(HAVE_RL_CALLBACK) && defined(HAVE_SELECT) */ | |
| 981 | |
| 982 | |
| 983 static char * | |
| 984 call_readline(FILE *sys_stdin, FILE *sys_stdout, char *prompt) | |
| 985 { | |
|
33255
3fbd2d1ca5bb
SF #1015517, get readline to compile with older compilers
Neal Norwitz <nnorwitz@gmail.com>
parents:
33206
diff
changeset
|
986 size_t n; |
|
3fbd2d1ca5bb
SF #1015517, get readline to compile with older compilers
Neal Norwitz <nnorwitz@gmail.com>
parents:
33206
diff
changeset
|
987 char *p, *q; |
|
3fbd2d1ca5bb
SF #1015517, get readline to compile with older compilers
Neal Norwitz <nnorwitz@gmail.com>
parents:
33206
diff
changeset
|
988 int signal; |
|
3fbd2d1ca5bb
SF #1015517, get readline to compile with older compilers
Neal Norwitz <nnorwitz@gmail.com>
parents:
33206
diff
changeset
|
989 |
|
33177
17973f2e3e0e
Patch #914291: Restore locale while readline is running.
Martin v. Löwis <martin@v.loewis.de>
parents:
33153
diff
changeset
|
990 #ifdef SAVE_LOCALE |
|
17973f2e3e0e
Patch #914291: Restore locale while readline is running.
Martin v. Löwis <martin@v.loewis.de>
parents:
33153
diff
changeset
|
991 char *saved_locale = strdup(setlocale(LC_CTYPE, NULL)); |
|
33206
69700687e30f
Fail fatally if strdup fails.
Martin v. Löwis <martin@v.loewis.de>
parents:
33177
diff
changeset
|
992 if (!saved_locale) |
|
69700687e30f
Fail fatally if strdup fails.
Martin v. Löwis <martin@v.loewis.de>
parents:
33177
diff
changeset
|
993 Py_FatalError("not enough memory to save locale"); |
|
33177
17973f2e3e0e
Patch #914291: Restore locale while readline is running.
Martin v. Löwis <martin@v.loewis.de>
parents:
33153
diff
changeset
|
994 setlocale(LC_CTYPE, ""); |
|
17973f2e3e0e
Patch #914291: Restore locale while readline is running.
Martin v. Löwis <martin@v.loewis.de>
parents:
33153
diff
changeset
|
995 #endif |
| 32526 | 996 |
| 27134 | 997 if (sys_stdin != rl_instream || sys_stdout != rl_outstream) { |
| 998 rl_instream = sys_stdin; | |
| 999 rl_outstream = sys_stdout; | |
|
26849
bca5409b76ec
Patch 659834 by Magnus Lie Hetland:
Guido van Rossum <guido@python.org>
parents:
25924
diff
changeset
|
1000 #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER |
| 27134 | 1001 rl_prep_terminal (1); |
|
26849
bca5409b76ec
Patch 659834 by Magnus Lie Hetland:
Guido van Rossum <guido@python.org>
parents:
25924
diff
changeset
|
1002 #endif |
| 27134 | 1003 } |
| 1004 | |
| 32526 | 1005 p = readline_until_enter_or_signal(prompt, &signal); |
| 1006 | |
| 1007 /* we got an interrupt signal */ | |
|
39098
50b0b54fb17d
Fix memory leaks in some conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
1008 if (signal) { |
|
50b0b54fb17d
Fix memory leaks in some conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
1009 RESTORE_LOCALE(saved_locale) |
| 32526 | 1010 return NULL; |
| 1011 } | |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1012 |
| 32526 | 1013 /* We got an EOF, return a empty string. */ |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1014 if (p == NULL) { |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1015 p = PyMem_Malloc(1); |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1016 if (p != NULL) |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1017 *p = '\0'; |
|
39098
50b0b54fb17d
Fix memory leaks in some conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
1018 RESTORE_LOCALE(saved_locale) |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1019 return p; |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1020 } |
| 32526 | 1021 |
| 1022 /* we have a valid line */ | |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1023 n = strlen(p); |
|
23782
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
1024 if (n > 0) { |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
1025 char *line; |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
1026 HISTORY_STATE *state = history_get_history_state(); |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
1027 if (state->length > 0) |
|
58820
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1028 #ifdef __APPLE__ |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1029 if (using_libedit_emulation) { |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1030 /* |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1031 * Libedit's emulation uses 0-based indexes, |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1032 * the real readline uses 1-based indexes. |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1033 */ |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1034 line = history_get(state->length - 1)->line; |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1035 } else |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1036 #endif /* __APPLE__ */ |
|
23782
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
1037 line = history_get(state->length)->line; |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
1038 else |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
1039 line = ""; |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
1040 if (strcmp(p, line)) |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
1041 add_history(p); |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
1042 /* the history docs don't say so, but the address of state |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
1043 changes each time history_get_history_state is called |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
1044 which makes me think it's freshly malloc'd memory... |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
1045 on the other hand, the address of the last line stays the |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
1046 same as long as history isn't extended, so it appears to |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
1047 be malloc'd but managed by the history package... */ |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
1048 free(state); |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
1049 } |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1050 /* Copy the malloc'ed buffer into a PyMem_Malloc'ed one and |
|
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1051 release the original. */ |
|
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1052 q = p; |
|
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1053 p = PyMem_Malloc(n+2); |
|
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1054 if (p != NULL) { |
|
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1055 strncpy(p, q, n); |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1056 p[n] = '\n'; |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1057 p[n+1] = '\0'; |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1058 } |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1059 free(q); |
|
39098
50b0b54fb17d
Fix memory leaks in some conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
1060 RESTORE_LOCALE(saved_locale) |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1061 return p; |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1062 } |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1063 |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1064 |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1065 /* Initialize the module */ |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1066 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
1067 PyDoc_STRVAR(doc_module, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
1068 "Importing this module enables command line editing using GNU readline."); |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1069 |
|
58820
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1070 #ifdef __APPLE__ |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1071 PyDoc_STRVAR(doc_module_le, |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1072 "Importing this module enables command line editing using libedit readline."); |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1073 #endif /* __APPLE__ */ |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1074 |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
23832
diff
changeset
|
1075 PyMODINIT_FUNC |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13644
diff
changeset
|
1076 initreadline(void) |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1077 { |
|
14972
3eecda2ba93a
Supporting rl_library_version is more trouble than it's worth --
Guido van Rossum <guido@python.org>
parents:
14707
diff
changeset
|
1078 PyObject *m; |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1079 |
|
58820
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1080 #ifdef __APPLE__ |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1081 if (strncmp(rl_library_version, libedit_version_tag, strlen(libedit_version_tag)) == 0) { |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1082 using_libedit_emulation = 1; |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1083 } |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1084 |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1085 if (using_libedit_emulation) |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1086 m = Py_InitModule4("readline", readline_methods, doc_module_le, |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1087 (PyObject *)NULL, PYTHON_API_VERSION); |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1088 else |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1089 |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1090 #endif /* __APPLE__ */ |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1091 |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1092 m = Py_InitModule4("readline", readline_methods, doc_module, |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1093 (PyObject *)NULL, PYTHON_API_VERSION); |
|
36324
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35650
diff
changeset
|
1094 if (m == NULL) |
|
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35650
diff
changeset
|
1095 return; |
|
25924
dc4a0336a2a3
Patch #512981: Update readline input stream on sys.stdin/out change.
Martin v. Löwis <martin@v.loewis.de>
parents:
25684
diff
changeset
|
1096 |
|
58820
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1097 |
|
f108f6275855
Backport the patch that enables linking the readline
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
56779
diff
changeset
|
1098 |
| 27134 | 1099 PyOS_ReadlineFunctionPointer = call_readline; |
| 1100 setup_readline(); | |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1101 } |
