In Emacs, there are just some things I needed to change right off the bat to feel at home. The
C-z binding, for instance- undo. No more of that suspend business! Since that first customization, I have devised dozens more. Some people I collaborate with somehow make minimal changes to the default interface, and when one of these Luddites tries driving my setup, will invariably grow confused when certain actions don’t do what he/she is expecting- which is perfectly reasonable! I’m the weirdo, for changing what the Emacs creators have designed, so the onus is on me to provide a quick way back to a machine anybody can drive. Hello, minor modes.
A minor mode is a perfect solution to introduce customizations within Emacs. For one thing, all of my settings can be toggled on or off instantly. When I’m driving, I slip into my familiar vehicle, perfectly molded to my tastes. When I leave the driver’s seat, the same vehicle loses all specificity to my former presence.
Another convenience I didn’t realize I would enjoy until I implemented this feature is that minor mode keymaps have the ability to override Major Mode keymaps. This is quite nice, because now I don’t feel like I’m a backseat driver to certain Major Modes! When I define a keybinding, it will work under just about any conditions. (Some exceptions I have found to this rule are org-mode and flyspell-mode. How irritating!)
So, how’s this implemented? Get to the juicy part! The command we’ll be using is
define-minor-mode. The top gist contains the setup- the minor mode itself, and the keymap that we will bind to it. The second will contain a snapshot of my current customizations, all the ones that I can flip on or off with a single command. If you are interested in the latest version, it will be eternally accessible on github. As you can see, we can be quite flexible and creative with the material we provide with this personal mode.
Once this is all set up, to toggle my personal minor mode (and all the jazz that comes with it), all I have to run is