Directory Local Variables

Recently, someone posted a link to Artur Malabarba’s old blog. Sadly, Malabarba no longer posts to it but it still has a lot of good and relevant information. The link was to a Malabarba post about directory local variables.

The idea is that you can place various variables controlling Emacs in a file in a directory and those variables will apply only to other files in that directory (and its subdirectories). It’s ideal, for example, if you have a project directory and would like to apply some Emacs customizations to the project’s files. You can specify that variables should apply only to file having a specific major mode or to all files.

The file format is a tiny bit fussy but fortunately you can simply call add-dir-local-variable and it will prompt you for the necessary information and write it to the local variables file, creating it if necessary.

I really like the idea but it never seems to work for me. That’s mainly because almost all the customizations I want to make involve running some code—invoking a minor mode, for example. File local variables support this (see Malabarba’s post or the documentation for the details) but every time I try to use it I get error messages about exceeding maximum evaluation depth. I wrote about this back in October.

Malabarba’s post is short and well worth a read if you’re not familiar with directory local variables or have mostly forgotten the details.

Posted in General | Tagged | Leave a comment

A Factory For Ideas

The title of this post was coined by Arthur C. Clarke to describe the famed Bell Laboratories facility at Murray Hill, New Jersey. If you’re in the software industry and like me, you probably think of Bell Labs as the birthplace of Unix and everything that went with it but the Labs were much, much more. The Computing Science Research Center was actually a small part of the labs.

Most Irreal readers will remember that the transistor was invented at the Labs but there were many other important breakthroughs including the Laser, radio astronomy, cellular and satellite communications, and that thing called Unix. During its heyday, lab researchers earned 10 Nobel Prizes, 5 Turing awards, and more than 20,000 patents.

I have always felt that the Labs would be the ideal place to work. Take a look at this Computerphile video with Brian Kernighan to see what I mean. It’s hard to imagine a better work environment. At least for me.

In a real sense the Labs have been dead for some time and now, in a bittersweet moment, they are abandoning their Murray Hill facility. They’re currently owned by Nokia who is moving the Labs to a new headquarters, called The HELIX Innovation Center, in New Brunswick. NJ.com has a nice article about the Labs and their history. It even has the iconic picture of Thompson and Ritchie working at their PDP-11, although Unix is barely mentioned in the article.

If your heart warms at the idea of Bell Labs and all it meant, be sure to give the article a look. It’s worth a few minutes of your time.

Posted in General | Tagged | Leave a comment

Two Org Mode Tips

Nicolas Martyanoff has a nifty post that discusses some tips for dealing with Org headlines. There are actually three tips but I adopted only two of them. The first involves what happens when you type Ctrl+Return on a headline. By default, it will start a new headline wherever the point is. By setting org-insert-heading-respect-content to t the new headline will be inserted after the current headline and its associated content. It seems to me that this is what you’d always want but it’s not the default.

In the past, I’ve avoided using Ctrl+Return to open a new headline because it messed up my current content. With this change it does the right thing so it’s definitely worth knowing.

The second tip involves another feature I’ve never really understood and never used: org-goto (bound to Ctrl+c Ctrl+j by default). The default action is to open another buffer with some confusing instructions but if you set org-goto-interface to 'outline-path-completion you just get a nice completing list providing you’re using some sort of completion framework. You’ll also need to disable org-outline-path-complete-in-steps, which you’ve probably already done if you’re using a completion package.

Once those changes are in place, org-goto will get you a list of your headlines with the usual fuzzy search capabilities. This make org-goto really useful, especially for big files with lots of headlines such as my list of blog posts and notes.

The third tip involves not highlighting the entire line of TODO headings. I use org-fontify-done-headline to set DONE headlines to a different color so I don’t need this tip. Even before I discovered org-fontify-done-headline, I was never bothered by having the entire headline the same color as the TODO keyword but your mileage may vary so do what works for you. As usual, Emacs lets you have it your way.

This is a short post but it has a lot of good information in it. Definitely worth a few minutes of your time.

Posted in General | Tagged , | Leave a comment

Dired Async Mode

James Dyer has another useful Emacs discovery. His workflow often involves copying large files, which he does from Emacs using Dired. Even though he’s configured Emacs to use rsync for Dired copies, the transfer can still take some time and Emacs hangs while the copy is in progress..

It turns out that as of Emacs 29 there is a nice solution. You can set dired-async-mode to on and all the Dired operations will happen asynchronously. That includes things like renaming, which, of course, takes no time at all but it really matters mostly for copying.

There isn’t much to say about the post. It boils down to “if you do a lot of copying with Dired, then switch on dired-async-mode.” Check out Dyer’s post for the full story but, as I say, it’s a short story. Nevertheless, it’s a useful tip and well worth knowing about

Posted in General | Tagged | Leave a comment

Bookmark+

Emacs Elements has a new video that takes a quick look at Bookmark+. It serves the same purpose as the builtin bookmark application but is extended in many ways. I’ve been using it for many years ever since abo abo wrote about it and his hack to make jumping to bookmarks easy (I wrote about it here).

The video details some of the additional types of bookmarks that bookmark+ supports. You can, for example, set a bookmark to a URL and bookmark+ will open it in the browser for you. I use that all the time to quickly jump to the Irreal site when I’m working on a post.

Another nice capability is to open a specialized buffer. For example, I have a bookmark to Ibuffer that will open a buffer with the current buffer list. Similarly, you can set a bookmark to a directory. That can be convenient when you have a directory with a long path. For instance, I have a bookmark to the the elpa directory that lives in the (for me) hard to type .emacs.d directory. When you open such a bookmark you get a Dired buffer for the target directory.

The video demonstrates another bookmark type that I don’t use but could be handy: you can mark a region in a file and bookmark that. When you open the bookmark, you jump right to it and it’s highlighted. Similarly, you can bookmark any position in a file although this may be possible with native bookmarks too.

The video is definitely worth a look. It’s 8 minutes, 13 seconds so it should be reasonably easy to find time for it.

Posted in General | Tagged | Leave a comment

Zamansky: Elisp 17

Mike Zamansky is back is back with part 2 of his thesaurus project. In his last video he started a project to explore using Web APIs. He chose to implement a thesaurus to illustrate the concepts and used the Merriam-Webster dictionary interface as his example API.

Once he had a key for the Merriam-Webster API it was a simple matter to retrieve the JSON that Merriam-Webster returns. The current video shows how to parse the JSON, chose a synonym, and replace the target word with it. Again, this turns out to be pretty simple. Once you have the JSON response string and have parsed it with json-parse-string it’s simply a matter of pulling out the required array from the JSON, converting it to a list, presenting it in a completing read, and replacing the target word with the choice from the completing read.

Zamansky finishes the project by turning the code into a minor mode and binding a key shortcut to it. The amazing thing about all this is how simple it is. There’s just a tiny amount of code that implements a reasonably complete thesaurus application. To be sure, a lot of the work is being done by Merriam-Webster but almost all such projects do the same thing with one dictionary provider or another.

This is a very instructive couple of videos that showcase how easy it is to leverage Elisp into a significant application. This last video is 16 minutes, 35 seconds long so you’ll need to schedule some time but it’s definitely worth your time. Be sure to take a look.

Posted in General | Tagged , | Leave a comment

Emacs For Writers

Fedora Magazine has an interesting article in which a journalist, odisej, discovers using Emacs as his writing tool. His article is a sort of perfect case study because odisej has no real technical background so his take on using Emacs for writing is that of someone without expertise in text editors. Of course, he does have experience with “word processors” and has tried a lot of them. He even tried using ancient ones such as WordStar and Word Perfect but none of them clicked for him. Then he tried Emacs and finally discovered his ideal writing environment.

Of course, Emacs is famously idiosyncratic, having existed long before IBM decided what the one true user interface should look like. This means that Emacs is infamous for its steep learning curve and odisej certainly suffered from it but once he learned the basics he knew he had found the perfect writing tool.

What makes it so perfect? He doesn’t say so explicitly but as usual it’s Emacs’ configuration and extensibility that makes the difference. For example, odisej likes wider margins than the default and Emacs makes it easy to set them to his preferred value. Of course, most editors can do that but Emacs makes just about everything configurable.

Then there’s extensibility. Emacs has thousands of packages available that can provide practically any capability the user desires. Odisej added flyspell and wc-mode to his configuration to take care of spelling correction and word counting. Again, most editors provide some flavor of these functions but Emacs has several packages to do them that differ slightly in how they work and how they present their results to the user. As always, Emacs lets you have it your way.

If you want to view Emacs from a writer’s point of view, take a look at odisej’s post.

Posted in General | Tagged | Leave a comment

NASA Coding Standards

In my A Fatal C Error post I talked about how hard it is to write error-free C code. Any large C program is almost guaranteed to have undetected errors. That’s true of all languages—TeX is famous for being the only large programming system that approaches zero errors—but is especially true of C.

Nevertheless, NASA is renowned for writing nearly faultless mission critical software in C. The NASA software developers are so good at this that after the Challenger disaster, the famed physicist Richard Feynman compared the rest of NASA unfavorably to the software team.

That raises the question of how they achieved such excellence. As I mentioned in the Fatal C Error post, part of their secret was a comprehensive and strict set of coding standards. Here they are.

If you’re like me, your first reaction is probably, “But but but…they’ve outlawed all my favorite techniques.” Still, all those favorite techniques are exactly why writing correct C code is so difficult. NASA, of course, is writing software where millions (or billions?) of dollars, not to mention lives, are at stake so there’s little room for error.

The article at the link doesn’t talk about their development process but it is similarly rigorous. All code is gone over line-by-line by the development team and subjected to numerous tests and simulations. I don’t have a link to those at the moment but if I find them, I’ll write another post because the NASA software developers show how it is possible to write safe and efficient code.

Again, if you aren’t terrified when you read about the code running the car you use everyday, you aren’t paying attention.

Afterword

After I wrote this post, I discovered Astroguard, a code auditing and profiling tool that enforces NASA’s coding standards. Take a look at it if you’re interested in such things.

Posted in General | Tagged | Leave a comment

Reinstall Packages

Someone posted a link to an old Bozhidar Batsov post that discusses a nifty little function that automates a simple but annoying manual process. Those of you who use package.el or the use-package macro are probably familiar with the problem. You update a package but it doesn’t load or work correctly. Usually, this is the result of byte compilation problems.

The answer is to uninstall the package and then install it again. It’s not hard but it is a pain. Batsov’s solution is to simply capture the process in a small function. The whole thing amounts to:

  1. Unloading the package
  2. Reinstalling the package
  3. Requiring the package

To make things really easy, he also has an interactive version that does a completing read to specify the package to reinstall. The completing read is populated with the complete package list so it’s easy to get the name right.

If you handle your packages with package.el you should definitely take a look at Batsov’s post. It’s short and easy to read and it’s also easy to just copy his code and insert it right into your init.el.

Posted in General | Tagged | Leave a comment

Lab Notebooks

I love the idea of lab notebooks. I was trained in the sciences but that training was in Mathematics so the idea of lab notebooks didn’t play much of a role. In the experimental sciences and most engineering disciplines, they are not merely crucial but required. If questions arise as to the provenance or precedence of some idea, the lab notebook can be a lifesaver.

When I worked for a computer manufacturer, even the field engineers were required to keep lab notebooks and to turn them in if they left. A crucial aspect of such notebooks is forensics but they can be much more.

Sam Bleckley has a nice post on lab notebooks and why they can be helpful even for software developers. He a software developer but nonetheless keeps a lab notebook for each client. Forensics and proof of precedence are part of that, of course, but as he points out we often try solutions that don’t work out and those experiments aren’t committed anywhere so other developers or our future selves won’t have access to that information and are apt to repeat the failed experiment. By keeping a lab notebook, that information is captured and made available when needed in the future.

I agree with all that but to tell the truth, the thing I liked most about Bleckley’s post is his link to Vela Labnotebooks. These are really beautiful notebooks and have things like numbered pages, a table of contents, and other amenities that make capturing your work easy. I much prefer to keep a digital notebook but for forensic reasons that isn’t always possible. When it isn’t, these Vela notebooks are a great solution.

Posted in General | Tagged | Leave a comment