]> code.delx.au - gnu-emacs-elpa/commitdiff
Simplify.
authorKen Manheimer <ken.manheimer@gmail.com>
Fri, 18 Dec 2015 19:48:44 +0000 (14:48 -0500)
committerKen Manheimer <ken.manheimer@gmail.com>
Fri, 18 Dec 2015 19:48:44 +0000 (14:48 -0500)
poptoshell.el

index 17c7ed10ef78418442eb28d4d0c03e62a49d6c96..7f54b2804f89cee416696799d353ea1b5580dd2a 100644 (file)
@@ -32,7 +32,7 @@ Otherwise, open a new window in the current frame."
 
 (defvar pop-to-shell-primary-name "*shell*"
   "Shell name to use for un-modified pop-to-shell buffer target.")
-(defvar pop-to-shell-buffer-name-history nil
+(defvar multishell:buffer-name-history nil
   "Distinct pop-to-shell completion history container.")
 
 (defun pop-to-shell (&optional arg)
@@ -40,8 +40,9 @@ Otherwise, open a new window in the current frame."
   "Navigate to or within local and remote shell buffers.
 
 Use universal arguments to launch and choose between alternate
-shell buffers, select which is default.  With Emacs tramp syntax,
-launch or return to a remote shell.
+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.
 
 ==== Basic operation:
 
@@ -105,7 +106,7 @@ slash will be used for the shell name."
   (let* ((from-buffer (current-buffer))
          (doublearg (equal arg '(16)))
          (temp (if arg
-                   (read-bare-shell-buffer-name
+                   (multishell:read-bare-shell-buffer-name
                     (format "Shell buffer name [%s]%s "
                             (substring-no-properties
                              pop-to-shell-primary-name
@@ -210,46 +211,33 @@ slash will be used for the shell name."
      nil 'visible)
     nil))
 
-(defun read-bare-shell-buffer-name (prompt default)
+(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 ((got
-         (completing-read
-          prompt
-          ;; COLLECTION:
-          (pop-to-shell-buffer-name-candidates)
-          ;; PREDICATE:
-          nil
-          ;; REQUIRE-MATCH:
-          'confirm
-          ;; INITIAL-INPUT:
-          nil
-          ;; HIST:
-          'pop-to-shell-buffer-name-history
-          )))
+  (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 "")) (bracket-asterisks got) default)))
 
-(defun pop-to-shell-buffer-name-candidates ()
-  "Return a list of the shell buffer name candidates.
-
-The list consists of the combination of existing shell buffer
-names plus the names in the history (which can include
-non-existent buffers, from saved history)."
- (append (remq nil
-               (mapcar (lambda (buffer)
-                         (let ((name (buffer-name buffer)))
-                           (if (with-current-buffer buffer
-                                 (eq major-mode 'shell-mode))
-                               (if (> (length name) 2)
-                                   (substring name 1 (1- (length
-                                                          name)))
-                                 name))))
-                       (buffer-list)))
-         pop-to-shell-buffer-name-history)
-)
-
 (defun 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) "*"))