[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 13a585b 1/4: multishell-list - provide for returning to st
From: |
ken manheimer |
Subject: |
[elpa] master 13a585b 1/4: multishell-list - provide for returning to stopped shells w/out restarting |
Date: |
Tue, 09 Feb 2016 09:33:06 +0000 |
branch: master
commit 13a585bed56dea2912d4d5daa4e2aa9fec880001
Author: Ken Manheimer <address@hidden>
Commit: Ken Manheimer <address@hidden>
multishell-list - provide for returning to stopped shells w/out restarting
... and other optional behaviors.
Fix positioning in multishell-list-clone-entry using line id rather than
text search.
---
multishell-list.el | 106 ++++++++++++++++++++++++++++++++++------------------
multishell.el | 3 +-
2 files changed, 72 insertions(+), 37 deletions(-)
diff --git a/multishell-list.el b/multishell-list.el
index b4ebe47..4ac2a31 100644
--- a/multishell-list.el
+++ b/multishell-list.el
@@ -12,11 +12,19 @@
(require 'tabulated-list)
-(defun multishell-list-open-pop ()
- "Pop to current entry's shell, and refresh the listing buffer."
- (interactive)
- (let ((list-buffer (current-buffer)))
- (multishell-pop-to-shell nil (tabulated-list-get-id))
+(defun multishell-list-open-pop (&optional arg)
+ "Pop to current entry's shell in separate window.
+
+The shell is started if it's not already going, unless this is
+invoked with optional `universal-argument'. In that case we
+pop to the buffer but don't change its run state."
+ (interactive "P")
+ (let ((list-buffer (current-buffer))
+ (entry (tabulated-list-get-id)))
+ (if arg
+ (pop-to-buffer
+ (multishell-bracket (multishell-name-from-entry entry)))
+ (multishell-pop-to-shell nil entry))
(with-current-buffer list-buffer
(revert-buffer))))
(defun multishell-list-open-as-default ()
@@ -27,21 +35,25 @@
(multishell-pop-to-shell '(16) (tabulated-list-get-id))
(with-current-buffer list-buffer
(revert-buffer))))
-(defun multishell-list-open-here ()
- "Switch to current entry's shell buffer."
- (interactive)
- (let ((list-buffer (current-buffer)))
- (multishell-pop-to-shell nil (tabulated-list-get-id) 'here)
+(defun multishell-list-open-here (&optional arg)
+ "Switch to current entry's shell buffer.
+
+The shell is started if it's not already going, unless this is
+invoked with optional `universal-argument'. In that case we
+switch to the buffer but don't activate (or deactivate) it it."
+ (interactive "P")
+ (let* ((list-buffer (current-buffer))
+ (entry (tabulated-list-get-id)))
+ (if arg
+ (switch-to-buffer
+ (multishell-bracket (multishell-name-from-entry entry)))
+ (multishell-pop-to-shell nil entry 'here))
(with-current-buffer list-buffer
- ;; In case they use switch-to-buffer or whatever to return.
(revert-buffer))))
-(defun multishell-list-delete ()
- "Remove current shell entry, and prompt for buffer-removal if present.
-
-\(We depend on intrinsic confirmation prompts for active buffers,
-supplemented by our own when buffer is inactive.)"
- (interactive)
+(defun multishell-list-delete (&optional arg)
+ "Remove current shell entry, and prompt for buffer-removal if present."
+ (interactive "P")
(let* ((entry (tabulated-list-get-id))
(name (multishell-name-from-entry entry))
(name-bracketed (multishell-bracket name))
@@ -54,10 +66,17 @@ supplemented by our own when buffer is inactive.)"
(kill-buffer name-bracketed)))
(tabulated-list-delete-entry)))
-(defun multishell-list-edit-entry ()
- "Edit the value of current shell entry."
- (interactive)
+(defun multishell-list-edit-entry (&optional arg)
+ "Edit the value of current shell entry.
+
+Submitting the change will not launch the entry, unless this is
+invoked with optional `universal-argument'. In the latter case,
+submitting the entry will pop to the shell in a new window,
+starting it if it's not already going."
+
+ (interactive "P")
(let* ((where (save-excursion (beginning-of-line) (point)))
+ (list-buffer (current-buffer))
(entry (tabulated-list-get-id))
(name (multishell-name-from-entry entry))
(revised (multishell-read-unbracketed-entry
@@ -71,18 +90,20 @@ supplemented by our own when buffer is inactive.)"
(when (and (not (string= name revised-name))
(setq buffer (get-buffer (multishell-bracket name))))
(with-current-buffer buffer
- (rename-buffer (multishell-bracket revised-name))))
+ (rename-buffer (multishell-bracket revised-name)))))
+ (when arg
+ (multishell-pop-to-shell nil revised-name))
+ (with-current-buffer list-buffer
(revert-buffer)
(goto-char where))))
(defun multishell-list-clone-entry (&optional arg)
- "Create a new list entry based on editing the current one.
+ "Create a new list entry, edited from the current one, ready to launch.
-You will be left in the list at the entry, not yet launched.
+If you provide an optional `universal-argument', the new entry
+will be launched when it's created.
-Providing a universal argument will also open the new shell.
-
-The already existing current entry is left untouched."
+The already existing original entry is left untouched."
(interactive "P")
(let* ((prototype (tabulated-list-get-id))
(name (multishell-name-from-entry prototype))
@@ -95,19 +116,18 @@ The already existing current entry is left untouched."
(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))))
+ (multishell-list-goto-item-by-entry new)
+ (when arg
+ (multishell-pop-to-shell nil new-name)))))
(defun multishell-list-placeholder (value default)
"Return VALUE if non-empty string, else DEFAULT."
(if (or (not value) (string= value ""))
default
value))
-(defconst multishell-list-active-buffer-flag "+")
-(defconst multishell-list-inactive-buffer-flag ".")
-(defconst multishell-list-absent-buffer-flag "x")
+(defconst multishell-list-active-flag "+")
+(defconst multishell-list-inactive-flag ".")
+(defconst multishell-list-absent-flag "x")
(defun multishell-list-entries ()
"Generate multishell name/path-spec entries list for tabulated-list."
@@ -120,10 +140,10 @@ The already existing current entry is left untouched."
(get-buffer
(multishell-bracket name))))
(status (cond ((not buffer)
- multishell-list-absent-buffer-flag)
+ multishell-list-absent-flag)
((comint-check-proc buffer)
- multishell-list-active-buffer-flag)
- (t multishell-list-inactive-buffer-flag)))
+ multishell-list-active-flag)
+ (t multishell-list-inactive-flag)))
(rest (cadr splat))
(dir (or (file-remote-p rest 'localname)
rest))
@@ -140,6 +160,13 @@ The already existing current entry is left untouched."
(multishell-list-placeholder dir "~")))))
(multishell-all-entries))))
+(defun multishell-list-goto-item-by-entry (entry)
+ "Position at beginning of line of tabulated list item for ENTRY."
+ (goto-char (point-min))
+ (while (and (not (eobp))
+ (not (string= (tabulated-list-get-id) entry)))
+ (forward-line 1)))
+
(defun compare-strings-as-numbers (a b)
(let ((a (aref (cadr a) 0))
(b (aref (cadr b) 0)))
@@ -160,6 +187,13 @@ The already existing current entry is left untouched."
(define-derived-mode multishell-list-mode
tabulated-list-mode "Shells"
"Major mode for listing current and historically registered shells.
+
+Initial sort is from most to least recently used:
+
+- First active shells, flagged with '+' a plus sign
+- Then, inactive shells, flagged with '.' a period
+- Then historical shells that currently have no buffer, flagged with 'x' an ex
+
\\{multishell-list-mode-map\}"
(setq tabulated-list-format
[;; (name width sort '(:right-align nil :pad-right nil))
diff --git a/multishell.el b/multishell.el
index f746c57..1f6a3a4 100644
--- a/multishell.el
+++ b/multishell.el
@@ -677,7 +677,8 @@ and path nil if none is resolved."
(when (and path (not is-active))
(when (and (derived-mode-p 'shell-mode) (file-remote-p path))
- ;; Returning to disconnected remote shell - tidy up:
+ ;; Returning to disconnected remote shell - do some tidying.
+ ;; (Prevents the "Args out of range" failure when reconnecting.)
(tramp-cleanup-connection
(tramp-dissect-file-name default-directory 'noexpand)
'keep-debug 'keep-password))