all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Determining size of a propertised string
@ 2016-11-29 10:39 Elias Mårtenson
  2016-11-29 11:00 ` martin rudalics
  0 siblings, 1 reply; 4+ messages in thread
From: Elias Mårtenson @ 2016-11-29 10:39 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 914 bytes --]

I have a string with a buch of properties applied (the main one: It uses a
different font). I now need to split the window, making the size of the
window just large enough to contain this text. If the string is not
propertised, I can simply count the number of lines in the text I'll be
inserting into the buffer and pass that as the HEIGHT parameter to
‘split-window’. But since the font used in this text is larger than the
default font, the window becomes slightly too small.

As far as I can tell, there seems to be no standard way of determining what
height to use in order to fit a given string. Is there a correct way to
handle this?

The context of this is the C-c C-k feature in gnu-apl-mode. It is used to
open a window that displays the APL keymap. It's common to use a slightly
larger font for APL since each character is important, and that makes this
problem immediately visible.

[-- Attachment #2: Type: text/html, Size: 987 bytes --]

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

* Re: Determining size of a propertised string
  2016-11-29 10:39 Determining size of a propertised string Elias Mårtenson
@ 2016-11-29 11:00 ` martin rudalics
  2016-11-29 11:05   ` Elias Mårtenson
  0 siblings, 1 reply; 4+ messages in thread
From: martin rudalics @ 2016-11-29 11:00 UTC (permalink / raw)
  To: Elias Mårtenson, emacs-devel

 > I have a string with a buch of properties applied (the main one: It uses a
 > different font). I now need to split the window, making the size of the
 > window just large enough to contain this text. If the string is not
 > propertised, I can simply count the number of lines in the text I'll be
 > inserting into the buffer and pass that as the HEIGHT parameter to
 > ‘split-window’. But since the font used in this text is larger than the
 > default font, the window becomes slightly too small.

Why can't you use ‘fit-window-to-buffer’?

martin




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

* Re: Determining size of a propertised string
  2016-11-29 11:00 ` martin rudalics
@ 2016-11-29 11:05   ` Elias Mårtenson
  2016-11-29 14:16     ` martin rudalics
  0 siblings, 1 reply; 4+ messages in thread
From: Elias Mårtenson @ 2016-11-29 11:05 UTC (permalink / raw)
  To: martin rudalics; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1091 bytes --]

On 29 November 2016 at 19:00, martin rudalics <rudalics@gmx.at> wrote:

> I have a string with a buch of properties applied (the main one: It uses a
> > different font). I now need to split the window, making the size of the
> > window just large enough to contain this text. If the string is not
> > propertised, I can simply count the number of lines in the text I'll be
> > inserting into the buffer and pass that as the HEIGHT parameter to
> > ‘split-window’. But since the font used in this text is larger than the
> > default font, the window becomes slightly too small.
>
> Why can't you use ‘fit-window-to-buffer’?


The short answer is that I didn't know about its existence. Thank you so
much for directing my attention to it.

The longer answer is that while this does indeed solve the problem at hand
(and I've already pushed it to gnu-apl-mode), there may be more complicated
cases where an answer to the original question may be needed.

So in the interest of satisfying my own curiosity, is there a way to
determine the height of a given string?

[-- Attachment #2: Type: text/html, Size: 1538 bytes --]

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

* Re: Determining size of a propertised string
  2016-11-29 11:05   ` Elias Mårtenson
@ 2016-11-29 14:16     ` martin rudalics
  0 siblings, 0 replies; 4+ messages in thread
From: martin rudalics @ 2016-11-29 14:16 UTC (permalink / raw)
  To: Elias Mårtenson; +Cc: emacs-devel

 > So in the interest of satisfying my own curiosity, is there a way to
 > determine the height of a given string?

"A given string" doesn't have a height per se.  It's assigned a height
only when you put it into a buffer and put that buffer in a window on a
display.  This may wrap the string and assigns the corresponding font,
text, overlay and other properties to that string's constituents.  You
can use the function ‘window-text-pixel-size’ in order to determine the
size of the string it would occupy, in pixels, at a given buffer
position on your display.  That's what ‘fit-window-to-buffer’ does.

martin




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

end of thread, other threads:[~2016-11-29 14:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-29 10:39 Determining size of a propertised string Elias Mårtenson
2016-11-29 11:00 ` martin rudalics
2016-11-29 11:05   ` Elias Mårtenson
2016-11-29 14:16     ` martin rudalics

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.