[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
kill-region defadvice
From: |
Joe |
Subject: |
kill-region defadvice |
Date: |
Sat, 7 Jun 2008 20:47:50 -0700 (PDT) |
User-agent: |
G2/1.0 |
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
- kill-region defadvice,
Joe <=
Re: kill-region defadvice, Barry Margolin, 2008/06/08