centaur-tabs icon indicating copy to clipboard operation
centaur-tabs copied to clipboard

Tabs don't show properly when running from emacsclient

Open nixin72 opened this issue 5 years ago • 15 comments

I use systemctl to start an Emacs server running as a daemon, and then whenever I open Emacs I use emacsclient. However, when I use emacsclient, centaur-tabs doesn't seem to display properly.

Without changing my config at all, here's centaur-tabs when using emacsclient image And here's it using regular Emacs. image

If I try disabling centaur-tabs-mode and re-enabling it, it doesn't make a difference, I just can't seem to get it to work using emacsclient.

nixin72 avatar Oct 01 '20 00:10 nixin72

I'm aware of this. PR #122 should fix this, but I'm yet to review it.

ema2159 avatar Oct 01 '20 16:10 ema2159

Oh, my bad, I didn't see that! I looked at the open issues to see if there was anything about this, but didn't look for open PRs.

I'll switch to that branch in the meantime, thank you so much!

nixin72 avatar Oct 01 '20 16:10 nixin72

Please don't hesitate to tell the PR author about any problems that may arise!

ema2159 avatar Oct 01 '20 16:10 ema2159

Your client mode issue might be related to the daemon launching in the terminal. You could test that by reloading your init from the client. If that fixes it, you would only need to isolate the code that isn't initializing and put it in a function that evaluates when the client launches, e.g. emacsclient.exe -c -n -a "" -e '(your-custom-function).'

In other news, just now explore centaur-tabs. Is there a quick way I missed to gather select buffers into a group?

cloudnine avatar Oct 07 '20 18:10 cloudnine

I also use emacsclient and when I opened a new client centaur-tabs-set-bar and centaur-tabs-show-navigation-buttons didn't work. I ended solving it by enabling centaur-tabs-mode on server-after-make-frame-hook: (add-hook 'server-after-make-frame-hook 'centaur-tabs-mode) Hope this helps solving your issue!

vpcano avatar Oct 22 '20 13:10 vpcano

I'm also having this issue. I've used your hook @vpcano and it doesn't work for me

jhilker98 avatar Nov 08 '20 19:11 jhilker98

I've updated #122 and ~~it now works for me.~~ CORRECTION: My issues, which do not include the issue described by OP, appear to be fixed by it.

If you start the daemon mode without display graphics, load centaur-tabs, and then later connect with a frame that is display graphics capable, some faces may not have been setup correctly, though. I don't think that is a centaur-tabs bug strictly speaking, but I'm not sure, so I haven't included the fix for that in my PR.

One way to work around that is to enable centaur-tabs like this (somewhere in one's init.el):

;; Enable centaur-tabs without faulty theming in daemon mode.
(if (not (daemonp))
	 (centaur-tabs-mode)

  (defun centaur-tabs-daemon-mode (frame)
	 (unless (and (featurep 'centaur-tabs) (centaur-tabs-mode-on-p))
		(run-at-time nil nil (lambda () (centaur-tabs-mode)))))
  (add-hook 'after-make-frame-functions #'centaur-tabs-daemon-mode))

Note the run-at-time with immediate timeout: Without that delay until "first idle", the faces may still be broken (and themes may look wrong).

MoritzMaxeiner avatar Dec 13 '20 16:12 MoritzMaxeiner

I've updated #122 and ~it now works for me.~ CORRECTION: My issues, which do not include the issue described by OP, appear to be fixed by it.

If you start the daemon mode without display graphics, load centaur-tabs, and then later connect with a frame that is display graphics capable, some faces may not have been setup correctly, though. I don't think that is a centaur-tabs bug strictly speaking, but I'm not sure, so I haven't included the fix for that in my PR.

One way to work around that is to enable centaur-tabs like this (somewhere in one's init.el):

;; Enable centaur-tabs without faulty theming in daemon mode.
(if (not (daemonp))
	 (centaur-tabs-mode)

  (defun centaur-tabs-daemon-mode (frame)
	 (unless (and (featurep 'centaur-tabs) (centaur-tabs-mode-on-p))
		(run-at-time nil nil (lambda () (centaur-tabs-mode)))))
  (add-hook 'after-make-frame-functions #'centaur-tabs-daemon-mode))

Note the run-at-time with immediate timeout: Without that delay until "first idle", the faces may still be broken (and themes may look wrong).

Not work.

c02y avatar Aug 07 '21 04:08 c02y

The problem is centaur-tabs-set-bar, if it is left, then the whole tab bar will be empty.

Besides I'm using Spaemacs, under or over will not work at all(https://github.com/ema2159/centaur-tabs/issues/86).

c02y avatar Aug 07 '21 04:08 c02y

I confirm the bug as described by @c02y

lebensterben avatar Jan 25 '22 04:01 lebensterben

I solved the problem by applying a "dirty hack", waiting for a fix. I added these lines of code to my init.el file (defun tdr/fix-centaur-tabs () (centaur-tabs-mode -1) (centaur-tabs-mode) (centaur-tabs-headline-match)

) (if (daemonp) (add-hook 'after-make-frame-functions (lambda (frame) (with-selected-frame frame (tdr/fix-centaur-tabs))) (tdr/fix-centaur-tabs)) )

Each time a new frame is ceated, centaur-tabs-mode is switched off and switched on again. No issue so far. I hope this may be useful to other users

uskebasi avatar May 15 '22 11:05 uskebasi

As none of suggested hacks work for me, fix for this problem would be greatly appreciated. Thank you.

dusanx avatar Apr 14 '23 19:04 dusanx

Well, the workaround that solved the issue for me was restarting centaur tabs all the times that I focus on an emacs window:

(defun tdr/fix-centaur-tabs ()
  "Reset Centaur Tabs."
  (centaur-tabs-mode -1) ; Disable Centaur Tabs
  (centaur-tabs-mode 1)  ; Re-enable Centaur Tabs
  (centaur-tabs-headline-match)) ; Update tabs

(add-hook 'focus-in-hook 'tdr/fix-centaur-tabs)

ramuyk avatar Dec 09 '23 04:12 ramuyk

Thanks @ramuyk , that snippet seems to work well, if I spot anything wrong I'll report here.

dusanx avatar Dec 11 '23 00:12 dusanx

None of the above proposed solutions worked for me either. In case it helps anyone, the following snippet fixes the rendering issue and is compatible with emacs and emacsclient.

(use-package centaur-tabs
  :custom
  (centaur-tabs-style "bar")
  (centaur-tabs-set-bar 'left)
  ;; other settings here
  :init
  (if (daemonp)
      (add-hook 'server-after-make-frame-hook 'centaur-tabs-mode)
    (add-hook 'after-init-hook 'centaur-tabs-mode))
  )

The tricky thing is that, as in the sample configuration in the repo's README.org, :demand is needed so that the tabs are displayed after the frame is initialized. But, :demand broke compatibility with emacsclient for me. I encountered some other quirks too, but the TLDR is that the above snippet handled those quirks (for example, in emacs, the scratch buffer icon would prematurely display the ELisp icon before updating to the Lisp Interaction icon), whereas previous attempts involving different combinations of :config, :init, and hooks broke compatibility with emacsclient, emacs, or both.

Lastly, note that I only needed the above workaround when centaur-tabs-set-bar was set to 'left. For 'over or 'under, a typical configuration such as below suffices:

(use-package centaur-tabs
  :demand
  :custom
  (centaur-tabs-style "bar")
  (centaur-tabs-set-bar 'over)
  ;; (x-underline-at-descent-line t) ;; for 'under
  ;; other settings here
  :config
  (centaur-tabs-mode)
  )

ahan98 avatar Dec 27 '23 11:12 ahan98