emacs-devel
[Top][All Lists]
Advanced

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

Re: Pixel-based display functions


From: martin rudalics
Subject: Re: Pixel-based display functions
Date: Sun, 01 Feb 2015 13:52:23 +0100

> Yes, that's what I meant by "worked around somehow".  :-)  If the eww
> buffer is visible in a window (and it usually should be), I can insert
> text I want to know the width of there, call the function, and then
> delete it again.
>
> However, if the eww buffer isn't visible, that approach won't be
> possible...
>
> But the other things you mention here (default window faces and overlays
> and stuff) doesn't apply to eww at all,

But a general function would have to take care of these.

> so it kinda sounds like I could
> just do all this in a buffer that's even more likely to be associated
> with a window, like the echo area.
>
> Or is that too hacky to contemplate?  I think it might be...

Simply do a `set-window-buffer' for some window on your frame and
restore the previously shown buffer afterwards.  A macro along these
lines:

(let ((old-buffer (window-buffer (frame-selected-window)))
      (old-start (window-start (frame-selected-window)))
      (old-point (window-point (frame-selected-window))))
  (set-window-buffer (frame-selected-window) your-buffer)
  ... do your calculations ....
  (set-window-buffer (frame-selected-window) old-buffer)
  (set-window-point (frame-selected-window) old-point)
  (set-window-start (frame-selected-window) old-start))

Or yet simpler: Save the entire window configuration around your
calculations.  If redisplay doesn't run for some miraculous reason in
between, nobody will notice.

And if this is still too complicated for you, simply give
`window-text-pixel-size' an additional argument which suppresses the

  buf = w->contents;
  CHECK_BUFFER (buf);
  b = XBUFFER (buf);

  if (b != current_buffer)
    {
      old_buffer = current_buffer;
      set_buffer_internal (b);
    }

  ...

  if (old_buffer)
    set_buffer_internal (old_buffer);

sections.  In that case it would be sufficient to make your temporary
buffer current around the `window-text-pixel-size' call.

martin



reply via email to

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