all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Lisp code to expand /~ and // but not env vars?
@ 2005-10-02 22:51 Drew Adams
  2005-10-02 23:16 ` Lennart Borgman
  2005-10-03 21:07 ` Drew Adams
  0 siblings, 2 replies; 8+ messages in thread
From: Drew Adams @ 2005-10-02 22:51 UTC (permalink / raw)


I'm looking for Lisp code that will expand /~ and // in a file name, just as
`substitute-in-file-name' does, but without substituting environment
variables.  I want to rationalize a user-input file name, which might
contain /~ and //, but I only want to expand env vars (recursively) in a
separate, later step (e.g. with `substitute-in-file-name').

Can anyone suggest a way to do this /~ and // conversion in Lisp?

Context: On Windows, `substitute-in-file-name' also changes \ to /, and
that's fine, inside env vars, but I don't want this to be done at the top
user-input level. Instead, I want to treat the user input as a regexp (with
normal regexp interpretation of backslash), and only afterward use
`substitute-in-file-name' to recursively expand the env vars. IOW, I don't
want to change \ to / at the top level; I just want to expand /~ and // at
the top level (and not \~ and \\, even on Windows).

It looks like the only existing code to do the /~ and // conversion is C
code (C function `search_embedded_absfilename') that is embedded as part of
the definition of `substitute-in-file-name'. I'm looking for a way to do
(only) that in Lisp.  Thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Lisp code to expand /~ and // but not env vars?
  2005-10-02 22:51 Drew Adams
@ 2005-10-02 23:16 ` Lennart Borgman
  2005-10-03  0:03   ` Drew Adams
  2005-10-03 21:07 ` Drew Adams
  1 sibling, 1 reply; 8+ messages in thread
From: Lennart Borgman @ 2005-10-02 23:16 UTC (permalink / raw)
  Cc: Help-Gnu-Emacs

Drew Adams wrote:

>I'm looking for Lisp code that will expand /~ and // in a file name, just as
>
>  
>
Not quite what you are looking for, but maybe you can use 
(expand-file-name "" "~/")?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: Lisp code to expand /~ and // but not env vars?
  2005-10-02 23:16 ` Lennart Borgman
@ 2005-10-03  0:03   ` Drew Adams
  2005-10-03 10:50     ` Peter Dyballa
       [not found]     ` <mailman.9543.1128345398.20277.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 8+ messages in thread
From: Drew Adams @ 2005-10-03  0:03 UTC (permalink / raw)


    >I'm looking for Lisp code that will expand /~ and // in a file
    name, just as

    Not quite what you are looking for, but maybe you can use
    (expand-file-name "" "~/")?

Thanks Lennart, but no, that's not it. I need to deal with an arbitrary
input file name, and an arbitrary default directory. Function
`expand-file-name' does not replace "//" and "/~" as
`substitute-in-file-name' does.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Lisp code to expand /~ and // but not env vars?
  2005-10-03  0:03   ` Drew Adams
@ 2005-10-03 10:50     ` Peter Dyballa
  2005-10-03 16:34       ` Lennart Borgman
       [not found]     ` <mailman.9543.1128345398.20277.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 8+ messages in thread
From: Peter Dyballa @ 2005-10-03 10:50 UTC (permalink / raw)
  Cc: Help-Gnu-Emacs


Am 03.10.2005 um 02:03 schrieb Drew Adams:

> Function `expand-file-name' does not replace "//" and "/~" as 
> `substitute-in-file-name' does.
>

// is in UNIX nonsense. The root is / and does not get more root when 
written as '//' -- this only has in ancient (Apollo) Domain OS a 
meaning (Domain OS could create ad-hoc networks and // was the root of 
the individual members in the network). '//' is created as a text in 
mini-buffer when you either try to find a file or try to dired. The 
right means to handle such strings would be to substitute everything 
from the beginning to // with /.

'/~' probably in every OS is nonsense. / is the root; ~ is, when 
followed by a /, my home directory; ~, when followed by a user's login 
name, means that user's home directory. The sequence '/~' happens to 
appear in mini-buffer when you either try to find a file or try to 
dired. The right means to handle such strings would be to substitute 
everything from the beginning to /~ with ~.


The routines in dired or find-file that handle such 'input' handle it 
already right.

--
Greetings

   Pete

There's no sense in being precise when you don't
even know what you're talking about.
         -- John von Neumann

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Lisp code to expand /~ and // but not env vars?
       [not found]     ` <mailman.9543.1128345398.20277.help-gnu-emacs@gnu.org>
@ 2005-10-03 14:55       ` Mathias Dahl
  0 siblings, 0 replies; 8+ messages in thread
From: Mathias Dahl @ 2005-10-03 14:55 UTC (permalink / raw)


Peter Dyballa <Peter_Dyballa@Web.DE> writes:

> // is in UNIX nonsense. The root is / and does not get more root when
> written as '//' -- this only has in ancient (Apollo) Domain OS a
> meaning (Domain OS could create ad-hoc networks and // was the root of
> the individual members in the network). '//' is created as a text in
> mini-buffer when you either try to find a file or try to dired. The
> right means to handle such strings would be to substitute everything
> from the beginning to // with /.

//server/share/file is a valid path to a file on Emacs running under
MS Windows.

/Mathias

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Lisp code to expand /~ and // but not env vars?
  2005-10-03 10:50     ` Peter Dyballa
@ 2005-10-03 16:34       ` Lennart Borgman
  0 siblings, 0 replies; 8+ messages in thread
From: Lennart Borgman @ 2005-10-03 16:34 UTC (permalink / raw)
  Cc: Help-Gnu-Emacs

Peter Dyballa wrote:

>> Function `expand-file-name' does not replace "//" and "/~" as 
>> `substitute-in-file-name' does.
>>
>
> // is in UNIX nonsense. The root is / and does not get more root when 
> written as '//' -- this only has in ancient (Apollo) Domain OS a 
> meaning (Domain OS could create ad-hoc networks and // was the root of 
> the individual members in the network). '//' is created as a text in 
> mini-buffer when you either try to find a file or try to dired. The 
> right means to handle such strings would be to substitute everything 
> from the beginning to // with /.

Sorry, but no! This is legal in a path like //host/path/path/file.ext on 
MS Windows.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Lisp code to expand /~ and // but not env vars?
       [not found] <mailman.9471.1128294372.20277.help-gnu-emacs@gnu.org>
@ 2005-10-03 20:40 ` Thien-Thi Nguyen
  0 siblings, 0 replies; 8+ messages in thread
From: Thien-Thi Nguyen @ 2005-10-03 20:40 UTC (permalink / raw)


"Drew Adams" <drew.adams@oracle.com> writes:

> Can anyone suggest a way to do this /~ and // conversion in Lisp?

double the dollar signs in the arg to `substitute-in-file-name'.
something like:

given-input => "def/~/abc/$HOME"

(double-dollar-signs given-input) => "def/~/abc/$$HOME"

(substitute-in-file-name 
  (double-dollar-signs given-input)) => "~/abc/$HOME"

you can write `double-dollar-signs' in various ways...

thi

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: Lisp code to expand /~ and // but not env vars?
  2005-10-02 22:51 Drew Adams
  2005-10-02 23:16 ` Lennart Borgman
@ 2005-10-03 21:07 ` Drew Adams
  1 sibling, 0 replies; 8+ messages in thread
From: Drew Adams @ 2005-10-03 21:07 UTC (permalink / raw)


    I'm looking for Lisp code that will expand /~ and // in a file
    name, just as
    `substitute-in-file-name' does, but without substituting environment
    variables.  I want to rationalize a user-input file name, which might
    contain /~ and //, but I only want to expand env vars (recursively) in a
    separate, later step (e.g. with `substitute-in-file-name').

Thanks to all who replied. My requirements statement wasn't very good, and I
actually figured out a different way to solve my problem.

FWIW, I meant // or /~ anywhere in an Emacs input file-name, not as the only
input. These are treated specially by substitute-in-file-name, to remove
everything up to and including these, and putting the rest into the root
directory or a home directory, respectively.

Anyway, it turned out that I need to do the regexp matching after this kind
of substitution, but also I want backslash to work for regexps, and not be
interpreted as a directory separator (on Windows). Since I need to
regexp-match after substitute-in-file-name substitution, the solution I
chose was just to fool substitute-in-file-name by replacing any backslashes
with another character (C-g), and then putting them back after
substitute-in-file-name is done.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2005-10-03 21:07 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.9471.1128294372.20277.help-gnu-emacs@gnu.org>
2005-10-03 20:40 ` Lisp code to expand /~ and // but not env vars? Thien-Thi Nguyen
2005-10-02 22:51 Drew Adams
2005-10-02 23:16 ` Lennart Borgman
2005-10-03  0:03   ` Drew Adams
2005-10-03 10:50     ` Peter Dyballa
2005-10-03 16:34       ` Lennart Borgman
     [not found]     ` <mailman.9543.1128345398.20277.help-gnu-emacs@gnu.org>
2005-10-03 14:55       ` Mathias Dahl
2005-10-03 21:07 ` Drew Adams

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.