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: Eli Zaretskii
Subject: bug#19395: 25.0.50; Setting left fringe to 0 messes up window-width
Date: Thu, 18 Dec 2014 18:15:36 +0200

> From: Titus von der Malsburg <malsburg@posteo.de>
> Cc: 19395@debbugs.gnu.org
> Date: Wed, 17 Dec 2014 19:36:04 -0800
> 
> > But if we want this function to be more generally useful, it
> > shouldn't be limited to the frame's canonical character size, and
> > should at least take the face-remapping into account.  Bonus points
> > for accepting a face as an argument and using that face's font
> > dimensions.
> 
> This is more difficult than I thought.  Below is a first sketch.  Let me
> know if you think this is going in the right direction and I'll polish
> it and add the bonus feature.
> 
> It appears that a font has to be rendered before Emacs can tell how wide
> a character is.  That's why we need the temporary buffer.  Not elegant,
> but I couldn't find a better way.  `default-font-width' complements
> `default-font-height' in simple.el.  The other function would go into
> window.el.

Given the changes I pushed in commit b197822, you will no longer need
all this complexity.  Just

   (aref (font-info (face-font 'default)) 11)

(For bullet-proof code, check that this is not zero, and if it is, use
the 10th member instead; see the docs.)

> (defun window-available-columns ()
>   "Return the maximal number of characters that can be displayed
> on one line.  This function is different from `window-body-width'
> in that it accounts for fringes (when at least one fringe has
> zero width, one column is reserved for continuation characters)
> and for the size of the default font (which may have been
> adjusted using, e.g., `text-scale-increase')."
>   (let* ((window-width (window-body-width nil t))
>        (font-width (default-font-width))
>        (ncols (/ window-width font-width)))
>     (if (and (not (featurep 'xemacs))
>            (display-graphic-p)
>            overflow-newline-into-fringe
>            (/= (frame-parameter nil 'left-fringe) 0)
>            (/= (frame-parameter nil 'right-fringe) 0))
>         ncols
>       (1- (ncols)))))

If we are going to put this in simple.el or subr.el, I don't think we
need to worry about XEmacs.

Thanks.





reply via email to

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