R7RS WG1 Update

Via Grant Rettke over at Wisdom and Wonder I found these slides from a talk at LispNYC by John Cowan on September 13. As readers from my old blog will recall, R7RS will be split into a “small Scheme” and a “large Scheme” with the small version being a modest expansion of R5RS and the large version being more like R6RS but still downward compatible with the small version.

Working Group 1 (WG1) is tasked with the small Scheme and has almost completed its work. Cowan expects the final committee draft to be out in a few weeks and after formal comments the final version. Working Group 2 is a subset of WG1 and has pretty much suspended their work until WG1 is completed.

Very often it’s hard to make sense of the slides from a presentation without having heard the actual talk. In this case, however, the slides stand alone very well and are quite informative. If you’re interested in Scheme and want to know what’s coming up, take a few minutes to look through them.

Added at the last minute: Video of Cowan’s talk is here. There’s a nice discussion of it on Slashdot.

Posted in Programming | Tagged | Leave a comment

VimGolf In Emacs

I recently saw a reference to Tim Visher’s VimGolf in Emacs videos on one of my feeds. It looked interesting so I hopped over to take a look. VimGolf is a site that poses editing challenges that are supposed to be done in Vim. As with golf, the winners are those with the lowest number of (key)strokes. Visher uses these challenges as a basis for videos that highlight various Emacs techniques. Why should Vim users have all the fun, after all?

I’ve watched a couple of the videos and already learned something very useful. I’m not sure what people who grew up with computers are doing but when I learned to type in high school—on a typewriter—we were taught to put two spaces after the period at the end of a sentence. This made sense with the monospaced typescript that typewriters produced but is incorrect for proportional fonts. After reading this rant on the practice I started using just a single space. Then one day I read that I could move forward and backward by sentences using 【Meta+a】 and 【Meta+e】. The problem was that it seemed to move by paragraphs instead. Moving by sentences isn’t something I do a lot so I just shrugged my shoulders and moved on.

During one of Visher’s videos, I learned that by default Emacs uses a period and two spaces to delimit sentences. That was why moving by sentence wasn’t working for me. The solution to the problem is trivial: simply put

(setq sentence-end-double-space nil) ;period single space ends sentence

in your .emacs or init.el file. After doing that, moving by sentences worked correctly.

I really recommend these videos. They’re entertaining and full of things that you might not have known. The later videos show the keystrokes on the screen but the earlier ones don’t so you have to pay attention to what Visher is saying. Still, it’s worth the effort. I’m sure I’ll be passing on other tidbits as I learn them.

Posted in General | Tagged | 4 Comments

Using Emacs To Convert Notes For Deft

Yesterday I wrote about Vivek Haldar’s Deft patch that allowed him to integrate his previous notes into Deft. Recall that Deft uses the first line of a note as its subject and names the file for a note deft-XXX whereas Haldar used the filename to describe the subject of the note. After I published that post I thought that it might have been easier to simply convert the existing notes to Deft format by making the file name the first line of the note.

It turns out that it is pretty simple to do that. Let’s assume that the file names are something like /Users/jcs/notes/ideas-for-Hercules-project.txt. We want to take the file name and convert it into a subject line by removing the directory information, removing the extension, changing the dashes to spaces and inserting the result as the first line of the file. Here’s a bit of Emacs Lisp that does that for one file:

(defun file-to-subject (filen)
  (let ((subject (replace-regexp-in-string
                  "-" " "
                  (file-name-sans-extension (file-name-nondirectory filen)))))
    (with-temp-buffer
      (insert-file-contents filen)
      (goto-char 1)
      (insert (concat subject "\n"))
      (write-file filen))))

The let at the beginning of the function converts the file name to a subject line. Then the file is read into a temporary buffer and the subject line is inserted at the beginning of the buffer. Finally the new file is written over the old.

To process all the files in, say, the ~/notes directory we could use the line

(mapc 'file-to-subject (directory-file "~/notes" nil "\\.txt$"))

or for more complicated directory structures we could use Dired to mark the files we want to convert and then use 【w】 (bound to dired-copy-filename-as-kill) to put the file names in the kill ring. Then we could just yank them right into the mapc in place of the (directory-file "~/notes" nil "\\.txt$").

That leaves changing ideas-for-Hercules-project.txt to deft-XXX. That could be done in several ways, with or without Emacs, but if you want to do it in Emacs here’s what you need for one file

(defvar deft-num 0)

(defun deft-name (filen)
  (rename-file filen (format "deft-%03d" (incf deft-num))))

The incf function1 increments deft-num and returns the incremented value so that the first time deft-name is called the format will return deft-001 and then deft-002 and so on.

You can do all the files with a mapc similar to what we used above. Alternatively, we could place the call to deft-name after the call to write-file in the file-to-subject function.

Footnotes:

1 incf is part of the Common Lisp package so you’ll need a (require 'cl) if you don’t already have it.

Posted in Programming | Tagged | Leave a comment

Deft Filenames

I’ve written a couple of times about Deft, which I described as a lightweight alternative to Org Mode. I’m still not using it for the reasons that I gave in those posts but lots of people are. One of those people, Vivek Haldar, liked it very much but had a problem. He had a bunch of pre-existing notes that used the filename as the subject of the note whereas Deft uses names of the form deft-xxx. He wanted to integrate his existing notes with Deft so he wrote a patch for Deft that added an option to use his method. Jason Blevin, the author of Deft, accepted his patch and added it to his source tree. Thus if you’re interested in Deft but were holding back because you already had notes with descriptive filenames, you no longer have an excuse not to try it out.

Posted in General | Tagged | Leave a comment

Inserting Quotation Marks In Emacs Revisited

The other day, I wrote about Inserting Quotation Marks In Emacs Org Mode and I wrote a little bit of elisp to insert \ldquo{}\rdquo in the buffer and then place the point between the two quote commands. I remarked at the time that what I’d really like is to just insert “” so that the quotes would work anywhere not just in an Org mode buffer. When I tested that, however, Org mode thought the buffer encoding was something besides UTF-8 and got confused.

After a bit of prodding by Xah Lee, I decided to figure out what was going on. I couldn’t find anything wrong and when I tested again everything worked fine. Somehow or other I must have set the wrong encoding and that’s why the Org mode exporter complained. When my language environment is set to UTF-8, everything works as expected. Thus I’ve added

(set-language-environment "UTF-8")

to my init.el file and I’ve changed my dq function to

(defun dq ()
  "Insert double quotes in an org buffer."
  (interactive)
  (insert "“”")
  (backward-char))
Posted in Programming | Tagged , | 4 Comments

Steve Jobs

I awoke this morning to the sad new that Steve Jobs had died. Of course, I was shocked but as Charlie Stross points out, I shouldn’t have been

Once his illness became public knowledge his level of activity,
already frenetic, became that of a man desperate to complete his
life’s work. People like that don’t go gently into the dark
night. They don’t leave the office unless they’re dragged away on a
stretcher. When he resigned as CEO of Apple in August, I expected him
to be dead within a week; I’m surprised he lasted this long.

That sounds right to me. Although he was by all accounts a devoted family man there was always “just one more thing.”

There’s been much twaddle in the technical press and blogosphere lately about Steve Jobs being this generation’s Edison; Steve Jobs not being this generation’s Edison and so on. I don’t know about any of that but I do know that he was a visionary unparalleled in his time. A man obsessive about attention to detail and a man who would accept nothing but the best from himself and those around him.

Steven Levy, technology’s biographer, has a touching obituary of Jobs over at Wired and the New York Times has a lengthy story on his life and accomplishments. Like most people, I never met Jobs but his work touches me on a daily basis and I will miss him.

Update: except → accept

Posted in General | Leave a comment

The Emacs interactive Special Form

Xah Lee has an interesting post that taught me something I already knew. The problem that Lee deals with is how to write an Emacs command (that is, a function callable by, say, 【Meta+x】 and the function name) that is also callable directly from elisp code. In general, that’s not hard because interactive functions are always callable from elisp. In Lee’s case, the problem was that the function was called differently in the two cases: when called interactively, the function was passed the beginning and end of a region to work on; when called directly, it was passed a string. Lee has a nice solution and if you write Emacs Lisp you should take a look at how he solved it.

What I want to talk about is the interactive declaration. If you’ve written any Emacs Lisp you know that it specifies how arguments are to be passed to the function when it’s called interactively. Normally this is specified by code letters in a string that makes up the argument to interactive. For example,

(interactive "nEnter a number: ")

says that the function will be passed a number that Emacs will prompt the user for with Enter a number:. Similarly,

(interactive "p")

passes the function the prefix argument. All the prefix codes are in the built in documentation as well as the Emacs Lisp Manual.

You can also pass interactive an expression instead of a string and have the expression return a list of the arguments to pass to the command. That’s the part that I learned but already knew. I already knew it because I read it every time I look up interactive in the built in documentation to check the code letters. Somehow, though, it just never sunk in. Maybe because it’s hard to imagine a realistic use case. Fortunately, Lee has more imagination that I do and came up with a very good use case. Again, you should look at his post to see a nice example of passing interactive an expression instead of a string.

The full story on interactive is in the Section 21.2.1 of the Emacs Lisp Manual. There’s a lot of useful information in there that’s worth reading about.

Posted in Programming | Tagged | Leave a comment

A Cool Common Lisp Tip

I wrote the other day about Zach Beane’s new Common Lisp Tips blog. Yesterday, he had a really nifty tip that solves a common problem. We’ve all had situations where we want to output something like

Processed 1 file.

or

Processed 23 files.

Some people are lazy and you end up with

Processed 1 files.

which I always find jarring. In Emacs Lisp we might solve this problem with something like

(print (format "Processed %d file%s" n (if (> n 1) "s." ".")))

and something very similar involving a printf in C.

Common Lisp has a special format directive that takes care of this automatically. What do you expect, after all, from a language that even has a directive for outputting numbers in Roman Numerals? This is Beane’s tip so I’ll direct you to his post for the details. If you’re a Lisp programmer and, like me, you didn’t already know about this, you should definitely head over and take a look.

Posted in Programming | Tagged | Leave a comment

Inserting Quotation Marks In Emacs Org Mode

As I was writing yesterday’s post I started to enter \rdquo{} to get an opening double quotation mark for what seemed like the millionth time. I suddenly realized that this was really stupid and a waste of time so I cooked up a small amount of Emacs Lisp to do the job for me. Before I start, let me state for the record that I know about yasnippet and know that I can do the same thing with it. The thing is, I don’t have it installed and I don’t think I’d use it for anything other than implementing the quotation mark template so a tiny bit of elisp seemed like a better solution.

The code itself is very simple

(defun dq ()
  "Insert double quotes in an org buffer."
  (interactive)
  (insert "\\ldquo{}\\rdquo")
  (backward-char 6))

When dq is called, the string \ldquo{}\rdquo is inserted into the buffer and the point is moved backwards 6 characters so that it is between the two quote commands. All I need do then is type the material to be quoted and do a 【Meta+f】 to jump over the \rdquo.

I thought about just having dq insert “” so that I’d have a more general solution but when I tested that idea the Org mode exporter (or Emacs, I’m not sure which) got confused about the character encoding and asked me some questions. Rather than deal with that every time I wanted to insert quotation marks, I just stuck with what I’ve always done but with a little automation.

I’m sure there are other ways of addressing this problem in Emacs but I’m a programmer and the problem looked like a nail to me so I hit it with my favorite hammer. Feel free to cure me of my ignorance in the comments.

Update: Added missing “I”

Posted in Programming | Tagged , | 2 Comments

PostScript And PDF

I’ve read several times that PDF is “just compressed PostScript” but I recently learned that that’s not true. David Evans has a nice article over at Adobe on PostScript vs. PDF.

Evans starts off by describing what PostScript is and how it is used. Like most of my readers, none of that came as a surprise—I’ve even written some simple PostScript programs so I’m pretty familiar with it. The interesting part for me was his description of PDF and how it differs from PostScript. In addition to describing the words on a page, PDF contains other information such as fonts, images, hyperlinks, keywords, and so on. More important, however, is that the PDF file has already been processed by a Raster Image Processor and made into objects that can be viewed on screen. This has the added benefit that it gives a very clear indication of what the object will actually look like when it’s printed.

Evans writes that he believes more people will begin to deliver PDF files to printing services as better tools become available. That’s already happening. Between my first and second books, my publisher switched from asking for PostScript to asking for PDF to deliver to their printing vendor. I used to send all my memos, reports, and papers as PostScript and sometimes people (especially non-Unix people) would be unable to read them. Now, like everyone else, I send PDF and everyone can read them—even the printer.

Unless you’re already familiar with PostScript and PDF, this article is a useful introduction that’s worth a read.

Posted in General | Tagged | Leave a comment