Can't change cursor color in emacsclient
Asked Answered
H

5

13

If I run emacs --daemon (in .xinitrc or later) and then emacsclient -c, newly created frame has black cursor color, regardless on colortheme or any other settings. More exactly, before I type anything, the cursor color is white (or other color), but with first keypresses it becomes black and cannot be changed via set-cursor-color. Both default and my custom colorthemes are black, so it makes editing very uncomfortable.

If I run emacs and M-x server-start instead of emacs --daemon then this problem does not appear. But this way I need to keep one emacs "main" frame and not kill it incidentally, this doesn't seem like a nice solution.

I have following block in .emacs.d/init.el but it doesn't help:

(set-cursor-color "red")
(setq initial-frame-alist '((cursor-color . "red")))
(setq default-frame-alist '((cursor-color . "red")))
(add-hook 'window-setup-hook '(lambda () (set-cursor-color "red")))
(add-hook 'after-make-frame-functions '(lambda (f) (with-selected-frame f (set-cursor-color "red"))))

If I run M-x describe-face RET cursor I get:

(...)
Defined in `faces.el'.

        Family: unspecified
       Foundry: unspecified
         Width: unspecified
        Height: unspecified
        Weight: unspecified
         Slant: unspecified
    Foreground: unspecified
    Background: black
     Underline: unspecified
      Overline: unspecified
Strike-through: unspecified
           Box: unspecified
       Inverse: unspecified
       Stipple: unspecified
          Font: unspecified
       Fontset: unspecified
       Inherit: unspecified
Honeycomb answered 20/11, 2011 at 20:6 Comment(1)
any news on the matter, did you find anything that worked in the end? I'm facing a similar issue where the color-theme won't be loaded by emacsclient, but emacs will happily apply my purple cursor.Mazzola
A
5

Alright.. This issue can be resolved by adding

(setq default-frame-alist '((cursor-color . "white")))

though I don't understand why it was not a problem before.

See this forum thread.

Amylopsin answered 31/12, 2014 at 17:39 Comment(0)
B
7

I believe that in recent Emacsen, using frame properties to set the cursor color is not the preferred method. So instead of using set-cursor-color or initial-frame-alist / default-frame-alist, try:

(set-face-background 'cursor "red")

Or, perhaps:

(set-face-attribute 'cursor nil :background "red"`)
Blucher answered 20/11, 2011 at 20:38 Comment(2)
Hmm, odd. I'll see if I can reproduce it.Blucher
I tried both too, but also without success. I'm also affected by this peculiar behaviour.Factious
S
5

Bwahahaha! I think no-one has posted a solution for the past 2 years because you are all EVIL emacs users!

Truth be told, I'm trying out evil-mode at the moment myself and I just solved this problem on my system. Put this in your .emacs file and smoke it:

'(evil-default-cursor (quote (t "white")))

I just opened a bug against the Evil repository in bitbucket.

For myself, I found that after the 6 years or so it took to really become proficient at emacs, the multi-key chords were hard on my tendons. Evil-mode may allow me to use emacs again, which is a good thing. As Benedict says (in the context of Functional Programming), "Some evil is often necessary to get work done." It seems that may apply to Emacs as well.

P.S. For anyone feels this answer is just DH0 or otherwise immature and inappropriate, the mostly tongue-in-cheek feud between Emacs and VI users has raged for years. Emacs has it's own Church of Emacs, VI has the video game, World War VI. So it is no surprise that the most successful port of VI keybindings to Emacs was named evil-mode (evil has the word VI in it). I like both editors and laud the evil developers who finally made VI keybindings work inside emacs.

Stricklan answered 11/10, 2013 at 14:57 Comment(2)
Thanks Glen, I'm EVIL user already (though I never use normal mode/state). I corrected your command (replaced ' with setq). It seems to work well for me. And even if for some reason cursor goes black again, I can repeat the command.Honeycomb
Since this is the only solution that works for me I'm accepting your answer. Though it's a bit unfair for emacs user who are not EVIL fans.Honeycomb
A
5

Alright.. This issue can be resolved by adding

(setq default-frame-alist '((cursor-color . "white")))

though I don't understand why it was not a problem before.

See this forum thread.

Amylopsin answered 31/12, 2014 at 17:39 Comment(0)
T
1

This worked for me :

(setq evil-default-cursor t) ;; Now evil takes the default cursors 
(set-cursor-color "white") ;; Set it to white
(set-mouse-color "white") ;; Same
Translatable answered 15/1, 2014 at 11:11 Comment(0)
S
0

I also have the very same issue, for years now.

In my case I do:

M-x
set-cursor-color
"white"<ENTER>

That works for me but I have to do this everytime, which sux..

Back in my old workplace I had this solved but I don't have the init.el that I used to have in my old workplace and now I need to figure this out all over again, hopefully someone in here will figure this out before me.

Syriac answered 9/7, 2013 at 1:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.