2

I got something like that:

(global-set-key [insert] (lambda () (interactive) (overwrite-mode) (setq cursor-type 't)))

But I don't know how to do it so that when you exit the insert mode (when you press insert again) it becomes a bar again.

(setq-default cursor-type 'bar) 
  • The cursor-type is frame-local, not buffer-local. So, changing the cursor-type will change any selected windows displaying a buffer in frame. – lawlist Sep 10 '18 at 15:10
  • @lawlist: "frame-local" doesn't exist any more in Emacs-26. cursor-type is a buffer-local variable. – Stefan Sep 10 '18 at 15:13
1

Rather than define a new command that you bind to the same key, you'll be better off using the minor mode's hook:

(add-hook 'overwrite-mode-hook
          (lambda ()
            (setq cursor-type (if overwrite-mode t 'bar))))
1

See Changing Cursor Dynamically, which describes library cursor-chg.el.

When a buffer is read-only or is in overwrite mode, the cursor type changes to curchg-overwrite/read-only-cursor-type (by default, box). This is controlled by change-cursor-mode and user option curchg-change-cursor-on-overwrite/read-only-flag.

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.