tags:

views:

326

answers:

3

How can you import the code to you .emacs -file?

I do not want to put all codes to one .emacs file.

+6  A: 

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.

Trey Jackson
Does this work for .el files nested in subdirectories under the load-path? I had to manually include a few .el files which were located lower than the ~/.emacs.d directory (where I store my .el files), though perhaps I did something wrong.
bedwyr
No, it doesn't work for nested directories. But I've added a link for how to do that.
Trey Jackson
+1  A: 

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…

Damien Pollet
Could you give me an example how you use the code? For example, in moving from Work settings to freeTimeSettings. I am new in Lisp.
Masi
I added details. I don't think that answers your question on work/free time, but thet I'm not sure I understand what you mean. That could be a question on its own I guess.
Damien Pollet
+1  A: 

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.

bedwyr
What does the require statement means? I get the following error in Emacs http://dpaste.com/38167/
Masi
The 'require in your solution is unnecessary as the 'require would result in a call to 'load anyway.
Trey Jackson
@Trey: How can you test that the Lisp files are included in Emacs?
Masi
The error message results because you have written (require 'google.el) but the library does (provide 'google). The symbol in require should not include the .el extension. You can also leave it out of the load statement, and Emacs will first look for a compiled .elc file, then for the source .el file. After the load the require is a no-op - require means "load the file unless it has been loaded already".
Jouni K. Seppänen