szermatt/emacs-bash-completion

Failure to Complete

phikal opened this issue · 5 comments

Hi, I was trying to complete a directory path ~/Doc to ~/Documents using M-x shell, but instead I got this error message:

commandline: <<EOF
__emacs_complete_pre_command; function __emacs_complete_pre_command {  if [[ -z "$__emacs_complete_ps1" ]]; then    __emacs_complete_ps1="$PS1";    __emacs_complete_pc="$PROMPT_COMMAND";  fi;  PROMPT_COMMAND=__emacs_complete_prompt;  if [[ ${BASH_VERSINFO[0]} -eq 5 && ${BASH_VERSINFO[1]} -ge 1 || ${BASH_VERSINFO[0]} -gt 5 ]]; then  history -d $HISTCMD &>/dev/null || true;else  history -d $((HISTCMD - 1)) &>/dev/null || true;fi;} &&function __emacs_complete_prompt {  PS1='	$?�';  PROMPT_COMMAND=__emacs_complete_recover_prompt;} &&function __emacs_complete_recover_prompt {  local r=$?;  PS1="${__emacs_complete_ps1}";  PROMPT_COMMAND="${__emacs_complete_pc}";  unset __emacs_complete_ps1 __emacs_complete_pc;  if [[ -n "$PROMPT_COMMAND" ]]; then    (exit $r); eval "$PROMPT_COMMAND";  fi;} &&__emacs_complete_pre_command
EOF

error: "timeout"

buffer-string: <<EOF
bash: __emacs_complete_pre_command: command not found...
EOF

process: #<process shell>

output-buffer: <<EOF
bash: __emacs_complete_pre_command: command not found...
	0�EOF

emacs-version: "30.0.50"

I have had a similar issue from time to time, but haven't been able to identify what the root cause is. Does the above give any hints? My Bash version is

$ bash --version
GNU bash, version 5.2.26(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

I have similar issue when I connect through TRAMP. I have a customized prompt.

My prompt is just a dollar sign, and this occurs locally. That being said, I do notice that the issue appears to disappear when I rename my .bashrc to something else, which Bash won't load.

After experimenting a bit, I pulled out this block from by .bashrc:

if [ -f /etc/bashrc ]
then
    . /etc/bashrc
fi

and added that to my .bash_profile. This had the same effect as disabling .bashrc, but now my regular terminal didn't do any completion. This could be fixed by enabling the "Run command as login shell" option, in GNOME terminal.

Sorry for the long silence! I hadn't noticed this issue.

This issue could be caused by a lot of things, such as some version incompatibility or some option turned on in your .bashrc, which interferes with the communication between bash and Emacs.

Ill try and reproduce the problem with the exact same versions of Emacs and bash to figure out whether this is a version problem and update this issue with the result.

If I understood correctly your last message, you basically turned off completion everywhere. This is unfortunate. There are other things you could try instead, until the underlying issue is fixed:

  • Turn off sections of your bashrc when running on emacs by checking INSIDE_EMACS. This way the non-emacs use-cases are not affected. For example:
if [[ -z "$INSIDE_EMACS" ]]; then
 . /etc/bashrc # enable completion
fi
  • Execute M-x cutomize-option bash-completion-use-separate-process and set the option to t. With this option, emacs-bash-completion.el uses a separate bash process to do completion. It is less convenient, but more robust as a fallback.

Emacs version 30.0.50 is a development version, which means that a lot of things can go wrong and I'll have trouble testing with the exact same version you're using.

Did you try running with a stable version of Emacs, such as 29.4? Do you have the same issues?

Ill try and reproduce the problem with the exact same versions of Emacs and bash to figure out whether this is a version problem and update this issue with the result.

I tried with the head version of Emacs and bash 5.2.26. This combination seems to work.

From the error output, it seems that Emacs thinks that bash has been initialized, when it hasn't. This typically happens when running remote shell from ssh or shells within a docker instance - or even afterwards, trying to run local completion. The latest version of emacs-bash-completion contains change that are meant to address such issues. Please try the latest version of emacs-bash-completion from melpa instead of melpa-stable, or directly from github.