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

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

[nongnu] elpa/bash-completion 318e32979f 135/313: Display completion pro


From: ELPA Syncer
Subject: [nongnu] elpa/bash-completion 318e32979f 135/313: Display completion progress message only if completion takes too long.
Date: Sat, 3 Dec 2022 10:59:24 -0500 (EST)

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

    Display completion progress message only if completion takes too long.
    issue #12
    
    bash-completion-message-delay now controls when an whether the message
    "Bash Completion..." is displayed:
     - if it a number, only display it if completion takes longer than
     that much time, in seconds.
     - if it is 0, always display it
     - if it is nil, never display it
    
    The default is to display it if completion takes longer than 400ms.
---
 bash-completion.el | 58 +++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 38 insertions(+), 20 deletions(-)

diff --git a/bash-completion.el b/bash-completion.el
index cefdc2f420..61d81b3897 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -178,6 +178,16 @@ ignored."
   :type '(float)
   :group 'bash-completion)
 
+(defcustom bash-completion-message-delay 0.4
+  "Time to wait before displaying a message while waiting for results.
+
+If completion takes longer than that time, a message is displayed
+on the minibuffer to make it clear what's happening. Set to nil
+to never display any such message. 0 to always display it.
+
+Only relevant when using bash completion in a shell, through
+`bash-completion-dynamic-complete'.")
+
 (defcustom bash-completion-initial-timeout 30
   "Timeout value to apply when talking to bash for the first time.
 The first thing bash is supposed to do is process /etc/bash_complete,
@@ -299,26 +309,34 @@ nil if no completions available.
 
 When doing completion outside of a comint buffer, call
 `bash-completion-dynamic-complete-nocomint' instead."
-    (when (not (window-minibuffer-p))
-      (message "Bash completion..."))
-    (let ((result (bash-completion-dynamic-complete-nocomint
-                   (comint-line-beginning-position)
-                   (point))))
-      (if bash-completion-comint-uses-standard-completion
-          result
-        ;; pre-emacs 24.1 compatibility code
-        (let ((result (bash-completion-dynamic-complete-0)))
-          (when result
-            (let ((stub (buffer-substring-no-properties
-                         (nth 0 result)
-                         (nth 1 result)))
-                  (completions (nth 2 result))
-                  ;; Setting comint-completion-addsuffix overrides
-                  ;; configuration for comint-dynamic-simple-complete.
-                  ;; Bash adds a space suffix automatically.
-                  (comint-completion-addsuffix nil))
-              (with-no-warnings
-                (comint-dynamic-simple-complete stub completions))))))))
+    (let ((message-timer
+           (if (and (not (window-minibuffer-p))
+                    (not (null bash-completion-message-delay)))
+               (run-at-time
+                bash-completion-message-delay nil
+                (lambda () (message "Bash completion..."))))))
+      (unwind-protect
+          (let ((result (bash-completion-dynamic-complete-nocomint
+                         (comint-line-beginning-position)
+                         (point))))
+            (if bash-completion-comint-uses-standard-completion
+                result
+              ;; pre-emacs 24.1 compatibility code
+              (let ((result (bash-completion-dynamic-complete-0)))
+                (when result
+                  (let ((stub (buffer-substring-no-properties
+                               (nth 0 result)
+                               (nth 1 result)))
+                        (completions (nth 2 result))
+                        ;; Setting comint-completion-addsuffix overrides
+                        ;; configuration for comint-dynamic-simple-complete.
+                        ;; Bash adds a space suffix automatically.
+                        (comint-completion-addsuffix nil))
+                    (with-no-warnings
+                      (comint-dynamic-simple-complete stub completions)))))))
+        ;; cleanup
+        (if message-timer
+            (cancel-timer message-timer)))))
 
 (defun bash-completion-dynamic-complete-nocomint (start pos)
   "Return completion information for bash command at an arbitrary position.



reply via email to

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