Monday, March 9, 2009

Using tags in emacs on windows




This requires you install the Gunwin32 tools or Cygwin, and describes how to build a tags table for the project you're working on, when using emacs to edit the source.

First you want to generate a file containing all the source files you want to have tagged. Go to the root folder of your project.
find . -regex ".*\(h$\|cpp$\)" > files.txt
Next pass this to etags to generate the tags table.
etags.exe - < files.txt 

Then when you're in emacs you need to visit the tags table, which will have been saved as TAGS. M-x visit-tags-table then browse to the folder where you made the TAGS file. Now when you have the curser on some function you can type... M-. to go to a tag and C-u M-. to go to the next tag. Once you're done, you can return to where you started with M-* Another useful function is tags-apropos Which will list all the tags matching a regex in a buffer.

Friday, February 20, 2009

Sending mail with emacs in Windows


Thanks to a commenter in my earlier blog post for pointing me to this way of sending mail that actually does work:

http://www.emacswiki.org/emacs/GnusMSMTP

You need to download msstp from sourceforge and install the exe in your path.

http://sourceforge.net/projects/msmtp/

There is one change I needed to make to get this working. In the config file:

msmtprc.txt

You need to add a line

from your.email@address.here

Without that I was getting an error number and no email. If you run into a problem like that you can make sure MSSTP is running by trying it from the command line:

msmtp -a yourname some@recipient.com

Type some mail and hit Ctrl-Z and it should send correctly.

Once that is working you can enter gnus within emacs, and send a mail using:

M-x message-mail

Fill out the fields and type C-c C-c and it should send correctly.

A security issue with this is that it doesn't seem to work if you leave your password empty in the configuration file. From the command line it simply prompts you for your password and away you go, but from emacs it just hangs. So if you use this method you're taking the huge risk of having your password in a readable file on the hard drive. I'll be trying to find a way around that before using this permanently.

Monday, February 16, 2009

Who uses the A* code

I often wonder who uses the A* code. Sometimes people write to me to tell me they've used the code in their University assignments or just for fun, but has anyone used this in a project that I don't know about?

My A* algorithm on google code

During my time at Activision I worked on a code base that included some code from their game Gun, and was happy to find my code, verbatim included there too!

Also, today, I downloaded a 2d game prototyping engine called Angel, from some EA guys. When I looked at how their path finding worked, I was surprised to see my code in there too!

http://code.google.com/p/angel-engine/

It's cool that people are using this code. If you do use it in some commercial or interesting project, please let me know. A credit or thank you in your product would be nice too!

A* algorithm bug fixes

It's been a while since I checked the issues page on my A* algorithm google code project. So it turns out there's a possible memory leak and the Manhattan distance calculation in the findpath.cpp is wrong. I've investigated both of these and uploaded a fixed version.

In the case of the memory leak, there is some code in my "fast simple allocator" which allocates some memory, assigns it to a temporary pointer, then converts it and stores it in a member variable. Apparently, this shows up in memory tracking software as a leak, even though the memory is released in the destructor, so I've changed the code so that the allocation and free is done with the same variable.

The Manhattan distance refers to a simple heuristic for finding a path when you can only move horizontally and vertically through a grid. Like calculating how far you would have to walk in a city on a grid system, like NY, you simple count how many blocks along and how many blocks up you need to walk. Well I implemented this carelessly and forgot to make sure that I take the absolute value when calculating the difference between 'streets'. That's done now.

You can download the latest version of the A* algorithm here...

http://code.google.com/p/a-star-algorithm-implementation/downloads/list

Friday, February 13, 2009

Setting up lispworks personal

I've always used this excellent pair of blog posts by Bill Clementson to get lispworks personal working with emacs/slime on windows.

Configuring SLIME for 3 Win32 CL Implementations
Using LispWorks Personal with Emacs/SLIME on Windows

Having had the joy of a hard drive failure last week I had to reinstall everything, and I've found that with the latest CVS version of slime you need to change your ".slime.lisp" file to look like this:


(load "/YOURPATHTOSLIME/slime/swank-loader.lisp")
(swank-loader:init)
(swank::create-server :port 4005)


So if your slime/lispworks personal setup stops working when you upgrade slime, hopefully you found your way here.

Searching Reddit, Flickr, and Google from emacs = Rad

I came across another brilliantly useful corner of emacs today.

webjump by Neil Van Dyke is part of emacs and Xemacs, and gives you a way to assign memorable names to web site urls, and to build simple search queries. It then opens the website using emacs' built in browse-url function.

Set up is easy. All you need to add something like this to .emacs:


(require 'webjump)
(global-set-key [f2] 'webjump)
(setq webjump-sites
(append '(
("Reddit Search" .
[simple-query "www.reddit.com" "http://www.reddit.com/search?q=" ""])
("Google Image Search" .
[simple-query "images.google.com" "images.google.com/images?hl=en&q=" ""])
("Flickr Search" .
[simple-query "www.flickr.com" "flickr.com/search/?q=" ""])
)
webjump-sample-sites))


The first line just makes sure the feature is loaded, and then I bind the webjump function to F2 in the second line.

To use webjump, just press F2, and press TAB to expand the sample sites that are built in, and the ones we just added above. Type Flickr Search for example, and then you get a prompt for the search string. Once you enter that your browser should open with flickr showing the search.

I've added Reddit, Flickr, and Google image search above, but it's easy to add your own as follows:

Each entry in the jump list takes the form (name . url|builtin), where the simplest shortcut is just a name, url pair like this:


("astar algorithm" . "http://www.heyes-jones.com/astar")


There are some builtin functions that you can use. For example simple-query lets you enter some text that will be inserted between two strings. The format is:


("Reddit Search" .
[simple-query "www.reddit.com" "http://www.reddit.com/search?q=" ""])


When doing something more clever than an url you pass in a vector (hence the []'s), where the first argument is the function, the second is the default url (if the user doesn't enter anything, and the third and forth arguments are the prefix and the postfix wrapped around the users input to make the search work. In this case the last argument is the empty string.

You can provide your own functions to do something really fancy if you need to.