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.

Like this:

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)

; 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)

;
; later:
; 
; make home and end buttons work better
; 
; figure out how to make emacs work better with markdown
;
; Tabs, fast tab switching 
;

Comments

  1. #1 Jim Ramsey
    Tallmadge, Ohio
    December 13, 2012

    http://files.myopera.com/bashvi/albums/642917/vi-emacs-final.png

    I’m only slightly evolved from using “ed”, so I use “vi”. At least I don’t have the crippled fingers from using “emacs”.

  2. #2 Eric Lund
    December 13, 2012

    Back when I was in grad school, there was an emacs vs. vi holy war raging (perhaps it rages still), and my sysadmin was definitely on the vi side. So I ended up using vi, despite its infamously user-hostile interface.

    It’s better now–at least it color codes keywords and comments when you are writing source code in any of several different languages–but it’s still frequently annoying. It likes to wrap lines when it wants to (there is a reason I want all of that text on one line, damn it!), and it can do spectacularly destructive things if you think you are in edit mode when you are not.

    But yes, it’s largely inertia that keeps me with vi. I’d have to (re)learn an entirely different set of arcane keystrokes to switch back to emacs, and I don’t use either program enough to justify the effort (I have a LaTeX application on my Mac, and it has an editor built in; for other things like paper reviews, TextEdit is perfectly adequate).

  3. #3 Greg Laden
    December 13, 2012

    Jim, you could always grow an extra finger in just the right place, using certain elisp code.

    Eric, yes, it rages!

    on the iMac, I recommend BBE.

  4. #4 Dave X
    December 13, 2012

    I never considered the C-f = isearch-forward setting. Duh. I’m doing it.

    I also like having a comment like this in my .emacs file, since I forget it after months, but always seem to want it when I’m looking at an elisp file.

    ;; C-x C-e == eval-last-sexp

  5. #5 gruebait
    December 13, 2012

    I’m suspicious of any text editor that includes a text adventure.

  6. #6 Greg Laden
    December 13, 2012

    But it makes coffee.

  7. #7 Tim Schafer
    December 13, 2012

    I’ll take this as an opportune moment to remind you of this:
    “The emacs philosophy is deeply flawed and needs to be overhauled. I’m working on a post that follows up on that rather tendentious statement, and don’t worry, I’ll make good on it.”

    It’s only been a year, no rush, I can wait. On the plus side you’ve got another follower.

    I see what you did there.

  8. #8 Greg Laden
    December 13, 2012

    Still working on it!

Current ye@r *