]> code.delx.au - gnu-emacs-elpa/blob - multishell.el
ea8958e5eecfaed4d12be8ef5b388b61ba435768
[gnu-emacs-elpa] / multishell.el
1 ;;; multishell.el --- facilitate multiple local and remote shell buffers
2
3 ;; Copyright (C) 1999-2016 Free Software Foundation, Inc. and Ken Manheimer
4
5 ;; Author: Ken Manheimer <ken.manheimer@gmail.com>
6 ;; Version: 1.0.5
7 ;; Created: 1999 -- first public availability
8 ;; Keywords: processes
9 ;; URL: https://github.com/kenmanheimer/EmacsMultishell
10 ;;
11 ;;; Commentary:
12 ;;
13 ;; Easily use and navigate multiple shell buffers, including remote shells.
14 ;; Fundamentally, multishell is the function `multishell-pop-to-shell' -
15 ;; a la `pop-to-buffer' - plus a keybinding. Together, they enable you to:
16 ;;
17 ;; * Get to the input point from wherever you are in a shell buffer,
18 ;; ... or to any of your shell buffers, from elsewhere inside emacs.
19 ;;
20 ;; * Use universal arguments to launch and choose among alternate shell buffers,
21 ;; * ... and change which is the current default.
22 ;;
23 ;; * Easily restart disconnected shells, or shells from prior sessions
24 ;; * ... the latter from Emacs builtin savehist minibuf history persistence
25 ;;
26 ;; * Append a path to a new shell name to launch a shell in that directory,
27 ;; * ... and use a path with Emacs tramp syntax to launch a remote shell -
28 ;; for example:
29 ;;
30 ;; * `/ssh:example.net:/` for a shell buffer in / on example.net.
31 ;; The buffer will be named "*example.net*".
32 ;;
33 ;; * `#ex/ssh:example.net|sudo:root@example.net:/etc` for a root shell
34 ;; starting in /etc on example.net named "*#ex*".
35 ;;
36 ;; * '\#intrn/ssh:corp.com|ssh:intern.corp.com|sudo:root@intern.corp.com:/etc'
37 ;; to go via corp.com to intern.corp.com, sudood to root, in /etc. Whee! (-:
38 ;; The buffer will be named "*#intrn*".
39 ;;
40 ;; * File visits will all be under the auspices of the account, and relative to
41 ;; the current directory, on the remote host.
42 ;;
43 ;; See the `multishell-pop-to-shell` docstring for details.
44 ;;
45 ;; Customize-group `multishell' to select and activate a keybinding and set
46 ;; various behaviors. Customize-group `savehist' to preserve buffer
47 ;; names/paths across emacs sessions.
48 ;;
49 ;; Please use
50 ;; [the multishell repository](https://github.com/kenmanheimer/EmacsMultishell)
51 ;; issue tracker to report problems, suggestions, etc.
52 ;;
53 ;; (NOTE - tramp sometimes has a problem opening a remote shell pointed at
54 ;; a homedir, eg `/ssh:example.net:` or `/ssh:example.net:~`. When it
55 ;; fails, it won't work for the rest of the session. Non-homedir remote
56 ;; access isn't disrupted. Until this is fixed, you may need to start
57 ;; remote shells with an explicit path, then cd ~.)
58 ;;
59 ;; Change Log:
60 ;;
61 ;; * 2016-01-16 1.0.5 Ken Manheimer:
62 ;; - History now includes paths, when designated
63 ;; - Actively track current directory in history entries that have a path.
64 ;; Custom control: multishell-history-entry-tracks-current-directory
65 ;; - Offer to remove shell's history entry when buffer is killed.
66 ;; (Currently the only UI mechanism to remove history entries.)
67 ;; - Fix - prevent duplicate entries for same name but different paths
68 ;; - Fix - recognize and respect tramp path syntax to start in home dir
69 ;; - But tramp bug, remote w/empty path (homedir) often fails, gets wedged.
70 ;; - Simplify history var name, migrate existing history if any from old name
71 ;; * 2016-01-04 1.0.4 Ken Manheimer - Released to ELPA
72 ;; * 2016-01-02 Ken Manheimer - working on this in public, but not yet released.
73 ;;
74 ;; TODO:
75 ;;
76 ;; * Isolate tramp sporadic failure to connect to remote+homedir (empty path)
77 ;; syntax
78 ;; (eg, /ssh:xyz.com|sudo:root@xyz.com: or /ssh:xyz.com|sudo:root@xyz.com:~)
79 ;; * Find suitable, internally consistent ways to sort tidy completions, eg:
80 ;; - first list completions for active shells, then present but inactive,
81 ;; then historical
82 ;; - some way for user to toggle between presenting just buffer names vs
83 ;; full buffer/path
84 ;; - without cutting user off from easy editing of path
85 ;; * Find proper method for setting field boundary at beginning of tramp path
86 ;; in the minibuffer, in order to see whether the field boundary magically
87 ;; enables tramp completion of the path.
88 ;; * Assess whether option to delete history entry on kill-buffer is
89 ;; sufficient.
90
91 ;;; Code:
92
93 (require 'comint)
94 (require 'shell)
95
96 (defgroup multishell nil
97 "Allout extension that highlights outline structure graphically.
98
99 Customize `allout-widgets-auto-activation' to activate allout-widgets
100 with allout-mode."
101 :group 'shell)
102
103 (defcustom multishell-command-key "\M- "
104 "The key to use if `multishell-activate-command-key' is true.
105
106 You can instead manually bind `multishell-pop-to-shell` using emacs
107 lisp, eg: (global-set-key \"\\M- \" 'multishell-pop-to-shell)."
108 :type 'key-sequence
109 :group 'multishell)
110
111 (defvar multishell--responsible-for-command-key nil
112 "Coordination for multishell key assignment.")
113 (defun multishell-activate-command-key-setter (symbol setting)
114 "Implement `multishell-activate-command-key' choice."
115 (set-default 'multishell-activate-command-key setting)
116 (when (or setting multishell--responsible-for-command-key)
117 (multishell-implement-command-key-choice (not setting))))
118 (defun multishell-implement-command-key-choice (&optional unbind)
119 "If settings dicate, implement binding of multishell command key.
120
121 If optional UNBIND is true, globally unbind the key.
122
123 * `multishell-activate-command-key' - Set this to get the binding or not.
124 * `multishell-command-key' - The key to use for the binding, if appropriate."
125 (cond (unbind
126 (when (and (boundp 'multishell-command-key) multishell-command-key)
127 (global-unset-key multishell-command-key)))
128 ((not (and (boundp 'multishell-activate-command-key)
129 (boundp 'multishell-command-key)))
130 nil)
131 ((and multishell-activate-command-key multishell-command-key)
132 (setq multishell--responsible-for-command-key t)
133 (global-set-key multishell-command-key 'multishell-pop-to-shell))))
134
135 (defcustom multishell-activate-command-key nil
136 "Set this to impose the `multishell-command-key' binding.
137
138 You can instead manually bind `multishell-pop-to-shell` using emacs
139 lisp, eg: (global-set-key \"\\M- \" 'multishell-pop-to-shell)."
140 :type 'boolean
141 :set 'multishell-activate-command-key-setter
142 :group 'multishell)
143
144 ;; Assert the customizations whenever the package is loaded:
145 (with-eval-after-load "multishell"
146 (multishell-implement-command-key-choice))
147
148 (defcustom multishell-pop-to-frame nil
149 "*If non-nil, jump to a frame already showing the shell, if another is.
150
151 Otherwise, disregard already-open windows on the shell if they're
152 in another frame, and open a new window on the shell in the
153 current frame.
154
155 \(Use `pop-up-windows' to change multishell other-buffer vs
156 current-buffer behavior.)"
157 :type 'boolean
158 :group 'multishell)
159
160 (defcustom multishell-history-entry-tracks-current-directory t
161 "Modify shell buffer's multishell entry to track the current directory.
162
163 When set, the path part of the name/path entry for each shell
164 will track the current directory of the shell with emacs. If
165 `savehist' is active, the directory tracking will extend across
166 emacs sessions."
167 :type 'boolean
168 :group 'multishell)
169
170 (defvar multishell-history nil
171 "Name/path entries, most recent first.")
172 (when (and (not multishell-history)
173 (boundp 'multishell-buffer-name-history)
174 multishell-buffer-name-history)
175 ;; Migrate few users who had old var to new.
176 (setq multishell-history multishell-buffer-name-history)
177 )
178
179 (defvar multishell-primary-name "*shell*"
180 "Shell name to use for un-modified multishell-pop-to-shell buffer target.")
181
182 ;; Multiple entries happen because completion also adds name to history.
183 (defun multishell-register-name-to-path (name path)
184 "Add or replace entry associating NAME with PATH in `multishell-history'.
185
186 If NAME already had a PATH and new PATH is empty, retain old one.
187
188 Promote added/changed entry to the front of the list."
189 ;; Add or promote to the front, tracking path changes in the process.
190 (let* ((entries (multishell-history-entries name))
191 (becomes (concat name path))
192 oldpath)
193 (dolist (entry entries)
194 (when (or (not path) (string= path ""))
195 ;; Retain explicit established path.
196 (setq path (cadr (multishell-split-entry-name-and-tramp entry))
197 becomes (concat name path)))
198 (setq multishell-history (delete entry multishell-history)))
199 (setq multishell-history (push becomes multishell-history))))
200
201 (defun multishell-history-entries (name)
202 "Return `multishell-history' entry that starts with NAME, or nil if none."
203 (let ((match-expr (concat "^" name "\\\(/.*$\\\)?"))
204 got)
205 (dolist (entry multishell-history)
206 (when (and (string-match match-expr entry)
207 (not (member entry got)))
208 (setq got (cons entry got))))
209 got))
210
211 (defun multishell-pop-to-shell (&optional arg)
212 "Easily navigate to and within multiple shell buffers, local and remote.
213
214 Use universal arguments to launch and choose between alternate
215 shell buffers and to select which is default. Append a path to
216 a new shell name to launch a shell in that directory, and use
217 Emacs tramp syntax to launch a remote shell.
218
219 Customize-group `multishell' to set up a key binding and tweak behaviors.
220
221 ==== Basic operation:
222
223 - If the current buffer is shell-mode (or shell-mode derived)
224 buffer then focus is moved to the process input point.
225
226 \(You can use a universal argument go to a different shell
227 buffer when already in a buffer that has a process - see
228 below.)
229
230 - If not in a shell buffer (or with universal argument), go to a
231 window that is already showing the (a) shell buffer, if any.
232
233 In this case, the cursor is left in its prior position in the
234 shell buffer. Repeating the command will then go to the
235 process input point, per the first item in this list.
236
237 We respect `pop-up-windows', so you can adjust it to set the
238 other-buffer/same-buffer behavior.
239
240 - Otherwise, start a new shell buffer, using the current
241 directory as the working directory.
242
243 If a buffer with the resulting name exists and its shell process
244 was disconnected or otherwise stopped, it's resumed.
245
246 ===== Universal arg to start and select between named shell buffers:
247
248 You can name alternate shell buffers to create or return to using
249 single or doubled universal arguments:
250
251 - With a single universal argument, prompt for the buffer name
252 to use (without the asterisks that shell mode will put around
253 the name), defaulting to 'shell'.
254
255 Completion is available.
256
257 This combination makes it easy to start and switch between
258 multiple shell buffers.
259
260 - A double universal argument will prompt for the name *and* set
261 the default to that name, so the target shell becomes the
262 primary.
263
264 ===== Select starting directory and remote host:
265
266 The shell buffer name you give to the prompt for a universal arg
267 can include an appended path. That will be used for the startup
268 directory. You can use tramp remote syntax to specify a remote
269 shell. If there is an element after a final '/', that's used for
270 the buffer name. Otherwise, the host, domain, or path is used.
271
272 For example:
273
274 * Use '/ssh:example.net:/home/myaccount' for a shell buffer in
275 /home/myaccount on example.net; the buffer will be named
276 \"*example.net*\".
277 * '\#ex/ssh:example.net|sudo:root@example.net:/etc' for a root
278 shell in /etc on example.net named \"*#ex*\".
279 * '\#in/ssh:corp.com|ssh:internal.corp.com|sudo:root@internal.corp.com:/etc'
280 for a root shell name \"*in*\" in /etc on internal.corp.com, via host
281 corp.com.
282
283 \(NOTE that there is a problem with specifying a remote homedir using
284 tramp syntax, eg '/ssh:example.net:'. That sometimes fails on an obscure
285 bug - particularly for remote with empty path (homedir) syntax. Until fixed,
286 you may need to start remote shells with an explicit path, then cd ~.)
287
288 You can change the startup path for a shell buffer by editing it
289 at the completion prompt. The new path will be preserved in
290 history but will not take effect for an already-running shell.
291
292 To remove a shell buffer's history entry, kill the buffer and
293 affirm removal of the entry when prompted.
294
295 ===== Activate savehist to retain shell buffer names and paths across Emacs sessions:
296
297 To have emacs maintain your history of shell buffer names and paths,
298 customize the savehist group to activate savehist."
299
300 (interactive "P")
301
302 (let* ((from-buffer (current-buffer))
303 (from-buffer-is-shell (derived-mode-p 'shell-mode))
304 (doublearg (equal arg '(16)))
305 (target-name-and-path
306 (multishell-derive-target-name-and-path
307 (if arg
308 (multishell-read-bare-shell-buffer-name
309 (format "Shell buffer name [%s]%s "
310 (substring-no-properties
311 multishell-primary-name
312 1 (- (length multishell-primary-name) 1))
313 (if doublearg " <==" ":"))
314 multishell-primary-name)
315 multishell-primary-name)))
316 (use-default-dir (cadr target-name-and-path))
317 (target-shell-buffer-name (car target-name-and-path))
318 (curr-buff-proc (get-buffer-process from-buffer))
319 (target-buffer (if from-buffer-is-shell
320 from-buffer
321 (let ((got (get-buffer target-shell-buffer-name)))
322 (if (buffer-live-p got)
323 got
324 (kill-buffer got)
325 (get-buffer target-shell-buffer-name)))))
326 inwin
327 already-there)
328
329 (when doublearg
330 (setq multishell-primary-name target-shell-buffer-name))
331
332 ;; Situate:
333
334 (cond
335
336 ((and (or curr-buff-proc from-buffer-is-shell)
337 (not arg)
338 (eq from-buffer target-buffer)
339 (not (eq target-shell-buffer-name (buffer-name from-buffer))))
340 ;; In a shell buffer, but not named - stay in buffer, but go to end.
341 (setq already-there t))
342
343 ((string= (buffer-name) target-shell-buffer-name)
344 ;; Already in the specified shell buffer:
345 (setq already-there t))
346
347 ((or (not target-buffer)
348 (not (setq inwin
349 (multishell-get-visible-window-for-buffer target-buffer))))
350 ;; No preexisting shell buffer, or not in a visible window:
351 (pop-to-buffer target-shell-buffer-name pop-up-windows))
352
353 ;; Buffer exists and already has a window - jump to it:
354 (t (if (and multishell-pop-to-frame
355 inwin
356 (not (equal (window-frame (selected-window))
357 (window-frame inwin))))
358 (select-frame-set-input-focus (window-frame inwin)))
359 (if (not (string= (buffer-name (current-buffer))
360 target-shell-buffer-name))
361 (pop-to-buffer target-shell-buffer-name t))))
362
363 ;; We're in the buffer. Activate:
364
365 (if (not (comint-check-proc (current-buffer)))
366 (multishell-start-shell-in-buffer (buffer-name (current-buffer))
367 use-default-dir))
368
369 ;; If the destination buffer has a stopped process, resume it:
370 (let ((process (get-buffer-process (current-buffer))))
371 (if (and process (equal 'stop (process-status process)))
372 (continue-process process)))
373 (multishell-register-name-to-path (multishell-unbracket-asterisks
374 target-shell-buffer-name)
375 use-default-dir)
376 (when (or already-there
377 (equal (current-buffer) from-buffer))
378 (goto-char (point-max))
379 (and (get-buffer-process from-buffer)
380 (goto-char (process-mark (get-buffer-process from-buffer)))))))
381
382 (defun multishell-kill-buffer-query-function ()
383 "Offer to remove multishell-history entry for buffer."
384 ;; Removal choice is crucial, so users can, eg, kill and a runaway shell
385 ;; and keep the history entry to easily restart it.
386 ;;
387 ;; We use kill-buffer-query-functions instead of kill-buffer-hook because:
388 ;;
389 ;; 1. It enables the user to remove the history without killing the buffer,
390 ;; by cancelling the kill-buffer process after affirming history removal.
391 ;; 2. kill-buffer-hooks often fails to run when killing shell buffers!
392 ;; I've failed to resolve that, and like the first reason well enough.
393
394 ;; (Use condition-case to avoid inadvertant disruption of kill-buffer
395 ;; activity. kill-buffer happens behind the scenes a whole lot.)
396 (condition-case anyerr
397 (let ((entries (and (derived-mode-p 'shell-mode)
398 (multishell-history-entries
399 (multishell-unbracket-asterisks (buffer-name))))))
400 (dolist (entry entries)
401 (when (and entry
402 (y-or-n-p (format "Remove multishell history entry `%s'? "
403 entry)))
404 (setq multishell-history
405 (delete entry multishell-history)))))
406 (error nil))
407 t)
408 (add-hook 'kill-buffer-query-functions 'multishell-kill-buffer-query-function)
409
410 (defun multishell-get-visible-window-for-buffer (buffer)
411 "Return visible window containing buffer."
412 (catch 'got-a-vis
413 (walk-windows
414 (function (lambda (win)
415 (if (and (eq (window-buffer win) buffer)
416 (equal (frame-parameter
417 (selected-frame) 'display)
418 (frame-parameter
419 (window-frame win) 'display)))
420 (throw 'got-a-vis win))))
421 nil 'visible)
422 nil))
423
424 (defun multishell-read-bare-shell-buffer-name (prompt default)
425 "PROMPT for shell buffer name, sans asterisks.
426
427 Return the supplied name bracketed with the asterisks, or specified DEFAULT
428 on empty input."
429 (let* ((candidates
430 (append
431 ;; Plain shell buffer names appended with names from name/path hist:
432 (remq nil
433 (mapcar (lambda (buffer)
434 (let* ((name (multishell-unbracket-asterisks
435 (buffer-name buffer))))
436 (and (buffer-live-p buffer)
437 (with-current-buffer buffer
438 ;; Shell mode buffers.
439 (derived-mode-p 'shell-mode))
440 (not (multishell-history-entries name))
441 name)))
442 (buffer-list)))
443 multishell-history))
444 (got (completing-read prompt
445 ;; COLLECTION:
446 (reverse candidates)
447 ;; PREDICATE:
448 nil
449 ;; REQUIRE-MATCH:
450 'confirm
451 ;; INITIAL-INPUT
452 nil
453 ;; HIST:
454 'multishell-history)))
455 (if (not (string= got ""))
456 (multishell-bracket-asterisks got)
457 default)))
458
459 (defun multishell-derive-target-name-and-path (path-ish)
460 "Give tramp-style PATH-ISH, determine target name and default directory.
461
462 The name is the part of the string before the initial '/' slash,
463 if any. Otherwise, it's either the host-name, domain-name, final
464 directory name, or local host name. The path is everything
465 besides the string before the initial '/' slash.
466
467 Return them as a list (name dir), with dir nil if none given."
468 (let (name (path "") dir)
469 (cond ((string= path-ish "") (setq dir multishell-primary-name))
470 ((string-match "^\\*\\([^/]*\\)\\(/.*\\)\\*" path-ish)
471 ;; We have a path, use it
472 (let ((overt-name (match-string 1 path-ish)))
473 (setq path (match-string 2 path-ish))
474 (if (string= overt-name "") (setq overt-name nil))
475 (if (string= path "") (setq path nil))
476 (setq name
477 (multishell-bracket-asterisks
478 (or overt-name
479 (if (file-remote-p path)
480 (let ((vec (tramp-dissect-file-name path)))
481 (or (tramp-file-name-host vec)
482 (tramp-file-name-domain vec)
483 (tramp-file-name-localname vec)
484 system-name))
485 (multishell-unbracket-asterisks
486 multishell-primary-name)))))))
487 (t (setq name (multishell-bracket-asterisks path-ish))))
488 (list name path)))
489
490 (defun multishell-bracket-asterisks (name)
491 "Return a copy of name, ensuring it has an asterisk at the beginning and end."
492 (if (not (string= (substring name 0 1) "*"))
493 (setq name (concat "*" name)))
494 (if (not (string= (substring name -1) "*"))
495 (setq name (concat name "*")))
496 name)
497 (defun multishell-unbracket-asterisks (name)
498 "Return a copy of name, removing asterisks, if any, at beginning and end."
499 (if (string= (substring name 0 1) "*")
500 (setq name (substring name 1)))
501 (if (string= (substring name -1) "*")
502 (setq name (substring name 0 -1)))
503 name)
504
505 (defun multishell-start-shell-in-buffer (buffer-name path)
506 "Ensure a shell is started, with name NAME and PATH."
507 ;; We work around shell-mode's bracketing of the buffer name, and do
508 ;; some tramp-mode hygiene for remote connections.
509
510 (let* ((buffer buffer-name)
511 (prog (or explicit-shell-file-name
512 (getenv "ESHELL")
513 (getenv "SHELL")
514 "/bin/sh"))
515 (name (file-name-nondirectory prog))
516 (startfile (concat "~/.emacs_" name))
517 (xargs-name (intern-soft (concat "explicit-" name "-args")))
518 is-remote)
519 (set-buffer buffer-name)
520 (if (and path (not (string= path "")))
521 (setq default-directory path))
522 (setq is-remote (file-remote-p default-directory))
523 (when (and is-remote
524 (derived-mode-p 'shell-mode)
525 (not (comint-check-proc (current-buffer))))
526 ;; We're returning to an already established but disconnected remote
527 ;; shell, tidy it:
528 (tramp-cleanup-connection
529 (tramp-dissect-file-name default-directory 'noexpand)
530 'keep-debug 'keep-password))
531 ;; (cd default-directory) will connect if remote:
532 (when is-remote
533 (message "Connecting to %s" default-directory))
534 (condition-case err
535 (cd default-directory)
536 (error
537 ;; Aargh. Need to isolate this tramp bug.
538 (when (and (stringp (cadr err))
539 (string-equal (cadr err)
540 "Selecting deleted buffer"))
541 (signal (car err)
542 (list
543 (format "%s, %s (\"%s\")"
544 "Tramp shell can fail on empty (homedir) path"
545 "please try again with an explicit path"
546 (cadr err)))))))
547 (setq buffer (set-buffer (apply 'make-comint
548 (multishell-unbracket-asterisks buffer-name)
549 prog
550 (if (file-exists-p startfile)
551 startfile)
552 (if (and xargs-name
553 (boundp xargs-name))
554 (symbol-value xargs-name)
555 '("-i")))))
556 (shell-mode)))
557
558 (defun multishell-track-dirchange (name newpath)
559 "Change multishell history entry to track current directory."
560 (let* ((entries (multishell-history-entries name)))
561 (dolist (entry entries)
562 (let* ((name-path (multishell-split-entry-name-and-tramp entry))
563 (name (car name-path))
564 (path (cadr name-path)))
565 (when path
566 (let* ((is-remote (file-remote-p path))
567 (vec (and is-remote (tramp-dissect-file-name path nil)))
568 (localname (if is-remote
569 (tramp-file-name-localname vec)
570 path))
571 (newlocalname
572 (replace-regexp-in-string (if (string= localname "")
573 "$"
574 (regexp-quote localname))
575 ;; REP
576 newpath
577 ;; STRING
578 localname
579 ;; FIXEDCASE
580 t
581 ;; LITERAL
582 t
583 ))
584 (newpath (if is-remote
585 (tramp-make-tramp-file-name (aref vec 0)
586 (aref vec 1)
587 (aref vec 2)
588 newlocalname
589 (aref vec 4))
590 newlocalname))
591 (newentry (concat name newpath))
592 (membership (member entry multishell-history)))
593 (when membership
594 (setcar membership newentry))))))))
595 (defvar multishell-was-default-directory ()
596 "Provide for tracking directory changes.")
597 (make-variable-buffer-local 'multishell-was-default-directory)
598 (defun multishell-post-command-business ()
599 "Do multishell bookkeeping."
600 ;; Update multishell-history with dir changes.
601 (condition-case err
602 (when (and multishell-history-entry-tracks-current-directory
603 (derived-mode-p 'shell-mode))
604 (let ((curdir (if (file-remote-p default-directory)
605 (tramp-file-name-localname
606 (tramp-dissect-file-name default-directory))
607 default-directory)))
608 (when (and multishell-was-default-directory
609 (not (string= curdir multishell-was-default-directory)))
610 (multishell-track-dirchange (multishell-unbracket-asterisks
611 (buffer-name))
612 curdir))
613 (setq multishell-was-default-directory curdir)))
614 ;; To avoid disruption as a pervasive hook function, swallow all errors:
615 (error nil)))
616 (add-hook 'post-command-hook 'multishell-post-command-business)
617
618 (defun multishell-split-entry-name-and-tramp (entry)
619 "Given multishell name/path ENTRY, return the separated name and path pair.
620
621 Returns nil for empty parts, rather than the empty string."
622 (string-match "^\\([^/]*\\)\\(/?.*\\)?" entry)
623 (let ((name (match-string 1 entry))
624 (path (match-string 2 entry)))
625 (and (string= name "") (setq name nil))
626 (and (string= path "") (setq path nil))
627 (list name path)))
628
629 (provide 'multishell)
630
631 ;;; multishell.el ends here