[Top][All Lists]

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

Re: Macros don't work in Dired

From: Eli Zaretskii
Subject: Re: Macros don't work in Dired
Date: Fri, 10 Aug 2001 14:16:14 +0300

deja8501 wrote:
> If I bind F6 to "m"
>   (global-set-key (kbd "<f6>") "m")
> and press f6 in a Dired buffer then the current file is marked, just
> like when I press "m".
> If I bind F6 to "R"
>   (global-set-key (kbd "<f6>") "R")
> and press f6 in a Dired buffer then nothing happens, unlike when I
> press simply "R" (rename file).

I think this is expected behavior: any command that asks the user for input
will ``not work'' in the same way as "R" didn't, if you bind a key to it via
a keyboard macro.  Commands that don't ask for input will work.  "R" asks
for the new name of the file, so it doesn't work, "m" doesn't ask anything,
so it does work.

You can get a hint as to what's going on if you look in the *Messages*
buffer after you press F6.  There you will see that the binding actually
worked, and the command was invoked, but it signaled an error and did
nothing.  To see why did it do nothing, press F6 and immediately after that
press ?.

What happens is this: you bind F6 to a keyboard macro which is supposed to
invoke the command that renames the file.  When the keyboard macro runs, it
expects to find _all_ of its input, including any input required by the
commands it invokes, as part of the macro text.  This is because a keyboard
macro works by effectively redirecting the input stream to the macro.

So, when dired-do-rename, the command bound to `R', asks for a new file
name, the response is read from the macro.  But there's nothing in your
keyboard macro after the `R', so dired-do-rename behaves as if the user
typed RET to the prompt for the new name.  A RET means you accept the
default file name offered as part of the prompt.  But the default is
identical to the original file name, so you are asking dired-do-rename to
rename a file into itself, which is not allowed.  Consequently,
dired-do-rename prints an error message (which only goes to *Messages*,
since we are in a keyboard macro), and does nothing.

The morale?  Don't bind keys to keyboard macros which run commands that ask
for input.  In this case, you can have what you want if you say something
like this:

  (global-set-key [f6] 'dired-do-rename)

(Actually, you probably don't want this binding to be global, but I didn't
want to change your example too much, lest that obscures the real issue.)

reply via email to

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