]> code.delx.au - gnu-emacs-elpa/blobdiff - multishell.el
multishell - 1.1.4, resolves several TODO items.
[gnu-emacs-elpa] / multishell.el
index 429d914b464abea3bd991d303d4ea84bef8efc95..8056669c0e78578240ed8adc8ef0e5796dc230e1 100644 (file)
 ;;
 ;; Change Log:
 ;;
-;; * 2016-02-10 1.1.4 Ken Manheimer:
+;; * 2016-02-11 1.1.4 Ken Manheimer:
 ;;   - hookup multishell-list as completion help buffer.
+;;     Mouse and keyboard selections from help listing properly exits
+;;     minibuffer.
 ;; * 2016-02-09 1.1.3 Ken Manheimer:
 ;;   multishell-list:
 ;;   - add some handy operations, like cloning new entry from existing
 ;;
 ;; TODO and Known Issues:
 ;;
-;; * Add mouse actions - buttons - to multishell-list entries
-;;   - see buf-menu.el, eg Buffer-menu-mouse-select
-;; * Resolve multishell-list sort glitches:
-;;   - Fix config so multishell-list-revert-buffer-kludge is not needed
-;;   - Make multishell-list-edit-entry in-place, so changed entries recency
-;;     doesn't change.
-;;   - Fill in kill-buffer prompting gaps, eg if default live-process
-;;     prompts are inhibited.
 ;; * Add custom shell launch prep actions
 ;;   - for, eg, port knocking, interface activations
 ;;   - shell commands to execute when shell name or path matches a regexp
 ;;   - list of (regexp, which - name, path, or both, command)
-;; * Adapt multishell-list facilities for all-completions
-;;   - See info on minibuffer-completion-help, display-completion-list
 ;; * Investigate whether we can recognize and provide for failed hops.
 ;;   - Tramp doesn't provide useful reactions for any hop but the first
 ;;   - Might be stuff we can do to detect and convey failures?
@@ -269,7 +261,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 +429,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 +622,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 ""))
@@ -699,7 +698,11 @@ and path nil if none is resolved."
 
       (when (and (derived-mode-p 'shell-mode) (file-remote-p path))
         ;; Returning to disconnected remote shell - do some tidying.
-        ;; Prevents an "Args out of range" failure when reconnecting.
+        ;; Without this cleanup, occasionally restarting a disconnected
+        ;; remote session, particularly one that includes sudo, results in
+        ;; an untraceable "Args out of range" error. That never happens if
+        ;; we precedeed connection attempts with this cleanup -
+        ;; prophylactic.
         (tramp-cleanup-connection
          (tramp-dissect-file-name default-directory 'noexpand)
          'keep-debug 'keep-password))