[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: (interactive "r") and (use-region-p)
From: |
Ingo Lohmar |
Subject: |
Re: (interactive "r") and (use-region-p) |
Date: |
Thu, 16 Mar 2017 19:31:08 +0100 |
On Thu, Mar 16 2017 13:20 (-0400), Sam Steingold wrote:
> --8<---------------cut here---------------start------------->8---
> (defun my-command (beg end)
> (interactive "r")
> (if (use-region-p)
> (my-command-region beg end)
> (my-command-non-region)))
> --8<---------------cut here---------------end--------------->8---
Hi Sam,
AFAIK, you cannot use the (interactive "r") form for this "dwim-ish"
kind of behavior. I find it easiest to just omit the arguments and the
interactive form, and then use (region-beginning) and (region-end) in
the function body.
If you want to be able to use the function non-interactively as well,
you could make the arguments optional and check for (or (beg
(use-region-p))).
HTH.