Hello% username%!
Recently started using Emacs. I really like the speed and simplicity. After buying a netbook, I ran into the fact that Emacs under Windows does not fit into its 1024x600 when it starts up, and you have to change the window exchange and move it every time. As a solution I wrote a small function that restores the window size at startup. I think it may be useful not only to users of netbooks.
How to do this
File
restore-window-on-startrup.el (defun restore-saved-window-size() (unless (load "~/.emacs.d/whsettings" t nil t) (setq saved-window-size '(80 30))) (nconc default-frame-alist `((width . ,(car saved-window-size)) (height . ,(cadr saved-window-size))))) (restore-saved-window-size) (defun save-window-size-if-changed (&optional unused) (let ((original-window-size `(,(frame-width) ,(frame-height)))) (unless (equal original-window-size saved-window-size) (with-temp-buffer (setq saved-window-size original-window-size) (insert (concat "(setq saved-window-size '" (prin1-to-string saved-window-size) ")")) (write-file "~/.emacs.d/whsettings"))))) (add-hook 'window-size-change-functions 'save-window-size-if-changed)
To make it work, you need to add a line to the
.emacs file
(load "restore-window-on-startrup.el")
How it works
For newbies, emacs (whom I consider myself to be) will explain how it all works:
The last line adds the
save-window-size-if-changed call to the list of window change capture functions. This function compares the new window size with those that have already been saved, and if they are different, it writes to the
~ / .emacs.d / whsettings file here, somewhere, with a new window size:
(setq saved-window-size '( 100 30)) .
The
restore-saved-window-size function, which is called right after its declaration, loads this file (if it doesn’t exist, fills the saved dimensions with a 80x30 hardcode) and sets the window dimensions.
')
For Windows users: the "~" directory, which contains
.emacs and the
.emacs.d directory
, is usually a folder of the form
C: \ Documents and Settings \% Username% . Also, be sure to read about other specific settings in
this topic .