Pergunta

I want to solve my “.emacs bankruptcy” issue, and I've gone through

https://help.ubuntu.com/community/EmacsHowto
http://www.emacswiki.org/emacs/DotEmacsBankruptcy
http://www.emacswiki.org/emacs/DotEmacsDotD
http://www.gnu.org/software/emacs/manual/html_node/emacs/Init-File.html

and it is still unclear to me whether the .emacs.d folder is the solution. I.e., whether it will behave just like a normal .d folder, e.g., /etc/profile.d/, where you drop you scripts and they will be picked up by the system auto-magically. Please confirm.

If not, can someone give me a script that does that, or give me a solution please?

Thanks

Foi útil?

Solução

The essential content of my ~/.emacs file is:

(require 'cl)

(loop for src in (directory-files "~/.emacs.d" 'full-path "[0-9].*\\.el$") do
      (let ((byte (concat src "c")))
    (when (file-newer-than-file-p src byte)
      (byte-compile-file src))
    (message "Loading %s.elc" byte)
    (load-file byte)))

It loads configuration files from ~/.emacs.d which start with a number. If the source file (extension .el) is newer than the byte-compiled version (extension .elc) then it byte-compiles the source. Afterwards it loads the byte compiled file.

Outras dicas

Here's my ~/.emacs:

;; base dirs
(defvar dropbox.d "~/Dropbox/")
(defvar emacs.d (concat dropbox.d "source/site-lisp/"))
;; load path
(add-to-list 'load-path emacs.d)
(defun add-subdirs-to-load-path (dir)
    (let ((default-directory dir))
      (normal-top-level-add-subdirs-to-load-path)))
(add-subdirs-to-load-path emacs.d)
(load "init")

All my other scripts are loaded by ~/Dropbox/source/site-lisp/init.el and are themselves located in ~/Dropbox/source/site-lisp. That's how I have the same config on multiple machines. And here's how .../site-lisp/hooks.el is loaded from init.el:

(load "hooks")

My init.el is about 100 lines, .emacs about 20 lines. The rest 8000 lines of scripts are sliced into around 20 files.

~/.emacs.d/ does not work like /etc/profile.d/ or /etc/modules-load.d/ or similar directories, i.e. Emacs does not automatically load any Emacs Lisp file in this directory.

In fact, Emacs explicitly advises against placing Emacs Lisp libraries in ~/.emacs.d/. The byte compiler emits a warning if you add ~/.emacs.d/ to the load-path.

Instead, create a new sub-directory, e.g. ~/.emacs.d/lisp. Add this directory to your load-path explicitly, with the following code in init.el:

(add-to-list 'load-path (locate-user-emacs-file "lisp"))

Then, place your Emacs Lisp files in this directory, e.g. ~/.emacs.d/lisp/foo.el, and load them in your init.el:

(load "foo" nil 'no-message)

The best approach to avoid the dreaded .emacs bankruptcy is to actually avoid large customizations! Most notably, try to avoid any custom functions and commands.

Instead, try to a find an ELPA package that comes closest to what you want, and either try to get used to it, or customize it to your needs. If you don't find any, first try to write your own and distribute it on Github, Marmalade or MELPA.

Don't be afraid of maintaining a package in the public. You'll have to maintain your customization anyway, whether in your init.el or not, so you can just as well let other Emacs users help you with this job.

Adding code to your init.el should be your very last resort!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top