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

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

[nongnu] elpa/bash-completion 8756e80737 184/313: Replace 'options' in t


From: ELPA Syncer
Subject: [nongnu] elpa/bash-completion 8756e80737 184/313: Replace 'options' in the completion struct with 'nospace'.
Date: Sat, 3 Dec 2022 10:59:29 -0500 (EST)

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

    Replace 'options' in the completion struct with 'nospace'.
    
    Turns out, there are no other options than nospace that need to be
    tracked, so the older implementation was overkill.
    
    Issue #19
---
 bash-completion.el                       |  51 ++++++---------
 test/bash-completion-integration-test.el |  23 ++++---
 test/bash-completion-test.el             | 109 ++++++++++++++++---------------
 3 files changed, 90 insertions(+), 93 deletions(-)

diff --git a/bash-completion.el b/bash-completion.el
index ae4b988748..c73586775e 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -184,7 +184,7 @@ which typically takes a long time."
   :type '(float)
   :group 'bash-completion)
 
-(defcustom bash-completion-nospace 'as-configured
+(defcustom bash-completion-nospace nil
   "Never let bash add a final space at the end of a completion.
 
 When there is only one completion candidate, bash sometimes adds
@@ -283,16 +283,17 @@ customized, usually by `bash-completion--customize'.
    ((bash-completion--compgen-args comp) 'custom)
    (t 'default)))
 
-(defun bash-completion--options (comp)
-  "Returns options for comp, either default or customized.
+(defun bash-completion--nospace (comp)
+  "Returns the value of the nospace option to use for COMP.
 
-See options definition in
-`bash-completion--extract-compgen-options'"
-  (bash-completion--parse-options 
-   (if (eq (bash-completion--type comp) 'custom)
-       (bash-completion--extract-compgen-options
-        (bash-completion--compgen-args comp))
-     nil)))
+The option can be:
+ - set globally, by setting `bash-completion-nospace' to t
+ - set for a customized completion, in bash, with
+   '-o' 'nospace'."
+  (if bash-completion-nospace
+      t ; set globally
+    (bash-completion--has-compgen-option
+     (bash-completion--compgen-args comp) "nospace")))
 
 (defun bash-completion--command (comp)
   "Return the current command for the completion, if there is one."
@@ -756,7 +757,7 @@ for directory name detection to work."
   (let ((parsed-prefix (bash-completion--stub comp))
         (unparsed-prefix (bash-completion--unparsed-stub comp))
         (open-quote (bash-completion--open-quote comp))
-        (options (bash-completion--options comp))
+        (nospace (bash-completion--nospace comp))
         (wordbreaks (bash-completion--wordbreaks comp))
         (suffix "")
         (rest) ; the part between the prefix and the suffix
@@ -795,7 +796,7 @@ for directory name detection to work."
     ;; build suffix
     (let ((last-char (bash-completion-last-char rest))
           (close-quote-str (if open-quote (char-to-string open-quote) ""))
-          (final-space-str (if (memq 'nospace options) "" " ")))
+          (final-space-str (if nospace "" " ")))
       (cond
        ((eq ?\  last-char)
         (setq rest (substring rest 0 -1))
@@ -1209,25 +1210,15 @@ Return the status code of the command, as a number."
         (file-remote-p expanded 'localname)
       expanded)))
 
-(defun bash-completion--extract-compgen-options (compgen-args)
-  "Extract from COMPGEN-ARGS the -o option strings."
-  (let ((rest compgen-args)
-        (options (list)))
-    (while (setq rest (cdr (member "-o" rest)))
-      (push (car rest) options)
+(defun bash-completion--has-compgen-option (compgen-args option-name)
+  "Check whether COMPGEN-ARGS contains -o OPTION-NAME."
+  (let ((rest compgen-args) (found))
+    (while (and (not found)
+                (setq rest (cdr (member "-o" rest))))
+      (when (string= option-name (car rest))
+        (setq found t))
       (setq rest (cdr rest)))
-    options))
-
-(defun bash-completion--parse-options (option-strings)
-  "Parse OPTIONS-STRINGS for compgen into a list of symbols.
-
-The only supported option is nospace, which might come from
-compgen options or from `bash-completion-nospace'"
-  (if (if (eq 'as-configured bash-completion-nospace)
-          (member "nospace" option-strings)
-        bash-completion-nospace)
-      '(nospace)
-    nil))
+    found))
 
 (provide 'bash-completion)
 ;;; bash-completion.el ends here
diff --git a/test/bash-completion-integration-test.el 
b/test/bash-completion-integration-test.el
index e3a753b46b..5a29b1a086 100644
--- a/test/bash-completion-integration-test.el
+++ b/test/bash-completion-integration-test.el
@@ -37,7 +37,7 @@
   `(if (file-executable-p bash-completion-prog)
      (let ((test-env-dir (bash-completion_test-setup-env)))
        (let ((bash-completion-processes nil)
-             (bash-completion-nospace 'as-configured)
+             (bash-completion-nospace nil)
              (bash-completion-enable-caching nil)
              (bash-completion-start-files nil)
              (bash-completion-args
@@ -119,17 +119,16 @@ for testing completion."
    (should (bash-completion-is-running))
    (should-not (null (member
                       "help "
-                      (let ((bash-completion-nospace nil))
-                        (bash-completion-comm
-                         (bash-completion--make
-                          :line "hel"
-                          :point 4
-                          :words '("hel")
-                          :cword 0
-                          :stub "hel"
-                          :unparsed-stub "hel"
-                          :wordbreaks "@><=;|&(:")
-                        (bash-completion-require-process))))))
+                      (bash-completion-comm
+                       (bash-completion--make
+                        :line "hel"
+                        :point 4
+                        :words '("hel")
+                        :cword 0
+                        :stub "hel"
+                        :unparsed-stub "hel"
+                        :wordbreaks "@><=;|&(:")
+                       (bash-completion-require-process)))))
    (bash-completion-reset)
    (should-not (bash-completion-is-running))))
 
diff --git a/test/bash-completion-test.el b/test/bash-completion-test.el
index 65e5617f88..afb202f193 100644
--- a/test/bash-completion-test.el
+++ b/test/bash-completion-test.el
@@ -667,33 +667,45 @@ Return (const return-value new-buffer-content)"
                       nil)))))
 
   ;; append a space for initial command that is not a directory
-  (should (let ((bash-completion-nospace nil))
-            (equal "somecmd "
-                   (bash-completion-fix
-                    "somecmd"
-                    (bash-completion--make
-                     :cword 0
-                     :stub "some"
-                     :unparsed-stub "some"
-                     :wordbreaks "")
-                    'single))))
+  (let ((bash-completion-nospace nil))
+    (should
+     (equal "somecmd "
+            (bash-completion-fix
+             "somecmd"
+             (bash-completion--make
+              :cword 0
+              :stub "some"
+              :unparsed-stub "some"
+              :wordbreaks "")
+             'single))))
+
+  ;; ... but not if nospace option is set for the function
+  (should (equal "somecmd"
+                 (bash-completion-fix
+                  "somecmd"
+                  (bash-completion--make
+                   :cword 0
+                   :stub "some"
+                   :unparsed-stub "some"
+                   :wordbreaks ""
+                   :compgen-args '("-o" "nospace"))
+                  nil)))
 
-  ;; ... but not if nospace option is set
-  (should (let ((bash-completion-nospace t))
-            (equal "somecmd"
+  ;; ... or globally
+  (let ((bash-completion-nospace t))
+    (should (equal "somecmd"
                    (bash-completion-fix
                     "somecmd"
                     (bash-completion--make
                      :cword 0
                      :stub "some"
                      :unparsed-stub "some"
-                     :wordbreaks ""
-                     :compgen-args '("-o" "nospace"))
+                     :wordbreaks "")
                     nil))))
 
   ;; append a space for a single completion
-  (should (let ((bash-completion-nospace nil))
-            (equal "somecmd "
+  (let ((bash-completion-nospace nil))
+    (should (equal "somecmd "
                    (bash-completion-fix
                     "somecmd"
                     (bash-completion--make
@@ -704,16 +716,17 @@ Return (const return-value new-buffer-content)"
                     'single))))
 
   ;; but only for a single completion
-  (should (let ((bash-completion-nospace nil))
-            (equal "somecmd"
-                   (bash-completion-fix
-                    "somecmd"
-                    (bash-completion--make
-                     :cword 0
-                     :stub "some"
-                     :unparsed-stub "some"
-                     :wordbreaks "")
-                    nil))))
+  (let ((bash-completion-nospace nil))
+    (should
+     (equal "somecmd"
+            (bash-completion-fix
+             "somecmd"
+             (bash-completion--make
+              :cword 0
+              :stub "some"
+              :unparsed-stub "some"
+              :wordbreaks "")
+             nil))))
 
   ;; subset of the prefix"
   (should (equal "Dexter"
@@ -850,7 +863,8 @@ before calling `bash-completion-dynamic-complete-nocomint'.
   `(let ((default-directory "/tmp/test")
          (bash-completion-alist '())
          (wordbreaks "@><=;|&(:")
-         (bash-completion-enable-caching nil))
+         (bash-completion-enable-caching nil)
+         (bash-completion-nospace nil))
      (lexical-let ((--process-buffer)
                    (--test-buffer)
                    (--send-results (list))
@@ -1120,28 +1134,21 @@ before calling 
`bash-completion-dynamic-complete-nocomint'.
               '("somedir/")
               (nth 2 (bash-completion-dynamic-complete-nocomint 3 
(point))))))))
 
-(ert-deftest bash-completion--extract-compgen-options-test ()
-  (should (equal '("filenames" "default")
-                 (bash-completion--extract-compgen-options
-                  '("-a" "-o" "default" "-F" "fun" "-o" "filenames"))))
-  (should (equal '()
-                 (bash-completion--extract-compgen-options
-                  '("-a" "-F" "fun"))))
-  (should (equal '()
-                 (bash-completion--extract-compgen-options
-                  '("-a" "-F" "fun" "-o")))))
-
-(ert-deftest bash-completion--parse-options ()
-  (let ((bash-completion-nospace 'as-configured))
-    (should (equal nil (bash-completion--parse-options nil)))
-    (should (equal '(nospace)
-                   (bash-completion--parse-options
-                    '("filenames" "nospace" "default"))))
-    (setq bash-completion-nospace nil)
-    (should (equal '() (bash-completion--parse-options
-                        '("nospace"))))
-    (setq bash-completion-nospace t)
-    (should (equal '(nospace)
-                   (bash-completion--parse-options '())))))
+(ert-deftest bash-completion--has-compgen-option ()
+  (should (equal nil
+                 (bash-completion--has-compgen-option
+                  '("-F" "boo" "-o" "filenames" "-a" "-o" "default")
+                  "nospace")))
+  (should (equal t
+                 (bash-completion--has-compgen-option
+                  '("-F" "boo" "-o" "filenames" "-a" "-o" "default")
+                  "filenames")))
+  (should (equal t
+                 (bash-completion--has-compgen-option
+                  '("-F" "boo" "-o" "filenames" "-a" "-o" "default")
+                  "default")))
+  (should (equal nil (bash-completion--has-compgen-option
+                      '("-o") "any")))
+  (should (equal nil (bash-completion--has-compgen-option '() "any"))))
 
 ;;; bash-completion_test.el ends here



reply via email to

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