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