;; 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
(if arg
(pop-to-buffer
(multishell-bracket (multishell-name-from-entry entry)))
- (multishell-list-selected entry t))
+ (multishell-list-dispatch-selected entry t))
(with-current-buffer list-buffer
(revert-buffer)
(multishell-list-goto-item-by-entry entry))))
(let ((list-buffer (current-buffer))
(entry (tabulated-list-get-id)))
(message "%s <==" (multishell-name-from-entry entry))
- (multishell-list-selected entry t t)
+ (multishell-list-dispatch-selected entry t t)
(with-current-buffer list-buffer
(revert-buffer)
(multishell-list-goto-item-by-entry entry))))
(if arg
(switch-to-buffer
(multishell-bracket (multishell-name-from-entry entry)))
- (multishell-list-selected entry nil))
+ (multishell-list-dispatch-selected entry nil))
(with-current-buffer list-buffer
(revert-buffer))))
(with-current-buffer buffer
(rename-buffer (multishell-bracket revised-name)))))
(when arg
- (multishell-list-selected revised-name t))
+ (multishell-list-dispatch-selected revised-name t))
(with-current-buffer list-buffer
(revert-buffer)
(multishell-list-goto-item-by-entry revised))))
(revert-buffer)
(multishell-list-goto-item-by-entry new)
(when arg
- (multishell-list-selected new-name t)))))
+ (multishell-list-dispatch-selected new-name t)))))
(defun multishell-list-mouse-select (event)
"Select the shell whose line is clicked."
(interactive "e")
(select-window (posn-window (event-end event)))
(let ((entry (tabulated-list-get-id (posn-point (event-end event)))))
- (multishell-list-selected entry nil)))
+ (multishell-list-dispatch-selected entry nil)))
-(defun multishell-list-selected (entry pop &optional set-primary)
- "Select multishell ENTRY, popping to window if POP is non-nil.
+(defun multishell-list-dispatch-selected (entry pop &optional set-primary)
+ "Go to multishell ENTRY, popping to window if POP is non-nil.
Optional arg SET-PRIMARY non-nil sets `multishell-primary-name' to entry.
Provide for concluding minibuffer interaction if we're in completing mode."
- (if multishell-completing
- (throw 'multishell-minibuffer-exit entry)
- (multishell-pop-to-shell (and set-primary '(16)) entry (not pop))))
+ (let ((set-primary-as-arg (and set-primary '(16))))
+ (if multishell-completing-read
+ ;; In multishell completing-read, arrange to conclude minibuffer input:
+ (throw 'multishell-minibuffer-exit (list entry pop set-primary-as-arg))
+ (multishell-pop-to-shell set-primary-as-arg entry (not pop)))))
(defun multishell-list-placeholder (value default)
"Return VALUE if non-empty string, else DEFAULT."
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.
(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))))