1999-07-23 21:43:58 +00:00
|
|
|
|
/* readline.c --- line editing support for Guile */
|
|
|
|
|
|
|
2000-01-09 17:01:34 +00:00
|
|
|
|
/* Copyright (C) 1997,1999, 2000 Free Software Foundation, Inc.
|
1999-07-23 21:43:58 +00:00
|
|
|
|
*
|
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
|
|
* any later version.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
*
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
|
* along with this software; see the file COPYING. If not, write to
|
1999-08-06 07:26:07 +00:00
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
|
|
|
|
* Boston, MA 02111-1307 USA
|
1999-07-23 21:43:58 +00:00
|
|
|
|
*
|
|
|
|
|
|
*/
|
1999-12-13 03:57:29 +00:00
|
|
|
|
|
|
|
|
|
|
/* Software engineering face-lift by Greg J. Badros, 11-Dec-1999,
|
|
|
|
|
|
gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */
|
|
|
|
|
|
|
1999-07-23 21:43:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
1999-07-24 11:40:11 +00:00
|
|
|
|
#include "libguile/_scm.h"
|
1999-07-23 21:43:58 +00:00
|
|
|
|
#if defined (HAVE_RL_GETC_FUNCTION)
|
2000-05-01 22:12:43 +00:00
|
|
|
|
#include "libguile.h"
|
1999-07-24 11:40:11 +00:00
|
|
|
|
#include "libguile/gh.h"
|
|
|
|
|
|
#include "libguile/iselect.h"
|
|
|
|
|
|
|
1999-07-23 21:43:58 +00:00
|
|
|
|
#include <readline/readline.h>
|
|
|
|
|
|
#include <readline/history.h>
|
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
2000-03-09 16:00:42 +00:00
|
|
|
|
#include "libguile/validate.h"
|
2000-04-21 14:16:44 +00:00
|
|
|
|
#include "guile-readline/readline.h"
|
1999-07-23 21:43:58 +00:00
|
|
|
|
|
|
|
|
|
|
scm_option scm_readline_opts[] = {
|
|
|
|
|
|
{ SCM_OPTION_BOOLEAN, "history-file", 1,
|
|
|
|
|
|
"Use history file." },
|
|
|
|
|
|
{ SCM_OPTION_INTEGER, "history-length", 200,
|
|
|
|
|
|
"History length." },
|
|
|
|
|
|
{ SCM_OPTION_INTEGER, "bounce-parens", 500,
|
|
|
|
|
|
"Time (ms) to show matching opening parenthesis (0 = off)."}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
extern void stifle_history (int max);
|
|
|
|
|
|
|
2000-01-05 19:06:35 +00:00
|
|
|
|
SCM_DEFINE (scm_readline_options, "readline-options-interface", 0, 1, 0,
|
1999-12-13 03:57:29 +00:00
|
|
|
|
(SCM setting),
|
|
|
|
|
|
"")
|
|
|
|
|
|
#define FUNC_NAME s_scm_readline_options
|
1999-07-23 21:43:58 +00:00
|
|
|
|
{
|
|
|
|
|
|
SCM ans = scm_options (setting,
|
|
|
|
|
|
scm_readline_opts,
|
|
|
|
|
|
SCM_N_READLINE_OPTIONS,
|
1999-12-13 03:57:29 +00:00
|
|
|
|
FUNC_NAME);
|
1999-07-23 21:43:58 +00:00
|
|
|
|
stifle_history (SCM_HISTORY_LENGTH);
|
|
|
|
|
|
return ans;
|
|
|
|
|
|
}
|
1999-12-13 03:57:29 +00:00
|
|
|
|
#undef FUNC_NAME
|
1999-07-23 21:43:58 +00:00
|
|
|
|
|
|
|
|
|
|
#ifndef HAVE_STRDUP
|
|
|
|
|
|
static char *
|
|
|
|
|
|
strdup (char *s)
|
|
|
|
|
|
{
|
|
|
|
|
|
int len = strlen (s);
|
|
|
|
|
|
char *new = malloc (len + 1);
|
|
|
|
|
|
strcpy (new, s);
|
|
|
|
|
|
return new;
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif /* HAVE_STRDUP */
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef HAVE_RL_CLEANUP_AFTER_SIGNAL
|
|
|
|
|
|
|
|
|
|
|
|
/* These are readline functions added in release 2.3. They will work
|
|
|
|
|
|
* together with readline-2.1 and 2.2. (The readline interface is
|
|
|
|
|
|
* disabled for earlier releases.)
|
|
|
|
|
|
* They are declared static; if we want to use them elsewhere, then
|
|
|
|
|
|
* we need external declarations for them, but at the moment, I don't
|
|
|
|
|
|
* think anything else in Guile ought to use these.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
extern void _rl_clean_up_for_exit ();
|
|
|
|
|
|
extern void _rl_kill_kbd_macro ();
|
|
|
|
|
|
extern int _rl_init_argument ();
|
|
|
|
|
|
|
1999-08-29 18:02:19 +00:00
|
|
|
|
void
|
1999-07-23 21:43:58 +00:00
|
|
|
|
rl_cleanup_after_signal ()
|
|
|
|
|
|
{
|
|
|
|
|
|
#ifdef HAVE_RL_CLEAR_SIGNALS
|
|
|
|
|
|
_rl_clean_up_for_exit ();
|
|
|
|
|
|
#endif
|
|
|
|
|
|
(*rl_deprep_term_function) ();
|
|
|
|
|
|
#ifdef HAVE_RL_CLEAR_SIGNALS
|
|
|
|
|
|
rl_clear_signals ();
|
|
|
|
|
|
#endif
|
|
|
|
|
|
rl_pending_input = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
1999-08-29 18:02:19 +00:00
|
|
|
|
void
|
1999-07-23 21:43:58 +00:00
|
|
|
|
rl_free_line_state ()
|
|
|
|
|
|
{
|
|
|
|
|
|
register HIST_ENTRY *entry;
|
|
|
|
|
|
|
|
|
|
|
|
free_undo_list ();
|
|
|
|
|
|
|
|
|
|
|
|
entry = current_history ();
|
|
|
|
|
|
if (entry)
|
|
|
|
|
|
entry->data = (char *)NULL;
|
|
|
|
|
|
|
|
|
|
|
|
_rl_kill_kbd_macro ();
|
|
|
|
|
|
rl_clear_message ();
|
|
|
|
|
|
_rl_init_argument ();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* !HAVE_RL_CLEANUP_AFTER_SIGNAL */
|
|
|
|
|
|
|
|
|
|
|
|
static int promptp;
|
|
|
|
|
|
static SCM input_port;
|
|
|
|
|
|
static SCM before_read;
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
|
current_input_getc (FILE *in)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (promptp && SCM_NIMP (before_read))
|
|
|
|
|
|
{
|
|
|
|
|
|
scm_apply (before_read, SCM_EOL, SCM_EOL);
|
|
|
|
|
|
promptp = 0;
|
|
|
|
|
|
}
|
2000-03-12 16:02:46 +00:00
|
|
|
|
return scm_getc (input_port);
|
1999-07-23 21:43:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
redisplay ()
|
|
|
|
|
|
{
|
|
|
|
|
|
rl_redisplay ();
|
|
|
|
|
|
/* promptp = 1; */
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int in_readline = 0;
|
|
|
|
|
|
#ifdef USE_THREADS
|
|
|
|
|
|
static scm_mutex_t reentry_barrier_mutex;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
1999-12-13 03:57:29 +00:00
|
|
|
|
static SCM internal_readline (SCM text);
|
|
|
|
|
|
static SCM handle_error (void *data, SCM tag, SCM args);
|
|
|
|
|
|
static void reentry_barrier ();
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-01-05 19:06:35 +00:00
|
|
|
|
SCM_DEFINE (scm_readline, "%readline", 0, 4, 0,
|
1999-12-13 03:57:29 +00:00
|
|
|
|
(SCM text, SCM inp, SCM outp, SCM read_hook),
|
|
|
|
|
|
"")
|
|
|
|
|
|
#define FUNC_NAME s_scm_readline
|
|
|
|
|
|
{
|
|
|
|
|
|
SCM ans;
|
|
|
|
|
|
|
|
|
|
|
|
reentry_barrier ();
|
|
|
|
|
|
|
|
|
|
|
|
before_read = SCM_BOOL_F;
|
|
|
|
|
|
|
|
|
|
|
|
if (!SCM_UNBNDP (text))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!(SCM_NIMP (text) && SCM_STRINGP (text)))
|
|
|
|
|
|
{
|
|
|
|
|
|
--in_readline;
|
|
|
|
|
|
scm_wrong_type_arg (s_scm_readline, SCM_ARG1, text);
|
|
|
|
|
|
}
|
|
|
|
|
|
SCM_COERCE_SUBSTR (text);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!((SCM_UNBNDP (inp) && SCM_NIMP (scm_cur_inp) && SCM_OPINFPORTP (inp))
|
|
|
|
|
|
|| SCM_NIMP (inp) && SCM_OPINFPORTP (inp)))
|
|
|
|
|
|
{
|
|
|
|
|
|
--in_readline;
|
|
|
|
|
|
scm_misc_error (s_scm_readline,
|
|
|
|
|
|
"Input port is not open or not a file port",
|
|
|
|
|
|
SCM_EOL);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!((SCM_UNBNDP (outp) && SCM_NIMP (scm_cur_outp) && SCM_OPINFPORTP (outp))
|
|
|
|
|
|
|| (SCM_NIMP (outp) && SCM_OPOUTFPORTP (outp))))
|
|
|
|
|
|
{
|
|
|
|
|
|
--in_readline;
|
|
|
|
|
|
scm_misc_error (s_scm_readline,
|
|
|
|
|
|
"Output port is not open or not a file port",
|
|
|
|
|
|
SCM_EOL);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!(SCM_UNBNDP (read_hook) || SCM_FALSEP (read_hook)))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!(SCM_NFALSEP (scm_thunk_p (read_hook))))
|
|
|
|
|
|
{
|
|
|
|
|
|
--in_readline;
|
|
|
|
|
|
scm_wrong_type_arg (s_scm_readline, SCM_ARG4, read_hook);
|
|
|
|
|
|
}
|
|
|
|
|
|
before_read = read_hook;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
scm_readline_init_ports (inp, outp);
|
|
|
|
|
|
|
|
|
|
|
|
ans = scm_internal_catch (SCM_BOOL_T,
|
|
|
|
|
|
(scm_catch_body_t) internal_readline,
|
2000-04-04 10:46:08 +00:00
|
|
|
|
(void *) SCM_UNPACK (text),
|
1999-12-13 03:57:29 +00:00
|
|
|
|
handle_error, 0);
|
|
|
|
|
|
|
|
|
|
|
|
fclose (rl_instream);
|
|
|
|
|
|
fclose (rl_outstream);
|
|
|
|
|
|
|
|
|
|
|
|
--in_readline;
|
|
|
|
|
|
return ans;
|
|
|
|
|
|
}
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-07-23 21:43:58 +00:00
|
|
|
|
static void
|
|
|
|
|
|
reentry_barrier ()
|
|
|
|
|
|
{
|
|
|
|
|
|
int reentryp = 0;
|
|
|
|
|
|
#ifdef USE_THREADS
|
|
|
|
|
|
/* We should rather use scm_mutex_try_lock when it becomes available */
|
|
|
|
|
|
scm_mutex_lock (&reentry_barrier_mutex);
|
|
|
|
|
|
#endif
|
|
|
|
|
|
if (in_readline)
|
|
|
|
|
|
reentryp = 1;
|
|
|
|
|
|
else
|
|
|
|
|
|
++in_readline;
|
|
|
|
|
|
#ifdef USE_THREADS
|
|
|
|
|
|
scm_mutex_unlock (&reentry_barrier_mutex);
|
|
|
|
|
|
#endif
|
|
|
|
|
|
if (reentryp)
|
1999-12-13 03:57:29 +00:00
|
|
|
|
scm_misc_error (s_scm_readline, "readline is not reentrant", SCM_EOL);
|
1999-07-23 21:43:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static SCM
|
|
|
|
|
|
handle_error (void *data, SCM tag, SCM args)
|
|
|
|
|
|
{
|
|
|
|
|
|
rl_free_line_state ();
|
|
|
|
|
|
rl_cleanup_after_signal ();
|
1999-07-24 11:40:11 +00:00
|
|
|
|
fputc ('\n', rl_outstream); /* We don't want next output on this line */
|
1999-07-23 21:43:58 +00:00
|
|
|
|
fclose (rl_instream);
|
|
|
|
|
|
fclose (rl_outstream);
|
|
|
|
|
|
--in_readline;
|
|
|
|
|
|
scm_handle_by_throw (data, tag, args);
|
|
|
|
|
|
return SCM_UNSPECIFIED; /* never reached */
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static SCM
|
|
|
|
|
|
internal_readline (SCM text)
|
|
|
|
|
|
{
|
|
|
|
|
|
SCM ret;
|
|
|
|
|
|
char *s;
|
|
|
|
|
|
char *prompt = SCM_UNBNDP (text) ? "" : SCM_CHARS (text);
|
|
|
|
|
|
|
|
|
|
|
|
promptp = 1;
|
|
|
|
|
|
s = readline (prompt);
|
|
|
|
|
|
if (s)
|
|
|
|
|
|
ret = scm_makfrom0str (s);
|
|
|
|
|
|
else
|
|
|
|
|
|
ret = SCM_EOF_VAL;
|
|
|
|
|
|
|
|
|
|
|
|
free (s);
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static FILE *
|
|
|
|
|
|
stream_from_fport (SCM port, char *mode, const char *subr)
|
|
|
|
|
|
{
|
|
|
|
|
|
int fd;
|
|
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
|
|
|
|
fd = dup (((struct scm_fport *) SCM_STREAM (port))->fdes);
|
|
|
|
|
|
if (fd == -1)
|
|
|
|
|
|
{
|
|
|
|
|
|
--in_readline;
|
|
|
|
|
|
scm_syserror (subr);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
f = fdopen (fd, mode);
|
|
|
|
|
|
if (f == NULL)
|
|
|
|
|
|
{
|
|
|
|
|
|
--in_readline;
|
|
|
|
|
|
scm_syserror (subr);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return f;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
1999-08-29 18:02:19 +00:00
|
|
|
|
void
|
|
|
|
|
|
scm_readline_init_ports (SCM inp, SCM outp)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (SCM_UNBNDP (inp))
|
|
|
|
|
|
inp = scm_cur_inp;
|
|
|
|
|
|
|
|
|
|
|
|
if (SCM_UNBNDP (outp))
|
|
|
|
|
|
outp = scm_cur_outp;
|
|
|
|
|
|
|
|
|
|
|
|
if (!(SCM_NIMP (inp) && SCM_OPINFPORTP (inp))) {
|
|
|
|
|
|
scm_misc_error (0,
|
|
|
|
|
|
"Input port is not open or not a file port",
|
|
|
|
|
|
SCM_EOL);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!(SCM_NIMP (outp) && SCM_OPOUTFPORTP (outp))) {
|
|
|
|
|
|
scm_misc_error (0,
|
|
|
|
|
|
"Output port is not open or not a file port",
|
|
|
|
|
|
SCM_EOL);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
input_port = inp;
|
1999-12-13 03:57:29 +00:00
|
|
|
|
rl_instream = stream_from_fport (inp, "r", s_scm_readline);
|
|
|
|
|
|
rl_outstream = stream_from_fport (outp, "w", s_scm_readline);
|
1999-08-29 18:02:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
1999-07-23 21:43:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
2000-01-05 19:06:35 +00:00
|
|
|
|
SCM_DEFINE (scm_add_history, "add-history", 1, 0, 0,
|
1999-12-13 03:57:29 +00:00
|
|
|
|
(SCM text),
|
|
|
|
|
|
"")
|
|
|
|
|
|
#define FUNC_NAME s_scm_add_history
|
1999-07-23 21:43:58 +00:00
|
|
|
|
{
|
|
|
|
|
|
char* s;
|
2000-01-05 19:20:06 +00:00
|
|
|
|
SCM_VALIDATE_STRING (1,text);
|
1999-07-23 21:43:58 +00:00
|
|
|
|
SCM_COERCE_SUBSTR (text);
|
|
|
|
|
|
|
|
|
|
|
|
s = SCM_CHARS (text);
|
|
|
|
|
|
add_history (strdup (s));
|
|
|
|
|
|
|
|
|
|
|
|
return SCM_UNSPECIFIED;
|
|
|
|
|
|
}
|
1999-12-13 03:57:29 +00:00
|
|
|
|
#undef FUNC_NAME
|
1999-07-23 21:43:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
2000-01-05 19:06:35 +00:00
|
|
|
|
SCM_DEFINE (scm_read_history, "read-history", 1, 0, 0,
|
1999-12-13 03:57:29 +00:00
|
|
|
|
(SCM file),
|
|
|
|
|
|
"")
|
|
|
|
|
|
#define FUNC_NAME s_scm_read_history
|
1999-07-23 21:43:58 +00:00
|
|
|
|
{
|
2000-01-05 19:20:06 +00:00
|
|
|
|
SCM_VALIDATE_STRING (1,file);
|
1999-12-13 03:57:29 +00:00
|
|
|
|
return SCM_NEGATE_BOOL(read_history (SCM_ROCHARS (file)));
|
1999-07-23 21:43:58 +00:00
|
|
|
|
}
|
1999-12-13 03:57:29 +00:00
|
|
|
|
#undef FUNC_NAME
|
1999-07-23 21:43:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
2000-01-05 19:06:35 +00:00
|
|
|
|
SCM_DEFINE (scm_write_history, "write-history", 1, 0, 0,
|
1999-12-13 03:57:29 +00:00
|
|
|
|
(SCM file),
|
|
|
|
|
|
"")
|
|
|
|
|
|
#define FUNC_NAME s_scm_write_history
|
1999-07-23 21:43:58 +00:00
|
|
|
|
{
|
2000-01-05 19:20:06 +00:00
|
|
|
|
SCM_VALIDATE_STRING (1,file);
|
1999-12-13 03:57:29 +00:00
|
|
|
|
return SCM_NEGATE_BOOL(write_history (SCM_ROCHARS (file)));
|
1999-07-23 21:43:58 +00:00
|
|
|
|
}
|
1999-12-13 03:57:29 +00:00
|
|
|
|
#undef FUNC_NAME
|
1999-07-23 21:43:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
2000-01-05 19:06:35 +00:00
|
|
|
|
SCM_DEFINE (scm_filename_completion_function, "filename-completion-function", 2, 0, 0,
|
1999-12-13 03:57:29 +00:00
|
|
|
|
(SCM text, SCM continuep),
|
|
|
|
|
|
"")
|
|
|
|
|
|
#define FUNC_NAME s_scm_filename_completion_function
|
1999-07-23 21:43:58 +00:00
|
|
|
|
{
|
|
|
|
|
|
char *s;
|
|
|
|
|
|
SCM ans;
|
2000-01-05 19:20:06 +00:00
|
|
|
|
SCM_VALIDATE_STRING (1,text);
|
1999-07-23 21:43:58 +00:00
|
|
|
|
SCM_COERCE_SUBSTR (text);
|
|
|
|
|
|
s = filename_completion_function (SCM_CHARS (text), SCM_NFALSEP (continuep));
|
|
|
|
|
|
ans = scm_makfrom0str (s);
|
|
|
|
|
|
free (s);
|
|
|
|
|
|
return ans;
|
|
|
|
|
|
}
|
1999-12-13 03:57:29 +00:00
|
|
|
|
#undef FUNC_NAME
|
1999-07-23 21:43:58 +00:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* The following has been modified from code contributed by
|
|
|
|
|
|
* Andrew Archibald <aarchiba@undergrad.math.uwaterloo.ca>
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
SCM scm_readline_completion_function_var;
|
|
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
|
|
completion_function (char *text, int continuep)
|
|
|
|
|
|
{
|
|
|
|
|
|
SCM compfunc = SCM_CDR (scm_readline_completion_function_var);
|
|
|
|
|
|
SCM res;
|
|
|
|
|
|
|
|
|
|
|
|
if (SCM_FALSEP (compfunc))
|
|
|
|
|
|
return NULL; /* #f => completion disabled */
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
SCM t = scm_makfrom0str (text);
|
|
|
|
|
|
SCM c = continuep ? SCM_BOOL_T : SCM_BOOL_F;
|
|
|
|
|
|
res = scm_apply (compfunc, SCM_LIST2 (t, c), SCM_EOL);
|
|
|
|
|
|
|
|
|
|
|
|
if (SCM_FALSEP (res))
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
|
|
if (!(SCM_NIMP (res) && SCM_STRINGP (res)))
|
1999-12-13 03:57:29 +00:00
|
|
|
|
scm_misc_error (s_scm_readline,
|
1999-07-23 21:43:58 +00:00
|
|
|
|
"Completion function returned bogus value: %S",
|
|
|
|
|
|
SCM_LIST1 (res));
|
|
|
|
|
|
SCM_COERCE_SUBSTR (res);
|
|
|
|
|
|
return strdup (SCM_CHARS (res));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*Bouncing parenthesis (reimplemented by GH, 11/23/98, since readline is strict gpl)*/
|
|
|
|
|
|
|
2000-01-09 17:01:34 +00:00
|
|
|
|
static int match_paren (int x, int k);
|
|
|
|
|
|
static int find_matching_paren (int k);
|
|
|
|
|
|
static void init_bouncing_parens ();
|
1999-07-23 21:43:58 +00:00
|
|
|
|
|
|
|
|
|
|
static void
|
2000-01-09 17:01:34 +00:00
|
|
|
|
init_bouncing_parens ()
|
1999-07-23 21:43:58 +00:00
|
|
|
|
{
|
2000-01-09 17:01:34 +00:00
|
|
|
|
if (strncmp (rl_get_keymap_name (rl_get_keymap ()), "vi", 2))
|
|
|
|
|
|
{
|
|
|
|
|
|
rl_bind_key (')', match_paren);
|
|
|
|
|
|
rl_bind_key (']', match_paren);
|
|
|
|
|
|
rl_bind_key ('}', match_paren);
|
|
|
|
|
|
}
|
1999-07-23 21:43:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
|
find_matching_paren(int k)
|
|
|
|
|
|
{
|
|
|
|
|
|
register int i;
|
|
|
|
|
|
register char c = 0;
|
|
|
|
|
|
int end_parens_found = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/* Choose the corresponding opening bracket. */
|
|
|
|
|
|
if (k == ')') c = '(';
|
|
|
|
|
|
else if (k == ']') c = '[';
|
|
|
|
|
|
else if (k == '}') c = '{';
|
|
|
|
|
|
|
|
|
|
|
|
for (i=rl_point-2; i>=0; i--)
|
|
|
|
|
|
{
|
|
|
|
|
|
/* Is the current character part of a character literal? */
|
|
|
|
|
|
if (i - 2 >= 0
|
|
|
|
|
|
&& rl_line_buffer[i - 1] == '\\'
|
|
|
|
|
|
&& rl_line_buffer[i - 2] == '#')
|
|
|
|
|
|
;
|
|
|
|
|
|
else if (rl_line_buffer[i] == k)
|
|
|
|
|
|
end_parens_found++;
|
|
|
|
|
|
else if (rl_line_buffer[i] == '"')
|
|
|
|
|
|
{
|
|
|
|
|
|
/* Skip over a string literal. */
|
|
|
|
|
|
for (i--; i >= 0; i--)
|
|
|
|
|
|
if (rl_line_buffer[i] == '"'
|
|
|
|
|
|
&& ! (i - 1 >= 0
|
|
|
|
|
|
&& rl_line_buffer[i - 1] == '\\'))
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (rl_line_buffer[i] == c)
|
|
|
|
|
|
{
|
2000-01-09 17:01:34 +00:00
|
|
|
|
if (end_parens_found==0)
|
|
|
|
|
|
return i;
|
1999-07-23 21:43:58 +00:00
|
|
|
|
else --end_parens_found;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2000-01-09 17:01:34 +00:00
|
|
|
|
static int
|
|
|
|
|
|
match_paren (int x, int k)
|
1999-07-23 21:43:58 +00:00
|
|
|
|
{
|
2000-03-12 16:02:46 +00:00
|
|
|
|
int tmp, fno;
|
2000-03-08 18:43:47 +00:00
|
|
|
|
SELECT_TYPE readset;
|
1999-07-23 21:43:58 +00:00
|
|
|
|
struct timeval timeout;
|
|
|
|
|
|
|
2000-01-09 17:01:34 +00:00
|
|
|
|
rl_insert (x, k);
|
1999-07-23 21:43:58 +00:00
|
|
|
|
if (!SCM_READLINE_BOUNCE_PARENS)
|
2000-01-09 17:01:34 +00:00
|
|
|
|
return 0;
|
1999-07-23 21:43:58 +00:00
|
|
|
|
|
|
|
|
|
|
/* Did we just insert a quoted paren? If so, then don't bounce. */
|
|
|
|
|
|
if (rl_point - 1 >= 1
|
|
|
|
|
|
&& rl_line_buffer[rl_point - 2] == '\\')
|
2000-01-09 17:01:34 +00:00
|
|
|
|
return 0;
|
1999-07-23 21:43:58 +00:00
|
|
|
|
|
|
|
|
|
|
tmp = 1000 * SCM_READLINE_BOUNCE_PARENS;
|
|
|
|
|
|
timeout.tv_sec = tmp / 1000000;
|
|
|
|
|
|
timeout.tv_usec = tmp % 1000000;
|
2000-01-09 17:01:34 +00:00
|
|
|
|
FD_ZERO (&readset);
|
2000-03-12 16:02:46 +00:00
|
|
|
|
fno = fileno (rl_instream);
|
|
|
|
|
|
FD_SET (fno, &readset);
|
1999-07-23 21:43:58 +00:00
|
|
|
|
|
2000-01-09 17:01:34 +00:00
|
|
|
|
if (rl_point > 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
tmp = rl_point;
|
|
|
|
|
|
rl_point = find_matching_paren (k);
|
|
|
|
|
|
if (rl_point > -1)
|
|
|
|
|
|
{
|
|
|
|
|
|
rl_redisplay ();
|
2000-03-12 16:02:46 +00:00
|
|
|
|
scm_internal_select (fno + 1, &readset, NULL, NULL, &timeout);
|
2000-01-09 17:01:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
rl_point = tmp;
|
1999-07-23 21:43:58 +00:00
|
|
|
|
}
|
2000-01-09 17:01:34 +00:00
|
|
|
|
return 0;
|
1999-07-23 21:43:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
scm_init_readline ()
|
|
|
|
|
|
{
|
2000-04-21 14:16:44 +00:00
|
|
|
|
#include "guile-readline/readline.x"
|
1999-07-23 21:43:58 +00:00
|
|
|
|
scm_readline_completion_function_var
|
|
|
|
|
|
= scm_sysintern ("*readline-completion-function*", SCM_BOOL_F);
|
|
|
|
|
|
rl_getc_function = current_input_getc;
|
|
|
|
|
|
rl_redisplay_function = redisplay;
|
|
|
|
|
|
rl_completion_entry_function = (Function*) completion_function;
|
|
|
|
|
|
rl_basic_word_break_characters = "\t\n\"'`;()";
|
* configure.in: check for hstrerror.
* socket.c (scm_htons, scm_ntohs, scm_htonl, scm_ntohl): new
functions for network data conversion.
* numbers.c (scm_num2long, scm_num2longlong):
throw out-of-range instead of wrong-type-arg if appropriate.
(scm_iint2str): handle -2^31 correctly.
(scm_num2long): handle -2^31 bignum correctly.
(scm_num2long_long): rewrite the bigdig case: basically copied
from scm_num2long.
numbers.h: (SCM_BITSPERLONGLONG): deleted.
* unif.c (rapr1): use sprintf instead of intprint for unsigned
longs: intprint can't cope with large values.
* numbers.c (scm_num2ulong): check more consistently that the
input is not negative. if it is, throw out-of-range instead of
wrong-type-arg.
* ramap.c (scm_array_fill_int): don't limit fill to INUM for
uvect, ivect or llvect.
Check that fill doesn't overflow short uniform array.
* __scm.h: add another long to the definition of long_long and
ulong_long.
* unif.c (scm_raprin1): use 'l' instead of "long_long" in the
print representation of llvect. read can't handle more than
one character.
(scm_dimensions_to_uniform_array): make "fill" an optional argument
instead of a rest argument.
* tags.h (scm_tc7_llvect): wasn't defined anywhere, so use the free
tag 29 for now.
* __scm.h: don't mention LONGLONGS.
* unif.c, numbers.c, eq.c, gc.c, print.c, eval.c, ramap.c:
replace LONGLONGS with HAVE_LONG_LONGS as set by configure.
* net_db.c (scm_inet_aton): throw errors using the misc-error key
instead of system-error. inet_aton doesn't set errno.
system-error isn't right in gethost either, since it's throwing
the value of h_errno instead of errno. so:
(scm_host_not_found_key, scm_try_again_key,
scm_no_recovery_key, scm_no_data_key): new error keys.
(scm_resolv_error): new procedure, use the new keys.
(scm_gethost): call scm_resolv_error not scm_syserror_msg.
* error.c: (various): use scm_cons instead of scm_listify
to build short lists.
* boot-9.scm (read-hash-extend to set up arrays): add 'l' for
long_long uniform vectors.
* networking.scm (sethostent, setnetent, setprotoent, setservent):
take an optional argument STAYOPEN. default is #f.
* readline.c (scm_init_readline): set rl_readline_name to Guile,
to allow conditionals in .inputrc.
1999-11-18 22:36:28 +00:00
|
|
|
|
rl_readline_name = "Guile";
|
|
|
|
|
|
|
1999-07-23 21:43:58 +00:00
|
|
|
|
#ifdef USE_THREADS
|
2000-03-12 14:26:59 +00:00
|
|
|
|
scm_mutex_init (&reentry_barrier_mutex);
|
1999-07-23 21:43:58 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
scm_init_opts (scm_readline_options,
|
|
|
|
|
|
scm_readline_opts,
|
|
|
|
|
|
SCM_N_READLINE_OPTIONS);
|
|
|
|
|
|
init_bouncing_parens();
|
|
|
|
|
|
scm_add_feature ("readline");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
2000-03-19 19:01:16 +00:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
Local Variables:
|
|
|
|
|
|
c-file-style: "gnu"
|
|
|
|
|
|
End:
|
|
|
|
|
|
*/
|