简体   繁体   中英

How to automatically set optimal frame width of Emacs?

How to automatically set optimal frame width of Emacs?

When open a file with Emacs from command line, how to let it automatically set the frame size such that

  • width is 2 characters wider than the widest row or the computer screen width, which ever is smaller

  • height is 80 rows, or the computer screen height, which ever is smaller?

You can use a find-file-hook which sets your frame's size. You'll need things like display-width and display-height, and you'll need to loop through the whole file computing the width of each line (using forward-line to move to the next line, end-of-line to go the end of the line and current-column to find the width). And you'll probably need to fiddle with off-by-one details in order to account for things like the menu-bar, the fringes, ...

Me? I prefer to declare that files should not go over 80 columns so I don't need to adjust the frame width.

This is just what libraries fit-frame.el and autofit-frame.el are for. See also http://www.emacswiki.org/FrameSize .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM