(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."
`savehist-additional-variables' to include the
`multishell-primary-name'.")
-(defvar multishell-completing nil
+(defvar multishell-completing-read nil
"Internal use, conveying whether or not we're in the midst of a multishell
completing-read.")
(throw 'multishell-minibuffer-exit token)
(let ((got (catch 'multishell-minibuffer-exit
(multishell-pop-to-shell-worker arg name here))))
- (if (equal token got)
- (multishell-list)
- (multishell-pop-to-shell-worker nil got here))))))
+ ;; Handle catch or plain fall-through - see cond comments for protocol.
+ (cond
+ ;; Caught token from recursive invocation in minibuffer:
+ ((equal token got) (multishell-list))
+ ;; Caught specifaction of multishell args, eg from multishell-list:
+ ((listp got) (multishell-pop-to-shell-worker (nth 2 got)
+ (nth 0 got)
+ (nth 1 got)))
+ ;; Regular fallthrough - just relay the result:
+ (t got))))))
(defun multishell-pop-to-shell-worker (&optional arg name here)
"Do real work of `multishell-pop-to-shell', which see."
Return what's provided, if anything, else nil."
(let* ((was-multishell-history multishell-history)
(candidates (multishell-all-entries 'active-duplicated))
- (got (cl-letf
- ;; Engage our custom display-completion-list, for
- ;; minibuffer-completion-help. `cl-letf' for dynamic
- ;; binding; cl-flet's lexical doesn't do what's needed.
- (((symbol-function 'display-completion-list)
- #'multishell-list))
- (let ((multishell-completing t))
- (completing-read prompt
- ;; COLLECTION:
- (reverse candidates)
- ;; PREDICATE:
- nil
- ;; REQUIRE-MATCH:
- 'confirm
- ;; INITIAL-INPUT
- initial
- ;; HIST:
- 'multishell-history)))))
+ (multishell-completing-read t)
+ (got
+ ;; Use `cl-letf' to dynamically bind multishell-list to
+ ;; display-completion-list, so multishell-list is used when doing
+ ;; minibuffer-completion-help.
+ (cl-letf (((symbol-function 'display-completion-list)
+ #'multishell-list))
+ (completing-read prompt
+ ;; COLLECTION:
+ (reverse candidates)
+ ;; PREDICATE:
+ nil
+ ;; REQUIRE-MATCH:
+ 'confirm
+ ;; INITIAL-INPUT
+ initial
+ ;; HIST:
+ 'multishell-history))))
(when no-record
(setq multishell-history was-multishell-history))
(if (not (string= got ""))