Mercurial > cpython-lru_cache-weakref
annotate Modules/readline.c @ 54294:dba767bc3155 legacy-trunk
remove mention of old ctypes version
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 23 May 2009 20:59:09 +0000 |
| parents | b0429c7fa71a |
| children | b0a2fba00458 |
| 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 |
|
a529e3dc695a
Merged revisions 67098 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47527
diff
changeset
|
41 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
|
42 #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
|
43 #endif |
|
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 |
|
43825
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
45 static void |
|
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
46 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
|
47 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
|
48 |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
49 |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
50 /* 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
|
51 |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
52 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
53 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
|
54 { |
|
9584
e66e88f52606
Bernard Herzog pointed out that rl_parse_and_bind modifies its
Guido van Rossum <guido@python.org>
parents:
8823
diff
changeset
|
55 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
|
56 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
|
57 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
|
58 /* 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
|
59 /* Bernard Herzog */ |
|
e66e88f52606
Bernard Herzog pointed out that rl_parse_and_bind modifies its
Guido van Rossum <guido@python.org>
parents:
8823
diff
changeset
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 free(copy); /* Free the copy */ |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
66 Py_RETURN_NONE; |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
67 } |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
68 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
69 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
|
70 "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
|
71 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
|
72 |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
73 |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
74 /* 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
|
75 |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
76 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
77 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
|
78 { |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
79 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
|
80 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
|
81 return NULL; |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
82 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
|
83 if (errno) |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
84 return PyErr_SetFromErrno(PyExc_IOError); |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
85 Py_RETURN_NONE; |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
86 } |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
87 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
88 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
|
89 "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
|
90 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
|
91 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
|
92 |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
93 |
|
13387
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
94 /* 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
|
95 |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
96 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
97 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
|
98 { |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
99 char *s = NULL; |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
100 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
|
101 return NULL; |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
102 errno = read_history(s); |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
103 if (errno) |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
104 return PyErr_SetFromErrno(PyExc_IOError); |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
105 Py_RETURN_NONE; |
|
13387
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
106 } |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
107 |
|
34027
7e99b0680adf
Rename a static variable "history_length" to "_history_length".
Hye-Shik Chang <hyeshik@gmail.com>
parents:
33686
diff
changeset
|
108 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
|
109 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
|
110 "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
|
111 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
|
112 The default filename is ~/.history."); |
|
13387
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
113 |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
114 |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
115 /* 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
|
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 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
|
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:write_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 = write_history(s); |
|
34027
7e99b0680adf
Rename a static variable "history_length" to "_history_length".
Hye-Shik Chang <hyeshik@gmail.com>
parents:
33686
diff
changeset
|
124 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
|
125 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
|
126 if (errno) |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
127 return PyErr_SetFromErrno(PyExc_IOError); |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
128 Py_RETURN_NONE; |
|
13387
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
129 } |
|
1be4665190f0
added read_history_file and write_history_file
Skip Montanaro <skip@pobox.com>
parents:
13084
diff
changeset
|
130 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
131 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
|
132 "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
|
133 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
|
134 The default filename is ~/.history."); |
|
13387
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 |
| 27134 | 137 /* Set history length */ |
| 138 | |
| 139 static PyObject* | |
| 140 set_history_length(PyObject *self, PyObject *args) | |
| 141 { | |
|
34027
7e99b0680adf
Rename a static variable "history_length" to "_history_length".
Hye-Shik Chang <hyeshik@gmail.com>
parents:
33686
diff
changeset
|
142 int length = _history_length; |
| 27134 | 143 if (!PyArg_ParseTuple(args, "i:set_history_length", &length)) |
| 144 return NULL; | |
|
34027
7e99b0680adf
Rename a static variable "history_length" to "_history_length".
Hye-Shik Chang <hyeshik@gmail.com>
parents:
33686
diff
changeset
|
145 _history_length = length; |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
146 Py_RETURN_NONE; |
| 27134 | 147 } |
| 148 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
149 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
|
150 "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
|
151 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
|
152 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
|
153 history truncation."); |
|
13644
2d5aa212a322
added history file truncation based upon code from Johannes Zellner.
Skip Montanaro <skip@pobox.com>
parents:
13496
diff
changeset
|
154 |
|
2d5aa212a322
added history file truncation based upon code from Johannes Zellner.
Skip Montanaro <skip@pobox.com>
parents:
13496
diff
changeset
|
155 |
| 27134 | 156 /* Get history length */ |
|
13644
2d5aa212a322
added history file truncation based upon code from Johannes Zellner.
Skip Montanaro <skip@pobox.com>
parents:
13496
diff
changeset
|
157 |
|
2d5aa212a322
added history file truncation based upon code from Johannes Zellner.
Skip Montanaro <skip@pobox.com>
parents:
13496
diff
changeset
|
158 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
|
159 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
|
160 { |
|
34027
7e99b0680adf
Rename a static variable "history_length" to "_history_length".
Hye-Shik Chang <hyeshik@gmail.com>
parents:
33686
diff
changeset
|
161 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
|
162 } |
|
2d5aa212a322
added history file truncation based upon code from Johannes Zellner.
Skip Montanaro <skip@pobox.com>
parents:
13496
diff
changeset
|
163 |
| 27134 | 164 PyDoc_STRVAR(get_history_length_doc, |
| 165 "get_history_length() -> int\n\ | |
| 166 return the maximum number of items that will be written to\n\ | |
| 167 the history file."); | |
| 168 | |
| 169 | |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
170 /* 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
|
171 |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
172 static PyObject * |
| 34843 | 173 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
|
174 { |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
175 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
|
176 char buf[80]; |
|
21073
304b34023876
sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents:
21066
diff
changeset
|
177 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
|
178 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
|
179 return NULL; |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
180 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
|
181 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
|
182 *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
|
183 } |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
184 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
|
185 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
|
186 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
|
187 *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
|
188 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
|
189 } |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
190 else { |
|
21073
304b34023876
sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents:
21066
diff
changeset
|
191 PyOS_snprintf(buf, sizeof(buf), |
|
304b34023876
sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents:
21066
diff
changeset
|
192 "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
|
193 funcname); |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
194 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
|
195 return NULL; |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
196 } |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
197 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
|
198 } |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
199 |
| 27134 | 200 |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
201 /* 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
|
202 |
|
43228
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
203 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
|
204 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
|
205 |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
206 #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
|
207 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
|
208 #endif |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
209 |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
210 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
|
211 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
|
212 { |
|
43825
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
213 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
|
214 &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
|
215 #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
|
216 /* 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
|
217 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
|
218 rl_completion_display_matches_hook = |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
219 completion_display_matches_hook ? |
|
49641
a529e3dc695a
Merged revisions 67098 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47527
diff
changeset
|
220 #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
|
221 (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
|
222 #else |
|
a529e3dc695a
Merged revisions 67098 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47527
diff
changeset
|
223 (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
|
224 #endif |
|
43825
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
225 #endif |
|
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
226 return result; |
|
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
227 |
|
43228
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
228 } |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
229 |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
230 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
|
231 "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
|
232 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
|
233 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
|
234 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
|
235 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
|
236 |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
237 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
|
238 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
|
239 { |
| 34843 | 240 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
|
241 } |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
242 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
243 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
|
244 "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
|
245 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
|
246 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
|
247 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
|
248 |
| 27134 | 249 |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
250 #ifdef HAVE_RL_PRE_INPUT_HOOK |
| 27134 | 251 |
| 252 /* Set pre-input hook */ | |
| 253 | |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
254 static PyObject * |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
255 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
|
256 { |
| 34843 | 257 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
|
258 } |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
259 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
260 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
|
261 "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
|
262 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
|
263 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
|
264 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
|
265 characters."); |
| 27134 | 266 |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
267 #endif |
|
13644
2d5aa212a322
added history file truncation based upon code from Johannes Zellner.
Skip Montanaro <skip@pobox.com>
parents:
13496
diff
changeset
|
268 |
| 27134 | 269 |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
270 /* 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
|
271 |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
272 static PyObject *completer = NULL; |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
273 |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
274 static PyObject *begidx = NULL; |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
275 static PyObject *endidx = NULL; |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
276 |
| 27134 | 277 |
|
43228
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
278 /* 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
|
279 static PyObject * |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
280 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
|
281 { |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
282 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
|
283 } |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
284 |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
285 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
|
286 "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
|
287 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
|
288 |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
289 |
| 27134 | 290 /* Get the beginning index for the scope of the tab-completion */ |
| 291 | |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
292 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
|
293 get_begidx(PyObject *self, PyObject *noarg) |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
294 { |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
295 Py_INCREF(begidx); |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
296 return begidx; |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
297 } |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
298 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
299 PyDoc_STRVAR(doc_get_begidx, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
300 "get_begidx() -> int\n\ |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
301 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
|
302 |
| 27134 | 303 |
| 304 /* Get the ending index for the scope of the tab-completion */ | |
| 305 | |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
306 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
|
307 get_endidx(PyObject *self, PyObject *noarg) |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
308 { |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
309 Py_INCREF(endidx); |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
310 return endidx; |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
311 } |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
312 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
313 PyDoc_STRVAR(doc_get_endidx, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
314 "get_endidx() -> int\n\ |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
315 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
|
316 |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
317 |
| 27134 | 318 /* 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
|
319 |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
320 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
321 set_completer_delims(PyObject *self, PyObject *args) |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
322 { |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
323 char *break_chars; |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
324 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11485
diff
changeset
|
325 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
|
326 return NULL; |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
327 } |
|
23204
6e568ee31a9c
#544265, Remove warnings for passing const to free()
Neal Norwitz <nnorwitz@gmail.com>
parents:
22714
diff
changeset
|
328 free((void*)rl_completer_word_break_characters); |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
329 rl_completer_word_break_characters = strdup(break_chars); |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
330 Py_RETURN_NONE; |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
331 } |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
332 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
333 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
|
334 "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
|
335 set the readline word delimiters for tab-completion"); |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
336 |
|
33136
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
337 static PyObject * |
|
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
338 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
|
339 { |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
340 int entry_number; |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
341 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
|
342 |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
343 if (!PyArg_ParseTuple(args, "i:remove_history", &entry_number)) |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
344 return NULL; |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
345 if (entry_number < 0) { |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
346 PyErr_SetString(PyExc_ValueError, |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
347 "History index cannot be negative"); |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
348 return NULL; |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
349 } |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
350 entry = remove_history(entry_number); |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
351 if (!entry) { |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
352 PyErr_Format(PyExc_ValueError, |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
353 "No history item at position %d", |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
354 entry_number); |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
355 return NULL; |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
356 } |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
357 /* free memory allocated for the history entry */ |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
358 if (entry->line) |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
359 free(entry->line); |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
360 if (entry->data) |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
361 free(entry->data); |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
362 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
|
363 |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
364 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
|
365 } |
|
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
366 |
|
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
367 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
|
368 "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
|
369 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
|
370 |
|
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
371 static PyObject * |
|
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
372 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
|
373 { |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
374 int entry_number; |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
375 char *line; |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
376 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
|
377 |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
378 if (!PyArg_ParseTuple(args, "is:replace_history", &entry_number, |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
379 &line)) { |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
380 return NULL; |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
381 } |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
382 if (entry_number < 0) { |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
383 PyErr_SetString(PyExc_ValueError, |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
384 "History index cannot be negative"); |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
385 return NULL; |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
386 } |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
387 old_entry = replace_history_entry(entry_number, line, (void *)NULL); |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
388 if (!old_entry) { |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
389 PyErr_Format(PyExc_ValueError, |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
390 "No history item at position %d", |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
391 entry_number); |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
392 return NULL; |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
393 } |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
394 /* free memory allocated for the old history entry */ |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
395 if (old_entry->line) |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
396 free(old_entry->line); |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
397 if (old_entry->data) |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
398 free(old_entry->data); |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
399 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
|
400 |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
401 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
|
402 } |
|
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
403 |
|
1d9835082be5
Add get_history_item and replace_history_item functions to the readline
Skip Montanaro <skip@pobox.com>
parents:
32549
diff
changeset
|
404 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
|
405 "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
|
406 replaces history item given by its position with contents of line"); |
| 27134 | 407 |
| 408 /* Add a line to the history buffer */ | |
| 409 | |
|
20550
6a5a10a5b526
SF patch #443759: Add Interface to readline's add_history
Guido van Rossum <guido@python.org>
parents:
20188
diff
changeset
|
410 static PyObject * |
|
6a5a10a5b526
SF patch #443759: Add Interface to readline's add_history
Guido van Rossum <guido@python.org>
parents:
20188
diff
changeset
|
411 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
|
412 { |
|
6a5a10a5b526
SF patch #443759: Add Interface to readline's add_history
Guido van Rossum <guido@python.org>
parents:
20188
diff
changeset
|
413 char *line; |
|
6a5a10a5b526
SF patch #443759: Add Interface to readline's add_history
Guido van Rossum <guido@python.org>
parents:
20188
diff
changeset
|
414 |
|
6a5a10a5b526
SF patch #443759: Add Interface to readline's add_history
Guido van Rossum <guido@python.org>
parents:
20188
diff
changeset
|
415 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
|
416 return NULL; |
|
6a5a10a5b526
SF patch #443759: Add Interface to readline's add_history
Guido van Rossum <guido@python.org>
parents:
20188
diff
changeset
|
417 } |
|
6a5a10a5b526
SF patch #443759: Add Interface to readline's add_history
Guido van Rossum <guido@python.org>
parents:
20188
diff
changeset
|
418 add_history(line); |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
419 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
|
420 } |
|
6a5a10a5b526
SF patch #443759: Add Interface to readline's add_history
Guido van Rossum <guido@python.org>
parents:
20188
diff
changeset
|
421 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
422 PyDoc_STRVAR(doc_add_history, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
423 "add_history(string) -> None\n\ |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
424 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
|
425 |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
426 |
| 27134 | 427 /* 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
|
428 |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
429 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
|
430 get_completer_delims(PyObject *self, PyObject *noarg) |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
431 { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
432 return PyString_FromString(rl_completer_word_break_characters); |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
433 } |
| 27134 | 434 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
435 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
|
436 "get_completer_delims() -> string\n\ |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
437 get the readline word delimiters for tab-completion"); |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
438 |
| 27134 | 439 |
| 440 /* Set the completer function */ | |
| 441 | |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
442 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
443 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
|
444 { |
| 34843 | 445 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
|
446 } |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
447 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
448 PyDoc_STRVAR(doc_set_completer, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
449 "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
|
450 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
|
451 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
|
452 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
|
453 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
|
454 |
| 27134 | 455 |
|
27530
5765d524de71
Add the get_completer() function based on Michael Stone's patch in
Michael W. Hudson <mwh@python.net>
parents:
27136
diff
changeset
|
456 static PyObject * |
|
28122
39cb917b5f7a
get_completer() takes no args
Neal Norwitz <nnorwitz@gmail.com>
parents:
27995
diff
changeset
|
457 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
|
458 { |
|
5765d524de71
Add the get_completer() function based on Michael Stone's patch in
Michael W. Hudson <mwh@python.net>
parents:
27136
diff
changeset
|
459 if (completer == NULL) { |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
460 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
|
461 } |
|
5765d524de71
Add the get_completer() function based on Michael Stone's patch in
Michael W. Hudson <mwh@python.net>
parents:
27136
diff
changeset
|
462 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
|
463 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
|
464 } |
|
5765d524de71
Add the get_completer() function based on Michael Stone's patch in
Michael W. Hudson <mwh@python.net>
parents:
27136
diff
changeset
|
465 |
|
5765d524de71
Add the get_completer() function based on Michael Stone's patch in
Michael W. Hudson <mwh@python.net>
parents:
27136
diff
changeset
|
466 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
|
467 "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
|
468 \n\ |
|
5765d524de71
Add the get_completer() function based on Michael Stone's patch in
Michael W. Hudson <mwh@python.net>
parents:
27136
diff
changeset
|
469 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
|
470 |
|
22488
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
471 /* 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
|
472 |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
473 static PyObject * |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
474 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
|
475 { |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
476 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
|
477 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
|
478 |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
479 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
|
480 return NULL; |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
481 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
|
482 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
|
483 else { |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
484 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
|
485 } |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
486 } |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
487 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
488 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
|
489 "get_history_item() -> string\n\ |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
490 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
|
491 |
| 27134 | 492 |
|
22488
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
493 /* 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
|
494 |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
495 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
|
496 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
|
497 { |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
498 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
|
499 |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
500 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
|
501 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
|
502 } |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
503 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
504 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
|
505 "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
|
506 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
|
507 |
| 27134 | 508 |
|
6429
14a711268c51
Add get_line_buffer() and insert_text(), suggested by Michael McLay.
Guido van Rossum <guido@python.org>
parents:
6338
diff
changeset
|
509 /* 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
|
510 |
|
14a711268c51
Add get_line_buffer() and insert_text(), suggested by Michael McLay.
Guido van Rossum <guido@python.org>
parents:
6338
diff
changeset
|
511 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
|
512 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
|
513 { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
514 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
|
515 } |
|
14a711268c51
Add get_line_buffer() and insert_text(), suggested by Michael McLay.
Guido van Rossum <guido@python.org>
parents:
6338
diff
changeset
|
516 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
517 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
|
518 "get_line_buffer() -> string\n\ |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
519 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
|
520 |
| 27134 | 521 |
|
30471
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
522 #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
|
523 |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
524 /* 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
|
525 |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
526 static PyObject * |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
527 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
|
528 { |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
529 clear_history(); |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
530 Py_RETURN_NONE; |
|
30471
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
531 } |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
532 |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
533 PyDoc_STRVAR(doc_clear_history, |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
534 "clear_history() -> None\n\ |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
535 Clear the current readline history."); |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
536 #endif |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
537 |
|
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
538 |
|
6429
14a711268c51
Add get_line_buffer() and insert_text(), suggested by Michael McLay.
Guido van Rossum <guido@python.org>
parents:
6338
diff
changeset
|
539 /* 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
|
540 |
|
14a711268c51
Add get_line_buffer() and insert_text(), suggested by Michael McLay.
Guido van Rossum <guido@python.org>
parents:
6338
diff
changeset
|
541 static PyObject * |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
542 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
|
543 { |
|
14a711268c51
Add get_line_buffer() and insert_text(), suggested by Michael McLay.
Guido van Rossum <guido@python.org>
parents:
6338
diff
changeset
|
544 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
|
545 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
|
546 return NULL; |
|
14a711268c51
Add get_line_buffer() and insert_text(), suggested by Michael McLay.
Guido van Rossum <guido@python.org>
parents:
6338
diff
changeset
|
547 rl_insert_text(s); |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
548 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
|
549 } |
|
14a711268c51
Add get_line_buffer() and insert_text(), suggested by Michael McLay.
Guido van Rossum <guido@python.org>
parents:
6338
diff
changeset
|
550 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
551 PyDoc_STRVAR(doc_insert_text, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
552 "insert_text(string) -> None\n\ |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
553 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
|
554 |
| 27134 | 555 |
| 556 /* Redisplay the line buffer */ | |
| 557 | |
|
22488
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
558 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
|
559 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
|
560 { |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
561 rl_redisplay(); |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
562 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
|
563 } |
|
1361f7bb3f19
Add get_history_item, get_current_history_length, and redisplay functions.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22114
diff
changeset
|
564 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
565 PyDoc_STRVAR(doc_redisplay, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
566 "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
|
567 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
|
568 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
|
569 |
| 27134 | 570 |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
571 /* 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
|
572 |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
573 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
|
574 { |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13676
diff
changeset
|
575 {"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
|
576 {"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
|
577 {"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
|
578 {"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
|
579 {"read_init_file", read_init_file, METH_VARARGS, doc_read_init_file}, |
| 27134 | 580 {"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
|
581 METH_VARARGS, doc_read_history_file}, |
| 27134 | 582 {"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
|
583 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
|
584 {"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
|
585 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
|
586 {"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
|
587 METH_NOARGS, doc_get_current_history_length}, |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
588 {"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
|
589 METH_VARARGS, set_history_length_doc}, |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
590 {"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
|
591 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
|
592 {"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
|
593 {"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
|
594 {"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
|
595 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
|
596 {"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
|
597 {"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
|
598 |
| 27134 | 599 {"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
|
600 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
|
601 {"add_history", py_add_history, METH_VARARGS, doc_add_history}, |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
602 {"remove_history_item", py_remove_history, METH_VARARGS, doc_remove_history}, |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
603 {"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
|
604 {"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
|
605 METH_NOARGS, doc_get_completer_delims}, |
| 27134 | 606 |
|
43228
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
607 {"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
|
608 METH_VARARGS, doc_set_completion_display_matches_hook}, |
| 27134 | 609 {"set_startup_hook", set_startup_hook, |
| 610 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
|
611 #ifdef HAVE_RL_PRE_INPUT_HOOK |
| 27134 | 612 {"set_pre_input_hook", set_pre_input_hook, |
| 613 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
|
614 #endif |
|
30471
94d829367473
Patch #800697: Add readline.clear_history.
Martin v. Löwis <martin@v.loewis.de>
parents:
29926
diff
changeset
|
615 #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
|
616 {"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
|
617 #endif |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
618 {0, 0} |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
619 }; |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
620 |
|
27135
c2663ca31d7d
A few more whitespace normalizations.
Guido van Rossum <guido@python.org>
parents:
27134
diff
changeset
|
621 |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
622 /* 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
|
623 |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
624 static int |
| 34843 | 625 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
|
626 { |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
627 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
|
628 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
|
629 PyObject *r; |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
630 #ifdef WITH_THREAD |
| 34843 | 631 PyGILState_STATE gilstate = PyGILState_Ensure(); |
| 632 #endif | |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
633 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
|
634 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
|
635 goto error; |
| 27134 | 636 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
|
637 result = 0; |
| 34843 | 638 else { |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
639 result = PyInt_AsLong(r); |
| 34843 | 640 if (result == -1 && PyErr_Occurred()) |
| 641 goto error; | |
| 642 } | |
|
20188
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
643 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
|
644 goto done; |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
645 error: |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
646 PyErr_Clear(); |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
647 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
|
648 done: |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
649 #ifdef WITH_THREAD |
| 34843 | 650 PyGILState_Release(gilstate); |
| 651 #endif | |
|
35650
d33f4fc84d4a
Fix parse errors in readline module when compiling without threads.
Georg Brandl <georg@python.org>
parents:
34877
diff
changeset
|
652 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
|
653 } |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
654 return result; |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
655 } |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
656 |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
657 static int |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
658 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
|
659 { |
| 34843 | 660 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
|
661 } |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
662 |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
663 #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
|
664 static int |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
665 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
|
666 { |
| 34843 | 667 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
|
668 } |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
669 #endif |
|
6dda498cccc4
Patch #462122: add readline startup and pre_event hooks.
Martin v. Löwis <martin@v.loewis.de>
parents:
18932
diff
changeset
|
670 |
|
27135
c2663ca31d7d
A few more whitespace normalizations.
Guido van Rossum <guido@python.org>
parents:
27134
diff
changeset
|
671 |
|
43228
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
672 /* 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
|
673 |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
674 static void |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
675 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
|
676 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
|
677 { |
|
43825
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
678 int i; |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
679 PyObject *m=NULL, *s=NULL, *r=NULL; |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
680 #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
|
681 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
|
682 #endif |
|
43825
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
683 m = PyList_New(num_matches); |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
684 if (m == NULL) |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
685 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
|
686 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
|
687 s = PyString_FromString(matches[i+1]); |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
688 if (s == NULL) |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
689 goto error; |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
690 if (PyList_SetItem(m, i, s) == -1) |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
691 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
|
692 } |
|
43228
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
693 |
|
43825
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
694 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
|
695 "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
|
696 |
|
52899
b0429c7fa71a
Issue #1113244: Py_XINCREF, Py_DECREF, Py_XDECREF: Add `do { ... } while (0)'
Matthias Klose <doko@ubuntu.com>
parents:
49641
diff
changeset
|
697 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
|
698 |
|
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
699 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
|
700 (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
|
701 goto error; |
|
29bece147893
Only set rl_completion_display_matches_hook if there
Martin v. Löwis <martin@v.loewis.de>
parents:
43228
diff
changeset
|
702 } |
|
52899
b0429c7fa71a
Issue #1113244: Py_XINCREF, Py_DECREF, Py_XDECREF: Add `do { ... } while (0)'
Matthias Klose <doko@ubuntu.com>
parents:
49641
diff
changeset
|
703 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
|
704 |
|
43834
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
705 if (0) { |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
706 error: |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
707 PyErr_Clear(); |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
708 Py_XDECREF(m); |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
709 Py_XDECREF(r); |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
710 } |
|
d7e9bec1feaa
readline module cleanup
Christian Heimes <christian@cheimes.de>
parents:
43825
diff
changeset
|
711 #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
|
712 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
|
713 #endif |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
714 } |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
715 |
|
1a0c73580665
Patch #1388440: Add set_completion_display_matches_hook and
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
716 |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
717 /* 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
|
718 |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
719 static char * |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
39802
diff
changeset
|
720 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
|
721 { |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
722 char *result = NULL; |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
723 if (completer != NULL) { |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
724 PyObject *r; |
| 34843 | 725 #ifdef WITH_THREAD |
| 726 PyGILState_STATE gilstate = PyGILState_Ensure(); | |
| 727 #endif | |
|
21940
32d0ef6f1955
Simon Budig's patch (posted by me):
Michael W. Hudson <mwh@python.net>
parents:
21712
diff
changeset
|
728 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
|
729 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
|
730 if (r == NULL) |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
731 goto error; |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
732 if (r == Py_None) { |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
733 result = NULL; |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
734 } |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
735 else { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
736 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
|
737 if (s == NULL) |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
738 goto error; |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
739 result = strdup(s); |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
740 } |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
741 Py_DECREF(r); |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
742 goto done; |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
743 error: |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
744 PyErr_Clear(); |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
745 Py_XDECREF(r); |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
746 done: |
| 34843 | 747 #ifdef WITH_THREAD |
| 748 PyGILState_Release(gilstate); | |
| 749 #endif | |
|
35650
d33f4fc84d4a
Fix parse errors in readline module when compiling without threads.
Georg Brandl <georg@python.org>
parents:
34877
diff
changeset
|
750 return result; |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
751 } |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
752 return result; |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
753 } |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
754 |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
755 |
|
27136
3d2962b0249e
Fix from Michael Stone for SF bug #660476 and #513033 (bogus thread
Guido van Rossum <guido@python.org>
parents:
27135
diff
changeset
|
756 /* 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
|
757 * before calling the normal completer */ |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
758 |
|
27995
e11a178bb453
flex_complete looks like a private (but callback) function, so make it static
Neal Norwitz <nnorwitz@gmail.com>
parents:
27531
diff
changeset
|
759 static char ** |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
760 flex_complete(char *text, int start, int end) |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
761 { |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
762 Py_XDECREF(begidx); |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
763 Py_XDECREF(endidx); |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
764 begidx = PyInt_FromLong((long) start); |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
765 endidx = PyInt_FromLong((long) end); |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
766 return completion_matches(text, *on_completion); |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
767 } |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
768 |
|
27135
c2663ca31d7d
A few more whitespace normalizations.
Guido van Rossum <guido@python.org>
parents:
27134
diff
changeset
|
769 |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
770 /* 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
|
771 |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
772 static void |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13644
diff
changeset
|
773 setup_readline(void) |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
774 { |
|
25684
c7d5801bbae8
GNU readline() mistakenly sets the LC_CTYPE locale.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
775 #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
|
776 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
|
777 if (!saved_locale) |
|
69700687e30f
Fail fatally if strdup fails.
Martin v. Löwis <martin@v.loewis.de>
parents:
33177
diff
changeset
|
778 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
|
779 #endif |
|
c7d5801bbae8
GNU readline() mistakenly sets the LC_CTYPE locale.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
780 |
|
23782
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
781 using_history(); |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
782 |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
783 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
|
784 #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
|
785 /* 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
|
786 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
|
787 #endif |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
788 /* 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
|
789 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
|
790 /* 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
|
791 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
|
792 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
|
793 /* 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
|
794 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
|
795 #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
|
796 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
|
797 #endif |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
798 /* Set our completion function */ |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
799 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
|
800 /* 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
|
801 rl_completer_word_break_characters = |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
802 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
|
803 /* All nonalphanums except '.' */ |
|
26849
bca5409b76ec
Patch 659834 by Magnus Lie Hetland:
Guido van Rossum <guido@python.org>
parents:
25924
diff
changeset
|
804 #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER |
|
23580
7dba80d58ffd
SF #558432: Prevent Annoying ' ' from readline (Holker Krekel).
Guido van Rossum <guido@python.org>
parents:
23204
diff
changeset
|
805 rl_completion_append_character ='\0'; |
|
26849
bca5409b76ec
Patch 659834 by Magnus Lie Hetland:
Guido van Rossum <guido@python.org>
parents:
25924
diff
changeset
|
806 #endif |
|
11485
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
807 |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
808 begidx = PyInt_FromLong(0L); |
|
9cdf3fadda92
Patches by Kannan Vijayan:
Guido van Rossum <guido@python.org>
parents:
10029
diff
changeset
|
809 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
|
810 /* 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
|
811 * |
|
034b42ba68a6
setup_readline(): Added a comment about memory leak (reported by
Barry Warsaw <barry@python.org>
parents:
9970
diff
changeset
|
812 * 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
|
813 * 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
|
814 */ |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
815 rl_initialize(); |
|
25684
c7d5801bbae8
GNU readline() mistakenly sets the LC_CTYPE locale.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
816 |
|
39098
50b0b54fb17d
Fix memory leaks in some conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
817 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
|
818 } |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
819 |
| 32526 | 820 /* Wrapper around GNU readline that handles signals differently. */ |
| 821 | |
| 822 | |
| 823 #if defined(HAVE_RL_CALLBACK) && defined(HAVE_SELECT) | |
| 824 | |
| 825 static char *completed_input_string; | |
| 826 static void | |
| 827 rlhandler(char *text) | |
| 828 { | |
| 829 completed_input_string = text; | |
| 830 rl_callback_handler_remove(); | |
| 831 } | |
| 832 | |
| 833 extern PyThreadState* _PyOS_ReadlineTState; | |
| 834 | |
| 835 static char * | |
| 836 readline_until_enter_or_signal(char *prompt, int *signal) | |
| 837 { | |
| 838 char * not_done_reading = ""; | |
| 839 fd_set selectset; | |
| 840 | |
| 841 *signal = 0; | |
| 842 #ifdef HAVE_RL_CATCH_SIGNAL | |
| 843 rl_catch_signals = 0; | |
| 844 #endif | |
| 845 | |
| 846 rl_callback_handler_install (prompt, rlhandler); | |
| 847 FD_ZERO(&selectset); | |
| 848 | |
| 849 completed_input_string = not_done_reading; | |
| 850 | |
|
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
|
851 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
|
852 int has_input = 0; |
| 32526 | 853 |
|
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
|
854 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
|
855 { 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
|
856 |
|
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
|
857 /* [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
|
858 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
|
859 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
|
860 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
|
861 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
|
862 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
|
863 /* 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
|
864 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
|
865 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
|
866 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
|
867 } |
|
1701dae6474e
This is Michiel de Hoon's patch, as attached to the bug report:
Michael W. Hudson <mwh@python.net>
parents:
33255
diff
changeset
|
868 |
| 32526 | 869 if(has_input > 0) { |
| 870 rl_callback_read_char(); | |
| 871 } | |
| 872 else if (errno == EINTR) { | |
| 873 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
|
874 #ifdef WITH_THREAD |
| 32526 | 875 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
|
876 #endif |
| 32526 | 877 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
|
878 #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
|
879 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
|
880 #endif |
| 32526 | 881 if (s < 0) { |
| 882 rl_free_line_state(); | |
| 883 rl_cleanup_after_signal(); | |
| 884 rl_callback_handler_remove(); | |
| 885 *signal = 1; | |
| 886 completed_input_string = NULL; | |
| 887 } | |
| 888 } | |
| 889 } | |
| 890 | |
| 891 return completed_input_string; | |
| 892 } | |
| 893 | |
| 894 | |
| 895 #else | |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
896 |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
897 /* Interrupt handler */ |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
898 |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
899 static jmp_buf jbuf; |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
900 |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
901 /* ARGSUSED */ |
|
13676
5423b132bc97
Removed all instances of RETSIGTYPE from the source code: signal
Tim Peters <tim.peters@gmail.com>
parents:
13665
diff
changeset
|
902 static void |
|
13496
03bc51e43f7a
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
903 onintr(int sig) |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
904 { |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
905 longjmp(jbuf, 1); |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
906 } |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
907 |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
908 |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
909 static char * |
| 32526 | 910 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
|
911 { |
|
14639
133624abc525
Use PyOS_setsig() instead of directly calling signal() or sigaction().
Guido van Rossum <guido@python.org>
parents:
14329
diff
changeset
|
912 PyOS_sighandler_t old_inthandler; |
| 32526 | 913 char *p; |
| 914 | |
| 915 *signal = 0; | |
| 27134 | 916 |
|
14639
133624abc525
Use PyOS_setsig() instead of directly calling signal() or sigaction().
Guido van Rossum <guido@python.org>
parents:
14329
diff
changeset
|
917 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
|
918 if (setjmp(jbuf)) { |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
919 #ifdef HAVE_SIGRELSE |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
920 /* 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
|
921 sigrelse(SIGINT); |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
922 #endif |
|
14639
133624abc525
Use PyOS_setsig() instead of directly calling signal() or sigaction().
Guido van Rossum <guido@python.org>
parents:
14329
diff
changeset
|
923 PyOS_setsig(SIGINT, old_inthandler); |
| 32526 | 924 *signal = 1; |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
925 return NULL; |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
926 } |
|
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
|
927 rl_event_hook = PyOS_InputHook; |
| 32526 | 928 p = readline(prompt); |
| 929 PyOS_setsig(SIGINT, old_inthandler); | |
| 930 | |
| 931 return p; | |
| 932 } | |
| 933 #endif /*defined(HAVE_RL_CALLBACK) && defined(HAVE_SELECT) */ | |
| 934 | |
| 935 | |
| 936 static char * | |
| 937 call_readline(FILE *sys_stdin, FILE *sys_stdout, char *prompt) | |
| 938 { | |
|
33255
3fbd2d1ca5bb
SF #1015517, get readline to compile with older compilers
Neal Norwitz <nnorwitz@gmail.com>
parents:
33206
diff
changeset
|
939 size_t n; |
|
3fbd2d1ca5bb
SF #1015517, get readline to compile with older compilers
Neal Norwitz <nnorwitz@gmail.com>
parents:
33206
diff
changeset
|
940 char *p, *q; |
|
3fbd2d1ca5bb
SF #1015517, get readline to compile with older compilers
Neal Norwitz <nnorwitz@gmail.com>
parents:
33206
diff
changeset
|
941 int signal; |
|
3fbd2d1ca5bb
SF #1015517, get readline to compile with older compilers
Neal Norwitz <nnorwitz@gmail.com>
parents:
33206
diff
changeset
|
942 |
|
33177
17973f2e3e0e
Patch #914291: Restore locale while readline is running.
Martin v. Löwis <martin@v.loewis.de>
parents:
33153
diff
changeset
|
943 #ifdef SAVE_LOCALE |
|
17973f2e3e0e
Patch #914291: Restore locale while readline is running.
Martin v. Löwis <martin@v.loewis.de>
parents:
33153
diff
changeset
|
944 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
|
945 if (!saved_locale) |
|
69700687e30f
Fail fatally if strdup fails.
Martin v. Löwis <martin@v.loewis.de>
parents:
33177
diff
changeset
|
946 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
|
947 setlocale(LC_CTYPE, ""); |
|
17973f2e3e0e
Patch #914291: Restore locale while readline is running.
Martin v. Löwis <martin@v.loewis.de>
parents:
33153
diff
changeset
|
948 #endif |
| 32526 | 949 |
| 27134 | 950 if (sys_stdin != rl_instream || sys_stdout != rl_outstream) { |
| 951 rl_instream = sys_stdin; | |
| 952 rl_outstream = sys_stdout; | |
|
26849
bca5409b76ec
Patch 659834 by Magnus Lie Hetland:
Guido van Rossum <guido@python.org>
parents:
25924
diff
changeset
|
953 #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER |
| 27134 | 954 rl_prep_terminal (1); |
|
26849
bca5409b76ec
Patch 659834 by Magnus Lie Hetland:
Guido van Rossum <guido@python.org>
parents:
25924
diff
changeset
|
955 #endif |
| 27134 | 956 } |
| 957 | |
| 32526 | 958 p = readline_until_enter_or_signal(prompt, &signal); |
| 959 | |
| 960 /* we got an interrupt signal */ | |
|
39098
50b0b54fb17d
Fix memory leaks in some conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
961 if (signal) { |
|
50b0b54fb17d
Fix memory leaks in some conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
962 RESTORE_LOCALE(saved_locale) |
| 32526 | 963 return NULL; |
| 964 } | |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
965 |
| 32526 | 966 /* 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
|
967 if (p == NULL) { |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
968 p = PyMem_Malloc(1); |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
969 if (p != NULL) |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
970 *p = '\0'; |
|
39098
50b0b54fb17d
Fix memory leaks in some conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
971 RESTORE_LOCALE(saved_locale) |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
972 return p; |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
973 } |
| 32526 | 974 |
| 975 /* we have a valid line */ | |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
976 n = strlen(p); |
|
23782
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
977 if (n > 0) { |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
978 char *line; |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
979 HISTORY_STATE *state = history_get_history_state(); |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
980 if (state->length > 0) |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
981 line = history_get(state->length)->line; |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
982 else |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
983 line = ""; |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
984 if (strcmp(p, line)) |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
985 add_history(p); |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
986 /* 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
|
987 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
|
988 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
|
989 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
|
990 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
|
991 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
|
992 free(state); |
|
54f6f89139db
patch #562492 - prevent duplicate lines in history
Skip Montanaro <skip@pobox.com>
parents:
23580
diff
changeset
|
993 } |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
994 /* 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
|
995 release the original. */ |
|
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
996 q = p; |
|
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
997 p = PyMem_Malloc(n+2); |
|
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
998 if (p != NULL) { |
|
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
999 strncpy(p, q, n); |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1000 p[n] = '\n'; |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1001 p[n+1] = '\0'; |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1002 } |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1003 free(q); |
|
39098
50b0b54fb17d
Fix memory leaks in some conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
1004 RESTORE_LOCALE(saved_locale) |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1005 return p; |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1006 } |
|
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1007 |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1008 |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1009 /* Initialize the module */ |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1010 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
1011 PyDoc_STRVAR(doc_module, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23782
diff
changeset
|
1012 "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
|
1013 |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
23832
diff
changeset
|
1014 PyMODINIT_FUNC |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13644
diff
changeset
|
1015 initreadline(void) |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1016 { |
|
14972
3eecda2ba93a
Supporting rl_library_version is more trouble than it's worth --
Guido van Rossum <guido@python.org>
parents:
14707
diff
changeset
|
1017 PyObject *m; |
|
6335
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1018 |
|
575f6b910f88
Reordered and reformatted, and added some cool new features:
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
1019 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
|
1020 (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
|
1021 if (m == NULL) |
|
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35650
diff
changeset
|
1022 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
|
1023 |
| 27134 | 1024 PyOS_ReadlineFunctionPointer = call_readline; |
| 1025 setup_readline(); | |
|
5947
7ca6a912d455
New mechanism for GNU readline interface, via module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1026 } |
