[OS X Emacs] fit-frame resizes frames too large in Aquamacs

David Reitter david.reitter at gmail.com
Mon Nov 2 07:25:47 EST 2009


Could the problem be that fit-frame doesn't respect `face-remapping- 
alist'?
The default face is remapped there (which is what `autoface-default'  
is about.
- David

On Nov 2, 2009, at 12:32 AM, Pete Siemsen wrote:

> David,
>
> I've traded some email with Drew Adams about my problems with fit- 
> frame in Aquamacs.  The thread is appended.  At this point, I think  
> it's best to ask you for some help.
>
>
> On October 21, 2009 4:32:49 PM MDT <siemsen at ucar.edu> <siemsen at ucar.edu 
> > wrote:
>
>>> I'm using Aquamacs "2.0preview2".
>>>
>>> When I open a file, I'd like the frame to automatically resize to  
>>> fit the text, as much as possible.  I found fit-frame on the web,  
>>> which seems exactly what I want.  I discovered that it's  
>>> distributed with Aquamacs.  When I did M-x fit-frame, it resized  
>>> the frame.  Very cool!
>>>
>>> Trouble is, it makes the frame wider than needed.  I think this is  
>>> because I've customized Aquamacs to use a default font height of  
>>> "120", while fit-frame uses the height attribute of the "default"  
>>> face, which is 130.  In other words, in my customizations.el file  
>>> I have
>>>
>>> (custom-set-faces
>>> '(autoface-default ((((type ns)) (:inherit default :height  
>>> 120 :family "Monaco" :background "#02053c"))))
>>>
>>> ...but when I evaluate (face-attribute `default :height) I get  
>>> 130.  I think fit-frame is using 130, hence my frames are resized  
>>> too large.  Admittedly, I'm guessing a bit here.
>>>
>>> To try to fix it, I put this in my Preferences.el:
>>>
>>> (set-face-attribute `default nil :height 120)
>>>
>>> It didn't work.  It doesn't set the value used by fit-frame.   
>>> Instead, it seems to set the height of the font of the current  
>>> frame, not of the height of the default face.
>>>
>>> Am I in the right ballpark?
>
>
> On October 21, 2009 4:59:59 PM MDT, David Reitter wrote:
>
>> Yes you are.  Emacs calculates dimensions and coordinates based on  
>> the frame font because you're setting the "frame size".  You can  
>> change the fit-frame function to be smarter - it should be pretty  
>> easy.  Convert to pixels based on the default face, then convert  
>> back to frame chars.
>> But even so: the "width" of the default face is just an  
>> approximation, because the default face may well be a variable- 
>> width font.
>>
>> If you do improve fit-frame, please post the new code.  (You can  
>> check if Drew Adams has an updated version.)
>
>
> I asked for Drew Adams for help.  Here's the relevant bits ( I've  
> tried to put them into a sensible order):
>
>
> On October 21, 2009 12:10:05 PM MDT, Pete Siemsen wrote:
>
>> Drew,
>>
>> I'm a brand new user of fit-frame.  Very cool, and I'm definitely  
>> going to explore your other stuff.  I have this problem:  I use  
>> Aquamacs, and I set the font size with this call in my  
>> "customizations.el" startup file:
>>
>> '(autoface-default ((((type ns)) (:inherit default :height  
>> 120 :family "Monaco" :background "#02053c"))))
>>
>> Fit-frame works, but miscalculates the frame size because it thinks  
>> the font size is something other than the one I'm using.  How can I  
>> make fit-frame base its calculations on the "Monaco 12" that I use?
>>
>> -- Pete
>
>
> On October 21, 2009 12:25:07 PM MDT, Drew Adams wrote:
>
>> I never heard of `autoface-default'. I don't know much about  
>> Aquamacs - perhaps that's an Aquamaces thing? I searched for  
>> `autoface-default' throughout the vanilla Emacs libraries - no  
>> hits. Googling for it suggests that it's an Aquamacs thing. You  
>> should perhaps ask the Aquamacs folks about this.
>>
>> What I would use is just the `default' face. You can customize  
>> that. The `font' attribute of face `default' corresponds to frame  
>> parameter `font'. And it corresponds to what is returned by  
>> functions `frame-char-height' and `frame-char-width', which is what  
>> fit-frame.el uses.
>>
>> You can also use various commands to change the current font or  
>> font size.
>>
>> HTH - Drew
>
>
> On October 22, 2009 3:38:35 PM MDT, Pete Siemsen wrote:
>
>
>
>> Yes, it's an Aquamacs thing.  It was added to allow per-mode  
>> fonts.  It works well.
>
>> I tried doing this in my startup file:
>>
>> (set-face-attribute `default nil :height 120)
>>
>> ...but it didn't affect fit-frame's behavior.  I confess to some  
>> confusion.  I can't do C-h v frame-char-width - Aquamacs doesn't  
>> know the variable.  Yet fit-frame works, sorta.
>
>
> On October 22, 2009 4:20:41 PM MDT, Drew Adams wrote:
>
>> Use M-: (face-attribute 'default :height) to see if the setting  
>> actually took effect.
>>
>> Do also M-: (frame-char-height). It should show the same height  
>> that you just set. If it does, then fit-frame should work, because  
>> it uses that function.
>>
>> If, for some reason, set-face-attribute didn't work, try instead `M- 
>> x customize-face default'. In the Customize buffer, change the  
>> Height value to the height you want (use Height in 1/10 pt from the  
>> Value Menu). Open a new Emacs session and see if that customization  
>> worked.
>>
>> This works for me, on Windows (with normal Emacs 23.1.1, not with  
>> Aquamacs). If I use `set-face-attribute' as you did, then `frame- 
>> char-height' reflects that, and fit-frame works.
>
>
> On October 22, 2009 3:38:35 PM MDT, Pete Siemsen wrote:
>
>> David Reitter, the author of Aquamacs, has suggested that I might  
>> "fix" fit-frame to make it work better.  I doubt that there's a  
>> problem in fit-frame.  I am sure that my Lisp skills are  
>> insufficient to "fix" it :-)
>
> On October 22, 2009 4:20:41 PM MDT, Drew Adams wrote:
>
>> To fix it, we need to first find out what the problem is. David  
>> should be able to help you with that, as there seems to be some  
>> interaction with Aquamacs changes to Emacs. I cannot reproduce the  
>> problem (without Aquamacs).
>>
>> I will help if I can from my end, but I'll need to know more about  
>> what's happening in your case, and why. Either you or David will  
>> need to debug this a bit, to see where the problem is.
>>
>> The first thing to see is what the value of (frame-char-height) is.  
>> That is what fit-frame uses. If it is correct (same as what you set  
>> using set-face-attribute), then we can try to see why fit-frame  
>> didn't do the right thing. If it is not correct (different from the  
>> value you set), then I'd suggest that it's an Aquamacs problem.  
>> AFAIK, set-face-attribute for the `default' face should always be  
>> reflected in `frame-char-height' (and -width). The `default' face  
>> is just shorthand for a certain number of frame parameters (or vice  
>> versa).
>>
>> Let me know what you can find out. Sorry for your trouble.
>>
>> Thx - Drew
>
>
> On October 22, 2009 3:38:35 PM MDT, Pete Siemsen wrote:
>
>> Perhaps this is due to Aquamacs' incomplete implementation of your  
>> libraries.  Aquamacs comes with these:
>>
>> autofit-frame.el frame+.el        icomplete+.el    strings.el        
>> upd2
>> files+.el        frame-cmds.el    misc-fns.el      thingatpt+.el
>> fit-frame.el     frame-fns.el     oneonone.el      upd
>
> On October 22, 2009 4:20:41 PM MDT, Drew Adams wrote:
>
>> No; for fit-frame.el to work, you do not need any other libraries  
>> at all.
>
>
> David, that's the thread.  When I use set-face-attribute to change  
> the height of the default font, my frames resize, but to a size that  
> is too small vertically and too wide horizontally.
>
> It seems like things almost work, but I don't understand the missing  
> piece.  What I want is: when I open a "thin" file, containing, like,  
> a column of numbers, I'd like the frame to appear sized just wide  
> enough to contain the numbers.  Similarly, when I open a file that  
> contains only 10 lines, I'd like the frame to be large enough  
> vertically to show the 10 lines, and no more.  If a file is too big  
> for its frame to fit horizontally or vertically on the screen, I'd  
> like the initial frame to be some maximum number of lines or  
> columns.  If I add content to such a buffer, scroll bars should  
> appear, and I can then evaluate fit-frame again to make the frames  
> use the right amount of real estate.  It seems that fit-frame can do  
> all this.
>
> I realize fit-frame won't work well with proportional fonts, but I  
> don't use proportional fonts.
>
> Thanks again for Aquamacs, it's fantastic!
>
> - Pete
>
> _____________________________________________________________
> MacOSX-Emacs mailing list
> MacOSX-Emacs at email.esm.psu.edu
> http://email.esm.psu.edu/mailman/listinfo/macosx-emacs
> List Archives: http://dir.gmane.org/gmane.emacs.macintosh.osx




More information about the MacOSX-Emacs mailing list