Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I found it really helpful to break my .emacs up into several files. Aside from trying to load .emacs, it will also try .emacs.d/init.el -- mine sets up the load path and then loads .emacs.d/my-options.el, etc. That way, the sprawling growth stays compartmentalized.

No guarantees this will work on xemacs, older versions of GNU emacs, or whatever, but here's what I use (some of which is adapted from the excellent Emacs wiki (http://emacswiki.org):

    (push "~/.emacs.d/" load-path)          ; my init files
    (push "~/.emacs.d/elisp/" load-path)    ; other elisp pkgs
    
    ; byte-compile files in ~/.emacs.d/ whenever we change them
     (defun byte-compile-init-files ()
       (when (and
              (string-match "/\.emacs.d/" buffer-file-name)
              (string-match "\.el" buffer-file-name))
         (when (file-exists-p (concat buffer-file-name ".elc"))
           (delete-file (concat buffer-file-name ".elc")))
         (byte-compile-file buffer-file-name)
         (if (get-buffer (concat (buffer-name) "c")) ;.el -> .elc
             (kill-buffer (concat (buffer-name) "c")))))
    (add-hook 'after-save-hook 'byte-compile-init-files)
    
    ; don't disable commands or mess with my init, grr grr
    (setq disabled-command-function 'nil)
    
    (defun my-load-wrap (fname)
      "Compile stuff if the .el file is newer than the .elc, and load."
      (let* ((fpath "~/.emacs.d/")
             (fn (concat fpath fname ".el")))
        (if (not (file-readable-p fn)) 
            (message (concat "File " fname " does not exist!")))
        (if (or 
             (not (file-readable-p (concat fn "c")))
             (newer-file (file-last-mod-time fn)              ;some .el
                         (file-last-mod-time (concat fn "c"))))     ;compiled
            (byte-compile-file fn t)     ;compile and load
            (load fn t))))               ;load with failsafe
    
    (my-load-wrap "my-options")                   ; general options
    (my-load-wrap "my-functions")                 ; my misc functions
    (my-load-wrap "my-server")                    ; emacs-server stuff
    (my-load-wrap "my-calendar")                  ; cal/diary options
    (my-load-wrap "my-bindings")                  ; and lots of 'em
    (my-load-wrap "my-packages")                  ; misc packages
    (my-load-wrap "my-text")                      ; text mode hooks
    (my-load-wrap "my-programming")               ; python, c, lisp, ocmal, etc
    (my-load-wrap "my-web")                       ; for browsing w/ w3m
    (my-load-wrap "my-irc")                       ; rcirc stuff
    (my-load-wrap "my-skel")                      ; skeletons, boo

    ; load my-aesthetic last, so if there's an error the
    ; faces don't get set, and to ensure faces from all packages exist
    (my-load-wrap "my-aesthetic")                 ; faces, interface stuff


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: