[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: (interactive "r") and (use-region-p)

From: Noam Postavsky
Subject: Re: (interactive "r") and (use-region-p)
Date: Fri, 17 Mar 2017 09:05:36 -0400

On Fri, Mar 17, 2017 at 4:16 AM, Andreas Röhler
<address@hidden> 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---
>> AFAIK, you cannot use the (interactive "r") form for this "dwim-ish"
>> kind of behavior.
> Why that? If a region is set, why should (use-region-p) fail?

(use-region-p) doesn't fail, the "r" in interactive fails, when there
is no mark (i.e., when a region is not and has never been set). It's
basically equivalent to this:

(defun my-command (beg end)
  (interactive (sort (list (point) (mark)) #'<))
  (if (use-region-p)
      (my-command-region beg end)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]