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

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

[nongnu] elpa/bash-completion a223260f2d 181/313: Get rid of bash-comple


From: ELPA Syncer
Subject: [nongnu] elpa/bash-completion a223260f2d 181/313: Get rid of bash-completion-alist completely.
Date: Sat, 3 Dec 2022 10:59:28 -0500 (EST)

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

    Get rid of bash-completion-alist completely.
    
    959e27d introduced per-process alists, but still kept the global
    bash-completion-alist in places. This commit removes that global
    completely, to avoid confusion.
---
 bash-completion.el                       | 84 +++++++++++---------------------
 test/bash-completion-integration-test.el |  1 -
 test/bash-completion-test.el             | 32 +-----------
 3 files changed, 30 insertions(+), 87 deletions(-)

diff --git a/bash-completion.el b/bash-completion.el
index 36a82d93b3..f0d8fbe54f 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -229,15 +229,6 @@ beginning of a bash completion subprocess.")
 
 Mapping between remote paths as returned by `file-remote-p' and
 Bash processes")
-(defvar bash-completion-alist nil
-  "Maps from command name to the 'complete' arguments.
-
-For example if the following completion is defined in bash:
-  complete -F _cdargs_aliases cdb
-the following entry is added to `bash-completion-alist':
- (\"cdb\" . (\"-F\" \"_cdargs\"))
-
-See `bash-completion-add-to-alist'.")
 
 (defconst bash-completion-wordbreaks-str "@><=;|&(:"
   "String of word break characters.
@@ -766,9 +757,6 @@ up the completion environment (COMP_LINE, COMP_POINT, 
COMP_WORDS,
 COMP_CWORD) and calls compgen.
 
 The result is a list of candidates, which might be empty."
-  ;; start process now, to make sure bash-completion-alist is
-  ;; set before we run bash-completion-generate-line
-  
   (let* ((entry (bash-completion-require-process))
          (process (car entry))
          (completion-status)
@@ -779,10 +767,8 @@ The result is a list of candidates, which might be empty."
       ;; functions bound by complete -D. Presumably, the function has
       ;; just setup completion for the current command and is asking
       ;; us to retry once with the new configuration.
-      (let ((bash-completion-alist nil))
-        (bash-completion-send "complete -p" process)
-        (bash-completion-build-alist (process-buffer process))
-        (setcdr entry bash-completion-alist))
+      (bash-completion-send "complete -p" process)
+      (setcdr entry (bash-completion-build-alist (process-buffer process)))
       (bash-completion--customize comp 'nodefault)
       (setq completion-status (bash-completion-send 
(bash-completion-generate-line comp) process)))
     (setq options (bash-completion--options comp))
@@ -1088,8 +1074,8 @@ is set to t."
               ;; spaces. Noticed in bash_completion v1.872.
               (bash-completion-send "function quote_readline { echo \"$1\"; }" 
process)
               (bash-completion-send "complete -p" process)
-              (bash-completion-build-alist (process-buffer process))
-              (let ((entry (cons process bash-completion-alist)))
+              (let ((entry (cons process (bash-completion-build-alist
+                                          (process-buffer process)))))
                 (push (cons remote entry)
                       bash-completion-processes)
                 (setq cleanup nil)
@@ -1116,47 +1102,34 @@ Return a bash command-line for going to 
default-directory or \"\"."
       "")))
 
 (defun bash-completion-build-alist (buffer)
-  "Build `bash-completion-alist' with the content of BUFFER.
+  "Parse the content of BUFFER into an alist.
 
 BUFFER should contains the output of:
   complete -p
 
-Return `bash-completion-alist', which is slightly parsed version
-of the output of \"complete -p\"."
-  (with-current-buffer buffer
-    (save-excursion
-      (setq bash-completion-alist nil)
-      (goto-char (point-max))
-      (while (= 0 (forward-line -1))
-       (bash-completion-add-to-alist
-        (bash-completion-strings-from-tokens
-         (bash-completion-tokenize
-          (line-beginning-position)
-          (line-end-position)))))))
-  bash-completion-alist)
-
-(defun bash-completion-add-to-alist (words)
-  "Add split 'complete' line WORDS to `bash-completion-add-to-alist'.
-
-This parses the complete command-line arguments as output by
-  complete -p
-
-This does not work on arbitrary 'complete' calls.
-
-Lines that do not start with the word complete are skipped.
-
-Return `bash-completion-alist'."
-  (when (string= "complete" (car words))
-    (if (member "-D" (cdr words))
-       ;; default completion 
-       (push (cons nil (delete "-D" (cdr words))) bash-completion-alist)
-      ;; normal completion
-      (let* ((reverse-wordsrest (nreverse (cdr words)))
-            (command (car reverse-wordsrest))
-            (options (nreverse (cdr reverse-wordsrest))) )
-       (when (and command options)
-         (push (cons command options) bash-completion-alist)))))
-  bash-completion-alist)
+The returned alist is a sligthly parsed version of the output of
+\"complete -p\"."
+  (let ((alist (list)))
+    (with-current-buffer buffer
+      (save-excursion
+        (setq alist nil)
+        (goto-char (point-max))
+        (while (= 0 (forward-line -1))
+          (let ((words (bash-completion-strings-from-tokens
+                        (bash-completion-tokenize
+                         (line-beginning-position)
+                         (line-end-position)))))
+            (when (string= "complete" (car words))
+              (if (member "-D" (cdr words))
+                  ;; default completion 
+                  (push (cons nil (delete "-D" (cdr words))) alist)
+                ;; normal completion
+                (let* ((reverse-wordsrest (nreverse (cdr words)))
+                       (command (car reverse-wordsrest))
+                       (options (nreverse (cdr reverse-wordsrest))) )
+                  (when (and command options)
+                    (push (cons command options) alist)))))))))
+    alist))
 
 (defun bash-completion--customize (comp &optional nodefault)
   (unless (eq 'command (bash-completion--type comp))
@@ -1166,7 +1139,6 @@ Return `bash-completion-alist'."
               (or (cdr (assoc command-name bash-completion-alist))
                   (and (not nodefault) (cdr (assoc nil 
bash-completion-alist)))))))))
 
-
 (defun bash-completion-generate-line (comp)
   "Generate a command-line that calls compgen for COMP.
 
diff --git a/test/bash-completion-integration-test.el 
b/test/bash-completion-integration-test.el
index 09d912aa4f..48e1713933 100644
--- a/test/bash-completion-integration-test.el
+++ b/test/bash-completion-integration-test.el
@@ -37,7 +37,6 @@
   `(if (file-executable-p bash-completion-prog)
      (let ((test-env-dir (bash-completion_test-setup-env)))
        (let ((bash-completion-processes nil)
-             (bash-completion-alist nil)
              (bash-completion-nospace 'as-configured)
              (bash-completion-enable-caching nil)
              (bash-completion-start-files nil)
diff --git a/test/bash-completion-test.el b/test/bash-completion-test.el
index 1ddde4d471..6a741d1b9f 100644
--- a/test/bash-completion-test.el
+++ b/test/bash-completion-test.el
@@ -279,34 +279,7 @@ The return value is the one returned by BODY."
             "cd '/vcr/shows/Dexter'\\''s"
             (bash-completion--parse (point-min) 27)))))
 
-(ert-deftest bash-completion-add-to-alist-test ()
-  ;; garbage
-  (should (equal nil
-                (let ((bash-completion-alist nil))
-                  (bash-completion-add-to-alist (list "just" "some" 
"garbage")))))
-
-  ;; empty
-  (should (equal nil
-                (let ((bash-completion-alist nil))
-                  (bash-completion-add-to-alist '()))))
-
-  ;; empty string
-  (should (equal nil
-                (let ((bash-completion-alist nil))
-                  (bash-completion-add-to-alist (list "")))))
-
-  ;; empty complete
-  (should (equal  nil
-                 (let ((bash-completion-alist nil))
-                   (bash-completion-add-to-alist (list "complete")))))
-
-  ;; one command
-  (should (equal '(("cdb" . ("-e" "-F" "_cdargs_aliases")))
-                (let (bash-completion-alist)
-                  (bash-completion-add-to-alist
-                   (list "complete" "-e" "-F" "_cdargs_aliases" "cdb"))))))
-
-(ert-deftest bash-completion-build-alist-test ()
+(ert-deftest bash-completion-build-alist ()
   (should (equal
           '(("cdb" "-F" "_cdargs_aliases")
             ("project" "-F" "complete_projects")
@@ -324,8 +297,7 @@ complete -F _cdargs_aliases cb
 complete -F _completion_loader -D
 garbage
 "
-           (let ((bash-completion-alist '(garbage)))
-             (bash-completion-build-alist (current-buffer)))))))
+            (bash-completion-build-alist (current-buffer))))))
 
 (ert-deftest bash-completion-quote-test ()
   ;; not necessary



reply via email to

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