Upgrade to readline 2.0 from bash1.14.1

This commit is contained in:
Andrey A. Chernov 1994-05-13 15:48:04 +00:00
parent bc5acff790
commit 9e9eefe958
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=1492
33 changed files with 3569 additions and 2081 deletions

View file

@ -1,17 +1,18 @@
# $Id: Makefile,v 1.6 1994/05/11 15:49:41 ache Exp $ # $Id: Makefile,v 1.7 1994/05/11 16:30:27 ache Exp $
SHLIB_MAJOR=1 SHLIB_MAJOR=1
SHLIB_MINOR=0 SHLIB_MINOR=0
CFLAGS+= -I${.CURDIR} -I${.CURDIR}/readline -DVOID_SIGHANDLER \ CFLAGS+= -I${.CURDIR} -I${.CURDIR}/readline -DVOID_SIGHANDLER \
-DHAVE_UNISTD_H -DHAVE_STRING_H -DHAVE_STDLIB_H -DHAVE_VARARGS_H \ -DHAVE_UNISTD_H -DHAVE_STRING_H -DHAVE_STDLIB_H -DHAVE_VARARGS_H \
-DVISIBLE_STATS -DVI_MODE -DPAREN_MATCHING \ -DFreeBSD \
-Dstricmp=strcasecmp -Dstrnicmp=strncasecmp -Dstricmp=strcasecmp -Dstrnicmp=strncasecmp
LIB= readline LIB= readline
SRCS+= readline.c funmap.c keymaps.c vi_mode.c parens.c \ SRCS+= readline.c funmap.c keymaps.c vi_mode.c parens.c \
rltty.c complete.c bind.c isearch.c display.c signals.c \ rltty.c complete.c bind.c isearch.c display.c signals.c \
history.c search.c tilde.c xmalloc.c history.c search.c tilde.c xmalloc.c
HEADERS= history.h readline.h keymaps.h chardefs.h tilde.h
NOMAN= noman NOMAN= noman
beforeinstall: beforeinstall:
@ -22,6 +23,6 @@ beforeinstall:
fi fi
cd ${.CURDIR}/readline; \ cd ${.CURDIR}/readline; \
install -c -o ${BINOWN} -g ${BINGRP} -m 444 \ install -c -o ${BINOWN} -g ${BINGRP} -m 444 \
history.h readline.h keymaps.h chardefs.h ${DESTDIR}/usr/include/readline ${HEADERS} ${DESTDIR}/usr/include/readline
.include <bsd.lib.mk> .include <bsd.lib.mk>

View file

@ -0,0 +1,6 @@
This is the distribution of the Gnu Readline library. See the file
STANDALONE for a description of the #defines that can be passed via
the makefile to build readline on different systems.
The file rlconf.h contains defines that enable and disable certain
readline features.

View file

@ -11,11 +11,9 @@ Workaround for this implemented via TIOCGWINSZ/TIOCSWINSZ
with same winsize structure: it does nothing expect polling with same winsize structure: it does nothing expect polling
process from background. Look tcsh_hack.readme for details. process from background. Look tcsh_hack.readme for details.
Here is megred version with readline comes from gdb4.11
and with readline 2.0 comes from bash1.13.1.CWRU
If you want 8-bit clean version, put If you want 8-bit clean version, put
set convert-meta off set convert-meta off
set output-meta on
in your ~/.inputrc file in your ~/.inputrc file
ache@astral.msk.su ache@astral.msk.su

View file

@ -0,0 +1,32 @@
This is a description of C preprocessor defines that readline accepts.
Most are passed in from the parent `make'; e.g. from the bash source
directory.
NO_SYS_FILE <sys/file.h> is not present
HAVE_UNISTD_H <unistd.h> exists
HAVE_STDLIB_H <stdlib.h> exists
HAVE_GETPW_DECLS declarations for the getpw functions are in <pwd.h>
HAVE_VARARGS_H <varargs.h> exists and is usable
HAVE_STRING_H <string.h> exists
HAVE_ALLOCA_H <alloca.h> exists and is needed for alloca()
HAVE_ALLOCA alloca(3) or a define for it exists
PRAGMA_ALLOCA use of alloca() requires a #pragma, as in AIX 3.x
VOID_SIGHANDLER signal handlers are void functions
HAVE_DIRENT_H <dirent.h> exists and is usable
HAVE_SYS_PTEM_H <sys/ptem.h> exists
HAVE_SYS_PTE_H <sys/pte.h> exists
HAVE_SYS_STREAM_H <sys/stream.h> exists
System-specific options:
OSF1 A machine running OSF/1
BSD386 BSDI's BSD/386 version 1.0 or 1.1
NetBSD NetBSD
FreeBSD FreeBSD version 1.1
_386BSD Old FreeBSD or NetBSD or ancient Jolitz 386bsd
AIX AIX 3.x
USG Running a variant of System V
USGr3 Running System V.3
XENIX_22 Xenix 2.2
Linux Linux
CRAY running a recent version of Cray UNICOS

View file

@ -0,0 +1,41 @@
/* ansi_stdlib.h -- An ANSI Standard stdlib.h. */
/* A minimal stdlib.h containing extern declarations for those functions
that bash uses. */
/* Copyright (C) 1993 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash 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.
Bash 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 Bash; see the file COPYING. If not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#if !defined (_STDLIB_H_)
#define _STDLIB_H_ 1
/* String conversion functions. */
extern int atoi ();
extern long int atol ();
/* Memory allocation functions. */
extern char *malloc ();
extern char *realloc ();
extern void free ();
/* Other miscellaneous functions. */
extern void abort ();
extern void exit ();
extern char *getenv ();
extern void qsort ();
#endif /* _STDLIB_H */

View file

@ -57,19 +57,22 @@ extern int errno;
extern char *strchr (), *strrchr (); extern char *strchr (), *strrchr ();
#endif /* !strchr && !__STDC__ */ #endif /* !strchr && !__STDC__ */
extern char *tilde_expand ();
extern int _rl_horizontal_scroll_mode; extern int _rl_horizontal_scroll_mode;
extern int _rl_mark_modified_lines; extern int _rl_mark_modified_lines;
extern int _rl_prefer_visible_bell; extern int _rl_bell_preference;
extern int _rl_meta_flag; extern int _rl_meta_flag;
extern int rl_blink_matching_paren; extern int rl_blink_matching_paren;
extern int _rl_convert_meta_chars_to_ascii; extern int _rl_convert_meta_chars_to_ascii;
extern int _rl_output_meta_chars;
extern int _rl_complete_show_all;
#if defined (VISIBLE_STATS) #if defined (VISIBLE_STATS)
extern int rl_visible_stats; extern int rl_visible_stats;
#endif /* VISIBLE_STATS */ #endif /* VISIBLE_STATS */
extern int rl_complete_with_tilde_expansion; extern int rl_complete_with_tilde_expansion;
extern int rl_completion_query_items; extern int rl_completion_query_items;
#if defined (VI_MODE)
extern char *rl_vi_comment_begin;
#endif
extern int rl_explicit_arg; extern int rl_explicit_arg;
extern int rl_editing_mode; extern int rl_editing_mode;
@ -80,6 +83,9 @@ extern char *possible_control_prefixes[], *possible_meta_prefixes[];
extern char **rl_funmap_names (); extern char **rl_funmap_names ();
/* Forward declarations */
void rl_set_keymap_from_edit_mode ();
static int glean_key_from_name (); static int glean_key_from_name ();
#if defined (STATIC_MALLOC) #if defined (STATIC_MALLOC)
@ -105,6 +111,7 @@ rl_add_defun (name, function, key)
if (key != -1) if (key != -1)
rl_bind_key (key, function); rl_bind_key (key, function);
rl_add_funmap_entry (name, function); rl_add_funmap_entry (name, function);
return 0;
} }
/* Bind KEY to FUNCTION. Returns non-zero if KEY is out of range. */ /* Bind KEY to FUNCTION. Returns non-zero if KEY is out of range. */
@ -120,12 +127,9 @@ rl_bind_key (key, function)
{ {
if (_rl_keymap[ESC].type == ISKMAP) if (_rl_keymap[ESC].type == ISKMAP)
{ {
#if defined (CRAY) Keymap escmap;
Keymap escmap = (Keymap)((int)_rl_keymap[ESC].function);
#else
Keymap escmap = (Keymap)_rl_keymap[ESC].function;
#endif
escmap = FUNCTION_TO_KEYMAP (_rl_keymap, ESC);
key = UNMETA (key); key = UNMETA (key);
escmap[key].type = ISFUNC; escmap[key].type = ISFUNC;
escmap[key].function = function; escmap[key].function = function;
@ -183,7 +187,7 @@ rl_set_key (keyseq, function, map)
Function *function; Function *function;
Keymap map; Keymap map;
{ {
rl_generic_bind (ISFUNC, keyseq, function, map); return (rl_generic_bind (ISFUNC, keyseq, function, map));
} }
/* Bind the key sequence represented by the string KEYSEQ to /* Bind the key sequence represented by the string KEYSEQ to
@ -249,7 +253,7 @@ rl_generic_bind (type, keyseq, data, map)
{ {
ic = UNMETA (ic); ic = UNMETA (ic);
if (map[ESC].type == ISKMAP) if (map[ESC].type == ISKMAP)
map = (Keymap) map[ESC].function; map = FUNCTION_TO_KEYMAP (map, ESC);
} }
if ((i + 1) < keys_len) if ((i + 1) < keys_len)
@ -260,16 +264,16 @@ rl_generic_bind (type, keyseq, data, map)
free ((char *)map[ic].function); free ((char *)map[ic].function);
map[ic].type = ISKMAP; map[ic].type = ISKMAP;
map[ic].function = (Function *)rl_make_bare_keymap (); map[ic].function = KEYMAP_TO_FUNCTION (rl_make_bare_keymap());
} }
map = (Keymap)map[ic].function; map = FUNCTION_TO_KEYMAP (map, ic);
} }
else else
{ {
if (map[ic].type == ISMACR) if (map[ic].type == ISMACR)
free ((char *)map[ic].function); free ((char *)map[ic].function);
map[ic].function = (Function *)data; map[ic].function = KEYMAP_TO_FUNCTION (data);
map[ic].type = type; map[ic].type = type;
} }
} }
@ -388,7 +392,7 @@ rl_function_of_keyseq (keyseq, map, type)
} }
else else
{ {
map = (Keymap)map[ESC].function; map = FUNCTION_TO_KEYMAP (map, ESC);
ic = UNMETA (ic); ic = UNMETA (ic);
} }
} }
@ -405,7 +409,7 @@ rl_function_of_keyseq (keyseq, map, type)
return (map[ic].function); return (map[ic].function);
} }
else else
map = (Keymap)map[ic].function; map = FUNCTION_TO_KEYMAP (map, ic);
} }
else else
{ {
@ -415,6 +419,7 @@ rl_function_of_keyseq (keyseq, map, type)
return (map[ic].function); return (map[ic].function);
} }
} }
return ((Function *) NULL);
} }
/* The last key bindings file read. */ /* The last key bindings file read. */
@ -424,15 +429,19 @@ static char *last_readline_init_file = (char *)NULL;
rl_re_read_init_file (count, ignore) rl_re_read_init_file (count, ignore)
int count, ignore; int count, ignore;
{ {
return (rl_read_init_file ((char *)NULL)); int r;
r = rl_read_init_file ((char *)NULL);
rl_set_keymap_from_edit_mode ();
return r;
} }
/* The final, last-ditch effort file name for an init file. */
#define DEFAULT_INPUTRC "~/.inputrc"
/* Do key bindings from a file. If FILENAME is NULL it defaults /* Do key bindings from a file. If FILENAME is NULL it defaults
to `~/.inputrc'. If the file existed and could be opened and to the first non-null filename from this list:
read, 0 is returned, otherwise errno is returned. */ 1. the filename used for the previous call
2. the value of the shell variable `INPUTRC'
3. ~/.inputrc
If the file existed and could be opened and read, 0 is returned,
otherwise errno is returned. */
int int
rl_read_init_file (filename) rl_read_init_file (filename)
char *filename; char *filename;
@ -445,9 +454,10 @@ rl_read_init_file (filename)
/* Default the filename. */ /* Default the filename. */
if (!filename) if (!filename)
{ {
if (last_readline_init_file) filename = last_readline_init_file;
filename = last_readline_init_file; if (!filename)
else filename = getenv ("INPUTRC");
if (!filename)
filename = DEFAULT_INPUTRC; filename = DEFAULT_INPUTRC;
} }
@ -462,10 +472,13 @@ rl_read_init_file (filename)
else else
free (openname); free (openname);
if (last_readline_init_file) if (filename != last_readline_init_file)
free (last_readline_init_file); {
if (last_readline_init_file)
free (last_readline_init_file);
last_readline_init_file = savestring (filename); last_readline_init_file = savestring (filename);
}
/* Read the file into BUFFER. */ /* Read the file into BUFFER. */
buffer = (char *)xmalloc ((int)finfo.st_size + 1); buffer = (char *)xmalloc ((int)finfo.st_size + 1);
@ -487,6 +500,10 @@ rl_read_init_file (filename)
/* Mark end of line. */ /* Mark end of line. */
line[i] = '\0'; line[i] = '\0';
/* Skip leading whitespace. */
while (*line && whitespace (*line))
line++;
/* If the line is not a comment, then parse it. */ /* If the line is not a comment, then parse it. */
if (*line && *line != '#') if (*line && *line != '#')
rl_parse_and_bind (line); rl_parse_and_bind (line);
@ -552,7 +569,7 @@ parser_if (args)
/* Terminals like "aaa-60" are equivalent to "aaa". */ /* Terminals like "aaa-60" are equivalent to "aaa". */
tname = savestring (rl_terminal_name); tname = savestring (rl_terminal_name);
tem = strrchr (tname, '-'); tem = strchr (tname, '-');
if (tem) if (tem)
*tem = '\0'; *tem = '\0';
@ -682,9 +699,6 @@ handle_parser_directive (statement)
return (1); return (1);
} }
/* Ugly but working hack for binding prefix meta. */
#define PREFIX_META_HACK
static int substring_member_of_array (); static int substring_member_of_array ();
/* Read the binding command from STRING and perform it. /* Read the binding command from STRING and perform it.
@ -928,10 +942,11 @@ static struct {
} boolean_varlist [] = { } boolean_varlist [] = {
{ "horizontal-scroll-mode", &_rl_horizontal_scroll_mode }, { "horizontal-scroll-mode", &_rl_horizontal_scroll_mode },
{ "mark-modified-lines", &_rl_mark_modified_lines }, { "mark-modified-lines", &_rl_mark_modified_lines },
{ "prefer-visible-bell", &_rl_prefer_visible_bell },
{ "meta-flag", &_rl_meta_flag }, { "meta-flag", &_rl_meta_flag },
{ "blink-matching-paren", &rl_blink_matching_paren }, { "blink-matching-paren", &rl_blink_matching_paren },
{ "convert-meta", &_rl_convert_meta_chars_to_ascii }, { "convert-meta", &_rl_convert_meta_chars_to_ascii },
{ "show-all-if-ambiguous", &_rl_complete_show_all },
{ "output-meta", &_rl_output_meta_chars },
#if defined (VISIBLE_STATS) #if defined (VISIBLE_STATS)
{ "visible-stats", &rl_visible_stats }, { "visible-stats", &rl_visible_stats },
#endif /* VISIBLE_STATS */ #endif /* VISIBLE_STATS */
@ -970,10 +985,6 @@ rl_variable_bind (name, value)
#if defined (VI_MODE) #if defined (VI_MODE)
_rl_keymap = vi_insertion_keymap; _rl_keymap = vi_insertion_keymap;
rl_editing_mode = vi_mode; rl_editing_mode = vi_mode;
#else
#if defined (NOTDEF)
ding ();
#endif /* NOTDEF */
#endif /* VI_MODE */ #endif /* VI_MODE */
} }
else if (strnicmp (value, "emacs", 5) == 0) else if (strnicmp (value, "emacs", 5) == 0)
@ -987,8 +998,6 @@ rl_variable_bind (name, value)
else if (stricmp (name, "comment-begin") == 0) else if (stricmp (name, "comment-begin") == 0)
{ {
#if defined (VI_MODE) #if defined (VI_MODE)
extern char *rl_vi_comment_begin;
if (*value) if (*value)
{ {
if (rl_vi_comment_begin) if (rl_vi_comment_begin)
@ -1009,6 +1018,37 @@ rl_variable_bind (name, value)
} }
rl_completion_query_items = nval; rl_completion_query_items = nval;
} }
else if (stricmp (name, "keymap") == 0)
{
Keymap kmap;
kmap = rl_get_keymap_by_name (value);
if (kmap)
rl_set_keymap (kmap);
}
else if (stricmp (name, "bell-style") == 0)
{
if (!*value)
_rl_bell_preference = AUDIBLE_BELL;
else
{
if (stricmp (value, "none") == 0 || stricmp (value, "off") == 0)
_rl_bell_preference = NO_BELL;
else if (stricmp (value, "audible") == 0 || stricmp (value, "on") == 0)
_rl_bell_preference = AUDIBLE_BELL;
else if (stricmp (value, "visible") == 0)
_rl_bell_preference = VISIBLE_BELL;
}
}
else if (stricmp (name, "prefer-visible-bell") == 0)
{
/* Backwards compatibility. */
if (*value && (stricmp (value, "on") == 0 ||
(*value == '1' && !value[1])))
_rl_bell_preference = VISIBLE_BELL;
else
_rl_bell_preference = AUDIBLE_BELL;
}
return 0; return 0;
} }
@ -1135,8 +1175,8 @@ rl_list_funmap_names (ignore)
/* Return a NULL terminated array of strings which represent the key /* Return a NULL terminated array of strings which represent the key
sequences that are used to invoke FUNCTION in MAP. */ sequences that are used to invoke FUNCTION in MAP. */
static char ** char **
invoking_keyseqs_in_map (function, map) rl_invoking_keyseqs_in_map (function, map)
Function *function; Function *function;
Keymap map; Keymap map;
{ {
@ -1194,11 +1234,7 @@ invoking_keyseqs_in_map (function, map)
their target. Add the key sequences found to RESULT. */ their target. Add the key sequences found to RESULT. */
if (map[key].function) if (map[key].function)
seqs = seqs =
#if defined (CRAY) rl_invoking_keyseqs_in_map (function, FUNCTION_TO_KEYMAP (map, key));
invoking_keyseqs_in_map (function, (Keymap)((int)map[key].function));
#else
invoking_keyseqs_in_map (function, (Keymap)map[key].function);
#endif
if (seqs) if (seqs)
{ {
@ -1252,18 +1288,16 @@ char **
rl_invoking_keyseqs (function) rl_invoking_keyseqs (function)
Function *function; Function *function;
{ {
return (invoking_keyseqs_in_map (function, _rl_keymap)); return (rl_invoking_keyseqs_in_map (function, _rl_keymap));
} }
/* Print all of the current functions and their bindings to /* Print all of the current functions and their bindings to
rl_outstream. If an explicit argument is given, then print rl_outstream. If an explicit argument is given, then print
the output in such a way that it can be read back in. */ the output in such a way that it can be read back in. */
int int
rl_dump_functions (count) rl_dump_functions (count, key)
int count; int count, key;
{ {
void rl_function_dumper ();
rl_function_dumper (rl_explicit_arg); rl_function_dumper (rl_explicit_arg);
rl_on_new_line (); rl_on_new_line ();
return (0); return (0);
@ -1290,7 +1324,7 @@ rl_function_dumper (print_readably)
char **invokers; char **invokers;
function = rl_named_function (name); function = rl_named_function (name);
invokers = invoking_keyseqs_in_map (function, _rl_keymap); invokers = rl_invoking_keyseqs_in_map (function, _rl_keymap);
if (print_readably) if (print_readably)
{ {
@ -1339,7 +1373,22 @@ rl_function_dumper (print_readably)
} }
} }
/* Bind key sequence KEYSEQ to DEFAULT_FUNC if KEYSEQ is unbound. */
void
_rl_bind_if_unbound (keyseq, default_func)
char *keyseq;
Function *default_func;
{
Function *func;
if (keyseq)
{
func = rl_function_of_keyseq (keyseq, _rl_keymap, (int *)NULL);
if (!func || func == rl_do_lowercase_version)
rl_set_key (keyseq, default_func, _rl_keymap);
}
}
/* **************************************************************** */ /* **************************************************************** */
/* */ /* */
/* String Utility Functions */ /* String Utility Functions */

View file

@ -43,17 +43,19 @@
extern int errno; extern int errno;
#endif /* !errno */ #endif /* !errno */
/* These next are for filename completion. Perhaps this belongs
in a different place. */
#include <pwd.h> #include <pwd.h>
#if defined (USG) && !defined (isc386) && !defined (sgi) #if defined (USG) && !defined (HAVE_GETPW_DECLS)
extern struct passwd *getpwuid (), *getpwent ();
#endif
#if defined (isc386) && !defined (__STDC__) && defined (_POSIX_SOURCE)
extern struct passwd *getpwent (); extern struct passwd *getpwent ();
#endif #endif /* USG && !HAVE_GETPW_DECLS */
/* #define HACK_TERMCAP_MOTION */ /* ISC systems don't define getpwent() if _POSIX_SOURCE is defined. */
#if defined (isc386) && defined (_POSIX_SOURCE)
# if defined (__STDC__)
extern struct passwd *getpwent (void);
# else
extern struct passwd *getpwent ();
# endif /* !__STDC__ */
#endif /* isc386 && _POSIX_SOURCE */
#include "posixstat.h" #include "posixstat.h"
@ -95,11 +97,14 @@ extern char *xmalloc (), *xrealloc ();
/* If non-zero, then this is the address of a function to call when /* If non-zero, then this is the address of a function to call when
completing on a directory name. The function is called with completing on a directory name. The function is called with
the address of a string (the current directory name) as an arg. */ the address of a string (the current directory name) as an arg. */
Function *rl_symbolic_link_hook = (Function *)NULL; Function *rl_directory_completion_hook = (Function *)NULL;
/* Non-zero means readline completion functions perform tilde expansion. */ /* Non-zero means readline completion functions perform tilde expansion. */
int rl_complete_with_tilde_expansion = 0; int rl_complete_with_tilde_expansion = 0;
/* If non-zero, non-unique completions always show the list of matches. */
int _rl_complete_show_all = 0;
#if defined (VISIBLE_STATS) #if defined (VISIBLE_STATS)
# if !defined (X_OK) # if !defined (X_OK)
# define X_OK 1 # define X_OK 1
@ -133,6 +138,10 @@ Function *rl_completion_entry_function = (Function *)NULL;
array of strings returned. */ array of strings returned. */
CPPFunction *rl_attempted_completion_function = (CPPFunction *)NULL; CPPFunction *rl_attempted_completion_function = (CPPFunction *)NULL;
/* Non-zero means to suppress normal filename completion after the
user-specified completion function has been called. */
int rl_attempted_completion_over = 0;
/* Local variable states what happened during the last completion attempt. */ /* Local variable states what happened during the last completion attempt. */
static int completion_changed_buffer = 0; static int completion_changed_buffer = 0;
@ -144,22 +153,24 @@ rl_complete (ignore, invoking_key)
int ignore, invoking_key; int ignore, invoking_key;
{ {
if (rl_last_func == rl_complete && !completion_changed_buffer) if (rl_last_func == rl_complete && !completion_changed_buffer)
rl_complete_internal ('?'); return (rl_complete_internal ('?'));
else if (_rl_complete_show_all)
return (rl_complete_internal ('!'));
else else
rl_complete_internal (TAB); return (rl_complete_internal (TAB));
} }
/* List the possible completions. See description of rl_complete (). */ /* List the possible completions. See description of rl_complete (). */
rl_possible_completions (ignore, invoking_key) rl_possible_completions (ignore, invoking_key)
int ignore, invoking_key; int ignore, invoking_key;
{ {
rl_complete_internal ('?'); return (rl_complete_internal ('?'));
} }
rl_insert_completions (ignore, invoking_key) rl_insert_completions (ignore, invoking_key)
int ignore, invoking_key; int ignore, invoking_key;
{ {
rl_complete_internal ('*'); return (rl_complete_internal ('*'));
} }
/* The user must press "y" or "n". Non-zero return means "y" pressed. */ /* The user must press "y" or "n". Non-zero return means "y" pressed. */
@ -170,9 +181,9 @@ get_y_or_n ()
for (;;) for (;;)
{ {
c = rl_read_key (); c = rl_read_key ();
if (c == 'y' || c == 'Y') if (c == 'y' || c == 'Y' || c == ' ')
return (1); return (1);
if (c == 'n' || c == 'N') if (c == 'n' || c == 'N' || c == RUBOUT)
return (0); return (0);
if (c == ABORT_CHAR) if (c == ABORT_CHAR)
rl_abort (); rl_abort ();
@ -263,11 +274,90 @@ _delete_quotes (text)
} }
#endif /* SHELL */ #endif /* SHELL */
/* Return the portion of PATHNAME that should be output when listing
possible completions. If we are hacking filename completion, we
are only interested in the basename, the portion following the
final slash. Otherwise, we return what we were passed. */
static char *
printable_part (pathname)
char *pathname;
{
char *temp = (char *)NULL;
if (rl_filename_completion_desired)
temp = strrchr (pathname, '/');
if (!temp)
return (pathname);
else
return (++temp);
}
/* Output TO_PRINT to rl_outstream. If VISIBLE_STATS is defined and we
are using it, check for and output a single character for `special'
filenames. Return 1 if we printed an extension character, 0 if not. */
static int
print_filename (to_print, full_pathname)
char *to_print, *full_pathname;
{
#if !defined (VISIBLE_STATS)
fputs (to_print, rl_outstream);
return 0;
#else
char *s, c, *new_full_pathname;
int extension_char = 0, slen, tlen;
fputs (to_print, rl_outstream);
if (rl_filename_completion_desired && rl_visible_stats)
{
/* If to_print != full_pathname, to_print is the basename of the
path passed. In this case, we try to expand the directory
name before checking for the stat character. */
if (to_print != full_pathname)
{
/* Terminate the directory name. */
c = to_print[-1];
to_print[-1] = '\0';
s = tilde_expand (full_pathname);
if (rl_directory_completion_hook)
(*rl_directory_completion_hook) (&s);
slen = strlen (s);
tlen = strlen (to_print);
new_full_pathname = xmalloc (slen + tlen + 2);
strcpy (new_full_pathname, s);
new_full_pathname[slen] = '/';
strcpy (new_full_pathname + slen + 1, to_print);
extension_char = stat_char (new_full_pathname);
free (new_full_pathname);
to_print[-1] = c;
}
else
{
s = tilde_expand (full_pathname);
extension_char = stat_char (s);
}
free (s);
if (extension_char)
putc (extension_char, rl_outstream);
return (extension_char != 0);
}
else
return 0;
#endif /* VISIBLE_STATS */
}
/* Complete the word at or before point. /* Complete the word at or before point.
WHAT_TO_DO says what to do with the completion. WHAT_TO_DO says what to do with the completion.
`?' means list the possible completions. `?' means list the possible completions.
TAB means do standard completion. TAB means do standard completion.
`*' means insert all of the possible completions. */ `*' means insert all of the possible completions.
`!' means to do standard completion, and list all possible completions if
there is more than one. */
rl_complete_internal (what_to_do) rl_complete_internal (what_to_do)
int what_to_do; int what_to_do;
{ {
@ -276,10 +366,10 @@ rl_complete_internal (what_to_do)
int start, scan, end, delimiter = 0, pass_next; int start, scan, end, delimiter = 0, pass_next;
char *text, *saved_line_buffer; char *text, *saved_line_buffer;
char *replacement; char *replacement;
char quote_char = '\0';
#if defined (SHELL) #if defined (SHELL)
int found_quote = 0; int found_quote = 0;
#endif #endif
char quote_char = '\0';
if (rl_line_buffer) if (rl_line_buffer)
saved_line_buffer = savestring (rl_line_buffer); saved_line_buffer = savestring (rl_line_buffer);
@ -352,12 +442,13 @@ rl_complete_internal (what_to_do)
substring on which to complete. */ substring on which to complete. */
while (--rl_point) while (--rl_point)
{ {
scan = rl_line_buffer[rl_point];
#if defined (SHELL) #if defined (SHELL)
/* Don't let word break characters in quoted substrings break /* Don't let word break characters in quoted substrings break
words for the completer. */ words for the completer. */
if (found_quote) if (found_quote)
{ {
if (strchr (rl_completer_quote_characters, rl_line_buffer[rl_point])) if (strchr (rl_completer_quote_characters, scan))
{ {
quoted = !quoted; quoted = !quoted;
continue; continue;
@ -366,23 +457,23 @@ rl_complete_internal (what_to_do)
continue; continue;
} }
#endif /* SHELL */ #endif /* SHELL */
if (strchr (rl_completer_word_break_characters, rl_line_buffer[rl_point])) if (strchr (rl_completer_word_break_characters, scan))
break; break;
} }
} }
/* If we are at a word break, then advance past it. */ /* If we are at a word break, then advance past it. */
if (strchr (rl_completer_word_break_characters, rl_line_buffer[rl_point])) scan = rl_line_buffer[rl_point];
if (strchr (rl_completer_word_break_characters, scan))
{ {
/* If the character that caused the word break was a quoting /* If the character that caused the word break was a quoting
character, then remember it as the delimiter. */ character, then remember it as the delimiter. */
if (strchr ("\"'", rl_line_buffer[rl_point]) && (end - rl_point) > 1) if (strchr ("\"'", scan) && (end - rl_point) > 1)
delimiter = rl_line_buffer[rl_point]; delimiter = scan;
/* If the character isn't needed to determine something special /* If the character isn't needed to determine something special
about what kind of completion to perform, then advance past it. */ about what kind of completion to perform, then advance past it. */
if (!rl_special_prefixes || if (!rl_special_prefixes || strchr (rl_special_prefixes, scan) == 0)
!strchr (rl_special_prefixes, rl_line_buffer[rl_point]))
rl_point++; rl_point++;
} }
} }
@ -399,11 +490,9 @@ rl_complete_internal (what_to_do)
{ {
matches = (*rl_attempted_completion_function) (text, start, end); matches = (*rl_attempted_completion_function) (text, start, end);
if (matches) if (matches || rl_attempted_completion_over)
{ {
/* XXX - This is questionable code. - XXX */ rl_attempted_completion_over = 0;
if (matches == (char **)-1)
matches = (char **)NULL;
our_func = (Function *)NULL; our_func = (Function *)NULL;
goto after_usual_completion; goto after_usual_completion;
} }
@ -441,6 +530,7 @@ rl_complete_internal (what_to_do)
char *lowest_common; char *lowest_common;
int j, newlen = 0; int j, newlen = 0;
char dead_slot; char dead_slot;
char **temp_array;
/* Sort the items. */ /* Sort the items. */
/* It is safe to sort this array, because the lowest common /* It is safe to sort this array, because the lowest common
@ -464,25 +554,19 @@ rl_complete_internal (what_to_do)
/* We have marked all the dead slots with (char *)&dead_slot. /* We have marked all the dead slots with (char *)&dead_slot.
Copy all the non-dead entries into a new array. */ Copy all the non-dead entries into a new array. */
{ temp_array = (char **)xmalloc ((3 + newlen) * sizeof (char *));
char **temp_array = for (i = j = 1; matches[i]; i++)
(char **)xmalloc ((3 + newlen) * sizeof (char *)); {
if (matches[i] != (char *)&dead_slot)
temp_array[j++] = matches[i];
}
temp_array[j] = (char *)NULL;
for (i = 1, j = 1; matches[i]; i++) if (matches[0] != (char *)&dead_slot)
{ free (matches[0]);
if (matches[i] != (char *)&dead_slot) free (matches);
temp_array[j++] = matches[i];
}
temp_array[j] = (char *)NULL; matches = temp_array;
if (matches[0] != (char *)&dead_slot)
free (matches[0]);
free (matches);
matches = temp_array;
}
/* Place the lowest common denominator back in [0]. */ /* Place the lowest common denominator back in [0]. */
matches[0] = lowest_common; matches[0] = lowest_common;
@ -500,6 +584,7 @@ rl_complete_internal (what_to_do)
switch (what_to_do) switch (what_to_do)
{ {
case TAB: case TAB:
case '!':
/* If we are matching filenames, then here is our chance to /* If we are matching filenames, then here is our chance to
do clever processing by re-examining the list. Call the do clever processing by re-examining the list. Call the
ignore function with the array as a parameter. It can ignore function with the array as a parameter. It can
@ -529,7 +614,11 @@ rl_complete_internal (what_to_do)
This also checks whether the common prefix of several This also checks whether the common prefix of several
matches needs to be quoted. If the common prefix should matches needs to be quoted. If the common prefix should
not be checked, add !matches[1] to the if clause. */ not be checked, add !matches[1] to the if clause. */
if (rl_strpbrk (matches[0], rl_completer_word_break_characters)) if (rl_strpbrk (matches[0], rl_completer_word_break_characters)
#if defined (SHELL)
|| rl_strpbrk (matches[0], "$`")
#endif
)
do_replace = matches[1] ? MULT_MATCH : SINGLE_MATCH; do_replace = matches[1] ? MULT_MATCH : SINGLE_MATCH;
if (do_replace != NO_MATCH) if (do_replace != NO_MATCH)
@ -558,7 +647,7 @@ rl_complete_internal (what_to_do)
free (mtext); free (mtext);
rlen = strlen (rtext); rlen = strlen (rtext);
replacement = (char *)alloca (rlen + 1); replacement = xmalloc (rlen + 1);
strcpy (replacement, rtext); strcpy (replacement, rtext);
if (do_replace == MULT_MATCH) if (do_replace == MULT_MATCH)
replacement[rlen - 1] = '\0'; replacement[rlen - 1] = '\0';
@ -567,7 +656,7 @@ rl_complete_internal (what_to_do)
/* Found an embedded word break character in a potential /* Found an embedded word break character in a potential
match, so we need to prepend a quote character if we match, so we need to prepend a quote character if we
are replacing the completion string. */ are replacing the completion string. */
replacement = (char *)alloca (strlen (matches[0]) + 2); replacement = xmalloc (strlen (matches[0]) + 2);
quote_char = *rl_completer_quote_characters; quote_char = *rl_completer_quote_characters;
*replacement = quote_char; *replacement = quote_char;
strcpy (replacement + 1, matches[0]); strcpy (replacement + 1, matches[0]);
@ -577,9 +666,13 @@ rl_complete_internal (what_to_do)
if (replacement) if (replacement)
{ {
rl_begin_undo_group ();
rl_delete_text (start, rl_point); rl_delete_text (start, rl_point);
rl_point = start; rl_point = start;
rl_insert_text (replacement); rl_insert_text (replacement);
rl_end_undo_group ();
if (replacement != matches[0])
free (replacement);
} }
/* If there are more matches, ring the bell to indicate. /* If there are more matches, ring the bell to indicate.
@ -589,7 +682,9 @@ rl_complete_internal (what_to_do)
of the line, then add a space. */ of the line, then add a space. */
if (matches[1]) if (matches[1])
{ {
if (rl_editing_mode != vi_mode) if (what_to_do == '!')
goto display_matches; /* XXX */
else if (rl_editing_mode != vi_mode)
ding (); /* There are other matches remaining. */ ding (); /* There are other matches remaining. */
} }
else else
@ -608,8 +703,7 @@ rl_complete_internal (what_to_do)
struct stat finfo; struct stat finfo;
char *filename = tilde_expand (matches[0]); char *filename = tilde_expand (matches[0]);
if ((stat (filename, &finfo) == 0) && if ((stat (filename, &finfo) == 0) && S_ISDIR (finfo.st_mode))
S_ISDIR (finfo.st_mode))
{ {
if (rl_line_buffer[rl_point] != '/') if (rl_line_buffer[rl_point] != '/')
rl_insert_text ("/"); rl_insert_text ("/");
@ -633,9 +727,9 @@ rl_complete_internal (what_to_do)
{ {
int i = 1; int i = 1;
rl_begin_undo_group ();
rl_delete_text (start, rl_point); rl_delete_text (start, rl_point);
rl_point = start; rl_point = start;
rl_begin_undo_group ();
if (matches[1]) if (matches[1])
{ {
while (matches[i]) while (matches[i])
@ -655,34 +749,17 @@ rl_complete_internal (what_to_do)
case '?': case '?':
{ {
int len, count, limit, max = 0; int len, count, limit, max;
int j, k, l; int j, k, l;
/* Handle simple case first. What if there is only one answer? */ /* Handle simple case first. What if there is only one answer? */
if (!matches[1]) if (!matches[1])
{ {
char *temp = (char *)NULL; char *temp;
if (rl_filename_completion_desired)
temp = strrchr (matches[0], '/');
if (!temp)
temp = matches[0];
else
temp++;
temp = printable_part (matches[0]);
crlf (); crlf ();
fprintf (rl_outstream, "%s", temp); print_filename (temp, matches[0]);
#if defined (VISIBLE_STATS)
if (rl_filename_completion_desired && rl_visible_stats)
{
int extension_char;
extension_char = stat_char (matches[0]);
if (extension_char)
putc (extension_char, rl_outstream);
}
#endif /* VISIBLE_STATS */
crlf (); crlf ();
goto restart; goto restart;
} }
@ -690,23 +767,13 @@ rl_complete_internal (what_to_do)
/* There is more than one answer. Find out how many there are, /* There is more than one answer. Find out how many there are,
and find out what the maximum printed length of a single entry and find out what the maximum printed length of a single entry
is. */ is. */
for (i = 1; matches[i]; i++) display_matches:
for (max = 0, i = 1; matches[i]; i++)
{ {
char *temp; char *temp;
int name_length; int name_length;
/* If we are hacking filenames, then only count the characters temp = printable_part (matches[i]);
after the last slash in the pathname. */
if (rl_filename_completion_desired)
temp = strrchr (matches[i], '/');
else
temp = (char *)NULL;
if (!temp)
temp = matches[i];
else
temp++;
name_length = strlen (temp); name_length = strlen (temp);
if (name_length > max) if (name_length > max)
@ -764,40 +831,15 @@ rl_complete_internal (what_to_do)
for (j = 0, l = i; j < limit; j++) for (j = 0, l = i; j < limit; j++)
{ {
if (l > len || !matches[l]) if (l > len || !matches[l])
{ break;
break;
}
else else
{ {
char *temp = (char *)NULL; char *temp;
int printed_length; int printed_length;
if (rl_filename_completion_desired) temp = printable_part (matches[l]);
temp = strrchr (matches[l], '/');
if (!temp)
temp = matches[l];
else
temp++;
printed_length = strlen (temp); printed_length = strlen (temp);
fprintf (rl_outstream, "%s", temp); printed_length += print_filename (temp, matches[l]);
#if defined (VISIBLE_STATS)
if (rl_filename_completion_desired &&
rl_visible_stats)
{
int extension_char;
extension_char = stat_char (matches[l]);
if (extension_char)
{
putc (extension_char, rl_outstream);
printed_length++;
}
}
#endif /* VISIBLE_STATS */
if (j + 1 < limit) if (j + 1 < limit)
{ {
@ -835,6 +877,7 @@ rl_complete_internal (what_to_do)
free (saved_line_buffer); free (saved_line_buffer);
} }
return 0;
} }
#if defined (VISIBLE_STATS) #if defined (VISIBLE_STATS)
@ -848,11 +891,18 @@ stat_char (filename)
char *filename; char *filename;
{ {
struct stat finfo; struct stat finfo;
int character = 0; int character, r;
if (stat (filename, &finfo) == -1) #if defined (S_ISLNK)
return (character); r = lstat (filename, &finfo);
#else
r = stat (filename, &finfo);
#endif
if (r == -1)
return (0);
character = 0;
if (S_ISDIR (finfo.st_mode)) if (S_ISDIR (finfo.st_mode))
character = '/'; character = '/';
#if defined (S_ISLNK) #if defined (S_ISLNK)
@ -888,9 +938,9 @@ username_completion_function (text, state)
int state; int state;
char *text; char *text;
{ {
#if defined (_GO32_) #if defined (__GO32__)
return (char *)NULL; return (char *)NULL;
#else /* !_GO32_ */ #else /* !__GO32__ */
static char *username = (char *)NULL; static char *username = (char *)NULL;
static struct passwd *entry; static struct passwd *entry;
static int namelen, first_char, first_char_loc; static int namelen, first_char, first_char_loc;
@ -914,7 +964,8 @@ username_completion_function (text, state)
while (entry = getpwent ()) while (entry = getpwent ())
{ {
if (strncmp (username, entry->pw_name, namelen) == 0) if ((username[0] == entry->pw_name[0]) &&
(strncmp (username, entry->pw_name, namelen) == 0))
break; break;
} }
@ -936,7 +987,7 @@ username_completion_function (text, state)
return (value); return (value);
} }
#endif /* !_GO32_ */ #endif /* !__GO32__ */
} }
/* **************************************************************** */ /* **************************************************************** */
@ -1091,13 +1142,20 @@ filename_completion_function (text, state)
users_dirname = savestring (dirname); users_dirname = savestring (dirname);
{ {
char *temp_dirname; char *temp_dirname;
int replace_dirname;
temp_dirname = tilde_expand (dirname); temp_dirname = tilde_expand (dirname);
free (dirname); free (dirname);
dirname = temp_dirname; dirname = temp_dirname;
if (rl_symbolic_link_hook) replace_dirname = 0;
(*rl_symbolic_link_hook) (&dirname); if (rl_directory_completion_hook)
replace_dirname = (*rl_directory_completion_hook) (&dirname);
if (replace_dirname)
{
free (users_dirname);
users_dirname = savestring (dirname);
}
} }
directory = opendir (dirname); directory = opendir (dirname);
filename_len = strlen (filename); filename_len = strlen (filename);
@ -1125,14 +1183,12 @@ filename_completion_function (text, state)
} }
else else
{ {
/* Otherwise, if these match upto the length of filename, then /* Otherwise, if these match up to the length of filename, then
it is a match. */ it is a match. */
if (((int)D_NAMLEN (entry)) >= filename_len && if (((int)D_NAMLEN (entry)) >= filename_len &&
(entry->d_name[0] == filename[0]) && (entry->d_name[0] == filename[0]) &&
(strncmp (filename, entry->d_name, filename_len) == 0)) (strncmp (filename, entry->d_name, filename_len) == 0))
{ break;
break;
}
} }
} }
@ -1166,7 +1222,8 @@ filename_completion_function (text, state)
{ {
char *temp; char *temp;
if (dirname && (strcmp (dirname, ".") != 0)) /* dirname && (strcmp (dirname, ".") != 0) */
if (dirname && (dirname[0] != '.' || dirname[1]))
{ {
if (rl_complete_with_tilde_expansion && *users_dirname == '~') if (rl_complete_with_tilde_expansion && *users_dirname == '~')
{ {
@ -1191,9 +1248,8 @@ filename_completion_function (text, state)
strcat (temp, entry->d_name); strcat (temp, entry->d_name);
} }
else else
{ temp = (savestring (entry->d_name));
temp = (savestring (entry->d_name));
}
return (temp); return (temp);
} }
} }
@ -1239,10 +1295,11 @@ rl_tilde_expand (ignore, key)
int len; int len;
len = end - start + 1; len = end - start + 1;
temp = (char *)alloca (len + 1); temp = xmalloc (len + 1);
strncpy (temp, rl_line_buffer + start, len); strncpy (temp, rl_line_buffer + start, len);
temp[len] = '\0'; temp[len] = '\0';
homedir = tilde_expand (temp); homedir = tilde_expand (temp);
free (temp);
insert: insert:
rl_begin_undo_group (); rl_begin_undo_group ();

View file

@ -53,12 +53,13 @@ extern int readline_echoing_p;
extern char *term_clreol, *term_im, *term_ic, *term_ei, *term_DC; extern char *term_clreol, *term_im, *term_ic, *term_ei, *term_DC;
/* Termcap variables. */ /* Termcap variables. */
extern char *term_up, *term_dc, *term_cr, *term_IC; extern char *term_up, *term_dc, *term_cr, *term_IC;
extern int screenheight, screenwidth, terminal_can_insert; extern int screenheight, screenwidth, screenchars;
extern int terminal_can_insert;
extern void _rl_output_some_chars (); extern void _rl_output_some_chars ();
extern void _rl_output_character_function (); extern int _rl_output_character_function ();
extern int _rl_convert_meta_chars_to_ascii; extern int _rl_output_meta_chars;
extern int _rl_horizontal_scroll_mode; extern int _rl_horizontal_scroll_mode;
extern int _rl_mark_modified_lines; extern int _rl_mark_modified_lines;
extern int _rl_prefer_visible_bell; extern int _rl_prefer_visible_bell;
@ -139,15 +140,138 @@ static int forced_display = 0;
/* Default and initial buffer size. Can grow. */ /* Default and initial buffer size. Can grow. */
static int line_size = 1024; static int line_size = 1024;
static char *last_prompt_string = (char *)NULL;
static char *local_prompt, *local_prompt_prefix;
static int visible_length, prefix_length;
/* The number of invisible characters in the line currently being
displayed on the screen. */
static int visible_wrap_offset = 0;
/* The length (buffer offset) of the first line of the last (possibly
multi-line) buffer displayed on the screen. */
static int visible_first_line_len = 0;
/* Expand the prompt string S and return the number of visible
characters in *LP, if LP is not null. This is currently more-or-less
a placeholder for expansion. */
/* Current implementation:
\001 (^A) start non-visible characters
\002 (^B) end non-visible characters
all characters except \001 and \002 (following a \001) are copied to
the returned string; all characters except those between \001 and
\002 are assumed to be `visible'. */
static char *
expand_prompt (pmt, lp)
char *pmt;
int *lp;
{
char *r, *ret, *p;
int l, rl, ignoring;
/* Short-circuit if we can. */
if (strchr (pmt, RL_PROMPT_START_IGNORE) == 0)
{
r = savestring (pmt);
if (lp)
*lp = strlen (r);
return r;
}
l = strlen (pmt);
r = ret = xmalloc (l + 1);
for (rl = ignoring = 0, p = pmt; p && *p; p++)
{
/* This code strips the invisible character string markers
RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE */
if (*p == RL_PROMPT_START_IGNORE)
{
ignoring++;
continue;
}
else if (ignoring && *p == RL_PROMPT_END_IGNORE)
{
ignoring = 0;
continue;
}
else
{
*r++ = *p;
if (!ignoring)
rl++;
}
}
*r = '\0';
if (lp)
*lp = rl;
return ret;
}
/*
* Expand the prompt string into the various display components, if
* necessary.
*
* local_prompt = expanded last line of string in rl_display_prompt
* (portion after the final newline)
* local_prompt_prefix = portion before last newline of rl_display_prompt,
* expanded via expand_prompt
* visible_length = number of visible characters in local_prompt
* prefix_length = number of visible characters in local_prompt_prefix
*
* This function is called once per call to readline(). It may also be
* called arbitrarily to expand the primary prompt.
*
* The return value is the number of visible characters on the last line
* of the (possibly multi-line) prompt.
*/
int
rl_expand_prompt (prompt)
char *prompt;
{
char *p, *t;
int c;
/* Clear out any saved values. */
if (local_prompt)
free (local_prompt);
if (local_prompt_prefix)
free (local_prompt_prefix);
local_prompt = local_prompt_prefix = (char *)0;
p = strrchr (prompt, '\n');
if (!p)
{
/* The prompt is only one line. */
local_prompt = expand_prompt (prompt, &visible_length);
local_prompt_prefix = (char *)0;
return (visible_length);
}
else
{
/* The prompt spans multiple lines. */
t = ++p;
local_prompt = expand_prompt (p, &visible_length);
c = *t; *t = '\0';
/* The portion of the prompt string up to and including the
final newline is now null-terminated. */
local_prompt_prefix = expand_prompt (prompt, &prefix_length);
*t = c;
return (prefix_length);
}
}
/* Basic redisplay algorithm. */ /* Basic redisplay algorithm. */
void void
rl_redisplay () rl_redisplay ()
{ {
register int in, out, c, linenum; register int in, out, c, linenum;
register char *line = invisible_line; register char *line = invisible_line;
int c_pos = 0, inv_botlin = 0, wrap_offset, wrap_column;
char *prompt_this_line; char *prompt_this_line;
int c_pos = 0;
int inv_botlin = 0; /* Number of lines in newly drawn buffer. */
if (!readline_echoing_p) if (!readline_echoing_p)
return; return;
@ -186,20 +310,41 @@ rl_redisplay ()
if (visible_line[0] != invisible_line[0]) if (visible_line[0] != invisible_line[0])
rl_display_fixed = 0; rl_display_fixed = 0;
prompt_this_line = strrchr (rl_display_prompt, '\n'); /* If the prompt to be displayed is the `primary' readline prompt (the
if (!prompt_this_line) one passed to readline()), use the values we have already expanded.
prompt_this_line = rl_display_prompt; If not, use what's already in rl_display_prompt. WRAP_OFFSET is the
number of non-visible characters in the prompt string. */
if (rl_display_prompt == rl_prompt)
{
int local_len = strlen (local_prompt);
if (local_prompt_prefix && forced_display)
_rl_output_some_chars (local_prompt_prefix, strlen (local_prompt_prefix));
if (local_prompt)
strncpy (line + out, local_prompt, local_len);
out += local_len;
line[out] = '\0';
wrap_offset = local_len - visible_length;
}
else else
{ {
prompt_this_line++; int pmtlen;
if (forced_display) prompt_this_line = strrchr (rl_display_prompt, '\n');
_rl_output_some_chars if (!prompt_this_line)
(rl_display_prompt, prompt_this_line - rl_display_prompt); prompt_this_line = rl_display_prompt;
} else
{
prompt_this_line++;
if (forced_display)
_rl_output_some_chars (rl_display_prompt, prompt_this_line - rl_display_prompt);
}
strncpy (line + out, prompt_this_line, strlen (prompt_this_line)); pmtlen = strlen (prompt_this_line);
out += strlen (prompt_this_line); strncpy (line + out, prompt_this_line, pmtlen);
line[out] = '\0'; out += pmtlen;
line[out] = '\0';
wrap_offset = 0;
}
for (in = 0; in < rl_end; in++) for (in = 0; in < rl_end; in++)
{ {
@ -218,7 +363,7 @@ rl_redisplay ()
if (META_CHAR (c)) if (META_CHAR (c))
{ {
if (_rl_convert_meta_chars_to_ascii) if (_rl_output_meta_chars == 0)
{ {
sprintf (line + out, "\\%o", c); sprintf (line + out, "\\%o", c);
out += 4; out += 4;
@ -226,7 +371,6 @@ rl_redisplay ()
else else
line[out++] = c; line[out++] = c;
} }
#define DISPLAY_TABS
#if defined (DISPLAY_TABS) #if defined (DISPLAY_TABS)
else if (c == '\t') else if (c == '\t')
{ {
@ -252,6 +396,8 @@ rl_redisplay ()
if (c_pos < 0) if (c_pos < 0)
c_pos = out; c_pos = out;
/* C_POS == position in buffer where cursor should be placed. */
/* PWP: now is when things get a bit hairy. The visible and invisible /* PWP: now is when things get a bit hairy. The visible and invisible
line buffers are really multiple lines, which would wrap every line buffers are really multiple lines, which would wrap every
(screenwidth - 1) characters. Go through each in turn, finding (screenwidth - 1) characters. Go through each in turn, finding
@ -263,7 +409,8 @@ rl_redisplay ()
if (!_rl_horizontal_scroll_mode && term_up && *term_up) if (!_rl_horizontal_scroll_mode && term_up && *term_up)
{ {
int total_screen_chars = (screenwidth * screenheight); int total_screen_chars = screenchars;
int nleft, cursor_linenum, pos;
if (!rl_display_fixed || forced_display) if (!rl_display_fixed || forced_display)
{ {
@ -275,15 +422,48 @@ rl_redisplay ()
if (out >= total_screen_chars) if (out >= total_screen_chars)
out = total_screen_chars - 1; out = total_screen_chars - 1;
/* Number of screen lines to display. */ /* Number of screen lines to display. The first line wraps at
inv_botlin = out / screenwidth; (screenwidth + wrap_offset) chars, the rest of the lines have
screenwidth chars. */
nleft = out - screenwidth - wrap_offset;
if (nleft > 0)
inv_botlin = 1 + nleft / screenwidth;
else
inv_botlin = 0;
/* The first line is at character position 0 in the buffer. The
second and subsequent lines start at N * screenwidth, offset by
OFFSET. OFFSET is wrap_offset for the invisible line and
visible_wrap_offset for the line currently displayed. */
#define L_OFFSET(n, offset) ((n) > 0 ? ((n) * screenwidth) + (offset) : 0)
#define VIS_CHARS(line) &visible_line[L_OFFSET((line), visible_wrap_offset)]
#define VIS_LINE(line) ((line) > _rl_vis_botlin) ? "" : VIS_CHARS(line)
#define INV_LINE(line) &invisible_line[L_OFFSET((line), wrap_offset)]
/* For each line in the buffer, do the updating display. */ /* For each line in the buffer, do the updating display. */
for (linenum = 0; linenum <= inv_botlin; linenum++) for (linenum = 0; linenum <= inv_botlin; linenum++)
update_line (linenum > _rl_vis_botlin ? "" {
: &visible_line[linenum * screenwidth], update_line (VIS_LINE(linenum), INV_LINE(linenum), linenum);
&invisible_line[linenum * screenwidth],
linenum); /* If this is the line with the prompt, we might need to
compensate for invisible characters in the new line. Do
this only if there is not more than one new line (which
implies that we completely overwrite the old visible line)
and the new line is shorter than the old. */
if (linenum == 0 &&
inv_botlin == 0 &&
(wrap_offset > visible_wrap_offset) &&
(_rl_last_c_pos < visible_first_line_len))
{
nleft = screenwidth + wrap_offset - _rl_last_c_pos;
clear_to_eol (nleft);
}
/* Since the new first line is now visible, save its length. */
if (linenum == 0)
visible_first_line_len = _rl_last_c_pos;
}
/* We may have deleted some lines. If so, clear the left over /* We may have deleted some lines. If so, clear the left over
blank ones at the bottom out. */ blank ones at the bottom out. */
@ -292,7 +472,7 @@ rl_redisplay ()
char *tt; char *tt;
for (; linenum <= _rl_vis_botlin; linenum++) for (; linenum <= _rl_vis_botlin; linenum++)
{ {
tt = &visible_line[linenum * screenwidth]; tt = VIS_CHARS (linenum);
_rl_move_vert (linenum); _rl_move_vert (linenum);
_rl_move_cursor_relative (0, tt); _rl_move_cursor_relative (0, tt);
clear_to_eol clear_to_eol
@ -302,9 +482,19 @@ rl_redisplay ()
_rl_vis_botlin = inv_botlin; _rl_vis_botlin = inv_botlin;
/* Move the cursor where it should be. */ /* Move the cursor where it should be. */
_rl_move_vert (c_pos / screenwidth); /* Which line? */
_rl_move_cursor_relative (c_pos % screenwidth, nleft = c_pos - screenwidth - wrap_offset;
&invisible_line[(c_pos / screenwidth) * screenwidth]); if (nleft > 0)
cursor_linenum = 1 + nleft / screenwidth;
else
cursor_linenum = 0;
_rl_move_vert (cursor_linenum);
/* Where on that line? And where does that line start
in the buffer? */
pos = L_OFFSET(cursor_linenum, wrap_offset);
nleft = c_pos - pos;
_rl_move_cursor_relative (nleft, &invisible_line[pos]);
} }
} }
else /* Do horizontal scrolling. */ else /* Do horizontal scrolling. */
@ -350,6 +540,7 @@ rl_redisplay ()
visible_line = invisible_line; visible_line = invisible_line;
invisible_line = temp; invisible_line = temp;
rl_display_fixed = 0; rl_display_fixed = 0;
visible_wrap_offset = wrap_offset;
} }
} }
@ -357,12 +548,12 @@ rl_redisplay ()
line on the screen; vis: line on the screen; vis:
/old first difference /old first difference
/beginning of line | /old last same /old EOL /beginning of line | /old last same /old EOL
v v v v v v v v
old: eddie> Oh, my little gruntle-buggy is to me, as lurgid as old: eddie> Oh, my little gruntle-buggy is to me, as lurgid as
new: eddie> Oh, my little buggy says to me, as lurgid as new: eddie> Oh, my little buggy says to me, as lurgid as
^ ^ ^ ^ ^ ^ ^ ^
\beginning of line | \new last same \new end of line \beginning of line | \new last same \new end of line
\new first difference \new first difference
All are character pointers for the sake of speed. Special cases for All are character pointers for the sake of speed. Special cases for
@ -494,6 +685,7 @@ rl_on_new_line ()
_rl_last_c_pos = _rl_last_v_pos = 0; _rl_last_c_pos = _rl_last_v_pos = 0;
_rl_vis_botlin = last_lmargin = 0; _rl_vis_botlin = last_lmargin = 0;
return 0;
} }
/* Actually update the display, period. */ /* Actually update the display, period. */
@ -508,6 +700,7 @@ rl_forced_update_display ()
rl_on_new_line (); rl_on_new_line ();
forced_display++; forced_display++;
rl_redisplay (); rl_redisplay ();
return 0;
} }
/* Move the cursor from _rl_last_c_pos to NEW, which are buffer indices. /* Move the cursor from _rl_last_c_pos to NEW, which are buffer indices.
@ -553,7 +746,7 @@ _rl_move_cursor_relative (new, data)
#else #else
for (i = _rl_last_c_pos; i < new; i++) for (i = _rl_last_c_pos; i < new; i++)
putc (data[i], rl_outstream); putc (data[i], rl_outstream);
#endif /* HACK_TERMCAP_MOTION */ #endif /* HACK_TERMCAP_MOTION */
} }
else else
backspace (_rl_last_c_pos - new); backspace (_rl_last_c_pos - new);
@ -570,14 +763,14 @@ _rl_move_vert (to)
if (_rl_last_v_pos == to || to > screenheight) if (_rl_last_v_pos == to || to > screenheight)
return; return;
#if defined (_GO32_) #if defined (__GO32__)
{ {
int row, col; int row, col;
ScreenGetCursor (&row, &col); ScreenGetCursor (&row, &col);
ScreenSetCursor ((row + to - _rl_last_v_pos), col); ScreenSetCursor ((row + to - _rl_last_v_pos), col);
} }
#else /* !_GO32_ */ #else /* !__GO32__ */
if ((delta = to - _rl_last_v_pos) > 0) if ((delta = to - _rl_last_v_pos) > 0)
{ {
@ -592,18 +785,20 @@ _rl_move_vert (to)
for (i = 0; i < -delta; i++) for (i = 0; i < -delta; i++)
tputs (term_up, 1, _rl_output_character_function); tputs (term_up, 1, _rl_output_character_function);
} }
#endif /* !_GO32_ */ #endif /* !__GO32__ */
_rl_last_v_pos = to; /* Now TO is here */ _rl_last_v_pos = to; /* Now TO is here */
} }
/* Physically print C on rl_outstream. This is for functions which know /* Physically print C on rl_outstream. This is for functions which know
how to optimize the display. */ how to optimize the display. Return the number of characters output. */
rl_show_char (c) rl_show_char (c)
int c; int c;
{ {
if (META_CHAR (c) && _rl_convert_meta_chars_to_ascii) int n = 1;
if (META_CHAR (c) && (_rl_output_meta_chars == 0))
{ {
fprintf (rl_outstream, "M-"); fprintf (rl_outstream, "M-");
n += 2;
c = UNMETA (c); c = UNMETA (c);
} }
@ -613,11 +808,14 @@ rl_show_char (c)
if (c < 32) if (c < 32)
#endif /* !DISPLAY_TABS */ #endif /* !DISPLAY_TABS */
{ {
fprintf (rl_outstream, "C-");
n += 2;
c += 64; c += 64;
} }
putc (c, rl_outstream); putc (c, rl_outstream);
fflush (rl_outstream); fflush (rl_outstream);
return n;
} }
int int
@ -625,7 +823,7 @@ rl_character_len (c, pos)
register int c, pos; register int c, pos;
{ {
if (META_CHAR (c)) if (META_CHAR (c))
return (_rl_convert_meta_chars_to_ascii ? 4 : 1); return ((_rl_output_meta_chars == 0) ? 4 : 1);
if (c == '\t') if (c == '\t')
{ {
@ -636,10 +834,7 @@ rl_character_len (c, pos)
#endif /* !DISPLAY_TABS */ #endif /* !DISPLAY_TABS */
} }
if (isprint (c)) return ((isprint (c)) ? 1 : 2);
return (1);
else
return (2);
} }
/* How to print things in the "echo-area". The prompt is treated as a /* How to print things in the "echo-area". The prompt is treated as a
@ -659,6 +854,7 @@ rl_message (va_alist)
rl_display_prompt = msg_buf; rl_display_prompt = msg_buf;
rl_redisplay (); rl_redisplay ();
return 0;
} }
#else /* !HAVE_VARARGS_H */ #else /* !HAVE_VARARGS_H */
rl_message (format, arg1, arg2) rl_message (format, arg1, arg2)
@ -667,6 +863,7 @@ rl_message (format, arg1, arg2)
sprintf (msg_buf, format, arg1, arg2); sprintf (msg_buf, format, arg1, arg2);
rl_display_prompt = msg_buf; rl_display_prompt = msg_buf;
rl_redisplay (); rl_redisplay ();
return 0;
} }
#endif /* !HAVE_VARARGS_H */ #endif /* !HAVE_VARARGS_H */
@ -675,6 +872,7 @@ rl_clear_message ()
{ {
rl_display_prompt = rl_prompt; rl_display_prompt = rl_prompt;
rl_redisplay (); rl_redisplay ();
return 0;
} }
rl_reset_line_state () rl_reset_line_state ()
@ -683,6 +881,7 @@ rl_reset_line_state ()
rl_display_prompt = rl_prompt ? rl_prompt : ""; rl_display_prompt = rl_prompt ? rl_prompt : "";
forced_display = 1; forced_display = 1;
return 0;
} }
/* Quick redisplay hack when erasing characters at the end of the line. */ /* Quick redisplay hack when erasing characters at the end of the line. */
@ -707,13 +906,13 @@ static void
clear_to_eol (count) clear_to_eol (count)
int count; int count;
{ {
#if !defined (_GO32_) #if !defined (__GO32__)
if (term_clreol) if (term_clreol)
{ {
tputs (term_clreol, 1, _rl_output_character_function); tputs (term_clreol, 1, _rl_output_character_function);
} }
else else
#endif /* !_GO32_ */ #endif /* !__GO32__ */
{ {
register int i; register int i;
@ -733,7 +932,7 @@ insert_some_chars (string, count)
char *string; char *string;
int count; int count;
{ {
#if defined (_GO32_) #if defined (__GO32__)
int row, col, width; int row, col, width;
char *row_start; char *row_start;
@ -779,7 +978,7 @@ insert_some_chars (string, count)
if (term_ei && *term_ei) if (term_ei && *term_ei)
tputs (term_ei, 1, _rl_output_character_function); tputs (term_ei, 1, _rl_output_character_function);
} }
#endif /* !_GO32_ */ #endif /* !__GO32__ */
} }
/* Delete COUNT characters from the display line. */ /* Delete COUNT characters from the display line. */
@ -787,7 +986,7 @@ static void
delete_chars (count) delete_chars (count)
int count; int count;
{ {
#if defined (_GO32_) #if defined (__GO32__)
int row, col, width; int row, col, width;
char *row_start; char *row_start;
@ -814,5 +1013,5 @@ delete_chars (count)
while (count--) while (count--)
tputs (term_dc, 1, _rl_output_character_function); tputs (term_dc, 1, _rl_output_character_function);
} }
#endif /* !_GO32_ */ #endif /* !__GO32__ */
} }

View file

@ -2,7 +2,7 @@
This file documents the user interface to the GNU History library. This file documents the user interface to the GNU History library.
Copyright (C) 1988, 1991 Free Software Foundation, Inc. Copyright (C) 1988, 1991 Free Software Foundation, Inc.
Authored by Brian Fox. Authored by Brian Fox and Chet Ramey.
Permission is granted to make and distribute verbatim copies of this manual Permission is granted to make and distribute verbatim copies of this manual
provided the copyright notice and this permission notice are preserved on provided the copyright notice and this permission notice are preserved on
@ -48,8 +48,8 @@ information on using the GNU History Library in your own programs,
@cindex expansion @cindex expansion
The History library provides a history expansion feature that is similar The History library provides a history expansion feature that is similar
to the history expansion in Csh. The following text describes the sytax to the history expansion in @code{csh}. The following text describes
that you use to manipulate the history information. the syntax used to manipulate the history information.
History expansion takes place in two parts. The first is to determine History expansion takes place in two parts. The first is to determine
which line from the previous history should be used during substitution. which line from the previous history should be used during substitution.
@ -57,13 +57,13 @@ The second is to select portions of that line for inclusion into the
current one. The line selected from the previous history is called the current one. The line selected from the previous history is called the
@dfn{event}, and the portions of that line that are acted upon are @dfn{event}, and the portions of that line that are acted upon are
called @dfn{words}. The line is broken into words in the same fashion called @dfn{words}. The line is broken into words in the same fashion
that the Bash shell does, so that several English (or Unix) words that Bash does, so that several English (or Unix) words
surrounded by quotes are considered as one word. surrounded by quotes are considered as one word.
@menu @menu
* Event Designators:: How to specify which history line to use. * Event Designators:: How to specify which history line to use.
* Word Designators:: Specifying which words are of interest. * Word Designators:: Specifying which words are of interest.
* Modifiers:: Modifying the results of susbstitution. * Modifiers:: Modifying the results of substitution.
@end menu @end menu
@node Event Designators @node Event Designators
@ -76,8 +76,8 @@ history list.
@table @asis @table @asis
@item @code{!} @item @code{!}
Start a history subsititution, except when followed by a space, tab, or Start a history substitution, except when followed by a space, tab,
the end of the line... @key{=} or @key{(}. the end of the line, @key{=} or @key{(}.
@item @code{!!} @item @code{!!}
Refer to the previous command. This is a synonym for @code{!-1}. Refer to the previous command. This is a synonym for @code{!-1}.
@ -94,6 +94,14 @@ Refer to the most recent command starting with @var{string}.
@item @code{!?string}[@code{?}] @item @code{!?string}[@code{?}]
Refer to the most recent command containing @var{string}. Refer to the most recent command containing @var{string}.
@item @code{!#}
The entire command line typed so far.
@item @code{^string1^string2^}
Quick Substitution. Repeat the last command, replacing @var{string1}
with @var{string2}. Equivalent to
@code{!!:s/string1/string2/}.
@end table @end table
@node Word Designators @node Word Designators
@ -107,13 +115,13 @@ with the first word being denoted by a 0 (zero).
@table @code @table @code
@item 0 (zero) @item 0 (zero)
The zero'th word. For many applications, this is the command word. The @code{0}th word. For many applications, this is the command word.
@item n @item n
The @var{n}'th word. The @var{n}th word.
@item ^ @item ^
The first argument. that is, word 1. The first argument; that is, word 1.
@item $ @item $
The last argument. The last argument.
@ -122,12 +130,18 @@ The last argument.
The word matched by the most recent @code{?string?} search. The word matched by the most recent @code{?string?} search.
@item x-y @item x-y
A range of words; @code{-@var{y}} Abbreviates @code{0-@var{y}}. A range of words; @code{-@var{y}} abbreviates @code{0-@var{y}}.
@item * @item *
All of the words, excepting the zero'th. This is a synonym for @code{1-$}. All of the words, except the @code{0}th. This is a synonym for @code{1-$}.
It is not an error to use @key{*} if there is just one word in the event. It is not an error to use @key{*} if there is just one word in the event;
The empty string is returned in that case. the empty string is returned in that case.
@item x*
Abbreviates @code{x-$}
@item x-
Abbreviates @code{x-$} like @code{x*}, but omits the last word.
@end table @end table
@ -139,11 +153,6 @@ of the following modifiers, each preceded by a @key{:}.
@table @code @table @code
@item #
The entire command line typed so far. This means the current command,
not the previous command, so it really isn't a word designator, and doesn't
belong in this section.
@item h @item h
Remove a trailing pathname component, leaving only the head. Remove a trailing pathname component, leaving only the head.
@ -151,11 +160,38 @@ Remove a trailing pathname component, leaving only the head.
Remove a trailing suffix of the form @samp{.}@var{suffix}, leaving the basename. Remove a trailing suffix of the form @samp{.}@var{suffix}, leaving the basename.
@item e @item e
Remove all but the suffix. Remove all but the trailing suffix.
@item t @item t
Remove all leading pathname components, leaving the tail. Remove all leading pathname components, leaving the tail.
@item p @item p
Print the new command but do not execute it. Print the new command but do not execute it.
@ifset BashFeatures
@item q
Quote the substituted words, escaping further substitutions.
@item x
Quote the substituted words as with @code{q},
but break into words at spaces, tabs, and newlines.
@end ifset
@item s/old/new/
Substitute @var{new} for the first occurrence of @var{old} in the
event line. Any delimiter may be used in place of @key{/}.
The delimiter may be quoted in @var{old} and @var{new}
with a single backslash. If @key{&} appears in @var{new},
it is replaced by @var{old}. A single backslash will quote
the @key{&}. The final delimiter is optional if it is the last
character on the input line.
@item &
Repeat the previous substitution.
@item g
Cause changes to be applied over the entire event line. Used in
conjunction with @code{s}, as in @code{gs/old/new/}, or with
@code{&}.
@end table @end table

View file

@ -5,14 +5,14 @@
@ignore @ignore
This file documents the end user interface to the GNU command line This file documents the end user interface to the GNU command line
editing feautres. It is to be an appendix to manuals for programs which editing features. It is to be an appendix to manuals for programs which
use these features. There is a document entitled "readline.texinfo" use these features. There is a document entitled "readline.texinfo"
which contains both end-user and programmer documentation for the GNU which contains both end-user and programmer documentation for the GNU
Readline Library. Readline Library.
Copyright (C) 1988 Free Software Foundation, Inc. Copyright (C) 1988 Free Software Foundation, Inc.
Authored by Brian Fox. Authored by Brian Fox and Chet Ramey.
Permission is granted to process this file through Tex and print the Permission is granted to process this file through Tex and print the
results, provided the printed document carries copying permission notice results, provided the printed document carries copying permission notice
@ -39,18 +39,23 @@ into another language, under the above conditions for modified versions.
@node Command Line Editing @node Command Line Editing
@chapter Command Line Editing @chapter Command Line Editing
This text describes GNU's command line editing interface. This chapter describes the basic features of the GNU
command line editing interface.
@menu @menu
* Introduction and Notation:: Notation used in this text. * Introduction and Notation:: Notation used in this text.
* Readline Interaction:: The minimum set of commands for editing a line. * Readline Interaction:: The minimum set of commands for editing a line.
* Readline Init File:: Customizing Readline from a user's view. * Readline Init File:: Customizing Readline from a user's view.
* Bindable Readline Commands:: A description of most of the Readline commands
available for binding
* Readline vi Mode:: A short description of how to make Readline
behave line the vi editor.
@end menu @end menu
@node Introduction and Notation @node Introduction and Notation
@section Introduction to Line Editing @section Introduction to Line Editing
The following paragraphs describe the notation we use to represent The following paragraphs describe the notation used to represent
keystrokes. keystrokes.
The text @key{C-k} is read as `Control-K' and describes the character The text @key{C-k} is read as `Control-K' and describes the character
@ -97,19 +102,19 @@ regardless of the location of the cursor within the line.
In order to enter characters into the line, simply type them. The typed In order to enter characters into the line, simply type them. The typed
character appears where the cursor was, and then the cursor moves one character appears where the cursor was, and then the cursor moves one
space to the right. If you mistype a character, you can use @key{DEL} to space to the right. If you mistype a character, you can use your
back up, and delete the mistyped character. erase character to back up and delete the mistyped character.
Sometimes you may miss typing a character that you wanted to type, and Sometimes you may miss typing a character that you wanted to type, and
not notice your error until you have typed several other characters. In not notice your error until you have typed several other characters. In
that case, you can type @key{C-b} to move the cursor to the left, and then that case, you can type @key{C-b} to move the cursor to the left, and then
correct your mistake. Aftwerwards, you can move the cursor to the right correct your mistake. Afterwards, you can move the cursor to the right
with @key{C-f}. with @key{C-f}.
When you add text in the middle of a line, you will notice that characters When you add text in the middle of a line, you will notice that characters
to the right of the cursor get `pushed over' to make room for the text to the right of the cursor are `pushed over' to make room for the text
that you have inserted. Likewise, when you delete text behind the cursor, that you have inserted. Likewise, when you delete text behind the cursor,
characters to the right of the cursor get `pulled back' to fill in the characters to the right of the cursor are `pulled back' to fill in the
blank space created by the removal of the text. A list of the basic bare blank space created by the removal of the text. A list of the basic bare
essentials for editing the text of an input line follows. essentials for editing the text of an input line follows.
@ -123,7 +128,7 @@ Delete the character to the left of the cursor.
@item @key{C-d} @item @key{C-d}
Delete the character underneath the cursor. Delete the character underneath the cursor.
@item @w{Printing characters} @item @w{Printing characters}
Insert itself into the line at the cursor. Insert the character into the line at the cursor.
@item @key{C-_} @item @key{C-_}
Undo the last thing that you did. You can undo all the way back to an Undo the last thing that you did. You can undo all the way back to an
empty line. empty line.
@ -160,11 +165,19 @@ operate on characters while meta keystrokes operate on words.
@subsection Readline Killing Commands @subsection Readline Killing Commands
@dfn{Killing} text means to delete the text from the line, but to save @dfn{Killing} text means to delete the text from the line, but to save
it away for later use, usually by @dfn{yanking} it back into the line. it away for later use, usually by @dfn{yanking} (re-inserting)
it back into the line.
If the description for a command says that it `kills' text, then you can If the description for a command says that it `kills' text, then you can
be sure that you can get the text back in a different (or the same) be sure that you can get the text back in a different (or the same)
place later. place later.
When you use a kill command, the text is saved in a @dfn{kill-ring}.
Any number of consecutive kills save all of the killed text together, so
that when you yank it back, you get it all. The kill
ring is not line specific; the text that you killed on a previously
typed line is available to be yanked back later, when you are typing
another line.
Here is the list of commands for killing text. Here is the list of commands for killing text.
@table @key @table @key
@ -186,7 +199,7 @@ Kill from the cursor to the previous whitespace. This is different than
@end table @end table
And, here is how to @dfn{yank} the text back into the line. Yanking And, here is how to @dfn{yank} the text back into the line. Yanking
is means to copy the most-recently-killed text from the kill buffer.
@table @key @table @key
@item C-y @item C-y
@ -197,13 +210,6 @@ Rotate the kill-ring, and yank the new top. You can only do this if
the prior command is @key{C-y} or @key{M-y}. the prior command is @key{C-y} or @key{M-y}.
@end table @end table
When you use a kill command, the text is saved in a @dfn{kill-ring}.
Any number of consecutive kills save all of the killed text together, so
that when you yank it back, you get it in one clean sweep. The kill
ring is not line specific; the text that you killed on a previously
typed line is available to be yanked back later, when you are typing
another line.
@node Readline Arguments @node Readline Arguments
@subsection Readline Arguments @subsection Readline Arguments
@ -226,81 +232,155 @@ the @key{C-d} command an argument of 10, you could type @key{M-1 0 C-d}.
@section Readline Init File @section Readline Init File
Although the Readline library comes with a set of Emacs-like Although the Readline library comes with a set of Emacs-like
keybindings, it is possible that you would like to use a different set keybindings installed by default,
it is possible that you would like to use a different set
of keybindings. You can customize programs that use Readline by putting of keybindings. You can customize programs that use Readline by putting
commands in an @dfn{init} file in your home directory. The name of this commands in an @dfn{init} file in your home directory. The name of this
file is @file{~/.inputrc}. file is taken from the value of the shell variable @code{INPUTRC}. If
that variable is unset, the default is @file{~/.inputrc}.
When a program which uses the Readline library starts up, the When a program which uses the Readline library starts up, the
@file{~/.inputrc} file is read, and the keybindings are set. init file is read, and the key bindings are set.
In addition, the @code{C-x C-r} command re-reads this init file, thus In addition, the @code{C-x C-r} command re-reads this init file, thus
incorporating any changes that you might have made to it. incorporating any changes that you might have made to it.
@menu @menu
* Readline Init Syntax:: Syntax for the commands in @file{~/.inputrc}. * Readline Init Syntax:: Syntax for the commands in the inputrc file.
* Readline Vi Mode:: Switching to @code{vi} mode in Readline. * Conditional Init Constructs:: Conditional key bindings in the inputrc file.
@end menu @end menu
@node Readline Init Syntax @node Readline Init Syntax
@subsection Readline Init Syntax @subsection Readline Init Syntax
There are only four constructs allowed in the @file{~/.inputrc} There are only a few basic constructs allowed in the
file: Readline init file. Blank lines are ignored.
Lines beginning with a @key{#} are comments.
Lines beginning with a @key{$} indicate conditional
constructs (@pxref{Conditional Init Constructs}). Other lines
denote variable settings and key bindings.
@table @asis @table @asis
@item Variable Settings @item Variable Settings
You can change the state of a few variables in Readline. You do this by You can change the state of a few variables in Readline by
using the @code{set} command within the init file. Here is how you using the @code{set} command within the init file. Here is how you
would specify that you wish to use Vi line editing commands: would specify that you wish to use @code{vi} line editing commands:
@example @example
set editing-mode vi set editing-mode vi
@end example @end example
Right now, there are only a few variables which can be set; so few in Right now, there are only a few variables which can be set;
fact, that we just iterate them here: so few, in fact, that we just list them here:
@table @code @table @code
@item editing-mode @item editing-mode
@vindex editing-mode @vindex editing-mode
The @code{editing-mode} variable controls which editing mode you are The @code{editing-mode} variable controls which editing mode you are
using. By default, GNU Readline starts up in Emacs editing mode, where using. By default, Readline starts up in Emacs editing mode, where
the keystrokes are most similar to Emacs. This variable can either be the keystrokes are most similar to Emacs. This variable can be
set to @code{emacs} or @code{vi}. set to either @code{emacs} or @code{vi}.
@item horizontal-scroll-mode @item horizontal-scroll-mode
@vindex horizontal-scroll-mode @vindex horizontal-scroll-mode
This variable can either be set to @code{On} or @code{Off}. Setting it This variable can be set to either @code{On} or @code{Off}. Setting it
to @code{On} means that the text of the lines that you edit will scroll to @code{On} means that the text of the lines that you edit will scroll
horizontally on a single screen line when they are larger than the width horizontally on a single screen line when they are longer than the width
of the screen, instead of wrapping onto a new screen line. By default, of the screen, instead of wrapping onto a new screen line. By default,
this variable is set to @code{Off}. this variable is set to @code{Off}.
@item mark-modified-lines @item mark-modified-lines
@vindex mark-modified-lines @vindex mark-modified-lines
This variable when set to @code{On}, says to display an asterisk This variable, when set to @code{On}, says to display an asterisk
(@samp{*}) at the starts of history lines which have been modified. (@samp{*}) at the start of history lines which have been modified.
This variable is off by default. This variable is @code{off} by default.
@item bell-style
@vindex bell-style
Controls what happens when Readline wants to ring the terminal bell.
If set to @code{none}, Readline never rings the bell. If set to
@code{visible}, Readline uses a visible bell if one is available.
If set to @code{audible} (the default), Readline attempts to ring
the terminal's bell.
@item comment-begin
@vindex comment-begin
The string to insert at the beginning of the line when the
@code{vi-comment} command is executed. The default value
is @code{"#"}.
@item meta-flag
@vindex meta-flag
If set to @code{on}, Readline will enable eight-bit input (it
will not strip the eighth bit from the characters it reads),
regardless of what the terminal claims it can support. The
default value is @code{off}.
@item convert-meta
@vindex convert-meta
If set to @code{on}, Readline will convert characters with the
eigth bit set to an ASCII key sequence by stripping the eigth
bit and prepending an @key{ESC} character, converting them to a
meta-prefixed key sequence. The default value is @code{on}.
@item output-meta
@vindex output-meta
If set to @code{on}, Readline will display characters with the
eighth bit set directly rather than as a meta-prefixed escape
sequence. The default is @code{off}.
@item completion-query-items
@vindex completion-query-items
The number of possible completions that determines when the user is
asked whether he wants to see the list of possibilities. If the
number of possible completions is greater than this value,
Readline will ask the user whether or not he wishes to view
them; otherwise, they are simply listed. The default limit is
@code{100}.
@item keymap
@vindex keymap
Sets Readline's idea of the current keymap for key binding commands.
Acceptable @code{keymap} names are
@code{emacs},
@code{emacs-standard},
@code{emacs-meta},
@code{emacs-ctlx},
@code{vi},
@code{vi-move},
@code{vi-command}, and
@code{vi-insert}.
@code{vi} is equivalent to @code{vi-command}; @code{emacs} is
equivalent to @code{emacs-standard}. The default value is @code{emacs}.
The value of the @code{editing-mode} variable also affects the
default keymap.
@item show-all-if-ambiguous
@vindex show-all-if-ambiguous
This alters the default behavior of the completion functions. If
set to @code{on},
words which have more than one possible completion cause the
matches to be listed immediately instead of ringing the bell.
The default value is @code{off}.
@item expand-tilde
@vindex expand-tilde
If set to @code{on}, tilde expansion is performed when Readline
attempts word completion. The default is @code{off}.
@item prefer-visible-bell
@vindex prefer-visible-bell
If this variable is set to @code{On} it means to use a visible bell if
one is available, rather than simply ringing the terminal bell. By
default, the value is @code{Off}.
@end table @end table
@item Key Bindings @item Key Bindings
The syntax for controlling keybindings in the @file{~/.inputrc} file is The syntax for controlling key bindings in the init file is
simple. First you have to know the @i{name} of the command that you simple. First you have to know the name of the command that you
want to change. The following pages contain tables of the command name, want to change. The following pages contain tables of the command name,
the default keybinding, and a short description of what the command the default keybinding, and a short description of what the command
does. does.
Once you know the name of the command, simply place the name of the key Once you know the name of the command, simply place the name of the key
you wish to bind the command to, a colon, and then the name of the you wish to bind the command to, a colon, and then the name of the
command on a line in the @file{~/.inputrc} file. The name of the key command on a line in the init file. The name of the key
can be expressed in different ways, depending on which is most can be expressed in different ways, depending on which is most
comfortable for you. comfortable for you.
@ -319,10 +399,11 @@ expressed on the right hand side (that is, to insert the text
@samp{>&output} into the line). @samp{>&output} into the line).
@item @w{"@var{keyseq}": @var{function-name} or @var{macro}} @item @w{"@var{keyseq}": @var{function-name} or @var{macro}}
@var{keyseq} differs from @var{keyname} above in that strings denoting @var{keyseq} differs from @var{keyname} above in that strings
an entire key sequence can be specified. Simply place the key sequence denoting an entire key sequence can be specified, by placing
in double quotes. GNU Emacs style key escapes can be used, as in the the key sequence in double quotes. Some GNU Emacs style key
following example: escapes can be used, as in the following example, but the
special character names are not recognized.
@example @example
"\C-u": universal-argument "\C-u": universal-argument
@ -334,10 +415,98 @@ In the above example, @samp{C-u} is bound to the function
@code{universal-argument} (just as it was in the first example), @code{universal-argument} (just as it was in the first example),
@samp{C-x C-r} is bound to the function @code{re-read-init-file}, and @samp{C-x C-r} is bound to the function @code{re-read-init-file}, and
@samp{ESC [ 1 1 ~} is bound to insert the text @samp{Function Key 1}. @samp{ESC [ 1 1 ~} is bound to insert the text @samp{Function Key 1}.
The following escape sequences are available when specifying key
sequences:
@table @code
@item @kbd{\C-}
control prefix
@item @kbd{\M-}
meta prefix
@item @kbd{\e}
an escape character
@item @kbd{\\}
backslash
@item @kbd{\"}
@key{"}
@item @kbd{\'}
@key{'}
@end table
When entering the text of a macro, single or double quotes should
be used to indicate a macro definition. Unquoted text
is assumed to be a function name. Backslash
will quote any character in the macro text, including @key{"}
and @key{'}.
For example, the following binding will make @kbd{C-x \}
insert a single @key{\} into the line:
@example
"\C-x\\": "\\"
@end example
@end table @end table
@end table @end table
@node Conditional Init Constructs
@subsection Conditional Init Constructs
Readline implements a facility similar in spirit to the conditional
compilation features of the C preprocessor which allows key
bindings and variable settings to be performed as the result
of tests. There are three parser directives used.
@ftable @code
@item $if
The @code{$if} construct allows bindings to be made based on the
editing mode, the terminal being used, or the application using
Readline. The text of the test extends to the end of the line;
no characters are required to isolate it.
@table @code
@item mode
The @code{mode=} form of the @code{$if} directive is used to test
whether Readline is in @code{emacs} or @code{vi} mode.
This may be used in conjunction
with the @samp{set keymap} command, for instance, to set bindings in
the @code{emacs-standard} and @code{emacs-ctlx} keymaps only if
Readline is starting out in @code{emacs} mode.
@item term
The @code{term=} form may be used to include terminal-specific
key bindings, perhaps to bind the key sequences output by the
terminal's function keys. The word on the right side of the
@samp{=} is tested against the full name of the terminal and the
portion of the terminal name before the first @samp{-}. This
allows @var{sun} to match both @var{sun} and @var{sun-cmd},
for instance.
@item application
The @var{application} construct is used to include
application-specific settings. Each program using the Readline
library sets the @var{application name}, and you can test for it.
This could be used to bind key sequences to functions useful for
a specific program. For instance, the following command adds a
key sequence that quotes the current or previous word in Bash:
@example
$if bash
# Quote the current or previous word
"\C-xq": "\eb\"\ef\""
$endif
@end example
@end table
@item $endif
This command, as you saw in the previous example, terminates an
@code{$if} command.
@item $else
Commands in this branch of the @code{$if} directive are executed if
the test fails.
@end ftable
@node Bindable Readline Commands
@section Bindable Readline Commands
@menu @menu
* Commands For Moving:: Moving about the line. * Commands For Moving:: Moving about the line.
* Commands For History:: Getting at previous lines. * Commands For History:: Getting at previous lines.
@ -345,11 +514,12 @@ In the above example, @samp{C-u} is bound to the function
* Commands For Killing:: Commands for killing and yanking. * Commands For Killing:: Commands for killing and yanking.
* Numeric Arguments:: Specifying numeric arguments, repeat counts. * Numeric Arguments:: Specifying numeric arguments, repeat counts.
* Commands For Completion:: Getting Readline to do the typing for you. * Commands For Completion:: Getting Readline to do the typing for you.
* Miscellaneous Commands:: Other miscillaneous commands. * Keyboard Macros:: Saving and re-executing typed characters
* Miscellaneous Commands:: Other miscellaneous commands.
@end menu @end menu
@node Commands For Moving @node Commands For Moving
@subsubsection Commands For Moving @subsection Commands For Moving
@ftable @code @ftable @code
@item beginning-of-line (C-a) @item beginning-of-line (C-a)
Move to the start of the current line. Move to the start of the current line.
@ -364,24 +534,38 @@ Move forward a character.
Move back a character. Move back a character.
@item forward-word (M-f) @item forward-word (M-f)
Move forward to the end of the next word. Move forward to the end of the next word. Words are composed of
letters and digits.
@item backward-word (M-b) @item backward-word (M-b)
Move back to the start of this, or the previous, word. Move back to the start of this, or the previous, word. Words are
composed of letters and digits.
@item clear-screen (C-l) @item clear-screen (C-l)
Clear the screen leaving the current line at the top of the screen. Clear the screen and redraw the current line,
leaving the current line at the top of the screen.
@item redraw-current-line ()
Refresh the current line. By default, this is unbound.
@end ftable @end ftable
@node Commands For History @node Commands For History
@subsubsection Commands For Manipulating The History @subsection Commands For Manipulating The History
@ftable @code @ftable @code
@item accept-line (Newline, Return) @item accept-line (Newline, Return)
@ifset BashFeatures
Accept the line regardless of where the cursor is. If this line is
non-empty, add it to the history list according to the setting of
the @code{HISTCONTROL} variable. If this line was a history
line, then restore the history line to its original state.
@end ifset
@ifclear BashFeatures
Accept the line regardless of where the cursor is. If this line is Accept the line regardless of where the cursor is. If this line is
non-empty, add it to the history list. If this line was a history non-empty, add it to the history list. If this line was a history
line, then restore the history line to its original state. line, then restore the history line to its original state.
@end ifclear
@item previous-history (C-p) @item previous-history (C-p)
Move `up' through the history list. Move `up' through the history list.
@ -393,7 +577,7 @@ Move `down' through the history list.
Move to the first line in the history. Move to the first line in the history.
@item end-of-history (M->) @item end-of-history (M->)
Move to the end of the input history, i.e., the line you are entering! Move to the end of the input history, i.e., the line you are entering.
@item reverse-search-history (C-r) @item reverse-search-history (C-r)
Search backward starting at the current line and moving `up' through Search backward starting at the current line and moving `up' through
@ -401,17 +585,44 @@ the history as necessary. This is an incremental search.
@item forward-search-history (C-s) @item forward-search-history (C-s)
Search forward starting at the current line and moving `down' through Search forward starting at the current line and moving `down' through
the the history as neccessary. the the history as necessary. This is an incremental search.
@item non-incremental-reverse-search-history (M-p)
Search backward starting at the current line and moving `up'
through the history as necessary using a non-incremental search
for a string supplied by the user.
@item non-incremental-forward-search-history (M-n)
Search forward starting at the current line and moving `down'
through the the history as necessary using a non-incremental search
for a string supplied by the user.
@item history-search-forward ()
Search forward through the history for the string of characters
between the start of the current line and the current point. This
is a non-incremental search. By default, this command is unbound.
@item history-search-backward ()
Search backward through the history for the string of characters
between the start of the current line and the current point. This
is a non-incremental search. By default, this command is unbound.
@item yank-nth-arg (M-C-y)
Insert the first argument to the previous command (usually
the second word on the previous line). With an argument @var{n},
insert the @var{n}th word from the previous command (the words
in the previous command begin with word 0). A negative argument
inserts the @var{n}th word from the end of the previous command.
@end ftable @end ftable
@node Commands For Text @node Commands For Text
@subsubsection Commands For Changing Text @subsection Commands For Changing Text
@ftable @code @ftable @code
@item delete-char (C-d) @item delete-char (C-d)
Delete the character under the cursor. If the cursor is at the Delete the character under the cursor. If the cursor is at the
beginning of the line, and there are no characters in the line, and beginning of the line, there are no characters in the line, and
the last character typed was not C-d, then return EOF. the last character typed was not C-d, then return EOF.
@item backward-delete-char (Rubout) @item backward-delete-char (Rubout)
@ -420,7 +631,7 @@ the characters instead of deleting them.
@item quoted-insert (C-q, C-v) @item quoted-insert (C-q, C-v)
Add the next character that you type to the line verbatim. This is Add the next character that you type to the line verbatim. This is
how to insert things like C-q for example. how to insert key sequences like @key{C-q}, for example.
@item tab-insert (M-TAB) @item tab-insert (M-TAB)
Insert a tab character. Insert a tab character.
@ -429,9 +640,12 @@ Insert a tab character.
Insert yourself. Insert yourself.
@item transpose-chars (C-t) @item transpose-chars (C-t)
Drag the character before point forward over the character at point. Drag the character before the cursor forward over
Point moves forward as well. If point is at the end of the line, then the character at the cursor, moving the
transpose the two characters before point. Negative args don't work. cursor forward as well. If the insertion point
is at the end of the line, then this
transposes the last two characters of the line.
Negative argumentss don't work.
@item transpose-words (M-t) @item transpose-words (M-t)
Drag the word behind the cursor past the word in front of the cursor Drag the word behind the cursor past the word in front of the cursor
@ -439,47 +653,56 @@ moving the cursor over that word as well.
@item upcase-word (M-u) @item upcase-word (M-u)
Uppercase the current (or following) word. With a negative argument, Uppercase the current (or following) word. With a negative argument,
do the previous word, but do not move point. do the previous word, but do not move the cursor.
@item downcase-word (M-l) @item downcase-word (M-l)
Lowercase the current (or following) word. With a negative argument, Lowercase the current (or following) word. With a negative argument,
do the previous word, but do not move point. do the previous word, but do not move the cursor.
@item capitalize-word (M-c) @item capitalize-word (M-c)
Uppercase the current (or following) word. With a negative argument, Capitalize the current (or following) word. With a negative argument,
do the previous word, but do not move point. do the previous word, but do not move the cursor.
@end ftable @end ftable
@node Commands For Killing @node Commands For Killing
@subsubsection Killing And Yanking @subsection Killing And Yanking
@ftable @code @ftable @code
@item kill-line (C-k) @item kill-line (C-k)
Kill the text from the current cursor position to the end of the line. Kill the text from the current cursor position to the end of the line.
@item backward-kill-line () @item backward-kill-line (C-x Rubout)
Kill backward to the beginning of the line. This is normally unbound. Kill backward to the beginning of the line.
@item unix-line-discard (C-u)
Kill backward from the cursor to the beginning of the current line.
Save the killed text on the kill-ring.
@item kill-whole-line ()
Kill all characters on the current line, no matter where the
cursor is. By default, this is unbound.
@item kill-word (M-d) @item kill-word (M-d)
Kill from the cursor to the end of the current word, or if between Kill from the cursor to the end of the current word, or if between
words, to the end of the next word. words, to the end of the next word. Word boundaries are the same
as @code{forward-word}.
@item backward-kill-word (M-DEL) @item backward-kill-word (M-DEL)
Kill the word behind the cursor. Kill the word behind the cursor. Word boundaries are the same
as @code{backward-word}.
@item unix-line-discard (C-u)
Do what C-u used to do in Unix line input. We save the killed text on
the kill-ring, though.
@item unix-word-rubout (C-w) @item unix-word-rubout (C-w)
Do what C-w used to do in Unix line input. The killed text is saved Kill the word behind the cursor, using white space as a word
on the kill-ring. This is different than backward-kill-word because boundary. The killed text is saved on the kill-ring.
the word boundaries differ.
@item delete-horizontal-space ()
Delete all spaces and tabs around point. By default, this is unbound.
@item yank (C-y) @item yank (C-y)
Yank the top of the kill ring into the buffer at point. Yank the top of the kill ring into the buffer at the current
cursor position.
@item yank-pop (M-y) @item yank-pop (M-y)
Rotate the kill-ring, and yank the new top. You can only do this if Rotate the kill-ring, and yank the new top. You can only do this if
@ -487,7 +710,7 @@ the prior command is yank or yank-pop.
@end ftable @end ftable
@node Numeric Arguments @node Numeric Arguments
@subsubsection Specifying Numeric Arguments @subsection Specifying Numeric Arguments
@ftable @code @ftable @code
@item digit-argument (M-0, M-1, ... M--) @item digit-argument (M-0, M-1, ... M--)
@ -495,64 +718,148 @@ Add this digit to the argument already accumulating, or start a new
argument. M-- starts a negative argument. argument. M-- starts a negative argument.
@item universal-argument () @item universal-argument ()
Do what C-u does in emacs. By default, this is not bound. Each time this is executed, the argument count is multiplied by four.
The argument count is initially one, so executing this function the
first time makes the argument count four. By default, this is not
bound to a key.
@end ftable @end ftable
@node Commands For Completion @node Commands For Completion
@subsubsection Letting Readline Type For You @subsection Letting Readline Type For You
@ftable @code @ftable @code
@item complete (TAB) @item complete (TAB)
Attempt to do completion on the text before point. This is Attempt to do completion on the text before the cursor. This is
implementation defined. Generally, if you are typing a filename implementation defined. Generally, if you are typing a filename
argument, you can do filename completion; if you are typing a command, argument, you can do filename completion; if you are typing a command,
you can do command completion, if you are typing in a symbol to GDB, you you can do command completion, if you are typing in a symbol to GDB, you
can do symbol name completion, if you are typing in a variable to Bash, can do symbol name completion, if you are typing in a variable to Bash,
you can do variable name completion... you can do variable name completion, and so on.
@ifset BashFeatures
See the Bash manual page for a complete list of available completion
functions.
@end ifset
@item possible-completions (M-?) @item possible-completions (M-?)
List the possible completions of the text before point. List the possible completions of the text before the cursor.
@item insert-completions ()
Insert all completions of the text before point that would have
been generated by @code{possible-completions}. By default, this
is not bound to a key.
@end ftable
@node Keyboard Macros
@subsection Keyboard Macros
@ftable @code
@item start-kbd-macro (C-x ()
Begin saving the characters typed into the current keyboard macro.
@item end-kbd-macro (C-x ))
Stop saving the characters typed into the current keyboard macro
and save the definition.
@item call-last-kbd-macro (C-x e)
Re-execute the last keyboard macro defined, by making the characters
in the macro appear as if typed at the keyboard.
@end ftable @end ftable
@node Miscellaneous Commands @node Miscellaneous Commands
@subsubsection Some Miscellaneous Commands @subsection Some Miscellaneous Commands
@ftable @code @ftable @code
@item re-read-init-file (C-x C-r) @item re-read-init-file (C-x C-r)
Read in the contents of your @file{~/.inputrc} file, and incorporate Read in the contents of your init file, and incorporate
any bindings found there. any bindings or variable assignments found there.
@item abort (C-g) @item abort (C-g)
Ding! Stops things. Abort the current editing command and
ring the terminal's bell (subject to the setting of
@code{bell-style}).
@item do-uppercase-version (M-a, M-b, ...) @item do-uppercase-version (M-a, M-b, ...)
Run the command that is bound to your uppercase brother. Run the command that is bound to the corresoponding uppercase
character.
@item prefix-meta (ESC) @item prefix-meta (ESC)
Make the next character that you type be metafied. This is for people Make the next character that you type be metafied. This is for people
without a meta key. Typing @samp{ESC f} is equivalent to typing without a meta key. Typing @samp{ESC f} is equivalent to typing
@samp{M-f}. @samp{M-f}.
@item undo (C-_) @item undo (C-_, C-x C-u)
Incremental undo, separately remembered for each line. Incremental undo, separately remembered for each line.
@item revert-line (M-r) @item revert-line (M-r)
Undo all changes made to this line. This is like typing the `undo' Undo all changes made to this line. This is like typing the @code{undo}
command enough times to get back to the beginning. command enough times to get back to the beginning.
@item tilde-expand (M-~)
Perform tilde expansion on the current word.
@item dump-functions ()
Print all of the functions and their key bindings to the
readline output stream. If a numeric argument is supplied,
the output is formatted in such a way that it can be made part
of an @var{inputrc} file.
@ifset BashFeatures
@item display-shell-version (C-x C-v)
Display version information about the current instance of Bash.
@item shell-expand-line (M-C-e)
Expand the line the way the shell does when it reads it. This
performs alias and history expansion as well as all of the shell
word expansions.
@item history-expand-line (M-^)
Perform history expansion on the current line.
@item insert-last-argument (M-., M-_)
Insert the last argument to the previous command (the last word on
the previous line). With an argument @var{n},
insert the @var{n}th word from the previous command (the words
in the previous command begin with word 0). A negative argument
inserts the @var{n}th word from the end of the previous command.
@item operate-and-get-next (C-o)
Accept the current line for execution and fetch the next line
relative to the current line from the history for editing. Any
argument is ignored.
@item emacs-editing-mode (C-e)
When in @code{vi} editing mode, this causes a switch back to
emacs editing mode, as if the command @code{set -o emacs} had
been executed.
@end ifset
@end ftable @end ftable
@node Readline Vi Mode @node Readline vi Mode
@subsection Readline Vi Mode @section Readline vi Mode
While the Readline library does not have a full set of Vi editing While the Readline library does not have a full set of @code{vi}
functions, it does contain enough to allow simple editing of the line. editing functions, it does contain enough to allow simple editing
of the line. The Readline @code{vi} mode behaves as specified in
the Posix 1003.2 standard.
In order to switch interactively between Emacs and Vi editing modes, use @ifset BashFeatures
the command M-C-j (toggle-editing-mode). In order to switch interactively between @code{Emacs} and @code{Vi}
editing modes, use the @code{set -o emacs} and @code{set -o vi}
commands (@pxref{The Set Builtin}).
@end ifset
@ifclear BashFeatures
In order to switch interactively between @code{Emacs} and @code{Vi}
editing modes, use the command M-C-j (toggle-editing-mode).
@end ifclear
The Readline default is @code{emacs} mode.
When you enter a line in Vi mode, you are already placed in `insertion' When you enter a line in @code{vi} mode, you are already placed in
mode, as if you had typed an `i'. Pressing @key{ESC} switches you into `insertion' mode, as if you had typed an @samp{i}. Pressing @key{ESC}
`edit' mode, where you can edit the text of the line with the standard switches you into `command' mode, where you can edit the text of the
Vi movement keys, move to previous history lines with `k', and following line with the standard @code{vi} movement keys, move to previous
lines with `j', and so forth. history lines with @samp{k}, and following lines with @samp{j}, and
so forth.

File diff suppressed because it is too large Load diff

View file

@ -322,7 +322,7 @@ KEYMAP_ENTRY_ARRAY emacs_standard_keymap = {
{ ISFUNC, rl_insert }, /* Latin small letter y with acute */ { ISFUNC, rl_insert }, /* Latin small letter y with acute */
{ ISFUNC, rl_insert }, /* Latin small letter thorn (Icelandic) */ { ISFUNC, rl_insert }, /* Latin small letter thorn (Icelandic) */
{ ISFUNC, rl_insert } /* Latin small letter y with diaeresis */ { ISFUNC, rl_insert } /* Latin small letter y with diaeresis */
#endif /* MEYMAP_SIZE > 128 */ #endif /* KEYMAP_SIZE > 128 */
}; };
KEYMAP_ENTRY_ARRAY emacs_meta_keymap = { KEYMAP_ENTRY_ARRAY emacs_meta_keymap = {
@ -336,7 +336,7 @@ KEYMAP_ENTRY_ARRAY emacs_meta_keymap = {
{ ISFUNC, (Function *)0x0 }, /* Meta-Control-e */ { ISFUNC, (Function *)0x0 }, /* Meta-Control-e */
{ ISFUNC, (Function *)0x0 }, /* Meta-Control-f */ { ISFUNC, (Function *)0x0 }, /* Meta-Control-f */
{ ISFUNC, rl_abort }, /* Meta-Control-g */ { ISFUNC, rl_abort }, /* Meta-Control-g */
{ ISFUNC, (Function *)0x0 }, /* Meta-Control-h */ { ISFUNC, rl_backward_kill_word }, /* Meta-Control-h */
{ ISFUNC, rl_tab_insert }, /* Meta-Control-i */ { ISFUNC, rl_tab_insert }, /* Meta-Control-i */
{ ISFUNC, rl_vi_editing_mode }, /* Meta-Control-j */ { ISFUNC, rl_vi_editing_mode }, /* Meta-Control-j */
{ ISFUNC, (Function *)0x0 }, /* Meta-Control-k */ { ISFUNC, (Function *)0x0 }, /* Meta-Control-k */
@ -356,7 +356,7 @@ KEYMAP_ENTRY_ARRAY emacs_meta_keymap = {
{ ISFUNC, rl_yank_nth_arg }, /* Meta-Control-y */ { ISFUNC, rl_yank_nth_arg }, /* Meta-Control-y */
{ ISFUNC, (Function *)0x0 }, /* Meta-Control-z */ { ISFUNC, (Function *)0x0 }, /* Meta-Control-z */
{ ISFUNC, (Function *)0x0 }, /* Meta-Control-[ */ { ISFUNC, rl_complete }, /* Meta-Control-[ */
{ ISFUNC, (Function *)0x0 }, /* Meta-Control-\ */ { ISFUNC, (Function *)0x0 }, /* Meta-Control-\ */
{ ISFUNC, (Function *)0x0 }, /* Meta-Control-] */ { ISFUNC, (Function *)0x0 }, /* Meta-Control-] */
{ ISFUNC, (Function *)0x0 }, /* Meta-Control-^ */ { ISFUNC, (Function *)0x0 }, /* Meta-Control-^ */
@ -469,7 +469,7 @@ KEYMAP_ENTRY_ARRAY emacs_meta_keymap = {
{ ISFUNC, (Function *)0x0 }, /* Meta-{ */ { ISFUNC, (Function *)0x0 }, /* Meta-{ */
{ ISFUNC, (Function *)0x0 }, /* Meta-| */ { ISFUNC, (Function *)0x0 }, /* Meta-| */
{ ISFUNC, (Function *)0x0 }, /* Meta-} */ { ISFUNC, (Function *)0x0 }, /* Meta-} */
{ ISFUNC, (Function *)0x0 }, /* Meta-~ */ { ISFUNC, rl_tilde_expand }, /* Meta-~ */
{ ISFUNC, rl_backward_kill_word }, /* Meta-rubout */ { ISFUNC, rl_backward_kill_word }, /* Meta-rubout */
#if KEYMAP_SIZE > 128 #if KEYMAP_SIZE > 128

View file

@ -36,6 +36,7 @@ extern char *xmalloc (), *xrealloc ();
# include "ansi_stdlib.h" # include "ansi_stdlib.h"
#endif /* HAVE_STDLIB_H */ #endif /* HAVE_STDLIB_H */
#include "rlconf.h"
#include "readline.h" #include "readline.h"
FUNMAP **funmap = (FUNMAP **)NULL; FUNMAP **funmap = (FUNMAP **)NULL;
@ -68,18 +69,24 @@ static FUNMAP default_funmap[] = {
{ "do-lowercase-version", rl_do_lowercase_version }, { "do-lowercase-version", rl_do_lowercase_version },
{ "downcase-word", rl_downcase_word }, { "downcase-word", rl_downcase_word },
{ "dump-functions", rl_dump_functions }, { "dump-functions", rl_dump_functions },
{ "emacs-editing-mode", rl_emacs_editing_mode },
{ "end-kbd-macro", rl_end_kbd_macro }, { "end-kbd-macro", rl_end_kbd_macro },
{ "end-of-history", rl_end_of_history }, { "end-of-history", rl_end_of_history },
{ "end-of-line", rl_end_of_line }, { "end-of-line", rl_end_of_line },
{ "forward-char", rl_forward }, { "forward-char", rl_forward },
{ "forward-search-history", rl_forward_search_history }, { "forward-search-history", rl_forward_search_history },
{ "forward-word", rl_forward_word }, { "forward-word", rl_forward_word },
{ "history-search-backward", rl_history_search_backward },
{ "history-search-forward", rl_history_search_forward },
{ "insert-completions", rl_insert_completions }, { "insert-completions", rl_insert_completions },
{ "kill-whole-line", rl_kill_full_line },
{ "kill-line", rl_kill_line }, { "kill-line", rl_kill_line },
{ "kill-word", rl_kill_word }, { "kill-word", rl_kill_word },
{ "next-history", rl_get_next_history }, { "next-history", rl_get_next_history },
{ "non-incremental-forward-search-history", rl_noninc_forward_search }, { "non-incremental-forward-search-history", rl_noninc_forward_search },
{ "non-incremental-reverse-search-history", rl_noninc_reverse_search }, { "non-incremental-reverse-search-history", rl_noninc_reverse_search },
{ "non-incremental-forward-search-history-again", rl_noninc_forward_search_again },
{ "non-incremental-reverse-search-history-again", rl_noninc_reverse_search_again },
{ "possible-completions", rl_possible_completions }, { "possible-completions", rl_possible_completions },
{ "previous-history", rl_get_previous_history }, { "previous-history", rl_get_previous_history },
{ "quoted-insert", rl_quoted_insert }, { "quoted-insert", rl_quoted_insert },
@ -90,6 +97,7 @@ static FUNMAP default_funmap[] = {
{ "self-insert", rl_insert }, { "self-insert", rl_insert },
{ "start-kbd-macro", rl_start_kbd_macro }, { "start-kbd-macro", rl_start_kbd_macro },
{ "tab-insert", rl_tab_insert }, { "tab-insert", rl_tab_insert },
{ "tilde-expand", rl_tilde_expand },
{ "transpose-chars", rl_transpose_chars }, { "transpose-chars", rl_transpose_chars },
{ "transpose-words", rl_transpose_words }, { "transpose-words", rl_transpose_words },
{ "undo", rl_undo_command }, { "undo", rl_undo_command },
@ -102,7 +110,6 @@ static FUNMAP default_funmap[] = {
{ "yank-pop", rl_yank_pop }, { "yank-pop", rl_yank_pop },
#if defined (VI_MODE) #if defined (VI_MODE)
{ "vi-append-eol", rl_vi_append_eol }, { "vi-append-eol", rl_vi_append_eol },
{ "vi-append-mode", rl_vi_append_mode }, { "vi-append-mode", rl_vi_append_mode },
{ "vi-arg-digit", rl_vi_arg_digit }, { "vi-arg-digit", rl_vi_arg_digit },
@ -135,10 +142,12 @@ static FUNMAP default_funmap[] = {
{ "vi-overstrike-delete", rl_vi_overstrike_delete }, { "vi-overstrike-delete", rl_vi_overstrike_delete },
{ "vi-prev-word", rl_vi_prev_word }, { "vi-prev-word", rl_vi_prev_word },
{ "vi-put", rl_vi_put }, { "vi-put", rl_vi_put },
{ "vi-redo", rl_vi_redo },
{ "vi-replace", rl_vi_replace }, { "vi-replace", rl_vi_replace },
{ "vi-search", rl_vi_search }, { "vi-search", rl_vi_search },
{ "vi-search-again", rl_vi_search_again }, { "vi-search-again", rl_vi_search_again },
{ "vi-subst", rl_vi_subst }, { "vi-subst", rl_vi_subst },
{ "vi-tilde-expand", rl_vi_tilde_expand },
{ "vi-yank-arg", rl_vi_yank_arg }, { "vi-yank-arg", rl_vi_yank_arg },
{ "vi-yank-to", rl_vi_yank_to }, { "vi-yank-to", rl_vi_yank_to },
@ -163,6 +172,7 @@ rl_add_funmap_entry (name, function)
funmap[funmap_entry]->function = function; funmap[funmap_entry]->function = function;
funmap[++funmap_entry] = (FUNMAP *)NULL; funmap[++funmap_entry] = (FUNMAP *)NULL;
return funmap_entry;
} }
static int funmap_initialized = 0; static int funmap_initialized = 0;

File diff suppressed because it is too large Load diff

View file

@ -27,27 +27,27 @@
#include <stdio.h> #include <stdio.h>
#if defined (__GNUC__) #include "memalloc.h"
# define alloca __builtin_alloca
#else
# if defined (sparc) || defined (HAVE_ALLOCA_H)
# include <alloca.h>
# endif
#endif
#include "readline.h" #include "readline.h"
#include "history.h" #include "history.h"
#define STREQ(a, b) (((a)[0] == (b)[0]) && (strcmp ((a), (b)) == 0))
#define STREQN(a, b, n) (((a)[0] == (b)[0]) && (strncmp ((a), (b), (n)) == 0))
/* Variables imported from other files in the readline library. */
extern Keymap _rl_keymap; extern Keymap _rl_keymap;
extern HIST_ENTRY *saved_line_for_history; extern HIST_ENTRY *saved_line_for_history;
extern int rl_line_buffer_len; extern int rl_line_buffer_len;
extern int rl_point, rl_end; extern int rl_point, rl_end;
extern char *rl_prompt, *rl_line_buffer; extern char *rl_line_buffer;
/* Remove these declarations when we have a complete libgnu.a. */
extern char *xmalloc (), *xrealloc (); extern char *xmalloc (), *xrealloc ();
static void rl_search_history (); static int rl_search_history ();
/* Last line found by the current incremental search, so we don't `find'
identical lines many times in a row. */
static char *prev_line_found;
/* Search backwards through the history looking for a string which is typed /* Search backwards through the history looking for a string which is typed
interactively. Start with the current line. */ interactively. Start with the current line. */
@ -55,7 +55,7 @@ rl_reverse_search_history (sign, key)
int sign; int sign;
int key; int key;
{ {
rl_search_history (-sign, key); return (rl_search_history (-sign, key));
} }
/* Search forwards through the history looking for a string which is typed /* Search forwards through the history looking for a string which is typed
@ -64,7 +64,7 @@ rl_forward_search_history (sign, key)
int sign; int sign;
int key; int key;
{ {
rl_search_history (sign, key); return (rl_search_history (sign, key));
} }
/* Display the current state of the search in the echo-area. /* Display the current state of the search in the echo-area.
@ -77,11 +77,9 @@ rl_display_search (search_string, reverse_p, where)
char *search_string; char *search_string;
int reverse_p, where; int reverse_p, where;
{ {
char *message = (char *)NULL; char *message;
message =
(char *)xmalloc (1 + (search_string ? strlen (search_string) : 0) + 30);
message = xmalloc (1 + (search_string ? strlen (search_string) : 0) + 30);
*message = '\0'; *message = '\0';
#if defined (NOTDEF) #if defined (NOTDEF)
@ -109,7 +107,7 @@ rl_display_search (search_string, reverse_p, where)
This is analogous to i-search. We start the search in the current line. This is analogous to i-search. We start the search in the current line.
DIRECTION is which direction to search; >= 0 means forward, < 0 means DIRECTION is which direction to search; >= 0 means forward, < 0 means
backwards. */ backwards. */
static void static int
rl_search_history (direction, invoking_key) rl_search_history (direction, invoking_key)
int direction; int direction;
int invoking_key; int invoking_key;
@ -124,7 +122,7 @@ rl_search_history (direction, invoking_key)
int search_string_size; int search_string_size;
/* The list of lines to search through. */ /* The list of lines to search through. */
char **lines; char **lines, *allocated_line = (char *)NULL;
/* The length of LINES. */ /* The length of LINES. */
int hlen; int hlen;
@ -136,13 +134,13 @@ rl_search_history (direction, invoking_key)
int orig_point = rl_point; int orig_point = rl_point;
int orig_line = where_history (); int orig_line = where_history ();
int last_found_line = orig_line; int last_found_line = orig_line;
int c, done = 0; int c, done = 0, found, failed, sline_len;
/* The line currently being searched. */ /* The line currently being searched. */
char *sline; char *sline;
/* Offset in that line. */ /* Offset in that line. */
int index; int line_index;
/* Non-zero if we are doing a reverse search. */ /* Non-zero if we are doing a reverse search. */
int reverse = (direction < 0); int reverse = (direction < 0);
@ -154,21 +152,18 @@ rl_search_history (direction, invoking_key)
/* Allocate space for this many lines, +1 for the current input line, /* Allocate space for this many lines, +1 for the current input line,
and remember those lines. */ and remember those lines. */
lines = (char **)alloca ((1 + (hlen = i)) * sizeof (char *)); lines = (char **)xmalloc ((1 + (hlen = i)) * sizeof (char *));
for (i = 0; i < hlen; i++) for (i = 0; i < hlen; i++)
lines[i] = hlist[i]->line; lines[i] = hlist[i]->line;
if (saved_line_for_history) if (saved_line_for_history)
lines[i] = saved_line_for_history->line; lines[i] = saved_line_for_history->line;
else else
/* So I have to type it in this way instead. */
{ {
char *alloced_line; /* Keep track of this so we can free it. */
allocated_line = xmalloc (1 + strlen (rl_line_buffer));
/* Keep that MIPS alloca () happy. */ strcpy (allocated_line, &rl_line_buffer[0]);
alloced_line = (char *)alloca (1 + strlen (rl_line_buffer)); lines[i] = allocated_line;
lines[i] = alloced_line;
strcpy (lines[i], &rl_line_buffer[0]);
} }
hlen++; hlen++;
@ -177,39 +172,37 @@ rl_search_history (direction, invoking_key)
i = orig_line; i = orig_line;
/* Initialize search parameters. */ /* Initialize search parameters. */
search_string = (char *)xmalloc (search_string_size = 128); search_string = xmalloc (search_string_size = 128);
*search_string = '\0'; *search_string = '\0';
search_string_index = 0; search_string_index = 0;
/* Normalize DIRECTION into 1 or -1. */ /* Normalize DIRECTION into 1 or -1. */
if (direction >= 0) direction = (direction >= 0) ? 1 : -1;
direction = 1;
else
direction = -1;
rl_display_search (search_string, reverse, -1); rl_display_search (search_string, reverse, -1);
sline = rl_line_buffer; sline = rl_line_buffer;
index = rl_point; sline_len = strlen (sline);
line_index = rl_point;
found = failed = 0;
while (!done) while (!done)
{ {
Function *f = (Function *)NULL;
/* Read a key and decide how to proceed. */
c = rl_read_key (); c = rl_read_key ();
/* Hack C to Do What I Mean. */ /* Hack C to Do What I Mean. */
{ if (_rl_keymap[c].type == ISFUNC)
Function *f = (Function *)NULL; {
f = _rl_keymap[c].function;
if (_rl_keymap[c].type == ISFUNC) if (f == rl_reverse_search_history)
{ c = reverse ? -1 : -2;
f = _rl_keymap[c].function; else if (f == rl_forward_search_history)
c = !reverse ? -1 : -2;
if (f == rl_reverse_search_history) }
c = reverse ? -1 : -2;
else if (f == rl_forward_search_history)
c = !reverse ? -1 : -2;
}
}
switch (c) switch (c)
{ {
@ -217,22 +210,36 @@ rl_search_history (direction, invoking_key)
done = 1; done = 1;
continue; continue;
/* case invoking_key: */
case -1: case -1:
goto search_again; if (!search_string_index)
continue;
else
{
if (reverse)
--line_index;
else
{
if (line_index != sline_len)
++line_index;
else
ding ();
}
}
break;
/* switch directions */ /* switch directions */
case -2: case -2:
direction = -direction; direction = -direction;
reverse = (direction < 0); reverse = (direction < 0);
break;
goto do_search;
case CTRL ('G'): case CTRL ('G'):
strcpy (rl_line_buffer, lines[orig_line]); strcpy (rl_line_buffer, lines[orig_line]);
rl_point = orig_point; rl_point = orig_point;
rl_end = strlen (rl_line_buffer); rl_end = strlen (rl_line_buffer);
rl_clear_message (); rl_clear_message ();
free (allocated_line);
free (lines);
return; return;
default: default:
@ -244,134 +251,122 @@ rl_search_history (direction, invoking_key)
} }
else else
{ {
/* Add character to search string and continue search. */
if (search_string_index + 2 >= search_string_size) if (search_string_index + 2 >= search_string_size)
search_string = (char *)xrealloc {
(search_string, (search_string_size += 128)); search_string_size += 128;
search_string = xrealloc (search_string, search_string_size);
}
search_string[search_string_index++] = c; search_string[search_string_index++] = c;
search_string[search_string_index] = '\0'; search_string[search_string_index] = '\0';
goto do_search;
search_again:
if (!search_string_index)
continue;
else
{
if (reverse)
--index;
else
if (index != strlen (sline))
++index;
else
ding ();
}
do_search:
while (1)
{
if (reverse)
{
while (index >= 0)
if (strncmp
(search_string, sline + index, search_string_index)
== 0)
goto string_found;
else
index--;
}
else
{
register int limit =
(strlen (sline) - search_string_index) + 1;
while (index < limit)
{
if (strncmp (search_string,
sline + index,
search_string_index) == 0)
goto string_found;
index++;
}
}
next_line:
i += direction;
/* At limit for direction? */
if ((reverse && i < 0) ||
(!reverse && i == hlen))
goto search_failed;
sline = lines[i];
if (reverse)
index = strlen (sline);
else
index = 0;
/* If the search string is longer than the current
line, no match. */
if (search_string_index > (int)strlen (sline))
goto next_line;
/* Start actually searching. */
if (reverse)
index -= search_string_index;
}
search_failed:
/* We cannot find the search string. Ding the bell. */
ding ();
i = last_found_line;
break; break;
string_found:
/* We have found the search string. Just display it. But don't
actually move there in the history list until the user accepts
the location. */
{
int line_len;
line_len = strlen (lines[i]);
if (line_len >= rl_line_buffer_len)
rl_extend_line_buffer (line_len);
strcpy (rl_line_buffer, lines[i]);
rl_point = index;
rl_end = line_len;
last_found_line = i;
rl_display_search
(search_string, reverse, (i == orig_line) ? -1 : i);
}
} }
} }
found = failed = 0;
while (1)
{
int limit = sline_len - search_string_index + 1;
/* Search the current line. */
while (reverse ? (line_index >= 0) : (line_index < limit))
{
if (STREQN(search_string, sline + line_index, search_string_index))
{
found++;
break;
}
else
line_index += reverse ? -1 : 1;
}
if (found)
break;
/* Move to the next line, but skip new copies of the line
we just found and lines shorter than the string we're
searching for. */
do
{
/* Move to the next line. */
i += direction;
/* At limit for direction? */
if ((reverse && i < 0) || (!reverse && i == hlen))
{
failed++;
break;
}
/* We will need these later. */
sline = lines[i];
sline_len = strlen (sline);
}
while ((prev_line_found && STREQ (prev_line_found, lines[i])) ||
(search_string_index > sline_len));
if (failed)
break;
/* Now set up the line for searching... */
if (reverse)
line_index = sline_len - search_string_index;
else
line_index = 0;
}
if (failed)
{
/* We cannot find the search string. Ding the bell. */
ding ();
i = last_found_line;
break;
}
/* We have found the search string. Just display it. But don't
actually move there in the history list until the user accepts
the location. */
if (found)
{
int line_len;
prev_line_found = lines[i];
line_len = strlen (lines[i]);
if (line_len >= rl_line_buffer_len)
rl_extend_line_buffer (line_len);
strcpy (rl_line_buffer, lines[i]);
rl_point = line_index;
rl_end = line_len;
last_found_line = i;
rl_display_search (search_string, reverse, (i == orig_line) ? -1 : i);
}
} }
/* The searching is over. The user may have found the string that she /* The searching is over. The user may have found the string that she
was looking for, or else she may have exited a failing search. If was looking for, or else she may have exited a failing search. If
INDEX is -1, then that shows that the string searched for was not LINE_INDEX is -1, then that shows that the string searched for was
found. We use this to determine where to place rl_point. */ not found. We use this to determine where to place rl_point. */
{
int now = last_found_line;
/* First put back the original state. */ /* First put back the original state. */
strcpy (rl_line_buffer, lines[orig_line]); strcpy (rl_line_buffer, lines[orig_line]);
/* Free the search string. */ /* Free the search string. */
free (search_string); free (search_string);
if (now < orig_line) if (last_found_line < orig_line)
rl_get_previous_history (orig_line - now); rl_get_previous_history (orig_line - last_found_line);
else else
rl_get_next_history (now - orig_line); rl_get_next_history (last_found_line - orig_line);
/* If the index of the "matched" string is less than zero, then the /* If the string was not found, put point at the end of the line. */
final search string was never matched, so put point somewhere if (line_index < 0)
reasonable. */ line_index = strlen (rl_line_buffer);
if (index < 0) rl_point = line_index;
index = strlen (rl_line_buffer); rl_clear_message ();
rl_point = index; free (allocated_line);
rl_clear_message (); free (lines);
}
return 0;
} }

View file

@ -25,6 +25,7 @@
# include "ansi_stdlib.h" # include "ansi_stdlib.h"
#endif /* HAVE_STDLIB_H */ #endif /* HAVE_STDLIB_H */
#include "rlconf.h"
#include "keymaps.h" #include "keymaps.h"
#include "emacs_keymap.c" #include "emacs_keymap.c"
@ -32,6 +33,9 @@
#include "vi_keymap.c" #include "vi_keymap.c"
#endif #endif
extern int rl_do_lowercase_version ();
extern int rl_rubout (), rl_insert ();
#if defined (STATIC_MALLOC) #if defined (STATIC_MALLOC)
static char *xmalloc (), *xrealloc (); static char *xmalloc (), *xrealloc ();
#else #else
@ -90,7 +94,6 @@ rl_copy_keymap (map)
Keymap Keymap
rl_make_keymap () rl_make_keymap ()
{ {
extern int rl_insert (), rl_rubout ();
register int i; register int i;
Keymap newmap; Keymap newmap;
@ -118,6 +121,7 @@ rl_make_keymap ()
} }
/* Free the storage associated with MAP. */ /* Free the storage associated with MAP. */
void
rl_discard_keymap (map) rl_discard_keymap (map)
Keymap (map); Keymap (map);
{ {

View file

@ -0,0 +1,56 @@
/* memalloc.h -- consolidate code for including alloca.h or malloc.h and
defining alloca. */
/* Copyright (C) 1993 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash 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.
Bash 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 Bash; see the file COPYING. If not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#if !defined (__MEMALLOC_H__)
# define __MEMALLOC_H__
#if defined (sparc) && defined (sun) && !defined (HAVE_ALLOCA_H)
# define HAVE_ALLOCA_H
#endif
#if defined (__GNUC__) && !defined (HAVE_ALLOCA)
# define HAVE_ALLOCA
#endif
#if defined (HAVE_ALLOCA_H) && !defined (HAVE_ALLOCA)
# define HAVE_ALLOCA
#endif /* HAVE_ALLOCA_H && !HAVE_ALLOCA */
#if !defined (BUILDING_MAKEFILE)
#if defined (__GNUC__)
# undef alloca
# define alloca __builtin_alloca
#else /* !__GNUC__ */
# if defined (HAVE_ALLOCA_H)
# if defined (IBMESA)
# include <malloc.h>
# else /* !IBMESA */
# include <alloca.h>
# endif /* !IBMESA */
# else
extern char *alloca ();
# endif /* !HAVE_ALLOCA_H */
#endif /* !__GNUC__ */
#endif /* !BUILDING_MAKEFILE */
#endif /* __MEMALLOC_H__ */

View file

@ -27,6 +27,8 @@
#endif #endif
#include "readline.h" #include "readline.h"
extern int rl_explicit_arg;
/* Non-zero means try to blink the matching open parenthesis when the /* Non-zero means try to blink the matching open parenthesis when the
close parenthesis is inserted. */ close parenthesis is inserted. */
#if defined (FD_SET) #if defined (FD_SET)
@ -40,8 +42,6 @@ static int find_matching_open ();
rl_insert_close (count, invoking_key) rl_insert_close (count, invoking_key)
int count, invoking_key; int count, invoking_key;
{ {
extern int rl_explicit_arg;
if (rl_explicit_arg || !rl_blink_matching_paren) if (rl_explicit_arg || !rl_blink_matching_paren)
rl_insert (count, invoking_key); rl_insert (count, invoking_key);
else else
@ -58,7 +58,7 @@ rl_insert_close (count, invoking_key)
/* Emacs might message or ring the bell here, but I don't. */ /* Emacs might message or ring the bell here, but I don't. */
if (match_point < 0) if (match_point < 0)
return; return -1;
FD_ZERO (&readfds); FD_ZERO (&readfds);
FD_SET (fileno (rl_instream), &readfds); FD_SET (fileno (rl_instream), &readfds);
@ -74,6 +74,7 @@ rl_insert_close (count, invoking_key)
rl_insert (count, invoking_key); rl_insert (count, invoking_key);
#endif /* !FD_SET */ #endif /* !FD_SET */
} }
return 0;
} }
static int static int

File diff suppressed because it is too large Load diff

View file

@ -32,19 +32,23 @@ extern char *xmalloc ();
#define UNMETA(c) ((c) & (~meta_character_bit)) #define UNMETA(c) ((c) & (~meta_character_bit))
#define UNCTRL(c) to_upper(((c)|control_character_bit)) #define UNCTRL(c) to_upper(((c)|control_character_bit))
#define lowercase_p(c) (((c) > ('a' - 1) && (c) < ('z' + 1))) #define lowercase_p(c) islower(c)
#define uppercase_p(c) (((c) > ('A' - 1) && (c) < ('Z' + 1))) #define uppercase_p(c) isupper(c)
#define pure_alphabetic(c) (lowercase_p(c) || uppercase_p(c)) #define pure_alphabetic(c) isalpha(c)
#ifndef to_upper #ifndef to_upper
#define to_upper(c) (lowercase_p(c) ? ((c) - 32) : (c)) #define to_upper(c) toupper(c)
#define to_lower(c) (uppercase_p(c) ? ((c) + 32) : (c)) #define to_lower(c) tolower(c)
#endif #endif
#define CTRL_P(c) ((c) < control_character_threshold) #define CTRL_P(c) ((c) < control_character_threshold)
#define META_P(c) ((c) > meta_character_threshold) #define META_P(c) ((c) > meta_character_threshold)
#ifndef digit_value
#define digit_value(x) ((x) - '0')
#endif
#ifndef NEWLINE #ifndef NEWLINE
#define NEWLINE '\n' #define NEWLINE '\n'
#endif #endif
@ -54,7 +58,7 @@ extern char *xmalloc ();
#endif #endif
#ifndef RUBOUT #ifndef RUBOUT
#define RUBOUT 0x07f #define RUBOUT 0x7f
#endif #endif
#ifndef TAB #ifndef TAB
@ -74,7 +78,7 @@ extern char *xmalloc ();
#ifdef SPACE #ifdef SPACE
#undef SPACE #undef SPACE
#endif #endif
#define SPACE 0x020 #define SPACE 0x20
#ifdef ESC #ifdef ESC
#undef ESC #undef ESC

View file

@ -125,6 +125,10 @@ extern int history_search ();
error message. */ error message. */
extern int history_expand (); extern int history_expand ();
/* Return an array of tokens, much as the shell might. The tokens are
parsed out of STRING. */
extern char **history_tokenize ();
/* Extract a string segment consisting of the FIRST through LAST /* Extract a string segment consisting of the FIRST through LAST
arguments present in STRING. Arguments are broken up as in arguments present in STRING. Arguments are broken up as in
the shell. */ the shell. */
@ -133,3 +137,13 @@ extern char *history_arg_extract ();
/* Return the number of bytes that the primary history entries are using. /* Return the number of bytes that the primary history entries are using.
This just adds up the lengths of the_history->lines. */ This just adds up the lengths of the_history->lines. */
extern int history_total_bytes (); extern int history_total_bytes ();
/* Exported history variables. */
extern int history_stifled;
extern int history_length;
extern int max_input_history;
extern char history_expansion_char;
extern char history_subst_char;
extern char history_comment_char;
extern char *history_no_expand_chars;
extern int history_base;

View file

@ -66,24 +66,26 @@ extern KEYMAP_ENTRY_ARRAY vi_insertion_keymap, vi_movement_keymap;
/* Return a new, empty keymap. /* Return a new, empty keymap.
Free it with free() when you are done. */ Free it with free() when you are done. */
Keymap rl_make_bare_keymap (); extern Keymap rl_make_bare_keymap ();
/* Return a new keymap which is a copy of MAP. */ /* Return a new keymap which is a copy of MAP. */
Keymap rl_copy_keymap (); extern Keymap rl_copy_keymap ();
/* Return a new keymap with the printing characters bound to rl_insert, /* Return a new keymap with the printing characters bound to rl_insert,
the lowercase Meta characters bound to run their equivalents, and the lowercase Meta characters bound to run their equivalents, and
the Meta digits bound to produce numeric arguments. */ the Meta digits bound to produce numeric arguments. */
Keymap rl_make_keymap (); extern Keymap rl_make_keymap ();
extern void rl_discard_keymap ();
/* Return the keymap corresponding to a given name. Names look like /* Return the keymap corresponding to a given name. Names look like
`emacs' or `emacs-meta' or `vi-insert'. */ `emacs' or `emacs-meta' or `vi-insert'. */
Keymap rl_get_keymap_by_name (); extern Keymap rl_get_keymap_by_name ();
/* Return the current keymap. */ /* Return the current keymap. */
Keymap rl_get_keymap (); extern Keymap rl_get_keymap ();
/* Set the current keymap to MAP. */ /* Set the current keymap to MAP. */
void rl_set_keymap (); extern void rl_set_keymap ();
#endif /* _KEYMAPS_H_ */ #endif /* _KEYMAPS_H_ */

View file

@ -24,6 +24,7 @@
#define _READLINE_H_ #define _READLINE_H_
#include <readline/keymaps.h> #include <readline/keymaps.h>
#include <readline/tilde.h>
/* The functions for manipulating the text of the line within readline. /* The functions for manipulating the text of the line within readline.
Most of these functions are bound to keys by default. */ Most of these functions are bound to keys by default. */
@ -38,13 +39,29 @@ extern int
rl_forward_word (), rl_tab_insert (), rl_yank_pop (), rl_yank_nth_arg (), rl_forward_word (), rl_tab_insert (), rl_yank_pop (), rl_yank_nth_arg (),
rl_backward_kill_word (), rl_backward_kill_line (), rl_transpose_words (), rl_backward_kill_word (), rl_backward_kill_line (), rl_transpose_words (),
rl_complete (), rl_possible_completions (), rl_insert_completions (), rl_complete (), rl_possible_completions (), rl_insert_completions (),
rl_do_lowercase_version (), rl_do_lowercase_version (), rl_kill_full_line (),
rl_digit_argument (), rl_universal_argument (), rl_abort (), rl_digit_argument (), rl_universal_argument (), rl_abort (),
rl_undo_command (), rl_revert_line (), rl_beginning_of_history (), rl_undo_command (), rl_revert_line (), rl_beginning_of_history (),
rl_end_of_history (), rl_forward_search_history (), rl_insert (), rl_end_of_history (), rl_forward_search_history (), rl_insert (),
rl_upcase_word (), rl_downcase_word (), rl_capitalize_word (), rl_upcase_word (), rl_downcase_word (), rl_capitalize_word (),
rl_restart_output (), rl_re_read_init_file (), rl_dump_functions (), rl_restart_output (), rl_re_read_init_file (), rl_dump_functions (),
rl_delete_horizontal_space (); rl_delete_horizontal_space (), rl_history_search_forward (),
rl_history_search_backward ();
/* `Public' utility functions. */
extern int rl_insert_text (), rl_delete_text (), rl_kill_text ();
extern int rl_complete_internal ();
extern int rl_expand_prompt ();
extern int rl_initialize ();
extern int rl_set_signals (), rl_clear_signals ();
extern int rl_init_argument (), rl_digit_argument ();
extern int rl_read_key (), rl_getc (), rl_stuff_char ();
extern int maybe_save_line (), maybe_unsave_line (), maybe_replace_line ();
extern int rl_modifying ();
extern int rl_begin_undo_group (), rl_end_undo_group ();
extern void rl_add_undo (), free_undo_list ();
extern int rl_do_undo ();
extern int rl_insert_close (); extern int rl_insert_close ();
@ -57,6 +74,7 @@ extern int
rl_noninc_forward_search_again (), rl_noninc_reverse_search_again (); rl_noninc_forward_search_again (), rl_noninc_reverse_search_again ();
/* Things for vi mode. */ /* Things for vi mode. */
extern int rl_vi_check (), rl_vi_textmod_command ();
extern int extern int
rl_vi_redo (), rl_vi_tilde_expand (), rl_vi_redo (), rl_vi_tilde_expand (),
rl_vi_movement_mode (), rl_vi_insertion_mode (), rl_vi_arg_digit (), rl_vi_movement_mode (), rl_vi_insertion_mode (), rl_vi_arg_digit (),
@ -73,8 +91,8 @@ extern int
rl_vi_complete (), rl_vi_fetch_history (); rl_vi_complete (), rl_vi_fetch_history ();
/* Keyboard macro commands. */ /* Keyboard macro commands. */
extern int extern int rl_start_kbd_macro (), rl_end_kbd_macro ();
rl_start_kbd_macro (), rl_end_kbd_macro (), rl_call_last_kbd_macro (); extern int rl_call_last_kbd_macro ();
extern int rl_arrow_keys(), rl_refresh_line (); extern int rl_arrow_keys(), rl_refresh_line ();
@ -137,10 +155,10 @@ extern char *rl_basic_word_break_characters;
rl_basic_word_break_characters. */ rl_basic_word_break_characters. */
extern char *rl_completer_word_break_characters; extern char *rl_completer_word_break_characters;
/* List of characters which are used to quote a substring of the command /* List of characters which can be used to quote a substring of the line.
line, upon which completion is to be performed for the entire substring. Completion occurs on the entire substring, and within the substring
Within quoted substrings, rl_completer_word_break_characters are treated rl_completer_word_break_characters are treated as any other character,
as normal characters, unless they also appear in this list. */ unless they also appear within this list. */
extern char *rl_completer_quote_characters; extern char *rl_completer_quote_characters;
/* List of characters that are word break characters, but should be left /* List of characters that are word break characters, but should be left
@ -177,7 +195,10 @@ extern Function *rl_startup_hook;
/* If non-zero, then this is the address of a function to call when /* If non-zero, then this is the address of a function to call when
completing on a directory name. The function is called with completing on a directory name. The function is called with
the address of a string (the current directory name) as an arg. */ the address of a string (the current directory name) as an arg. */
extern Function *rl_symbolic_link_hook; extern Function *rl_directory_completion_hook;
/* Backwards compatibility with previous versions of readline. */
#define rl_symbolic_link_hook rl_directory_completion_hook
/* The address of a function to call periodically while Readline is /* The address of a function to call periodically while Readline is
awaiting character input, or NULL, for no event handling. */ awaiting character input, or NULL, for no event handling. */
@ -187,28 +208,9 @@ extern Function *rl_event_hook;
with an asterisk. */ with an asterisk. */
extern int rl_show_star; extern int rl_show_star;
/* Non-zero means to suppress normal filename completion after the
/* **************************************************************** */ user-specified completion function has been called. */
/* */ extern int rl_attempted_completion_over;
/* Tilde Variables That Can be Externally Set */
/* */
/* **************************************************************** */
/* If non-null, this contains the address of a function to call if the
standard meaning for expanding a tilde fails. The function is called
with the text (sans tilde, as in "foo"), and returns a malloc()'ed string
which is the expansion, or a NULL pointer if there is no expansion. */
extern Function *tilde_expansion_failure_hook;
/* When non-null, this is a NULL terminated array of strings which
are duplicates for a tilde prefix. Bash uses this to expand
`=~' and `:~'. */
extern char **tilde_additional_prefixes;
/* When non-null, this is a NULL terminated array of strings which match
the end of a username, instead of just "/". Bash sets this to
`/' and `:'. */
extern char **tilde_additional_suffixes;
/* **************************************************************** */ /* **************************************************************** */
/* */ /* */
@ -219,14 +221,47 @@ extern char **tilde_additional_suffixes;
/* Read a line of input. Prompt with PROMPT. A NULL PROMPT means none. */ /* Read a line of input. Prompt with PROMPT. A NULL PROMPT means none. */
extern char *readline (); extern char *readline ();
/* These functions are from complete.c. */
/* Return an array of strings which are the result of repeatadly calling /* Return an array of strings which are the result of repeatadly calling
FUNC with TEXT. */ FUNC with TEXT. */
extern char **completion_matches (); extern char **completion_matches ();
extern char *username_completion_function ();
extern char *filename_completion_function ();
/* These functions are from bind.c. */
/* rl_add_defun (char *name, Function *function, int key) /* rl_add_defun (char *name, Function *function, int key)
Add NAME to the list of named functions. Make FUNCTION Add NAME to the list of named functions. Make FUNCTION
be the function that gets called. be the function that gets called.
If KEY is not -1, then bind it. */ If KEY is not -1, then bind it. */
extern int rl_add_defun (); extern int rl_add_defun ();
extern int rl_bind_key (), rl_bind_key_in_map ();
extern int rl_unbind_key (), rl_unbind_key_in_map ();
extern int rl_set_key ();
extern int rl_macro_bind (), rl_generic_bind (), rl_variable_bind ();
extern int rl_translate_keyseq ();
extern Function *rl_named_function (), *rl_function_of_keyseq ();
extern int rl_parse_and_bind ();
extern Keymap rl_get_keymap (), rl_get_keymap_by_name ();
extern void rl_set_keymap ();
extern char **rl_invoking_keyseqs (), **rl_invoking_keyseqs_in_map ();
extern void rl_function_dumper ();
extern int rl_read_init_file ();
/* Functions in funmap.c */
extern void rl_list_funmap_names ();
extern void rl_initialize_funmap ();
/* Functions in display.c */
extern void rl_redisplay ();
extern int rl_message (), rl_clear_message ();
extern int rl_reset_line_state ();
extern int rl_character_len ();
extern int rl_show_char ();
extern int crlf (), rl_on_new_line ();
extern int rl_forced_update_display ();
/* Definitions available for use by readline clients. */
#define RL_PROMPT_START_IGNORE '\001'
#define RL_PROMPT_END_IGNORE '\002'
#endif /* _READLINE_H_ */ #endif /* _READLINE_H_ */

View file

@ -0,0 +1,38 @@
/* tilde.h: Externally available variables and function in libtilde.a. */
#if !defined (__TILDE_H__)
# define __TILDE_H__
/* Function pointers can be declared as (Function *)foo. */
#if !defined (__FUNCTION_DEF)
# define __FUNCTION_DEF
typedef int Function ();
typedef void VFunction ();
typedef char *CPFunction ();
typedef char **CPPFunction ();
#endif /* _FUNCTION_DEF */
/* If non-null, this contains the address of a function to call if the
standard meaning for expanding a tilde fails. The function is called
with the text (sans tilde, as in "foo"), and returns a malloc()'ed string
which is the expansion, or a NULL pointer if there is no expansion. */
extern CPFunction *tilde_expansion_failure_hook;
/* When non-null, this is a NULL terminated array of strings which
are duplicates for a tilde prefix. Bash uses this to expand
`=~' and `:~'. */
extern char **tilde_additional_prefixes;
/* When non-null, this is a NULL terminated array of strings which match
the end of a username, instead of just "/". Bash sets this to
`:' and `=~'. */
extern char **tilde_additional_suffixes;
/* Return a new string which is the result of tilde expanding STRING. */
extern char *tilde_expand ();
/* Do the work of tilde expansion on FILENAME. FILENAME starts with a
tilde. If there is no expansion, call tilde_expansion_failure_hook. */
extern char *tilde_expand_word ();
#endif /* __TILDE_H__ */

View file

@ -0,0 +1,57 @@
/* rlconf.h -- readline configuration definitions */
/* Copyright (C) 1994 Free Software Foundation, Inc.
This file contains the Readline Library (the Library), a set of
routines for providing Emacs style line input to programs that ask
for it.
The Library 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 1, or (at your option)
any later version.
The Library 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.
The GNU General Public License is often shipped with GNU software, and
is generally kept in a file called COPYING or LICENSE. If you do not
have a copy of the license, write to the Free Software Foundation,
675 Mass Ave, Cambridge, MA 02139, USA. */
#if !defined (_RLCONF_H_)
#define _RLCONF_H_
/* Define this if you want the vi-mode editing available. */
#define VI_MODE
/* Define this to get an indication of file type when listing completions. */
#define VISIBLE_STATS
/* If defined, readline shows opening parens and braces when closing
paren or brace entered. */
#define PAREN_MATCHING
/* This definition is needed by readline.c, rltty.c, and signals.c. */
/* If on, then readline handles signals in a way that doesn't screw. */
#define HANDLE_SIGNALS
/* Ugly but working hack for binding prefix meta. */
#define PREFIX_META_HACK
/* The final, last-ditch effort file name for an init file. */
#define DEFAULT_INPUTRC "~/.inputrc"
/* If defined, expand tabs to spaces. */
#define DISPLAY_TABS
/* If defined, use the terminal escape sequence to move the cursor forward
over a character when updating the line rather than rewriting it. */
/* #define HACK_TERMCAP_MOTION */
/* The string inserted by the vi-mode `insert comment' command. */
#define VI_COMMENT_BEGIN_DEFAULT "#"
#endif /* _RLCONF_H_ */

View file

@ -26,13 +26,8 @@
#if !defined (_RLDEFS_H) #if !defined (_RLDEFS_H)
#define _RLDEFS_H #define _RLDEFS_H
#if defined (__GNUC__) #if !defined (PRAGMA_ALLOCA)
# undef alloca # include "memalloc.h"
# define alloca __builtin_alloca
#else
# if defined (sparc) || defined (HAVE_ALLOCA_H)
# include <alloca.h>
# endif
#endif #endif
#define NEW_TTY_DRIVER #define NEW_TTY_DRIVER
@ -75,11 +70,11 @@
/* System V.3 machines have the old 4.1 BSD `reliable' signal interface. */ /* System V.3 machines have the old 4.1 BSD `reliable' signal interface. */
#if !defined (HAVE_BSD_SIGNALS) && !defined (HAVE_POSIX_SIGNALS) #if !defined (HAVE_BSD_SIGNALS) && !defined (HAVE_POSIX_SIGNALS)
# if defined (USGr3) # if defined (USGr3) && !defined (XENIX_22)
# if !defined (HAVE_USG_SIGHOLD) # if !defined (HAVE_USG_SIGHOLD)
# define HAVE_USG_SIGHOLD # define HAVE_USG_SIGHOLD
# endif /* !HAVE_USG_SIGHOLD */ # endif /* !HAVE_USG_SIGHOLD */
# endif /* USGr3 */ # endif /* USGr3 && !XENIX_22 */
#endif /* !HAVE_BSD_SIGNALS && !HAVE_POSIX_SIGNALS */ #endif /* !HAVE_BSD_SIGNALS && !HAVE_POSIX_SIGNALS */
/* Other (BSD) machines use sgtty. */ /* Other (BSD) machines use sgtty. */
@ -125,7 +120,9 @@
#endif /* !HAVE_DIRENT_H */ #endif /* !HAVE_DIRENT_H */
#if defined (USG) && defined (TIOCGWINSZ) && !defined (Linux) #if defined (USG) && defined (TIOCGWINSZ) && !defined (Linux)
# include <sys/stream.h> # if defined (HAVE_SYS_STREAM_H)
# include <sys/stream.h>
# endif /* HAVE_SYS_STREAM_H */
# if defined (HAVE_SYS_PTEM_H) # if defined (HAVE_SYS_PTEM_H)
# include <sys/ptem.h> # include <sys/ptem.h>
# endif /* HAVE_SYS_PTEM_H */ # endif /* HAVE_SYS_PTEM_H */
@ -137,7 +134,7 @@
/* Posix macro to check file in statbuf for directory-ness. /* Posix macro to check file in statbuf for directory-ness.
This requires that <sys/stat.h> be included before this test. */ This requires that <sys/stat.h> be included before this test. */
#if defined (S_IFDIR) && !defined (S_ISDIR) #if defined (S_IFDIR) && !defined (S_ISDIR)
#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) # define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
#endif #endif
/* Decide which flavor of the header file describing the C library /* Decide which flavor of the header file describing the C library
@ -163,14 +160,31 @@ extern char *strchr (), *strrchr ();
# include <varargs.h> # include <varargs.h>
#endif /* HAVE_VARARGS_H */ #endif /* HAVE_VARARGS_H */
/* This definition is needed by readline.c, rltty.c, and signals.c. */
/* If on, then readline handles signals in a way that doesn't screw. */
#define HANDLE_SIGNALS
#if !defined (emacs_mode) #if !defined (emacs_mode)
# define no_mode -1 # define no_mode -1
# define vi_mode 0 # define vi_mode 0
# define emacs_mode 1 # define emacs_mode 1
#endif #endif
/* If you cast map[key].function to type (Keymap) on a Cray,
the compiler takes the value of map[key].function and
divides it by 4 to convert between pointer types (pointers
to functions and pointers to structs are different sizes).
This is not what is wanted. */
#if defined (CRAY)
# define FUNCTION_TO_KEYMAP(map, key) (Keymap)((int)map[key].function)
# define KEYMAP_TO_FUNCTION(data) (Function *)((int)(data))
#else
# define FUNCTION_TO_KEYMAP(map, key) (Keymap)(map[key].function)
# define KEYMAP_TO_FUNCTION(data) (Function *)(data)
#endif
/* Possible values for _rl_bell_preference. */
#define NO_BELL 0
#define AUDIBLE_BELL 1
#define VISIBLE_BELL 2
/* CONFIGURATION SECTION */
#include "rlconf.h"
#endif /* !_RLDEFS_H */ #endif /* !_RLDEFS_H */

View file

@ -40,10 +40,10 @@ extern int errno;
extern int readline_echoing_p; extern int readline_echoing_p;
extern int _rl_eof_char; extern int _rl_eof_char;
#if defined (_GO32_) #if defined (__GO32__)
# include <sys/pc.h> # include <sys/pc.h>
# undef HANDLE_SIGNALS # undef HANDLE_SIGNALS
#endif /* _GO32_ */ #endif /* __GO32__ */
/* **************************************************************** */ /* **************************************************************** */
/* */ /* */
@ -107,10 +107,10 @@ release_sigint ()
sigint_blocked = 0; sigint_blocked = 0;
} }
/* **************************************************************** */ /* **************************************************************** */
/* */ /* */
/* Controlling the Meta Key */ /* Controlling the Meta Key and Keypad */
/* */ /* */
/* **************************************************************** */ /* **************************************************************** */
@ -118,11 +118,13 @@ extern int term_has_meta;
extern char *term_mm; extern char *term_mm;
extern char *term_mo; extern char *term_mo;
static void extern char *term_ks;
extern char *term_ke;
static int
outchar (c) outchar (c)
int c; int c;
{ {
putc (c, rl_outstream); return putc (c, rl_outstream);
} }
/* Turn on/off the meta key depending on ON. */ /* Turn on/off the meta key depending on ON. */
@ -138,7 +140,17 @@ control_meta_key (on)
tputs (term_mo, 1, outchar); tputs (term_mo, 1, outchar);
} }
} }
static void
control_keypad (on)
int on;
{
if (on && term_ks)
tputs (term_ks, 1, outchar);
else if (!on && term_ke)
tputs (term_ke, 1, outchar);
}
/* **************************************************************** */ /* **************************************************************** */
/* */ /* */
/* Saving and Restoring the TTY */ /* Saving and Restoring the TTY */
@ -250,7 +262,7 @@ prepare_terminal_settings (meta_flag, otio, tiop)
int meta_flag; int meta_flag;
TIOTYPE otio, *tiop; TIOTYPE otio, *tiop;
{ {
#if !defined (_GO32_) #if !defined (__GO32__)
readline_echoing_p = (otio.sgttyb.sg_flags & ECHO); readline_echoing_p = (otio.sgttyb.sg_flags & ECHO);
/* Copy the original settings to the structure we're going to use for /* Copy the original settings to the structure we're going to use for
@ -316,7 +328,7 @@ prepare_terminal_settings (meta_flag, otio, tiop)
tiop->ltchars.t_dsuspc = -1; /* C-y */ tiop->ltchars.t_dsuspc = -1; /* C-y */
tiop->ltchars.t_lnextc = -1; /* C-v */ tiop->ltchars.t_lnextc = -1; /* C-v */
#endif /* TIOCGLTC */ #endif /* TIOCGLTC */
#endif /* !_GO32_ */ #endif /* !__GO32__ */
} }
#else /* !defined (NEW_TTY_DRIVER) */ #else /* !defined (NEW_TTY_DRIVER) */
@ -455,7 +467,7 @@ void
rl_prep_terminal (meta_flag) rl_prep_terminal (meta_flag)
int meta_flag; int meta_flag;
{ {
#if !defined (_GO32_) #if !defined (__GO32__)
int tty = fileno (rl_instream); int tty = fileno (rl_instream);
TIOTYPE tio; TIOTYPE tio;
@ -482,17 +494,18 @@ rl_prep_terminal (meta_flag)
} }
control_meta_key (1); control_meta_key (1);
control_keypad (1);
terminal_prepped = 1; terminal_prepped = 1;
release_sigint (); release_sigint ();
#endif /* !_GO32_ */ #endif /* !__GO32__ */
} }
/* Restore the terminal's normal settings and modes. */ /* Restore the terminal's normal settings and modes. */
void void
rl_deprep_terminal () rl_deprep_terminal ()
{ {
#if !defined (_GO32_) #if !defined (__GO32__)
int tty = fileno (rl_instream); int tty = fileno (rl_instream);
if (!terminal_prepped) if (!terminal_prepped)
@ -508,10 +521,11 @@ rl_deprep_terminal ()
} }
control_meta_key (0); control_meta_key (0);
control_keypad (0);
terminal_prepped = 0; terminal_prepped = 0;
release_sigint (); release_sigint ();
#endif /* !_GO32_ */ #endif /* !__GO32__ */
} }
/* **************************************************************** */ /* **************************************************************** */
@ -548,6 +562,8 @@ rl_restart_output (count, key)
# endif /* TCXONC */ # endif /* TCXONC */
# endif /* !TERMIOS_TTY_DRIVER */ # endif /* !TERMIOS_TTY_DRIVER */
#endif /* !TIOCSTART */ #endif /* !TIOCSTART */
return 0;
} }
rl_stop_output (count, key) rl_stop_output (count, key)
@ -573,6 +589,8 @@ rl_stop_output (count, key)
# endif /* TCXONC */ # endif /* TCXONC */
# endif /* !TERMIOS_TTY_DRIVER */ # endif /* !TERMIOS_TTY_DRIVER */
#endif /* !TIOCSTOP */ #endif /* !TIOCSTOP */
return 0;
} }
/* **************************************************************** */ /* **************************************************************** */

View file

@ -23,17 +23,15 @@
#include <stdio.h> #include <stdio.h>
#if defined (__GNUC__) #include "memalloc.h"
# define alloca __builtin_alloca
#else
# if defined (sparc) || defined (HAVE_ALLOCA_H)
# include <alloca.h>
# endif
#endif
#include "readline.h" #include "readline.h"
#include "history.h" #include "history.h"
#define STREQ(a, b) (((a)[0] == (b)[0]) && (strcmp ((a), (b)) == 0))
#define STREQN(a, b, n) (((a)[0] == (b)[0]) && (strncmp ((a), (b), (n)) == 0))
#define abs(x) (((x) > 0) ? (x) : -(x))
extern char *xmalloc (), *xrealloc (); extern char *xmalloc (), *xrealloc ();
/* Variables imported from readline.c */ /* Variables imported from readline.c */
@ -42,9 +40,14 @@ extern Keymap _rl_keymap;
extern char *rl_prompt; extern char *rl_prompt;
extern char *rl_line_buffer; extern char *rl_line_buffer;
extern HIST_ENTRY *saved_line_for_history; extern HIST_ENTRY *saved_line_for_history;
extern Function *rl_last_func;
/* Functions imported from the rest of the library. */
extern int _rl_free_history_entry ();
static char *noninc_search_string = (char *) NULL; static char *noninc_search_string = (char *) NULL;
static int noninc_history_pos = 0; static int noninc_history_pos = 0;
static char *prev_line_found = (char *) NULL;
/* Search the history list for STRING starting at absolute history position /* Search the history list for STRING starting at absolute history position
POS. If STRING begins with `^', the search must match STRING at the POS. If STRING begins with `^', the search must match STRING at the
@ -123,7 +126,7 @@ noninc_dosearch (string, dir)
rl_clear_message (); rl_clear_message ();
if (saved_line_for_history) if (saved_line_for_history)
free_history_entry (saved_line_for_history); _rl_free_history_entry (saved_line_for_history);
saved_line_for_history = (HIST_ENTRY *)NULL; saved_line_for_history = (HIST_ENTRY *)NULL;
} }
@ -147,14 +150,16 @@ noninc_search (dir, pchar)
rl_line_buffer[0] = 0; rl_line_buffer[0] = 0;
rl_end = rl_point = 0; rl_end = rl_point = 0;
/* XXX - this needs fixing to work with the prompt expansion stuff - XXX */
pmtlen = (rl_prompt && *rl_prompt) ? strlen (rl_prompt) : 0; pmtlen = (rl_prompt && *rl_prompt) ? strlen (rl_prompt) : 0;
p = (char *)alloca (2 + pmtlen); p = xmalloc (2 + pmtlen);
if (pmtlen) if (pmtlen)
strcpy (p, rl_prompt); strcpy (p, rl_prompt);
p[pmtlen] = pchar ? pchar : ':'; p[pmtlen] = pchar ? pchar : ':';
p[pmtlen + 1] = '\0'; p[pmtlen + 1] = '\0';
rl_message (p, 0, 0); rl_message (p, 0, 0);
free (p);
/* Read the search string. */ /* Read the search string. */
while (c = rl_read_key ()) while (c = rl_read_key ())
@ -170,11 +175,15 @@ noninc_search (dir, pchar)
rl_point = saved_point; rl_point = saved_point;
return; return;
} }
/* FALLTHROUGH */ rl_rubout (1);
break;
case CTRL('W'): case CTRL('W'):
rl_unix_word_rubout ();
break;
case CTRL('U'): case CTRL('U'):
rl_dispatch (c, _rl_keymap); rl_unix_line_discard ();
break; break;
case RETURN: case RETURN:
@ -273,3 +282,79 @@ rl_noninc_reverse_search_again (count, key)
noninc_dosearch (noninc_search_string, -1); noninc_dosearch (noninc_search_string, -1);
return 0; return 0;
} }
static int
rl_history_search_internal (count, direction)
int count, direction;
{
HIST_ENTRY *temp, *old_temp;
int line_len;
maybe_save_line ();
temp = old_temp = (HIST_ENTRY *)NULL;
while (count)
{
temp = (direction < 0) ? previous_history () : next_history ();
if (!temp)
break;
if (STREQN (rl_line_buffer, temp->line, rl_point))
{
/* Don't find multiple instances of the same line. */
if (prev_line_found && STREQ (prev_line_found, temp->line))
continue;
if (direction < 0)
old_temp = temp;
prev_line_found = temp->line;
count--;
}
}
if (!temp)
{
if (direction < 0 && old_temp)
temp = old_temp;
else
{
maybe_unsave_line ();
ding ();
return 1;
}
}
line_len = strlen (temp->line);
if (line_len >= rl_line_buffer_len)
rl_extend_line_buffer (line_len);
strcpy (rl_line_buffer, temp->line);
rl_undo_list = (UNDO_LIST *)temp->data;
rl_end = line_len;
return 0;
}
/* Search forward in the history for the string of characters
from the start of the line to rl_point. This is a non-incremental
search. */
int
rl_history_search_forward (count, ignore)
int count, ignore;
{
if (count == 0)
return (0);
if (rl_last_func != rl_history_search_forward)
prev_line_found = (char *)NULL;
return (rl_history_search_internal (abs (count), (count > 0) ? 1 : -1));
}
/* Search backward through the history for the string of characters
from the start of the line to rl_point. This is a non-incremental
search. */
int
rl_history_search_backward (count, ignore)
int count, ignore;
{
if (count == 0)
return (0);
if (rl_last_func != rl_history_search_backward)
prev_line_found = (char *)NULL;
return (rl_history_search_internal (abs (count), (count > 0) ? -1 : 1));
}

View file

@ -62,10 +62,11 @@ static void cr ();
extern int readline_echoing_p; extern int readline_echoing_p;
extern int rl_pending_input; extern int rl_pending_input;
extern char *term_cr;
extern int _rl_meta_flag; extern int _rl_meta_flag;
extern void _rl_output_character_function (); extern int _rl_output_character_function ();
extern void free_undo_list (); extern void free_undo_list ();
@ -79,9 +80,9 @@ extern void free_undo_list ();
to say SigHandler *foo = signal (SIGKILL, SIG_IGN); */ to say SigHandler *foo = signal (SIGKILL, SIG_IGN); */
typedef sighandler SigHandler (); typedef sighandler SigHandler ();
#if defined (_GO32_) #if defined (__GO32__)
# undef HANDLE_SIGNALS # undef HANDLE_SIGNALS
#endif /* _GO32_ */ #endif /* __GO32__ */
#if defined (STATIC_MALLOC) #if defined (STATIC_MALLOC)
static char *xmalloc (), *xrealloc (); static char *xmalloc (), *xrealloc ();
@ -125,11 +126,14 @@ rl_handle_sigwinch (sig)
/* Interrupt handling. */ /* Interrupt handling. */
static SigHandler static SigHandler
*old_int = (SigHandler *)NULL, *old_int = (SigHandler *)NULL,
*old_alrm = (SigHandler *)NULL;
#if !defined (SHELL)
static SigHandler
*old_tstp = (SigHandler *)NULL, *old_tstp = (SigHandler *)NULL,
*old_ttou = (SigHandler *)NULL, *old_ttou = (SigHandler *)NULL,
*old_ttin = (SigHandler *)NULL, *old_ttin = (SigHandler *)NULL,
*old_cont = (SigHandler *)NULL, *old_cont = (SigHandler *)NULL;
*old_alrm = (SigHandler *)NULL; #endif /* !SHELL */
/* Handle an interrupt character. */ /* Handle an interrupt character. */
static sighandler static sighandler
@ -261,6 +265,7 @@ rl_set_signals ()
old_sigwinch = old_sigwinch =
(SigHandler *) rl_set_sighandler (SIGWINCH, rl_handle_sigwinch); (SigHandler *) rl_set_sighandler (SIGWINCH, rl_handle_sigwinch);
#endif /* SIGWINCH */ #endif /* SIGWINCH */
return 0;
} }
rl_clear_signals () rl_clear_signals ()
@ -284,14 +289,14 @@ rl_clear_signals ()
#if defined (SIGWINCH) #if defined (SIGWINCH)
signal (SIGWINCH, old_sigwinch); signal (SIGWINCH, old_sigwinch);
#endif #endif
return 0;
} }
/* Move to the start of the current line. */ /* Move to the start of the current line. */
static void static void
cr () cr ()
{ {
extern char *term_cr;
if (term_cr) if (term_cr)
tputs (term_cr, 1, _rl_output_character_function); tputs (term_cr, 1, _rl_output_character_function);
} }

View file

@ -1,5 +1,5 @@
*** rltty.c.orig Tue May 10 02:18:03 1994 *** rltty.c.orig Thu May 12 19:02:50 1994
--- rltty.c Tue May 10 03:12:55 1994 --- rltty.c Thu May 12 19:03:06 1994
*************** ***************
*** 21,26 **** *** 21,26 ****
--- 21,27 ---- --- 21,27 ----
@ -11,8 +11,8 @@
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
*************** ***************
*** 347,352 **** *** 359,364 ****
--- 348,359 ---- --- 360,371 ----
int tty; int tty;
TIOTYPE *tiop; TIOTYPE *tiop;
{ {

View file

@ -19,18 +19,7 @@
along with Readline; see the file COPYING. If not, write to the Free along with Readline; see the file COPYING. If not, write to the Free
Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#if defined (__GNUC__) #include "memalloc.h"
# undef alloca
# define alloca __builtin_alloca
#else /* !__GNUC__ */
# if defined (_AIX)
#pragma alloca
# else /* !_AIX */
# if defined (HAVE_ALLOCA_H)
# include <alloca.h>
# endif /* HAVE_ALLOCA_H */
# endif /* !AIX */
#endif /* !__GNUC__ */
#if defined (HAVE_STRING_H) #if defined (HAVE_STRING_H)
# include <string.h> # include <string.h>
@ -44,15 +33,12 @@
# include "ansi_stdlib.h" # include "ansi_stdlib.h"
#endif /* HAVE_STDLIB_H */ #endif /* HAVE_STDLIB_H */
#include <tilde.h> #include "tilde.h"
#include <pwd.h> #include <pwd.h>
#if defined (USG) && !defined (isc386) && !defined (sgi) #if defined (USG) && !defined (HAVE_GETPW_DECLS)
extern struct passwd *getpwuid (), *getpwent (); extern struct passwd *getpwuid (), *getpwnam ();
#endif #endif /* USG && !defined (HAVE_GETPW_DECLS) */
#if defined (isc386) && !defined (__STDC__) && defined (_POSIX_SOURCE)
extern struct passwd *getpwent ();
#endif
#if !defined (savestring) #if !defined (savestring)
extern char *xmalloc (); extern char *xmalloc ();
@ -254,21 +240,23 @@ tilde_expand_word (filename)
temp_home = entry->pw_dir; temp_home = entry->pw_dir;
} }
temp_name = (char *)alloca (1 + strlen (&dirname[1]) temp_name = xmalloc (1 + strlen (&dirname[1])
+ (temp_home ? strlen (temp_home) : 0)); + (temp_home ? strlen (temp_home) : 0));
temp_name[0] = '\0'; temp_name[0] = '\0';
if (temp_home) if (temp_home)
strcpy (temp_name, temp_home); strcpy (temp_name, temp_home);
strcat (temp_name, &dirname[1]); strcat (temp_name, dirname + 1);
free (dirname); free (dirname);
dirname = savestring (temp_name); dirname = temp_name;
} }
else else
{ {
char u_name[257];
struct passwd *user_entry; struct passwd *user_entry;
char *username = (char *)alloca (257); char *username;
int i, c; int i, c;
username = u_name;
for (i = 1; c = dirname[i]; i++) for (i = 1; c = dirname[i]; i++)
{ {
if (c == '/') if (c == '/')
@ -291,25 +279,25 @@ tilde_expand_word (filename)
if (expansion) if (expansion)
{ {
temp_name = (char *)alloca (1 + strlen (expansion) temp_name = xmalloc (1 + strlen (expansion)
+ strlen (&dirname[i])); + strlen (&dirname[i]));
strcpy (temp_name, expansion); strcpy (temp_name, expansion);
strcat (temp_name, &dirname[i]); strcat (temp_name, &dirname[i]);
free (expansion); free (expansion);
goto return_name; free (dirname);
dirname = temp_name;
} }
} }
/* We shouldn't report errors. */ /* We shouldn't report errors. */
} }
else else
{ {
temp_name = (char *)alloca (1 + strlen (user_entry->pw_dir) temp_name = xmalloc (1 + strlen (user_entry->pw_dir)
+ strlen (&dirname[i])); + strlen (&dirname[i]));
strcpy (temp_name, user_entry->pw_dir); strcpy (temp_name, user_entry->pw_dir);
strcat (temp_name, &dirname[i]); strcat (temp_name, &dirname[i]);
return_name:
free (dirname); free (dirname);
dirname = savestring (temp_name); dirname = temp_name;
} }
endpwent (); endpwent ();
} }

View file

@ -26,7 +26,9 @@
#include "readline.h" #include "readline.h"
#if 0
extern KEYMAP_ENTRY_ARRAY vi_escape_keymap; extern KEYMAP_ENTRY_ARRAY vi_escape_keymap;
#endif
/* The keymap arrays for handling vi mode. */ /* The keymap arrays for handling vi mode. */
KEYMAP_ENTRY_ARRAY vi_movement_keymap = { KEYMAP_ENTRY_ARRAY vi_movement_keymap = {
@ -59,7 +61,7 @@ KEYMAP_ENTRY_ARRAY vi_movement_keymap = {
{ ISFUNC, rl_yank }, /* Control-y */ { ISFUNC, rl_yank }, /* Control-y */
{ ISFUNC, (Function *)0x0 }, /* Control-z */ { ISFUNC, (Function *)0x0 }, /* Control-z */
{ ISFUNC, rl_abort }, /* Control-[ */ { ISFUNC, rl_abort }, /* Control-[ */ /* vi_escape_keymap */
{ ISFUNC, (Function *)0x0 }, /* Control-\ */ { ISFUNC, (Function *)0x0 }, /* Control-\ */
{ ISFUNC, (Function *)0x0 }, /* Control-] */ { ISFUNC, (Function *)0x0 }, /* Control-] */
{ ISFUNC, (Function *)0x0 }, /* Control-^ */ { ISFUNC, (Function *)0x0 }, /* Control-^ */
@ -84,7 +86,7 @@ KEYMAP_ENTRY_ARRAY vi_movement_keymap = {
{ ISFUNC, rl_vi_search }, /* / */ { ISFUNC, rl_vi_search }, /* / */
/* Regular digits. */ /* Regular digits. */
{ ISFUNC, rl_vi_arg_digit }, /* 0 */ { ISFUNC, rl_beg_of_line }, /* 0 */
{ ISFUNC, rl_vi_arg_digit }, /* 1 */ { ISFUNC, rl_vi_arg_digit }, /* 1 */
{ ISFUNC, rl_vi_arg_digit }, /* 2 */ { ISFUNC, rl_vi_arg_digit }, /* 2 */
{ ISFUNC, rl_vi_arg_digit }, /* 3 */ { ISFUNC, rl_vi_arg_digit }, /* 3 */
@ -592,8 +594,9 @@ KEYMAP_ENTRY_ARRAY vi_insertion_keymap = {
#endif /* KEYMAP_SIZE > 128 */ #endif /* KEYMAP_SIZE > 128 */
}; };
/* Unused for the time being. */
#if 0
KEYMAP_ENTRY_ARRAY vi_escape_keymap = { KEYMAP_ENTRY_ARRAY vi_escape_keymap = {
/* The regular control keys come first. */ /* The regular control keys come first. */
{ ISFUNC, (Function *)0x0 }, /* Control-@ */ { ISFUNC, (Function *)0x0 }, /* Control-@ */
{ ISFUNC, (Function *)0x0 }, /* Control-a */ { ISFUNC, (Function *)0x0 }, /* Control-a */
@ -871,3 +874,4 @@ KEYMAP_ENTRY_ARRAY vi_escape_keymap = {
{ ISFUNC, (Function *)0x0 } { ISFUNC, (Function *)0x0 }
#endif /* KEYMAP_SIZE > 128 */ #endif /* KEYMAP_SIZE > 128 */
}; };
#endif

View file

@ -20,12 +20,14 @@
is generally kept in a file called COPYING or LICENSE. If you do not is generally kept in a file called COPYING or LICENSE. If you do not
have a copy of the license, write to the Free Software Foundation, have a copy of the license, write to the Free Software Foundation,
675 Mass Ave, Cambridge, MA 02139, USA. */ 675 Mass Ave, Cambridge, MA 02139, USA. */
/* **************************************************************** */ /* **************************************************************** */
/* */ /* */
/* VI Emulation Mode */ /* VI Emulation Mode */
/* */ /* */
/* **************************************************************** */ /* **************************************************************** */
#include "rlconf.h"
#if defined (VI_MODE) #if defined (VI_MODE)
#include <sys/types.h> #include <sys/types.h>
@ -36,12 +38,6 @@
# include "ansi_stdlib.h" # include "ansi_stdlib.h"
#endif /* HAVE_STDLIB_H */ #endif /* HAVE_STDLIB_H */
#if defined (STATIC_MALLOC)
static char *xmalloc (), *xrealloc ();
#else
extern char *xmalloc (), *xrealloc ();
#endif /* STATIC_MALLOC */
#include <stdio.h> #include <stdio.h>
/* Some standard library routines. */ /* Some standard library routines. */
@ -77,6 +73,12 @@ extern char *xmalloc (), *xrealloc ();
#define VI_COMMENT_BEGIN_DEFAULT "#" #define VI_COMMENT_BEGIN_DEFAULT "#"
#endif #endif
#if defined (STATIC_MALLOC)
static char *xmalloc (), *xrealloc ();
#else
extern char *xmalloc (), *xrealloc ();
#endif /* STATIC_MALLOC */
/* Variables imported from readline.c */ /* Variables imported from readline.c */
extern int rl_point, rl_end, rl_mark, rl_done; extern int rl_point, rl_end, rl_mark, rl_done;
extern FILE *rl_instream; extern FILE *rl_instream;
@ -86,11 +88,13 @@ extern char *rl_prompt;
extern char *rl_line_buffer; extern char *rl_line_buffer;
extern int rl_arg_sign; extern int rl_arg_sign;
extern void _rl_dispatch ();
extern void rl_extend_line_buffer (); extern void rl_extend_line_buffer ();
extern int rl_vi_check (), rl_digit_loop1 (); extern int rl_vi_check ();
/* Non-zero means enter insertion mode. */ /* Non-zero means enter insertion mode. */
int _rl_vi_doing_insert = 0; static int _rl_vi_doing_insert = 0;
/* String inserted into the line by rl_vi_comment (). */ /* String inserted into the line by rl_vi_comment (). */
char *rl_vi_comment_begin = (char *)NULL; char *rl_vi_comment_begin = (char *)NULL;
@ -106,9 +110,14 @@ static Keymap vi_replace_map = (Keymap)NULL;
/* The number of characters inserted in the last replace operation. */ /* The number of characters inserted in the last replace operation. */
static int vi_replace_count = 0; static int vi_replace_count = 0;
int _rl_vi_last_command = 'i'; /* default `.' puts you in insert mode */ /* If non-zero, we have text inserted after a c[motion] command that put
int _rl_vi_last_repeat = 1; us implicitly into insert mode. Some people want this text to be
int _rl_vi_last_arg_sign = 1; attached to the command so that it is `redoable' with `.'. */
static int vi_continued_command = 0;
static int _rl_vi_last_command = 'i'; /* default `.' puts you in insert mode */
static int _rl_vi_last_repeat = 1;
static int _rl_vi_last_arg_sign = 1;
static int _rl_vi_last_motion = 0; static int _rl_vi_last_motion = 0;
static int _rl_vi_last_search_char = 0; static int _rl_vi_last_search_char = 0;
static int _rl_vi_last_replacement = 0; static int _rl_vi_last_replacement = 0;
@ -118,8 +127,10 @@ static int vi_redoing = 0;
/* Text modification commands. These are the `redoable' commands. */ /* Text modification commands. These are the `redoable' commands. */
static char *vi_textmod = "_*\\AaIiCcDdPpYyRrSsXx~"; static char *vi_textmod = "_*\\AaIiCcDdPpYyRrSsXx~";
static int rl_digit_loop1 ();
void void
rl_vi_set_last () _rl_vi_reset_last ()
{ {
_rl_vi_last_command = 'i'; _rl_vi_last_command = 'i';
_rl_vi_last_repeat = 1; _rl_vi_last_repeat = 1;
@ -127,6 +138,15 @@ rl_vi_set_last ()
_rl_vi_last_motion = 0; _rl_vi_last_motion = 0;
} }
void
_rl_vi_set_last (key, repeat, sign)
int key, repeat, sign;
{
_rl_vi_last_command = key;
_rl_vi_last_repeat = repeat;
_rl_vi_last_arg_sign = sign;
}
/* Is the command C a VI mode text modification command? */ /* Is the command C a VI mode text modification command? */
int int
rl_vi_textmod_command (c) rl_vi_textmod_command (c)
@ -148,7 +168,7 @@ rl_vi_redo (count, c)
} }
vi_redoing = 1; vi_redoing = 1;
rl_dispatch (_rl_vi_last_command, _rl_keymap); _rl_dispatch (_rl_vi_last_command, _rl_keymap);
vi_redoing = 0; vi_redoing = 0;
return (0); return (0);
@ -158,9 +178,6 @@ rl_vi_redo (count, c)
rl_vi_yank_arg (count) rl_vi_yank_arg (count)
int count; int count;
{ {
/* vi mode is defined to insert a space before the last argument. */
rl_insert (1, ' ');
/* Readline thinks that the first word on a line is the 0th, while vi /* Readline thinks that the first word on a line is the 0th, while vi
thinks the first word on a line is the 1st. Compensate. */ thinks the first word on a line is the 1st. Compensate. */
if (rl_explicit_arg) if (rl_explicit_arg)
@ -168,7 +185,6 @@ rl_vi_yank_arg (count)
else else
rl_yank_nth_arg ('$', 0); rl_yank_nth_arg ('$', 0);
rl_vi_insertion_mode ();
return (0); return (0);
} }
@ -256,7 +272,10 @@ rl_vi_complete (ignore, key)
rl_complete (0, key); rl_complete (0, key);
if (key == '*' || key == '\\') if (key == '*' || key == '\\')
rl_vi_insertion_mode (); {
_rl_vi_set_last (key, 1, rl_arg_sign);
rl_vi_insertion_mode ();
}
return (0); return (0);
} }
@ -265,6 +284,7 @@ rl_vi_tilde_expand (ignore, key)
int ignore, key; int ignore, key;
{ {
rl_tilde_expand (0, key); rl_tilde_expand (0, key);
_rl_vi_set_last (key, 1, rl_arg_sign); /* XXX */
rl_vi_insertion_mode (); rl_vi_insertion_mode ();
return (0); return (0);
} }
@ -292,7 +312,7 @@ rl_vi_prev_word (count, key)
/* Next word in vi mode. */ /* Next word in vi mode. */
rl_vi_next_word (count, key) rl_vi_next_word (count, key)
int count; int count, key;
{ {
if (count < 0) if (count < 0)
return (rl_vi_prev_word (-count, key)); return (rl_vi_prev_word (-count, key));
@ -493,7 +513,7 @@ rl_vi_insert_beg ()
rl_vi_append_mode () rl_vi_append_mode ()
{ {
if (rl_point < rl_end) if (rl_point < rl_end)
rl_point += 1; rl_point++;
rl_vi_insertion_mode (); rl_vi_insertion_mode ();
return (0); return (0);
} }
@ -522,25 +542,33 @@ rl_vi_insertion_mode ()
return (0); return (0);
} }
void
_rl_vi_done_inserting ()
{
if (_rl_vi_doing_insert)
{
rl_end_undo_group ();
/* Now, the text between rl_undo_list->next->start and
rl_undo_list->next->end is what was inserted while in insert
mode. */
_rl_vi_doing_insert = 0;
vi_continued_command = 1;
}
else
vi_continued_command = 0;
}
rl_vi_movement_mode () rl_vi_movement_mode ()
{ {
if (rl_point > 0) if (rl_point > 0)
rl_backward (1); rl_backward (1);
rl_vi_set_last (); #if 0
_rl_vi_reset_last ();
#endif
_rl_keymap = vi_movement_keymap; _rl_keymap = vi_movement_keymap;
vi_done_inserting (); _rl_vi_done_inserting ();
return (0);
}
vi_done_inserting ()
{
if (_rl_vi_doing_insert)
{
rl_end_undo_group ();
_rl_vi_doing_insert = 0;
}
return (0); return (0);
} }
@ -639,9 +667,7 @@ rl_vi_domove (key, nextkey)
c = rl_read_key (); /* real command */ c = rl_read_key (); /* real command */
*nextkey = c; *nextkey = c;
} }
else if ((key == 'd' && c == 'd') || else if (key == c && (key == 'd' || key == 'y' || key == 'c'))
(key == 'y' && c == 'y') ||
(key == 'c' && c == 'c'))
{ {
rl_mark = rl_end; rl_mark = rl_end;
rl_beg_of_line (); rl_beg_of_line ();
@ -660,7 +686,7 @@ rl_vi_domove (key, nextkey)
rl_line_buffer[rl_end++] = ' '; rl_line_buffer[rl_end++] = ' ';
rl_line_buffer[rl_end] = '\0'; rl_line_buffer[rl_end] = '\0';
rl_dispatch (c, _rl_keymap); _rl_dispatch (c, _rl_keymap);
/* Remove the blank that we added. */ /* Remove the blank that we added. */
rl_end = old_end; rl_end = old_end;
@ -675,23 +701,30 @@ rl_vi_domove (key, nextkey)
/* rl_vi_f[wW]ord () leaves the cursor on the first character of the next /* rl_vi_f[wW]ord () leaves the cursor on the first character of the next
word. If we are not at the end of the line, and we are on a word. If we are not at the end of the line, and we are on a
non-whitespace character, move back one (presumably to whitespace). */ non-whitespace character, move back one (presumably to whitespace). */
if ((c == 'w' || c == 'W') && (rl_point < rl_end) && if ((to_upper (c) == 'W') && rl_point < rl_end && rl_point > rl_mark &&
!whitespace (rl_line_buffer[rl_point])) !whitespace (rl_line_buffer[rl_point]))
rl_point--; rl_point--;
/* If cw or cW, back up to the end of a word, so the behaviour of ce /* If cw or cW, back up to the end of a word, so the behaviour of ce
or cE is the actual result. Brute-force, no subtlety. */ or cE is the actual result. Brute-force, no subtlety. */
if (key == 'c' && (to_upper (c) == 'W')) if (key == 'c' && rl_point >= rl_mark && (to_upper (c) == 'W'))
{ {
while (rl_point && whitespace (rl_line_buffer[rl_point])) /* Don't move farther back than where we started. */
while (rl_point > rl_mark && whitespace (rl_line_buffer[rl_point]))
rl_point--; rl_point--;
/* Move past the end of the word so that the kill doesn't remove the /* Posix.2 says that if cw or cW moves the cursor towards the end of
last letter of the previous word. Only do this if we are not at the line, the character under the cursor should be deleted. */
the end of the line. */ if (rl_point == rl_mark)
if ((rl_point >= 0) && (rl_point < (rl_end - 1)) && rl_point++;
!whitespace (rl_line_buffer[rl_point])) else
rl_point++; {
/* Move past the end of the word so that the kill doesn't
remove the last letter of the previous word. Only do this
if we are not at the end of the line. */
if (rl_point >= 0 && rl_point < (rl_end - 1) && !whitespace (rl_line_buffer[rl_point]))
rl_point++;
}
} }
if (rl_mark < rl_point) if (rl_mark < rl_point)
@ -702,6 +735,7 @@ rl_vi_domove (key, nextkey)
/* A simplified loop for vi. Don't dispatch key at end. /* A simplified loop for vi. Don't dispatch key at end.
Don't recognize minus sign? */ Don't recognize minus sign? */
static int
rl_digit_loop1 () rl_digit_loop1 ()
{ {
int key, c; int key, c;
@ -790,9 +824,11 @@ rl_vi_change_to (count, key)
if ((to_upper (c) == 'W') && rl_point < start_pos) if ((to_upper (c) == 'W') && rl_point < start_pos)
rl_point = start_pos; rl_point = start_pos;
rl_kill_text (rl_point, rl_mark);
rl_begin_undo_group (); rl_begin_undo_group ();
_rl_vi_doing_insert = 1; _rl_vi_doing_insert = 1;
rl_kill_text (rl_point, rl_mark); _rl_vi_set_last (key, count, rl_arg_sign);
rl_vi_insertion_mode (); rl_vi_insertion_mode ();
return (0); return (0);
@ -930,7 +966,7 @@ rl_vi_char_search (count, key)
if (pos == 0) if (pos == 0)
{ {
ding (); ding ();
return; return -1;
} }
pos--; pos--;
@ -1096,7 +1132,6 @@ rl_vi_subst (count, key)
int count, key; int count, key;
{ {
rl_begin_undo_group (); rl_begin_undo_group ();
_rl_vi_doing_insert = 1;
if (uppercase_p (key)) if (uppercase_p (key))
{ {
@ -1108,7 +1143,12 @@ rl_vi_subst (count, key)
rl_end_undo_group (); rl_end_undo_group ();
_rl_vi_set_last (key, count, rl_arg_sign);
rl_begin_undo_group ();
_rl_vi_doing_insert = 1;
rl_vi_insertion_mode (); rl_vi_insertion_mode ();
return (0); return (0);
} }
@ -1202,6 +1242,7 @@ rl_vi_replace (count, key)
return (0); return (0);
} }
#if 0
/* Try to complete the word we are standing on or the word that ends with /* Try to complete the word we are standing on or the word that ends with
the previous character. A space matches everything. Word delimiters are the previous character. A space matches everything. Word delimiters are
space and ;. */ space and ;. */
@ -1211,9 +1252,9 @@ rl_vi_possible_completions()
if (rl_line_buffer[rl_point] != ' ' && rl_line_buffer[rl_point] != ';') if (rl_line_buffer[rl_point] != ' ' && rl_line_buffer[rl_point] != ';')
{ {
while (rl_line_buffer[rl_point] != ' ' && while (rl_point < rl_end && rl_line_buffer[rl_point] != ' ' &&
rl_line_buffer[rl_point] != ';') rl_line_buffer[rl_point] != ';')
; rl_point++;
} }
else if (rl_line_buffer[rl_point - 1] == ';') else if (rl_line_buffer[rl_point - 1] == ';')
{ {
@ -1226,6 +1267,7 @@ rl_vi_possible_completions()
return (0); return (0);
} }
#endif
#if defined (STATIC_MALLOC) #if defined (STATIC_MALLOC)