all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jim Porter <jporterbugs@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Daniel Mendler <mail@daniel-mendler.de>, 54001@debbugs.gnu.org
Subject: bug#54001: 29.0.50; abbreviate-file-name has side-effects
Date: Mon, 14 Feb 2022 13:38:58 -0800	[thread overview]
Message-ID: <e00f81a3-91f8-3c52-c95c-b6cf2c2a5db6@gmail.com> (raw)
In-Reply-To: <jwv1r05xixs.fsf-monnier+emacs@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 961 bytes --]

On 2/14/2022 1:00 PM, Stefan Monnier via Bug reports for GNU Emacs, the 
Swiss army knife of text editors wrote:
>> Looking at my original patch again, this value is already cached as a Tramp
>> connection property named "home-directory". If the code were changed to set
>> that connection property in a more-appropriate place, and
>> `tramp-handle-abbreviate-file-name' simply *reads* that connection property,
>> then I think that should resolve this issue.
> 
> Sounds like it,

I've only lightly tested this patch, but I think it should resolve the 
issue. It only sets the "home-directory" connection property when a 
connection is already established. Otherwise, it just uses the cached 
value (if any).

Maybe there's a cleaner way to do this though; opportunistically setting 
a connection property like this seems like something there might be a 
special function for in Tramp, but I didn't see one after a bit of 
looking so this is what I went with.

[-- Attachment #2: 0001-Don-t-attempt-to-connect-to-a-remote-server-during-a.patch --]
[-- Type: text/plain, Size: 2206 bytes --]

From f66dcbdbcd26ad97423e37034508a32f55263597 Mon Sep 17 00:00:00 2001
From: Jim Porter <jporterbugs@gmail.com>
Date: Mon, 14 Feb 2022 13:16:05 -0800
Subject: [PATCH] Don't attempt to connect to a remote server during
 'abbreviate-file-name'

* lisp/net/tramp.el (tramp-handle-abbreviate-file-name): Only use the
"home-directory" when a connection has been established.
---
 lisp/net/tramp.el | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 32712efb3e..3c06ad1630 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -3343,16 +3343,24 @@ tramp-handle-abbreviate-file-name
   (let* ((case-fold-search (file-name-case-insensitive-p filename))
 	 (vec (tramp-dissect-file-name filename))
          (home-dir
-          (with-tramp-connection-property vec "home-directory"
-            (tramp-compat-funcall
-	     'directory-abbrev-apply
-	     (expand-file-name (tramp-make-tramp-file-name vec "~"))))))
+          (if (let ((non-essential t)) (tramp-connectable-p vec))
+              ;; If a connection has already been established, make
+              ;; sure the "home-directory" connection property is
+              ;; properly set.
+              (with-tramp-connection-property vec "home-directory"
+                (tramp-compat-funcall
+	         'directory-abbrev-apply
+	         (expand-file-name (tramp-make-tramp-file-name vec "~"))))
+            ;; Otherwise, just use the cached value.
+            (tramp-get-connection-property vec "home-directory" nil))))
     ;; If any elt of `directory-abbrev-alist' matches this name,
     ;; abbreviate accordingly.
     (setq filename (tramp-compat-funcall 'directory-abbrev-apply filename))
     ;; Abbreviate home directory.
-    (if (string-match
-	 (tramp-compat-funcall 'directory-abbrev-make-regexp home-dir) filename)
+    (if (and home-dir
+             (string-match
+	      (tramp-compat-funcall 'directory-abbrev-make-regexp home-dir)
+              filename))
         (tramp-make-tramp-file-name
 	 vec (concat "~" (substring filename (match-beginning 1))))
       (tramp-make-tramp-file-name (tramp-dissect-file-name filename)))))
-- 
2.25.1


  reply	other threads:[~2022-02-14 21:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-14 17:19 bug#54001: 29.0.50; abbreviate-file-name has side-effects Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-14 17:52 ` Jim Porter
2022-02-14 19:48   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-14 20:52     ` Jim Porter
2022-02-14 21:00       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-14 21:38         ` Jim Porter [this message]
2022-02-14 21:51           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-15  8:52             ` Michael Albinus
2022-02-15 13:11           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-15 13:26             ` Daniel Mendler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e00f81a3-91f8-3c52-c95c-b6cf2c2a5db6@gmail.com \
    --to=jporterbugs@gmail.com \
    --cc=54001@debbugs.gnu.org \
    --cc=mail@daniel-mendler.de \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.