1 /* readline.c --- line editing support for Guile */
3 /* Copyright (C) 1997 Free Software Foundation, Inc.
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)
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.
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
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19 * As a special exception, the Free Software Foundation gives permission
20 * for additional uses of the text contained in its release of GUILE.
22 * The exception is that, if you link the GUILE library with other files
23 * to produce an executable, this does not by itself cause the
24 * resulting executable to be covered by the GNU General Public License.
25 * Your use of that executable is in no way restricted on account of
26 * linking the GUILE library code into it.
28 * This exception does not however invalidate any other reasons why
29 * the executable file might be covered by the GNU General Public License.
31 * This exception applies only to the code released by the
32 * Free Software Foundation under the name GUILE. If you copy
33 * code from other Free Software Foundation releases into a copy of
34 * GUILE, as the General Public License permits, the exception does
35 * not apply to the code that you add in this way. To avoid misleading
36 * anyone as to the status of such modified files, you must delete
37 * this exception notice from them.
39 * If you write modifications of your own for GUILE, it is your choice
40 * whether to permit this exception to apply to your modifications.
41 * If you do not wish that, delete this exception notice.
46 #ifdef HAVE_LIBREADLINE
50 #include <readline/readline.h>
51 #include <readline/history.h>
56 return scm_getc (scm_cur_inp
);
59 SCM_PROC (s_readline
, "readline", 0, 1, 0, scm_readline
);
62 scm_readline (SCM text
)
68 if (! SCM_UNBNDP (text
))
70 SCM_ASSERT ((SCM_NIMP(text
) && SCM_STRINGP(text
)), text
, SCM_ARG1
,
72 SCM_COERCE_SUBSTR (text
);
75 prompt
= SCM_UNBNDP (text
) ? "" : SCM_CHARS (text
);
77 s
= readline (prompt
);
79 ret
= scm_makfrom0str (s
);
88 SCM_PROC (s_add_history
, "add-history", 1, 0, 0, scm_add_history
);
91 scm_add_history (SCM text
)
94 SCM_ASSERT ((SCM_NIMP(text
) && SCM_STRINGP(text
)), text
, SCM_ARG1
,
96 SCM_COERCE_SUBSTR (text
);
100 add_history (strdup (s
));
103 return SCM_UNSPECIFIED
;
106 static SCM subr_filename_completion_function
;
107 static char s_filename_completion_function
[] = "filename-completion-function";
110 scm_filename_completion_function (SCM text
, SCM continuep
)
114 SCM_ASSERT (SCM_NIMP (text
) && SCM_STRINGP (text
),
117 s_filename_completion_function
);
118 SCM_COERCE_SUBSTR (text
);
119 s
= filename_completion_function (SCM_CHARS (text
), SCM_NFALSEP (continuep
));
120 ans
= scm_makfrom0str (s
);
126 * The following has been modified from code contributed by
127 * Andrew Archibald <aarchiba@undergrad.math.uwaterloo.ca>
130 SCM scm_readline_completion_function_var
;
135 return scm_apply (SCM_CAR (a
), SCM_CDR (a
), SCM_EOL
);
139 completion_function (char *text
, int continuep
)
142 SCM compfunc
= SCM_CDR (scm_readline_completion_function_var
);
145 if (SCM_FALSEP (compfunc
))
146 return NULL
; /* #f => completion disabled */
149 SCM t
= scm_makfrom0str (text
);
150 SCM c
= continuep
? SCM_BOOL_T
: SCM_BOOL_F
;
151 res
= scm_internal_cwdr ((scm_catch_body_t
) apply
,
152 (void *) SCM_LIST3 (compfunc
, t
, c
),
157 if (SCM_FALSEP (res
))
160 if (!(SCM_NIMP (res
) && SCM_STRINGP (res
)))
161 scm_misc_error (s_readline
,
162 "Completion function returned bogus value: %S",
164 SCM_COERCE_SUBSTR (res
);
165 return strdup (SCM_CHARS (res
));
173 #include "readline.x"
174 subr_filename_completion_function
175 = scm_make_subr (s_filename_completion_function
,
177 scm_filename_completion_function
);
178 scm_readline_completion_function_var
179 = scm_sysintern ("*readline-completion-function*", SCM_BOOL_F
);
180 rl_getc_function
= current_input_getc
;
181 rl_completion_entry_function
= (Function
*) completion_function
;
182 scm_add_feature ("readline");