How to change the cursor color on emacs
Asked Answered
D

9

38

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?

Divulsion answered 10/1, 2011 at 0:42 Comment(0)
W
47

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

Wertz answered 8/2, 2011 at 12:23 Comment(1)
Note that the first suggestion here will only affect the current frame. If you want to change the color for all new frames, modify default-frame-alist as suggested by @TreyJackson in his answer.Strohbehn
P
22

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

Privet answered 15/6, 2014 at 22:40 Comment(2)
Thanks, that works a treat. It also looks like you can click on the Apply and Save button shown at the top of your screenshot. A bright red cursor for me. My matching paren indicator colors are too dark, and the color hides the (rainbow) parens, so all I see is two solid colored blocks. To change the matching parens color to something lighter (white for me), see here: emacs.stackexchange.com/a/76410Lubricity
Thanks this solved my problem as well. In my case the mouse pointer was black, but I just followed your instructions and substituted mouse for cursor after M-x customize-face RETSelig
A
11

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"))
Aporia answered 10/1, 2011 at 1:29 Comment(2)
default-frame-alist usually contains some X specific staff (such as default frame size) already. Did you mean (add-to-list 'default-frame-alist '(cursor-color . "palegoldenrod"))?Catsup
@Henry That's reasonable, though default-frame-alist on my build of Emacs seems to default to just ((menu-bar-lines . 1) (tool-bar-lines . 1)) - which wouldn't be sorely missed. Adjusting answer.Aporia
E
5

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

*cursorColor: #ff7700
Equestrienne answered 26/9, 2011 at 18:8 Comment(0)
A
2

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.

Aluino answered 11/8, 2020 at 18:7 Comment(0)
W
1

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)
Windjammer answered 8/2, 2011 at 12:36 Comment(3)
Note that you don't need the progn wrapper in this instance (i.e. at the top level of a function).Octavalent
This did not make any change on the color of the cursor @WindjammerDownes
this sets all buffer's backgroundDownes
F
1

There is also a command line option:

--cursor-color, -cr COLOR       color of the Emacs cursor indicating point
Frasquito answered 8/1, 2014 at 18:54 Comment(0)
D
1

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

Downes answered 28/6, 2020 at 13:51 Comment(0)
P
1

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

Pantile answered 11/10, 2022 at 0:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.