Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modularize an emacs configuration?

I've decided to rewrite my .emacs from the ground up, and I want to setup something that's modular, in order to avoid a dreaded 1k+ LoC init.el file...

I think there are some basic concerns that each configuration needs to address :

  • global options
  • editing functions
  • navigation (frames & buffers)
  • keybindings
  • modes customizations

While I'm still tying to think the structure through, I'm looking for some pointers on how to achieve this.
I've looked at some .emacs on github and such, and there seems to be deifferent approaches, and no preferred way to go with this, which is a bit confusing.
I would be interested in reading some ideas regarding how to structure such a setup, and especially some related elisp code.


edit : Been caught up with things, and haven't had much time to play with this yet. Will try out the proposed methods in a few days, and see what's best, meanwhile thanks for all the recommendations !


edit2 : I've been using a literate init file with org-mode, and this is absolutely terrific !
I 'm not yet set on a specific load mechanism, I've been using this code, to recursively load my elisp directory, then require or whatever the setup instructions say.

  (if (fboundp 'normal-top-level-add-subdirs-to-load-path)   (let* ((my-lisp-dir "~/.emacs.d/elisp/")   (default-directory my-lisp-dir))   (setq load-path (cons my-lisp-dir load-path))   (normal-top-level-add-subdirs-to-load-path))) 

I still need to polish this, maybe using autoload, and some byte-recompile if modified tricks ; would love to hear suggestions on that.

like image 861
julien Avatar asked Jan 16 '10 22:01

julien


People also ask

Where is the config file of emacs?

Emacs can also look in an XDG-compatible location for init. el , the default is the directory ~/. config/emacs .

Where is emacs config file in Ubuntu?

emacs config file usually resides in your home directory. See also The Emacs Initialization File. If you need to start with a blank . emacs , try touch ~/.

What is emacs config file?

This is a file containing pieces of emacs lisp (the language emacs is written in) that alter the behaviour of emacs. Your emacs config file is probably in one of three places: in ~/. emacs though this is now a bit outdated and instead it will usually be in.

What is the emacs init file?

When Emacs is started, it normally tries to load a Lisp program from an initialization file, or init file for short. This file, if it exists, specifies how to initialize Emacs for you.


1 Answers

My .emacs file loads ~/.emacs.d/init.el, which defines the following functions, written first for XEmacs, but working well enough for Emacs these days:

(defconst user-init-dir   (cond ((boundp 'user-emacs-directory)          user-emacs-directory)         ((boundp 'user-init-directory)          user-init-directory)         (t "~/.emacs.d/")))   (defun load-user-file (file)   (interactive "f")   "Load a file in current user's configuration directory"   (load-file (expand-file-name file user-init-dir))) 

Then the rest of the file goes and loads lots of individual files with forms like this:

(load-user-file "personal.el") 

My current set of files is as follows:

  • personal.el
  • platform.el
  • cygwin.el
  • variables.el
  • paths.el
  • mail-news.el
  • misc-funcs.el
  • bbdb.el
  • calendar.el
  • gnus-funcs.el
  • c-and-java.el
  • lisp.el
  • clojure.el
  • go.el
  • markdown.el
  • sgml-xml.el
  • tex.el
  • spelling.el
  • org.el
  • packages.el
  • fonts.el
  • color-theme.el
  • frame.el
  • server.el
  • keys.el
  • aquamacs.el

Some of them are much more specific in intent than others, as the names suggest. The more fine-grained the files, the easier it is to disable a cluster of forms when you're reinstalling a package or library. This is especially useful when "moving in" to a new system, where you drag your configuration files over but don't yet have all the supporting packages installed.

like image 102
seh Avatar answered Sep 22 '22 05:09

seh