colorsemacstext-cursor

How to change the cursor color on 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?


Solution

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