(throw 'eshell-replace-command
(eshell-parse-command "cd" (flatten-tree args)))))
-(defun eshell-expand-user-reference-1 (file)
+(defun eshell-expand-user-reference (file)
"Expand a user reference in FILE to its real directory name."
(replace-regexp-in-string
(rx bos (group "~" (*? anychar)) (or "/" eos))
#'expand-file-name file))
-(defun eshell-expand-user-reference (file)
- "Expand a user reference in FILE to its real directory name.
-FILE can be either a string or a list of strings to expand."
- ;; If the argument was a glob pattern, then FILE is a list, so
- ;; expand each element of the glob's resulting list.
- (if (listp file)
- (mapcar #'eshell-expand-user-reference-1 file)
- (eshell-expand-user-reference-1 file)))
-
(defun eshell-parse-user-reference ()
"An argument beginning with ~ is a filename to be expanded."
(when (and (not eshell-current-argument)
(eq (char-after) ?~))
- (add-to-list 'eshell-current-modifiers #'eshell-expand-user-reference)
+ ;; Apply this modifier fairly early so it happens before things
+ ;; like glob expansion.
+ (add-hook 'eshell-current-modifiers #'eshell-expand-user-reference -50)
(forward-char)
(char-to-string (char-before))))
(defun eshell-add-glob-modifier ()
"Add `eshell-extended-glob' to the argument modifier list."
(when eshell-glob-splice-results
- (add-to-list 'eshell-current-modifiers 'eshell-splice-args t))
- (add-to-list 'eshell-current-modifiers 'eshell-extended-glob))
+ (add-hook 'eshell-current-modifiers #'eshell-splice-args 99))
+ (add-hook 'eshell-current-modifiers #'eshell-extended-glob))
(defun eshell-parse-glob-chars ()
"Parse a globbing delimiter.
(preds (car modifiers))
(mods (cdr modifiers)))
(when (or preds mods)
- ;; Has to go at the end, which is only natural since
+ ;; Has to go near the end (but before
+ ;; `eshell-splice-args'), which is only natural since
;; syntactically it can only occur at the end.
- (setq eshell-current-modifiers
- (append
- eshell-current-modifiers
- (list
- (lambda (lst)
- (eshell-apply-modifiers
- lst preds mods modifier-string)))))
- (when (memq 'eshell-splice-args eshell-current-modifiers)
- ;; If splicing results, ensure that
- ;; `eshell-splice-args' is the last modifier.
- ;; Eshell's command parsing can't handle it anywhere
- ;; else.
- (setq eshell-current-modifiers
- (append (delq 'eshell-splice-args
- eshell-current-modifiers)
- (list 'eshell-splice-args)))))))
+ (add-hook 'eshell-current-modifiers
+ (lambda (lst)
+ (eshell-apply-modifiers
+ lst preds mods modifier-string))
+ 90))))
(goto-char (1+ end))
(eshell-finish-arg))))))