Skip to content

SidharthArya/modular-config.el

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

modular-config.el

http://melpa.org/packages/modular-config-badge.svg

Organize your emacs config into modules.

Synopsis

Let’s start with a short story. When i began using emacs i was overwhelmed with the options and features it provided me, but this overwhelming was not just limited to me, it seemed to be that emacs itself was overwhelmed with these options. If you don’t believe me, try making emacs do everything, all the time: mail+irc+programming+tracking+shell+organize. This may not be the most intelligent way of using emacs, in my opinion, no offence. Emacs can do everything but don’t make it do everything at once. So, i started breaking down my config file into usable blocks, for example, i may want emoji support in news, chat, and mail but not programming. This package is what springed out of this need. You cannot necessarily have a usable emacs if you have to constantly run all the features it provides. It, then, makes sense to spring multiple instances for specific use cases. You can, do this manually, or you can use this package.

Basic Usage

Make sure the folder containing modules.el file is in your load-path.

  (require 'modular-config)
  (setq modular-config-list '(
		       (none ())
		       (minimal (compile core appearance vi))
		       (news (compile core appearance mount mail ivy news org))
		       (programming (compile core appearance vi ivy mount org programming vc))
		       (org (compile core appearance vi ivy mount org server compile dashboard))
		       (main (compile core appearance programming vi mount org news mail dashboard vc tracking finance server))
		       ))
  (setq modular-config-default 'main)
  (setq modular-config-path "~/.emacs.d/lisp")
(modular-config-command-line-args-process)

Use Package

If you already use use-package. Then, the config below works, although this package is not yet part of melpa so, either have it manually be in the load-path, or use straight.el.

(use-package modular-config
  :custom
  (modular-config-list '(
                         (none ())
                         (minimal (compile core appearance vi))
                         (news (compile core appearance mount mail ivy news org))
                         (programming (compile core appearance vi ivy mount org programming vc))
                         (org (compile core appearance vi ivy mount org server compile dashboard))
                         (main (compile core appearance programming vi mount org news mail dashboard vc tracking finance server))
                         ))
  (modular-config-default 'main)
  (modular-config-path "~/.emacs.d/lisp")
  :config
  (modular-config-command-line-args-process))

Modules can also be loaded interactively by using the modular-config-load-modules function.

All the different configurations can be accessed from the command line as

emacs --config none --modules "core appearance vi"

Dependencies

If a module depends on another module for some feature or service, the module can include a line which lists all the modules it needs.

(modular-config-load-modules '(space separated list of modules))

A module will be loaded, only once regardless of how many times it’s added within modular-config-load during startup. But when modules-load is called interactively, it will always load the module again.

If you have a portion of code in one of your module which depends on another module. You can can use a when block to make sure that portion of code is not evaluated if the module is not loaded.

(when (modular-config-modules-loaded-p 'module-name)
  ;; Dependent Code
  )

Example Module

There are no restrictions at all as to what belongs in your specific module. But if you need to depend on a module you must add (modular-config-load ‘(list of modules)).

(modular-config-load-modules '(versioncontrol syntaxcheck completion))
;; Specific emacs settings for programming environment
(add-hook 'prog-mode-hook 'flycheck-mode)
(add-hook 'prog-mode-hook 'company-mode)
(global-set-key (kbd "C-x g") 'magit)

Feel free to refer to my config at: https://github.com/SidharthArya/.emacs.d

Miscellaneous

Using Different Bookmarks for each config

(setq modular-config-use-separate-bookmarks t)
;; Optionally
(setq modular-config-separate-bookmarks-directory "~/.config/emacs-bookmarks") ;; Directory of Choice

Inherit other config

Since, currently the modular-config-list is written in simple list. We can inherit as follows:

(setq modular-config-list '(
                            (base (core appearance search selectrum help vi))
                            (org ((base vi) dashboard org vc completion))))

(base vi) here means, include everything in base config except vi module Credit for this feature goes to nv-elisp.

About

Organize your emacs config into small manageable modules

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published