unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Standard check before creating large num of frames
@ 2016-09-15  6:26 Tino Calancha
  2016-09-15 12:00 ` Stefan Monnier
  2016-09-15 14:58 ` Eli Zaretskii
  0 siblings, 2 replies; 4+ messages in thread
From: Tino Calancha @ 2016-09-15  6:26 UTC (permalink / raw)
  To: Emacs developers; +Cc: tino.calancha


Dear all,

several functions might create new frames.  In particular when
`pop-up-frames' is non-nil, `display-buffer' creates a new frame.
Creating a lot of new frames might be expensive.

Some functions may ask for user confirmation before creating an
many frames.
For instance, see `ibuffer-do-view-1': this function ask for confirmation
before creating > 3 frames.
IMO, it's good if each function creating a large number of frames
do a similar check.
We might add a new option, for instance 'max-number-of-frames'
or 'frame-max-number':

(defcustom max-number-of-frames 3
   "Maximum number of frames to create before asking user confirmation."
     :version "25.2"
     :type 'integer
     :group 'convenience)

We might want to standarize the check as well:
(defun frame-create-many-frames-p (nframes &optional prompt)
   "Return non-nil if it's OK to create NFRAMES.
If NFRAMES + current number of frames is > `max-number-of-frames',
ask for user confirmation.
An optional arg is the prompt to ask the user."
   (let* ((tot (+ nframes (length (frame-list))))
          (str (or prompt (format "Really create %s frames? " nframes)))
          (res (or (<= tot max-number-of-frames)
                   (y-or-n-p str))))
     res))

Please, let me know your opinions/suggestions about this proposal.
In case we want to add these things: where should they live?

Regards,
Tino



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Standard check before creating large num of frames
  2016-09-15  6:26 Standard check before creating large num of frames Tino Calancha
@ 2016-09-15 12:00 ` Stefan Monnier
  2016-09-15 15:33   ` Tino Calancha
  2016-09-15 14:58 ` Eli Zaretskii
  1 sibling, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2016-09-15 12:00 UTC (permalink / raw)
  To: emacs-devel

> several functions might create new frames.  In particular when
> `pop-up-frames' is non-nil, `display-buffer' creates a new frame.
> Creating a lot of new frames might be expensive.

> Some functions may ask for user confirmation before creating an many
> frames.  For instance, see `ibuffer-do-view-1': this function ask for
> confirmation before creating > 3 frames.  IMO, it's good if each
> function creating a large number of frames do a similar check.  We might
> add a new option, for instance 'max-number-of-frames' or
> 'frame-max-number':

I get the impression that setting pop-up-frames will inevitably lead to
many more frames than 3.  IOW setting pop-up-frames non-nil is already
a way to say that you're OK with having many frames.


        Stefan




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Standard check before creating large num of frames
  2016-09-15  6:26 Standard check before creating large num of frames Tino Calancha
  2016-09-15 12:00 ` Stefan Monnier
@ 2016-09-15 14:58 ` Eli Zaretskii
  1 sibling, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2016-09-15 14:58 UTC (permalink / raw)
  To: Tino Calancha; +Cc: emacs-devel

> From: Tino Calancha <tino.calancha@gmail.com>
> Date: Thu, 15 Sep 2016 15:26:43 +0900 (JST)
> Cc: tino.calancha@gmail.com
> 
> several functions might create new frames.  In particular when
> `pop-up-frames' is non-nil, `display-buffer' creates a new frame.
> Creating a lot of new frames might be expensive.
> 
> Some functions may ask for user confirmation before creating an
> many frames.
> For instance, see `ibuffer-do-view-1': this function ask for confirmation
> before creating > 3 frames.
> IMO, it's good if each function creating a large number of frames
> do a similar check.
> We might add a new option, for instance 'max-number-of-frames'
> or 'frame-max-number':
> 
> (defcustom max-number-of-frames 3
>    "Maximum number of frames to create before asking user confirmation."
>      :version "25.2"
>      :type 'integer
>      :group 'convenience)

FWIW, I don't like nagging users like that.  It could be an optional
feature, off by default, I guess.  Did you really hear from someone
complaining about too many frames open without their consent?

A couple of minor comments:

> (defun frame-create-many-frames-p (nframes &optional prompt)
>    "Return non-nil if it's OK to create NFRAMES.
> If NFRAMES + current number of frames is > `max-number-of-frames',
> ask for user confirmation.
> An optional arg is the prompt to ask the user."
>    (let* ((tot (+ nframes (length (frame-list))))
>           (str (or prompt (format "Really create %s frames? " nframes)))
>           (res (or (<= tot max-number-of-frames)
>                    (y-or-n-p str))))
>      res))

First, the message text is confusing: when the user asked for creating
a single additional frame, we are asking them

  Really create 4 frames?

The user didn't ask for 4 frames, she only asked for one.  A better
text would be

  You already have 3 frames; really create another one?

In addition, I think you should also allow the user to tell Emacs
never ask this question again in the current session, not just yes/no
for this one frame.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Standard check before creating large num of frames
  2016-09-15 12:00 ` Stefan Monnier
@ 2016-09-15 15:33   ` Tino Calancha
  0 siblings, 0 replies; 4+ messages in thread
From: Tino Calancha @ 2016-09-15 15:33 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs developers



On Thu, 15 Sep 2016, Stefan Monnier wrote:

>> several functions might create new frames.  In particular when
>> `pop-up-frames' is non-nil, `display-buffer' creates a new frame.
>> Creating a lot of new frames might be expensive.
>
>> Some functions may ask for user confirmation before creating an many
>> frames.  For instance, see `ibuffer-do-view-1': this function ask for
>> confirmation before creating > 3 frames.  IMO, it's good if each
>> function creating a large number of frames do a similar check.  We might
>> add a new option, for instance 'max-number-of-frames' or
>> 'frame-max-number':
>
> I get the impression that setting pop-up-frames will inevitably lead to
> many more frames than 3.  IOW setting pop-up-frames non-nil is already
> a way to say that you're OK with having many frames.
That was an example: that's why i said 'in particular'.
Anyway, i might say i want icecream: maybe i eat 2, 3 or even more.  I ate 
one summer one icecream cone with 6 balls (the shop offered cones with
even 20 balls).  Said that, I will not eat one cone with 100 icecream balls;
i would prefer to be asked for confirmation before pay it.

`ibuffer-do-view-1' is another example: introduces a hardcoded `3'.
Why `3'?  Isn't it better allow users to define what is in their opinion 
a large number of frames?
It's good having an standard check.  Otherwise we could have one 
Emacs library FOO asking you if nframes > N1 is Ok, and another Emacs 
library BAR asking the same when nframes > N2.

I saw more use cases in 3rd party code where this could be useful.
It might be more cases in Emacs source.



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-09-15 15:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-15  6:26 Standard check before creating large num of frames Tino Calancha
2016-09-15 12:00 ` Stefan Monnier
2016-09-15 15:33   ` Tino Calancha
2016-09-15 14:58 ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).