Function: window-max-chars-per-line
window-max-chars-per-line is a byte-compiled function defined in
window.el.gz.
Signature
(window-max-chars-per-line &optional WINDOW FACE)
Documentation
Return the number of characters that can be displayed on one line in WINDOW.
WINDOW must be a live window and defaults to the selected one.
The character width of FACE is used for the calculation. If FACE
is nil or omitted, the default face is used. If FACE is
remapped (see face-remapping-alist), the function uses the
remapped face.
This function is different from window-body-width in two
ways. First, it accounts for the portions of the line reserved
for the continuation glyph. Second, it accounts for the size of
the font.
Probably introduced at or before Emacs version 25.1.
Source Code
;; Defined in /usr/src/emacs/lisp/window.el.gz
(defun window-max-chars-per-line (&optional window face)
"Return the number of characters that can be displayed on one line in WINDOW.
WINDOW must be a live window and defaults to the selected one.
The character width of FACE is used for the calculation. If FACE
is nil or omitted, the default face is used. If FACE is
remapped (see `face-remapping-alist'), the function uses the
remapped face.
This function is different from `window-body-width' in two
ways. First, it accounts for the portions of the line reserved
for the continuation glyph. Second, it accounts for the size of
the font."
(with-selected-window (window-normalize-window window t)
(let* ((window-width (window-body-width window t))
(font-width (window-font-width window face))
(ncols (- (/ window-width font-width)
(ceiling (line-number-display-width 'columns)))))
(if (and (display-graphic-p)
overflow-newline-into-fringe
(not
(or (eq left-fringe-width 0)
(and (null left-fringe-width)
(= (frame-parameter nil 'left-fringe) 0))))
(not
(or (eq right-fringe-width 0)
(and (null right-fringe-width)
(= (frame-parameter nil 'right-fringe) 0)))))
ncols
;; FIXME: This should remove 1 more column when there are no
;; fringes, lines are truncated, and the window is hscrolled,
;; but EOL is not in the view, because then there are 2
;; truncation glyphs, not one.
(1- ncols)))))