Subject: bug#13956: 24.3; An initial frame already exists before reading .emacs on daemon mode

From: [email-masked]
Date: Wed, 14 Jun 2017 20:02:11 -0400

tags 13956 notabug wontfix
close 13956
quit

Arthur Tu <[email-masked]> writes:

> I want to call emacsclient to edit my file after start emacs
> server once manually.
>
> I have following code in my .emacs:
>
> (defun set-frame ()
>   (interactive)
>   ;;(setq initial-frame-alist '((width . 80) (height . 20)
> (menu-bar-lines . 1)))
>   (progn
>     ;; use 120 char wide window for largeish displays
>     ;; and smaller 80 column windows for smaller displays
>     ;; pick whatever numbers make sense for you
>     (if (> (x-display-pixel-width) 1280)
>     (add-to-list 'default-frame-alist (cons 'width 120))
>       (add-to-list 'default-frame-alist (cons 'width 120)))
>     ;; for the height, subtract a couple hundred pixels
>     ;; from the screen height (for panels, menubars and
>     ;; whatnot), then divide by the height of a char to
>     ;; get the height we want
>     (add-to-list 'default-frame-alist
>          (cons 'height (/ (- (x-display-pixel-height) 250)
>                   (frame-char-height))))
>     ))
>
> (add-hook 'after-init-hook
>       ;; ask user whether to restore desktop at start-up
>       (lambda ()
>         (if initial-window-system
>         (set-frame)
>           (add-hook 'server-visit-hook 'set-frame))))
>
> However, the first emacsclient frame can't be set to the size i want.
>
> I don't know if this bug is in cygwin branch only or global.
>
> Help please.

In daemon mode, the initial frame stays hidden, so there's no meaningful
size.  You should do something like

    (if (and (not (daemonp)) initial-window-system)
       ...)