unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#6823: 24.0.50; Wdired or Dired enhancement
@ 2010-08-07 18:37 Drew Adams
  2010-08-09  2:59 ` Eli Zaretskii
  2010-08-09  5:50 ` Thierry Volpiatto
  0 siblings, 2 replies; 7+ messages in thread
From: Drew Adams @ 2010-08-07 18:37 UTC (permalink / raw)
  To: 6823

Emacs sorely needs one or more commands that let you rename the
marked files as a sequence (following a pattern).
 
See MS Windows for an example (but we could do better):
 
1. You sort the file list the way you want, to put the files you want to
act on in the right order.  Especially with libraries such as Francis
Wright's `dired-sort-menu.el', you can sort Dired in many different
ways.
 
2. You mark the files you want to rename.  (In Windows you select them.)
 
3. You invoke a rename command, and enter a pattern for the new names.
The pattern includes an optional starting index, which is a whole
number.  In Windows you put the index in parens, which are included in
the file names.  Example: `new name (100)'.  The marked files are named
`new name (100)', `new name (101)'...
 
Obviously, in Emacs we could provide for better patterns and
substitutions than this.  But AFAIK today we offer nothing like this.

If you have 1000 family photo files you want to rename to something like
`2010 Summer Vacation (1000)', `2010 Summer Vacation (1001)' etc. (or
even just `1000', `1001'...), then AFAIK the best you can do now is to
use Wdired and perform query-replace with some fancy replacement
expression.  We should offer something simpler for the common task of
renaming a sequence of files.

 
In GNU Emacs 24.0.50.1 (i386-mingw-nt5.1.2600)
 of 2010-08-02 on 3249CTO
Windowing system distributor `Microsoft Corp.', version 5.1.2600
configured using `configure --with-gcc (4.4) --no-opt --cflags -Ic:/xpm/include'
 






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

* bug#6823: 24.0.50; Wdired or Dired enhancement
  2010-08-07 18:37 bug#6823: 24.0.50; Wdired or Dired enhancement Drew Adams
@ 2010-08-09  2:59 ` Eli Zaretskii
  2010-08-09  6:08   ` Thierry Volpiatto
  2010-08-09 14:02   ` Drew Adams
  2010-08-09  5:50 ` Thierry Volpiatto
  1 sibling, 2 replies; 7+ messages in thread
From: Eli Zaretskii @ 2010-08-09  2:59 UTC (permalink / raw)
  To: Drew Adams; +Cc: 6823

> From: "Drew Adams" <drew.adams@oracle.com>
> Date: Sat, 7 Aug 2010 11:37:43 -0700
> Cc: 
> 
> Emacs sorely needs one or more commands that let you rename the
> marked files as a sequence (following a pattern).

Doesn't the "% R" command in Dired use query-replace under the hood?
If so, doesn't it already allow to include Lisp expressions in the
replacement that are eval'ed?





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

* bug#6823: 24.0.50; Wdired or Dired enhancement
  2010-08-07 18:37 bug#6823: 24.0.50; Wdired or Dired enhancement Drew Adams
  2010-08-09  2:59 ` Eli Zaretskii
@ 2010-08-09  5:50 ` Thierry Volpiatto
  2010-08-09 14:16   ` Drew Adams
  1 sibling, 1 reply; 7+ messages in thread
From: Thierry Volpiatto @ 2010-08-09  5:50 UTC (permalink / raw)
  To: bug-gnu-emacs

Hi Drew,

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

> Emacs sorely needs one or more commands that let you rename the
> marked files as a sequence (following a pattern).
>  
> See MS Windows for an example (but we could do better):
>  
> 1. You sort the file list the way you want, to put the files you want to
> act on in the right order.  Especially with libraries such as Francis
> Wright's `dired-sort-menu.el', you can sort Dired in many different
> ways.
>  
> 2. You mark the files you want to rename.  (In Windows you select them.)
>  
> 3. You invoke a rename command, and enter a pattern for the new names.
> The pattern includes an optional starting index, which is a whole
> number.  In Windows you put the index in parens, which are included in
> the file names.  Example: `new name (100)'.  The marked files are named
> `new name (100)', `new name (101)'...
>  
> Obviously, in Emacs we could provide for better patterns and
> substitutions than this.  But AFAIK today we offer nothing like this.
>
> If you have 1000 family photo files you want to rename to something like
> `2010 Summer Vacation (1000)', `2010 Summer Vacation (1001)' etc. (or
> even just `1000', `1001'...), then AFAIK the best you can do now is to
> use Wdired and perform query-replace with some fancy replacement
> expression.  We should offer something simpler for the common task of
> renaming a sequence of files.

We have have two tools to achieve this, wdired-change-to-wdired-mode,
and query-replace-regexp used with \, and \# in the replacement regexp.

,----
| E.g: (in dired)
| C-x C-q
| C-M-%
| ==> [A-Za-z0-9]*.jpg
| ==> 2010-summer-vaccation-\,(format "1%03d" \#).jpg
`----

You can use also this function:(You may have to run it two times in some
rare cases)

,----
| (defun serial-rename (dir ext name start)
|   "rename all the files of DIR matching regex EXT with the name NAME \
| starting to number START - ex: file01.jpg"
|   (interactive "Ddir: \nsExt(no dot): \nsName: \nnStart: ")
|   (find-file dir)
|   (let* ((ls-dir     (file-expand-wildcards (format "*.%s" ext) t))
|          (new-ls-dir (loop with len = (length ls-dir) 
|                         repeat len for count from start
|                         for fnum = (if (< start 10) "0%s" "%s")
|                         collect (concat dir name (format fnum count) "." ext))))
|     (loop for i in ls-dir for index from 0
|        for new-name = (nth index new-ls-dir)
|        unless (file-exists-p new-name) do (rename-file i new-name)))
|   (revert-buffer nil t nil))
`----



-- 
Thierry Volpiatto
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997 






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

* bug#6823: 24.0.50; Wdired or Dired enhancement
  2010-08-09  2:59 ` Eli Zaretskii
@ 2010-08-09  6:08   ` Thierry Volpiatto
  2010-08-09 14:02   ` Drew Adams
  1 sibling, 0 replies; 7+ messages in thread
From: Thierry Volpiatto @ 2010-08-09  6:08 UTC (permalink / raw)
  To: bug-gnu-emacs

Eli Zaretskii <eliz@gnu.org> writes:

>> From: "Drew Adams" <drew.adams@oracle.com>
>> Date: Sat, 7 Aug 2010 11:37:43 -0700
>> Cc: 
>> 
>> Emacs sorely needs one or more commands that let you rename the
>> marked files as a sequence (following a pattern).
>
> Doesn't the "% R" command in Dired use query-replace under the hood?
> If so, doesn't it already allow to include Lisp expressions in the
> replacement that are eval'ed?

It seem "%R" rename only files matching regexp to newname but
doesn't allow the use of "\," and "\#" in the regexp replacement like
query-replace-regexp does.

>
>
>

-- 
Thierry Volpiatto
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997 






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

* bug#6823: 24.0.50; Wdired or Dired enhancement
  2010-08-09  2:59 ` Eli Zaretskii
  2010-08-09  6:08   ` Thierry Volpiatto
@ 2010-08-09 14:02   ` Drew Adams
  1 sibling, 0 replies; 7+ messages in thread
From: Drew Adams @ 2010-08-09 14:02 UTC (permalink / raw)
  To: 'Eli Zaretskii'; +Cc: 6823

> > Emacs sorely needs one or more commands that let you rename the
> > marked files as a sequence (following a pattern).
> 
> Doesn't the "% R" command in Dired use query-replace under the hood?
> If so, doesn't it already allow to include Lisp expressions in the
> replacement that are eval'ed?

That kind of thing is what I had in mind when I said (though I mentioned Wdired,
not Dired):

>> AFAIK the best you can do now is to use Wdired and perform
>> query-replace with some fancy replacement expression

The Windows behavior does not require any use of a fancy replacement expression
(Lisp).

Again, we can do better than Windows does, and it is good to also offer fancy
replacement (e.g. Lisp sexps).  But we should also offer something as simple as
Windows does, and not _require_ users who want to do this kind of common
renaming to work their way through Lisp replacement sexps (no matter how simple
the sexp might be).

In addition, we should probably advertise this renaming better (even %R in
Dired), in the Dired/Wdired doc.  If %R is the best we can do for now, then
perhaps add a very simple, short example to illustrate the kind of renaming I
mentioned.






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

* bug#6823: 24.0.50; Wdired or Dired enhancement
  2010-08-09  5:50 ` Thierry Volpiatto
@ 2010-08-09 14:16   ` Drew Adams
  2010-08-09 14:48     ` Thierry Volpiatto
  0 siblings, 1 reply; 7+ messages in thread
From: Drew Adams @ 2010-08-09 14:16 UTC (permalink / raw)
  To: 'Thierry Volpiatto', bug-gnu-emacs

> > AFAIK the best you can do now is to use Wdired and perform
> > query-replace with some fancy replacement expression.
> > We should offer something simpler for the common task of
> > renaming a sequence of files.
> 
> We have have two tools to achieve this, wdired-change-to-wdired-mode,
> and query-replace-regexp used with \, and \# in the 
> replacement regexp.

That's exactly what I meant by "use Wdired and perform query-replace with some
fancy replacement expression."

I know that a user can do it.  What I suggest is that we also "offer something
simpler for the common task of renaming a sequence of files."

A Windows user need not be familiar with Lisp sexps (and especially arcane
incantations using `\,' and \#).  It's great to have that capability, but we
should also offer something simpler for the common, simple case.

> You can use also this function:(You may have to run it two 
> times in some rare cases)
>
>  (defun serial-rename (dir ext name start)...

I haven't tried it, but from the doc string, it sounds like the kind of thing I
had in mind.

The doc for Dired should mention such a command (which should be bound to a
key), and it should mention that you can do fancier, more flexible replacement
using query-replace with `\,', `\#', etc.






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

* bug#6823: 24.0.50; Wdired or Dired enhancement
  2010-08-09 14:16   ` Drew Adams
@ 2010-08-09 14:48     ` Thierry Volpiatto
  0 siblings, 0 replies; 7+ messages in thread
From: Thierry Volpiatto @ 2010-08-09 14:48 UTC (permalink / raw)
  To: Drew Adams; +Cc: bug-gnu-emacs

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

>> > AFAIK the best you can do now is to use Wdired and perform
>> > query-replace with some fancy replacement expression.
>> > We should offer something simpler for the common task of
>> > renaming a sequence of files.
>> 
>> We have have two tools to achieve this, wdired-change-to-wdired-mode,
>> and query-replace-regexp used with \, and \# in the 
>> replacement regexp.
>
> That's exactly what I meant by "use Wdired and perform query-replace with some
> fancy replacement expression."

Ah! yes sorry.

> I know that a user can do it.  What I suggest is that we also "offer something
> simpler for the common task of renaming a sequence of files."
>
> A Windows user need not be familiar with Lisp sexps (and especially arcane
> incantations using `\,' and \#).  It's great to have that capability, but we
> should also offer something simpler for the common, simple case.

Maybe have a special command for wdired that start wdired-mode but
provide a special regexp template for this case to give to
query-replace.

What is good with wdired+query-replace is we can undo if regexp is
wrong until we find a good regexp.

>> You can use also this function:(You may have to run it two 
>> times in some rare cases)
>>
>>  (defun serial-rename (dir ext name start)...
>
> I haven't tried it, but from the doc string, it sounds like the kind of thing I
> had in mind.
>
> The doc for Dired should mention such a command (which should be bound to a
> key), and it should mention that you can do fancier, more flexible replacement
> using query-replace with `\,', `\#', etc.
>
This command (serial-rename) is not part of emacs, it's just a little
command of my config i use sometime to rename quickly my photos.
However i prefer wdired/query-replace-regexp.

-- 
Thierry Volpiatto
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997 





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

end of thread, other threads:[~2010-08-09 14:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-07 18:37 bug#6823: 24.0.50; Wdired or Dired enhancement Drew Adams
2010-08-09  2:59 ` Eli Zaretskii
2010-08-09  6:08   ` Thierry Volpiatto
2010-08-09 14:02   ` Drew Adams
2010-08-09  5:50 ` Thierry Volpiatto
2010-08-09 14:16   ` Drew Adams
2010-08-09 14:48     ` Thierry Volpiatto

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).