]> code.delx.au - gnu-emacs-elpa/blobdiff - multishell-list.el
multishell - 1.1.5, preserve listing recency, increment multishell-version
[gnu-emacs-elpa] / multishell-list.el
index d2765dd1ac4d79db45b83dd0230f300db2f93f19..dc7529b6ae237d6219e8425f2e6cb8dcc7faff98 100644 (file)
@@ -3,7 +3,7 @@
 ;; Copyright (C) 2016 Free Software Foundation, Inc. and Ken Manheimer
 
 ;; Author: Ken Manheimer <ken.manheimer@gmail.com>
-;; Version: 1.1.3
+;; Version: 1.1.5
 ;; Created: 2016 -- first public availability
 ;; Keywords: processes
 ;; URL: https://github.com/kenmanheimer/EmacsMultishell
@@ -247,6 +247,25 @@ Initial sort is from most to least recently used:
         tabulated-list-entries #'multishell-list-entries)
   (tabulated-list-init-header))
 
+(defun multishell-list-cull-dups (entries)
+  "Return list of multishell ENTRIES sans ones with duplicate names.
+
+For duplicates, we prefer the ones that have paths."
+  (let ((tally (make-hash-table :test #'equal))
+        got name name-order-reversed already)
+    (mapcar #'(lambda (entry)
+                (setq name (multishell-name-from-entry entry)
+                      already (gethash name tally nil))
+                (when (not already)
+                  (push name name-order-reversed))
+                (when (or (not already) (< (length already) (length entry)))
+                  ;; Add new or replace shorter prior entry for name:
+                  (puthash name entry tally)))
+            entries)
+    (dolist (name name-order-reversed)
+      (push (gethash name tally) got))
+    got))
+
 ;;;###autoload
 (defun multishell-list (&optional completing)
   "Edit your current and historic list of shell buffers.
@@ -278,13 +297,11 @@ You can get to the shells listing by recursively invoking
     (progv
         ;; Temporarily assign multishell-history only when completing:
         (when completing '(multishell-history))
-        (when completing (list (mapcar 'substring-no-properties completing)))
+        (when completing
+          (list (multishell-list-cull-dups (mapcar 'substring-no-properties
+                                                   completing))))
       (tabulated-list-print))
     (when completing
-      ;; XXX Do proper completion prep.
-      ;; - looks like stuff in minibuffer.el.gz is too hairy w/too little gain.
-      ;; - Add a buffer-change hook that throws a 'multishell-completion-done,
-      ;;   and revise the catch in multishell-pop-to-shell
       )
     (when from-entry
       (multishell-list-goto-item-by-entry from-entry))))