Commit | Line | Data |
---|---|---|
c374ab69 MV |
1 | /* readline.c --- line editing support for Guile */ |
2 | ||
d3075c52 | 3 | /* Copyright (C) 1997,1999,2000,2001, 2002, 2003, 2006, 2007 Free Software Foundation, Inc. |
c374ab69 MV |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2, or (at your option) | |
8 | * any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this software; see the file COPYING. If not, write to | |
92205699 MV |
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | * Boston, MA 02110-1301 USA | |
c374ab69 MV |
19 | * |
20 | */ | |
f48e47b9 | 21 | |
f48e47b9 | 22 | |
c374ab69 MV |
23 | \f |
24 | ||
5be9f729 KR |
25 | /* Include private, configure generated header (i.e. config.h). */ |
26 | #include "guile-readline-config.h" | |
26aff4f9 | 27 | |
62947883 | 28 | #ifdef HAVE_RL_GETC_FUNCTION |
fbf68f8b | 29 | #include "libguile.h" |
739b3bf1 MD |
30 | #include "libguile/gh.h" |
31 | #include "libguile/iselect.h" | |
32 | ||
ffdeebc3 | 33 | #include <stdio.h> |
48552b1d MD |
34 | #ifdef HAVE_UNISTD_H |
35 | #include <unistd.h> | |
36 | #endif | |
c374ab69 MV |
37 | #include <readline/readline.h> |
38 | #include <readline/history.h> | |
5e90b6ac | 39 | #ifndef __MINGW32__ |
c374ab69 | 40 | #include <sys/time.h> |
5e90b6ac MV |
41 | #else |
42 | #include <io.h> | |
43 | #endif | |
b71099ba | 44 | #include <signal.h> |
c374ab69 | 45 | |
1c537018 | 46 | #include "libguile/validate.h" |
a0599745 | 47 | #include "guile-readline/readline.h" |
c374ab69 | 48 | |
593be5d2 | 49 | scm_t_option scm_readline_opts[] = { |
c374ab69 MV |
50 | { SCM_OPTION_BOOLEAN, "history-file", 1, |
51 | "Use history file." }, | |
52 | { SCM_OPTION_INTEGER, "history-length", 200, | |
53 | "History length." }, | |
54 | { SCM_OPTION_INTEGER, "bounce-parens", 500, | |
62560650 HWN |
55 | "Time (ms) to show matching opening parenthesis (0 = off)."}, |
56 | { 0 } | |
c374ab69 MV |
57 | }; |
58 | ||
59 | extern void stifle_history (int max); | |
60 | ||
b916d813 | 61 | SCM_DEFINE (scm_readline_options, "readline-options-interface", 0, 1, 0, |
f48e47b9 GB |
62 | (SCM setting), |
63 | "") | |
64 | #define FUNC_NAME s_scm_readline_options | |
c374ab69 MV |
65 | { |
66 | SCM ans = scm_options (setting, | |
67 | scm_readline_opts, | |
f48e47b9 | 68 | FUNC_NAME); |
c374ab69 MV |
69 | stifle_history (SCM_HISTORY_LENGTH); |
70 | return ans; | |
71 | } | |
f48e47b9 | 72 | #undef FUNC_NAME |
c374ab69 MV |
73 | |
74 | #ifndef HAVE_STRDUP | |
75 | static char * | |
76 | strdup (char *s) | |
77 | { | |
1be6b49c | 78 | size_t len = strlen (s); |
c374ab69 MV |
79 | char *new = malloc (len + 1); |
80 | strcpy (new, s); | |
81 | return new; | |
82 | } | |
83 | #endif /* HAVE_STRDUP */ | |
84 | ||
85 | #ifndef HAVE_RL_CLEANUP_AFTER_SIGNAL | |
86 | ||
87 | /* These are readline functions added in release 2.3. They will work | |
88 | * together with readline-2.1 and 2.2. (The readline interface is | |
89 | * disabled for earlier releases.) | |
90 | * They are declared static; if we want to use them elsewhere, then | |
91 | * we need external declarations for them, but at the moment, I don't | |
92 | * think anything else in Guile ought to use these. | |
93 | */ | |
94 | ||
95 | extern void _rl_clean_up_for_exit (); | |
96 | extern void _rl_kill_kbd_macro (); | |
97 | extern int _rl_init_argument (); | |
98 | ||
2e3d5987 | 99 | void |
c374ab69 MV |
100 | rl_cleanup_after_signal () |
101 | { | |
102 | #ifdef HAVE_RL_CLEAR_SIGNALS | |
103 | _rl_clean_up_for_exit (); | |
104 | #endif | |
105 | (*rl_deprep_term_function) (); | |
106 | #ifdef HAVE_RL_CLEAR_SIGNALS | |
107 | rl_clear_signals (); | |
108 | #endif | |
109 | rl_pending_input = 0; | |
110 | } | |
111 | ||
2e3d5987 | 112 | void |
c374ab69 MV |
113 | rl_free_line_state () |
114 | { | |
115 | register HIST_ENTRY *entry; | |
116 | ||
117 | free_undo_list (); | |
118 | ||
119 | entry = current_history (); | |
120 | if (entry) | |
121 | entry->data = (char *)NULL; | |
122 | ||
123 | _rl_kill_kbd_macro (); | |
124 | rl_clear_message (); | |
125 | _rl_init_argument (); | |
126 | } | |
127 | ||
128 | #endif /* !HAVE_RL_CLEANUP_AFTER_SIGNAL */ | |
129 | ||
130 | static int promptp; | |
131 | static SCM input_port; | |
132 | static SCM before_read; | |
133 | ||
134 | static int | |
e81d98ec | 135 | current_input_getc (FILE *in SCM_UNUSED) |
c374ab69 | 136 | { |
be49d1df | 137 | if (promptp && scm_is_true (before_read)) |
c374ab69 MV |
138 | { |
139 | scm_apply (before_read, SCM_EOL, SCM_EOL); | |
140 | promptp = 0; | |
141 | } | |
bc858b80 | 142 | return scm_getc (input_port); |
c374ab69 MV |
143 | } |
144 | ||
c374ab69 | 145 | static int in_readline = 0; |
bb0f37e7 | 146 | static SCM reentry_barrier_mutex; |
c374ab69 | 147 | |
f48e47b9 GB |
148 | static SCM internal_readline (SCM text); |
149 | static SCM handle_error (void *data, SCM tag, SCM args); | |
48552b1d | 150 | static void reentry_barrier (void); |
f48e47b9 GB |
151 | |
152 | ||
b916d813 | 153 | SCM_DEFINE (scm_readline, "%readline", 0, 4, 0, |
f48e47b9 GB |
154 | (SCM text, SCM inp, SCM outp, SCM read_hook), |
155 | "") | |
156 | #define FUNC_NAME s_scm_readline | |
157 | { | |
158 | SCM ans; | |
159 | ||
160 | reentry_barrier (); | |
161 | ||
162 | before_read = SCM_BOOL_F; | |
163 | ||
164 | if (!SCM_UNBNDP (text)) | |
165 | { | |
ad6dec05 | 166 | if (!scm_is_string (text)) |
f48e47b9 GB |
167 | { |
168 | --in_readline; | |
169 | scm_wrong_type_arg (s_scm_readline, SCM_ARG1, text); | |
170 | } | |
f48e47b9 GB |
171 | } |
172 | ||
0ddf47fc | 173 | if (!((SCM_UNBNDP (inp) && SCM_OPINFPORTP (scm_current_input_port ())) |
379b35da | 174 | || SCM_OPINFPORTP (inp))) |
f48e47b9 GB |
175 | { |
176 | --in_readline; | |
177 | scm_misc_error (s_scm_readline, | |
178 | "Input port is not open or not a file port", | |
179 | SCM_EOL); | |
180 | } | |
181 | ||
0ddf47fc | 182 | if (!((SCM_UNBNDP (outp) && SCM_OPOUTFPORTP (scm_current_output_port ())) |
379b35da | 183 | || SCM_OPOUTFPORTP (outp))) |
f48e47b9 GB |
184 | { |
185 | --in_readline; | |
186 | scm_misc_error (s_scm_readline, | |
187 | "Output port is not open or not a file port", | |
188 | SCM_EOL); | |
189 | } | |
190 | ||
be49d1df | 191 | if (!(SCM_UNBNDP (read_hook) || scm_is_false (read_hook))) |
f48e47b9 | 192 | { |
be49d1df | 193 | if (scm_is_false (scm_thunk_p (read_hook))) |
f48e47b9 GB |
194 | { |
195 | --in_readline; | |
196 | scm_wrong_type_arg (s_scm_readline, SCM_ARG4, read_hook); | |
197 | } | |
198 | before_read = read_hook; | |
199 | } | |
200 | ||
201 | scm_readline_init_ports (inp, outp); | |
202 | ||
203 | ans = scm_internal_catch (SCM_BOOL_T, | |
593be5d2 | 204 | (scm_t_catch_body) internal_readline, |
f60d011a | 205 | (void *) SCM_UNPACK (text), |
f48e47b9 GB |
206 | handle_error, 0); |
207 | ||
8f99e3f3 | 208 | #ifndef __MINGW32__ |
f48e47b9 GB |
209 | fclose (rl_instream); |
210 | fclose (rl_outstream); | |
8f99e3f3 | 211 | #endif |
f48e47b9 GB |
212 | |
213 | --in_readline; | |
214 | return ans; | |
215 | } | |
216 | #undef FUNC_NAME | |
217 | ||
218 | ||
c374ab69 MV |
219 | static void |
220 | reentry_barrier () | |
221 | { | |
222 | int reentryp = 0; | |
246c563b | 223 | /* We should rather use scm_try_mutex when it becomes available */ |
bb0f37e7 | 224 | scm_lock_mutex (reentry_barrier_mutex); |
c374ab69 MV |
225 | if (in_readline) |
226 | reentryp = 1; | |
227 | else | |
228 | ++in_readline; | |
bb0f37e7 | 229 | scm_unlock_mutex (reentry_barrier_mutex); |
c374ab69 | 230 | if (reentryp) |
f48e47b9 | 231 | scm_misc_error (s_scm_readline, "readline is not reentrant", SCM_EOL); |
c374ab69 MV |
232 | } |
233 | ||
234 | static SCM | |
235 | handle_error (void *data, SCM tag, SCM args) | |
236 | { | |
237 | rl_free_line_state (); | |
238 | rl_cleanup_after_signal (); | |
739b3bf1 | 239 | fputc ('\n', rl_outstream); /* We don't want next output on this line */ |
8f99e3f3 | 240 | #ifndef __MINGW32__ |
c374ab69 MV |
241 | fclose (rl_instream); |
242 | fclose (rl_outstream); | |
8f99e3f3 | 243 | #endif |
c374ab69 MV |
244 | --in_readline; |
245 | scm_handle_by_throw (data, tag, args); | |
246 | return SCM_UNSPECIFIED; /* never reached */ | |
247 | } | |
248 | ||
249 | static SCM | |
250 | internal_readline (SCM text) | |
251 | { | |
252 | SCM ret; | |
253 | char *s; | |
ad6dec05 | 254 | char *prompt = SCM_UNBNDP (text) ? "" : scm_to_locale_string (text); |
c374ab69 MV |
255 | |
256 | promptp = 1; | |
257 | s = readline (prompt); | |
258 | if (s) | |
ad6dec05 | 259 | ret = scm_from_locale_string (s); |
c374ab69 MV |
260 | else |
261 | ret = SCM_EOF_VAL; | |
262 | ||
ad6dec05 MV |
263 | if (!SCM_UNBNDP (text)) |
264 | free (prompt); | |
c374ab69 MV |
265 | free (s); |
266 | ||
267 | return ret; | |
268 | } | |
269 | ||
270 | static FILE * | |
271 | stream_from_fport (SCM port, char *mode, const char *subr) | |
272 | { | |
273 | int fd; | |
274 | FILE *f; | |
275 | ||
593be5d2 | 276 | fd = dup (((struct scm_t_fport *) SCM_STREAM (port))->fdes); |
c374ab69 MV |
277 | if (fd == -1) |
278 | { | |
279 | --in_readline; | |
280 | scm_syserror (subr); | |
281 | } | |
282 | ||
283 | f = fdopen (fd, mode); | |
284 | if (f == NULL) | |
285 | { | |
286 | --in_readline; | |
287 | scm_syserror (subr); | |
288 | } | |
289 | ||
290 | return f; | |
291 | } | |
292 | ||
2e3d5987 MD |
293 | void |
294 | scm_readline_init_ports (SCM inp, SCM outp) | |
295 | { | |
296 | if (SCM_UNBNDP (inp)) | |
0ddf47fc | 297 | inp = scm_current_input_port (); |
2e3d5987 MD |
298 | |
299 | if (SCM_UNBNDP (outp)) | |
0ddf47fc | 300 | outp = scm_current_output_port (); |
2e3d5987 | 301 | |
379b35da | 302 | if (!SCM_OPINFPORTP (inp)) { |
2e3d5987 MD |
303 | scm_misc_error (0, |
304 | "Input port is not open or not a file port", | |
305 | SCM_EOL); | |
306 | } | |
307 | ||
379b35da | 308 | if (!SCM_OPOUTFPORTP (outp)) { |
2e3d5987 MD |
309 | scm_misc_error (0, |
310 | "Output port is not open or not a file port", | |
311 | SCM_EOL); | |
312 | } | |
313 | ||
314 | input_port = inp; | |
8f99e3f3 | 315 | #ifndef __MINGW32__ |
f48e47b9 GB |
316 | rl_instream = stream_from_fport (inp, "r", s_scm_readline); |
317 | rl_outstream = stream_from_fport (outp, "w", s_scm_readline); | |
8f99e3f3 | 318 | #endif |
2e3d5987 MD |
319 | } |
320 | ||
c374ab69 | 321 | |
c374ab69 | 322 | |
b916d813 | 323 | SCM_DEFINE (scm_add_history, "add-history", 1, 0, 0, |
f48e47b9 GB |
324 | (SCM text), |
325 | "") | |
326 | #define FUNC_NAME s_scm_add_history | |
c374ab69 MV |
327 | { |
328 | char* s; | |
c374ab69 | 329 | |
ad6dec05 MV |
330 | s = scm_to_locale_string (text); |
331 | add_history (s); | |
d3075c52 | 332 | free (s); |
c374ab69 MV |
333 | |
334 | return SCM_UNSPECIFIED; | |
335 | } | |
f48e47b9 | 336 | #undef FUNC_NAME |
c374ab69 MV |
337 | |
338 | ||
b916d813 | 339 | SCM_DEFINE (scm_read_history, "read-history", 1, 0, 0, |
f48e47b9 GB |
340 | (SCM file), |
341 | "") | |
342 | #define FUNC_NAME s_scm_read_history | |
c374ab69 | 343 | { |
ad6dec05 MV |
344 | char *filename; |
345 | SCM ret; | |
346 | ||
347 | filename = scm_to_locale_string (file); | |
348 | ret = scm_from_bool (!read_history (filename)); | |
349 | free (filename); | |
350 | return ret; | |
c374ab69 | 351 | } |
f48e47b9 | 352 | #undef FUNC_NAME |
c374ab69 MV |
353 | |
354 | ||
b916d813 | 355 | SCM_DEFINE (scm_write_history, "write-history", 1, 0, 0, |
f48e47b9 GB |
356 | (SCM file), |
357 | "") | |
358 | #define FUNC_NAME s_scm_write_history | |
c374ab69 | 359 | { |
ad6dec05 MV |
360 | char *filename; |
361 | SCM ret; | |
362 | ||
363 | filename = scm_to_locale_string (file); | |
364 | ret = scm_from_bool (!write_history (filename)); | |
365 | free (filename); | |
366 | return ret; | |
c374ab69 | 367 | } |
f48e47b9 | 368 | #undef FUNC_NAME |
c374ab69 | 369 | |
8ed35a15 MV |
370 | SCM_DEFINE (scm_clear_history, "clear-history", 0, 0, 0, |
371 | (), | |
372 | "Clear the history buffer of the readline machinery.") | |
373 | #define FUNC_NAME s_scm_clear_history | |
374 | { | |
375 | clear_history(); | |
376 | return SCM_UNSPECIFIED; | |
377 | } | |
378 | #undef FUNC_NAME | |
379 | ||
c374ab69 | 380 | |
b916d813 | 381 | SCM_DEFINE (scm_filename_completion_function, "filename-completion-function", 2, 0, 0, |
f48e47b9 GB |
382 | (SCM text, SCM continuep), |
383 | "") | |
384 | #define FUNC_NAME s_scm_filename_completion_function | |
c374ab69 MV |
385 | { |
386 | char *s; | |
387 | SCM ans; | |
ad6dec05 | 388 | char *c_text = scm_to_locale_string (text); |
dcb17187 | 389 | #ifdef HAVE_RL_FILENAME_COMPLETION_FUNCTION |
ad6dec05 | 390 | s = rl_filename_completion_function (c_text, scm_is_true (continuep)); |
dcb17187 | 391 | #else |
ad6dec05 | 392 | s = filename_completion_function (c_text, scm_is_true (continuep)); |
dcb17187 | 393 | #endif |
ad6dec05 MV |
394 | ans = scm_take_locale_string (s); |
395 | free (c_text); | |
c374ab69 MV |
396 | return ans; |
397 | } | |
f48e47b9 | 398 | #undef FUNC_NAME |
c374ab69 MV |
399 | |
400 | /* | |
401 | * The following has been modified from code contributed by | |
402 | * Andrew Archibald <aarchiba@undergrad.math.uwaterloo.ca> | |
403 | */ | |
404 | ||
405 | SCM scm_readline_completion_function_var; | |
406 | ||
407 | static char * | |
408 | completion_function (char *text, int continuep) | |
409 | { | |
296ff5e7 | 410 | SCM compfunc = SCM_VARIABLE_REF (scm_readline_completion_function_var); |
c374ab69 MV |
411 | SCM res; |
412 | ||
be49d1df | 413 | if (scm_is_false (compfunc)) |
c374ab69 MV |
414 | return NULL; /* #f => completion disabled */ |
415 | else | |
416 | { | |
ad6dec05 | 417 | SCM t = scm_from_locale_string (text); |
be49d1df | 418 | SCM c = scm_from_bool (continuep); |
5b2a7b59 | 419 | res = scm_apply (compfunc, scm_list_2 (t, c), SCM_EOL); |
c374ab69 | 420 | |
be49d1df | 421 | if (scm_is_false (res)) |
c374ab69 MV |
422 | return NULL; |
423 | ||
ad6dec05 | 424 | return scm_to_locale_string (res); |
c374ab69 MV |
425 | } |
426 | } | |
427 | ||
428 | /*Bouncing parenthesis (reimplemented by GH, 11/23/98, since readline is strict gpl)*/ | |
429 | ||
576cdec4 MD |
430 | static int match_paren (int x, int k); |
431 | static int find_matching_paren (int k); | |
432 | static void init_bouncing_parens (); | |
c374ab69 MV |
433 | |
434 | static void | |
576cdec4 | 435 | init_bouncing_parens () |
c374ab69 | 436 | { |
576cdec4 MD |
437 | if (strncmp (rl_get_keymap_name (rl_get_keymap ()), "vi", 2)) |
438 | { | |
439 | rl_bind_key (')', match_paren); | |
440 | rl_bind_key (']', match_paren); | |
441 | rl_bind_key ('}', match_paren); | |
442 | } | |
c374ab69 MV |
443 | } |
444 | ||
445 | static int | |
446 | find_matching_paren(int k) | |
447 | { | |
448 | register int i; | |
449 | register char c = 0; | |
450 | int end_parens_found = 0; | |
451 | ||
452 | /* Choose the corresponding opening bracket. */ | |
453 | if (k == ')') c = '('; | |
454 | else if (k == ']') c = '['; | |
455 | else if (k == '}') c = '{'; | |
456 | ||
457 | for (i=rl_point-2; i>=0; i--) | |
458 | { | |
459 | /* Is the current character part of a character literal? */ | |
460 | if (i - 2 >= 0 | |
461 | && rl_line_buffer[i - 1] == '\\' | |
462 | && rl_line_buffer[i - 2] == '#') | |
463 | ; | |
464 | else if (rl_line_buffer[i] == k) | |
465 | end_parens_found++; | |
466 | else if (rl_line_buffer[i] == '"') | |
467 | { | |
468 | /* Skip over a string literal. */ | |
469 | for (i--; i >= 0; i--) | |
470 | if (rl_line_buffer[i] == '"' | |
471 | && ! (i - 1 >= 0 | |
472 | && rl_line_buffer[i - 1] == '\\')) | |
473 | break; | |
474 | } | |
475 | else if (rl_line_buffer[i] == c) | |
476 | { | |
576cdec4 MD |
477 | if (end_parens_found==0) |
478 | return i; | |
c374ab69 MV |
479 | else --end_parens_found; |
480 | } | |
481 | } | |
482 | return -1; | |
483 | } | |
484 | ||
576cdec4 MD |
485 | static int |
486 | match_paren (int x, int k) | |
c374ab69 | 487 | { |
8f99e3f3 SJ |
488 | int tmp; |
489 | #ifndef __MINGW32__ | |
490 | int fno; | |
aba2031a | 491 | SELECT_TYPE readset; |
c374ab69 | 492 | struct timeval timeout; |
8f99e3f3 SJ |
493 | #endif |
494 | ||
576cdec4 | 495 | rl_insert (x, k); |
c374ab69 | 496 | if (!SCM_READLINE_BOUNCE_PARENS) |
576cdec4 | 497 | return 0; |
c374ab69 MV |
498 | |
499 | /* Did we just insert a quoted paren? If so, then don't bounce. */ | |
500 | if (rl_point - 1 >= 1 | |
501 | && rl_line_buffer[rl_point - 2] == '\\') | |
576cdec4 | 502 | return 0; |
c374ab69 | 503 | |
8f99e3f3 | 504 | #ifndef __MINGW32__ |
c374ab69 MV |
505 | tmp = 1000 * SCM_READLINE_BOUNCE_PARENS; |
506 | timeout.tv_sec = tmp / 1000000; | |
507 | timeout.tv_usec = tmp % 1000000; | |
576cdec4 | 508 | FD_ZERO (&readset); |
bc858b80 MD |
509 | fno = fileno (rl_instream); |
510 | FD_SET (fno, &readset); | |
8f99e3f3 SJ |
511 | #endif |
512 | ||
576cdec4 MD |
513 | if (rl_point > 1) |
514 | { | |
515 | tmp = rl_point; | |
516 | rl_point = find_matching_paren (k); | |
517 | if (rl_point > -1) | |
518 | { | |
519 | rl_redisplay (); | |
8f99e3f3 | 520 | #ifndef __MINGW32__ |
0ddf47fc | 521 | scm_std_select (fno + 1, &readset, NULL, NULL, &timeout); |
8f99e3f3 SJ |
522 | #else |
523 | WaitForSingleObject (GetStdHandle(STD_INPUT_HANDLE), | |
524 | SCM_READLINE_BOUNCE_PARENS); | |
525 | #endif | |
576cdec4 MD |
526 | } |
527 | rl_point = tmp; | |
c374ab69 | 528 | } |
576cdec4 | 529 | return 0; |
c374ab69 MV |
530 | } |
531 | ||
b71099ba MD |
532 | #if defined (HAVE_RL_PRE_INPUT_HOOK) && defined (GUILE_SIGWINCH_SA_RESTART_CLEARED) |
533 | /* Readline disables SA_RESTART on SIGWINCH. | |
534 | * This code turns it back on. | |
535 | */ | |
536 | static int | |
537 | sigwinch_enable_restart (void) | |
538 | { | |
539 | #ifdef HAVE_SIGINTERRUPT | |
540 | siginterrupt (SIGWINCH, 0); | |
541 | #else | |
542 | struct sigaction action; | |
543 | ||
544 | sigaction (SIGWINCH, NULL, &action); | |
545 | action.sa_flags |= SA_RESTART; | |
546 | sigaction (SIGWINCH, &action, NULL); | |
547 | #endif | |
548 | return 0; | |
549 | } | |
550 | #endif | |
551 | ||
26047451 MD |
552 | #endif /* HAVE_RL_GETC_FUNCTION */ |
553 | ||
c374ab69 MV |
554 | void |
555 | scm_init_readline () | |
556 | { | |
62947883 | 557 | #ifdef HAVE_RL_GETC_FUNCTION |
a0599745 | 558 | #include "guile-readline/readline.x" |
c374ab69 | 559 | scm_readline_completion_function_var |
296ff5e7 | 560 | = scm_c_define ("*readline-completion-function*", SCM_BOOL_F); |
8f99e3f3 | 561 | #ifndef __MINGW32__ |
c374ab69 | 562 | rl_getc_function = current_input_getc; |
8f99e3f3 | 563 | #endif |
dcb17187 MV |
564 | #if defined (_RL_FUNCTION_TYPEDEF) |
565 | rl_completion_entry_function = (rl_compentry_func_t*) completion_function; | |
566 | #else | |
c374ab69 | 567 | rl_completion_entry_function = (Function*) completion_function; |
dcb17187 | 568 | #endif |
c374ab69 | 569 | rl_basic_word_break_characters = "\t\n\"'`;()"; |
5c11cc9d | 570 | rl_readline_name = "Guile"; |
b71099ba MD |
571 | #if defined (HAVE_RL_PRE_INPUT_HOOK) && defined (GUILE_SIGWINCH_SA_RESTART_CLEARED) |
572 | rl_pre_input_hook = sigwinch_enable_restart; | |
573 | #endif | |
5c11cc9d | 574 | |
bb0f37e7 | 575 | reentry_barrier_mutex = scm_permanent_object (scm_make_mutex ()); |
c374ab69 | 576 | scm_init_opts (scm_readline_options, |
07109436 | 577 | scm_readline_opts); |
c374ab69 MV |
578 | init_bouncing_parens(); |
579 | scm_add_feature ("readline"); | |
62947883 | 580 | #endif /* HAVE_RL_GETC_FUNCTION */ |
c374ab69 MV |
581 | } |
582 | ||
89e00824 ML |
583 | /* |
584 | Local Variables: | |
585 | c-file-style: "gnu" | |
586 | End: | |
587 | */ |