I just reconfigured my laptop with a new system (a form of Linux) and, almost as important, a new power brick. That second item may be more interesting than it sounds for some of you; I’ll write that up later. This change also meant trashing my emacs configuration file. I didn’t have to trash it, of course, but it made sense to do so. I don’t use my laptop in any way that requires that I pay attention to data saved on it. It is a data-free appliance. Sort of. Or, at least, if I took the hard drive out of it and put it in a blender, I would not lose anything important other than a blender which would surely break. In order to achieve this state, I manage certain data not by backing it up but by ignoring it. If I toss the hard drive and put in a new one and install a new system, my emacs configuration file(s) can be gotten off of another computer. Or, preferably, just recreated from scratch.
Why would I want to recreate my emacs configuration files from scratch? Because a) it is fun and b) with the newest version of emacs, a number of things that required excessive messing around with before have become normal. Thus, the configuration files are less cumbersome and easier to manage.
In case you are still reading this post about emacs (good for you!) but don’t know much about it let me explain a few things. If you are already an emacs expert, you may want to skip down to my .emacs file and get right into ridiculing it.
emacs is the best text editor in the world for a number of reasons, but mainly because pretty nearly everything is configurable, and it is very cleanly associated with a very powerful programming language that you can write programs in to make your emacs text editor do amazing things like manage your email, carry out sophisticated statistical analyses on data, make coffee, or stand in for an operating system. Or, you can do like I do; find where other people have written these things and graciously made them available for others to use.
But emacs also suffers from a logical conundrum I call The emacs Paradox. Here is how it goes:
emacs is wonderful because you can configure it any way you want.
emacs keybindings (what happens when you press certain keys) are the most efficient possible therefore you must not change emacs keybindings.
We know this is an interesting paradox because right after hearing all about how emacs keybindings are wonderful, the first thing you will be told to do if you read the introductory material on emacs is to swap the caps lock and control keys, and the second thing you will be told to do is to replace the alt key with any one of a number of alternatives “so you won’t have to squish up your fingers” while executing “meta” commands. This duality (’emacs is perfect ’emacs is flawed) is part of what makes emacs a religion.
That’s the guy who invented emacs.
OK, back to the point. emacs out off the box is probably pefect for some people. emacs with two or three hundred lines of elisp code in various files, some compiled, is perfect for others. But I use emacs to write, not program, so my needs are met by the out of the box version with a hadnful of changes.
My emacs file is below, and it is annotated to make it clear what each step does. This is all hand-codedd. Many of these changes can be made by selecting configuration options from the emacs menu.
Included in the file are a few comments of possible additional changes I may or may not make. I’m agnostic as to whether these changes are worthwhile; I go back and forth. The comments are in there as reminders.
The file is called .emacs and resides in the home directory on a Linux computer with all the other “dot” files, which are by default hidden from view in many file managers (unless you specify otherwise).
And here is mine (UPDATED to make CUA work better within emacs and between apps:
; ; ; This is a text editing-focused .emacs file ; a ";" means "comment" if it is in the first position ; ;---Reload the .emacs file after messing with with alt-x reload-dotemacs (defun reload-dotemacs() "Reload .emacs file" (interactive) (load-file "~/.emacs")) ; do not display the annoying startup screen (setq inhibit-splash-screen t) ; get rid of annoying box cursor ; replace it with a nice bar cursor (set-default 'cursor-type 'bar) ; type face size needs to be bigger on this laptop ; number (190)/10 = point size (set-face-attribute 'default nil :height 190) ; scroll bar on right where all other scroll bars ; in the universe ever are (set-scroll-bar-mode 'right) ; make Visual Line Mode work in text mode all the time ; (this means, make the text wrap as in a normal ; text editor) (setq text-mode t) (global-visual-line-mode 1) (cua-mode t) ; ; Make sure ctrl-a selects all ; (global-set-key (kbd "C-a") 'mark-whole-buffer) ; ; ; turn automatic spell checking on more or less universally (defun turn-spell-checking-on () "Turn flyspell-mode on." (flyspell-mode 1) ) (add-hook 'text-mode-hook 'turn-spell-checking-on) ; turn on "CUA mode" ... so control -c, -v, -x, -z and ; a few other things work as they do in virtually all ; other software ever (setq cua-auto-tabify-rectangles nil) ;; Don't tabify after rectangle commands (transient-mark-mode 1) ;; No region when it is not highlighted (setq cua-keep-region-after-copy t) ;; Standard Windows behaviour ; Make the keys work even if CUA does not: (global-set-key (kbd "C-c") 'copy) (global-set-key (kbd "C-v") 'paste) ; Make emacs use the system clipboard even if CUA does not: (setq x-select-enable-clipboard t) ; associations ; add later some minor modes for certain kinds of files ; ; macros ; add later some handy markdown and html macros and functions ; ; make ctrl f cause forward "search" (global-set-key (kbd "C-f") 'isearch-forward) ; make ctrl s save the current document (global-set-key (kbd "C-s") 'save-buffer) ; some other time make the escape key stop commands in process ; ; Don't make the files with the #'s in the names ; a default emacs behavior we don't want (setq auto-save-default nil) ; stop creating those #auto-save# files ; make a hidden backup to a directory mirroring the full path ; of files edited (defun my-backup-file-name (fpath) "Return a new file path of a given file path. If the new path's directories does not exist, create them." (let* ( (backupRootDir "~/.emacs.d/emacs-backup/") (filePath (replace-regexp-in-string "[A-Za-z]:" "" fpath )) ; remove Windows driver letter in path, e.g. “C:” (backupFilePath (replace-regexp-in-string "//" "/" (concat backupRootDir filePath "~") )) ) (make-directory (file-name-directory backupFilePath) (file-name-directory backupFilePath)) backupFilePath ) ) (setq make-backup-file-name-function 'my-backup-file-name) ; make the titlebar (window frame top) show the name of the file in the buffer. (setq frame-title-format "%b") ; ; ; ; Line by line scrolling. By default, Emacs scrolls off the visible buffer by several lines. This is annoying ; This causes the scroll set to be whatever you want, in this ase, 1 ; ; (setq scroll-step 1) ; ; ; also, make the middle mouse wheel scroll only one line at a time ; ; (setq mouse-wheel-scroll-amount '(1 ((shift) . 1))) ; ; later: ; ; make home and end buttons work better ; ; figure out how to make emacs work better with markdown ; ; Tabs, fast tab switching ;