[Top][All Lists]

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

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

From: Andreas Röhler
Subject: Re: (interactive "r") and (use-region-p)
Date: Sat, 18 Mar 2017 18:40:29 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:45.0) Gecko/20100101 Icedove/45.6.0

On 17.03.2017 14:05, Noam Postavsky wrote:
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)
--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)

Okay, thanks. So that's no occasion to question the use-region-p, region-active-p design.
For the case given, think the error is reasonable, as a command explicitly working on region might expect an existing one.

reply via email to

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