As I mentioned, my preferred text entry tool is a fountain pen. That doesn’t work on a computer. While I use a variety of email clients, Microsoft Word, and browser-based tools, my text editor of choice is GNU EMACS. Part of it is an appreciation of its heritage–this software dates back to the Seventies. It’s my choice in the long-running editor war with (the far inferior) vi. It’s multi-platform: I can use essentially the same tool in OS X, Windows, LINUX, and other operating systems. Designed in the days of VT100 terminals, it is as happy at the command prompt as it is in a GUI.
I appreciate the power. It can be configured to support different programming languages, or automate some processes. Hypothetically, I could use it as my email client (though I haven’t quite mastered getting it right), or act as a web browser. Some have compared it to an operating system.
The key configuration file is called .emacs (“dot emacs”). People spend years tuning and adjusting their .emacs file. I recently realized I was pasting in chunks from the various files on various systems. I wondered: in this era of cloud storage, could I have one .emacs to manage all my systems? For that matter, could I also use cloud storage to be the location for my extension modules. The advantage of this approach is I can ensure the settings are the same on each machine. Ideally, this also means that any modules I install will be present as well. There may be some tuning per machine, but, for the most part, it will be in common.
I decided my approach would be to host my core .emacs and modules on Copy.com as my cloud provider, though I think it could be used with OneDrive, Google Drive, or a similar product. Each machine would have a local .emacs that would point to the shared one, which I’m calling dot.emacs, though it could readily be called shared.emacs or common.emacs. dot.emacs would set some common settings, as well as machine-specific ones based on the hostname (the name assigned to a given computer).
Most cloud storage services create a spot on the local hard drive to point the cloud files to. On my MacBook, it’s /users/mrguilt/copy; on the WorkTop, it’s c:\users\my.real.name\copy. On the cloud, I created a directory called elisp for all the EMACS files, including dot.emacs. A variable, cloud-dir, is set th point to the cloud elisp directory, so all the modules I use can exist there. The local .emacs looks like this:
;;;Creates a variable pointing to where the cloud directory appears on ;;;this machine. (setq cloud-dir "~/Copy/elisp") ;;;showswhere the cloud elisp directory is. ;;;Hand-off to shared "dot-emacs" file (dot.emacs.el) (add-to-list 'load-path cloud-dir) (load-library "dot.emacs")
dot.emacs does the heavy lifting of settings. Notionally, I divided it into four sections or subsections:
- First, I wanted to test if the GUI version of EMACS was being used, or a terminal version, and make settings based on that.
- Within the GUI vs. terminal sections, I wanted to make some per-machine settings. Primarily, this is about fonts and colors, though other local settings may go into that section.
- Set some basic parameters, like what mode to activate for certain file types, whether or not I want backup files, etc.
- Set up and load any extensions, such as a twitter client.
The dot.emacs, which needs to be named dot.emacs.el, looks a bit like this:
;;;GUI vs. terminal, and per-machin settings (if (display-graphic-p) (progn (print "It's a GUI!") ;;; I like to have some feedback, for testing among other things ;;;General GUI Stuff (tool-bar-mode -1) ;Turn Off Toolbar (set-fringe-mode '(0 . 0)) ;;;Turn off fringe mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Checking what machine I'm using, and setting fonts and other local settings (if (string= system-name "WorkTop") (progn (print "It's the WorkTop!") (set-face-attribute 'default nil :font "Consolas") (set-face-attribute 'default (selected-frame) :height 120) ;;;Make the typeface a bit bigger (120%). (set-background-color "#FFFFCC") (if (string-match "MacBook.*" system-name) ;;;Work-Around for 10.10's hostname bug (progn (print "It's the MacBook!") (set-face-attribute 'default nil :font "Anonymous Pro") (set-face-attribute 'default (selected-frame) :height 165) ;;;Make the typeface a bit bigger (125%). (set-background-color "#8a9ff2") ;;;Set colors )) (if (string= system-name "WinVM") (progn (print "It's the Windows VM!") (set-face-attribute 'default nil :font "Consolas") (set-background-color "#A9F5A9") )) ) ;;; else ;;; Things for terminal mode (progn (print "It's a Terminal")) ) ;;;Common settings--these are mine; you may have something different (setq make-backup-files nil) ;;; I don't want backup files. ;;; Auto Longline Mode for .txt and .html (blogstuff) (setq auto-mode-alist (cons '("\.txt" . longlines-mode) auto-mode-alist)) (setq auto-mode-alist (cons '("\.html" . longlines-mode) auto-mode-alist)) ;;;Here is where loading extensions and settings go. ;;;Twittering Mode (add-to-list 'load-path (concat cloud-dir "/twittering-mode-3.0.0")) (require 'twittering-mode)
Adding machines is as simple as adding another if-then block.
One question might be, why not put local settings, like colors and fonts, into the local .emacs file. In fact, I had a note in the comments of my dot.emacs file asking that very question–my initial implementation became as much a game of “can I do this” as a practical event. Recently, the wisdom of putting local settings in the common file made sense: my WorkTop hard drive needed to be reimaged. I was able to sett this back up by simply copying the .emacs, as written above, into the proper place. In effect, all my systems also have the same local .emacs file.
I’m not sure if everyone has a need for such a crazy configuration, or uses as many different systems as I do. However, I think it speaks to the power of the EMACS that it can accommodate a shared configuration file.