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

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

[nongnu] elpa/bash-completion 583d1dde61 151/313: Remove usage of seq-po


From: ELPA Syncer
Subject: [nongnu] elpa/bash-completion 583d1dde61 151/313: Remove usage of seq-position with a custom implementation.
Date: Sat, 3 Dec 2022 10:59:25 -0500 (EST)

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

    Remove usage of seq-position with a custom implementation.
    
    seq.el isn't available in older emacs versions.
---
 bash-completion-test.el |  6 ++++++
 bash-completion.el      | 20 +++++++++++++-------
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/bash-completion-test.el b/bash-completion-test.el
old mode 100644
new mode 100755
index cde751e50b..1ef90ac66c
--- a/bash-completion-test.el
+++ b/bash-completion-test.el
@@ -361,6 +361,12 @@ garbage
                 (default-directory "/test"))
             (bash-completion-generate-line "zorg worl" 7 '("zorg" "worl") 1 
nil)))))
 
+(ert-deftest bash-completion--find-last-test ()
+  (should (equal nil (bash-completion--find-last ?a "xxxxx")))
+  (should (equal 3 (bash-completion--find-last ?d "abcdef")))
+  (should (equal 5 (bash-completion--find-last ?f "abcdef")))
+  (should (equal 9 (bash-completion--find-last ?d "abcdefabcdef"))))
+
 (ert-deftest bash-completion-generate-list-test ()
   ;; empty str
   (should (equal nil
diff --git a/bash-completion.el b/bash-completion.el
index ca15281907..da211ed8fb 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -373,22 +373,28 @@ This function is not meant to be called outside of
         (after-wordbreak (nth 1 wordbreak-split))
          (separator (nth 2 wordbreak-split))
          (unparsed-stub (buffer-substring-no-properties stub-start pos))
-         ;; separator-pos-in-unparsed finds the same separator that
-         ;; was used for the split in unparsed-stub.
-         (separator-pos-in-unparsed
-          (- (length unparsed-stub)
-             (or (seq-position (reverse unparsed-stub) separator) 0)))
+         (after-wordbreak-in-unparsed-pos
+          (1+ (or (bash-completion--find-last separator unparsed-stub) -1)))
          (unparsed-after-wordbreak
           (substring unparsed-stub
-                     separator-pos-in-unparsed
+                     after-wordbreak-in-unparsed-pos
                      (length unparsed-stub))))
     (when (> (length before-wordbreak) 0)
-      (list (+ stub-start separator-pos-in-unparsed)
+      (list (+ stub-start after-wordbreak-in-unparsed-pos)
             pos
             (bash-completion--default-completion
              after-wordbreak unparsed-after-wordbreak
              open-quote 'wordbreak)))))
 
+(defun bash-completion--find-last (elt array)
+  "Return the position of the last intance of ELT in array or nil."
+  (catch 'bash-completion-return
+    (let ((array-len (length array)))
+      (dotimes (index array-len)
+        (if (eq elt (aref array (- array-len index 1)))
+            (throw 'bash-completion-return (- array-len index 1)))))
+    nil))
+
 (defun bash-completion--default-completion
     (stub unparsed-stub open-quote completion-type)
   "Do default completion on the given STUB.



reply via email to

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