No Clean Feed - Stop Internet Censorship in Australia

Emacs

Posts relating to the Emacs editor.

Column editing in Visual Studio 2010

Visual 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

Astute 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

Yet 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

I 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

  1. First, install ccrypt with:
    sudo apt-get install ccrypt
  2. 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

  1. First, download the Cygwin build of ccrypt from ccrypt-1.7.cygwin-i386.zip.
  2. Then, unzip that file into your program files folder, so that you have something like C:\Program Files\ccrypt-1.7.cygwin-i386 containing 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
  3. 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.



  4. 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

I 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.

  1. 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).
  2. Extract the emacs-22.3 folder inside the ZIP file into your Program Files directory (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 like C:\Program Files\emacs-22.3 that contains the following:
    bin
    etc
    info
    leim
    lisp
    site-lisp
    BUGS
    COPYING
    INSTALL
    README
    README.W32


  3. Create a per-user environment variable (instructions for Vista / Windows 7 and XP) called HOME, with the value %USERPROFILE%. Emacs uses the HOME environment variable to work out where to store your settings, and by default HOME isn'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.



  4. Add Emacs to your start menu by opening Program Files\emacs-22.3\bin (Program Files\emacs-22.3\bin on Windows 7), and double-clicking on runemacs.exe. Once Emacs has opened, close it, then right-click on runemacs.exe and choose Pin to Start Menu. (You could have pinned emacs.exe but 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.





  5. 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).
  6. 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 clone fails, you might be behind a firewall that prevents Git traffic; if so, try using http:// instead of git://.

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:

Emacs Screenshot on Windows

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

I 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).

  1. 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.

  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.

  3. 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:

Emacs Screenshot on Linux

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

I 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 ...

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

This 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

Here'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.

  1. Download profont-x11.tar.gz from here and save it in your home directory.
  2. 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 .
  3. Log out and then restart the X server with Ctrl + Alt + Backspace.
  4. Log in and run Emacs.
  5. Choose Options -> Customize Emacs -> Browse Customization Groups.
  6. Expand Emacs -> Faces -> Basic Faces.
  7. Click the Face link to the left of Default.
  8. Scroll down in the second buffer until you see Font Family, and enter nil-profont in the text field.
  9. In the height field, enter 89.
  10. C-x C-s to save, and your font should immediately change to 9 point ProFont.
Syndicate content