Devigner blog about development and design

Django Clippings for BBEdit


I took a break from Emacs this weekend to give the new version of BBEdit a spin. The first thing I noticed was that it doesn’t have snippets (clippings are the accurate term) for Django. Personally, I use yasnippet in Emacs so I took an hour and converted the library I use to clippings for BBEdit in the hopes someone finds them useful.

I put the clippings up on Github for download or fork/clone. Download and put them in ~/Library/Application Support/BBEdit/Clippings or clone the project and symlink it to the same directory. If you find a problem, open a new issue at the project page or fork it and fix it.

Applescript to Send Safari Url to Emacs Org-Mode

I’ve been a long time OmniFocus user and am a daily (or habitual) emacs user so it only makes sense for me to dabble with org mode for a GTD system. After all, when I’m writing code, why not have my projects todo lists in the next window. So this morning I figured I’d give org mode a try. It’s not polished like OmniFocus or Things but seriously; why does a todo list need satin pajamas? I’m not sure I’ll stick with it but I at least need to give it a trial run for a week or two.

How I Roll
When I get an email from a client that needs attention I use the clipper that comes with OmniFocus (Clip-o-tron 3000) to create a new task with a link to the email embedded. I also like to send research urls from Safari for projects to my todo lists as notes. This helps keep me on top of things (if that’s possible) as projects progress.

The Immediate Problem; No Clip-O-Tron
Since org-mode is basically a text file displayed within emacs, I need a way to send these to my org-mode file. I’m using gmail these days (trying to) and gmail has unique addresses for each email. All I need is to capture that url and send to org-mode.

Applescript to the rescue!
I wrote this applescript today that will capture the url from the foremost Safari window and save it to my org-mode file where I keep a “Inbox” at the very bottom of my file. Before saving the link I have it prompt me for a title for the link so that I can name it something meaningful. After it saves it to the end of my file, I get a growl notification telling me it’s done.

The AppleScript

To use this effectively, change the line 19 which reads set theFilePath to "Macintosh HD:Users:greg:gtd:" & "greg.org" as string to the path where your org file is located. I also keep my “Inbox” at the bottom of my org file so that when these new urls are saved, they are appended to the bottom of the inbox.

If you can’t get the script from this page, you can grab it over at Snipt here: http://snipt.net/gregnewman/send-safari-url-to-emacs-org-mode

If you use this script and find it useful, leave a comment and let me know about it. If you have ways to make it better, I’d love to see your changes.

Eldarion Logo


Those of you who follow my good friend James Tauber on twitter, facebook or through the Pinax Project have already heard that James has resigned from mValent.
James approached me about a logo for this mysterious endeavor, which I jumped on in short order. I unveil the eldarion logo and I’m sure a lot of you will immediately recognize from it what influences James was looking for in the design.

If you want to learn more, follow the eldarion team on twitter or the eldarion website. I’m confident there will be more announcements very soon.

James, I wish you success in the next score you compose!

Freshmeat.net Logo and New Site

Most of you already know of freshmeat.net. Over the last few months I’ve been lucky enough to work with Patrick Lenz on the next incarnation of freshmeat.net.


freshmeat_concept.pngAlong with the new site design I’m creating I also provided the new logo for the freshmeat identity. Coming up with a concept for freshmeat was not an easy process in the long run. After many days with the sketchbook and conversations with Patrick the logo was finalized.


As for the site design, I’m not going to expand on that just yet until the beta invites are sent. Patrick has written an article about the new site and the beta signup process; I won’t duplicate his efforts here. Head over to freshmeat to find out how to get involved.

Emacs Starter Kits

Outside of my usual ramblings I wanted to point out that Phil Hagelberg has a great collection of emacs starter-kits over at github for those interested in going for a swim but don’t know where the water is.

I am currently working on a Python/Django starter kit to add to his collection. We definitely don’t want the Ruby guys to have all the fun now do we? Phil is also working on a Peepcode screencast which the little birdies have told me might be available later this week if all goes well.

Emacs Mode for dpaste.com

Since Paul Bissex announced the api for Django-powered dpaste.com last week I’ve had it’s been on my todo list to make a emacs mode for posting pasties.

Last evening, again while watching football, I whipped up a emacs mode and have it hosted over at github.

git clone git://github.com/gregnewman/dpaste.el.git and add to your .emacs

or track the changes within your .emacs configs

git submodule add git://github.com/gregnewman/dpaste.el.git vendor/dpaste

M-x dpaste-buffer

Will post the current buffer to dpaste.com and put the curl to the paste in the kill-ring

M-x dpaste-region-or-buffer

Will post the marked region or current buffer to dpaste.com and put the curl to the paste in the kill-ring

If there is any interest, I can also make a version for my vim using friends.

I have a few items remaining that I want to do with it but at this point it is fully functional. If you have a wish or a bug, either leave a comment here or at the github project. I hope you find it useful.

Textmate and Gist for Emacs

First of all, Happy Thanksgiving to everyone. I hope you’re enjoying food, family and football, I know I am. I’m also enjoying my new emacs minor-mode developed by Chris Wanstrath, aka defunkt.

Textmate.el for Emacs

Since switching from Textmate to Emacs, the only thing I have missed is ⌘T or Go to File. I used it all the time in Textmate and although there were some minor-modes for Emacs that got me closer, it still wasn’t ⌘T.

Chris has developed Textmate.el, a minor-mode that brings some of the similar key bindings to Emacs for those of us who relied on Textmate bindings.

From the readme:

⌘T – Go to File ⇧⌘T – Go to Symbol ⌘L – Go to Line ⌘/ – Comment Line (or Selection/Region) ⌘] – Shift Right (currently indents region) ⌘[ – Shift Left (not yet implemented) ⌥⌘] – Align Assignments ⌥⌘[ – Indent Line ⌘RET – Insert Newline at Line’s End ⌥⌘T – Reset File Cache (for Go to File)

A “project” in textmate-mode is determined by the presence of a .git directory. If no .git directory is found in your current directory, textmate-mode will traverse upwards until one (or none) is found. The directory housing the .git directory is presumed to be the project’s root.

In other words, calling Go to File from ~/Projects/fieldrunners/app/views/towers/show.html.erb will use ~/Projects/fieldrunners/ as the root if ~/Projects/fieldrunners/.git exists.

In your emacs config:

(add-to-list ’load-path “~/.emacs.d/vendor/textmate.el”)
(require ’textmate)

Chris’s example above is typical of Rails projects but I can attest to the fact that this works nicely for Python/Django projects.

Thanks Chris!

Gist.el for Emacs

While you’re visiting Chris at Github I recommend you also grab a copy of Gist.el. Gists are like pasties for those who aren’t familiar with the term. What Gist.el does well is paste the buffer or region to your account on github and return the url in your kill-ring, public or private. Gist.el will also allow you to yank a gist into a buffer.

Emacs: Dired Directory Management

Picking back up on the Emacs series I started earlier this month I would like to take some time to discuss the Dired mode for directory management.

I’ve used ECB in the past and found it nice, feature rich but in my opinion it had too much information and was in my way, not to mention it drastically increases emacs load time. So I removed it from my configs and now only use Dired. Once you get used to it it really is very powerful.
h3. The Basics

To initiate a Dired buffer type C-x d and you will be prompted for a directory path starting in the directory of your current open buffer. Navigate the path you want to open and return to open it. If you haven’t extended Dired with additional modes, you’ll get something that looks like a terminal directory listing (ls -lna). I’ll tell you how to change this later.

Movement in Dired is exactly like any buffer so I won’t go into that here. For long directories I always navigate with iSearch (C-s and C-r). It’s much easier to jump to a particular location.

To open a folder press f (find-file). To go up a directory type ^. Every time you open a new directory a new buffer is opened in the background for you and always accessible until you kill it.

Top view a file in read-only mode, press v. To return to the Dired buffer press q.

o will open the file in another window while RET or f will open the file in the current window. At anytime in the Dired buffer you can sort by typing s.

Deleting files

Dired allows you to perform actions on files and folders such as deletion, renaming, etc.

To delete files, you first must mark the files you want to delete by navigating to the file or folder and pressing d which will place a capital D to the left of the file. When you are done with your selections x will initiate the actions and you will be prompted to confirm your actions. Typing # marks all the autosave files for deletion with a D status and typing ~ marks all the backup files for deletion with the same status. At any time, if you accidentally mark a file you can press u to unmark it.

Copying and Renaming Files

To copy a file first navigate to it and press C (capital C). Emacs will ask you for the name of the file to copy to. Enter will execute the copy. If you type C4 from the file you are on, the current file and the next three will be copied.

To rename a file type R. Are you getting the naming conventions yet? Emacs will ask you for the new file name and again, Enter will execute it.

File Compression

You can compress and uncompress files from Dired by typing Z. You will be asked to confirm. Z is universal in that it will uncompress a compressed file or compress it if it’s not compressed already.


Dired lets you compare a file with its respective backup file. This has come in handy many times for me. Find the file you want to compare and press =. You’ll be presented a buffer showing you the difference in the two files.


To make the dired buffer a little more presentable and less like terminal I installed a few other modes. Install Dired+ which will give you extra command and expand on existing commmands. It will also give you some better file highlighting than what is present in the default Dired mode. I also installed Dired-details and Dired-details+ to customize the look of my Dired buffers like the picture above.

With these additions I added the following to my dotemacs files to hide files I don’t want to see, such as .pyc, backups and autosave files.

(require 'dired-x) 
(setq dired-omit-files 
      (rx (or (seq bol (? ".") "#")         ;; emacs autosave files 
              (seq "~" eol)                 ;; backup-files 
              (seq bol "svn" eol)           ;; svn dirs 
              (seq ".pyc" eol)
(setq dired-omit-extensions 
      (append dired-latex-unclean-extensions 
(add-hook 'dired-mode-hook (lambda () (dired-omit-mode 1))) 
(put 'dired-find-alternate-file 'disabled nil)

Django PDF Concatenation

On the heels of PDF Generation with Pisa in Django I’ve had the need to pull from a library of pdfs and concatenate based on user selection. At first there seemed to be no good solutions but research and a recommendation by James Tauber (thanks James) turned up pdftk (the pdf toolkit).
The pdf toolkit has some nice features beyond concatenation to inlcude:

  • Merge PDF Documents
  • Split PDF Pages into a New Document
  • Rotate PDF Pages or Documents
  • Decrypt Input as Necessary (Password Required)
  • Encrypt Output as Desired
  • Fill PDF Forms with FDF Data or XFDF Data and/or Flatten Forms
  • Apply a Background Watermark or a Foreground Stamp
  • Report on PDF Metrics such as Metadata, Bookmarks, and Page Labels
  • Update PDF Metadata
  • Attach Files to PDF Pages or the PDF Document
  • Unpack PDF Attachments
  • Burst a PDF Document into Single Pages
  • Uncompress and Re-Compress Page Streams
  • Repair Corrupted PDF (Where Possible)

I won’t go into all these options. You can see the command reference on the pdftk site.

To do the concatenation in your Django app you can something like this:

import os

def makepdf(request, some_id_todo_something_with):
    os.system("pdftk filename1.pdf filename2.pdf cat output newname.pdf")
    return HttpResponseRedirect(reverse('send_somewhere'))

I’m simply serving them up as static files when they are done.

Book Meme

“Prototypes can be deceptively attractive to people who don’t know that they are just prototypes.”

The Pragmatic Programmer

  • Grab the nearest book.
  • Open it to page 56.
  • Find the fifth sentence.
  • Post the text of the sentence in your journal along with these # instructions.
  • Don’t dig for your favorite book, the cool book, or the intellectual one: pick the CLOSEST.

Done on the blogs of Justin Lilly, Brian Rosner, Barbara Shaurette, James Tauber, and Eric Florenzano as well.