From 7b6604880039245e326921b68b689e52e2b618d1 Mon Sep 17 00:00:00 2001 From: Ken Manheimer Date: Fri, 12 Feb 2016 03:01:01 -0500 Subject: [PATCH] multishell - Use better names for completing read and dispatch provisions. --- multishell-list.el | 24 ++++++++++++---------- multishell.el | 51 ++++++++++++++++++++++++++-------------------- 2 files changed, 42 insertions(+), 33 deletions(-) diff --git a/multishell-list.el b/multishell-list.el index 773b799fe..d2765dd1a 100644 --- a/multishell-list.el +++ b/multishell-list.el @@ -33,7 +33,7 @@ pop to the buffer but don't change its run state." (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)))) @@ -44,7 +44,7 @@ pop to the buffer but don't change its run state." (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)))) @@ -61,7 +61,7 @@ switch to the buffer but don't activate (or deactivate) it it." (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)))) @@ -105,7 +105,7 @@ starting it if it's not already going." (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)))) @@ -131,24 +131,26 @@ The already existing original entry is left untouched." (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." diff --git a/multishell.el b/multishell.el index 429d914b4..3043ad7d0 100644 --- a/multishell.el +++ b/multishell.el @@ -269,7 +269,7 @@ one emacs session to be resumed at the next, customize `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.") @@ -437,9 +437,16 @@ customize the savehist group to activate savehist." (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." @@ -623,24 +630,24 @@ Input and completion can include associated path, if any. 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 "")) -- 2.39.2