bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#19395: 25.0.50; Setting left fringe to 0 messes up window-width


From: Titus von der Malsburg
Subject: bug#19395: 25.0.50; Setting left fringe to 0 messes up window-width
Date: Sun, 21 Dec 2014 23:04:51 +0100

On 2014-12-20 Sat 17:31, Eli Zaretskii wrote:
>> From: Titus von der Malsburg <address@hidden>
>> Cc: address@hidden
>> Date: Sat, 20 Dec 2014 15:51:27 +0100
>> 
>> >    (aref (font-info (face-font 'default)) 11)
>> 
>> Great, thanks for adding this.  Below the updated version of my solution
>> to the original problem:
>
> Looks good to me.  A few comments about the doc strings:

Eli, I fixed the doc strings following your suggestions and added the
function `window-char-height' analogous to `window-char-width' (see code
below).  If there are no objections, I'll go ahead and submit a patch
(after reading the relevant guidelines).

Thanks for your input.  I learned a lot about fonts and faces in Emacs.

  Titus

(defun default-font-width ()
  "Return the width in pixels of the current buffer's default face font.

If the default font is remapped (see `face-remapping-alist'), the
function returns the width of the remapped face."
  (let* ((info (font-info (face-font 'default)))
         (width (aref info 11)))
    (if (> width 0)
        width
      (aref info 10))))

(defun window-char-width (&optional window face)
   "Return average character width for the font of FACE used in WINDOW.
WINDOW must be a live window and defaults to the selected one.

If FACE is nil or omitted, the default face is used.  If FACE is
remapped (see `face-remapping-alist'), the function returns the
information for the remapped face."
   (with-selected-window (window-normalize-window window t)
     (let* ((face (if face face 'default))
            (info (font-info (face-font face)))
            (width (aref info 11)))
       (if (> width 0)
          width
         (aref info 10)))))

(defun window-char-height (&optional window face)
   "Return character height for the font of FACE used in WINDOW.
WINDOW must be a live window and defaults to the selected one.

If FACE is nil or omitted, the default face is used.  If FACE is
remapped (see `face-remapping-alist'), the function returns the
information for the remapped face."
   (with-selected-window (window-normalize-window window t)
     (let* ((face (if face face 'default))
            (info (font-info (face-font face))))
       (aref info 3))))

(defun window-max-characters-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, which may have been adjusted, e.g., using
`text-scale-increase')."
  (with-selected-window (window-normalize-window window t)
    (let* ((window-width (window-body-width window t))
           (font-width (window-char-width window face))
           (ncols (/ window-width font-width)))
      (if (and (display-graphic-p)
               overflow-newline-into-fringe
               (/= (frame-parameter nil 'left-fringe) 0)
               (/= (frame-parameter nil 'right-fringe) 0))
          ncols
        (1- ncols)))))
  

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]