unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* kill-region defadvice
@ 2008-06-08  3:47 Joe
  2008-06-08  9:10 ` Nikolaj Schumacher
  2008-06-08 21:18 ` Barry Margolin
  0 siblings, 2 replies; 8+ messages in thread
From: Joe @ 2008-06-08  3:47 UTC (permalink / raw)
  To: help-gnu-emacs

Hey all,

I liked the tip in Steve Yegge's "Effective Emacs" of rebinding
backward-kill-word to C-w but I still wanted to use C-w for kill-
region.  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.  Here's my
attempt:

(defadvice kill-region (around smart-kill activate)
  "If something is highlighted, then kill the region, otherwise
backward-kill-word"
  (interactive (list (point) (mark)))
   (if mark-active
       ad-do-it
     (backward-kill-word 1)))

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

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

Thanks for the help,
Joe



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

end of thread, other threads:[~2008-06-09  8:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-08  3:47 kill-region defadvice Joe
2008-06-08  9:10 ` Nikolaj Schumacher
2008-06-08 16:45   ` Kevin Rodgers
2008-06-08 19:56     ` Nikolaj Schumacher
2008-06-08 20:51       ` Kevin Rodgers
2008-06-09  8:25         ` Nikolaj Schumacher
2008-06-08 21:18 ` Barry Margolin
2008-06-09  1:23   ` Joe

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