Emacs Doping for Netbooks

    Hello% username%!
    Recently started using Emacs. I really like for the speed and simplicity. After buying a netbook, I was faced with the fact that Emacs for Windows does not fit into its 1024x600 when it starts, and every time we have to change the window change and move it. As a solution, I wrote a small function that restores the window size at startup. I think this may be useful not only to netbook users.

    How to do it

    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)))))
    (defun save-window-size-if-changed (&optional unused)
      (let ((original-window-size  `(,(frame-width) ,(frame-height))))
        (unless (equal original-window-size saved-window-size)
            (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, add a line to the .emacs file(load "restore-window-on-startrup.el")

    How it works

    For beginners, 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 differ, it writes somewhere in the ~ / .emacs.d / whsettings file with the new window size: (setq saved-window-size '( 100 30)) .
    The restore-saved-window-size function , which is called right after its declaration, downloads this file (if it is not there, it fills the saved sizes with the 80x30 hardcode) and sets the window sizes.

    For Windows users: the "~" directory, which contains .emacs and the directory.emacs.d is usually a folder of the form C: \ Documents and Settings \% Username% . Also, be sure to read about other specific settings in this topic .

    Also popular now: