emacs-devel
[Top][All Lists]
Advanced

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

should frame names be unique? [was: difficulty creating unique frame nam


From: Drew Adams
Subject: should frame names be unique? [was: difficulty creating unique frame names]
Date: Fri, 21 Mar 2008 08:40:23 -0700

It is not the best design to have multiple frames with the
same name. When you choose a frame by its name via the
minibuffer or a menu, it's possible to see duplicate names
that represent different frames - there is then no way to
know which name corresponds to which frame.

Frames are uniquely identified internally, but the `name'
frame parameter does not reflect this uniqueness. It might
be better to treat frame names similarly to how we treat
buffer names (foo, foo<2>, foo<3>...). But because the frame
name is often based on a buffer name (via frame-title-format
"%b"), angle brackets are perhaps not the best choice for
making frame names unique.

In my code, I provide unique names for choosing frames,
without actually renaming the frames. The unique names use
brackets ([]) with a counter: foo, foo[2], bar<3>,
bar<3>[2], and so on - the bracketed counter is appended to
the existing frame name (existing frame name bar<3> comes
from buffer bar<3>).

My code doesn't change frame-parameter `name' in this way;
it just gives users a way to refer to frames using unique
names.

I think it would be good, however, if Emacs actually named
frames in this way. When a frame is named, if a frame with
the same name already exists, then the new name would get a
bracketed counter id.

WDOT?

For reference, here is the code I use to map existing frame
names to unique names (again, without renaming the frames
themselves):

(defun icicle-make-frame-alist ()
  "Return an alist of entries (FNAME . FRAME), where FNAME
names FRAME.
Frame parameter `name' is used as FNAME, unless there is
more than one
frame with the same name.  In that case, FNAME includes a
suffix
\[NUMBER], to make it a unique name.  The NUMBER order among
frame
names that differ only by their [NUMBER] is arbitrary."
  (let ((fr-alist ())
        (count 2)
        fname new-name)
    (dolist (fr (frame-list))
      (setq fname (frame-parameter fr 'name))
      (if (not (assoc fname fr-alist))
          (push (cons fname fr) fr-alist)
        (setq new-name fname)
        (while (assoc new-name fr-alist)
          (setq new-name (format "%s[%d]" fname count)
                count (1+ count)))
        (push (cons new-name fr) fr-alist))
      (setq count 2))
    fr-alist))

Trying that gives you an idea of the kinds of names I'm
talking about, but what's needed is to actually name frames
from the outset using some such convention.

See also Damon's remarks and code, below.

> From: Damon Permezel Sent: Monday, March 10, 2008 8:42 PM
> To: address@hidden
> Subject: difficulty creating unique frame names
> 
> The default naming scheme for certain emacs
implementations is to use
> the string in the frame-title-format which defaults to
"%b".  It is
> thus quite easy to create many frames with the same name.
Just start
> emacs and hit ^x-5-2 repeatedly.
> 
> The Buffers>Frames menu thus presents a list of buffers
many with the
> same names.  Also, any command for manipulating frames by
frame names
> really cannot use the name to distinguish between the
frames. 
>  Note that
> the Buffers>Frames cannot be used to select all the frames

> with the same
> name when there are more than 2 with the same name.  This
is a bug!
> 
> In order to avoid this bug, one has to have unique frame
names.
> 
> I wish to retain the "%b" functionality in the
frame-title-format, so
> I have attempted to construct a FORM that will be
evaluated when the
> frame title is desired to provide some unique element ---
in this case
> a F%d where the %d is the index of the frame within the 
> (frame-list),  
> say.
> 
> I find that it is not possible to calculate this
correctly, as I have
> no means, from elisp, at the time the FORM is being
evaluated, to
> obtain the frame in question.
> 
> I have also tried setting a :zz-count property on the
frames to
> uniquely identify them, however there is no means I know
of to
> retrieve this property again as the frame in question is
not available
> to me.
> 
> I do not want to set the 'name property for the frame, as
I wish to
> retain the "%b" functionality, and I note that this does
not work.
> IE: I could arrange to set each frame's 'name to "<unique>
%b" readily
> enough, but then the %b is not expanded.  Also, cannot set
name to
> anything by a string.
> 
> I have tried setting the 'frame-title-format property in a
frame,
> given that this is rumoured to create
frame-local-variables, but this
> does not seem to influence the global frame-title-format.
> 
> (setq zz-frame-count 0)
> 
> ;;
> ;; this will put a unique :zz-count in each frame's
properties
> ;;
> (add-hook 'after-make-frame-functions
>         '(lambda (frame)
>            (progn
>              (modify-frame-parameters frame (list (cons 
> :zz-count (setq zz- 
> frame-count (1+ zz-frame-count)))))
>              (message "%S" (frame-parameters frame)))))
> 
> ;;
> ;; this attempts to set F%d to the index of the frame in
the
> ;; frame-list, but it just does so for the current frame.
> ;;
> 
> (setq frame-title-format
>        (cons :eval
>           '((let ((f (next-frame (previous-frame)))
>                   (x nil))
>               (format "F%d:%%b - %%F"
>                       (apply '+ (mapcar
>                                  (lambda (_)
>                                    (if x 0
>                                      (setq x (eq _ f))
>                                      1))
>                                  (frame-list))))))
> 
> ;; try the above, and then a a slew of ^x-5-2 and then
cycle 
> thru the  
> frames and look at the names.
> 
> 
> I would either like to be able to have (current-frame)
return the
> frame for which the frame-title-format is being expanded,
or I would
> like to have a '%Z[pname]' (or something less revolting) 
> expand out to  
> a named property for
> the implicit frame, just as '%F' expands the implicit
frame's name.
> 
> (setq frame-title-format "F%Z[:zz-count]:%b")
> 
> would give me "F1:*scratch*", "F2:*scratch*", ... for
example.
> 
> Another solution would be to use the per-frame
frame-title-format.





reply via email to

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