Tags: patch Based on the recent discussion around counting lines, I proposed the patch below. Part of it aims to just document the way in which the `w->base_line_number` cache is maintained, but it goes further, fixing the problem with format-mode-line and narrowing I discovered and simplifying some of the code based on the new understanding of how the cache is supposed to work. Stefan 2022-08-17 Stefan Monnier * src/xdisp.c (BASE_LINE_NUMBER_VALID_P): New macro. (try_scrolling): Use it. Ignore `just_this_one_p` because it was too pessimistic. (redisplay_window): Remove `buffer_unchanged_p`, not used any more. Check BASE_LINE_NUMBER_VALID_P once and for all at the beginning and don't rely on other side-information that is only correlated with BASE_LINE_NUMBER_VALID_P to decide when to flush this cache. (decode_mode_spec): Check `BASE_LINE_NUMBER_VALID_P` before using the cache. * src/window.c (set_window_buffer): Flush the `base_line_number` cache. In GNU Emacs 29.0.50 (build 1, i686-pc-linux-gnu, GTK+ Version 3.24.34, cairo version 1.16.0) of 2022-08-15 built on lechazo Repository revision: 5564f72d5b3e2f162f52d935c077f6ea15fb60b7 Repository branch: work Windowing system distributor 'The X.Org Foundation', version 11.0.12011000 System Description: Debian GNU/Linux bookworm/sid Configured using: 'configure -C --enable-checking --enable-check-lisp-object-type --with-modules --with-cairo --with-tiff=ifavailable 'CFLAGS=-Wall -g3 -Og -Wno-pointer-sign' PKG_CONFIG_PATH=/home/monnier/lib/pkgconfig'