Truism of the Day

Posted in General | Tagged | Leave a comment

Progress Indicator for Org-Mode Code Blocks

Via Grant Rettke, here is a nice snippet of code from John Kitchin that gives a visual indication of when an org-mode code block is executing. It’s just a defadvice around org-babel-execute-src-block so it’s easy to modify to suit your preferences.

Most of my code blocks execute more or less instantly so I would have limited use for this but if, like Kitchin, you have long running processes, it’s a nice hack to let you know the status.

This is another example of how Kitchin is automating his life with Emacs. Happily, the rest of us benefit from his work as well.

Posted in General | Tagged , | Leave a comment

Temporary Syntax Tables Revisited

The other day, I wrote about Xah Lee’s post on temporary syntax tables and the with-syntax-table macro. Subsequently, Lee discovered a nasty side effect that he wrote about on the G+ Emacs Community site. The problem was that his code

(with-syntax-table (standard-syntax-table)
  (modify-syntax-entry ?\« "(»")
  (modify-syntax-entry ?\» ")«")
  ;; 
  )

modified the original standard syntax table for all buffers.

The problem is (standard-syntax-table) doesn’t copy the standard syntax table; it just returns a pointer to the standard syntax table object. This is the same thing that happens if you assign a list to a variable:

(setq x '(1 2 3))
(setq y x)
(setf (car y) 5)
(message "x is %s" x)

returns

x is (5 2 3)

because x and y refer to the same object.

What we need to do is first make a copy of the standard syntax table. Happily, the copy-syntax-table function does just that1 so if we evaluate

(with-syntax-table (copy-syntax-table)
  (modify-syntax-entry ?‹ "(›")
  (describe-syntax))

the ‹ is described as an open bracket but if we open a new fundamental buffer and call describe-syntax it is described as punctuation, as expected.

Lee solved this problem by creating a new syntax table with make-syntax-table and added his definitions to it. You might think that Lee’s solution is incorrect because the other syntax definitions will be missing from his new table but it is correct because make-syntax-table will create a table that inherits from the standard syntax table (or whatever table you specify).

Footnotes:

1

copy-syntax-table copies standard syntax table by default but you can specify a table explicitly if you want to start with some other table.

Posted in Programming | Tagged | Leave a comment

Sacha Chats with Mickey

Sacha Chua has her latest Emacs chat up. This time it’s with Mickey Petersen proprietor of the excellent Mastering Emacs. If you follow the Emacs scene at all, you will be familiar with Mickey and his definitive articles on the ins and outs of Emacs.

Mickey came to Emacs pretty much because he was told all the cool kids use Vim. In the intervening 10 years he’s worked to master Emacs and share his knowledge with the rest of us through his blog. Watching him use Emacs you can see that mastery in action. He navigates through files so quickly and easily that it’s hard to follow the action.

One of the things that impressed and inspired me was that he tends to think in term of language constructs rather than characters. Thus, for example, he navigates by and manipulates s-expressions. That’s an attitude that I want to cultivate; it can’t help but increase my editing speed and efficiency.

The chat is about 53 and a half minutes so plan accordingly. As with all of Chua’s chats, you’re sure to learn a few things. For example, I learned the efficient way to backwards kill an s-expression.

Update: Sacha has a transcript of the chat up.

Posted in General | Tagged | Leave a comment

Transposing Words

Howard Abrams has a nice video on transposing words in Emacs. You might think that there’s not much to say about the subject: just type 【Meta+t】 and you’re done. Of course there’s also the fact that you can use it to “pull” a word towards the end of the line by repeated invocation of the command or by using a prefix number but that’s also well known.

Abrams explores an interesting edge case. What if you’re at the end of the line? He’s got an actual use for that. Suppose you’re typing along and realize you forgot a word

The brown fox

Rather than backing up and inserting the missing word, you can just type it at the end

The brown fox quick

and then type 【Meta+t Meta+t】 and quick gets inserted in the proper place.

That’s a nice trick that takes advantage of a side effect of transpose-words and you can use it as is. But Abrams shows how to advise transpose-words so that it handles this case with a single invocation. That means you just type 【Meta+t】 as usual and Emacs does the right thing.

The video is only 8 minutes so you can watch it whenever you have a few minutes. Very nice. Even if you don’t add the advise, it’s worth knowing the trick.

Posted in General | Tagged | 1 Comment

SBCL 1.2.3

The latest version of Steel Bank Common Lisp, 1.2.3, is available at the usual place. As always, it built without problem and successfully ran the test suite. ASDF has been upgraded to 3.1.3 and there are a couple more enhancements and some bug fixes as well. Check the NEWS page for details.

As Christophe Rhodes remarked, this month’s release is less exciting (read controversial) than last month’s. Regardless, SBCL is an excellent Lisp environment that gets better and better with each release.

Update: months → month’s

Posted in Programming | Tagged , | Leave a comment

Temporary Syntax Tables

Xah Lee has a nice post on how to temporarily modify a syntax table. It’s not something you want to do everyday, of course, but the example Lee gives is a real-world case.

It turns out that it’s pretty easy. Just use the with-syntax-table macro and you can change the syntax table in a way useful for the rest of the code in the macro’s body. When control exits the macro expansion, the old syntax table is restored. You can also use the macro to temporarily switch to a different syntax table. If the foregoing seems opaque, the example in Lee’s post will clear things up.

I didn’t know about the with-syntax-table macro so this post is my way of writing it down so I won’t forget. I’m sure I won’t need it often but when I do, it’s just the thing.

Posted in General | Tagged | Leave a comment

Another Reason Closed Source is Harmful

Open Source/Free Software includes a number of tribes. There are the FSF true believers, epitomized by RMS, who hold that software should be free on philosophical/ideological grounds. Even if one could adduce facts showing that Free Software was less optimal than closed source, these folks would be unmoved; it’s a matter of morality.

Then there are folks like Cory Doctorow and ESR who still insist on using strictly Open Software but do so on (mostly) pragmatic grounds. Members of this tribe seek to avoid lock-in or loss of data. It’s easy to see why someone like Doctorow would fear having his data locked in some proprietary format that could become unsupported at the whim of some software company.

There’s also the tribe that is willing to use a proprietary program or OS, when necessary, as long as it doesn’t involve their data. As a Mac user, I fall into this group. Even though I prefer open source, I’m perfectly happy to enjoy the benefits that OS X brings me but I would never use Word, or Pages (the Mac answer to Word), or Numbers (the Mac spreadsheet). Instead all my data is held as plain text (even, thanks to Org Mode, spreadsheet type data). If OS X were to die tomorrow, my data would be just as useful and accessible on Linux or even Windows.

The key here is that you must never commit any data you care about to anything but plain text. If someone or something requires, say, word documents, you write and maintain it in Org- or Markdown-mode and export it to word as Mark Szepieniec and Christophe-Marie Duquesne outlined for résumés. Most of us know and practice all this no matter which tribe we adhere to.

It turns out, though, that it’s a bit more complicated. Jonathan Zdziarski has an interesting post on digital forensics and the threat that closed source poses to it. Most law enforcement agencies use closed source programs to extract data from phones or computers and for other forensic tasks. One problem is that the user has no way of knowing what the programs are doing or how they’re massaging the data. This can present legal problems when, for example, the defense insists on auditing the program that produced the data. In the case of breathalyzers, which are also mostly closed source, this has already resulted in DUI dismissals.

It gets worse though. Zdziarski reports that the results these forensic programs produce are often flat out wrong—even made up in some cases. That’s an obvious problem no matter which side of law enforcement you’re on. If you’re the defendant, you might get wrongly convicted. If you’re with law enforcement, guilty parties may be erroneously cleared.

Closed source isn’t the only problem that Zdziarski describes but it is a large one. We will certainly see cases involving forensics depending on these programs challenged and dismissed. In the mean time, those of us who support open source get to feel smug. Just don’t find yourself on the wrong end of a digital forensics investigation.

Posted in General | Tagged | Leave a comment

Version Control

Everybody agrees that version control (VC) is the right thing but, sadly, too often it’s ignored anyway. I use version control—Git via Magit—in two ways. First, it’s the primary way that I keep my machines synchronized. I could, of course, use something like Dropbox for this but Git works well for me and I’ve automated the process so I see no reason to change. The point is that synchronization is not something you need version control for.

The real reason for VC is that you have a history of the changes you’ve made and that, as a result, it’s easy to drop back to a previous state if you code (or write) yourself into a box. Eric Raymond has a revealing post neatly demonstrates the virtues of version control. He writes about a “phase-of-the-moon bug” that, despite frequent and comprehensive regression tests, suddenly appeared after a commit. Nothing too strange about that but when he dropped back to the previous commit the regression tests still failed even though they had passed just a few minutes ago.

It turned out that several commits had the mysterious bug but Raymond was able to locate the culprit pretty quickly with Git bisect. Even if you’re not a Git user, you could still perform the bisection process manually although a good deal less conveniently. The real enabling mechanism was VC. Without it, he’d have had a long and frustrating ordeal of trying to locate each change and test if it was the genesis of the problem.

I’ve heard many developers express the opinion that they don’t need VC because they work alone. As Raymond’s story illustrates, VC can save the day even for the lone developer1. Hop on over and read Raymond’s post and see if it doesn’t convince you that you should be using VC whether or not you’re working alone.

Footnotes:

1

The code Raymond was working on, GPSD, is, in fact, a multi-developer project but that doesn’t come into play here. The story takes place while he was working alone and all the code was his.

Posted in Programming | Tagged | 1 Comment

Extending Isearch

Nicolas Petton presents a nice bit of Elisp that extends the isearch functionality. With his code, you can search for the symbol at point or the active region if there is one.

The first of these is easily accomplished using【Ctrl+w】from within isearch but that takes an extra key chord. With Petton’s code you just invoke his isearch-thing function and it searches for the symbol at point unless there is an active region.

If you are a heavy user of isearch and find yourself typing 【Ctrl+s】 and then 【Ctrl+w】 a lot, this may be win for you.

Posted in General | Tagged | 2 Comments