From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Joe Newsgroups: gmane.emacs.help Subject: kill-region defadvice Date: Sat, 7 Jun 2008 20:47:50 -0700 (PDT) Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1212900062 14327 80.91.229.12 (8 Jun 2008 04:41:02 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 8 Jun 2008 04:41:02 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Jun 08 06:41:45 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1K5Ciu-0003St-Pt for geh-help-gnu-emacs@m.gmane.org; Sun, 08 Jun 2008 06:41:45 +0200 Original-Received: from localhost ([127.0.0.1]:48904 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K5Ci7-0000Qi-RE for geh-help-gnu-emacs@m.gmane.org; Sun, 08 Jun 2008 00:40:55 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!d1g2000hsg.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 27 Original-NNTP-Posting-Host: 98.169.3.157 Original-X-Trace: posting.google.com 1212896871 5357 127.0.0.1 (8 Jun 2008 03:47:51 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Sun, 8 Jun 2008 03:47:51 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d1g2000hsg.googlegroups.com; posting-host=98.169.3.157; posting-account=ZyfIlgoAAADvwmSv7gUPoyt-iOc2yu_g User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14,gzip(gfe),gzip(gfe) X-HTTP-Via: 1.1 indian.schafers.us:800 (squid/2.6.STABLE17) Original-Xref: news.stanford.edu gnu.emacs.help:159245 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:54601 Archived-At: 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