Context

Jessica Kerr makes a good point.

If you have a heavily customized Emacs configuration, using someone else’s Emacs could feel like using a completely different editor.

Posted in General | Tagged | Leave a comment

Debugging Emacs Lisp

Nic Ferrier has posted a nice video tutorial on debugging Elisp. Ferrier covers the basics of instrumenting your code, stepping through it, setting breakpoints, and other edebug functions.

He also demonstrates macrostep, a package that allows you to expand and step through your macros as well. The whole video is just under 11 minutes so it’s easy to find time for it. If you write Elisp and aren’t familiar with edebug, you should definitely watch this video.

Posted in Programming | Tagged , | Leave a comment

Emacs Screen Shots

I really enjoy looking at Emacs screen shots (I know, I know. I’m seeking help) so I was happy to see this from the estimable Bastien Guerry.

Posted in General | Tagged | Leave a comment

Atabey Kaygun on Common Lisp Memoization

Atabey Kaygun is a mathematician who likes to experiment with various (mostly mathematical) algorithms using Common Lisp. Many times, a function is most naturally implemented via recursion but this can lead to disastrously inefficient implementations. The canonical example is the Fibonacci sequence. Its definition is \[\begin{equation*} fib(n) = \begin{cases} 0 & x = 0\\ 1 & x = 1\\ fib(n-1) + fib(n-2) & x > 1\\ \end{cases} \end{equation*}\] so a natural implementation is

(defun fib (n)
  (cond
    ((zerop n) 0)
    ((= n 1) 1)
    (t (+ (fib (1- n)) (fib (- n 2))))))

But when we run

(time (fib 45))

we get

: 1134903170

Evaluation took:
  60.287 seconds of real time
  60.217115 seconds of total run time (60.163250 user, 0.053865 system)
  99.88% CPU
  132,297,562,672 processor cycles
  0 bytes consed

What’s going on here is that the same values are computed over and over. I wrote about this and various other, more efficient implementations here and gave some timings (although for Scheme not Common Lisp) here. The times for the other implementations are too small to measure with a 100 Hz clock. As explained in the first post, calculating \(fib(45)\) recursively makes 3,672,623,805 calls to \(fib\).

For this reason, the recursive implementation is never used and serves mostly as a warning to n00bs about the dangers of blindly using recursion. Still, the recursive implementation is natural and in many other situations the only reasonable solution. That’s where Atabey comes to our aid. He provides a Common Lisp macro, mem-defun, that implements memoization, a technique where previously calculated function values are cached so that subsequent calls to the function for the same argument are retrieved from the cache rather than being recalculated.

The mem-defun macro is a drop-in replacement for defun. Head over to his post for the definition. When we use his macro

(mem-defun fib (n)
  (cond
    ((zerop n) 0)
    ((= n 1) 1)
    (t (+ (fib (1- n)) (fib (- n 2))))))

and rerun the test

(time(fib 45))

we get

: 1134903170

Evaluation took:
  0.000 seconds of real time
  0.000018 seconds of total run time (0.000018 user, 0.000000 system)
  100.00% CPU
  37,477 processor cycles
  0 bytes consed

a clear win. It’s probably not as fast as one of the alternative implementations but when you need to use recursion, it can be a lifesaver.

Posted in Programming | Tagged , | 1 Comment

Emacs for (Non-Programming) Text Processing

Om Prakash Singh is fairly new to Emacs and wanted to increase his skills and knowledge so he accepted the Emacs 30-day challenge. I found Day 7, Commands for Human Languages, particularly interesting. I use Emacs for a lot of writing as well as programming, so I’m always interested in picking up new tips. I don’t use any “word processing” programs so everything I write I write in Emacs1.

Singh’s post is really a recapitulation of the commands and modes that are useful for writing text. But even if you’re experienced, you may find some useful commands. I learned a couple of things about fill prefixes that could come in handy. The post is well worth taking a look at. If you’re a n00b, you definitely should take a look.

Footnotes:

1

I mean that more literally than you might think. For several years I have avoided pen and paper and tried to capture everything digitally.

Posted in General | Tagged | 2 Comments

Emacs Debugger Tip

Wilfred Hughes has a tip on debugging Elisp:

Posted in Programming | Tagged | Leave a comment

Common Lisp format Summary

The Common Lisp format function is a bit controversial among some Lispers1. The problem is that the language used by format to specify output strings is un-Lisp like. I’m not one of those people. I like format and feel comfortable with the language2, probably because of my years cranking out C.

One of the problems with format is that its input language is very comprehensive. You can, for example, specify that a number be output in Roman numerals. Happily, Jean-Philippe Paradis has us covered with his format directive summary. It’s part of his on-going series of articles on the Common Lisp HyperSpec. It’s a nice summary and worth bookmarking for future reference.

Footnotes:

1

For those not familiar with format, it’s much like printf from C, although the formatting language is richer.

2

I’m not a complete libertine, though. I do dislike the loop macro for the same reason given by those who don’t like format: it’s input language is not Lisp.

Posted in Programming | Tagged , | 1 Comment

October Quicklisp

The October Quicklisp is available. Upgrade with the usual

(ql:update-dist "quicklisp")
Posted in Programming | Tagged , | Leave a comment

Xah’s Roundup of Keyboard Articles

As I mentioned recently, Xah Lee is obsessed with keyboards and knows a lot about the subject matter. The choice of a keyboard is a lot like the choice of a spouse or boy/girl friend: everyone has their own idea of what the perfect specimen looks like. Lee, as most of you know, has strong opinions on keyboards and many other matters but still provides excellent data on even those keyboards he doesn’t like.

Now Lee has posted a compendium of his keyboard posts. It’s a great resource if you’re trying to decide on a new keyboard. He even has some links to Amazon for some of the keyboards he discusses.

Lee and I agree on very little about keyboards. I like straight (traditional) keyboards while Lee prefers ergonomic keyboards. I have used QWERTY for all of my life and am not about to change now. Lee has gone to the effort of learning Dvorak. We both agree, more or less, on key switches. Even so, I find his articles very interesting and helpful. If you’re in the market for a keyboard or wondering if you should choose QWERTY, Dvorak, or something else, check out his articles. You’re sure to learn something useful.

Posted in General | Tagged | Leave a comment

Grabbing the Current Browser Tab from Emacs

A little while ago, I wrote about grabbing the URL associated with a browser tab from within Emacs. I’ve been using since then and it simplifies things in more ways than I anticipated. Sadly, the method depends on OS X (specifically AppleScript) so users with other operating systems couldn’t use it.

Recently, I saw this entry on the Google G+ Emacs community that announces the inclusion of a new command to Ren Wenshan’s emacs-moz-controller that grabs the URL of the current Firefox tab. I don’t use Firefox so I haven’t tried it but it seems like it would be an fairly easy way for Firefox users to implement their own version of my jcs-get-link function.

Posted in Programming | Tagged | 1 Comment