This commit is contained in:
Andrey A. Chernov 1995-03-17 01:40:52 +00:00
parent c5b0a90902
commit 0efbb29eec
8 changed files with 172 additions and 39 deletions

View file

@ -308,18 +308,41 @@ printable_part (pathname)
/* 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. */
#define PUTX(c) \
if (CTRL_CHAR (c)) \
{ \
putc ('^', rl_outstream); \
putc (UNCTRL (c), rl_outstream); \
} \
else if (c == RUBOUT) \
{ \
putc ('^', rl_outstream); \
putc ('?', rl_outstream); \
} \
else \
putc (c, rl_outstream)
static int
print_filename (to_print, full_pathname)
char *to_print, *full_pathname;
{
#if !defined (VISIBLE_STATS)
fputs (to_print, rl_outstream);
char *s;
for (s = to_print; *s; s++)
{
PUTX (*s);
}
return 0;
#else
char *s, c, *new_full_pathname;
int extension_char = 0, slen, tlen;
fputs (to_print, rl_outstream);
for (s = to_print; *s; s++)
{
PUTX (*s);
}
if (rl_filename_completion_desired && rl_visible_stats)
{
/* If to_print != full_pathname, to_print is the basename of the
@ -645,7 +668,7 @@ rl_complete_internal (what_to_do)
not be checked, add !matches[1] to the if clause. */
should_quote = rl_strpbrk (matches[0], rl_completer_word_break_characters) != 0;
#if defined (SHELL)
should_quote = should_quote || rl_strpbrk (matches[0], "#$`") != 0;
should_quote = should_quote || rl_strpbrk (matches[0], "#$`?*[") != 0;
#endif
if (should_quote)

View file

@ -247,6 +247,9 @@ rl_expand_prompt (prompt)
free (local_prompt_prefix);
local_prompt = local_prompt_prefix = (char *)0;
if (prompt == 0 || *prompt == '\0')
return (0);
p = strrchr (prompt, '\n');
if (!p)
{

View file

@ -44,6 +44,8 @@ in your own programs, this section is for you.
@menu
* Basic Behavior:: Using the default behavior of Readline.
* Custom Functions:: Adding your own functions to Readline.
* Readline Variables:: Variables accessible to custom
functions.
* Readline Convenience Functions:: Functions which Readline supplies to
aid in writing your own
* Custom Completers:: Supplanting or supplementing Readline's
@ -230,6 +232,11 @@ to do something useful with both negative and positive arguments.
At the very least, it should be aware that it can be passed a
negative argument.
@node Readline Variables
@section Readline Variables
These variables are available to function writers.
@deftypevar {char *} rl_line_buffer
This is the line gathered so far. You are welcome to modify the
contents of the line, but see @ref{Allowing Undoing}.
@ -289,6 +296,11 @@ If non-zero, this is the address of a function to call just
before @code{readline} prints the first prompt.
@end deftypevar
@deftypevar {Function *} rl_event_hook
If non-zero, this is the address of a function to call periodically
when readline is waiting for terminal input.
@end deftypevar
@node Readline Convenience Functions
@section Readline Convenience Functions
@ -422,6 +434,11 @@ perform any key bindings and variable assignments found
(@pxref{Readline Init File}).
@end deftypefun
@deftypefun int rl_read_init_file (char *filename)
Read keybindings and variable assignments from @var{filename}
(@pxref{Readline Init File}).
@end deftypefun
@node Associating Function Names and Bindings
@subsection Associating Function Names and Bindings
@ -449,6 +466,17 @@ Return an array of strings representing the key sequences used to
invoke @var{function} in the keymap @var{map}.
@end deftypefun
@deftypefun void rl_function_dumper (int readable)
Print the readline function names and the key sequences currently
bound to them to @code{rl_outstream}. If @var{readable} is non-zero,
the list is formatted in such a way that it can be made part of an
@code{inputrc} file and re-read.
@end deftypefun
@deftypefun void rl_list_funmap_names ()
Print the names of all bindable Readline functions to @code{rl_outstream}.
@end deftypefun
@node Allowing Undoing
@subsection Allowing Undoing
@ -577,6 +605,22 @@ not a kill, a new kill ring slot is used.
@node Utility Functions
@subsection Utility Functions
@deftypefun int rl_read_key ()
Return the next character available. This handles input inserted into
the input stream via @var{pending input} (@pxref{Readline Variables})
and @code{rl_stuff_char ()}, macros, and characters read from the keyboard.
@end deftypefun
@deftypefun int rl_stuff_char (int c)
Insert @var{c} into the Readline input stream. It will be "read"
before Readline attempts to read characters from the terminal with
@code{rl_read_key ()}.
@end deftypefun
@deftypefun int rl_initialize ()
Initialize or re-initialize Readline's internal state.
@end deftypefun
@deftypefun int rl_reset_terminal (char *terminal_name)
Reinitialize Readline's idea of the terminal settings using
@var{terminal_name} as the terminal type (e.g., @code{vt100}).
@ -869,6 +913,13 @@ The list of characters that signal a break between words for
@code{rl_basic_word_break_characters}.
@end deftypevar
@deftypevar {char *} rl_completer_quote_characters
List of characters which can be used to quote a substring of the line.
Completion occurs on the entire substring, and within the substring
@code{rl_completer_word_break_characters} are treated as any other character,
unless they also appear within this list.
@end deftypevar
@deftypevar {char *} rl_special_prefixes
The list of characters that are word break characters, but should be
left in @var{text} when it is passed to the completion function.
@ -909,14 +960,13 @@ re-arrange the list of matches as required, but each element deleted
from the array must be freed.
@end deftypevar
@deftypevar {char *} rl_completer_quote_characters
List of characters which can be used to quote a substring of the line.
Completion occurs on the entire substring, and within the substring
@code{rl_completer_word_break_characters} are treated as any other character,
unless they also appear within this list.
@deftypevar {Function *} rl_directory_completion_hook
This function, if defined, is allowed to modify the directory portion
of filenames Readline completes. It is called with the address of a
string (the current directory name) as an argument. It could be used
to expand symbolic links or shell variables in pathnames.
@end deftypevar
@node A Short Completion Example
@subsection A Short Completion Example

View file

@ -102,6 +102,7 @@ static int subst_lhs_len = 0;
static int subst_rhs_len = 0;
static char *get_history_word_specifier ();
static char *history_find_word ();
#if defined (SHELL)
extern char *single_quote ();
@ -875,6 +876,9 @@ history_set_pos (pos)
/* The last string searched for in a !?string? search. */
static char *search_string = (char *)NULL;
/* The last string matched by a !?string? search. */
static char *search_match = (char *)NULL;
/* Return the event specified at TEXT + OFFSET modifying OFFSET to
point to after the event specifier. Just a pointer to the history
line is returned; NULL is returned in the event of a bad specifier.
@ -1000,6 +1004,10 @@ get_history_event (string, caller_index, delimiting_quote)
if (search_string)
free (search_string);
search_string = temp;
if (search_match)
free (search_match);
search_match = history_find_word (entry->line, local_index);
}
else
free (temp);
@ -1799,7 +1807,7 @@ get_history_word_specifier (spec, from, caller_index)
if (spec[i] == '%')
{
*caller_index = i + 1;
return (search_string ? savestring (search_string) : savestring (""));
return (search_match ? savestring (search_match) : savestring (""));
}
/* `*' matches all of the arguments, but not the command. */
@ -1932,11 +1940,14 @@ history_arg_extract (first, last, string)
#define slashify_in_quotes "\\`\"$"
/* Return an array of tokens, much as the shell might. The tokens are
parsed out of STRING. */
char **
history_tokenize (string)
/* Parse STRING into tokens and return an array of strings. If WIND is
not -1 and INDP is not null, we also want the word surrounding index
WIND. The position in the returned array of strings is returned in
*INDP. */
static char **
history_tokenize_internal (string, wind, indp)
char *string;
int wind, *indp;
{
char **result = (char **)NULL;
register int i, start, result_index, size;
@ -2026,6 +2037,11 @@ history_tokenize (string)
}
got_token:
/* If we are looking for the word in which the character at a
particular index falls, remember it. */
if (indp && wind >= 0 && wind >= start && wind < i)
*indp = result_index;
len = i - start;
if (result_index + 2 >= size)
result = (char **)xrealloc (result, ((size += 10) * sizeof (char *)));
@ -2038,6 +2054,38 @@ history_tokenize (string)
return (result);
}
/* Return an array of tokens, much as the shell might. The tokens are
parsed out of STRING. */
char **
history_tokenize (string)
char *string;
{
return (history_tokenize_internal (string, -1, (int *)NULL));
}
/* Find and return the word which contains the character at index IND
in the history line LINE. Used to save the word matched by the
last history !?string? search. */
static char *
history_find_word (line, ind)
char *line;
int ind;
{
char **words, *s;
int i, wind;
words = history_tokenize_internal (line, ind, &wind);
if (wind == -1)
return ((char *)NULL);
s = words[wind];
for (i = 0; i < wind; i++)
free (words[i]);
for (i = wind + 1; words[i]; i++)
free (words[i]);
free (words);
return s;
}
#if defined (STATIC_MALLOC)
/* **************************************************************** */

View file

@ -6,9 +6,9 @@
.\" Case Western Reserve University
.\" chet@ins.CWRU.Edu
.\"
.\" Last Change: Mon Jun 13 20:06:14 EDT 1994
.\" Last Change: Wed Jul 20 16:13:11 EDT 1994
.\"
.TH READLINE 3 "1994 June 13" GNU
.TH READLINE 3 "1994 July 26" GNU
.\"
.\" File Name macro. This used to be `.PN', for Path Name,
.\" but Sun doesn't seem to like that very much.
@ -22,8 +22,8 @@ readline \- get a line from a user with editing
.LP
.nf
.ft B
#include <readline/readline.h>
#include <readline/history.h>
#include <readline.h>
#include <history.h>
.ft
.fi
.LP
@ -78,6 +78,8 @@ int key;
Keymap keymap;
.ft
.fi
.LP
.nf
.ft B
int rl_macro_bind (keyseq, macro, keymap)
char *keyseq, *macro;
@ -737,6 +739,12 @@ cursor position). With an argument
insert the \fIn\fPth word from the previous command (the words
in the previous command begin with word 0). A negative argument
inserts the \fIn\fPth word from the end of the previous command.
.TP
.B
yank\-last\-arg (M\-.\^, M\-_\^)
Insert the last argument to the previous command (the last word on
the previous line). With an argument,
behave exactly like @code{yank-nth-arg}.
.PD
.SS Commands for Changing Text
.PP
@ -1164,9 +1172,9 @@ VI Command Mode functions
.SH "SEE ALSO"
.PD 0
.TP
\fIThe Gnu Readline Library\fP, Brian Fox
\fIThe Gnu Readline Library\fP, Brian Fox and Chet Ramey
.TP
\fIThe Gnu History Library\fP, Brian Fox
\fIThe Gnu History Library\fP, Brian Fox and Chet Ramey
.TP
\fIbash\fP(1)
.PD

View file

@ -284,7 +284,7 @@ readline (prompt)
return ((char *)NULL);
}
rl_visible_prompt_length = (rl_prompt && *rl_prompt) ? rl_expand_prompt (rl_prompt) : 0;
rl_visible_prompt_length = rl_expand_prompt (rl_prompt);
rl_initialize ();
rl_prep_terminal (_rl_meta_flag);

View file

@ -34,10 +34,6 @@
# include "memalloc.h"
#endif
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
#endif /* HAVE_UNISTD_H */
#define NEW_TTY_DRIVER
#define HAVE_BSD_SIGNALS
/* #define USE_XON_XOFF */
@ -91,18 +87,6 @@
# include <sgtty.h>
#endif
/* Define _POSIX_VDISABLE if we are not using the `new' tty driver and
it is not already defined. It is used both to determine if a
special character is disabled and to disable certain special
characters. Posix systems should set to 0, USG systems to -1. */
#if !defined (NEW_TTY_DRIVER) && !defined (_POSIX_VDISABLE)
# if defined (_POSIX_VERSION)
# define _POSIX_VDISABLE 0
# else /* !_POSIX_VERSION */
# define _POSIX_VDISABLE -1
# endif /* !_POSIX_VERSION */
#endif /* !NEW_TTY_DRIVER && !_POSIX_VDISABLE */
#if !defined (SHELL) && (defined (_POSIX_VERSION) || defined (USGr3))
# if !defined (HAVE_DIRENT_H)
# define HAVE_DIRENT_H
@ -176,6 +160,23 @@ extern char *strchr (), *strrchr ();
# define GWINSZ_IN_SYS_IOCTL
#endif
/* Define _POSIX_VDISABLE if we are not using the `new' tty driver and
it is not already defined. It is used both to determine if a
special character is disabled and to disable certain special
characters. Posix systems should set to 0, USG systems to -1. */
#if !defined (NEW_TTY_DRIVER) && !defined (_POSIX_VDISABLE)
# if defined (_SVR4_VDISABLE)
# define _POSIX_VDISABLE _SVR4_VDISABLE
# else
# if defined (_POSIX_VERSION)
# define _POSIX_VDISABLE 0
# else /* !_POSIX_VERSION */
# define _POSIX_VDISABLE -1
# endif /* !_POSIX_VERSION */
# endif /* !_SVR4_VDISABLE */
#endif /* !NEW_TTY_DRIVER && !_POSIX_VDISABLE */
#if !defined (emacs_mode)
# define no_mode -1
# define vi_mode 0

View file

@ -189,11 +189,11 @@ noninc_search (dir, pchar)
break;
case CTRL('W'):
rl_unix_word_rubout ();
rl_unix_word_rubout (1, c);
break;
case CTRL('U'):
rl_unix_line_discard ();
rl_unix_line_discard (1, c);
break;
case RETURN: