From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: =?UTF-8?Q?Andreas_R=c3=b6hler?= Newsgroups: gmane.emacs.devel Subject: Re: (interactive "r") and (use-region-p) Date: Sat, 18 Mar 2017 18:40:29 +0100 Message-ID: References: <8760j9845v.fsf@acer.localhost.com> <75ca08aa-f9b1-4407-c150-c96f738e268c@online.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="------------601F9CE525C4782EB17C19B8" X-Trace: blaine.gmane.org 1489858152 12142 195.159.176.226 (18 Mar 2017 17:29:12 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 18 Mar 2017 17:29:12 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux i686; rv:45.0) Gecko/20100101 Icedove/45.6.0 Cc: Ingo Lohmar , Sam Steingold , Emacs developers To: Noam Postavsky Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Mar 18 18:29:08 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cpIA7-0002c4-Q7 for ged-emacs-devel@m.gmane.org; Sat, 18 Mar 2017 18:29:08 +0100 Original-Received: from localhost ([::1]:54174 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cpIAD-0003k9-R6 for ged-emacs-devel@m.gmane.org; Sat, 18 Mar 2017 13:29:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59663) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cpIA7-0003k4-TF for emacs-devel@gnu.org; Sat, 18 Mar 2017 13:29:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cpIA6-0006bH-Sa for emacs-devel@gnu.org; Sat, 18 Mar 2017 13:29:07 -0400 Original-Received: from mout.kundenserver.de ([212.227.126.130]:63609) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cpIA2-0006ar-Le; Sat, 18 Mar 2017 13:29:02 -0400 Original-Received: from [192.168.178.35] ([77.12.43.221]) by mrelayeu.kundenserver.de (mreue003 [212.227.15.167]) with ESMTPSA (Nemesis) id 0M6AMY-1c1Jw421Wc-00yDTa; Sat, 18 Mar 2017 18:28:46 +0100 In-Reply-To: X-Provags-ID: V03:K0:ZOL9WA2Y0DBypXFLeOBDCDzA592Q3druE3OUZqAMW4FEQgcwpG4 oPxWfg1jfRjG7qXQIlsOdGJboayCCG0dZ47u5FsPCtLswQCXt4XKDlbd/GLhcWvw5geazON /mQjqE+p4VUMm5WP109ysN8M/p6LNt6gkYkMOy2x2gVaEhPRdHJThRfa59Bqrau1Fs5KEpo QPMBn9RAimcat6tbeLceQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:vOlm+dH1i8Q=:1a645W/NyKIAePgBkr+46a +cLC8GRrv3WXZIoS+H+38TWmxF+WYwFj9eAUnk+uyyDJSWQiWxFE9I1/ivgqVZMe9+Oa3jgsY snhRTTqCBOYN0GwZKY9ffSz6inb5AU8LdhJV+fdIbdKQkaPITceIvoZ8E+l6bvM8Ih05GtR7H 0R48Upybiv5eY1CakaB/aIaMCeDNYOrhNw0uMY8vVArDfg1B/ioZhDuXiXZfDVj8B+IkSEv+v wruS3cT4fyHdSzCQqGBP4f2VxLlNHa+pHT7IVHNvIN5rcLTfnO9cW2PHLLCVZK7F5KwmEqvzX iyFqglTpgnGJk5mVwcZw2q4tRL7EWzbx5IlTS1hlvmqEtEBZTHjuye4i9pS73xPsK2KPiOIQp hrstZGcE3xweyxnKk6WyqVChFxQ0GxnRfnCqSebXRZW8GOpcRAygjLfnalNC3PWzu9QmD4vJG 8lxKSQOK+FIoHKXRK1DXhlxNdaOJCFkb7dr6VAwLsxCEP4Rmrq/7PsvkR8sxS6/HKpUK0HAj2 mXdBowpTLsbmunMloZcZkj/12noewqRACk68AAHbk08L8AFE0SDW+Nm+pCRYSt+GsjkBoVD1N nwShuWPlPEWYrPddYRaGrQHTnWn2bYc/KaLfYpr8aDhQI0NFsZKThzAx7QI0T7uSbqyTBkGfD G9RvOwXgokGAe20Yd+78w/eDwmW9ZSiTprI3cslmlqg01YVC7OUFT2J8jlF6UKQQv+QjFD+HT tLxr8vDe++XaUA6N X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.126.130 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:213136 Archived-At: This is a multi-part message in MIME format. --------------601F9CE525C4782EB17C19B8 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 17.03.2017 14:05, Noam Postavsky wrote: > On Fri, Mar 17, 2017 at 4:16 AM, Andreas Röhler > 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) > (my-command-non-region))) 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. --------------601F9CE525C4782EB17C19B8 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit



On 17.03.2017 14:05, Noam Postavsky wrote:
On Fri, Mar 17, 2017 at 4:16 AM, Andreas Röhler
<andreas.roehler@online.de> 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)
    (my-command-non-region)))

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.



--------------601F9CE525C4782EB17C19B8--