unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How do I get the window height in lines, taking in account line-spacing?
@ 2014-08-04 12:11 Dmitry Gutov
  2014-08-04 14:17 ` Michael Heerdegen
  0 siblings, 1 reply; 13+ messages in thread
From: Dmitry Gutov @ 2014-08-04 12:11 UTC (permalink / raw)
  To: help-gnu-emacs

I can see two ways to obtain the number of visible lines:

1. (window-body-height) - this doesn't take line-spacing into account. 
Furthermore, (/ (window-body-height) (1+ line-spacing)) doesn't seem to 
produce the exactly correct result, even when line-spacing is a float, 
even if I round it up.

2. (count-screen-lines (window-start) (window-end)) takes line-spacing 
into account, naturally, but it also includes the partially visible line 
at the bottom, if there is one.

Is there a better way?

Related: 
https://github.com/company-mode/company-mode/issues/160#issuecomment-51022508



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

* Re: How do I get the window height in lines, taking in account line-spacing?
  2014-08-04 12:11 How do I get the window height in lines, taking in account line-spacing? Dmitry Gutov
@ 2014-08-04 14:17 ` Michael Heerdegen
  2014-08-04 18:31   ` Dmitry
  0 siblings, 1 reply; 13+ messages in thread
From: Michael Heerdegen @ 2014-08-04 14:17 UTC (permalink / raw)
  To: help-gnu-emacs

Dmitry Gutov <dgutov@yandex.ru> writes:

> Is there a better way?

There's `window-screen-lines', but it's also not reliable when the
window displays different fonts or images etc.

You maybe want to use `window-end' combined with
`pos-visible-in-window-p'.

What's the problem you want to solve, btw?


Michael.




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

* Re: How do I get the window height in lines, taking in account line-spacing?
  2014-08-04 14:17 ` Michael Heerdegen
@ 2014-08-04 18:31   ` Dmitry
       [not found]     ` <CAPhAwGyGvNy5rUf2M9jaE=kBrtZNDo_Ey+F6Oq2VqzZB+OoKEA@mail.gmail.com>
                       ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Dmitry @ 2014-08-04 18:31 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs

Michael Heerdegen <michael_heerdegen@web.de> writes:

> There's `window-screen-lines', but it's also not reliable when the
> window displays different fonts or images etc.

This would be fine, except even in the simple case it returns the same
mistaken result as my alternative solution in the option 1.

For example, with line-spacing 0.2 I see 48.5 text lines visible in my
maximized window, but (window-screen-lines) evaluates to 46.66(6).

> You maybe want to use `window-end' combined with
> `pos-visible-in-window-p'.

Yep, this seems to be the most accurate approach, although probably the
slowest one. Thanks.

> What's the problem you want to solve, btw?

Count the screen lines in order to determine in which direction to
render the completion popup (below or above the current line).

I've linked to the related issue in the initial message.



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

* Re: How do I get the window height in lines, taking in account line-spacing?
       [not found]     ` <CAPhAwGyGvNy5rUf2M9jaE=kBrtZNDo_Ey+F6Oq2VqzZB+OoKEA@mail.gmail.com>
@ 2014-08-04 19:16       ` Dmitry Gutov
       [not found]       ` <mailman.6572.1407179803.1147.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 13+ messages in thread
From: Dmitry Gutov @ 2014-08-04 19:16 UTC (permalink / raw)
  To: John W Higgins; +Cc: help-gnu-emacs

On 08/04/2014 10:43 PM, John W Higgins wrote:
> It would appear for the purpose of the issue you are discussing that a
> smaller number would not matter because at worst you would put the popup
> above the line for 2 extra rows.

True, that drawback is not critical.

> That would, to me at least, be
> irrelevant to solving the problem. I appreciate the need for accuracy -
> but this would at least fail in a good way for you.

That might be so, but I'm already solving a non-critical problem: 
drawing popup better for users who customized the line-spacing value, 
which is a relatively rare thing to do, I believe.

So as long as I'm doing that, I might as well look for a good solution.

> I'm assuming you have not discovered a scenario where the calculation,
> for example, comes up with 50.5 lines for 49 actual visible lines.

Indeed, I haven't.



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

* Re: How do I get the window height in lines, taking in account line-spacing?
       [not found]       ` <mailman.6572.1407179803.1147.help-gnu-emacs@gnu.org>
@ 2014-08-05  0:11         ` Emanuel Berg
  2014-08-05  0:45           ` Dmitry
  0 siblings, 1 reply; 13+ messages in thread
From: Emanuel Berg @ 2014-08-05  0:11 UTC (permalink / raw)
  To: help-gnu-emacs

Dmitry Gutov <dgutov@yandex.ru> writes:

> So as long as I'm doing that, I might as well look
> for a good solution.

In my efforts to get civilized scrolling [1], I wrote
something that might fit - should fit, if it doesn't, I
want to now :)

(defun get-window-lines ()
  (let*((edges  (window-inside-edges))
        (top    (nth 1 edges))
        (bottom (nth 3 edges))
        (lines  (- bottom top)) )
    (if (or (string= major-mode "w3m-mode")
            (string= major-mode "package-menu-mode"))
        (1- lines) lines) ))

[1] http://user.it.uu.se/~embe8573/conf/emacs-init/scroll.el        

-- 
underground experts united


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

* Re: How do I get the window height in lines, taking in account line-spacing?
  2014-08-05  0:11         ` Emanuel Berg
@ 2014-08-05  0:45           ` Dmitry
  0 siblings, 0 replies; 13+ messages in thread
From: Dmitry @ 2014-08-05  0:45 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <embe8573@student.uu.se> writes:

> In my efforts to get civilized scrolling [1], I wrote
> something that might fit - should fit, if it doesn't, I
> want to now :)

Nope, this doesn't take line-spacing into account either.

Try this: (setq-default line-spacing 0.2)

And then M-x linum-mode, so that you can see the number of lines
yourself.  (get-window-lines) will return a value larger than the amount
of lines that is visible in a window.



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

* Re: How do I get the window height in lines, taking in account line-spacing?
  2014-08-04 18:31   ` Dmitry
       [not found]     ` <CAPhAwGyGvNy5rUf2M9jaE=kBrtZNDo_Ey+F6Oq2VqzZB+OoKEA@mail.gmail.com>
@ 2014-08-05  1:41     ` Dmitry
  2014-08-05  1:42     ` Dmitry
  2 siblings, 0 replies; 13+ messages in thread
From: Dmitry @ 2014-08-05  1:41 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs

Dmitry <dgutov@yandex.ru> writes:
> Michael Heerdegen <michael_heerdegen@web.de> writes:
>> You maybe want to use `window-end' combined with
>> `pos-visible-in-window-p'.
>
> Yep, this seems to be the most accurate approach, although probably the
> slowest one. Thanks.

Looks like this isn't good enough either: if the window is longer than
the buffer, the value we get this way only reflects the number of lines
in the buffer.



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

* Re: How do I get the window height in lines, taking in account line-spacing?
  2014-08-04 18:31   ` Dmitry
       [not found]     ` <CAPhAwGyGvNy5rUf2M9jaE=kBrtZNDo_Ey+F6Oq2VqzZB+OoKEA@mail.gmail.com>
  2014-08-05  1:41     ` Dmitry
@ 2014-08-05  1:42     ` Dmitry
  2014-08-05 11:55       ` Michael Heerdegen
  2 siblings, 1 reply; 13+ messages in thread
From: Dmitry @ 2014-08-05  1:42 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs

Dmitry <dgutov@yandex.ru> writes:
> Michael Heerdegen <michael_heerdegen@web.de> writes:
>> You maybe want to use `window-end' combined with
>> `pos-visible-in-window-p'.
>
> Yep, this seems to be the most accurate approach, although probably the
> slowest one. Thanks.

Looks like this isn't good enough either: if the window is longer than
the buffer, the value we get this way only reflects the number of lines
in the buffer.



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

* Re: How do I get the window height in lines, taking in account line-spacing?
  2014-08-05  1:42     ` Dmitry
@ 2014-08-05 11:55       ` Michael Heerdegen
  2014-08-05 12:11         ` Dmitry
  0 siblings, 1 reply; 13+ messages in thread
From: Michael Heerdegen @ 2014-08-05 11:55 UTC (permalink / raw)
  To: help-gnu-emacs

Dmitry <dgutov@yandex.ru> writes:

> Looks like this isn't good enough either: if the window is longer than
> the buffer, the value we get this way only reflects the number of
> lines in the buffer.

Maybe working with pixel coordinates is better suited for your case,
e.g. use `posn-x-y' (for the event position),
`window-inside-pixel-edges'.  Can you calculate how long your menu will
be, measured in pixels?




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

* Re: How do I get the window height in lines, taking in account line-spacing?
  2014-08-05 11:55       ` Michael Heerdegen
@ 2014-08-05 12:11         ` Dmitry
  2014-08-05 12:22           ` Michael Heerdegen
  0 siblings, 1 reply; 13+ messages in thread
From: Dmitry @ 2014-08-05 12:11 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs

Michael Heerdegen <michael_heerdegen@web.de> writes:

> Can you calculate how long your menu will be, measured in pixels?

Nope. I'd need the line height in pixels for that, too.



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

* Re: How do I get the window height in lines, taking in account line-spacing?
  2014-08-05 12:11         ` Dmitry
@ 2014-08-05 12:22           ` Michael Heerdegen
  2014-08-06 13:56             ` Dmitry
  0 siblings, 1 reply; 13+ messages in thread
From: Michael Heerdegen @ 2014-08-05 12:22 UTC (permalink / raw)
  To: help-gnu-emacs

Dmitry <dgutov@yandex.ru> writes:

> > Can you calculate how long your menu will be, measured in pixels?
>
> Nope. I'd need the line height in pixels for that, too.

`line-pixel-height'?




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

* Re: How do I get the window height in lines, taking in account line-spacing?
  2014-08-05 12:22           ` Michael Heerdegen
@ 2014-08-06 13:56             ` Dmitry
  2014-08-06 14:47               ` Eli Zaretskii
  0 siblings, 1 reply; 13+ messages in thread
From: Dmitry @ 2014-08-06 13:56 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs

Michael Heerdegen <michael_heerdegen@web.de> writes:

> `line-pixel-height'?

Hmm, guess I could use that. Eli has fixed the problem with
`window-screen-lines', though (http://debbugs.gnu.org/18195), so I went
with that.



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

* Re: How do I get the window height in lines, taking in account line-spacing?
  2014-08-06 13:56             ` Dmitry
@ 2014-08-06 14:47               ` Eli Zaretskii
  0 siblings, 0 replies; 13+ messages in thread
From: Eli Zaretskii @ 2014-08-06 14:47 UTC (permalink / raw)
  To: Dmitry; +Cc: michael_heerdegen, help-gnu-emacs

> From: Dmitry <dgutov@yandex.ru>
> Date: Wed, 06 Aug 2014 17:56:50 +0400
> Cc: help-gnu-emacs@gnu.org
> 
> Michael Heerdegen <michael_heerdegen@web.de> writes:
> 
> > `line-pixel-height'?
> 
> Hmm, guess I could use that.

It only works on lines that show text.  You sometimes need to know how
much space is available at the window bottom even if there's no text
there (i.e. beyond EOB).



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

end of thread, other threads:[~2014-08-06 14:47 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-04 12:11 How do I get the window height in lines, taking in account line-spacing? Dmitry Gutov
2014-08-04 14:17 ` Michael Heerdegen
2014-08-04 18:31   ` Dmitry
     [not found]     ` <CAPhAwGyGvNy5rUf2M9jaE=kBrtZNDo_Ey+F6Oq2VqzZB+OoKEA@mail.gmail.com>
2014-08-04 19:16       ` Dmitry Gutov
     [not found]       ` <mailman.6572.1407179803.1147.help-gnu-emacs@gnu.org>
2014-08-05  0:11         ` Emanuel Berg
2014-08-05  0:45           ` Dmitry
2014-08-05  1:41     ` Dmitry
2014-08-05  1:42     ` Dmitry
2014-08-05 11:55       ` Michael Heerdegen
2014-08-05 12:11         ` Dmitry
2014-08-05 12:22           ` Michael Heerdegen
2014-08-06 13:56             ` Dmitry
2014-08-06 14:47               ` Eli Zaretskii

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