]> code.delx.au - gnu-emacs-elpa/blobdiff - multishell-list.el
multishell - multishell-list "clone"; small edits
[gnu-emacs-elpa] / multishell-list.el
index 63c6f120065313341073e4ec9b54dd5ddbca3912..b4ebe47bc2d371f0e40b97ba3c2c47da4c54d3eb 100644 (file)
@@ -3,11 +3,13 @@
 ;; Copyright (C) 2016 Free Software Foundation, Inc. and Ken Manheimer
 
 ;; Author: Ken Manheimer <ken.manheimer@gmail.com>
-;; Version: 1.0.10
+;; Version: 1.1.2
 ;; Created: 2016 -- first public availability
 ;; Keywords: processes
 ;; URL: https://github.com/kenmanheimer/EmacsMultishell
 
+;; See multishell.el for commentary, change log, etc.
+
 (require 'tabulated-list)
 
 (defun multishell-list-open-pop ()
@@ -60,21 +62,44 @@ supplemented by our own when buffer is inactive.)"
          (name (multishell-name-from-entry entry))
          (revised (multishell-read-unbracketed-entry
                    (format "Edit shell spec for %s: " name)
-                   nil
-                   entry))
-         (revised-path (and revised (cadr (multishell-split-entry revised))))
+                   entry
+                   'no-record))
          (revised-name (multishell-name-from-entry revised))
          buffer)
     (when (not (string= revised entry))
-      (multishell-delete-history-name name)
+      (multishell-replace-entry entry revised)
       (when (and (not (string= name revised-name))
                  (setq buffer (get-buffer (multishell-bracket name))))
         (with-current-buffer buffer
           (rename-buffer (multishell-bracket revised-name))))
-      (multishell-register-name-to-path revised-name revised-path)
       (revert-buffer)
       (goto-char where))))
 
+(defun multishell-list-clone-entry (&optional arg)
+  "Create a new list entry based on editing the current one.
+
+You will be left in the list at the entry, not yet launched.
+
+Providing a universal argument will also open the new shell.
+
+The already existing current entry is left untouched."
+  (interactive "P")
+  (let* ((prototype (tabulated-list-get-id))
+         (name (multishell-name-from-entry prototype))
+         (new (multishell-read-unbracketed-entry
+               (format "Clone new shell spec from %s: " name)
+               prototype
+               'no-record))
+         (new-name (multishell-name-from-entry new))
+         (new-path (cadr (multishell-split-entry new))))
+    (when (not (string= new prototype))
+      (multishell-register-name-to-path new-name new-path)
+      (revert-buffer)
+      (goto-char (point-min))
+      (re-search-forward (format "^ . \\b%s\\b"
+                                 (regexp-quote new-name)))
+      (beginning-of-line))))
+
 (defun multishell-list-placeholder (value default)
   "Return VALUE if non-empty string, else DEFAULT."
   (if (or (not value) (string= value ""))
@@ -85,7 +110,7 @@ supplemented by our own when buffer is inactive.)"
 (defconst multishell-list-absent-buffer-flag "x")
 
 (defun multishell-list-entries ()
-  "Generate multishell name/path entries list for tabulated-list."
+  "Generate multishell name/path-spec entries list for tabulated-list."
   (let ((recency 0))
     (mapcar #'(lambda (entry)
                 (setq recency (1+ recency))
@@ -100,13 +125,11 @@ supplemented by our own when buffer is inactive.)"
                                       multishell-list-active-buffer-flag)
                                      (t multishell-list-inactive-buffer-flag)))
                        (rest (cadr splat))
-                       (dissected (and rest (file-remote-p rest)
-                                       (tramp-dissect-file-name rest t)))
-                       (path (or (and dissected (aref dissected 3))
-                                 rest))
-                       (hops (and dissected
+                       (dir (or (file-remote-p rest 'localname)
+                                rest))
+                       (hops (and (file-remote-p rest 'localname)
                                   (substring
-                                   rest 0 (- (length rest) (length path))))))
+                                   rest 0 (- (length rest) (length dir))))))
                   (when (not name)
                     (setq name (multishell-name-from-entry entry)))
                   (list entry
@@ -114,16 +137,29 @@ supplemented by our own when buffer is inactive.)"
                                 status
                                 name
                                 (multishell-list-placeholder hops "-")
-                                (multishell-list-placeholder path "~")))))
+                                (multishell-list-placeholder dir "~")))))
             (multishell-all-entries))))
 
 (defun compare-strings-as-numbers (a b)
   (let ((a (aref (cadr a) 0))
         (b (aref (cadr b) 0)))
     (> (string-to-number a) (string-to-number b))))
+
+(defvar multishell-list-mode-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map (kbd "c") 'multishell-list-clone-entry)
+    (define-key map (kbd "d") 'multishell-list-delete)
+    (define-key map (kbd "\C-k") 'multishell-list-delete)
+    (define-key map (kbd "k") 'multishell-list-delete)
+    (define-key map (kbd "e") 'multishell-list-edit-entry)
+    (define-key map (kbd "o") 'multishell-list-open-pop)
+    (define-key map (kbd " ") 'multishell-list-open-pop)
+    (define-key map (kbd "O") 'multishell-list-open-as-default)
+    (define-key map (kbd "RET") 'multishell-list-open-here)
+    map))
 (define-derived-mode multishell-list-mode
     tabulated-list-mode "Shells"
-  "Major mode for listing current and historically registered shells..
+  "Major mode for listing current and historically registered shells.
 \\{multishell-list-mode-map\}"
   (setq tabulated-list-format
         [;; (name width sort '(:right-align nil :pad-right nil))
@@ -131,30 +167,11 @@ supplemented by our own when buffer is inactive.)"
          ("! " 1 t :pad-right 1)
          ("Name" 15 t)
          ("Hops" 30 t)
-         ("Path" 30 t)]
+         ("Directory" 30 t)]
         tabulated-list-sort-key '("#" . t)
         tabulated-list-entries #'multishell-list-entries)
   (tabulated-list-init-header))
 
-(defvar multishell-list-already-re-reverting nil
-  "Don't set - internal for `multishell-list-revert-buffer-kludge'.")
-(defun multishell-list-revert-buffer-kludge ()
-  "Double revert for kludge workaround of untable sorting."
-  (if (not multishell-list-already-re-reverting)
-      (let ((multishell-list-already-re-reverting t))
-        (revert-buffer))))
-(add-hook 'tabulated-list-revert-hook 'multishell-list-revert-buffer-kludge)
-
-(define-key multishell-list-mode-map (kbd "d") 'multishell-list-delete)
-(define-key multishell-list-mode-map (kbd "\C-k") 'multishell-list-delete)
-(define-key multishell-list-mode-map (kbd "k") 'multishell-list-delete)
-(define-key multishell-list-mode-map (kbd "e") 'multishell-list-edit-entry)
-(define-key multishell-list-mode-map (kbd "o") 'multishell-list-open-pop)
-(define-key multishell-list-mode-map (kbd " ") 'multishell-list-open-pop)
-(define-key multishell-list-mode-map (kbd "O") 'multishell-list-open-as-default)
-(define-key multishell-list-mode-map
-  (kbd "<return>") 'multishell-list-open-here)
-
 ;;;###autoload
 (defun multishell-list ()
   "Edit your current and historic list of shell buffers.