Parcourir la source

Add a safe version of ido-chop (currently unused)

Ryan C. Thompson il y a 7 ans
Parent
commit
20638efde5
1 fichiers modifiés avec 13 ajouts et 0 suppressions
  1. 13 0
      ido-completing-read+.el

+ 13 - 0
ido-completing-read+.el

@@ -880,6 +880,19 @@ result."
    for hare on (cdr x) by #'cddr
    thereis (eq tortoise hare)))
 
+(defun ido-cr+-maybe-chop (items elem)
+  "Like `ido-chop', but a no-op if ELEM is not in ITEMS.
+
+Normal `ido-chop' hangs infinitely in this case."
+  (cl-loop
+   with new-tail = ()
+   for remaining on items
+   for next = (car remaining)
+   if (equal next elem)
+   return (nconc remaining new-tail)
+   else collect next into new-tail
+   finally return items))
+
 (defun ido-cr+-update-dynamic-collection ()
   "Update the set of completions for a dynamic collection.