Tabs and Indentation in Emacs

To my mind, one of the most confusing and arcane “everyday things” in Emacs is the subject of tabs, the Tab key, and indentation. I’ve been using Emacs for over a decade but I still remember how hard it was for me to get Emacs configured to do what I wanted. Back in those days, I was still doing a lot of C coding and the default behavior of C indentation was so odd and off-putting that I almost gave up on Emacs and went back to Vim. Being a n00b, I had no idea how to fix things so I asked Google and found some configuration items to put in my init.el that made things work correctly.

When I was researching this post, I searched my init.el for “indent” and found that I still wasn’t clear on what some of those configuration items were doing. These days, of course, I know how to look them up but you’d think after all this time I’d understand these things a little better.

Doug Beney to the rescue. Over at dougie.io he has a very useful post that discusses how to get tabs and spaces to work as you’d like them to. It’s definitely worth reading to get a handle on how to get indentation and the Tab key working in a sane manner.

Beney likes using tabs instead of spaces and his default configuration reflects that. I’ve never cared much about that controversy but I’ve come to believe that spaces are the better answer (this despite my using tabs in my Vim days). Beney is careful to show how to configure things to use spaces and even provides a couple of functions to enable one or the other so if you’re in the spaces camp, the post is still useful.

Posted in General | Tagged | Leave a comment

Brian Kernighan & Ken Thompson Chat

Last Saturday at the Vintage Computer Festival East, Brian Kernighan and Ken Thompson sat down and chatted about some Unix history and other interesting events in Thompson’s life. The chat was billed as “Kernighan interviewing Thompson” but it was really more like two old friends sitting down and reminiscing. Happily, there’s a video of the chat.

You don’t often see Thompson in public and I can’t recall ever hearing him say more than a few words so the video is a real treat. He turns out to be an engaging and amusing speaker and, of course, there is no one more qualified to talk about the early days of Unix than he.

He tells the story of how after AT&T withdrew from the Multics project and declared that Bell Labs “would no longer do operating systems” the small group (about 4) of users of the nascent Unix system wanted to move it off the PDP-7 to a larger machine. The request for a new machine was denied because “we don’t do operating systems” so Joe Ossana came up with a fib about them building a word processing system for the Patent Department. That proposal was accepted and Unix was officially under way.

Thompson tells a bunch of other stories, including how he came to work at Bell Labs and a slightly different version of the genesis of grep. The whole thing is an hour and 4 minutes so you’ll definitely need to schedule some time but it’s a great video and you really should watch it. It may be your last chance to hear about early Unix from the people who built it.

Posted in General | Tagged , | Leave a comment

A Practical Guide to Sed

Yesterday, I wrote about Liran B. H’s Practical AWK Guide. He has a similar guide for sed called Understanding sed – Practical Guide. Like the Practical AWK post, it illustrates some of sed’s power by showing a few sed one-liners.

Sed is, in principle, pretty simple—especially if you’re familiar with Vi/Vim colon commands—but in practice it can be tricky to get its use exactly right. That’s the real value, I think, of guides like this: it serves to remind us of the basic form of the commands and some of the common tasks it’s used to perform.

If you like the command and want more, the best “quick” guide that I know of is this one. Sadly, tools like sed (and even awk) aren’t used as much these days. It’s sad because they’re powerful tools that often provide a much faster and easier way to accomplish certain tasks than the tools that have replaced them.

Posted in General | Tagged | Leave a comment

A Practical Guide to Understanding AWK

Over at the Developers Area, Liran B.H has a nice practical guide to understanding AWK. There’s a whole book dedicated to AWK so obviously a single blog post isn’t going to cover everything but it does speak to one of AWK’s most powerful features: the one-liner. Brian Kernighan—the ‘K’ in AWK—has said that AWK excells in 1, 2, or 3 line programs and is hard to beat in that domain.

Liran B.H’s guide focuses on short programs for manipulating text data and shows a small amount of the power that AWK has. Two of my favorite features of AWK are the implicit main loop that reads each line of the text and operates on it usually as the result of matching some regex. The other part I like is that all arrays are associative arrays and you don’t have to worry about what form an array index takes or even keep their type consistent. You use whatever’s handiest and it just works. These days, of course, most “modern” languages have associative arrays built in (although maybe not by that name) but when AWK was first implemented, that was much less true.

The post doesn’t cover arrays but does a good job on the implicit main loop and using regexes to trigger actions. AWK is a nice language for certain types of problems and well worth knowing. Take a look at the post and if you want more, find a copy of the AWK book or check out more comprehensive guides such as this one over at Grymoire.com.

Posted in General | Tagged | Leave a comment

Two Nice Org-mode Tutorials

Today I came across two Org-mode tutorials: one a blast from the past, the other new. If you enjoyed yesterday’s post on Jack of Some’s introductory Spacemacs video, you may also like his new video on the absolute minimum you need to know about Spacemacs and Org-mode. As the link tag suggests, it’s an introductory tutorial on using Org-mode with Spacemacs. Org-mode is Org-mode, of course, but Spacemacs has its own shortcuts that won’t be familiar if you’re used to vanilla Emacs.

The value of this tutorial is that it shows how to do elementary Org-mode things in Spacemacs. You won’t learn a whole lot about Org-mode itself as Jack purposely avoids the more advanced topics. My only complaint is his method of adding a header line to a table. Org has shortcuts for this—which probably work with Spacemacs—and no doubt Spacemacs has a custom binding for it. In any event, you can always call org-table-insert-hline directly.

I’ve written about the second video before. It’s Niklas Carlsson’s Literate Programming in Emacs Org-mode. Someone tweeted a link to it and I watched almost the whole thing before I realized that I’d seen it before. It’s a long video and the information content is very dense but it’s one of the best Org-mode videos I know of. As I say, I got so interested in what he was doing that I forgot I’d already seen it. If you haven’t already watched it, you definitely should. I learned a lot from it both times I did.

Posted in General | Tagged , | Leave a comment

Introduction to Spacemacs

Many Irreal readers are fans of Spacemacs. The Spacemacs motto is “The best editor is neither Emacs nor Vim, it’s Emacs and Vim!” That’s a good summary of what it’s all about. If you’ve wondered about Spacemacs or are thinking about trying it out, Jack of Some has a nice video introduction to it on YouTube.

The video begins by covering installation and configuration. I’m not a Spacemacs user so I can’t say for sure but it seems as if the configuration is easier than with vanilla Emacs. Regardless, it’s pretty easy to get things set up.

Most of the video discusses navigation. If you’re used to vanilla Emacs, it will seem foreign. You have the normal Vim keybindings, of course, but there are also special Spacemacs shortcuts that start with what they call the “leader key” (defaulted to Space) followed by 1 or more command keys. The command keys are meant to be mnemonic and as Jack says, you can often guess what the shortcut for a command is even if you aren’t familiar with it. As with Vim, these shortcuts are short and fast to type. You also get a which-key-like help screen if you pause while typing. You can, of course, also use the familiar Emacs shortcuts.

Jack is planning further videos on Spacemacs so you can subscribe to his channel if you’re interested in pursuing the Spacemacs way. Even if you aren’t, the video is worth watching so you can read discussions of Spacemacs intelligently.

Posted in General | Tagged | Leave a comment

Logging Money with Org-mode

Ilker Mutlu tweeted a pointer to an old post by Brian Wisti on how he uses Org-mode to log money. His technique uses only elementary features of Org-mode so, in a sense, it’s not worth recapitulating the post but if, like Mutlu, you’re looking for a light-weight method of tracking income and expenses, you may find the Wisti’s solution useful.

If you’re looking for a full-fledged personal bookkeeping solution, this isn’t it; you should take a look at John Wiegley’s ledger program and the associated ledger-mode for Emacs. If you’re not ready for a double-entry accounting system and its complexities, Wisti’s solution may be just what you’re looking for. Wisti effortlessly integrated his technique into his existing journal but his method works whether or not you are already logging things.

I display my journal entry headers in my agenda so that it can serve as a précis of my day. I would, therefore, prefer an active timestamp rather than the inactive one that Wisti uses. That’s just a matter of changing the %U to %T (or perhaps %t if you don’t care about the time) in his capture template.

Even if you’re not in the market for a way of logging money transactions, it’s worth taking a look Wisti’s post as a nice example of an application of Org-mode.

Posted in General | Tagged , | Leave a comment

Making Design Documents with Org-mode

Christian Blades over at the Beard Institute has a nice post on how he uses Org-mode to write and manage design documents. One interesting feature of his workflow is that the document starts as a TODO item in his agenda and the details—including the text—get filled in as the document evolves. When he’s ready to share the document with the rest of his team, he exports the TODO subtree to PDF and uploads it to Google drive.

Since he’s exporting only a subtree, he puts the desired export options in a PROPERTIES drawer so that he can have per-document options if needed. That includes the file name for the PDF so he doesn’t have to manually rename the file before moving it to Google drive.

Another nice technique he uses is to decorate diagrams with sizing information so they aren’t overlarge. He does that with a bit of Elisp that gets called by the :post keyword in the source block that generates the diagram.

Take a look at Blades’ post for the details. It’s a nice workflow and one that would work for most kinds of documentation. It’s simple but seems very effective.

Posted in General | Tagged , | Leave a comment

Using C-x 4 in Emacs

Marcin Borkowski (mbork) has an interesting post on the Emacs C-x 4 bindings. My normal Emacs window configuration is two side-by-side windows in a full screen frame and my workflow often involves opening related buffers in the two windows so I am constantly using commands like find-file-other-window (Ctrl+x 4 f) and switch-to-buffer-other-window (Ctrl+x 4 b). All that’s by way of saying that I’m pretty familiar with the Ctrl+x 4 bindings. Nevertheless, I learned some new things from Borkowski’s post.

One of those new things is display-buffer (Ctrl+x 4 Ctrl+o). It’s sort of like find-file-other-window except that it doesn’t switch focus. That’s handy if you want to open a file in the other window but keep working in the current window.

Another new command I learned is clone-indirect-buffer-other-window (Ctrl+x 4 c). Cloning buffers is something I rarely do so I always forget the exact commands. This makes it easy to clone a buffer with a single key sequence.

Finally, there’s an infelicity. I always think of Ctrl+x 4 as meaning perform an action in the other window. Indeed, if you’re using which-key, and you should be, you’ll see that all the Ctrl+x 4 completions do perform some action in the other window. All, that is, except Ctrl+x 4 0. You’d think that it would delete the other window but it does something entirely different. It deletes the current window and its associated buffer. To my mind, that’s a blatant violation of the principle of least surprise.

Take a look at Borkowski’s post. He discusses additional Ctrl+x 4 commands and provides a deeper explanation of some of the commands I’ve mentioned.

Posted in General | Tagged | Leave a comment

Drawing Figures in Math Lectures

A month ago I wrote about Gilles Castel’s system for taking notes with LaTeX during Math lectures. As I wrote at the time, I was astounded that he could type the LaTeX fast enough to keep up with the lecturer. It turned out he used a snippet completion system and some Vim customizations to make it possible. Castel’s post didn’t explain how he drew the figures to go with the text.

Now Castel has published a second post that explains how he’s able to draw those figures. Take a look at either post to see some of those figures: they’re professional quality drawings rendered directly in the LaTeX.

Once again, he does this with some snippets and Vim customizations along with the use of Inkscape, a vector graphics editor that’s freely available for Linux, macOS, and Windows. As with entering the mathematical text, the secret of his speed is the aggressive optimization of keystrokes, including a Python program that filters his keystrokes before passing them onto Inkscape. Castel’s post has several animated GIFs that show the process in action.

Most or all of what’s he’s doing could easily be ported to Emacs/AUCTeX. A bit of Elisp could replace his first script and probably his Python filtering program although I’m not sure of the details for replacing the filtering program. If you’re interested on porting his system to Emacs and, say, macOS, it should be fairly easy to do the necessary research.

Posted in General | Tagged , | Leave a comment