From 4c06767983603e85d0c219520989d9ab75e3fecf Mon Sep 17 00:00:00 2001 From: Ken Manheimer Date: Sat, 30 Jan 2016 13:30:16 -0500 Subject: [PATCH] multishell - shake out some initial multishell-list glitches - (Offer to) delete shell buffer, if present, when deleting an entry. Rely on the default active-shell deletion prompting for confirmation, supplementing with our own confirmation for inactive shell buffers. - Set recency (numeric rank) as initial sort field, get closer to stable sort - still needs work. - Recompute list on any operation that affects it, and try to preserve stability. Also needs more work. --- multishell-list.el | 54 +++++++++++++++++++++++++++++++--------------- multishell.el | 20 +++++++++++++++-- 2 files changed, 55 insertions(+), 19 deletions(-) diff --git a/multishell-list.el b/multishell-list.el index 578abdbb5..f80ed4bc3 100644 --- a/multishell-list.el +++ b/multishell-list.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2016 Free Software Foundation, Inc. and Ken Manheimer ;; Author: Ken Manheimer -;; Version: 1.0.9 +;; Version: 1.0.10 ;; Created: 2016 -- first public availability ;; Keywords: processes ;; URL: https://github.com/kenmanheimer/EmacsMultishell @@ -13,19 +13,32 @@ (defun multishell-list-open-pop () "Pop to current entry's shell, and refresh the listing buffer." (interactive) - (multishell-pop-to-shell nil (tabulated-list-get-id))) + (let ((start-buffer (current-buffer))) + (multishell-pop-to-shell nil (tabulated-list-get-id)) + (with-current-buffer start-buffer + (revert-buffer)))) (defun multishell-list-open-as-default () "Pop to current entry's shell, and set as the default shell." (interactive) - (message "%s <==" (multishell-name-from-entry (tabulated-list-get-id))) - (multishell-pop-to-shell '(16) (tabulated-list-get-id))) + (let ((start-buffer (current-buffer))) + (message "%s <==" (multishell-name-from-entry (tabulated-list-get-id))) + (multishell-pop-to-shell '(16) (tabulated-list-get-id))) + (with-current-buffer start-buffer + (revert-buffer))) (defun multishell-list-open-here () "Switch to current entry's shell buffer." (interactive) - (multishell-pop-to-shell nil (tabulated-list-get-id) 'here)) + (let ((start-buffer (current-buffer))) + (multishell-pop-to-shell nil (tabulated-list-get-id) 'here)) + (with-current-buffer start-buffer + ;; In case they use switch-to-buffer or whatever to return. + (revert-buffer))) (defun multishell-list-delete () - "Remove current environment variable value." + "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) (let* ((where (save-excursion (beginning-of-line) (point))) (entry (tabulated-list-get-id)) @@ -39,8 +52,6 @@ (y-or-n-p (format "Kill buffer %s? " name-bracketed))) (kill-buffer name-bracketed))) (revert-buffer) - (if (not tabulated-list-sort-key) - (revert-buffer)) (goto-char where))) (defun multishell-list-edit-entry () @@ -64,8 +75,6 @@ (rename-buffer (multishell-bracket revised-name)))) (multishell-register-name-to-path revised-name revised-path) (revert-buffer) - (if (not tabulated-list-sort-key) - (revert-buffer)) (goto-char where)))) (defun multishell-list-placeholder (value default) @@ -101,7 +110,7 @@ status name (multishell-list-placeholder hops "-") - (multishell-list-placeholder path ":"))))) + (multishell-list-placeholder path "~"))))) (multishell-all-entries)))) (defun compare-strings-as-numbers (a b) @@ -112,15 +121,26 @@ tabulated-list-mode "Shells" "Major mode for listing current and historically registered shells.. \\{multishell-list-mode-map\}" - (setq tabulated-list-format [("#" 0 compare-strings-as-numbers) - ("! " 1 t) - ("Name" 15 t) - ("Hops" 30 t) - ("Path" 30 t)] - tabulated-list-sort-key nil + (setq tabulated-list-format + [;; (name width sort '(:right-align nil :pad-right nil)) + ("#" 0 compare-strings-as-numbers) + ("! " 1 t) + ("Name" 15 t) + ("Hops" 30 t) + ("Path" 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 "e") 'multishell-list-edit-entry) (define-key multishell-list-mode-map (kbd "o") 'multishell-list-open-pop) diff --git a/multishell.el b/multishell.el index 7aa4b462d..0ea7bfab4 100644 --- a/multishell.el +++ b/multishell.el @@ -3,7 +3,7 @@ ;; Copyright (C) 1999-2016 Free Software Foundation, Inc. and Ken Manheimer ;; Author: Ken Manheimer -;; Version: 1.0.9 +;; Version: 1.0.10 ;; Created: 1999 -- first public availability ;; Keywords: processes ;; URL: https://github.com/kenmanheimer/EmacsMultishell @@ -59,6 +59,16 @@ ;; ;; Change Log: ;; +;; * 2016-01-30 1.0.10 Ken Manheimer: +;; - shake out some initial multishell-list glitches: +;; - Delete shell buffer, if present, when deleting an entry. +;; (Offer to) delete shell buffer, if present, when deleting an +;; entry. Rely on the default active-shell deletion prompting +;; for confirmation, supplementing with our own confirmation +;; for inactive shell buffers. +;; - Set recency (numeric rank) as initial sort field +;; - Recompute list on any operation that affects it, and try to +;; preserve stability. (Still needs work.) ;; * 2016-01-30 1.0.9 Ken Manheimer: ;; - Add multishell-list for managing the collection of current and ;; history-registered shells: edit, delete, and switch/pop to entries. @@ -108,6 +118,12 @@ ;; ;; TODO and Known Issues: ;; +;; * 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 @@ -129,7 +145,7 @@ (require 'savehist) (require 'multishell-list) -(defvar multishell-version "1.0.9") +(defvar multishell-version "1.0.10") (defun multishell-version (&optional here) "Return string describing the loaded multishell version." (interactive "P") -- 2.39.2