A GDB Tutorial

Before coming to Lisp, I spent many many years writing C code. Despite the disrepute that C has fallen into with some of those damn kids playing on my lawn, I think it’s a really great language for the problems in its domain—certainly superior to C++, no matter what they tell you. In any event, if you’re a C (or C++ or other GCC-based language) programmer, one of the handiest debugging tools at your disposal is GDB, the Gnu Debugger.

The problem is that GDB can be a bit intimidating for the uninitiated. Happily, Ryan Schmidt wrote a nice tutorial to get you started. It’s written in a question/answer format and takes you through all the basic operations. After he discusses the commands there are a couple of examples that show you how to actually work with the debugger.

Emacs users will, of course, want to use the Emacs interface to GDB. It’s separate from GUD (the Grand Unified Debugger) and has a nice multi-window IDE-like presentation. For more information, visit the online documentation for it with【Ctrl+h Fgdb (note the capital F).

Non-Emacs users might want to look at cgdb, a split-screen, terminal-based interface to GDB. I haven’t used it but it looks quite nice from the Web site.

Update: 【Ctrl+x F】 → 【Ctrl+h F

Posted in Programming | Tagged | 2 Comments

An Up-To-Date Paredit Reference Card

I learned something new from Magnar Sveen’s excellent Emacs Rocks! episode on Paredit: the paredit-convolute-sexp command (bound to【Meta+?】). It’s hard to describe exactly what it does so check out the video to see it in action. The thing is, I didn’t even know that command existed; it wasn’t on my Paredit Reference Card. I noticed some of the other commands were missing too so I decided to find out exactly what commands were available and make a list of them.

I brought up the paredit.el file and started looking around and noticed there’s an odd list of commands complete with examples built right into the code. Here’s the first few entries:

(progn (setq paredit-commands
 `(
   "Basic Insertion Commands"
   ("("         paredit-open-round
                ("(a b |c d)"
                 "(a b (|) c d)")
                ("(foo \"bar |baz\" quux)"
                 "(foo \"bar (|baz\" quux)"))
   (")"         paredit-close-round
                ("(a b |c   )" "(a b c)|")
                ("; Hello,| world!"
                 "; Hello,)| world!"))
   ("M-)"       paredit-close-round-and-newline
                ("(defun f (x|  ))"
                 "(defun f (x)\n  |)")
                ("; (Foo.|"
                 "; (Foo.)|"))
...)))

I thought, “This is perfect. I can use this list to programmatically build a reference card and it will always be up to date.” So I started mapping out the Lisp code in my head but then I remembered this is Emacs so I thought I better check the code to make sure it wasn’t already doing something like that. Sure enough, there’s a function called paredit-insert-html-examples that will format a nice HTML reference card for you. What I did was open an empty file called paredit.html and then call paredit-insert-html-examples. Next I saved the file and then opened it with my browser and set a bookmark to it in my Docs section. Now I have a nicely formatted reference card complete with examples and I know it’s correct because it’s generated from the actual code in the package.

You may have seen a version of this reference card on the Internet. It’s not this one, which is nicer looking but not complete. Here’s a older version of what gets generated. If you’re new to paredit or the type of person who doesn’t remember key sequences unless you use them all the time, this may be just what you need and it’s easy to generate when new versions of paredit come around.

Posted in General | Tagged | 1 Comment

Iain M. Banks

The careful Irreal reader will have noticed the quote from Iain M. Banks in the upper right corner of the blog. The quote comes from Excession, my favorite of Banks’ Culture Novels. It’s a description of metamathics, which Banks describes as

the investigation of the properties of Realities (more correctly,
Reality-fields) intrinsically unknowable by and from our own, but whose
general principles could be hazarded at.

The investigation of metamathics is how the Minds—the powerful AIs that effectively run the Culture—amuse themselves. It’s inclusion here is meant to suggest a parallel with Lisp.

Now, sadly, we learn that Banks has terminal cancer and does not expect to live longer than a year. If, like me, you’ve read and enjoyed Banks’ novels you might want to visit Banksophilia, a site set up by his family and friends, where you can check his progress and leave him a message if you like. The Culture is a wonderful place full of hope and progress where something like this could never happen. It’s heartbreaking to see it happen to the Culture’s creator.

Posted in General | Leave a comment

Smartparens Video

Irreal readers who follow the comments will be familiar with Fuco, one of our best EmacsGolf/VimGolf in Emacs solvers. In addition to making me feel inadequate about my Emacs Fu, Fuco is also the author of smartparens. You can think of it as a configurable paredit for when you’re not programming in Lisp (or are, for that matter).

If you’ve been wondering about smartparens, Fuco has produced two videos that show off its capabilities. They’re only 24 minutes together so there’s no reason not to take a look to see if smartparens might be useful in your workflow. At the very least, you’ll probably do better in the EmacsGolf challenges.

Smartparens Video – Part 1
Smartparens Video – Part 2

Posted in General | Tagged | 2 Comments

Some Handy Electric Modes

Bozhidar Batsov is blogging up a storm on his new Emacs Redux blog. The other day, he mentioned a couple of useful modes that, since Emacs 24.1, are built in. The first is electric-pair-mode. It provides the automatic pairing of special delimiters such as “, (, [, and {. Much like paredit, when you type the left character of the pair, the right character is also inserted and the point is placed between them. Typing the right character merely skips over the already inserted right character rather than inserting a new one. You can insert just a single character by preceding it with the quote sequence 【Ctrl+q】.

I didn’t realize this was a built-in and have been meaning to install the package. It was a nice surprise to learn that all I needed to do was enable it.

The second electric mode is electric-indent-mode. It’s purpose is to automatically indent the next line after you type certain characters such as a newline. I already have 【Return】 mapped to newline-and-indnet so this is less useful to me and I haven’t enabled it. You may find it useful, though. Be aware that it reportedly causes problems with Python mode so be alert.

Posted in General | Tagged | 4 Comments

Opening Emacs Files in External Applications

Xah Lee has a nice post that shows how to open files in an external app or on the desktop from Emacs. When opening files in an external application, the current visited file will be opened unless you’re in a dired buffer in which case all the marked files are opened.

There are two functions: one to open the file(s) in an external application and the other to open the current file in the OS’s file manager. In the first case, “open” means to do whatever clicking on the file would do.

What I like about this code is that it handles the three cases of Windows, OS X, and Linux. In each case you have to do something a little different. Even if you don’t have a need for these functions, the Elisp code is handy as a go by for writing functions to perform similar tasks.

Posted in General | Tagged | 1 Comment

SBCL 1.1.6 Released

The latest version of SBCL has been released. As usual, compilation and installation went without problem. You can read the News file for a complete list of changes but the TL;DR is

  • Speed up of the compiler for certain constructs
  • Enhancement of error processing
  • A bunch of bug fixes

As I’ve said before, SBCL is an amazingly mature and capable Common Lisp implementation. Sadly, not many people appreciate Lisp these days but SBCL really is one of the crown jewels of the Open Source movement.

Posted in General | Tagged , | Leave a comment

Yet Another Reason to Encrypt Files in Dropbox

As I’ve written many many times, if you’re storing anything in Dropbox that you wouldn’t want to see published in the New York Times then you better encrypt it. Here’s yet another reason to do so.

Posted in General | Tagged | Leave a comment

Package Management Across Machines

Daniel Szmulewicz has an interesting post up on his blog about managing Emacs packages when you have multiple machines that you want to keep configured identically. He went through the usual cycle of solutions: First, he managed it by simply copying over his init.d to each of the machines and then loading whatever packages he needed from ELPA or other sources. Then he put his .emacs.d under version control but he found that objectionable because he was putting external code under version control. Next he wrote a bit of Elisp to load a list of packages, put it in his init.d and put just that under version control.

That’s where most of us would have stopped but he asked himself how he could also automate deleting packages. He found a very nice solution using el-get that handles both adding and deleting packages according the one simple list in his init.el. If you’re trying to maintain the same Emacs configuration on more than one machine, you may find his solution useful. Definitely worth a look.

Posted in General | Tagged | 4 Comments

Google Same Day Shopping and Focus

John Gruber has a trenchant comment on Google’s need to focus.

Posted in General | Leave a comment