Tutorial :Unable to import a file to your .emacs


How can you import a new chunk of code (an Emacs lisp library) into your .emacs file?

I do not want to put everything into one huge .emacs file.


Put the file google.el in a directory, say ~/lisp, and then in your .emacs:

(add-to-list 'load-path "~/lisp")  (require 'google)  

If you want to add a directory and its sub-directories, you can check out the answers in this SO question.

And, as you add more and more 'require lines, you'll notice things slowing down on startup. At which point you'll want to find out how to make Emacs start up faster I of course like my answer best.


elisp-load-dir can help, if you need to load many files at once. I use it to load per-topic setup files, which in turn only autoload the heavy stuff when actually needed:

.emacs  .emacs.d/    lisp/      elisp-load-dir.el      ... other .el files that provide a feature    rc/      ... many small .el file that set variables, defaults, etc for me  

So my .emacs is really minimal, it just adds ~/.emacs.d/lisp to the load path, so that I can install third-party extensions there. Then it requires elisp-load-dir and uses it to load whatever config files I have in ~/.emacs.d/rc:

(add-to-list 'load-path "~/.emacs.d/lisp")  (require 'elisp-load-dir)  (elisp-load-dir "~/.emacs.d/rc")  ;; then comes all the custom-set-faces stuff that emacs puts there  

The rc/*.el files are basically what you'd put in your .emacs, except it's modularized. For instance, I have one for each mode I regularly use, one for the startup, disabling the splashscreen, the toolbar, etc…


You can also add an simple load statement in your .emacs file:

(load "/path/to/library.el")  

Frankly, though, I like Trey's solution: it keeps all .el files in a single location.

Edit: removed the 'require' statement, as per Trey's statement.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »