- (let* ((got (assoc name multishell-name-to-path-history))
- becomes
- (return (list got becomes)))
- (cond ((or (not path)(string= path ""))
- ;; Remove entry, if present:
- (if got
- (setq multishell-name-to-path-history
- (delete got multishell-name-to-path-history))))
- (got
- ;; Replace the path of the existing entry, and move to the front:
- (setq becomes (cons (car got) path)
- multishell-name-to-path-history
- (cons becomes (remove got multishell-name-to-path-history)))
- (setq return (list got becomes)))
- ;; Add a new entry, at the front:
- (t (setq becomes (cons name path)
- return (list got becomes)
- multishell-name-to-path-history
- (cons becomes multishell-name-to-path-history))))
- return))
+ (let* ((entry (multishell-name-entry name))
+ (becomes (concat name path)))
+ ;; Promote to the front, tracking path changes in the process:
+ (setq multishell-history (delete entry multishell-history))
+ (if (string= path "")
+ (push entry multishell-history)
+ (push becomes multishell-history))))
+
+(defun multishell-name-entry (name)
+ "Return `multishell-history' entry that starts with NAME, or nil if none."
+ (let ((match-expr (concat "^" name "\\\(/.*$\\\)?")))
+ (dolist (entry multishell-history)
+ (when (string-match match-expr entry)
+ (return entry)))))