help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: [External] : interactive to do `use-region-p'


From: Emanuel Berg
Subject: Re: [External] : interactive to do `use-region-p'
Date: Sun, 06 Nov 2022 19:53:21 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

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 via email to

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