After 'emacs --deamon' I can not see new theme in emacsclient frame. It works from 'emacs M-x server-start'

妖精的绣舞 提交于 2019-12-03 05:32:21

For Emacs 24,

(if (daemonp)
    (add-hook 'after-make-frame-functions
        (lambda (frame)
            (select-frame frame)
            (load-theme 'tronesque t)))
    (load-theme 'tronesque t))

or

(if (daemonp)
    (add-hook 'after-make-frame-functions
        (lambda (frame)
            (with-selected-frame frame
                (load-theme 'tronesque t))))
    (load-theme 'tronesque t))

should do.

Using all mentioned approaches the theme is being reloaded in vain starting from the second frame creation.

For loading it only one time I did:

(if (daemonp)
    (add-hook 'after-make-frame-functions (lambda (frame)
                        (when (eq (length (frame-list)) 2)
                            (progn
                              (select-frame frame)
                              (load-theme 'tronesque)))))
  (load-theme 'tronesque 1))

Update

After some tests in Emacs 24.5.1 with the distinguished theme and using emacs as daemon, I have got some issues.

If my first client is a terminal emacsclient -t and later I open a window client emacsclient -c, the window client loses theme configurations.

Then I came up with this solution:

;; theme
(defvar my:theme 'distinguished)
(defvar my:theme-window-loaded nil)
(defvar my:theme-terminal-loaded nil)

(if (daemonp)
    (add-hook 'after-make-frame-functions(lambda (frame)
                       (select-frame frame)
                       (if (window-system frame)
                           (unless my:theme-window-loaded
                             (if my:theme-terminal-loaded
                                 (enable-theme my:theme)
                               (load-theme my:theme t))
                             (setq my:theme-window-loaded t))
                         (unless my:theme-terminal-loaded
                           (if my:theme-window-loaded
                               (enable-theme my:theme)
                             (load-theme my:theme t))
                           (setq my:theme-terminal-loaded t)))))

  (progn
    (load-theme my:theme t)
    (if (display-graphic-p)
        (setq my:theme-window-loaded t)
      (setq my:theme-terminal-loaded t))))

It's not so elegant, I know, but solves the two problems (unnecessary reloading and lost of config).

The following extension of the above answer fixed the problem for me with Emacs 24, setting the color-theme via the color-theme call, as shown with the solarized theme.

(if (daemonp)
(add-hook 'after-make-frame-functions
          '(lambda (f)
             (with-selected-frame f
               (when (window-system f) (color-theme-solarized-dark)))))
(color-theme-solarized-dark))

HTH

J.

Since it's a daemon startup, there was no any frame created when the load-theme function was involved. After the startup, you created a new frame by entering `emacsclient -c', nothing happened of course.

So you have to tell emacs to apply the theme after frames are created. The hook after-make-frame-functions is made for that:

(if (daemonp)
    (add-hook 'after-make-frame-functions
              (lambda (frame)
                (load-theme 'tronesque t)))
    (load-theme 'tronesque t))

If it's a daemon startup, load theme after frames are created, otherwise load theme directly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!