Daily Archives: December 12, 2012

Do you know where your .emacs file is? UPDATED

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"
  (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))

(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

Could there be an "Out" Atheist in the US Senate?

Tea Party leader South Carolina Senator Jim DeMint is stepping down from his position in the US Senate to take on leadership of the Conservative Heritage Foundation. That itself is kind of strange, since being a US Senator is a Big Huge Deal and being the head of some think tank is only a moderately big deal. But no matter. Since he is leaving office, he needs to be replaced, and that job, in South Carolina, goes to the Governor, Nikki Haley, one of those enigmatically female Republicans. One of the candidates she is apparently considering for the job is Jenny Sanford, the ex wife of Mark Sanford. Remember him? He’s the guy ow disappeared in 2009 while he was governor to visit his mistress in Argentina. That would be funny.

Meanwhile, the Charleston City Paper is running a poll to see who should be selected to fill this seat. The poll is here. Naturally, one of the names proposed in that poll is Stephen Colbert, the TV comedian guy, who happens to be from South Carolina. At present, he has 11% of the vote and as such is in distant second place to Herb Silverman.

Who is Herb Silverman, you may ask? He’s the president of the Secular Coalition for America, and while technically one does not have to be an Atheist to have that job, he is one. And, he has 87% of the vote in the City Paper’s poll!

I understand that the Secular Coalition for America, on Silverman’s behalf, has challenged Colbert to a debate. They are in touch with Colbert via his twitter handle @StephenAtHome and the conversation is happening with the hashtags #SenatorHerb and #senatorcolbert … you might want to go join the fun.

By the way, Richard Dawkins has come out with an endorsement of Silverman.

“South Carolina has recently shown itself to be a leader in political diversity, with an Indian-American Governor and the only African-American Republican in Congress,” Dawkins said, according to the Charleston City Paper. “I think the time is now ripe for South Carolina Governor Nikki Haley to appoint Herb Silverman as the first acknowledged Jewish Atheist in the United States Senate.”

I am not holding my breath, but I am making popcorn!

See also this.

Why are some animals rare, and why is this very important?

A friend of mine told me this story: As a special forces soldier, a Green Beret, he was alone and traveling through a dense area of jungle in or near Viet Nam during the 1960s. Enemy soldiers were nearby and he intended to pass through their patrol area to arrive at some safe destination, but he fully expected to run into a trip wire, a sentry, or a squadron of hostiles. His rifle was loaded and ready to fire at any moment. Continue reading Why are some animals rare, and why is this very important?