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: Sat, 20 Dec 2014 16:45:26 +0100


(Sent from my cell phone.)

>> On 20.12.2014, at 16:06, martin rudalics <address@hidden> wrote:
>> 
>> (defun window-char-width (&optional window face)
>>    "Return character width for WINDOW.
>> WINDOW must be a live window and defaults to the selected one.
>> 
>> FACE is the face for which character width should be
>> returned.  Buffer-local face remappings are applied.  If nil, the
>> default face is used."
>>    (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-max-characters-per-line (&optional window face)
>>   "Return the number of characters that can be displayed
>> on one line.
>> WINDOW must be a live window and defaults to the selected one.
>> 
>> FACE is the face whose character width should be used for the
>> calculation.  Buffer-local face remappings are applied.  If nil,
>> the default face is used.
>> 
>> 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')."
>>   (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)))))
>> 
>> Note that the first function is a variant of Martin's version which had
>> a bug: if the buffer in the specified window is displayed in two frames,
>> the returned character width was always the one used in the current
>> frame which is not necessarily the character width in the specified
>> window (the window may be in the other frame).  This is a problem
>> because character width can be different, if the two frames use
>> different default fonts.
> 
> So this what I've been trying to find out all the time.  The faces
> apparently _get_ merged dependent on the buffer _and_ the frame.

Yes, my understanding is that each frame has a default face. The properties in 
the buffer-local face-remapping-alist overwrite the vales of the dafault face. 
Windows do not influence the font.

> 
> I need a corresponding `window-char-height' as well, probably also with
> a FACE argument.

Yes, that makes sense. I can add it if you want.

> 
>> For completeness, it probably also makes sense to include the following
>> function in simple.el, which already has a function
>> `default-font-height'.
>> 
>> (defun default-font-width ()
>>   "Return the width in pixels of the current buffer's default face font.
> 
> I profoundly dislike the "default-" prefix here.  `buffer-font-height'
> and `buffer-font-width' would be much better IMHO.
> 
>> I also added the bonus feature which lets you specify a specific face
>> that should be used for the calculations.
> 
> So are you now sure that we don't need a specific character ("M") any
> more?
> 
> martin





reply via email to

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