Function: eca--path--translate
eca--path--translate is a natively compiled function defined in
eca-util.el.
Signature
(eca--path--translate PATH FROM-FN TO-FN EXPAND-FROM-P)
Documentation
Translate PATH using explicit and TRAMP-derived path mappings.
FROM-FN extracts the side of each mapping to match against PATH; TO-FN extracts the side to substitute in. If EXPAND-FROM-P is non-nil, expand the from-side path. The longest matching prefix wins; explicit user mappings take priority over TRAMP-derived ones for equal-length prefixes.
Source Code
;; Defined in /nix/store/jklqzw6pzz6j4jrbv8wy0iwgi7jlrbld-emacs-packages-deps/share/emacs/site-lisp/elpa/eca-20260928.1827/eca-util.el
(defun eca--path--translate (path from-fn to-fn expand-from-p)
"Translate PATH using explicit and TRAMP-derived path mappings.
FROM-FN extracts the side of each mapping to match against PATH;
TO-FN extracts the side to substitute in. If EXPAND-FROM-P is
non-nil, expand the from-side path. The longest matching prefix
wins; explicit user mappings take priority over TRAMP-derived ones
for equal-length prefixes."
(let* ((ensure-slash (lambda (s) (if (string-suffix-p "/" s) s (concat s "/"))))
(strip-slash (lambda (s) (if (string-suffix-p "/" s) (substring s 0 -1) s)))
(sorted (sort (copy-sequence (eca--path-mappings))
(lambda (a b)
(let ((la (length (funcall from-fn a)))
(lb (length (funcall from-fn b))))
(if (= la lb)
(let ((explicit-a (member a eca-local-to-remote-prefix-map))
(explicit-b (member b eca-local-to-remote-prefix-map)))
(cond
((and explicit-a (not explicit-b)) t)
((and (not explicit-a) explicit-b) nil)
(t (> (length (funcall to-fn a))
(length (funcall to-fn b))))))
(> la lb)))))))
(or (seq-some
(lambda (m)
(let* ((from-raw (funcall from-fn m))
(to-raw (funcall to-fn m))
(from (funcall ensure-slash
(if (and expand-from-p (not (file-remote-p from-raw)))
(expand-file-name from-raw)
from-raw)))
(to-expanded (if (and (not expand-from-p) (not (file-remote-p to-raw)))
(expand-file-name to-raw)
to-raw)))
(cond
((string= path (funcall strip-slash from))
(funcall strip-slash to-expanded))
((string-prefix-p from path)
(concat (funcall ensure-slash to-expanded) (substring path (length from)))))))
sorted)
path)))