From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nikolaj Schumacher Newsgroups: gmane.emacs.help Subject: Re: kill-region defadvice Date: Sun, 08 Jun 2008 11:10:09 +0200 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1212916387 13482 80.91.229.12 (8 Jun 2008 09:13:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 8 Jun 2008 09:13:07 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Joe Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Jun 08 11:13:49 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 1K5Gy9-0003G8-VG for geh-help-gnu-emacs@m.gmane.org; Sun, 08 Jun 2008 11:13:46 +0200 Original-Received: from localhost ([127.0.0.1]:56321 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K5GxM-000603-KX for geh-help-gnu-emacs@m.gmane.org; Sun, 08 Jun 2008 05:12:56 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K5Gul-0005zV-O2 for help-gnu-emacs@gnu.org; Sun, 08 Jun 2008 05:10:16 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K5Gui-0005yy-Cf for help-gnu-emacs@gnu.org; Sun, 08 Jun 2008 05:10:12 -0400 Original-Received: from [199.232.76.173] (port=50768 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K5Guh-0005yq-Qd for help-gnu-emacs@gnu.org; Sun, 08 Jun 2008 05:10:11 -0400 Original-Received: from fmmailgate01.web.de ([217.72.192.221]:40654) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1K5Guh-0003Ao-AI for help-gnu-emacs@gnu.org; Sun, 08 Jun 2008 05:10:11 -0400 Original-Received: from smtp07.web.de (fmsmtp07.dlan.cinetic.de [172.20.5.215]) by fmmailgate01.web.de (Postfix) with ESMTP id 2FC8CE3467FD; Sun, 8 Jun 2008 11:10:10 +0200 (CEST) Original-Received: from [77.135.169.185] (helo=thursday-2.local) by smtp07.web.de with asmtp (WEB.DE 4.109 #226) id 1K5Gug-0000NG-00; Sun, 08 Jun 2008 11:10:10 +0200 In-Reply-To: (Joe's message of "Sat\, 7 Jun 2008 20\:47\:50 -0700 \(PDT\)") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (darwin) X-Sender: n_schumacher@web.de X-Provags-ID: V01U2FsdGVkX1/AZXnLQAfnPuLsN3Nmw/2FQdNKWxzIz0veb1Ot X5V58qd0LlPHEyzQBsNr2ZrNZXVtnegRFJlFN9IRkGXxB+uURq vfNKdcPZczkO+59XWGfw== X-detected-kernel: by monty-python.gnu.org: Linux 2.4-2.6 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:54612 Archived-At: Joe 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