unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Feature Request: Function to quote filenames
@ 2015-06-24 15:26 raman
  2015-06-24 15:34 ` Andreas Schwab
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: raman @ 2015-06-24 15:26 UTC (permalink / raw)
  To: emacs-devel

Feature Request:

Motivated by the  increasing number of filenames that show up with spc,
"'"  and other punctuation characters in their name.

The only helper function Emacs provides today is shell-quote-argument --
which often doesn't do the trick.

As an example: Given the filename:

Alice's Adventures in Wonderland

(setq f (shell-quote-argument "Alice's Adventures in Wonderland"))
returns 
"Alice\\'s\\ Adventures\\ in\\ Wonderland"

 But invocations like 
(shell-command (format "ls %s" f))

 throw an error 

it's never obvious what quoting magic to  use to get all the cases
right.

Would be nice if we had a shell-quote-filename elisp function that did
all of the magic quoting.


-- 



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

* Re: Feature Request: Function to quote filenames
  2015-06-24 15:26 Feature Request: Function to quote filenames raman
@ 2015-06-24 15:34 ` Andreas Schwab
  2015-06-24 15:34 ` Nicolas Richard
  2015-06-24 15:53 ` Eli Zaretskii
  2 siblings, 0 replies; 7+ messages in thread
From: Andreas Schwab @ 2015-06-24 15:34 UTC (permalink / raw)
  To: raman; +Cc: emacs-devel

raman <raman@google.com> writes:

> As an example: Given the filename:
>
> Alice's Adventures in Wonderland
>
> (setq f (shell-quote-argument "Alice's Adventures in Wonderland"))
> returns 
> "Alice\\'s\\ Adventures\\ in\\ Wonderland"
>
>  But invocations like 
> (shell-command (format "ls %s" f))
>
>  throw an error 

Which error does it throw?

ELISP> (shell-command (format "ls %s" (shell-quote-argument "Alice's Adventures in Wonderland")))
2 (#o2, #x2, ?\C-b)

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



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

* Re: Feature Request: Function to quote filenames
  2015-06-24 15:26 Feature Request: Function to quote filenames raman
  2015-06-24 15:34 ` Andreas Schwab
@ 2015-06-24 15:34 ` Nicolas Richard
  2015-06-24 16:50   ` T.V Raman
  2015-06-24 15:53 ` Eli Zaretskii
  2 siblings, 1 reply; 7+ messages in thread
From: Nicolas Richard @ 2015-06-24 15:34 UTC (permalink / raw)
  To: raman; +Cc: emacs-devel

Hi,

raman <raman@google.com> writes:
> (setq f (shell-quote-argument "Alice's Adventures in Wonderland"))
> returns 
> "Alice\\'s\\ Adventures\\ in\\ Wonderland"
>
>  But invocations like 
> (shell-command (format "ls %s" f))
>
>  throw an error 

It works for me after saying
    touch "Alice's Adventures in Wonderland"
in a shell. What error do you get ?

> Would be nice if we had a shell-quote-filename elisp function that did
> all of the magic quoting.

If the aim is to quote for the shell, shell-quote-argument always did
the job for me.

-- 
Nico.



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

* Re: Feature Request: Function to quote filenames
  2015-06-24 15:26 Feature Request: Function to quote filenames raman
  2015-06-24 15:34 ` Andreas Schwab
  2015-06-24 15:34 ` Nicolas Richard
@ 2015-06-24 15:53 ` Eli Zaretskii
  2 siblings, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2015-06-24 15:53 UTC (permalink / raw)
  To: raman; +Cc: emacs-devel

> From: raman <raman@google.com>
> Date: Wed, 24 Jun 2015 08:26:52 -0700
> 
> Motivated by the  increasing number of filenames that show up with spc,
> "'"  and other punctuation characters in their name.
> 
> The only helper function Emacs provides today is shell-quote-argument --
> which often doesn't do the trick.
> 
> As an example: Given the filename:
> 
> Alice's Adventures in Wonderland
> 
> (setq f (shell-quote-argument "Alice's Adventures in Wonderland"))
> returns 
> "Alice\\'s\\ Adventures\\ in\\ Wonderland"
> 
>  But invocations like 
> (shell-command (format "ls %s" f))
> 
>  throw an error 

It does?  What error?  I see no error, just a return value meaning
there's no such file.

> it's never obvious what quoting magic to  use to get all the cases
> right.
> 
> Would be nice if we had a shell-quote-filename elisp function that did
> all of the magic quoting.

The magic, if there is one, depends on the application, because only
the application knows the semantics of the file-name argument for the
program to be invoked.  So I don't see how a general-purpose utility
function could solve the problem.  Unless I misunderstand the problem
you have.



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

* Re: Feature Request: Function to quote filenames
  2015-06-24 15:34 ` Nicolas Richard
@ 2015-06-24 16:50   ` T.V Raman
  2015-06-24 18:53     ` Stefan Monnier
  0 siblings, 1 reply; 7+ messages in thread
From: T.V Raman @ 2015-06-24 16:50 UTC (permalink / raw)
  To: youngfrog; +Cc: emacs-devel, raman

interesting, it worked for me just now -- not sure why I hit an error
when I last tried. I likely did somethign else that messed it up -- --
but in general, I've had trouble with quoting arguments from elisp to
the shell.
-- 

-- 



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

* Re: Feature Request: Function to quote filenames
  2015-06-24 16:50   ` T.V Raman
@ 2015-06-24 18:53     ` Stefan Monnier
  2015-06-24 20:24       ` T.V Raman
  0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2015-06-24 18:53 UTC (permalink / raw)
  To: T.V Raman; +Cc: youngfrog, emacs-devel

> interesting, it worked for me just now -- not sure why I hit an error
> when I last tried. I likely did somethign else that messed it up -- --
> but in general, I've had trouble with quoting arguments from elisp to
> the shell.

Quoting is tricky business, and it's easy to mess it up. But details
matter, and in most cases the problem is not that shell-quote-argument
doesn't work right, but that it's not called on the right data, or it's
not called at all, or the result is then later massaged incorrectly,
etc...
Once you have a concrete problem case, file a bug report.


        Stefan



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

* Re: Feature Request: Function to quote filenames
  2015-06-24 18:53     ` Stefan Monnier
@ 2015-06-24 20:24       ` T.V Raman
  0 siblings, 0 replies; 7+ messages in thread
From: T.V Raman @ 2015-06-24 20:24 UTC (permalink / raw)
  To: monnier; +Cc: emacs-devel, youngfrog, raman

Thanks Stefan -- In this instance, I went back and looked in the
buffer on my laptop where I hit the error -- like you said I had used
the result from shell-quote-argument  incorrectly -- had used
"... '%s'" and  the "'%s'" was the cause of the breakage.

Stefan Monnier writes:
 > > interesting, it worked for me just now -- not sure why I hit an error
 > > when I last tried. I likely did somethign else that messed it up -- --
 > > but in general, I've had trouble with quoting arguments from elisp to
 > > the shell.
 > 
 > Quoting is tricky business, and it's easy to mess it up. But details
 > matter, and in most cases the problem is not that shell-quote-argument
 > doesn't work right, but that it's not called on the right data, or it's
 > not called at all, or the result is then later massaged incorrectly,
 > etc...
 > Once you have a concrete problem case, file a bug report.
 > 
 > 
 >         Stefan

-- 

-- 



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

end of thread, other threads:[~2015-06-24 20:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-24 15:26 Feature Request: Function to quote filenames raman
2015-06-24 15:34 ` Andreas Schwab
2015-06-24 15:34 ` Nicolas Richard
2015-06-24 16:50   ` T.V Raman
2015-06-24 18:53     ` Stefan Monnier
2015-06-24 20:24       ` T.V Raman
2015-06-24 15:53 ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).