This file is bind.def, from which is created bind.c.
It implements the builtin "bind" in Bash.
-Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
+Copyright (C) 1987-2002 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
$BUILTIN bind
$DEPENDS_ON READLINE
$FUNCTION bind_builtin
-$SHORT_DOC bind [-lpvsPVS] [-m keymap] [-f filename] [-q name] [-u name] [-r keyseq] [-x keyseq:shell-command] [keyseq:readline-function]
-Bind a key sequence to a Readline function, or to a macro. The
-syntax is equivalent to that found in ~/.inputrc, but must be
-passed as a single argument: bind '"\C-x\C-r": re-read-init-file'.
-Arguments we accept:
+$SHORT_DOC bind [-lpvsPVS] [-m keymap] [-f filename] [-q name] [-u name] [-r keyseq] [-x keyseq:shell-command] [keyseq:readline-function or readline-command]
+Bind a key sequence to a Readline function or a macro, or set
+a Readline variable. The non-option argument syntax is equivalent
+to that found in ~/.inputrc, but must be passed as a single argument:
+bind '"\C-x\C-r": re-read-init-file'.
+bind accepts the following options:
-m keymap Use `keymap' as the keymap for the duration of this
command. Acceptable keymap names are emacs,
emacs-standard, emacs-meta, emacs-ctlx, vi, vi-move,
-p List functions and bindings in a form that can be
reused as input.
-r keyseq Remove the binding for KEYSEQ.
- -x keyseq:shell-command Cause SHELL-COMMAND to be executed when KEYSEQ
- is entered.
+ -x keyseq:shell-command Cause SHELL-COMMAND to be executed when
+ KEYSEQ is entered.
-f filename Read key bindings from FILENAME.
-q function-name Query about which keys invoke the named function.
-u function-name Unbind all keys which are bound to the named function.
-v List variable names and values in a form that can
be reused as input.
-S List key sequences that invoke macros and their values
- -s List key sequences that invoke macros and their values in
- a form that can be reused as input.
+ -s List key sequences that invoke macros and their values
+ in a form that can be reused as input.
$END
#if defined (READLINE)
#include "bashgetopt.h"
#include "common.h"
-static int query_bindings ();
-static int unbind_command ();
+static int query_bindings __P((char *));
+static int unbind_command __P((char *));
extern int no_line_editing;
WORD_LIST *list;
{
int return_code;
- FILE *old_rl_outstream;
Keymap kmap, saved_keymap;
int flags, opt;
char *initfile, *map_name, *fun_name, *unbind_name, *remove_seq, *cmd_seq;
if (!bash_readline_initialized)
initialize_readline ();
- /* Cannot use unwind_protect_pointer () on "FILE *", it is only
- guaranteed to work for strings. */
- /* XXX -- see if we can use unwind_protect here */
- old_rl_outstream = rl_outstream;
+ begin_unwind_frame ("bind_builtin");
+ unwind_protect_var (rl_outstream);
+
rl_outstream = stdout;
reset_internal_getopt ();
{
kmap = rl_get_keymap_by_name (map_name);
if (!kmap)
- {
+ {
builtin_error ("`%s': invalid keymap name", map_name);
BIND_RETURN (EXECUTION_FAILURE);
- }
+ }
}
if (kmap)
{
if (rl_read_init_file (initfile) != 0)
{
- builtin_error ("cannot read %s: %s", initfile, strerror (errno));
+ builtin_error ("%s: cannot read: %s", initfile, strerror (errno));
BIND_RETURN (EXECUTION_FAILURE);
}
}
if ((flags & RFLAG) && remove_seq)
{
- if (rl_set_key (remove_seq, (Function *)NULL, rl_get_keymap ()) != 0)
+ if (rl_set_key (remove_seq, (rl_command_func_t *)NULL, rl_get_keymap ()) != 0)
{
- builtin_error ("cannot unbind %s", remove_seq);
+ builtin_error ("`%s': cannot unbind", remove_seq);
BIND_RETURN (EXECUTION_FAILURE);
}
}
if (saved_keymap)
rl_set_keymap (saved_keymap);
- rl_outstream = old_rl_outstream;
+ run_unwind_frame ("bind_builtin");
+
return (return_code);
}
query_bindings (name)
char *name;
{
- Function *function;
+ rl_command_func_t *function;
char **keyseqs;
int j;
function = rl_named_function (name);
if (function == 0)
{
- builtin_error ("unknown function name `%s'", name);
+ builtin_error ("`%s': unknown function name", name);
return EXECUTION_FAILURE;
}
printf ("\"%s\"%s", keyseqs[j], keyseqs[j + 1] ? ", " : ".\n");
if (keyseqs[j])
printf ("...\n");
- free_array (keyseqs);
+ strvec_dispose (keyseqs);
return EXECUTION_SUCCESS;
}
unbind_command (name)
char *name;
{
- Function *function;
+ rl_command_func_t *function;
function = rl_named_function (name);
if (function == 0)
{
- builtin_error ("unknown function name `%s'", name);
+ builtin_error ("`%s': unknown function name", name);
return EXECUTION_FAILURE;
}