Emacs
Column editing in Visual Studio 2010
Submitted by Duncan Bayne on Wed, 2010-07-28 00:29Visual Studio 2010 now - finally - has column editing; see Visual Studio 2010 - Box Selection for instructions. It's gradually catching up to Emacs in some respects ;-)
Clearing the deck
Submitted by Duncan Bayne on Wed, 2010-06-30 03:26Astute observers may have noticed that I've removed several GitHub repositories (duncans_fvwm, duncans_emacs and plumbing) and emptied the andelys repository.
I originally made duncans_emacs and duncans_fvwm public as part of a tutorial series on Emacs, but seing as almost no-one has been making use of them or following the tutorial, I've shut them down and incorporated both into my private Subversion repository. Plumbing has gone west as a consequence of my decision to restart the andelys (Rails-based media player) project using Hobo.
Finally, I've marked the Wuji project as no longer under active development, simply because it does what I need it to and I have no plans for additional features.
Instant messaging in Emacs
Submitted by Duncan Bayne on Sat, 2009-09-26 23:42Yet another reason not to leave Emacs ... courtesy the console-based CenterIM and a little bit of code in my .emacs file, I can do all my instant messaging (MSN, Google Talk, ICQ, ...) from within Emacs (thanks to Anselm Helbig on comp.emacs for some elisp advice):
I've updated my Emacs setup on GitHub to include the code to set up CenterIM in a multi-term window. You'll want to ensure that your system has CenterIM installed; on Ubuntu this is as simple as:
sudo apt-get install centerim
Note that my Emacs setup is sufficiently clueful to detect if you're running on MS Windows, & not try to start up any multi-term sessions, including CenterIM.
HOWTO: Emacs: Encrypted Files
Submitted by Duncan Bayne on Sat, 2009-04-25 05:20I have deleted The GitHub repositories referred to in this post; see Clearing the deck for details.
This post is part of my HOWTO series on Emacs.
There is a tool called ccrypt that uses Rijndael encryption to encrypt and decrypt files. I use this myself to secure my personal journal, and a file containing useful passwords and the like. Normally, I'd use it like this:
$ echo Hello world! > foo.txt $ ccrypt -e foo.txt Enter encryption key: pass Enter encryption key: (repeat) pass $ cat foo.txt.cpt ��䒨y u��t4@�6Z?UE� ��[~u50Օ���d����� $ ccrypt -d foo.txt.cpt Enter decryption key: pass $ cat foo.txt Hello world!
As you can see, ccrypt -e does the encryption after prompting for a key, renaming foo.txt to foo.txt.cpt in the process. Obviously, ccrypt -d does the decryption. Unfortunately the whole process is a bit convoluted, involving a command prompt and the possibility of forgetting to encrypt the file again afterwards.
Fortunately there's an Emacs plugin for ccrypt that handles all of this for you. Below are instructions on setting this up for Linux and Windows; as usual (nowadays - how things have changed), the Linux installation is quick and easy and the Windows installation awkward.
After the installation instructions, I describe how to use the plugin, and then go on to explain the changes I made to my .emacs file and .emacs.d directory to enable it.
Linux Installation
- First, install ccrypt with:
sudo apt-get install ccrypt
- Next, if you've installed my personal Emacs configuration from GitHub, update it with:
cd ~/duncans_emacs git pull
... and you're good to go.
Go and bask in the sun, drink a beer, reflect on how easy that was ... and consider making a donation to the folks who make your Linux Distro (Ubuntu in my case), or the Free Software Foundation who make Emacs.
Windows Installation
- First, download the Cygwin build of ccrypt from ccrypt-1.7.cygwin-i386.zip.
- Then, unzip that file into your program files folder, so that you have something like
C:\Program Files\ccrypt-1.7.cygwin-i386containing the following:
AUTHORS ccrypt.1 ccrypt.exe ccrypt.html ChangeLog COPYING cygwin1.dll cypfaq01.txt jka-compr-ccrypt.el jka-compr-ccrypt.elc NEWS README README.win
- Edit your PATH environment variable (instructions for Vista and XP) and add the folder you created in Step 2 above, separating it from the others with a semicolon.
You can test that your new environment variable is set correctly by opening a Command Prompt and typing:
ccrypt --version
You should see something like:
ccrypt 1.7. Secure encryption and decryption of files and streams. Copyright (C) 2000-2004 Peter Selinger.
... in response.
- Finally, if you've installed my personal Emacs configuration from GitHub, update it with by running Git Bash and entering:
cd ~/duncans_emacs git pull cd ~ rm -rf .emacs .emacs.d cp -f duncans_emacs/emacs .emacs cp -rf duncans_emacs/emacs.d .emacs.d
... and don't forget to glare at your Linux-using neighbour who's lazing around outside in the sun at this point :-)
Using It
If you save a buffer with a file extension .cpt, Emacs will automatically prompt you for a key and encrypt the buffer with ccrypt when it saves. If you open a file with the extension .cpt, Emacs will prompt you for a password to decrypt the buffer into memory. That's all there is to it.
If you're a real Emacs newbie and you're sitting there thinking "what does he mean by buffer?" then you should read through the Keyboard Basics section of this excellent Emacs tutorial. All will become clear, I promise ... and if it doesn't, please either post your questions in the comments section, or email me.
Details
In order for Emacs to load the ccrypt plugin we need to do two things in the .emacs file: add the path to the plugin to load-path (the list of paths Emacs checks when instructed to load something), and then actually load the plugin.
This line adds to the path:
(add-to-list 'load-path
"~/.emacs.d/ccrypt")And these lines load the plugin (well actually, the first is a comment):
;; allow automagic editing of ccrypt-ed files (require 'jka-compr-ccrypt "jka-compr-ccrypt.el")
HOWTO: Emacs: Windows Installation
Submitted by Duncan Bayne on Sat, 2009-04-25 02:07I have deleted The GitHub repositories referred to in this post; see Clearing the deck for details.
This post is part of my HOWTO series on Emacs.
Thanks to Nigel Thorne for feedback and bug reports on this HOWTO.
Installing Emacs on Microsoft Windows is a little more convoluted than on Linux, because a lot of the functionality we take for granted on most modern Linux distros is missing from Windows.
- Download Emacs 22.3 from http://ftpmirror.gnu.org/emacs/windows/emacs-22.3-bin-i386.zip (this URL will find the closest GNU mirror to you).
- Extract the
emacs-22.3folder inside the ZIP file into yourProgram Filesdirectory (Program Files (x86)on Windows 7). (I suggest using a free third-party ZIP utility like FilZip - credit to Joseph Iscaro for bringing FilZip to my attention).
You should be left with a directory called something likeC:\Program Files\emacs-22.3that contains the following:
bin etc info leim lisp site-lisp BUGS COPYING INSTALL README README.W32
- Create a per-user environment variable (instructions for Vista / Windows 7 and XP) called
HOME, with the value%USERPROFILE%. Emacs uses theHOMEenvironment variable to work out where to store your settings, and by defaultHOMEisn't set on Windows.
You can test that your new environment variable is set correctly by opening a Command Prompt and typing:
echo %HOME%You should see something like:
C:\Users\duncan... in response.
- Add Emacs to your start menu by opening
Program Files\emacs-22.3\bin(Program Files\emacs-22.3\binon Windows 7), and double-clicking onrunemacs.exe. Once Emacs has opened, close it, then right-click onrunemacs.exeand choosePin to Start Menu. (You could have pinnedemacs.exebut then you'd get a DOS box opening every time you ran Emacs from the Start Menu).
In the following steps, we'll get my personalised Emacs configuration and plugins from GitHub. You could skip them as I'll be going through how it all works in detail in subsequent posts, but for now if you want all the Emacs Goodness (TM) and you want it now! then you should follow these steps. - Download and install Git from http://msysgit.googlecode.com/files/Git-1.6.5.1-preview20091022.exe. When installing, choose Unix line endings but accept all other defaults. (Thanks to the msysgit team for this - up until recently installing Git on Windows was a truly painful experience).
- Open Git Bash from the Start Menu, and enter the following commands:
cd ~/ git clone git://github.com/duncan-bayne/duncans_emacs.git duncans_emacs ln duncans_emacs/emacs .emacs ln -s duncans_emacs/emacs.d .emacs.d
Note that if the
git clonefails, you might be behind a firewall that prevents Git traffic; if so, try usinghttp://instead ofgit://.
With installation complete, you can now verify that all is well by running Emacs from the Start Menu (just click on the runemacs.exe shortcut we created in step 4. You should be met with a window that looks a lot like this one:

Now might be a good time to introduce you to your first Emacs command, save-buffers-kill-emacs, which prompts you to save any open buffers and then exits.
You can run this command by pressing Crtl-x, then Ctrl-c. Or you can run it manually by typing Alt-x then typing save-buffers-kill-emacs and pressing enter (you can use tab-completion to avoid typing the entire command).
That's all there is to it. Now that I've covered installing Emacs, I'll soon get started with the meat of the series - how to improve your productivity as a developer using Emacs.
HOWTO: Emacs: Linux Installation
Submitted by Duncan Bayne on Sat, 2009-04-04 03:46I have deleted The GitHub repositories referred to in this post; see Clearing the deck for details.
This post is part of my HOWTO series on Emacs.
These instructions assume you're reasonably familiar with Linux already, and that you're happy working from a command prompt (we'll assume bash). If not, I suggest you go and take a look at Getting Started With Linux.
(These instructions apply to Ubuntu and its derivatives, such as XUbuntu, KUbuntu, etc. They should also work on Debian and any other apt based distros. Instructions specific to other distros would be greatly appreciated; either email me or just post them in the comments).
- Do you have Emacs installed? Type:
whereis emacs22
... in a console and if you see a list of binary file locations, you can proceed to step 3. If not, continue on to step 2.
- Install Emacs 22 with:
sudo apt-get install emacs22
... supply your password when / if prompted, agree to install any required dependencies, and you're done.
- Get my personalised Emacs configuration and plugins from GitHub.
You could skip this step as I'll be going through how it all works in detail in subsequent posts, but for now if you want all the Emacs Goodness (TM) and you want it now! then you should ...
cd ~/ git clone git://github.com/duncan-bayne/duncans_emacs.git duncans_emacs ln -s duncans_emacs/emacs .emacs ln -s duncans_emacs/emacs.d .emacs.d
Note that if the git clone fails, you might be behind a firewall that prevents Git traffic; if so, try using http:// instead of git://.
Now that you've finished installing, you can verify that all is well by running Emacs - either from the menu in your chosen window manager, or from the command line with:
emacs &
You should be met with a window that looks a lot like this one:

Now might be a good time to introduce you to your first Emacs command, save-buffers-kill-emacs, which prompts you to save any open buffers and then exits.
You can run this command by pressing Crtl-x, then Ctrl-c. Or you can run it manually by typing Alt-x then typing save-buffers-kill-emacs and pressing enter (you can use tab-completion to avoid typing the entire command).
That's all there is to it. Soon I'll post installation instructions for MS Windows, and then we'll get on to the meat of the series - how to improve your productivity as a developer using Emacs.
HOWTO: Emacs: Index
Submitted by Duncan Bayne on Sun, 2009-03-29 04:07I have deleted The GitHub repositories referred to in this post; see Clearing the deck for details.
Emacs isn't just a text editor, it's a cross-platform scriptable productivity tool. You can use it to debug your Ruby applications, run terminals, browse the web, check your email, and more.
Over the next few weeks, I'll be posting a series of HOWTOs covering many of the cool Emacs tricks I've figured out.
If you're not already familiar with the basics of Emacs, I suggest installing as per my instructions below, then working through this excellent Emacs Beginner's HOWTO by Jeremy D. Zawodny. If you're in a hurry, the Keyboard Basics section covers opening and saving files, and navigating through buffers.
So far ...
- Index - the post that you're reading right now!
- Linux Installation - installing Emacs 22 on Ubuntu & derivatives.
- Windows Installation - installing Emacs 22 on Microsoft Windows XP, Windows Vista and Windows 7.
- Encrypted Files - how to use Emacs to automagically encrypt and decrypt files.
- My first real-world LISP code - how to write an Emacs macro to close all open unmodified file buffers.
In the pipeline ...
- how to make your Emacs configuration portable, so you can take it with you wherever you go
- some of my favourite Emacs plugins (oriented towards Rails development and productivity)
- how to enhance it by writing your own Elisp code
(Thanks to Dr. Nic for his inspirational presentation on tools & efficiency at Trampoline; the motivation to actually get into gear and write up this series is in no small measure due to his infections enthusiasm while evangelising TextMate).
Rails on Cygwin on Vista
Submitted by Duncan Bayne on Sun, 2008-11-09 12:06This is, frankly,amazingly cool. With a bit (alright, a lot) of fiddling around I've got Cygwin running sufficiently well on Vista that I can use said operating system to test out an idea (specifically: emitting WSDL from Ruby based on ActiveRecord objects, and having Visual Studio build a .NET 2.0 - based web service client from that).
Anyway, here's what it looks like:
Personally I'm quite chuffed. I'll be posting details - along with an archive of my emacs setup - shortly.
HOWTO: Ubuntu, ProFont, Emacs
Submitted by Duncan Bayne on Mon, 2008-03-31 13:26Here's how to install ProFont on Ubuntu, and change it to be the default font in Emacs. This should work on all flavours of Ubuntu, but I've only tested it on Xubuntu 8.04 and Ubuntu 8.10.
- Download profont-x11.tar.gz from here and save it in your home directory.
- From your home directory, run the following shell commands:
tar -zxvf profont-x11.tar.gz
cd profont-x11
gzip *
sudo cp *.gz /usr/share/fonts/X11/misc
cd /usr/share/fonts/X11/misc
sudo mkfontdir . - Log out and then restart the X server with Ctrl + Alt + Backspace.
- Log in and run Emacs.
- Choose Options -> Customize Emacs -> Browse Customization Groups.
- Expand Emacs -> Faces -> Basic Faces.
- Click the Face link to the left of Default.
- Scroll down in the second buffer until you see Font Family, and enter nil-profont in the text field.
- In the height field, enter 89.
- C-x C-s to save, and your font should immediately change to 9 point ProFont.




Recent comments
1 week 1 day ago
3 weeks 3 days ago
3 weeks 6 days ago
11 weeks 1 day ago
15 weeks 5 days ago
31 weeks 18 hours ago
31 weeks 23 hours ago
37 weeks 3 days ago
37 weeks 3 days ago
37 weeks 4 days ago