Zamansky Live Codes Advent of Code 2016 #2

Mike Zamansky who is, after all, a teacher, demonstrates his coding technique by live coding the second exercise in the 2016 Advent of Code. He is coding in C++ because that’s what he’s teaching at the moment but even if, like me, it’s not your favorite language, it’s still a nice introduction to a certain style of coding.

That style is basically ensuring that each little piece of your code is working before you move onto to the next piece. That’s the technique that I use and love when I’m coding in Lisp. The REPL makes it really easy because you can execute a single statement and see what the result is without having to add special scaffolding. It’s a little harder in a C-like language but not, as Zamansky shows, impossible.

Note that this is a bit different from Test Driven Development. You’re merely trying to discover your errors as soon as possible rather than trying for a rigorous demonstration of correctness at each step. Since starting to program in Lisp, I use this technique no matter what language I’m using. Still, it works best in a REPL-driven language like Lisp.

Another point the video makes is the importance of data representation. By choosing a good representation you can reduce the complexity of your code and also make it easier to adjust to changes in the specifications of the problem you’re trying to solve.

The video is 17 minutes so plan accordingly.

Posted in Programming | Tagged , | Leave a comment

Literate Programming with Babel

Angelo Basile has an interesting post on using Babel and Org Mode for literate programming. As he remarks, his setup is particularly useful in an educational environment.

It’s a short post but has some useful ideas. If you’d like to try a sort of light-weight literate programming take a look at Basile’s post and try it out on a small program. Pay particular attention to the #+PROPERTY line that he puts at the top of each file. It sets up a nice default environment.

Posted in General | Tagged , | Leave a comment

Moving a File in Emacs

Sometimes you want to move a file you have open in Emacs. More often, perhaps, you simply want to rename the file. Emacs has some functions that do this but none of them are entirely satisfactory. The write-file function comes close but it leaves the old file in place and the rename functions don’t take care of the buffer. Zachary Kanfer has an interesting bit of Elisp that does the right thing.

His code copies the file to a new location (or name) using write-file so that the buffer name is changed and any changes later saved will be written to the new file. If the move is successful, the old file is deleted.

This seems pretty simple and it is but it’s surprising how often it comes up. If you find yourself in this situation more than once it’s probably worth your while to add Kanfer’s code to your init.el.

Posted in General | Tagged | 4 Comments

Scientific Writing with Zotero and Org Mode

Michael Behr has an interesting post on his scientific writing workflow. The post isn’t really about how he writes his papers but rather how he organizes and curates his research materials. As you’d expect, he uses an Org file to store links to research papers and take notes on them. If you’re an Org mode user you won’t have any difficulty imagining what this looks like.

What’s interesting about his workflow is that he use Zotero to capture and store copies of the papers he needs for his research. I used Zotero long ago when I was still using Vim and Zotero existed solely as a Firefox plugin. These days, it’s available as a standalone application as well so even if you’re not a Firefox user, you can still take advantage of it. One very nice aspect of Zotero is that it has Emacs integration so that you can interact with it from within Emacs. Behr’s post describes how this works and how he uses it.

I’m not sure how necessary Zotero is if you want a similar workflow. You can easily store the papers and link to them from within Org files without a separate application. You could, for example, use the org-attach command (see this video for an excellent introduction) to store and associate copies of the papers with an Org file. It appears that Zotero does make it a bit easier to retrieve papers but I’m pretty sure that a bit of Elisp could easily duplicate its capabilities. On the other hand, Zotero is already available and has nice integration so if you don’t mind the separate utility, it’s a good solution.

If you’re a student or researcher who needs to keep tract of papers, be sure to take a look at Behr’s post. His workflow is interesting and may give you some ideas.

Posted in General | Tagged , | 2 Comments

Zamansky 24: Org Capture (Part 2)

Mike Zamansky has another video up in his Using Emacs series. This one is a continuation of his last video on Org Mode capture. Most of the video explains how Zamansky pops up an Org capture buffer even if he’s not in Emacs. I use a similar method all the time and find it really useful. If I want to make a quick note or capture a browser link for a blog post, I just pop up the capture menu and use the appropriate template.

Zamansky’s method is better than mine because his pops up a temporary frame that is deleted when he saves the capture and leaves him back where he started. Mine switches to Emacs and displays the menu but I have to switch back to whatever I was doing after I save the capture. It’s a bit harder to pop up a capture buffer with MacOS because you have to use AppleScript. I think if I install a keyboard macro app I can duplicate Zamansky’s method so I’ll probably give that a try.

The other nice trick I learned from the video is obvious but I never thought of it. Zamansky maintains an Org file of useful browser links along with helpful commentary. He exports this to HTML and then saves the file as a browser bookmark. That way, he can click on the book mark to bring up the page of his links and then click on the appropriate link to visit the page he’s interested in. As I said, it’s obvious in retrospect but a great tip if you haven’t considered it.

Posted in General | Tagged , | Leave a comment

Awesome Emacs (Again)

I’ve written about the community sourced Awesome Emacs before but it’s worth revisiting it because

  1. It’s really useful.
  2. It’s always being added to.

This time, I ignored the Table of Contents and just read down the list of packages and other goodies. Being crowd sourced, it offers an up-to-date list of Emacs resources that reflects a broad cross sections of interests and needs. For instance, it covers packages and modes for languages such as

  • C/C++
  • Python
  • Ruby
  • Common Lisp
  • Scheme
  • Clojure
  • Elisp
  • JavaScript
  • CoffeScript
  • TypeScript
  • PureScript
  • PHP
  • Java
  • Go
  • C#
  • Rust
  • Erlang
  • Elixir
  • Haskell
  • Swift
  • Scala
  • Lua
  • SML
  • Groovy
  • OCaml
  • Nim
  • D
  • Elm
  • Stan

The packages in each category are listed more or less in the order of popularity so you can get an idea of how useful others have found a particular package. I like the list because it’s an easy place to surf for new and useful packages. You can do that with something like MELPA, of course, but that list is so large it can be intimidating. If you haven’t seen the list, take a moment to browse through it; you may find something useful.

Posted in General | Tagged | Leave a comment

Blub Programmers: Editor Division

The other day I saw this tweet

and immediately thought of Paul Graham’s essay about Blub programmers. I don’t mean to beat up on Mr. Littlebury, who I don’t know but am sure is a splendid fellow. I do think, however, that rather than reveling in his lack of knowledge he might investigate why so many of the best engineers do use Vim or Emacs.

His main complaint appears to be that Vim and Emacs are old. To that point I recommend Vivek Haldar’s observation that editors are like wine. You want an editor that’s old because, as Haldar says, “You want the text editor that has been around long enough and used by enough geeks that every conceivable pattern of manipulating symbols on the screen has been thought of, and crystallized into a re-usable pack.”

We use a vintage editor not because of some weird retro fetishism but because we want the best possible tool to get the job done. And nano? Really? It’s a great editor for people who don’t use editors. It’s definitely not what I have in mind when I think of powerful tools. On the other hand, it does, apparently, help protect you from the old ones.

Posted in General | Tagged | 2 Comments

Zamansky 23: Org Capture (Part 1)

Mike Zamansky has another video up. It’s number 23 in his Using Emacs Series and is part 1 of a sequence videos about Org capture. In this first installment, he covers the mechanics of Org capture: how to configure it, how to call it, and how to write your own custom capture templates.

If you’ve been around here for awhile, you know that the Org capture system is an integral part of my workflow. Like Zamansky, I record blog ideas with Org capture and use that entry as an anchor for the subsequent blog. After I write the actual blog post, I put a pointer to the blog text in the anchor entry as well as recording the time I worked on the post. Since each blog idea is a TODO item, my blog ideas file also tracks the state of the post: waiting to be started, ready to post, done, and so on. I should probably write about that process since it’s changed considerably since the last time I wrote about it.

I have several other templates that I use to capture journal entries, appointments, and other such information. All of this data is nicely displayed by the agenda system, which, presumably, Zamansky will talk about in his next video. The other strategy that I use is to insert tags into each entry. The capture templates prompt me for these so I don’t forget. The tags idea is something I learned from Karl Voit. The tags allow me to instantly display any entries with a certain tag. If, for example, I can’t remember the name of a nice restaurant I had dinner at last year, I can display all agenda items with a tag of dinner and quickly locate the entry that has the restaurant’s name.

It’s conventional wisdom that Org is Emacs’ killer app but the capture/agenda seem to be to be Org’s killer app. All my day-to-day planning and recording of events is centered around it and it fits in seamlessly with my workflow. If you aren’t using it take a look at Zamansky’s video (and the following ones on Org capture) and try it out for yourself. You won’t be sorry.

Posted in General | Tagged , | Leave a comment

Writing a format-like Function

Marcin Borkowski (mbork) has an interesting post on something I didn’t know about. He needed to write his own format-like function, presumably with %-tags not defined by the format function. It’s not too hard to write something like that but he asked about it on the Emacs help mailing list and got pointed to format-spec. That was just what he needed.

All the values are ultimately printed by princ so you can use it to print just about any Elisp object. You probably aren’t going to have a lot of use for format-spec but when you do need it, it’s just what you want. As Borkowski notes, you can use format-spec-make to help build the value list. I found the documentation for the two functions a bit ambiguous but the code is short and easy to read and resolved the questions I had about the functions.

Posted in General | Tagged | Leave a comment

Thoughts on Emacs Configuration

I sometimes feel that I have the most unorganized Emacs configuration strategy imaginable. I don’t worry about autoloading or other quick-loading strategies and I throw my entire configuration (other than machine and OS specific items) into my init.el file. All the really cool guys have their configurations broken out into separate files, carefully optimized for the smallest possible loading time.

I was, therefore, happy to discover that I’m not alone. Selah not only has the same strategy but argues that it’s the correct strategy. He used to obsess over Emacs loading times like the rest of us but realized that he spent far more time tweaking his configuration for optimal load time than he did waiting for it to load. That’s because like most of us he didn’t load it very often. He says he loads it only about twice a week. Even that seems like a lot to me. My Emacs instances generally run from a week to a month before I reload it because I get into an error condition or need to refresh a package. Reloading takes me about 5 seconds so it makes no sense worrying about reducing the time—except maybe as an interesting engineering problem.

Selah says that he likes everything in a single file because he doesn’t have to spend time remembering where things are as he did when he had everything broken out to multiple files. I like keeping everything in a single init.el for the same reason. Yes, you can locate things reasonably quickly with some form of grep or indexing (such as a TAGS file) but as Selah notes, that means you have to perform a context switch and think about something besides the problem you’re solving. The other advantage of having a single file is that it makes it easy to convert it to an annotated Org file. I haven’t done that yet but it’s on my TODO list.

UPDATE [2016-11-29 Tue 10:17]: Correct post’s author.

UPDATE [2016-11-30 Wed 12:41]: iniitinit.

Posted in General | Tagged | 8 Comments