Archive for the ‘Emacs’ Category

Undo in Emacs

Friday, June 20th, 2008

There are a variety of ways to “undo” something in Emacs.  Unfortunately some of the keystrokes work in some environments, while others do not.  Here’s a quick rundown:

  1. Meta-x undo — Will undo only the most recent changes.  Cannot be used multiple times.
  2. Ctrl-x u — Undo.  Consecutive repetitions will undo earlier and earlier changes.
  3. Ctrl-_ or Ctrl-/ — Same as Ctrl-x u, however does not work in some envrionments.
  4. Ctrl-Shift-Minus — Same as Ctrl-x u, however does not work in some environments.

For whatever reason I can never remember the Ctrl-Shift-Minus sequence when I find myself in an environment where Ctrl-_ and Ctrl-/ don’t work.

Keep in mind that Emacs undo is a bit different from traditional undo:  Undo actions themselves are recorded as actions.  This can be confusing.

In some environments, Ctrl-x Ctrl-_ will reverse the order of undo.  I avoid this out of fear that it will cause the universe to implode.

See the Emacs info node for more good undo lore, such as how to use “selective undo” which restricts undo actions to changes performed in the current active region.  (Very useful.)

Scratch that WordPress Etch

Tuesday, May 27th, 2008

This post comes via notes taken from another blog… seemingly gone awol.   Here for posterity.

Etch naturally has an older version of WordPress.  To upgrade to a more recent, possibly though unlikely more secure version,  the easiest way is to change your tracking to testing, install WordPress and then change back.  How to do it:

1.  Edit your /etc/apt/sources.list to track testing. If your sources.list says etch or stable, change that to testing.  For example if your source.list has:

deb http://debian.lcs.mit.edu/debian etch main contrib non-free
deb-src http://debian.lcs.mit.edu/debian etch main contrib non-free

change those to:

deb http://debian.lcs.mit.edu/debian testing main contrib non-free
deb-src http://debian.lcs.mit.edu/debian testing main contrib non-free

2.  After you change your tracking to testing do an apt-get update.

apt-get update

3.  Install WordPress

apt-get install wordpress

this may pull in a few new php libraries, such as libphp-phpmailer.  Let it.

(Note that you do not want to do an “upgrade”, but rather “install” as listed above.   “upgrade” will try to upgrade a ridiculous number of packages, whereas install will focus only on packages required for installing and/or upgrading WordPress.)

4.  Change your tracking back to Etch. just reverse what you did in step 1. that is change testing back to etch.

5.  Clean everything up.

apt-get clean && apt-get update

After all this is done, login back in as admin to WordPress, and it will tell you that you have to update your WordPress database tables.  Do that and you’re done.

Line number column in Emacs

Wednesday, May 7th, 2008

 Line number column in Emacs

This is something I’d always wished Emacs did; finally got around to finding a minor mode for it.

While the built-in line-number and column-number modes are fine, linum-mode makes it much easier to see where you are in the code at a glance.

To apply it to all buffers by default, throw the following in your .emacs:

(require 'linum)
(global-linum-mode)

Update: Now baked-in to version 23+ of Emacs!

Highlight Tail for Emacs

Saturday, April 12th, 2008

highlight tail for emacs Highlight Tail for EmacsThis is a cool little minor mode hack for Emacs. It’s like a last-typed heat map.

Onlookers will be amazed as you burn up the screen with your brilliant code.

Update: Rafal Jedruszek’s site above has gone AWOL, so I am preserving a copy here:

Highlight Tail version 1.3.9 (02 Apr 2007).

Prevent Emacs from whining about excess backup versions

Friday, April 11th, 2008

This Emacs prompt gets old after awhile:

Delete excess backup versions of SomeCode.php (y or n)

Emacs is trying to preserve space and clean up after itself.  And, always willing to please, it wants to make sure you’re cool with that.  The prompt is nice, but a tad overprotective.

Adding (setq delete-old-versions t) to .emacs will instruct Emacs to silently delete the older backups. This makes toggle testing between the editor and app much more pleasant.  (Or, for that matter, much less painful.)

Oh, and speaking of overprotective.. Remember to always practice safe emacs.

The easiest way to get Emacs Tramp Mode to play nicely with Windows and secure ssh connections

Saturday, March 1st, 2008

The easiest way is to go “under” Emac’s head and not bother with Tramp at all..

The currently distributed version of Tramp (2.0.x) has a design flaw wherein it assumes that ports are designated with a “-p” switch.  If you’re running Emacs on Windows, however, you will probably want to use Putty’s <code>plink</code> command instead of an command line ssh client.  Problem is plink uses a capitalized “-P” to indicate the port.  Urgh.  (Supposedly this is fixed in Tramp 2.1.x..)

Rather than muck around with this, consider tools that map the remote connection such that it appears local.  The well done open source app WinSCP does a pretty good job of this, though is a bit clunky in the way it syncs up its temporary cache.  South River Technologies’ WedDrive, however, is practically seamless.  Well worth the $60 for a one year license.

Emacs Reference Mug

Wednesday, December 5th, 2007

13045051 240x240 back.thumbnail Emacs Reference MugOh gentle reader, you have no idea how much I want one of these. Receptacle of refreshing beverage. Dispenser of Emacs wisdom.

Christmas is coming.

I wonder if I can convince family members to read my blog.
No one’s going to get this hint.

Update: I forced my wife to read my blog. She points out that it is both sad and telling that all I want for Christmas is an Emacs mug.

I’m going to bar her IP.

Killing Cygwin Emacs

Saturday, December 1st, 2007

This has been bothering me for a long time. According to an old post, Ctrl-C can’t be properly mapped in the normal Cygwin console running under Windows; so Ctrl-X-Ctrl-C-ing out of Emacs under Cygwin is not an option.

Alternatives are as follows:

  • Set the environmental variable CYGWIN=tty. (This may disable echo back to the local terminal when you exit Emacs.)
  • Run emacs under rxvt or X.
  • Use M-x kill-emacs. (I wish I had know about this years ago.)

Die, emacs. Die.

Default .emacs on Gentoo

Monday, July 2nd, 2007

Just a quick follow-up to Practicing Safe Emacs. Everyone knows that Gentoo is the greatest distro on the planet, superior in all ways to RedHat. Anyway, in Gentoo it’s possible to create a generic .emacs file for all users. A great way to ensure that everyone is, among other things, practicing safe editing.

To set this up, simply cons the commands you want into

/usr/share/emacs/site-lisp/site-start.el

and the config commands will be applied to all users. See the Gentoo Wiki Tip on using this to load Portage-installed Emacs packages.

Practicing Safe Emacs

Tuesday, June 26th, 2007

This has been bugging me for years and I finally got around to looking up a solution.

Everyone knows that Emacs is the greatest editor on the planet, superior in all ways to vi. Unfortunately, Emacs has this nasty habit of tossing tilde-terminated backup files around whatever directory in which you happen to be editing. Not only does this clutter up the file system, it can also be something of a security risk; especially if you’re working on web servers. And really, snapshots of your most recent save is not so useful if, like me, you pathologically ctrl-x ctrl-s your code every few characters or so.

After a bit of hunting I discovered that Emacs’ built-in versioning could solve both of these problems. Cons the following two commands into your local .emacs:

;; Enable versioning with default values.
(setq version-control t)

;; Save all backup file into the designated directory.
(setq backup-directory-alist (quote ((".*" . "~/.emacs.d/backups/"))))

and not only will Emacs remember all saves:

$ ls .emacs.d/backups/
!home!gates!GPLv3.txt.~1~ !home!gates!GPLv3.txt.~2~

but, as you see, it also tucks your backups safely out of harm’s way.