如何更改 emacs 上的光标颜色

发布于 2024-10-11 01:04:41 字数 59 浏览 10 评论 0原文

我对 Emacs 的颜色做了一些更改,现在唯一的问题是光标在黑色背景上为黑色,我必须更改它。我该怎么办?

I made some changes in Emacs's colors and the only thing wrong now is the cursor that is black on black background and I will have to change that. What do I do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

回心转意 2024-10-18 01:04:41

如果您运行的是最新版本的 emacs,您可以使用:

; Set cursor color to white
(set-cursor-color "#ffffff") 

您可以使用任何您喜欢的颜色,而不是 #ffffff。对于十六进制代码列表,谷歌说: http://www.tayloredmktg.com/rgb/


也许你喜欢这个...以下代码会更改每次闪烁时的光标颜色。只需评估代码及其运行:

; Using in Emacs 24.0 

(defvar blink-cursor-colors (list  "#92c48f" "#6785c5" "#be369c" "#d9ca65")
  "On each blink the cursor will cycle to the next color in this list.")

(setq blink-cursor-count 0)
(defun blink-cursor-timer-function ()
  "Zarza wrote this cyberpunk variant of timer `blink-cursor-timer'. 
Warning: overwrites original version in `frame.el'.

This one changes the cursor color on each blink. Define colors in `blink-cursor-colors'."
  (when (not (internal-show-cursor-p))
    (when (>= blink-cursor-count (length blink-cursor-colors))
      (setq blink-cursor-count 0))
    (set-cursor-color (nth blink-cursor-count blink-cursor-colors))
    (setq blink-cursor-count (+ 1 blink-cursor-count))
    )
  (internal-show-cursor nil (not (internal-show-cursor-p)))
  )

请注意,此代码替换了“frame.el”中的 emacs 函数“blink-cursor-timer-function”。

If you are running a recent version of emacs you can use:

; Set cursor color to white
(set-cursor-color "#ffffff") 

Instead of #ffffff you can use any color you like. For a list of hex code google Says: http://www.tayloredmktg.com/rgb/


Maybe you like this one... the following code changes the cursor color on each blink. Just eval code and its running:

; Using in Emacs 24.0 

(defvar blink-cursor-colors (list  "#92c48f" "#6785c5" "#be369c" "#d9ca65")
  "On each blink the cursor will cycle to the next color in this list.")

(setq blink-cursor-count 0)
(defun blink-cursor-timer-function ()
  "Zarza wrote this cyberpunk variant of timer `blink-cursor-timer'. 
Warning: overwrites original version in `frame.el'.

This one changes the cursor color on each blink. Define colors in `blink-cursor-colors'."
  (when (not (internal-show-cursor-p))
    (when (>= blink-cursor-count (length blink-cursor-colors))
      (setq blink-cursor-count 0))
    (set-cursor-color (nth blink-cursor-count blink-cursor-colors))
    (setq blink-cursor-count (+ 1 blink-cursor-count))
    )
  (internal-show-cursor nil (not (internal-show-cursor-p)))
  )

Note that this code replaces the emacs function 'blink-cursor-timer-function' from 'frame.el'.

望她远 2024-10-18 01:04:41

以上都不适合我,所以我自己做了一些研究。来自Emacs 手册

14.20 显示光标

在文本终端上,光标的外观由
终端,很大程度上不受 Emacs 的控制。部分航站楼提供
两种不同的光标:“可见”静态光标和“非常可见”
闪烁的光标。默认情况下,Emacs 使用非常明显的光标,并且
当您启动或恢复 Emacs 时切换到它。如果变量
当 Emacs 启动或恢复时,visible-cursor 为 nil,它使用正常的
光标。

在图形显示上,可以设置文本光标的更多属性
改变了。要自定义其颜色,请更改 :background 属性
名为光标的面(请参阅面自定义)。 (其他属性
这张脸没有任何影响;绘制光标下显示的文本
使用框架的背景颜色。)要更改其形状,请自定义
缓冲区局部变量游标类型;可能的值为 box(
默认)、hollow(空心框)、bar(垂直条)、(bar . n) (a
垂直条 n 像素宽)、hbar(水平条)、(hbar . n) (a
水平条 n 像素高),或 nil(根本没有光标)。

要禁用光标闪烁,请将变量眨眼光标模式更改为
nil(请参阅轻松自定义),或添加行 (blink-cursor-mode 0) 到
你的初始化文件。或者,您可以更改光标的外观
当它通过自定义列表变量“闪烁”时
闪烁光标列表。列表中的每个元素应具有以下形式
(开启型。关闭型);这意味着如果光标显示为
on-type 当它闪烁时(其中 on-type 是光标类型之一
如上所述),则闪烁时显示为关闭型。

某些字符(例如制表符)是“超宽”的。当
光标位于这样的字符上,通常用
默认字符宽度。您可以使光标伸展以覆盖
宽字符,通过将变量 x-stretch-cursor 更改为
非零值。

光标通常在未选定的窗口中显示为不闪烁
空心盒子。 (对于条形光标,它显示为较细的条形。)
要关闭未选定窗口中的光标,请更改变量
光标在非选定窗口中为零。

为了使光标更加明显,您可以使用 HL Line 模式,这是一种
次要模式,突出显示包含点的线。使用MX
hl-line-mode 在当前缓冲区中启用或禁用它。 MX
global-hl-line-mode 全局启用或禁用相同的模式。

所以方法如下:

  1. Mxcustomize-face,输入
  2. cursor回车
  3. 选择您喜欢的背景颜色。
  4. 单击状态,保存以供将来的会话使用。

屏幕截图位于:

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

None of above worked for me, so I did a little research on my own. From the Emacs Manual:

14.20 Displaying the Cursor

On a text terminal, the cursor's appearance is controlled by the
terminal
, largely out of the control of Emacs. Some terminals offer
two different cursors: a “visible” static cursor, and a “very visible”
blinking cursor. By default, Emacs uses the very visible cursor, and
switches to it when you start or resume Emacs. If the variable
visible-cursor is nil when Emacs starts or resumes, it uses the normal
cursor.

On a graphical display, many more properties of the text cursor can be
altered. To customize its color, change the :background attribute of
the face named cursor (see Face Customization). (The other attributes
of this face have no effect; the text shown under the cursor is drawn
using the frame's background color.) To change its shape, customize
the buffer-local variable cursor-type; possible values are box (the
default), hollow (a hollow box), bar (a vertical bar), (bar . n) (a
vertical bar n pixels wide), hbar (a horizontal bar), (hbar . n) (a
horizontal bar n pixels tall), or nil (no cursor at all).

To disable cursor blinking, change the variable blink-cursor-mode to
nil (see Easy Customization), or add the line (blink-cursor-mode 0) to
your init file. Alternatively, you can change how the cursor looks
when it “blinks off” by customizing the list variable
blink-cursor-alist. Each element in the list should have the form
(on-type . off-type); this means that if the cursor is displayed as
on-type when it blinks on (where on-type is one of the cursor types
described above), then it is displayed as off-type when it blinks off.

Some characters, such as tab characters, are “extra wide”. When the
cursor is positioned over such a character, it is normally drawn with
the default character width. You can make the cursor stretch to cover
wide characters, by changing the variable x-stretch-cursor to a
non-nil value.

The cursor normally appears in non-selected windows as a non-blinking
hollow box. (For a bar cursor, it instead appears as a thinner bar.)
To turn off cursors in non-selected windows, change the variable
cursor-in-non-selected-windows to nil.

To make the cursor even more visible, you can use HL Line mode, a
minor mode that highlights the line containing point. Use M-x
hl-line-mode to enable or disable it in the current buffer. M-x
global-hl-line-mode enables or disables the same mode globally.

So here is the way to do it:

  1. M-x customize-face, enter
  2. cursor enter
  3. choose the background color of you liking.
  4. click on state, save for future sessions.

Screenshots here:

enter image description here

enter image description here

enter image description here

enter image description here

昔日梦未散 2024-10-18 01:04:41

试试这个:

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

如果您想保留 default-frame-alist 中的其他值,您可以使用 Mark 的建议:

(add-to-list 'default-frame-alist '(cursor-color . "palegoldenrod"))

Try this:

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

If you want to preserve the other values in default-frame-alist you can us Mark's suggestion:

(add-to-list 'default-frame-alist '(cursor-color . "palegoldenrod"))
风渺 2024-10-18 01:04:41

如果您使用 X 窗口系统,请尝试将类似的内容放入 .Xdefaults 中:

*cursorColor: #ff7700

If you use X window system, try out put something like this to .Xdefaults:

*cursorColor: #ff7700
著墨染雨君画夕 2024-10-18 01:04:41

您可以使用它来自定义 emacs 颜色:

(defun good-colors ()
  (progn
     ;; Set cursor color
     (set-cursor-color "Black")

     (set-background-color "grey46")
     (set-foreground-color "White")
     (set-border-color "dark orange")
     (set-mouse-color "dark orange") 
))

(good-colors)

You can use this for customize emacs colors:

(defun good-colors ()
  (progn
     ;; Set cursor color
     (set-cursor-color "Black")

     (set-background-color "grey46")
     (set-foreground-color "White")
     (set-border-color "dark orange")
     (set-mouse-color "dark orange") 
))

(good-colors)
清晨说晚安 2024-10-18 01:04:41

对我来说,根据其他答案的建议在 init 上设置光标颜色实际上并不起作用,因为可能会干扰我正在加载的主题和包。我的解决方案是添加以下内容:

(add-hook 'after-init-hook
          (lambda () (run-with-timer 5 nil #'set-cursor-color "SystemRedColor")))

此解决方案使得对 set-cursor-color 的调用仅在 init 完成后 5 秒发生,从而为所有其他包和主题更改提供足够的时间来完全加载。

For me, setting the cursor color on init with the recommendation from the other answers wouldn't really work because of some possible interference with the themes and packages I was loading. My solution was to add the following instead:

(add-hook 'after-init-hook
          (lambda () (run-with-timer 5 nil #'set-cursor-color "SystemRedColor")))

This solution makes it so that a call to set-cursor-color will only happen 5 seconds after init finishes, allowing enough time for all the other packages and theme changes to fully load.

守不住的情 2024-10-18 01:04:41

还有一个命令行选项:

--cursor-color, -cr COLOR       color of the Emacs cursor indicating point

There is also a command line option:

--cursor-color, -cr COLOR       color of the Emacs cursor indicating point
草莓酥 2024-10-18 01:04:41

请记住,如果您使用的是 iTerm2,则必须对其设置进行更改,否则不会对 .emacs 配置文件进行更改。

首选项=>个人资料 =>颜色=>光标颜色

在此处输入图像描述

Keep in mind if you are using iTerm2 you have to make changes on its settings, otherwise changes on the .emacs config file does not take place.

Preferences => Profiles => Color => Cursor Colors

enter image description here

能否归途做我良人 2024-10-18 01:04:41

我将 (set-face-attribute 'cursor nil :background "#A0F") 添加到我的 .emacs 文件中,使我的光标变成漂亮的紫罗兰色。

我不确定版本和系统信息有多重要,但我在 Ubuntu 22.04.1 LTS 上以 GUI 模式运行 GNU Emacs 27.1。 (Emacs 28.2 可从 GNU 网站获取,所以 YMMV。)

I added (set-face-attribute 'cursor nil :background "#A0F") to my .emacs file, making my cursor a nice violet color.

I'm not sure how critical version and system info are, but I'm running GNU Emacs 27.1 in GUI mode on Ubuntu 22.04.1 LTS. (Emacs 28.2 is available from the GNU website, so YMMV.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文