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

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

[nongnu] elpa/bash-completion 47a890dd72 010/313: launch process, send c


From: ELPA Syncer
Subject: [nongnu] elpa/bash-completion 47a890dd72 010/313: launch process, send commands
Date: Sat, 3 Dec 2022 10:59:07 -0500 (EST)

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

    launch process, send commands
---
 bash-complete.el | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/bash-complete.el b/bash-complete.el
index 0a2567d88d..e102496f33 100644
--- a/bash-complete.el
+++ b/bash-complete.el
@@ -1,6 +1,10 @@
 
 (require 'comint)
 
+(defvar bash-complete-executable "bash"
+  "Command-line to execute bash")
+(defvar bash-complete-process-timeout 2.5)
+
 (defvar bash-complete-process nil
   "Bash process object")
 (defvar bash-complete-alist nil
@@ -119,6 +123,41 @@ The result is a list of candidates, which might be empty."
 
   )
 
+(defun bash-complete-require-process ()
+  ;; TODO(szermatt): if this fails, kill process and complain
+  (unless (bash-complete-is-running)
+    (setq bash-complete-process
+         (start-process
+          "*bash-complete*"
+          "*bash-complete*"
+          bash-complete-executable
+          "--noediting"))
+    (set-process-query-on-exit-flag bash-complete-process nil)
+    (bash-complete-send "PS1='\v'")
+    (bash-complete-send "complete -p")
+    (bash-complete-build-alist (process-buffer bash-complete-process)))
+  bash-complete-process)
+
+(defun bash-complete-kill-process ()
+  (when (bash-complete-is-running)
+    (kill-process bash-complete-process)))
+
+(defun bash-complete-buffer ()
+  (process-buffer (bash-complete-require-process)))
+
+(defun bash-complete-is-running ()
+  (and bash-complete-process (eq 'run (process-status bash-complete-process))))
+
+(defun bash-complete-send (commandline)
+  (with-current-buffer (bash-complete-buffer)
+    (erase-buffer)
+    (process-send-string bash-complete-process (concat commandline "\n"))
+    (while (not (progn (goto-char 1) (search-forward "\v" nil t)))
+      (unless (accept-process-output bash-complete-process 
bash-complete-process-timeout)
+       (error "Timeout while waiting for an answer from bash-complete 
process")))
+    (goto-char (point-max))
+    (delete-backward-char 1)))
+
 (defun bash-complete-build-alist (buffer)
   "Build `bash-complete-alist' with the content of BUFFER.
 



reply via email to

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