[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: kill-region defadvice
From: |
Nikolaj Schumacher |
Subject: |
Re: kill-region defadvice |
Date: |
Mon, 09 Jun 2008 10:25:51 +0200 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.2 (darwin) |
Kevin Rodgers <kevin.d.rodgers@gmail.com> wrote:
> Nikolaj Schumacher wrote:
>> Kevin Rodgers <kevin.d.rodgers@gmail.com> wrote:
>>
>>> Nikolaj Schumacher wrote:
>>>> Joe <joesmoe10@gmail.com> wrote:
>>>>
>>>>> Originally I did this by writing a new function that checked
>>>>> if the mark was active. However, I think that using defadvice is a
>>>>> better solution but I got stuck while trying to write it.
>>>>
>>>> No, it's not! By using advice, you modify the kill-region function and
>>>> risk that any command using it will backward-kill-word instead.
>>>
>>> Just write the advice as
>>>
>>> (if (and (interactive-p) mark-active)
>>> ad-do-it
>>> (backward-kill-word 1))
>>
>> Still not a good idea.
>> `interactive-p' will return nil when used in a keyboard macro. That
>> will most likely cause unintended behavior at some point.
>
> (if (and (or (interactive-p) executing-kbd-macro)
> mark-active)
First of all, that should probably read:
(if (or (not (or (interactive-p) executing-kbd-macro)
mark-active))
But that still won't work. executing-kbd-macro will remain non-nil when
called non-interactively by another command while inside a macro.
Of course, I'm not saying that it can't be done. I'm just saying it's
easy to mess up and difficult to debug.
regards,
Nikolaj Schumacher
Re: kill-region defadvice, Barry Margolin, 2008/06/08