From 0a4fb38555646226dc45ed6c86e3bae2d108bf6b Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Fri, 5 Nov 2021 20:11:04 -0700 Subject: [PATCH 3/3] Abbreviate home directory for remote files * lisp/files.el (abbreviate-file-name): Support homedir abbreviation of remote files. --- lisp/files.el | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lisp/files.el b/lisp/files.el index 94b78df40c..aa230dc0c6 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -2001,8 +2001,9 @@ abbreviate-file-name home directory is a root directory)." (save-match-data ;FIXME: Why? ;; Avoid treating /home/foo as /home/Foo during `~' substitution. - (let ((case-fold-search (file-name-case-insensitive-p filename)) - (home-dir (expand-file-name "~"))) + (let* ((case-fold-search (file-name-case-insensitive-p filename)) + (remote-host (file-remote-p filename)) + (home-dir (expand-file-name (concat remote-host "~")))) ;; If any elt of directory-abbrev-alist matches this name, ;; abbreviate accordingly. (dolist (dir-abbrev directory-abbrev-alist) @@ -2039,13 +2040,13 @@ abbreviate-file-name (mb1 (match-beginning 1)) ((and ;; If the home dir is just /, don't change it. - (not (and (= (match-end 0) 1) - (= (aref filename 0) ?/))) + (not (and (= (match-end 0) (1+ (length remote-host))) + (= (aref filename (length remote-host)) ?/))) ;; MS-DOS root directories can come with a drive letter; ;; Novell Netware allows drive letters beyond `Z:'. (not (and (memq system-type '(ms-dos windows-nt cygwin)) (string-match "\\`[a-zA-`]:/\\'" filename)))))) - (concat "~" (substring filename mb1)) + (concat remote-host "~" (substring filename mb1)) filename)))) (defun find-buffer-visiting (filename &optional predicate) -- 2.25.1