I have opened a buffer with some text on 100 lines.
I would like to change the color of my cursor to red when I reach the row 90?
How would such Elisp function I could put in my init file look like?
Let's say the hook should work for all modes, for simplicity.
Disclaimer: I did not know how to do that before answering. I will tell you how I did find the solution using Emacs.
You can change the colour of the cursor by changing the
:backgroundattribute of thecursorface (as seen when usingdescribe-face, or by reading the "Cursor Display" section of the Emacs manual - which is built-in and can be read from Emacs)I am not aware of a "good" hook that could be used to do this, though. An idea could be to use
post-command-hook, but it might be slow.A (possibly, and probably bad, not thoroughly tested) solution:
Of course, to be safe, you should probably do other checks (what happens in pdf-view-mode/doc-view-mode, etc), but this "should work".
How to get all this information: Inside Emacs:
C-h iopens the Info directorym) to the Emacs oneiand search for cursor, or search in the Index directly, or search withsthe "cursor" regexp ... until you find the "Cursor Display" section. If you forgot how to do that, as usual in this kind of mode, try pressingh, or?, orC-h m(they don't necessarily do the same thing, but are all helping you)set-face-attributefunction), repeat the steps above to view how to do it.set-face-background, a simple wrapper aroundset-face-attribute. To discover this function, you can (and should) also use Emacs: a proper completion/selection system, or the functionapropos-command, bound toC-h a, with e.g. the search "face background", and the aforementioned function is then immediately found.C-h C-h. This command is shown in the tutorial, itself accessible from the menus, or from the initial buffer when starting Emacs (by default), or ... etc.