Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Minimal config https://www.refheap.com/18816

Scenario 1.

  • Run 'emacs' from terminal.
  • M-x server-start
  • Run 'emacsclient -c' from terminal.
  • Effect: Theme applied.

Scenario 2.

  • Run 'emacs --daemon' from terminal
  • Run 'emacsclient -c'
  • Effect: Theme is not applied.

Why is that?

.emacs.d/init.d config:

(require 'package)
(package-initialize)

(defun install-pack (p)
"A utility function to help in installing emacs package."
(unless (package-installed-p p) (package-install p)))

(defun install-packs (packs)
"A utility function to help in installing emacs packages."
(unless package-archive-contents
        (package-refresh-contents))
(dolist (p packs) (install-pack p)))

;(load-theme 'tronesque)
(load-theme 'tronesque t)

or

;(load-theme 'tronesque)
;;(load-theme 'tronesque t)
(custom-set-variables
;; custom-set-variables was added by Custom.
'(custom-enabled-themes (quote (tronesque)))
'(custom-safe-themes (quote    ("b8f561a188a77e450ab8a060128244c81dea206f15c1152a6899423dd607b327" default))))
 (custom-set-faces
 ;; custom-set-faces was added by Custom.
 )
like image 250
Ace Rimmer Avatar asked Sep 19 '13 20:09

Ace Rimmer


3 Answers

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.

like image 71
handsomeyang Avatar answered Oct 20 '22 22:10

handsomeyang


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

like image 8
Geyslan G. Bem Avatar answered Oct 20 '22 21:10

Geyslan G. Bem


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.

like image 3
jomis Avatar answered Oct 20 '22 22:10

jomis