unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Emanuel Berg <incal@dataswamp.org>
To: help-gnu-emacs@gnu.org
Subject: Re: [External] : interactive to do `use-region-p'
Date: Sun, 06 Nov 2022 19:53:21 +0100	[thread overview]
Message-ID: <87tu3bc3tq.fsf@dataswamp.org> (raw)
In-Reply-To: SJ0PR10MB548864CAB669766DFEA9A7BBF33D9@SJ0PR10MB5488.namprd10.prod.outlook.com

Drew Adams wrote:

> But instead of (nil nil) you might prefer `(,(point-min)
> ,(point-max)). This use case:

It can be good to know if the user set the region or not, and
if it's set it is obvious what the boundaries are, if unset,
there are several courses of action and that one, while
perhaps the most common one, isn't the only one, one can also
think of ((point) (point-max)) and many other scenarios.

So I think (nil nil) is best, signaling "not set by the user",
then instead of asking `user-region-p' one can just check if
BEG and END are set, if not one would explicitly have to set
them to something that makes sense for that function.

> (interactive
>   (let* ((regp (use-region-p))
>          (st   (if regp (region-beginning) (point-min)))
>          (en   (if regp (region-end) (point-max))))
>     (list st en)))

Yes, they can still be nil nil from Lisp tho if &optional so
then they have to be set outside of (after) `interactive' as
well unless nil values make sense which often when dealing with
the region and buffer positions they don't ...

(defun gnus-summary-respool-all (&optional beg end)
  (interactive (when (use-region-p)
                 (list (region-beginning) (region-end)) ))
  (or beg (setq beg (point-min)))
  (or end (setq end (point-max)))
  (let ((lines  (count-lines beg end))
        (method (gnus-find-method-for-group "nnml:mail.misc")) )
    (goto-char beg)
    (gnus-summary-respool-article lines method) ))

> `interactive' with string arg is OK, but often isn't TRT.

TRT = The Right Thing

> It can sometimes be clearer to just define a function that
> does what you want, and use that with (interactive
> `(,@(DTRT))).

It can but it takes more time and the code gets longer so if
you can use `interactive' without a function I think that is
TRT :) And in this CASE it seems there isn't an uppercase "R"
anyway so yeah, that's what I'm proposing ...

-- 
underground experts united
https://dataswamp.org/~incal




  reply	other threads:[~2022-11-06 18:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-06 13:45 interactive to do `use-region-p' Emanuel Berg
2022-11-06 15:41 ` [External] : " Drew Adams
2022-11-06 18:53   ` Emanuel Berg [this message]
2022-11-07  1:41   ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-11-07  2:29     ` Drew Adams
2022-11-07 12:28       ` Emanuel Berg
2022-11-07 15:51         ` Drew Adams
2022-11-07 17:25           ` Emanuel Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tu3bc3tq.fsf@dataswamp.org \
    --to=incal@dataswamp.org \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).