Skip to content

Commit

Permalink
Only use rl_extend_line_buffer if available
Browse files Browse the repository at this point in the history
The BSD editline library (libedit, version 3.1-20221030) doesn't
implement the rl_extend_line_buffer function. Alternative approaches to
replace the line buffer using the readline interface don't give the
desired behavior. So simply don't use history expansion in the
completion function if the rl_extend_line_buffer function is not
available.
  • Loading branch information
rkraats committed Jul 4, 2023
1 parent b6afced commit e6c2b96
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
/* Define the name of the executing macro variable in libreadline. */
#undef EXECUTING_MACRO_NAME

/* Define if rl_extend_line_buffer is resolved in libreadline. */
#undef EXTEND_LINE_BUFFER

/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H

Expand Down
31 changes: 31 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -12689,6 +12689,37 @@ $as_echo "yes" >&6; };

$as_echo "#define CLEANUP_AFER_SIGNAL 1" >>confdefs.h

else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext

# check for readline's rl_extend_line_buffer

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for rl_extend_line_buffer() in -lreadline" >&5
$as_echo_n "checking for rl_extend_line_buffer() in -lreadline... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
extern void rl_extend_line_buffer(int len);
rl_extend_line_buffer(1);
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; };

$as_echo "#define EXTEND_LINE_BUFFER 1" >>confdefs.h

else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
Expand Down
12 changes: 12 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,18 @@ AC_TRY_LINK(,[
[ Define if rl_cleanup_after_signal is resolved in libreadline. ]),
AC_MSG_RESULT(no))

# check for readline's rl_extend_line_buffer

AC_MSG_CHECKING([for rl_extend_line_buffer() in -lreadline])
AC_TRY_LINK(,[
extern void rl_extend_line_buffer(int len);
rl_extend_line_buffer(1);
],
AC_MSG_RESULT(yes);
AC_DEFINE(EXTEND_LINE_BUFFER, 1,
[ Define if rl_extend_line_buffer is resolved in libreadline. ]),
AC_MSG_RESULT(no))


AC_MSG_CHECKING([for the readline version number])
AC_TRY_RUN([
Expand Down
7 changes: 7 additions & 0 deletions tclreadline.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
#endif


#ifdef EXTEND_LINE_BUFFER
/*
* this prototype may be missing
* in readline.h
*/
void rl_extend_line_buffer(int len);
#endif

#ifdef EXECUTING_MACRO_HACK
/**
Expand Down Expand Up @@ -700,6 +702,10 @@ TclReadlineCompletion(char* text, int start, int end)
int status;
rl_completion_append_character = ' '; /* reset, just in case ... */

/* Only enable history expansion like '!!<TAB>' if the rl_extend_line_buffer
* function is available; e.g. libedit doesn't provide it, and alternative
* approaches to replace the line buffer don't give the desired behavior */
#ifdef EXTEND_LINE_BUFFER
if (tclrl_use_history_expansion && text && ('!' == text[0]
|| (start && rl_line_buffer[start - 1] == '!' /* for '$' */))) {
char* expansion = (char*) NULL;
Expand All @@ -721,6 +727,7 @@ TclReadlineCompletion(char* text, int start, int end)
}
FREE(expansion);
}
#endif

if (tclrl_custom_completer) {
char start_s[BUFSIZ], end_s[BUFSIZ];
Expand Down

0 comments on commit e6c2b96

Please sign in to comment.