all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Juanma Barranquero <lekktu@gmail.com>
Cc: Emacs developers <emacs-devel@gnu.org>
Subject: Re: Freezing frameset-restore
Date: Mon, 10 Mar 2014 00:29:44 -0400	[thread overview]
Message-ID: <jwvfvmqbtoa.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <CAAeL0SRHsxTNJU7CFkn92EzyW68Y_vSjkpLyv-bdVgO72y+p_A@mail.gmail.com> (Juanma Barranquero's message of "Sun, 9 Mar 2014 00:45:19 +0100")

> A variant of the last patch.

Looks good, thanks.  Comments below.

> +(defvar frameset--action-map nil
> +  "Map of frames to actions.
> +Its value is only meaningful during execution of `frameset-restore'.
> +Internal use only.")

Make it just (defvar frameset--action-map).

> -REUSE-FRAMES selects the policy to use to reuse frames when restoring:
> -  t        Reuse existing frames if possible, and delete those not reused.
> -  nil      Restore frameset in new frames and delete existing frames.
> -  :keep    Restore frameset in new frames and keep the existing ones.
> +REUSE-FRAMES selects the policy to reuse frames when restoring:
> +  :all     All existing frames can be reused.  This is the default.
> +  :none    No existing frame can be reused.
> +  :match   Only frames with matching frame ids can be reused.
>    LIST     A list of frames to reuse; only these are reused (if possible).
> -            Remaining frames in this list are deleted; other frames not
> -            included on the list are left untouched.
> +  PRED     A predicate function; it receives as argument a live frame,
> +             and must return non-nil to allow reusing it, nil otherwise.

So far, I only see :all, :none, and :match being used.
I suggest the following changes:
- Get rid of the LIST case (it's not used and the caller could use
  PRED instead anyway to get the same result).
- I prefer it when keywords are used only for the argument names and not
  for their values, so you don't need to count them to know which
  is which.  So I'd favor using `all', `none', and `match'.  Tho that
  slightly clashes with the PRED case.  So I'd then suggest to rename
  `all' to t, `none' to nil, and to get rid of `match' (i.e. use the
  PRED case for it, probably providing a handy function for it).

> +    (setq frameset--action-map nil)

let-bind it, instead.

> +    ;; Mark candidates as :ignored; they will be reassigned later, if chosen.
> +    (mapc (lambda (frame)
> +           (push (cons frame :ignored) frameset--action-map))
> +         frameset--reuse-list)

Maybe a hash-table would be better than an alist.  This would save us
from the hideous cl-acons/assq-delete-all.

> +by `frameset-restore' (which see).  Optional arg ACTION-MAP is an alist
> +\((ACTIONn . FUNCTIONn)...) mapping actions to their cleanup functions.
> +ACTION can be an action, or a list of actions.

Allowing a list of actions is over-engineering it.

> +  (frameset-restore-cleanup
> +   (frameset-restore (aref data 0)
> +                    :filters frameset-session-filter-alist
> +                    :reuse-frames (if current-prefix-arg nil :match))
> +   (if current-prefix-arg
> +       ;; delete frames
> +       nil
> +     ;; iconify frames
> +     '((:rejected . iconify-frame)
> +       ;; In the unexpected case that a frame was a candidate (matching frame id)
> +       ;; and yet not restored, remove it because it is in fact a duplicate.
> +       (:ignored . delete-frame))))

Without frameset-restore-cleanup this could look like

  (pcase-dolist
      (`(,frame . ,action)
       (frameset-restore (aref data 0)
                         :filters frameset-session-filter-alist
                         :reuse-frames (if current-prefix-arg nil :match)))
    (with-demoted-errors "Error cleaning up frame: %S"
      (pcase action
        (`:rejected
         (if current-prefix-arg (delete-frame frame) (iconify-frame frame)))
        ;; In the unexpected case that a frame was a candidate (matching frame
        ;; id) and yet not restored, remove it because it is in fact
        ;; a duplicate.
        (`:ignored (delete-frame frame)))))

It's admittedly longer than your version, but I'm not convinced it
justifies the complexity of frameset-restore-cleanup.


        Stefan



  reply	other threads:[~2014-03-10  4:29 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-06  0:03 Freezing frameset-restore Juanma Barranquero
2014-03-06 17:27 ` martin rudalics
2014-03-06 17:33   ` Juanma Barranquero
2014-03-06 18:16     ` martin rudalics
2014-03-06 18:35       ` Juanma Barranquero
2014-03-06 18:41       ` Juanma Barranquero
2014-03-07  7:38         ` martin rudalics
2014-03-07 11:28           ` Juanma Barranquero
2014-03-07 15:16             ` martin rudalics
2014-03-07 20:32 ` Stefan Monnier
2014-03-07 21:34   ` Juanma Barranquero
2014-03-07 21:40     ` Juanma Barranquero
2014-03-08  0:34     ` Stefan Monnier
2014-03-08  1:42       ` Juanma Barranquero
2014-03-08  2:25         ` Juanma Barranquero
2014-03-08  4:31         ` Stefan Monnier
2014-03-08  6:00           ` Juanma Barranquero
2014-03-08 14:27             ` Stefan Monnier
2014-03-08 16:34               ` Juanma Barranquero
2014-03-08 23:45                 ` Juanma Barranquero
2014-03-10  4:29                   ` Stefan Monnier [this message]
2014-03-10  5:26                     ` Juanma Barranquero
2014-03-10 13:04                       ` Juanma Barranquero
2014-03-10 14:19                       ` Stefan Monnier
2014-03-10 15:06                         ` Juanma Barranquero
2014-03-10 18:33                           ` Juanma Barranquero
2014-03-10 23:10                             ` Stefan Monnier
2014-03-11  0:47                               ` Juanma Barranquero
2014-03-10 20:32                           ` Stefan Monnier
2014-03-10 21:07                             ` Juanma Barranquero
2014-03-09 12:29                 ` Stefan Monnier

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

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

  git send-email \
    --in-reply-to=jwvfvmqbtoa.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=lekktu@gmail.com \
    /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.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.