From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ken Manheimer Newsgroups: gmane.emacs.devel Subject: [ELPA] New package: multishell Date: Sat, 2 Jan 2016 17:19:02 -0500 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=94eb2c0948929fe5a905286147ee X-Trace: ger.gmane.org 1451773192 18863 80.91.229.3 (2 Jan 2016 22:19:52 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 2 Jan 2016 22:19:52 +0000 (UTC) To: "emacs-devel@gnu.org" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jan 02 23:19:48 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aFUWZ-0003dZ-NF for ged-emacs-devel@m.gmane.org; Sat, 02 Jan 2016 23:19:48 +0100 Original-Received: from localhost ([::1]:39904 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aFUWY-0003BL-Vw for ged-emacs-devel@m.gmane.org; Sat, 02 Jan 2016 17:19:47 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51813) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aFUWE-0003B2-MH for emacs-devel@gnu.org; Sat, 02 Jan 2016 17:19:30 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aFUWB-0005oa-2N for emacs-devel@gnu.org; Sat, 02 Jan 2016 17:19:26 -0500 Original-Received: from mail-oi0-x230.google.com ([2607:f8b0:4003:c06::230]:34404) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aFUWA-0005oW-Pn for emacs-devel@gnu.org; Sat, 02 Jan 2016 17:19:22 -0500 Original-Received: by mail-oi0-x230.google.com with SMTP id o124so238026602oia.1 for ; Sat, 02 Jan 2016 14:19:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=U7mhIeSzDDZObE3wAlRXxoSLlud8gKo9jH4s6gY0Iqo=; b=uvyCrWSF26nh3sXWptiYVwF2xKsQiyVDWB7qQr1hVJyB6L+X1DE+4640rPiXw6jTX0 NYniiXN3K0V7SpaSmvrKHAUY5HDLpZHVTAaP+DDw7g02IRhr5UWXjdsq6tb5+EGGBJSI vqZ1CClHniWz+VQlRN4sWGb1HROUKEA6eABiJtU+kMOintqXl6/u1VTx6Y8lZIvlF6rG soR11p5NPCe0SUv+fTgN7BA/5xOO/5aV3+r93zGPMP3VIE0xtpsdQv2ehtUNkvnug6Mq 6+cJV4j71F50UC+szz7+ACmQjVAlVwyVWuy46M96e5hXEjRQZi7cIjiAr/wC+rfdUXgz UsdA== X-Received: by 10.202.241.11 with SMTP id p11mr51635939oih.51.1451773162151; Sat, 02 Jan 2016 14:19:22 -0800 (PST) Original-Received: by 10.202.187.6 with HTTP; Sat, 2 Jan 2016 14:19:02 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4003:c06::230 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:197387 Archived-At: --94eb2c0948929fe5a905286147ee Content-Type: text/plain; charset=UTF-8 I'm about to push a multishell as a new packge in the git.sv.gnu.org:/srv/git/emacs/elpa.git. I've been using rudimentary versions of this package for a long time. I only recently discovered how well tramp is integrated to emacs shell, and feel that my multishell approach to navigating multiple shell buffers, in conjunction with remote shells, is extremely useful, hence this release. While I have a few packages included with emacs, I haven't released anything via ELPA before, and welcome corrections and suggestions. One coding wrinkle worth mentioning - I prefixed most of my package's functions with "multishell:" for pseudo-namespace partitioning, but did not prefix the primary function, "pop-to-shell". I see that as the package's exported api. I do not feel strongly bound to this choice, and can be persuaded to also prefix it if someone feels there is good reason to do so. Since my package is a single file, I'm including the commentary and etc. by including the whole thing. Ken Manheimer ;;; multishell.el --- manage interaction with multiple local and remote shells ;; Copyright (C) 1999-2016 Free Software Foundation, Inc. and Ken Manheimer ;; Author: Ken Manheimer ;; Version: 1.0.0 ;; Maintainer: Ken Manheimer ;; Created: 1999 -- first public availability ;; Keywords: processes ;; URL: https://github.com/kenmanheimer/EmacsUtils ;; ;;; Commentary: ;; ;; Easily use and manage multiple shell buffers, including remote shells. ;; Fundamentally, multishell is the function `multishell:pop-to-shell - like ;; pop-to-buffer - plus a keybinding. Together, they enable you to: ;; ;; * Get to the input point from wherever you are in a shell buffer, ;; * ... or to a shell buffer if you're not currently in one. ;; * Use universal arguments to launch and choose among alternate shell buffers, ;; * ... and select which is default. ;; * Prepend a path to a new shell name to launch a shell in that directory, ;; * ... and use a path with Emacs tramp syntax to launch a remote shell. ;; ;; Customize-group `multishell` to select and activate a keybinding and set ;; various behaviors. ;; ;; See the pop-to-shell docstring for details. ;; ;;; Change Log: ;; ;; 2016-01-02 Ken Manheimer - initial release ;; ;;; TODO: ;; ;; * Preserveable (savehist) history that associates names with paths ;; - Using an association list between names and paths ;; - Searched for search backwards/forwards on isearch-like M-r/M-s bindings ;; - *Not* searched for regular completion ;; - Editible ;; - Using isearch keybinding M-e ;; - Edits path ;; - New association overrides previous ;; - Deleting path removes association and history entry ;; * Customize activation of savehist ;; - Customize entry has warning about activating savehist ;; - Adds the name/path association list to savehist-additional-variables ;; - Activates savehist, if inactive ;;; Code: (defvar non-interactive-process-buffers '("*compilation*" "*grep*")) (require 'comint) (require 'shell) (defgroup multishell nil "Allout extension that highlights outline structure graphically. Customize `allout-widgets-auto-activation' to activate allout-widgets with allout-mode." :group 'shell) (defcustom multishell:non-interactive-process-buffers '("*compilation*" "*grep*") "Names of buffers that have processes but are not for interaction. Add names of buffers that you don't want pop-to-shell to stick around in." :type '(repeat string) :group 'multishell) (defcustom multishell:command-key "\M- " "The key to use if `multishell:activate-command-key' is true. You can instead bind `pop-to-shell` to your preferred key using emacs lisp, eg: (global-set-key \"\\M- \" 'pop-to-shell)." :type 'key-sequence :group 'multishell) (defvar multishell:responsible-for-command-key nil "Multishell internal.") (defun multishell:activate-command-key-setter (symbol setting) "Implement `multishell:activate-command-key' choice." (set-default 'multishell:activate-command-key setting) (when (or setting multishell:responsible-for-command-key) (multishell:implement-command-key-choice (not setting)))) (defun multishell:implement-command-key-choice (&optional unbind) "If settings dicate, implement binding of multishell command key. If optional UNBIND is true, globally unbind the key. * `multishell:activate-command-key' - Set this to get the binding or not. * `multishell:command-key' - The key to use for the binding, if appropriate." (cond (unbind (when (and (boundp 'multishell:command-key) multishell:command-key) (global-unset-key multishell:command-key))) ((not (and (boundp 'multishell:activate-command-key) (boundp 'multishell:command-key))) nil) ((and multishell:activate-command-key multishell:command-key) (setq multishell:responsible-for-command-key t) (global-set-key multishell:command-key 'pop-to-shell)))) (defcustom multishell:activate-command-key nil "Set this to impose the `multishell:command-key' binding. You can instead bind `pop-to-shell` to your preferred key using emacs lisp, eg: (global-set-key \"\\M- \" 'pop-to-shell)." :type 'boolean :set 'multishell:activate-command-key-setter :group 'multishell) ;; Assert the customizations whenever the package is loaded: (with-eval-after-load "multishell" (multishell:implement-command-key-choice)) (defcustom multishell:pop-to-frame nil "*If non-nil, jump to a frame already showing the shell, if another is. Otherwise, open a new window in the current frame. \(Adjust `pop-up-windows' to change other-buffer vs current-buffer behavior.)" :type 'boolean :group 'multishell) ;; (defcustom multishell:persist-shell-names nil ;; "Remember shell name/path associations across sessions. Note well: ;; This will activate minibuffer history persistence, in general, if it's not ;; already active." ;; :type 'boolean ;; :group 'shell) (defvar multishell:name-path-assoc nil "Assoc list from name to path") (defvar multishell:primary-name "*shell*" "Shell name to use for un-modified pop-to-shell buffer target.") (defvar multishell:buffer-name-history nil "Distinct pop-to-shell completion history container.") (defun pop-to-shell (&optional arg) "Easily navigate to and within multiple shell buffers, local and remote. Use universal arguments to launch and choose between alternate shell buffers and to select which is default. Prepend a path to a new shell name to launch a shell in that directory, and use Emacs tramp syntax to launch a remote shell. Customize-group `multishell' to set up a key binding and tweak behaviors. ==== Basic operation: - If the current buffer is associated with a subprocess (that is not among those named on `non-interactive-process-buffers'), then focus is moved to the process input point. \(You can use a universal argument go to a different shell buffer when already in a buffer that has a process - see below.) - If not in a shell buffer (or with universal argument), go to a window that is already showing the (a) shell buffer, if any. In this case, the cursor is left in its prior position in the shell buffer. Repeating the command will then go to the process input point, per the first item in this list. We respect `pop-up-windows', so you can adjust it to set the other-buffer/same-buffer behavior. - Otherwise, start a new shell buffer, using the current directory as the working directory. If a buffer with the resulting name exists and its shell process was disconnected or otherwise stopped, it's resumed. ===== Universal arg to start and select between named shell buffers: You can name alternate shell buffers to create or return to using single or doubled universal arguments: - With a single universal argument, prompt for the buffer name to use (without the asterisks that shell mode will put around the name), defaulting to 'shell'. Completion is available. This combination makes it easy to start and switch between multiple shell buffers. - A double universal argument will prompt for the name *and* set the default to that name, so the target shell becomes the primary. ===== Select starting directory and remote host: The shell buffer name you give to the prompt for a universal arg can include a preceding path. That will be used for the startup directory. You can use tramp remote syntax to specify a remote shell. If there is an element after a final '/', that's used for the buffer name. Otherwise, the host, domain, or path is used. For example: * Use '/ssh:example.net:/' for a shell buffer on example.net named \"example.net\". * '/ssh:example.net|sudo:root@example.net:/\#ex' for a root shell on example.net named \"#ex\"." ;; I'm leaving the following out of the docstring for now because just ;; saving the buffer names, and not the paths, yields sometimes unwanted ;; behavior. ;; ===== Persisting your alternate shell buffer names and paths: ;; You can use emacs builtin SaveHist to preserve your alternate ;; shell buffer names and paths across emacs sessions. To do so, ;; customize the `savehist' group, and: ;; 1. Add `multishell:pop-to-shell-buffer-name-history' to Savehist Additional ;; Variables. ;; 2. Activate Savehist Mode, if not already activated. ;; 3. Save. (interactive "P") (let* ((from-buffer (current-buffer)) (from-buffer-is-shell (eq major-mode 'shell-mode)) (doublearg (equal arg '(16))) (temp (if arg (multishell:read-bare-shell-buffer-name (format "Shell buffer name [%s]%s " (substring-no-properties multishell:primary-name 1 (- (length multishell:primary-name) 1)) (if doublearg " <==" ":")) multishell:primary-name) multishell:primary-name)) use-default-dir (target-shell-buffer-name ;; Derive target name, and default-dir if any, from temp. (cond ((string= temp "") multishell:primary-name) ((string-match "^\\*\\(/.*/\\)\\(.*\\)\\*" temp) (setq use-default-dir (match-string 1 temp)) (multishell:bracket-asterisks (if (string= (match-string 2 temp) "") (let ((v (tramp-dissect-file-name use-default-dir))) (or (tramp-file-name-host v) (tramp-file-name-domain v) (tramp-file-name-localname v) use-default-dir)) (match-string 2 temp)))) (t (multishell:bracket-asterisks temp)))) (curr-buff-proc (get-buffer-process from-buffer)) (target-buffer (if (and (or curr-buff-proc from-buffer-is-shell) (not (member (buffer-name from-buffer) non-interactive-process-buffers))) from-buffer (get-buffer target-shell-buffer-name))) inwin already-there) (when doublearg (setq multishell:primary-name target-shell-buffer-name)) ;; Situate: (cond ((and (or curr-buff-proc from-buffer-is-shell) (not arg) (eq from-buffer target-buffer) (not (eq target-shell-buffer-name (buffer-name from-buffer)))) ;; In a shell buffer, but not named - stay in buffer, but go to end. (setq already-there t)) ((string= (buffer-name) target-shell-buffer-name) ;; Already in the specified shell buffer: (setq already-there t)) ((or (not target-buffer) (not (setq inwin (multishell:get-visible-window-for-buffer target-buffer)))) ;; No preexisting shell buffer, or not in a visible window: (pop-to-buffer target-shell-buffer-name pop-up-windows)) ;; Buffer exists and already has a window - jump to it: (t (if (and multishell:pop-to-frame inwin (not (equal (window-frame (selected-window)) (window-frame inwin)))) (select-frame-set-input-focus (window-frame inwin))) (if (not (string= (buffer-name (current-buffer)) target-shell-buffer-name)) (pop-to-buffer target-shell-buffer-name t)))) ;; We're in the buffer. ;; If we have a use-default-dir, impose it: (when use-default-dir (cd use-default-dir)) ;; Activate: (if (not (comint-check-proc (current-buffer))) (multishell:start-shell-in-buffer (buffer-name (current-buffer)))) ;; If the destination buffer has a stopped process, resume it: (let ((process (get-buffer-process (current-buffer)))) (if (and process (equal 'stop (process-status process))) (continue-process process))) (when (or already-there (equal (current-buffer) from-buffer)) (goto-char (point-max)) (and (get-buffer-process from-buffer) (goto-char (process-mark (get-buffer-process from-buffer))))))) (defun multishell:get-visible-window-for-buffer (buffer) "Return visible window containing buffer." (catch 'got-a-vis (walk-windows (function (lambda (win) (if (and (eq (window-buffer win) buffer) (equal (frame-parameter (selected-frame) 'display) (frame-parameter (window-frame win) 'display))) (throw 'got-a-vis win)))) nil 'visible) nil)) (defun multishell:read-bare-shell-buffer-name (prompt default) "PROMPT for shell buffer name, sans asterisks. Return the supplied name bracketed with the asterisks, or specified DEFAULT on empty input." (let* ((candidates (append (remq nil (mapcar (lambda (buffer) (let ((name (buffer-name buffer))) (if (with-current-buffer buffer (eq major-mode 'shell-mode)) ;; Shell mode buffers. (if (> (length name) 2) ;; Strip asterisks. (substring name 1 (1- (length name))) name)))) (buffer-list))))) (got (completing-read prompt candidates ; COLLECTION nil ; PREDICATE 'confirm ; REQUIRE-MATCH nil ; INITIAL-INPUT 'multishell:buffer-name-history ; HIST ))) (if (not (string= got "")) (multishell:bracket-asterisks got) default))) (defun multishell:bracket-asterisks (name) "Return a copy of name, ensuring it has an asterisk at the beginning and end." (if (not (string= (substring name 0 1) "*")) (setq name (concat "*" name))) (if (not (string= (substring name -1) "*")) (setq name (concat name "*"))) name) (defun multishell:unbracket-asterisks (name) "Return a copy of name, removing asterisks, if any, at beginning and end." (if (string= (substring name 0 1) "*") (setq name (substring name 1))) (if (string= (substring name -1) "*") (setq name (substring name 0 -1))) name) (defun multishell:start-shell-in-buffer (buffer-name) "Ensure a shell is started, using whatever name we're passed." ;; We work around shell-mode's bracketing of the buffer name, and do ;; some tramp-mode hygiene for remote connections. (require 'comint) (require 'shell) (let* ((buffer buffer-name) (prog (or explicit-shell-file-name (getenv "ESHELL") (getenv "SHELL") "/bin/sh")) (name (file-name-nondirectory prog)) (startfile (concat "~/.emacs_" name)) (xargs-name (intern-soft (concat "explicit-" name "-args")))) (set-buffer buffer-name) (when (and (file-remote-p default-directory) (eq major-mode 'shell-mode) (not (comint-check-proc (current-buffer)))) ;; We're returning to an already established but disconnected remote ;; shell, tidy it: (tramp-cleanup-connection (tramp-dissect-file-name default-directory 'noexpand) 'keep-debug 'keep-password)) (setq buffer (set-buffer (apply 'make-comint (multishell:unbracket-asterisks buffer-name) prog (if (file-exists-p startfile) startfile) (if (and xargs-name (boundp xargs-name)) (symbol-value xargs-name) '("-i"))))) (shell-mode))) (provide 'multishell) ;;; multishell.el ends here --94eb2c0948929fe5a905286147ee Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I'm about to push a multishell as a new packge in the= =C2=A0git.sv.gnu.org:/srv/git/emacs/elpa.git. I've been using rudimenta= ry versions of this package for a long time. I only recently discovered how= well tramp is integrated to emacs shell, and feel that my multishell appro= ach to navigating multiple shell buffers, in conjunction with remote shells= , is extremely useful, hence this release.

While I have = a few packages included with emacs, I haven't released anything via ELP= A before, and welcome corrections and suggestions.

One coding wrinkle worth mentioning - I prefixed most of my package's = functions with "multishell:" for pseudo-namespace partitioning, b= ut did not prefix the primary function, "pop-to-shell". I see tha= t as the package's exported api. I do not feel strongly bound to this c= hoice, and can be persuaded to also prefix it if someone feels there is goo= d reason to do so.

Since my package is a single fi= le, I'm including the commentary and etc. by including the whole thing.=

Ken Manheimer

;;; m= ultishell.el --- manage interaction with multiple local and remote shells

;; Copyright (C) 1999-2016 Free Software Foundation= , Inc. and Ken Manheimer

;; Author: Ken Manheimer = <ken dot manheimer at gmail...>
;; Version: 1.0.0
;; Maintainer: Ken Manheimer <ken dot manheimer at gmail...>
;; Created: 1999 -- first public availability
;; Keywords: pro= cesses
;;
= ;;; Commentary:
;;
;; Easily use and manage multiple sh= ell buffers, including remote shells.
;; Fundamentally, multishel= l is the function `multishell:pop-to-shell - like
;; pop-to-buffe= r - plus a keybinding. Together, they enable you to:
;;
;; * Get to the input point from wherever you are in a shell buffer,=
;; * ... or to a shell buffer if you're not currently in one.
;; * Use universal arguments to launch and choose among alternate she= ll buffers,
;; * ... and select which is default.
;; * = Prepend a path to a new shell name to launch a shell in that directory,
;; * ... and use a path with Emacs tramp syntax to launch a remote s= hell.
;;
;; Customize-group `multishell` to select and = activate a keybinding and set
;; various behaviors.
;;<= /div>
;; See the pop-to-shell docstring for details.
;;
=
;;; Change Log:
;;
;; 2016-01-02 Ken Manheimer - i= nitial release
;;
;;; TODO:
;;
;; *= Preserveable (savehist) history that associates names with paths
;; =C2=A0 - Using an association list between names and paths
;;= =C2=A0 - Searched for search backwards/forwards on isearch-like M-r/M-s bi= ndings
;; =C2=A0 =C2=A0 - *Not* searched for regular completion
;; =C2=A0 - Editible
;; =C2=A0 =C2=A0 - Using isearch ke= ybinding M-e
;; =C2=A0 =C2=A0 - Edits path
;; =C2=A0 = =C2=A0 - New association overrides previous
;; =C2=A0 =C2=A0 - De= leting path removes association and history entry
;; * Customize = activation of savehist
;; =C2=A0 - Customize entry has warning ab= out activating savehist
;; =C2=A0 - Adds the name/path associatio= n list to savehist-additional-variables
;; =C2=A0 - Activates sav= ehist, if inactive

;;; Code:

<= div>(defvar non-interactive-process-buffers '("*compilation*"= "*grep*"))

(require 'comint)
<= div>(require 'shell)

(defgroup multishell nil<= /div>
=C2=A0 "Allout extension that highlights outline structure g= raphically.

Customize `allout-widgets-auto-activat= ion' to activate allout-widgets
with allout-mode."
=
=C2=A0 :group 'shell)

(defcustom multishe= ll:non-interactive-process-buffers
=C2=A0 '("*compilatio= n*" "*grep*")
=C2=A0 "Names of buffers that h= ave processes but are not for interaction.
Add names of buffers t= hat you don't want pop-to-shell to stick around in."
=C2= =A0 :type '(repeat string)
=C2=A0 :group 'multishell)
(defcustom multishell:command-key "\M- "
=C2=A0 = "The key to use if `multishell:activate-command-key' is true.

You can instead bind `pop-to-shell` to your preferred = key using emacs
lisp, eg: (global-set-key \"\\M- \" = 9;pop-to-shell)."
=C2=A0 :type 'key-sequence
= =C2=A0 :group 'multishell)

(defvar multishell:= responsible-for-command-key nil
=C2=A0 "Multishell internal.= ")
(defun multishell:activate-command-key-setter (symbol set= ting)
=C2=A0 "Implement `multishell:activate-command-key'= ; choice."
=C2=A0 (set-default 'multishell:activate-comm= and-key setting)
=C2=A0 (when (or setting multishell:responsible-= for-command-key)
=C2=A0 =C2=A0 (multishell:implement-command-key-= choice (not setting))))
(defun multishell:implement-command-key-c= hoice (&optional unbind)
=C2=A0 "If settings dicate, imp= lement binding of multishell command key.

If optio= nal UNBIND is true, globally unbind the key.

* `mu= ltishell:activate-command-key' - Set this to get the binding or not.
* `multishell:command-key' - The key to use for the binding, if= appropriate."
=C2=A0 (cond (unbind
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0(when (and (boundp 'multishell:command-key) multish= ell:command-key)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(global= -unset-key multishell:command-key)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = ((not (and (boundp 'multishell:activate-command-key)
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(boundp '= multishell:command-key)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0nil)<= /div>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ((and multishell:activate-command-key= multishell:command-key)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(setq = multishell:responsible-for-command-key t)
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0(global-set-key multishell:command-key 'pop-to-shell))))

(defcustom multishell:activate-command-key nil
=C2=A0 "Set this to impose the `multishell:command-key' bind= ing.

You can instead bind `pop-to-shell` to your p= referred key using emacs
lisp, eg: (global-set-key \"\\M- \&= quot; 'pop-to-shell)."
=C2=A0 :type 'boolean
=C2=A0 :set 'multishell:activate-command-key-setter
=C2=A0= :group 'multishell)

;; Assert the customizati= ons whenever the package is loaded:
(with-eval-after-load "m= ultishell"
=C2=A0 (multishell:implement-command-key-choice))=

(defcustom multishell:pop-to-frame nil
= =C2=A0 "*If non-nil, jump to a frame already showing the shell, if ano= ther is.

Otherwise, open a new window in the curre= nt frame.

\(Adjust `pop-up-windows' to change = other-buffer vs current-buffer behavior.)"
=C2=A0 :type '= ;boolean
=C2=A0 :group 'multishell)

= ;; (defcustom multishell:persist-shell-names nil
;; =C2=A0 "= Remember shell name/path associations across sessions. Note well:
;; This will activate minibuffer history persistence, in general, if it= 9;s not
;; already active."
;; =C2=A0 :type 'b= oolean
;; =C2=A0:group 'shell)

(defv= ar multishell:name-path-assoc nil
=C2=A0 "Assoc list from na= me to path")

(defvar multishell:primary-name = "*shell*"
=C2=A0 "Shell name to use for un-modifie= d pop-to-shell buffer target.")
(defvar multishell:buffer-na= me-history nil
=C2=A0 "Distinct pop-to-shell completion hist= ory container.")

(defun pop-to-shell (&op= tional arg)
=C2=A0 "Easily navigate to and within multiple s= hell buffers, local and remote.

Use universal argu= ments to launch and choose between alternate
shell buffers and to= select which is default.=C2=A0 Prepend a path to
a new shell nam= e to launch a shell in that directory, and use
Emacs tramp syntax= to launch a remote shell.

Customize-group `multis= hell' to set up a key binding and tweak behaviors.

=
=3D=3D=3D=3D Basic operation:

=C2=A0- If the = current buffer is associated with a subprocess (that is
=C2=A0 = =C2=A0not among those named on `non-interactive-process-buffers'),
=C2=A0 =C2=A0then focus is moved to the process input point.

=C2=A0 =C2=A0\(You can use a universal argument go to a di= fferent shell
=C2=A0 =C2=A0buffer when already in a buffer that h= as a process - see
=C2=A0 =C2=A0below.)

= =C2=A0- If not in a shell buffer (or with universal argument), go to a
=C2=A0 =C2=A0window that is already showing the (a) shell buffer, if = any.

=C2=A0 =C2=A0In this case, the cursor is left= in its prior position in the
=C2=A0 =C2=A0shell buffer. Repeatin= g the command will then go to the
=C2=A0 =C2=A0process input poin= t, per the first item in this list.

=C2=A0 =C2=A0W= e respect `pop-up-windows', so you can adjust it to set the
= =C2=A0 =C2=A0other-buffer/same-buffer behavior.

= =C2=A0- Otherwise, start a new shell buffer, using the current
= =C2=A0 =C2=A0directory as the working directory.

I= f a buffer with the resulting name exists and its shell process
w= as disconnected or otherwise stopped, it's resumed.

=3D=3D=3D=3D=3D Universal arg to start and select between named shell= buffers:

You can name alternate shell buffers to = create or return to using
single or doubled universal arguments:<= /div>

=C2=A0- With a single universal argument, prompt f= or the buffer name
=C2=A0 =C2=A0to use (without the asterisks tha= t shell mode will put around
=C2=A0 =C2=A0the name), defaulting t= o 'shell'.

=C2=A0 =C2=A0Completion is avai= lable.

=C2=A0 =C2=A0This combination makes it easy= to start and switch between
=C2=A0 =C2=A0multiple shell buffers.=

=C2=A0- A double universal argument will prompt f= or the name *and* set
=C2=A0 =C2=A0the default to that name, so t= he target shell becomes the
=C2=A0 =C2=A0primary.

<= /div>
=3D=3D=3D=3D=3D Select starting directory and remote host:
<= div>
The shell buffer name you give to the prompt for a unive= rsal arg
can include a preceding path. That will be used for the = startup
directory. You can use tramp remote syntax to specify a r= emote
shell. If there is an element after a final '/', th= at's used for
the buffer name. Otherwise, the host, domain, o= r path is used.

For example:

<= div>* Use '/ssh:example.net:/' for a shell buffer on example.net named
=C2=A0 \"example.net\".
* '/ssh:example.net|sudo:root@example.net:/\#ex' for a= root shell on=C2=A0
=C2=A0 exampl= e.net named \"#ex\"."

;; I'= m leaving the following out of the docstring for now because just
;; saving the buffer names, and not the paths, yields sometimes unwanted
;; behavior.

;; =3D=3D=3D=3D=3D Persistin= g your alternate shell buffer names and paths:

;; = You can use emacs builtin SaveHist to preserve your alternate
;; = shell buffer names and paths across emacs sessions. To do so,
;; = customize the `savehist' group, and:

;; 1. Add= `multishell:pop-to-shell-buffer-name-history' to Savehist Additional
;; =C2=A0 =C2=A0Variables.
;; 2. Activate Savehist Mode,= if not already activated.
;; 3. Save.

= =C2=A0 (interactive "P")

=C2=A0 (let* ((= from-buffer (current-buffer))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(= from-buffer-is-shell (eq major-mode 'shell-mode))
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0(doublearg (equal arg '(16)))
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0(temp (if arg
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(multishell:read-bare-shell-bu= ffer-name
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 (format "Shell buffer name [%s]%s "
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 (substring-no-properties
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0multishell:primary-name
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A01 (- (length multishell:primary-name) 1))
=C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 (if doublearg " <=3D=3D" ":"))
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 multishell:p= rimary-name)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0multishell:primary-name))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0use-default-dir
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(target-s= hell-buffer-name
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ;; Derive tar= get name, and default-dir if any, from temp.
=C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 (cond ((string=3D temp "") multishell:primary-name= )
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ((strin= g-match "^\\*\\(/.*/\\)\\(.*\\)\\*" temp)
=C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(setq use-default-dir (mat= ch-string 1 temp))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0(multishell:bracket-asterisks=C2=A0
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (if (string=3D (match-= string 2 temp) "")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (let ((v (tramp-dissect-file-name=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 use-default-dir)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 (or (tramp-file-name-host v)
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 (tramp-file-name-domain v)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (tramp-file= -name-localname v)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 use-default-dir))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= (match-string 2 temp))))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 (t (multishell:bracket-asterisks temp))))
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(curr-buff-proc (get-buffer-process from-buf= fer))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(target-buffer (if (and (= or curr-buff-proc from-buffer-is-shell)
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0(not (member (buffer-name from-buffer)
=C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 non-interactive-process-buffers)))
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 from-buffer
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (get-buffer target-shell-buffer-n= ame)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0inwin
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0already-there)

=C2=A0 = =C2=A0 (when doublearg
=C2=A0 =C2=A0 =C2=A0 (setq multishell:prim= ary-name target-shell-buffer-name))

=C2=A0 =C2=A0 = ;; Situate:

=C2=A0 =C2=A0 (cond=C2=A0
=C2=A0 =C2=A0 =C2=A0((and (or curr-buff-proc from-buffer-is-sh= ell)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(not arg)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(eq from-buffer target-buffer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(not (eq target-shell-buff= er-name (buffer-name from-buffer))))
=C2=A0 =C2=A0 =C2=A0 ;; In a= shell buffer, but not named - stay in buffer, but go to end.
=C2= =A0 =C2=A0 =C2=A0 (setq already-there t))

=C2=A0 = =C2=A0 =C2=A0((string=3D (buffer-name) target-shell-buffer-name)
= =C2=A0 =C2=A0 =C2=A0 ;; Already in the specified shell buffer:
= =C2=A0 =C2=A0 =C2=A0 (setq already-there t))

=C2= =A0 =C2=A0 =C2=A0((or (not target-buffer)
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 (not (setq inwin
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(multishell:get-visible-window-fo= r-buffer target-buffer))))
=C2=A0 =C2=A0 =C2=A0 ;; No preexisting= shell buffer, or not in a visible window:
=C2=A0 =C2=A0 =C2=A0 (= pop-to-buffer target-shell-buffer-name pop-up-windows))

=C2=A0 =C2=A0 =C2=A0 =C2=A0;; Buffer exists and already has a window = - jump to it:
=C2=A0 =C2=A0 =C2=A0(t (if (and multishell:pop-to-f= rame
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0inwin
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0(not (equal (window-frame (selected-window))
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0(window-frame inwin))))
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 (select-frame-set-input-focus (window-frame inwin)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (if (not (string=3D (buffer-name (current= -buffer))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 target-shell-buffer-name))
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (pop-to-buffer target-shell-buffe= r-name t))))

=C2=A0 =C2=A0 ;; We're in the buf= fer.

=C2=A0 =C2=A0 ;; If we have a use-default-dir= , impose it:
=C2=A0 =C2=A0 (when use-default-dir
=C2=A0= =C2=A0 =C2=A0 =C2=A0 (cd use-default-dir))

=C2=A0= =C2=A0 ;; Activate:

=C2=A0 =C2=A0 (if (not (comin= t-check-proc (current-buffer)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (mult= ishell:start-shell-in-buffer (buffer-name (current-buffer))))
=C2=A0 =C2=A0 ;; If the destination buffer has a stopped proces= s, resume it:
=C2=A0 =C2=A0 (let ((process (get-buffer-process (c= urrent-buffer))))
=C2=A0 =C2=A0 =C2=A0 (if (and process (equal &#= 39;stop (process-status process)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 (continue-process process)))
=C2=A0 =C2=A0 (when (or alrea= dy-there
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(equal (= current-buffer) from-buffer))
=C2=A0 =C2=A0 =C2=A0 (goto-char (po= int-max))
=C2=A0 =C2=A0 =C2=A0 (and (get-buffer-process from-buff= er)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(goto-char (process-= mark (get-buffer-process from-buffer)))))))

(defun= multishell:get-visible-window-for-buffer (buffer)
=C2=A0 "R= eturn visible window containing buffer."
=C2=A0 (catch '= got-a-vis
=C2=A0 =C2=A0 (walk-windows
=C2=A0 =C2=A0 =C2= =A0(function (lambda (win)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0(if (and (eq (window-buffer win) buffer)
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 (equal (frame-parameter
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 (selected-frame) 'display)
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(frame-parameter
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (window-frame win) 'display)))
=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0(throw 'got-a-vis win))))
=C2=A0 =C2=A0 =C2=A0nil '= visible)
=C2=A0 =C2=A0 nil))

(defun mult= ishell:read-bare-shell-buffer-name (prompt default)
=C2=A0 "= PROMPT for shell buffer name, sans asterisks.

Retu= rn the supplied name bracketed with the asterisks, or specified DEFAULT
on empty input."
=C2=A0 (let* ((candidates (append
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 (remq nil
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (mapcar (lambda (bu= ffer)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (= let ((name (buffer-name buffer)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (if (with-current-buffer buffer
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 (eq major-mode 'shell-mode))
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ;; Shell mod= e buffers.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 (if (> (length name) 2)
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 ;; Strip asterisks.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (substring name= 1
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(1= - (length name)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 name))))
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (buffer-list)))))
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0(got (completing-read prompt
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0candidates ; COLLECTION
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0nil =C2=A0 =C2=A0 =C2=A0 =C2=A0; PREDICATE
=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0'confirm =C2=A0 ; REQUIRE-MATC= H
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0nil =C2=A0 =C2=A0 =C2=A0 = =C2=A0; INITIAL-INPUT
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0'm= ultishell:buffer-name-history ; HIST
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0)))
=C2=A0 =C2=A0 (if (not (string=3D got "")= ) (multishell:bracket-asterisks got) default)))

(d= efun multishell:bracket-asterisks (name)
=C2=A0 "Return a co= py of name, ensuring it has an asterisk at the beginning and end."
=C2=A0 (if (not (string=3D (substring name 0 1) "*"))
=C2=A0 =C2=A0 =C2=A0 (setq name (concat "*" name)))
=C2=A0 (if (not (string=3D (substring name -1) "*"))
=C2=A0 =C2=A0 =C2=A0 (setq name (concat name "*")))
= =C2=A0 name)
(defun multishell:unbracket-asterisks (name)
=C2=A0 "Return a copy of name, removing asterisks, if any, at begin= ning and end."
=C2=A0 (if (string=3D (substring name 0 1) &q= uot;*")
=C2=A0 =C2=A0 =C2=A0 (setq name (substring name 1)))=
=C2=A0 (if (string=3D (substring name -1) "*")
=C2=A0 =C2=A0 =C2=A0 (setq name (substring name 0 -1)))
=C2=A0= name)
(defun multishell:start-shell-in-buffer (buffer-name)
=C2=A0 "Ensure a shell is started, using whatever name we're= passed."
=C2=A0 ;; We work around shell-mode's bracketi= ng of the buffer name, and do
=C2=A0 ;; some tramp-mode hygiene f= or remote connections.

=C2=A0 (require 'comint= )
=C2=A0 (require 'shell)

=C2=A0 (le= t* ((buffer buffer-name)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(prog = (or explicit-shell-file-name
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(getenv "ESHELL")
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(getenv &= quot;SHELL")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0"/bin/sh"))
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0(name (file-name-nondirectory prog))
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0(startfile (concat "~/.emacs_" name))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(xargs-name (intern-soft (concat &= quot;explicit-" name "-args"))))
=C2=A0 =C2=A0 (se= t-buffer buffer-name)
=C2=A0 =C2=A0 (when (and (file-remote-p def= ault-directory)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0(eq major-mode 'shell-mode)
=C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0(not (comint-check-proc (current-buffer))))
=C2=A0 =C2=A0 =C2=A0 ;; We're returning to an already establishe= d but disconnected remote
=C2=A0 =C2=A0 =C2=A0 ;; shell, tidy it:=
=C2=A0 =C2=A0 =C2=A0 (tramp-cleanup-connection
=C2=A0 = =C2=A0 =C2=A0 =C2=A0(tramp-dissect-file-name default-directory 'noexpan= d)
=C2=A0 =C2=A0 =C2=A0 =C2=A0'keep-debug 'keep-password)= )
=C2=A0 =C2=A0 (setq buffer (set-buffer (apply 'make-comint<= /div>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (multishell:= unbracket-asterisks buffer-name)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 prog
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 (if (file-exists-p startfile)
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 startfile)
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (if (and xargs-name
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0(boundp xargs-name))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (symbol-value xargs-name)
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 '("-i"= ;)))))
=C2=A0 =C2=A0 (shell-mode)))

(pro= vide 'multishell)

;;; multishell.el ends here<= /div>



--94eb2c0948929fe5a905286147ee--