all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Nikolaj Schumacher <n_schumacher@web.de>
To: Joe <joesmoe10@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: kill-region defadvice
Date: Sun, 08 Jun 2008 11:10:09 +0200	[thread overview]
Message-ID: <m2mylwcmxa.fsf@nschum.de> (raw)
In-Reply-To: <c09cac8e-fd66-4731-947d-c18a9060ba92@d1g2000hsg.googlegroups.com> (Joe's message of "Sat\, 7 Jun 2008 20\:47\:50 -0700 \(PDT\)")

Joe <joesmoe10@gmail.com> 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	other threads:[~2008-06-08  9:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-08  3:47 kill-region defadvice Joe
2008-06-08  9:10 ` Nikolaj Schumacher [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2mylwcmxa.fsf@nschum.de \
    --to=n_schumacher@web.de \
    --cc=help-gnu-emacs@gnu.org \
    --cc=joesmoe10@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.