无法在emacsclient中更改光标颜色

13
如果我运行emacs --daemon(在.xinitrc或之后),然后运行emacsclient -c,新创建的窗口的光标颜色是黑色,无论颜色主题或其他设置如何。更确切地说,在我输入任何内容之前,光标的颜色是白色(或其他颜色),但是随着第一次按键,它变成了黑色,并且无法通过set-cursor-color来改变颜色。默认和我的自定义配色方案都是黑色,因此这使得编辑非常不舒服。
如果我使用emacsM-x server-start代替emacs --daemon,则不会出现此问题。但这种方式需要保留一个emacs“主”窗口,并且不能意外杀死它,这似乎不是一个好的解决方案。
我在.emacs.d/init.el中有以下块,但它没有帮助:
(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"))))

如果我运行M-x describe-face RET cursor,会得到以下结果:

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

关于这个问题有什么新消息吗?最终你找到了有效的解决方法吗?我也遇到了类似的问题,即emacsclient无法加载color-theme,但是Emacs可以很好地应用我的紫色光标。 - kristianlm
5个回答

7

我相信在最近的 Emacs 中,使用框架属性来设置光标颜色不再是首选的方法。所以,不要使用 set-cursor-colorinitial-frame-alist / default-frame-alist,而是尝试使用:

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

或者,可能是这样:
(set-face-attribute 'cursor nil :background "red"`)

嗯,有点奇怪。我看看能不能再现出来。 - sanityinc
1
我也尝试了两种方法,但都没有成功。我也受到了这种奇怪行为的影响。 - plc

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.

请查看这个论坛帖子。


5

哈哈哈!我认为过去两年没有人发布解决方案,因为你们都是邪恶的emacs用户!

说实话,我目前正在尝试使用evil-mode,并且我已经在我的系统上解决了这个问题。将以下内容放入您的.emacs文件中:

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

我刚刚在Bitbucket的Evil存储库中提出了一个bug
对于自己而言,在花费了大约6年的时间真正熟练掌握emacs之后,多键和弦对我的肌腱造成了一定的损伤。使用Evil模式可能会让我再次使用emacs,这是一件好事。如Benedict所说(在函数式编程的上下文中),"有时需要一些恶意才能完成工作。"看来这也可能适用于Emacs。

附言:如果有人觉得这个答案只是 DH0或者不成熟和不恰当,那么Emacs和VI用户之间大多是半开玩笑的争吵已经持续了多年。Emacs有自己的 Emacs教会,VI有视频游戏World War VI。因此,最成功的将VI键绑定移植到Emacs的方法被命名为evil-mode(evil中含有VI一词)。我喜欢两个编辑器,并赞扬那些终于使VI键绑定在emacs内工作的evil开发人员。


谢谢Glen,我已经是EVIL用户了(虽然我从来不使用正常模式/状态)。我更正了你的命令(用setq替换了')。它对我来说似乎很好用。即使光标再次变黑,我也可以重复执行该命令。 - modular
由于这是唯一对我有效的解决方案,我接受了你的答案。尽管这对于不是EVIL粉丝的Emacs用户有点不公平。 - modular

1
这对我有用:
(setq evil-default-cursor t) ;; Now evil takes the default cursors 
(set-cursor-color "white") ;; Set it to white
(set-mouse-color "white") ;; Same

0

我也有同样的问题,已经有好几年了。

在我的情况下,我做如下操作:

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

这对我来说是可行的,但每次都要这样做,很烦人。

在我以前的工作场所,我已经解决了这个问题,但我现在没有我以前工作场所使用的init.el文件,现在我需要重新弄清楚这个问题,希望这里的某个人能在我之前解决这个问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接