-(defun multishell-derive-target-name-and-path (path-ish)
- "Give tramp-style PATH-ISH, determine target name and default directory.
-
-The name is the part of the string before the initial '/' slash,
-if any. Otherwise, it's either the host-name, domain-name, final
-directory name, or local host name. The path is everything
-besides the string before the initial '/' slash.
-
-Return them as a list (name dir), with dir nil if none given."
- (let (name (path "") dir)
- (cond ((string= path-ish "") (setq dir multishell-primary-name))
- ((string-match "^\\*\\([^/]*\\)\\(/.*\\)\\*" path-ish)
- ;; We have a path, use it
- (let ((overt-name (match-string 1 path-ish)))
- (setq path (match-string 2 path-ish))
- (if (string= overt-name "") (setq overt-name nil))
- (if (string= path "") (setq path nil))
- (setq name
- (multishell-bracket-asterisks
- (or overt-name
- (if (file-remote-p path)
- (let ((vec (tramp-dissect-file-name path)))
- (or (tramp-file-name-host vec)
- (tramp-file-name-domain vec)
- (tramp-file-name-localname vec)
- system-name))
- (multishell-unbracket-asterisks
- multishell-primary-name)))))))
- (t (setq name (multishell-bracket-asterisks path-ish))))
- (list name path)))
+(defun multishell-resolve-target-name-and-path (path-ish)
+ "Given name/tramp-path PATH-ISH, resolve buffer name and initial directory.
+
+The name is the part of the string up to the first '/' slash, if
+any. Missing pieces are filled in from remote path elements, if
+any, and multishell history. Given a path and no name, either the
+host-name, domain-name, final directory name, or local host name
+is used.
+
+Return them as a list (name path), with name asterisk-bracketed
+and path nil if none resolved."
+ (let* ((splat (multishell-split-entry path-ish))
+ (name (car splat))
+ (path (cadr splat)))
+ (if path
+ (if (not name)
+ (setq name
+ (if (file-remote-p path)
+ (let ((vec (tramp-dissect-file-name path)))
+ (or (tramp-file-name-host vec)
+ (tramp-file-name-domain vec)
+ (tramp-file-name-localname vec)
+ system-name))
+ multishell-primary-name)))
+ ;; No path - get one from history, if present.
+ (when (not name)
+ (setq name multishell-primary-name))
+ (mapcar #'(lambda (entry)
+ (when (or (not path) (string= path ""))
+ (setq path (cadr (multishell-split-entry entry)))))
+ (multishell-history-entries
+ (multishell-unbracket-asterisks name))))
+ (list (multishell-bracket-asterisks name) path)))