0

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")))))
  • Please specify the problem. What did you put in your init file ("the following")? "Did not work" doesn't help people help you. Please provide a step-by-step recipe to reproduce the problem, starting from emacs -Q (no init file). In other, specify what you tried, what you saw, and what you expected to see instead. Thx. – Drew Dec 4 '19 at 23:11
0

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.

| improve this answer | |
  • i'm sure using the cursor change library you referenced above is probably a better way to do this, but like the editor said, its hard to tell from your question what exactly "isn't working" – shoshin Dec 5 '19 at 2:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.