help-gnu-emacs
[Top][All Lists]
Advanced

[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: Sun, 08 Jun 2008 11:10:09 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (darwin)

Joe <address@hidden> 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.

> When I run the command it works normally if I have something
> highlighted, but if I don't have anything highlighted, I get the usual
> "The mark is not active now.".

The reason for this is: (mark)
That throws the error if the mark is not active.

Also, try setting the variable debug-on-error to t.  It'll give you a
backtrace to help locate such errors.

> How can I kill the region if the mark is active and backward-kill-word
> if its not?

(defun control-w-dwim ()
  (interactive)
  (if mark-active
      (call-interactively 'kill-region)
    (call-interactively 'backward-kill-word)))


regards,
Nikolaj Schumacher




reply via email to

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