开发者

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?


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


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

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:

How to change the cursor color on emacs

How to change the cursor color on emacs

How to change the cursor color on emacs

How to change the cursor color on emacs


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


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

*cursorColor: #ff7700


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.


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)


There is also a command line option:

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


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

How to change the cursor color on emacs


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜