TransWikia.com

cursor color depending on insert or overwrite mode

Emacs Asked by tamifo on February 19, 2021

how can I change the cursor color depending on insert or overwrite mode?

I looked at this page

https://www.emacswiki.org/emacs/ChangingCursorDynamically

and put as recommended 3 lines in the Emacs init file at the end of the custom-set-variables block as well at the end of the custom-set-faces block. In both cases the color of the cursor was black both in insert and overwrite mode.

This is my Emacs init file

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(blink-cursor-mode nil) ; Cursor nicht blinken lassen
 '(inhibit-startup-screen t) ; Keinen startup screen für Emacs anzeigen
 '(x-stretch-cursor t) ; Cursor bei Tabulatoren breit machen
 '(show-trailing-whitespace t) ; Leerzeichen am Zeilenende anzeigen
 '(sentence-end-double-space nil) ; Keine zwei Leerzeichen nach einem Punkt
 '(require-final-newline (quote ask)) ; Zeilenende an letzter Zeile erzwingen
 '(column-number-mode t) ; Zeilennummer und Spalte in Statuszeile anzeigen
 '(show-paren-mode t) ; show matching parantheses
 '(transient-mark-mode t) ; show marked region (fails; work around see below)
 '(require 'cursor-chg)  ; Load the library
 '(toggle-cursor-type-when-idle 1) ; Turn on cursor change when Emacs is idle
 '(change-cursor-mode 1)) ; Turn on change for overwrite, read-only, and input mode
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(region ((t (:background "light gray" :distant-foreground"gtk_selection_fg_color")))))

One Answer

Here's a quick example of a naive way you could accomplish this:

(defun toggle-cursor-color ()
  (if (equalp "deep pink" (face-background 'cursor))
      (set-cursor-color "Dark Turquoise")
    (set-cursor-color "deep pink")))

(add-hook 'overwrite-mode-hook 'toggle-cursor-color)

Assuming your normal cursor color is "deep pink" and you want it to change to "Dark Turquoise" when you enter overwrite-mode, the toggle-cursor-color function defined above will be triggered whenever overwrite-mode is turned on or off. This solution isn't very robust and requires some hardcoded color strings here, but it may give you an idea of where to start and how to interact with the cursor "face", and how to use hooks to change things when a mode is turned on or off.

Answered by shoshin on February 19, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP