Function: eshell-electric-forward-slash
eshell-electric-forward-slash is a byte-compiled function defined in
em-elecslash.el.gz.
Signature
(eshell-electric-forward-slash)
Documentation
Implementation of electric forward slash in remote Eshells.
Initializing the eshell-elecslash module adds this function to
post-self-insert-hook. Typing / or ~/ as the first character
of a command line argument automatically inserts the Tramp prefix
in the case that default-directory is remote and the command is
a Lisp function. Typing a second forward slash undoes the
insertion.
Source Code
;; Defined in /usr/src/emacs/lisp/eshell/em-elecslash.el.gz
(defun eshell-electric-forward-slash ()
"Implementation of electric forward slash in remote Eshells.
Initializing the `eshell-elecslash' module adds this function to
`post-self-insert-hook'. Typing / or ~/ as the first character
of a command line argument automatically inserts the Tramp prefix
in the case that `default-directory' is remote and the command is
a Lisp function. Typing a second forward slash undoes the
insertion."
(when (eq ?/ (char-before))
(delete-char -1)
(let ((tilde-before (eq ?~ (char-before)))
(command (save-excursion
(eshell-bol)
(skip-syntax-forward " ")
(thing-at-point 'sexp)))
(prefix (file-remote-p default-directory)))
(if (and prefix
;; We can't formally parse the input. But if there is
;; one of these operators behind us, then looking at
;; the first command would not be sensible. So be
;; conservative: don't insert the Tramp prefix if there
;; are any of these operators behind us.
(not (looking-back (regexp-opt '("&&" "|" ";"))
eshell-last-output-end))
(or (= (point) eshell-last-output-end)
(and tilde-before
(= (1- (point)) eshell-last-output-end))
(and (or tilde-before
(eq ?\s (char-syntax (char-before))))
(or (eshell-find-alias-function command)
(and (fboundp (intern-soft command))
(or eshell-prefer-lisp-functions
(not (eshell-search-path command))))))))
(let ((map (make-sparse-keymap))
(start (if tilde-before (1- (point)) (point))))
(when tilde-before (delete-char -1))
(insert prefix)
(unless tilde-before (insert "/"))
;; Typing a second slash undoes the insertion, for when
;; you really do want to type a local absolute file name.
(define-key map "/" (lambda ()
(interactive)
(delete-region start (point))
(insert (if tilde-before "~/" "/"))))
(set-transient-map map))
(insert "/")))))