emacs-devel
[Top][All Lists]
Advanced

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

Re: info inconsistency about "Shell Commands in Dired"


From: Masatake YAMATO
Subject: Re: info inconsistency about "Shell Commands in Dired"
Date: Sun, 22 Aug 2004 23:00:16 +0900 (JST)

> > > > How do you think using `format' function directly instead of `?' ?
> > > > 
> > > > e.g.
> > > > 
> > > >         uuencode %s %s > %s.uu
> > > > 
> > > > Advantage:
> > > > - If the user want to `%' itself in the command line, format function
> > > >   can handle it:
> > > > 
> > > >       echo %%s
> > > > 
> > > > - Implementation is not so difficult(for us).
> > > 
> > > Not?  How do you call the format function?  Depends on the number of
> > > %s...
> > 
> > Good point.
> > I found next code works.
> > 
> >     (apply 'format "echo %s" '("a" "a" "a"))
> >     => "echo a"
> > 
> > So we can pass arguments as much as possible:-P.
> 
> As much as possible?
> (apply 'format "echo %s %s %s %s" '#1=("a" . #1#))
> 
> Just turns out that apply is not too happy about passing infinitely
> long argument lists on.

Sorry. "as much as possible" is wrong expression.

What I'd like to say is:

(defun count-%s (string)
  (let ((count 0)
        (pos 0))
    (while (string-match "%s" string pos)
      (setq pos (match-end 0))
      (setq count (1+ count)))
    count))

(let ((cmdline "echo %s %s %s %s")
      (filenanme "a"))
   (apply 'format cmdline (make-list (count-%s cmdline) filenanme)))
=> "echo a a a a"

However, we don't have to take care about "%%s".
Even if %%s is appeared on the `cmdline', we can count it as one.
Giving the `filename' as arguments for `format' more than necessary is
ok.

(let ((cmdline "echo %%s %%s %%s %s")
      (filenanme "a"))
   (apply 'format cmdline (make-list (count-%s cmdline) filenanme)))
=> "echo %s %s %s a"

Anyway, I think using an environment varaible method I wrote in 
another mail is better than this method.




reply via email to

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