emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Emacs syntax for filenames to mean "absolute location on the current


From: Michael Albinus
Subject: Re: Emacs syntax for filenames to mean "absolute location on the current remote host"?
Date: Thu, 31 Aug 2023 15:58:01 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

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 via email to

[Prev in Thread] Current Thread [Next in Thread]