all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michael Albinus <michael.albinus@gmx.de>
To: Jim Porter <jporterbugs@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Emacs syntax for filenames to mean "absolute location on the current remote host"?
Date: Thu, 31 Aug 2023 15:58:01 +0200	[thread overview]
Message-ID: <87o7injouu.fsf@gmx.de> (raw)
In-Reply-To: <3ba84988-49d4-1a9f-471b-0436658c6ee2@gmail.com> (Jim Porter's message of "Tue, 29 Aug 2023 22:07:37 -0700")

Jim Porter <jporterbugs@gmail.com> writes:

Hi Jim,

>> What if you declare, that in Eshell an absolute file name "/foo/bar" is
>> always on "host"? Then it doesn't matter, whether a user writes "cd /foo/bar"
>> or "*cd /foo/bar". This would cover most use cases in Eshell, and it is
>> simpler to type than "cd /.:/foo/bar".
>
> My main worry is that we only want to do this for absolute file names,
> not just things that *look* like absolute file names. For example
> "/foo/" might be a regexp instead of a directory name. We could add
> special handling for commands where we know they take file names, but
> that's laborious, and we'd never cover everything.
>
> I see a couple options:
>
> * Eshell lets you escape characters so they have their literal
>   meaning, like \$ or '$' (if you don't want to use
>   dollar-expansion). We could do the same for a leading /. That is,
>   /foo/bar (no quotes) would get automatically expanded to
>   /method:host:/foo/bar when on host. '/foo/bar' would just remain as
>  /foo/bar though.
>
> * I realized an important part of the Eshell side: we have Eshell-only
>   variables! I could define a variable that expands to
>   '(file-remote-p)'. The only question is what to call it. For
>   example, we could use $/ or $:, so a user could type $//foo/bar or
>   $:/foo/bar. I think I like $:, but I'm open to other
>   suggestions. For single-char variable names, we can use any symbol
>  except: ( ) { } [ ] < > " ' @ # $ * + - _ ?
>
> We could even do both of these, and provide a user option for
> enabling/disabling the first one. That way, with the first one
> enabled, you get something pretty close to ordinary shells. However,
> if you don't like it, you still have the latter as a more-explicit
> option. (The latter is nice too because it should be a single line of
> code to implement.)

I would let it to you.

>> In the few cases a user means the local absolute file name "/foo/bar",
>> she still can type "cd /:/foo/bar".
>
> The one edge case I'm not quite sure what to do about is: how should
> we spell "the user's home directory on localhost"? Using "/:~" *could*
> work (in that Eshell could recognize it and do the right thing), but
> it's also the way that you spell "the file named ~" elsewhere in
> Emacs. (Eshell would spell that \~ or '~'). Maybe that's not such a
> big deal though: we can just document this corner case and hope users
> don't get *too* confused.

IIUC, "~" in a file name means always the home directory when it is the
first character (of the local part in remote file names), or it comes
after a slash like in "/~". See (info "(elisp) File Name Expansion")

--8<---------------cut here---------------start------------->8---
     If the part of FILENAME before the first slash is ‘~’, it expands
     to your home directory, which is typically specified by the value
     of the ‘HOME’ environment variable (*note (emacs)General
     Variables::).  If the part before the first slash is ‘~USER’ and if
     USER is a valid login name, it expands to USER’s home directory.
     If you do not want this expansion for a relative FILENAME that
     might begin with a literal ‘~’, you can use ‘(concat
     (file-name-as-directory directory) filename)’ instead of
     ‘(expand-file-name filename directory)’.
--8<---------------cut here---------------end--------------->8---

Best regards, Michael.



  reply	other threads:[~2023-08-31 13:58 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-29  3:51 Emacs syntax for filenames to mean "absolute location on the current remote host"? Jim Porter
2023-08-29  7:30 ` Michael Albinus
2023-08-29 11:57   ` Eli Zaretskii
2023-08-30  5:07   ` Jim Porter
2023-08-31 13:58     ` Michael Albinus [this message]
2023-09-01 17:36       ` Jim Porter
2023-09-01 18:13         ` Michael Albinus
2023-09-01 18:36           ` Jim Porter
2023-09-01 19:23             ` Jim Porter
2023-09-02 11:20               ` Michael Albinus

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=87o7injouu.fsf@gmx.de \
    --to=michael.albinus@gmx.de \
    --cc=emacs-devel@gnu.org \
    --cc=jporterbugs@gmail.com \
    /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.