Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

emacs thin cursor on empty line

Tags:

emacs24

Is there a way to make the emacs cursor a "thinner" bar when it is positioned on an empty line? If the line has whitespace, or text, it should be the default width block cursor. This is for emacs 24.

This is the default cursor behaviour on XEmacs, FWIW.

like image 419
Vijay Ramachandran Avatar asked Jun 26 '26 13:06

Vijay Ramachandran


1 Answers

To change cursor dynamically, depending on the contents of the current line add this to your .emacs:

(defun cursor-shape-hook ()
    (if (equal (thing-at-point 'line) "\n") (setq cursor-type 'bar)
       (setq cursor-type 'box)))

(add-hook 'post-command-hook 'cursor-shape-hook)

All possibilities for cursor shape are:

nil       don't display a cursor
box       display a filled box cursor
hollow    display a hollow box cursor
bar       display a vertical bar cursor with default width
(bar . WIDTH)     display a vertical bar cursor with width WIDTH
hbar          display a horizontal bar cursor with default height
(hbar . HEIGHT) display a horizontal bar cursor with height HEIGHT
ANYTHING ELSE     display a hollow box cursor
like image 117
BartoszKP Avatar answered Jul 01 '26 19:07

BartoszKP



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!