Subject: bug#37563: 27.0.50; fit-frame-to-buffer does not account for line-spacing

From: Ingo Lohmar <[email-masked]>
Date: Mon, 30 Sep 2019 20:41:08 +0200

I noticed the behavior due to company-posframe, which uses the posframe
package to show a completion popup frame.  The frame size is set using
window.el's `fit-frame-to-buffer'.  Some time ago, the call was changed
to provide the explicit frame max-height in terms of lines, which
exposed the following behavior:

If (default-value line-spacing) is the usual 0, the height of the popup
frame is correct, ie, all lines are fully shown.  If, however,
(default-value line-spacing) is 1 or larger (as in my setup), the bottom
of the popup frame cuts off parts of the lowest line.

I do not understand all the details, but it here's what my debugging
shows: 

1) When max-height is provided, the actual frame height is calculated in
ll 8736ff of window.el (as of commit
5746202c182a9c69c732beb29b8507a6e6364799), and that just multiplies by
the char-height, which excludes the line-spacing.  This is the buggy
case.

2) When max-height is NOT provided, the above lines set max-height to
the total (parent frame) height, and the popup frame size is calculated
only when reaching l 8767.  This yields a larger height, correctly
accounting for the line-spacing.

Hope this helps and can be easily fixed.  Thanks!

Ingo

In GNU Emacs 27.0.50 (build 24, x86_64-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
 of 2019-02-16 built on kenko
Repository revision: aff0c585060b7cc92d52a32978c6aa64cf7e2a5e
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12004000
System Description: Debian GNU/Linux bullseye/sid

Recent messages:
1
Evaluating...
Showing all blocks ... done
nil [3 times]
Evaluating...
Showing all blocks ... done
nil [2 times]
t
Saving file /home/il/Documents/emacs/emacs.org...
Wrote /home/il/Documents/emacs/emacs.org

Configured using:
 'configure --with-imagemagick --without-gsettings --without-gconf
 --with-x-toolkit=lucid --with-modules'

Configured features:
XAW3D XPM JPEG TIFF GIF PNG RSVG SOUND GPM DBUS GLIB NOTIFY INOTIFY ACL
LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS LUCID X11 XDBE XIM MODULES THREADS PDUMPER GMP

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Org

Minor modes in effect:
  semantic-minor-modes-format: ((:eval (if (or semantic-highlight-edits-mode semantic-show-unmatched-syntax-mode)  S)))
  TeX-PDF-mode: t
  TeX-source-correlate-mode: t
  magit-todos-mode: t
  global-magit-file-mode: t
  global-git-commit-mode: t
  async-bytecomp-package-mode: t
  server-mode: t
  buffer-face-mode: t
  org-indent-mode: t
  shell-dirtrack-mode: t
  diff-auto-refine-mode: t
  global-flycheck-mode: t
  dired-async-mode: t
  mimuma-global-mode: t
  global-hl-todo-mode: t
  pollen-global-mode: t
  counsel-mode: t
  ivy-mode: t
  amx-mode: t
  minibuffer-depth-indicate-mode: t
  savehist-mode: t
  enchive-mode: t
  xterm-mouse-mode: t
  ws-butler-global-mode: t
  ws-butler-mode: t
  global-auto-revert-mode: t
  my/window-number-mode: t
  desktop-save-mode: t
  company-posframe-mode: t
  company-statistics-mode: t
  global-company-mode: t
  company-mode: t
  show-paren-mode: t
  electric-pair-mode: t
  beginend-global-mode: t
  beginend-org-mode: t
  beginend-outline-mode: t
  global-undo-tree-mode: t
  undo-tree-mode: t
  delete-selection-mode: t
  guide-key-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  global-prettify-symbols-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  size-indication-mode: t
  column-number-mode: t
  line-number-mode: t
  auto-fill-function: org-auto-fill-function
  transient-mark-mode: t

Load-path shadows:
[... elided ...]

Features:
(shadow sort emacsbug sendmail mail-extr edebug timezone dired-x
mule-diag ox-org ox-odt ox-latex ox-icalendar ox-html table ox-ascii
ox-publish ox my-grep cl-print ielm quail systemd preview prv-emacs
reftex-dcr reftex-auc reftex-toc-patch reftex-toc reftex-config reftex
reftex-loaddefs reftex-vars tex-buf font-latex latex-config my-fill
latex-addons latex-mode-expansions latex latex-flymake tex-ispell
tex-style tex-config tex tex-mode hippie-expand-config my-mode-groups
hippie-expand-addons my-flex-search hippie-exp pkg-info epl
network-stream cider cider-debug cider-inspector cider-browse-ns
cider-repl-history two-column iso-transl org-attach ess-r-mode
ess-r-flymake ess-r-xref ess-trns ess-r-package ess-r-completion
ess-roxy ess-r-syntax ess-rd ess-s-lang ess-help ess-mode ess-inf
ess-tracebug ess ess-utils ess-custom magit-bookmark bookmark
org-capture cal-move cs-mode cc-langs sql-config sql-addons sql rng-xsd
xsd-regexp rng-cmpct nxml-addons nxml-mode-expansions rng-nxml rng-valid
rng-loc rng-uri rng-parse nxml-parse rng-match rng-dt rng-util rng-pttrn
nxml-ns nxml-mode nxml-outln nxml-rap nxml-util nxml-enc xmltok solar
cal-dst holidays hol-loaddefs cal-iso org-addons window-addons
my-window-funs pulse misearch multi-isearch shell-addons my-completion
magit-extras magit-addons magit-config magit-bundle magit-todos pcre2el
rxt re-builder f wgrep-patch wgrep grep-config grep forge-config
forge-list forge-commands forge-semi forge-bitbucket buck forge-gogs
gogs forge-gitea gtea forge-gitlab glab forge-github ghub-graphql treepy
gsexp ghub let-alist gnutls forge-notify forge-revnote forge-pullreq
forge-issue forge-topic bug-reference forge-post forge-repo forge
forge-core forge-db closql emacsql-sqlite emacsql emacsql-compiler
url-http url-auth url-gw nsm magit-submodule magit-obsolete magit-blame
magit-stash magit-reflog magit-bisect magit-push magit-pull magit-fetch
magit-clone magit-remote magit-commit magit-sequence magit-notes
magit-worktree magit-tag magit-merge magit-branch magit-reset
magit-files magit-refs magit-status magit magit-repos-addons tablist
tablist-filter semantic/wisent/comp semantic/wisent
semantic/wisent/wisent semantic/util-modes semantic/util semantic
semantic/tag semantic/lex semantic/fw mode-local cedet magit-repos
magit-apply magit-wip magit-log which-func magit-diff smerge-config
smerge-mode magit-core magit-autorevert magit-margin magit-transient
magit-process magit-mode transient git-commit magit-git magit-section
magit-utils log-edit pcvs-util add-log with-editor async-bytecomp
hi-lock eieio-opt speedbar sb-image ezimage dframe em-unix em-term term
ehelp em-script em-prompt em-ls em-hist em-pred em-glob em-dirs em-cmpl
em-basic em-banner em-alias windmove tabify server time notmuch-config
notmuch-addons notmuch-patch notmuch hl-line notmuch-hello notmuch-tree
notmuch-show notmuch-print notmuch-crypto notmuch-mua notmuch-message
notmuch-draft notmuch-maildir-fcc notmuch-address notmuch-company
notmuch-parser notmuch-wash coolj notmuch-query icalendar diary-lib
diary-loaddefs notmuch-tag crm notmuch-lib notmuch-version
notmuch-compat cl message rmc rfc822 mml mailabbrev gmm-utils mailheader
mm-view mml-smime mml-sec epa epg smime dig mm-decode mm-bodies
mm-encode mail-parse rfc2231 wconf racket-mode racket-bug-report
racket-collection racket-stepper racket-logger racket-profile
racket-imenu racket-edit racket-complete racket-repl ido racket-common
racket-parens racket-indent racket-font-lock racket-util racket-ppss
racket-keywords-and-builtins racket-custom vimrc-mode ngo make-mode
gitconfig-mode macrostep-c cmacexp my/publish-blog fish-mode mhtml-mode
skewer-html sh-flymake-backends sh-script executable skewer-css
company-skewer skewer-addons skewer-repl skewer-mode cache-table
js2-mode-expansions js2-mode js-config js-patch js-mode-expansions js
cc-mode-expansions cc-mode cc-fonts cc-guess cc-menus cc-cmds cc-styles
cc-align cc-engine cc-vars cc-defs simple-httpd css-mode-expansions
css-mode smie html-mode-expansions sgml-mode eww mm-url gnus nnheader
gnus-util rmail rmail-loaddefs rfc2047 rfc2045 ietf-drums mail-utils
cus-edit cus-start cus-load wid-edit url-queue shr text-property-search
puny svg dom conf-mode markdown-mode edit-indirect pyvenv-config pyvenv
esh-var esh-cmd esh-opt esh-io esh-ext esh-proc esh-arg esh-groups
eshell-config eshell esh-module esh-mode esh-util python-config
python-el-fgallina-expansions python tramp-sh geiser-config geiser-mode
geiser-xref geiser-compile geiser-debug geiser-patch geiser-gambit
geiser-chibi geiser-mit geiser-chez geiser-chicken geiser-racket
geiser-guile info-look geiser-repl geiser-image geiser-company
geiser-doc geiser-menu geiser-edit geiser-completion geiser-autodoc
geiser-eval geiser-connection tq geiser-syntax geiser-log geiser-popup
view scheme cider-mode cider-completion cider-profile cider-eval
cider-repl cider-resolve cider-eldoc cider-test cider-stacktrace
cider-doc cider-browse-spec cider-clojuredocs cider-popup cider-overlays
cider-client cider-common cider-util cider-connection sesman-browser
nrepl-client tramp tramp-loaddefs trampver tramp-compat ucs-normalize
parse-time queue nrepl-dict cider-compat spinner parseedn
parseclj-parser parseclj-lex a clojure-mode-expansions sesman
clojure-mode lisp-mnt align org-duration slime-config slime-fancy
slime-trace-dialog slime-fontifying-fu slime-package-fu slime-references
slime-compiler-notes-tree slime-scratch slime-presentations bridge
slime-macrostep macrostep slime-mdot-fu slime-enclosing-context
slime-fuzzy slime-fancy-trace slime-fancy-inspector slime-c-p-c
slime-editing-commands slime-autodoc slime-addons slime-repl slime-parse
slime arc-mode archive-mode hyperspec browse-url imenu go-config go-guru
go-flymake-backends my-flymake-addons go-mode derived url url-proxy
url-privacy url-expand url-methods url-history url-cookie url-domsuf
mailcap find-file ffap face-remap org-indent image-file org-table
disp-table vc-hg vc-src vc-svn my-misc-funs elisp-addons subword-patch
subword-mode-expansions cap-words superword subword goto-addr
idle-highlight-mode rainbow-delimiters hideshow outshine
outshine-org-cmds outorg org-capture-config org-config my-org-contacts
org-protocol org-irc org-info org-id org-docview doc-view jka-compr
image-mode org-bibtex org-element avl-tree bibtex-config
bibtex-clean-addons bibtex ob-scheme geiser-impl help-fns radix-tree
geiser-custom geiser-base geiser ob-dot ob-js ob-sql ob-latex ob-python
ob-shell shell-config shell org-clock org-agenda the-org-mode-expansions
org ob ob-tangle ob-ref ob-lob ob-table ob-exp org-macro org-footnote
org-src ob-comint ob-keys org-pcomplete pcomplete org-list org-faces
org-entities time-date org-version ob-emacs-lisp ob-core ob-eval
org-compat org-macs org-loaddefs format-spec calendar-config cal-menu
calendar cal-loaddefs noutline outline vc-git diff-mode flycheck-config
flycheck faces-config ui-config comint-config dired-guess dired-subtree
dired-hacks-utils dired-async async dired-aux dired-config
modeline-config dired-patch ls-lisp-config ls-lisp-patch ls-lisp
mini-multi-major xref-addons my-eval-result-overlays my-solarized-colors
hl-todo flymake-config help-at-pt eglot-config eglot-patch eglot jsonrpc
array ert pp ewoc debug backtrace subr-x flymake-proc flymake warnings
url-util pollen compile-config compile-addons locals-patch my-project vc
vc-dispatcher counsel-addons counsel xdg dired dired-loaddefs compile
comint ansi-color swiper-addons swiper ivy-config ivy-hydra ivy flx
colir color ivy-overlay amx mb-depth savehist secrets dbus xml
enchive-mode xt-mouse ws-butler autorevert filenotify my-file-funs
desktop-config my-window-numbers display-actions desktop frameset
company-posframe posframe company-statistics company-keywords
company-dabbrev-code company-dabbrev etags-addons company-etags etags
fileloop generator xref project company-gtags company-template
company-capf company-elisp find-func company-config company sexp-addons
pcase paren elec-pair occur-config my-aux-funs easy-mmode beginend
ace-link avy multiple-cursors mc-hide-unmatched-lines-mode
mc-separate-operations rectangular-region-mode mc-mark-pop mc-mark-more
mc-cycle-cursors mc-edit-lines multiple-cursors-core rect expand-region
text-mode-expansions er-basic-expansions thingatpt expand-region-core
expand-region-custom undo-tree-patch undo-tree diff delsel indent-config
indent-addons mm-util mail-prsvr diminish guide-key advice s popwin dash
my-loaddefs edmacro kmacro cl-extra help-mode hydra ring lv
my-setup-funs mule-util info tex-site slime-autoloads rx package
easymenu epg-config url-handlers url-parse auth-source cl-seq eieio
eieio-core cl-macs eieio-loaddefs password-cache json map url-vars seq
byte-opt gv bytecomp byte-compile cconv cl-loaddefs cl-lib tooltip eldoc
electric uniquify ediff-hook vc-hooks lisp-float-type mwheel term/x-win
x-win term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode elisp-mode lisp-mode
prog-mode register page menu-bar rfn-eshadow isearch timer select
scroll-bar mouse jit-lock font-lock syntax facemenu font-core
term/tty-colors frame cl-generic cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932
hebrew greek romanian slovak czech european ethiopic indian cyrillic
chinese composite charscript charprop case-table epa-hook jka-cmpr-hook
help simple abbrev obarray minibuffer cl-preloaded nadvice loaddefs
button faces cus-face macroexp files text-properties overlay sha1 md5
base64 format env code-pages mule custom widget hashtable-print-readable
backquote threads dbusbind inotify dynamic-setting font-render-setting
x-toolkit x multi-tty make-network-process emacs)

Memory information:
((conses 16 5731969 544737)
 (symbols 48 74465 205)
 (strings 32 351286 127943)
 (string-bytes 1 10253755)
 (vectors 16 264560)
 (vector-slots 8 5833430 221798)
 (floats 8 1203 4037)
 (intervals 56 781876 5606)
 (buffers 992 301))