emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/bash-completion 4b80c75c43 272/313: Take current directory


From: ELPA Syncer
Subject: [nongnu] elpa/bash-completion 4b80c75c43 272/313: Take current directory from shell when in single-process mode.
Date: Sat, 3 Dec 2022 10:59:37 -0500 (EST)

branch: elpa/bash-completion
commit 4b80c75c433e5a5db9ba11fd6cc0832a30bff603
Author: Stephane Zermatten <szermatt@gmx.net>
Commit: Stephane Zermatten <szermatt@gmx.net>

    Take current directory from shell when in single-process mode.
    
    This change avoids having to rely on directory tracking to keep
    default-directory in sync with the shell's current directory. When
    possible, the current directory is sent out together with the
    completion.
---
 bash-completion.el                       | 22 +++++++++++++---------
 test/bash-completion-integration-test.el |  8 ++++++++
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/bash-completion.el b/bash-completion.el
index c2c935cd6c..b9c2d4c571 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -924,8 +924,9 @@ for directory name detection to work.
 Post-processing includes escaping special characters, adding a /
 to directory names, replacing STUB with UNPARSED-STUB in the
 result. See `bash-completion-fix' for more details."
-  (let ((output) (candidates))
+  (let ((output) (candidates) (pwd))
     (with-current-buffer buffer
+      (setq pwd (bash-completion--parse-side-channel-data "pwd"))
       (let ((compopt (bash-completion--parse-side-channel-data "compopt")))
         (cond
          ((string= "-o nospace" compopt)
@@ -934,13 +935,16 @@ result. See `bash-completion-fix' for more details."
           (setf (bash-completion--compopt comp) '((nospace . nil))))))
       (setq output (buffer-string)))
     (setq candidates (delete-dups (split-string output "\n" t)))
-    (if (eq 1 (length candidates))
-        (list (bash-completion-fix (car candidates) comp t))
-      ;; multiple candidates
-      (let ((result (list)))
-        (dolist (completion candidates)
-          (push (bash-completion-fix completion comp nil) result))
-        (delete-dups (nreverse result))))))
+    (let ((default-directory (if pwd
+                                 (concat (file-remote-p default-directory) pwd)
+                               default-directory)))
+      (if (eq 1 (length candidates))
+          (list (bash-completion-fix (car candidates) comp t))
+        ;; multiple candidates
+        (let ((result (list)))
+          (dolist (completion candidates)
+            (push (bash-completion-fix completion comp nil) result))
+          (delete-dups (nreverse result)))))))
 
 (defun bash-completion-fix (str comp single)
   "Fix completion candidate in STR for COMP
@@ -1350,7 +1354,7 @@ completion candidates."
     (concat
      (if bash-completion-use-separate-processes
          (bash-completion-cd-command-prefix)
-       "")
+       (bash-completion--side-channel-data "pwd" "${PWD}"))
      (cond
       ((eq 'command completion-type)
        (concat "compgen -b -c -a -A function -- " quoted-stub))
diff --git a/test/bash-completion-integration-test.el 
b/test/bash-completion-integration-test.el
index d718110052..be9765f5aa 100644
--- a/test/bash-completion-integration-test.el
+++ b/test/bash-completion-integration-test.el
@@ -530,4 +530,12 @@ other
     4  history
 $ ")))))
 
+(ert-deftest bash-completion-integration-bad-directory-tracking ()
+  "When using single-process, bad directory tracking shouldn't be a problem."
+  (bash-completion_test-with-shell-harness
+   ""  ; .bashrc
+   nil ; use-separate-process
+   (let ((default-directory "/does-not-exist/"))
+     (should (equal "ls some/" (bash-completion_test-complete "ls so"))))))
+
 ;;; bash-completion-integration-test.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]