The result of window-body-width
doesn't change when display-line-number-mode
is enabled / disabled.
How can I get the window width but excluding the fringe?
The function window-max-chars-per-line
does exactly this.
Found in the emacs manual: the effective width of the window in characters.
For e.g., its return value does change based on whether or not line numbers are enabled in the current buffer. It can do this for any face via an optional argument.
If I understand you right, this might do it (size in pixels):
(defun window-pixel-width-minus-fringe ()
(let ((width (window-pixel-width))
(fringes (window-fringes)))
(- width (+ (car fringes) (cadr fringes)))))
See the Elisp manual, nodes Window Sizes and Fringe Size and Position.
(window-fringes)
doesn't change when displaying line number is toggled: (global-display-line-numbers-mode)
Commented
Feb 14, 2022 at 5:40
window-fringes
doesn't change according to whether line numbers are displayed. Fringes have nothing to do with line numbers.
display-line-number-mode
, and notline-number-mode
. The latter just puts the line number in the mode-line.linum-mode
andnlinum-mode
used the left of the fringe, which is different than the current built-in version.xdisp.c
, at the line that reads:strcat (lnum_buf, " ");
I haven't played with the internals for a few years now, but my recollection is that there were some geometry functions written for users to call from lisp to obtain additional values that were not previously available in earlier versions of Emacs.