branch: elpa/bash-completion commit d32863dde8d35a44d8b88930d50d3979ea22788e Author: Stephane Zermatten <szerm...@gmx.net> Commit: Stephane Zermatten <szerm...@gmx.net>
fix: Update prompt after a syntax error. Before this change, the prompt may be left to the special bash prompt after a syntax error, because Bash won't execute the DEBUG trap at all in such a scenario. At least recent ones won't; that might depend on the exact version of Bash. This change switches to a new scheme that recovers PS1 after bash has executed commands without relying on a trap. This means that PS1 may be printed, but after the special bash-completion marker, so the string will be skipped. PROMPT_COMMAND is still recovered as it was before this change, using a DEBUG trap, to avoid slow prompt command making completion unusable. The drawback of this approach is that that PS1 may not updated after a bash syntax error as it would normally. issue #79 --- bash-completion.el | 23 +++++++++++++---------- test/bash-completion-integration-test.el | 26 -------------------------- 2 files changed, 13 insertions(+), 36 deletions(-) diff --git a/bash-completion.el b/bash-completion.el index 4d24b4038c..d82958cae9 100644 --- a/bash-completion.el +++ b/bash-completion.el @@ -1536,7 +1536,7 @@ Return the status code of the command, as a number." " __ebcpre; %s; __ebcret $?; " "else " " echo ==emacs==nopre=${BASH_VERSION}==.; " - " __ebcp=(\"$PS1\" \"$PROMPT_COMMAND\" $__ebcor);" + " __ebcp=(\"$PS1\" \"${__ebcpc:-$PROMPT_COMMAND}\" $__ebcor);" " unset PS1 PROMPT_COMMAND __ebcor;" "fi;\n")) ;; single process, define __ebcpre @@ -1549,13 +1549,16 @@ Return the status code of the command, as a number." " fi;" " history -d $c &>/dev/null || true;" "} ; function __ebcret {" - " __ebcret=$1;" - " return ${__ebcp[2]};" - "} ; function __ebctrap {" - " if [[ -n \"$__ebcret\" && ${#__ebcp[@]} -gt 0 ]]; then" + " local r=$1 e=${__ebcp[2]};" " PS1=\"${__ebcp[0]}\";" - " PROMPT_COMMAND=\"${__ebcp[1]}\";" - " unset __ebcp __ebcret;" + " __ebcpc=\"${__ebcp[1]}\";" + " unset __ebcp;" + " echo \"==emacs==ret=$r==.\";" + " return $e;" + "} ; function __ebctrap {" + " if [[ ${#__ebcpc} -gt 0 ]]; then" + " PROMPT_COMMAND=\"${__ebcpc}\";" + " unset __ebcpc;" " fi;" "} ; " "if [[ \"$(trap -p DEBUG)\" =~ trap\\ --\\ \\'(.*)\\'\\ DEBUG ]]; then " @@ -1568,10 +1571,10 @@ Return the status code of the command, as a number." " set +x; set +o emacs; set +o vi;" " echo \"==emacs==bash=${BASH_VERSION}==.\";" " if [[ ${#__ebcp[@]} = 0 ]]; then " - " __ebcp=(\"$PS1\" \"$PROMPT_COMMAND\" $__ebcor);" + " __ebcp=(\"$PS1\" \"${__ebcpc:-$PROMPT_COMMAND}\" $__ebcor);" " fi;" - " PS1=" bash-completion--ps1 ";" - " unset PROMPT_COMMAND __ebcor;" + ;;" PS1='==emacs==prompt=1==.';" + " unset PS1 PROMPT_COMMAND __ebcor;" " __ebcnohistory 1;" "} ; { __ebcpre; %s; __ebcret $?; }\n"))) commandline))) diff --git a/test/bash-completion-integration-test.el b/test/bash-completion-integration-test.el index 2364cf6d0f..02c24ecc0d 100644 --- a/test/bash-completion-integration-test.el +++ b/test/bash-completion-integration-test.el @@ -960,30 +960,4 @@ $ "))))) "101\n" "$ "))))) -(ert-deftest bash-completion-keep-existing-trap () - (bash-completion_test-with-shell-harness - (concat ; .bashrc - "calls=0\n" - "function _calltrap {\n" - " calls=$((calls+1))\n" - "}\n" - "trap _calltrap DEBUG\n" - "PS1='\$ '") - nil - (bash-completion_test-send "n=$calls") - (bash-completion_test-send "tru" 'complete) - (bash-completion_test-send "fals" 'complete) - (bash-completion_test-send "[[ $calls -gt $n ]] && echo ok") - (bash-completion_test-send "trap -p DEBUG") - (should (equal (bash-completion_test-buffer-string) - (concat - "$ n=$calls\n" - "$ true\n" - "$ false\n" - "$ [[ $calls -gt $n ]] && echo ok\n" - "ok\n" - "$ trap -p DEBUG\n" - "trap -- '_calltrap; __ebctrap' DEBUG\n" - "$ "))))) - ;;; bash-completion-integration-test.el ends here