Update on OS X Emacs Battery Status

Yesterday, I wrote about the problems I had with Emacs when I updated to OS X Mavericks. The problem was that the call to display-battery-mode failed. For OS X, Emacs uses pmset to get the battery status data. With Maverics, pmset was returning a string that began with “Now drawing from ‘(AC|Battery) Power’” but in previous versions returned “Currently drawing from ‘(AC|Battery) Power’.” Since Emacs was looking for the latter string, the output was corrupted and the call to display-battery-mode failed.

It was pretty easy to track this down using Edebug. The problem is that the regular expression used to search the pmset output is a constant string and not configurable. That means that fixing the problem pretty much boils downs to

  1. Fixing battery-pmset, where the problem occurs, to look for “Now” as well as “Currently” or
  2. Making a local copy of battery-pmset that looks for “Now.”

While I was pondering what to do, Bernd Berndsen wrote to tell me that a change had already been pushed to the development branch. Since this is not a critical issue for me, I’m content to wait to the next update. If it’s more important to you, the easiest thing to do is either to edit and recompile battery-pmset on your local version of Emacs or install the latest development branch. Follow the “development branch” link to see the change you need to make.

I’m not privy to Apple’s thinking on this, of course, but the change seems gratuitous to me. Yes, “Now” is slightly better wording than “Currently” but they had to know that it was apt to break programmatic processing of pmset‘s output. If anyone knows why the change was made, please leave a comment.

Posted in General | Tagged | 2 Comments

Mavericks and Battery Status

I just upgraded my iMac and MacBook Pro to the new OS X, Mavericks. The upgrade went flawlessly—everything should work as well—and my iMac came up without a problem. I spend most of my time in Emacs, of course, so it was the first thing I checked out. No problems.

A bit later, my MacBook finished upgrading and again it came up without a problem but Emacs got an error very early in loading init.el and there wasn’t much indication of what was wrong. I was a bit confused because the same init.el is pulled from a Git archive for both machines so why was it working on the iMac but not the MacBook?

I drag in platform and system specific configuration with the code

;; Just keep on going if the requisite file isn't there.
;; Manipulations in second load is for "gnu/linux" → "linux"

(load (car (split-string (system-name) "\\.")) t)
(load (car (reverse (split-string (symbol-name system-type) "/"))) t)

The MacBook is named manfred so I tried loading manfred.el manually and got the error. The manfred.el file is pretty simple

;; -*- mode: Emacs-Lisp -*-
;; Time-stamp: <Sunday, October 28, 2012  16:21:00 EDT (by jcs)>
;; Emacs configuration specific to manfred

(set-frame-height (selected-frame) 53)
(display-battery-mode 1)

so the problem was obvious. Apparently the Mavericks battery interface changed from Mountain Lion so the display of battery status was failing.

I’ll probably take a look at the code to see what I can do but displaying battery status on the mode line is not a high priority so it’s not an urgent problem. The point of this post is to alert other Mac users who upgrade to Mavericks about the problem. It’s only a problem if you display battery status, of course, so probably only affects Laptop users.

Posted in General | Tagged | 1 Comment

The Aaron Swartz Legacy

I’ve written before about Aaron Swartz’s last project, software to enable whistle blowers to communicate with news organizations anonymously. The New Yorker was the first to implement the system. Those with information about government misdeeds finally had a secure way of passing their information on to journalists.

Wired’s Kevin Poulsen, who collaborated with Swartz on the project, has headed the program until now. On October 15th the Freedom of the Press Foundation took over the project and renamed it SecuredDrop.

The project has received an extensive security review by well known experts, including Bruce Schneier, that should help assuage prospective whistle blower’s fears.

This is a great project that we should all support. The Freedom of the Press Foundation announcement has more details.

Update: Freesom → Freedom

Posted in General | Tagged | 2 Comments

List of Free Programming Books

Victor Felder has an excellent list of free programming books over at Github. The list is indexed in several ways so it’s pretty easy to find books in the area you’re interested in. Among other things, I learned that there are a couple of free Lisp books I haven’t looked at.

This is a useful resource and worth bookmarking for the day when you need a pointer to a readily available programming book.

Posted in Programming | Tagged | Leave a comment

Specifying Indent Rules for Emacs Lisp

Eric J.M. Ritz has an excellent post on indenting Elisp code. Say what? Isn’t that what Emacs is for? Yes but there’s a corner case when you’re writing macros.

Here’s a macro that I use to make my Elisp code work on a region if one’s defined or on the whole buffer if not.

(defmacro with-region-or-buffer (args &rest body)
  "Execute BODY with BEG and END bound to the beginning and end of the
current region if one exists or the current buffer if not."
  `(let ((,(car args) (if (use-region-p) (region-beginning) (point-min)))
         (,(cadr args) (if (use-region-p) (region-end) (point-max))))
     ,@body))

As it stands, a call to that macro would get formatted as

(with-region-or-buffer (start end)
                       (blah start end)
                       (more blahs start end))

but that’s not what we want. We’d like it to get formatted as

(with-region-or-buffer (start end)
  (blah start end)
  (more blahs start end))

The easy way to get Emacs to indent it properly is with the declare declaration as shown in the slightly revised version of with-region-or-buffer shown below.

(defmacro with-region-or-buffer (args &rest body)
  "Execute BODY with BEG and END bound to the beginning and end of the
current region if one exists or the current buffer if not."
  (declare (indent 1))
  `(let ((,(car args) (if (use-region-p) (region-beginning) (point-min)))
         (,(cadr args) (if (use-region-p) (region-end) (point-max))))
     ,@body))

It’s really hard to find the documentation for this (at least I always find it hard) so I’m glad to have Ritz’s post for bookmarking purposes. The post has a link to the documentation for declare so you can see what other arguments to the indent declaration are possible.

Update: what’s → what

Posted in Programming | Tagged , | 6 Comments

Emacs Rocks at WebRebels 4

The fourth episode of Magnar Sveen’s cleaned up WebRebels talk is available. This section continues the demonstration of his JavaScript refactoring tools. He’s able to select a code snippet and turn it into a function with a single call. He can even parameterize the process in a way that’s hard to explain in print but easy to understand when you watch it. He’s also added some of the Paredit functionality. Very nice; it’s almost enough to make me start programming in JavaScript.

This episode is just under 2 minutes so you can watch it any time. You can find the code that he’s using at Sveen’s github repository (the js2 refactoring code is here).

Posted in General | Tagged | Leave a comment

NIST and Keccak

I’m a bit of a crypto nerd—though far from a practitioner or expert—so I’m on NIST‘s SHA-3 mailing list. The mailing list’s main purpose was to keep the contestant teams and other interested observers up to date on the competition. The winner was the Keccak team and just about everyone believes it was a good choice.

It’s NIST’s job to turn the Keccak algorithms into the SHA-3 standard. That’s were the trouble began. NIST made (what some call substantial) changes to the Keccak algorithm and reduced its security in service of increasing its speed. The list went crazy and now the technical press has taken note.

I don’t have the expertise to evaluate the arguments going back and forth but it is worth noting that the Keccak team is on board with the proposed changes. Last year that would have been the end of it but now everyone is donning their tin foil hats. After the Snowden revelations concerning the NSA’s successful attempt to weaken other crypto standards, I can’t understand what NIST is thinking.

Well, actually, I can. It’s the typical nerd reaction of, “the facts are on my side so I don’t have to pay attention to what anyone says about this.” The problem is most people—even most people who are going to use SHA-3 in their code—don’t have the wherewithal to make an informed judgment on the merits of the arguments but they sure understand that (1) NIST, by law, must solicit input from NSA and (2) the NSA is not to be trusted. Ever. Thus by forging ahead, NIST risks blowing up the whole SHA-3 process. As Schneier and others have said, there isn’t an urgent need for SHA-3 because the SHA-2 family is apt to be secure for some time. The careful (or paranoid) engineer is very apt to say, “Forget SHA-3, I’ll stick with SHA-512.”

That would be too bad but it’s exactly what NIST is risking by ignoring the public’s suspicion and distrust. It’s fine to dismiss them all as crazies who don’t understand the crypto but NIST has already shown itself susceptible to abuse at the hands of the NSA. Those “crazies” will just pick up their marbles and walk.

Posted in General | Tagged , | Leave a comment

Emacs Rocks at WebRebels 3

Magnar Sveen has posted the third part of his cleaned up WebRebels talk. This section demonstrates some Javascript refactoring. It’s only 58 seconds long so you won’t have to map out a block of time to watch.

Posted in General | Tagged | Leave a comment

WDIRED

Mickey over at Mastering Emacs has a nice post on wdired. Dired is an underappreciated part of Emacs but even many who use it don’t realize that you can edit file names, permissions, and owner/group directly in the dired buffer and have the changes reflected in the file system. That ability is already built-in. All you need to do is toggle it on with 【Ctrl+x Ctrl+q】 and make your changes. See Mickey’s post for the details.

If you want to see it in action, watch Magnar Sveen use it to change the names of several files at once using wdired and multiple cursors.

Posted in General | Tagged | Leave a comment

Word

Over at Charlie’s Diary, Charlie Stross has an excellent rant entitled Why Microsoft Word Must Die. I’ve written previously of my own feelings about Word: hatred bordering on the pathological. I consider it the apotheosis of everything that can be wrong in a piece of software. Sadly, its open source clones aren’t any better. They are, as the saying goes, bug compatible with the monstrosity they are emulating.

As great as Charlie’s post is, the comments are what’s really interesting. With a couple of exceptions they mostly amount to a long wail of anguish from pitiful souls condemned by circumstances to use Word. I was surprised to learn that even some scientific researchers are being forced to use it.

Charlie’s concern, of course, is writing fiction. He uses a number of tools for that including Scrivener and Vim. In the end, though, he must convert it to Word for his publishers. Other writers do the same. Vernor Vinge, for example, writes his novels with Emacs. Cory Doctorow uses Vim. No one, it seems, wants to actually do their writing in Word.

I wrote and typeset my two (technical) books using Vim and Groff. These days, all my writing is done with Emacs and Org Mode. Mostly that writing gets exported to HTML, but I’d feel comfortable using Org Mode to write a book. In many ways, it’s a superior solution to using Groff. It means working with LaTex instead of Groff1, which I’m most familiar with, but being able to write in Org Mode would be well worth the effort. My publisher is willing to accept camera ready copy so I would just export to LaTex and run off the PDF.

Even fiction writers can benefit from Org Mode. As of version 8, Org Mode can also export to ODT which should make submitting Word compatible files easier. Writers will choose their own tools for their own reasons but if you want a simple, powerful platform that doesn’t second guess you and can produce output in a variety of formats, it’s hard to beat the Emacs/Org Mode combination.

Footnotes:

1

There is an Org Mode back end that exports to Groff but it uses a different Troff macro package and I’ve never used it.

Posted in General | Tagged | Leave a comment