From mboxrd@z Thu Jan 1 00:00:00 1970
Path: news.gmane.org!.POSTED!not-for-mail
From: Philipp Stephani
Newsgroups: gmane.emacs.help
Subject: Re: DWIM region
Date: Fri, 05 Jan 2018 23:18:30 +0000
Message-ID:
References: <86shbmcldx.fsf@zoho.com>
<86d12pcvgj.fsf@zoho.com> <86d12pb988.fsf_-_@zoho.com>
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: blaine.gmane.org 1515194251 6286 195.159.176.226 (5 Jan 2018 23:17:31 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Fri, 5 Jan 2018 23:17:31 +0000 (UTC)
Cc: help-gnu-emacs@gnu.org
To: Stefan Monnier
Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Jan 06 00:17:27 2018
Return-path:
Envelope-to: geh-help-gnu-emacs@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 1eXbEo-00013M-9m
for geh-help-gnu-emacs@m.gmane.org; Sat, 06 Jan 2018 00:17:22 +0100
Original-Received: from localhost ([::1]:35478 helo=lists.gnu.org)
by lists.gnu.org with esmtp (Exim 4.71)
(envelope-from )
id 1eXbGn-00058z-PG
for geh-help-gnu-emacs@m.gmane.org; Fri, 05 Jan 2018 18:19:25 -0500
Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36883)
by lists.gnu.org with esmtp (Exim 4.71)
(envelope-from ) id 1eXbG8-00057E-Tl
for help-gnu-emacs@gnu.org; Fri, 05 Jan 2018 18:18:46 -0500
Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
(envelope-from ) id 1eXbG7-0003Bo-Br
for help-gnu-emacs@gnu.org; Fri, 05 Jan 2018 18:18:44 -0500
Original-Received: from mail-qt0-x22e.google.com ([2607:f8b0:400d:c0d::22e]:41246)
by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
(Exim 4.71) (envelope-from )
id 1eXbG6-0003AJ-Ml
for help-gnu-emacs@gnu.org; Fri, 05 Jan 2018 18:18:43 -0500
Original-Received: by mail-qt0-x22e.google.com with SMTP id i40so7598781qti.8
for ; Fri, 05 Jan 2018 15:18:42 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to
:cc; bh=EjYmlwL3D4DE3KtmDUJxSRnAarLlWBeDhpclP97lub4=;
b=QVi/CmzIGzA5nGZMAiKefGqTTyrJvbRnYUGoMPLyJlSW0P9GPsDkqQ7aUynkaJ+mVK
9yRWJJD/XPbjdKZb7EDIot2GLI9j0Kw3sEIFtwwt8OAb5Cd9ckqZLcI3hthW8hlBXFgv
RmbFZvf/BOIpek6L9YXEFTGs4JKk8AfJMqGBjCHEseAbTc/RxXLdURg515fulfYyAiao
WnsWAsLZRzSHsISqFvGAkaPS5umXVcHfeEkdP0yVDyc16g4+rI92wQqiydeXXIC2KqlD
xA/H6HBNnM6wcEasLnLbvjbXLPjgawS4VBbJHgS1aYGV5+zetB/6fv2UjU6+WHRhJIZZ
Uqbw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to:cc;
bh=EjYmlwL3D4DE3KtmDUJxSRnAarLlWBeDhpclP97lub4=;
b=n7XYWC/FklJL2bzEb5xfH8LrQHBBCpZ4yqLAzRXFEDPnCFsvY1xo6sX9A1shJTIWca
6eB/6vkwMrnlDLYPpX9holMnIEdTPw6+32E7+1aDB0HERF7xAwm3gB2llF8U1dAoNyJT
XH+hZXdyW9+n8/tlxFjfNmUo2zyRKg32XT9bIhyA70H0RTFIvOE/tlgwkyxJExx4Ljwg
1yhMPVDPbOHyvV7sWxHTCK4OcEq2e9GtmD3RajWw7eI4haCSQti5s+exBYvVezLm5mwv
aNgedNVjrW4h1XlsD94plj27GZJJ3LUPQWphx0O4fuTvVoYnW9A2ViAC3qO8zTmEbLWh
aL4w==
X-Gm-Message-State: AKwxytemFvNd8sdN3km3QlR34Q66+0TDbD/uD3ExII8xAKNIdsy1a+gN
md6jHUMJTTl5rVGcALFnG7iRXOlWb7DX1UX7qhM=
X-Google-Smtp-Source: ACJfBotxv46vVyWYSMuJ88/0+2z9b6Qp2FxAJ5Nt0SqR2BTM8JS+2l8Ywtg8SvVWB9xiq2AzYFM+DTsd+CAEGPdftWg=
X-Received: by 10.237.38.229 with SMTP id q92mr6773472qtd.310.1515194321651;
Fri, 05 Jan 2018 15:18:41 -0800 (PST)
In-Reply-To:
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
recognized.
X-Received-From: 2607:f8b0:400d:c0d::22e
X-Content-Filtered-By: Mailman/MimeDel 2.1.21
X-BeenThere: help-gnu-emacs@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: Users list for the GNU Emacs text editor
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Original-Sender: "help-gnu-emacs"
Xref: news.gmane.org gmane.emacs.help:115596
Archived-At:
Stefan Monnier schrieb am Do., 4. Jan. 2018 um
23:19 Uhr:
> > (defun count-regexp-hits (regexp)
> > (interactive "sregexp: ")
> > (let*((region (if mark-active
> > `(,(region-beginning) ,(region-end))
> > `(,(point-min) ,(point-max)) ))
>
> 2 "errors":
> - you should check `use-region-p` instead of `mark-active`.
> - `region` should be an argument, so the use-region-p check is performed
> in the interactive spec rather than in the body of the function:
>
> (defun count-regexp-hits (regexp start end)
> (interactive
> ;; The "s" thingy from `interactive` corresponds to `read-string`
> ;; but we might as well use `read-regexp` here since we can.
> (let ((re (read-regexp "regexp: ")))
> (if (use-region-p)
> (list re (region-beginning) (region-end))
> (list re (point-min) (point-max)))))
> (count-matches regexp start end t))
>
Since this pattern seems to be very common, would it make sense to add an
interactive specifier 'R' that behaves like 'r' if `use-region-p` returns
true and otherwise adds `nil, nil`?