tags: patch From emacs -Q, insert the following in *scratch*, and evaluate it twice. (with-current-buffer (get-buffer-create "foo") (erase-buffer) (insert (make-string 200 ?\n)) (cursor-sensor-mode +1) (display-buffer (current-buffer))) The second time an error is triggered, here is a backtrace: Debugger entered--Lisp error: (args-out-of-range 0) get-char-property(0 cursor-sensor-functions) cursor-sensor--detect(#) run-hook-with-args(cursor-sensor--detect #) redisplay--pre-redisplay-functions((#)) apply(redisplay--pre-redisplay-functions (#)) #[128 "\300\301\"\210\300\302\"\207" [apply redisplay--pre-redisplay-functions ignore nil] 4 nil nil]((#)) redisplay_internal\ \(C\ function\)() cursor-sensor-mode is a new feature in Emacs 25, so I propose the following patch for emacs-25: