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

Two Great New Lisp Blogs

Recently, Zach Beane and stassats have started new blogs about Common Lisp and Slime. Beane, the well-known Xach, is writing the Common Lisp Tips blog, which promises a new Common Lisp tip every day. As of today, there are only 3 tips but they are all useful and interesting. The second tip is a pointer to the second blog, Slime Tips.

Slime Tips discusses little known features of Slime. Like Common Lisp Tips, the blog has only 3 tips so far. These tips are definitely for someone who’s familiar with Slime basics and wants to explore some of the more esoteric features.

Both these blogs look promising and are worth adding to your news feed if you are a Lisp/Slime user.

Posted in Programming | Tagged , | Leave a comment

Emacs As A Lisp Machine

Xah Lee has an update to his Emacs and Unicode Tips page that I’ve written about before on my old blog. This is a great reference that tells you how to deal with Unicode and UTF-8 in Emacs. One of the new parts that I really like is how to enter a Unicode character by its decimal number. I like this not because I want to do it—I’m perfectly happy using the 【Ctrl+x 8 Entername-or-hex-number method—but because of the way it works and what it tells us about Emacs.

Lee tells us that to input a λ character by its decimal number, 955, you type (ucs-insert 955) into the text and then evaluate it by typing 【Ctrl+x Ctrl+e】 to insert the lambda character. Of course, now you have to delete the (ucs-insert 955) so the method isn’t really that practical.

What I like about it is what it tell us about Emacs. It’s easy, and nominally correct, to think of Emacs as an editor that has elisp as an extension language but Emacs is really more. It’s more accurate to think of it as a lisp machine that’s specialized for editing functions. With that view, you’re always typing into a REPL of sorts where each “normal” character that you type runs the command self-insert-command. You can run other commands by using various control sequences or other special keys. Lee’s method shows both these functions. First you type in the string (ucs-insert 955) and then you use 【Ctrl+x Ctrl+e】 to run eval-last-sexp.

With this view, elisp isn’t an extension language but an instance of a running Lisp interpreter that knows a lot of commands useful for editing and whose REPL (or more accurately reader) behaves a little differently than other Lisps. The point is that it expands your view of what Emacs is and allows you to imagine new and non-intuitive ways of doing things.

By the way, if you must enter a Unicode character by its decimal number, an easier, but similar, way is to type 【Meta+:(ucs-insert 955) or whatever number you need.

Posted in General | Tagged | 7 Comments

Power Update

Two weeks ago I wrote about power management in electronic devices. The thrust of that post was that because battery technology hasn’t advanced very much it was necessary to work on the problem at the other end by making our electronics more efficient in their power use. Now the Lawrence Berkeley National Laboratory has announced a dramatic improvement in lithium-ion batteries. As most of us know, there are two problems with the lithium-ion batteries that power cell phones, computers, and other electronic devices: they can’t hold a lot of power—hence the inability of many smart phones to get through the day on a single charge—and they lose energy storage capacity after a number of charge-discharge cycles.

In a recent press release the Berkeley labs announced a dramatic improvement in both of those problems. The batteries store energy by attracting lithium ions onto the anode of the battery. This causes the anode to swell and then shrink again when the power is consumed. Because the current anodes are typically made of graphite, the constant swelling and shrinking breaks the electrical contacts in the anode and the battery is unable to hold a charge. The Berkeley folks are using a new polymer that hold up to 8 times the number of ions and is not damaged (as much) by the swelling and shrinking. After a year of testing and many hundreds of charge-discharge cycles the new batteries have held their increased energy capacity. As a bonus, the new polymer is economical.

The press release has lots of technical details and is well worth a read. We may, finally, be on the verge of batteries that hold their charges longer and don’t wear out as quickly. That combined with the improvements in the efficiency of the electronics may end the battery hassles that we all endure now.

Posted in General | Tagged | Leave a comment