Subject: bug#5098: [NS] 23.1.50; display-pixel-height / display-pixel-width don't work in .emacs

From: Ian Eure <[email-masked]>
Date: Sat, 28 Nov 2009 15:30:29 -0800

I have a function which sets up the Emacs frame how I like it. This
involves centering the frame within the screen; since I run Emacs on
multiple systems, I calculate it based on the current screen
dimensions.

However, calling both display-pixel-height and display-pixel-width
return zero when called from my .emacs file. I added some debug messages
to emacs-startup-hook and window-setup-hook, and they return zero there
as well.

After Emacs has started, they return the correct values.

This is irritating, since I must manually call my function after Emacs
starts up.

Here’s a simple testcase:

(defun report-display-size ()
  (message "Screen dimensions are %dx%d"
    (display-pixel-width) (display-pixel-height)))

(add-hook 'window-setup-hook 'report-display-size)

 -> "Screen dimensions are 0x0"

M-: (report-display-size) RET

 -> "Screen dimensions are 1440x900"

In GNU Emacs 23.1.50.1 (x86_64-apple-darwin10.2.0, NS apple-appkit-1038.25)
 of 2009-11-27 on proton.local
Windowing system distributor `Apple', version 10.3.1038
configured using `configure  '--without-dbus' '--with-ns' 'CFLAGS=-pipe -O2 -march=nocona''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: nil
  value of $XMODIFIERS: nil
  locale-coding-system: nil
  default enable-multibyte-characters: t

Major mode: Magit

Minor modes in effect:
  erc-spelling-mode: t
  erc-ring-mode: t
  erc-pcomplete-mode: t
  erc-netsplit-mode: t
  erc-button-mode: t
  erc-fill-mode: t
  erc-autojoin-mode: t
  erc-match-mode: t
  erc-irccontrols-mode: t
  erc-noncommands-mode: t
  erc-readonly-mode: t
  erc-scrolltobottom-mode: t
  which-function-mode: t
  yas/minor-mode: t
  shell-dirtrack-mode: t
  ime-bindings: t
  show-paren-mode: t
  recentf-mode: t
  iswitchb-mode: t
  cua-mode: t
  auto-insert-mode: t
  tooltip-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  global-auto-composition-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
  transient-mark-mode: t
  abbrev-mode: t

Recent input:
f r o m SPC . e m a c s SPC o r SPC <M-backspace> <backspace> 
, SPC C-x o C-x b <return> C-x o C-n C-p C-n C-p C-x 
b H <return> C-x o C-x b <return> e m a c s - s t a 
r t u p h <backspace> - h o o k , M-q C-o C-o C-n C-n 
C-a C-c C-c C-p C-p C-e <help-echo> <down-mouse-1> 
<mouse-1> C-c C-b C-c C-b C-SPC C-M-f M-w C-x o SPC 
C-y C-x o C-p C-n C-p C-e C-b C-b C-b C-b C-b <return> 
C-x 1 M-< C-s - h o o k C-s C-s C-s C-s C-s C-s C-s 
C-s C-s C-s C-s C-s C-s C-s C-s C-s C-s C-s C-s C-s 
C-s C-s C-s C-s C-s C-s C-s C-s C-s C-s C-s C-s C-s 
C-s C-s C-s C-s C-x k RET C-n C-p C-n C-p C-x b C-g 
C-x b <return> C-n C-p M-b M-b M-b o r SPC C-e . M-q 
C-SPC C-p C-a M-w C-n C-n C-d C-x C-s C-c C-g n n n 
n n n n <tab> <tab> p p <tab> <return> C-n C-p C-p 
C-p C-p C-p C-p C-p C-p C-p C-n C-p C-n C-x C-t C-x 
C-s C-x b <return> g s c C o m m e n t SPC u p <backspace> 
<backspace> o u t SPC f r a m e - c e n t e r SPC c 
a l l , SPC i t SPC d o e n s ' t SPC w o r k SPC a 
t SPC a t s t <M-backspace> s t a r t u p SPC t i m 
e . C-c C-c M-x r e p o r t - e m <tab> <return>

Recent messages:
Mark set
Saving file /Users/ieure/Projects/dotfiles/emacs.d/ime-lisp/ime-top.el...
Mark set
Wrote /Users/ieure/Projects/dotfiles/emacs.d/ime-lisp/ime-top.el
(No files need saving)
Saving file /Users/ieure/Projects/dotfiles/emacs.d/ime-lisp/ime-top.el...
Mark set
Wrote /Users/ieure/Projects/dotfiles/emacs.d/ime-lisp/ime-top.el
Type C-c C-c to commit (C-c C-k to cancel).
Git finished.

Load-path shadows:
None found.

Features:
(shadow mail-extr emacsbug magit diff-mode log-edit pcvs-util add-log
parse-time ielm jka-compr find-func cua-rect rect dired-aux dired
cus-edit grep executable newcomment apropos dabbrev erc-spelling
flyspell ispell erc-ring erc-pcomplete pcomplete erc-netsplit erc-button
erc-fill erc-stamp erc-join help-mode view erc-track erc-match
erc-goodies erc erc-backend erc-compat pp multi-isearch vc-git
test-case-mode compile goto-addr light-symbol hi-lock thingatpt hl-line
eldoc which-func imenu ime-top ime-ns dpkg-dev-el dpkg-dev-el-loaddefs
ime-smarty ime-help ime-thrift ime-diff ime-org ime-m4 ime-markdown
ime-clojure swank-clojure-autoload ime-slime slime-autoloads ime-w3m
w3m-load ime-snippets dropdown-list yasnippet cl cl-19 ime-dired
ime-ibuffer edmacro kmacro ime-abbrev ime-inferior ime-erc ime-ssh
ime-sql ime-javascript ime-xml ime-html ime-sh ime-tcl ime-elisp
ime-python ime-php skeleton ime-vc ime-programming tramp-imap epa
derived epg epg-config imap-hash imap message sendmail ecomplete rfc822
mml mml-sec mm-decode mm-bodies mm-encode mailcap mail-parse rfc2231
rfc2047 rfc2045 qp ietf-drums mailabbrev nnheader mm-util mail-prsvr
gmm-utils mailheader canlock sha1 hex-util hashcash mail-utils assoc
tramp-gw tramp-fish tramp-smb tramp-cache tramp-ftp tramp-cmds tramp
regexp-opt auth-source gnus-util netrc time-date shell comint ring
password-cache format-spec tramp-compat trampver ime-inserts ime-editing
ime-bindings easy-mmode ime-vars ime-fonts ime-autoloads ime-frame
ibuf-ext ibuffer uniquify advice help-fns advice-preload paren server
recentf tree-widget wid-edit iswitchb cua-base autoinsert cus-start
cus-load tooltip ediff-hook vc-hooks lisp-float-type mwheel ns-win
easymenu tool-bar dnd fontset image fringe lisp-mode register page
menu-bar rfn-eshadow timer select scroll-bar mldrag mouse jit-lock
font-lock syntax facemenu font-core frame cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese hebrew
greek romanian slovak czech european ethiopic indian cyrillic chinese
case-table epa-hook jka-cmpr-hook help simple abbrev loaddefs button
minibuffer faces cus-face text-properties overlay md5 base64 format env
code-pages mule custom widget hashtable-print-readable backquote
make-network-process ns multi-tty emacs)