Making Ad Hoc SQL Tables From Org Tables

This is the coolest thing. Charles Choi—who contributions I’ve written about several times—has a really surprising post on turning Org tables into ad hoc SQL tables. There are a couple of things that make this a worthwhile endeavor:

  1. It’s easy to do
  2. SQL queries that you make on the SQL table are output as a RESULTS block just like any other Org Babel invocation.

If you’re used to using SQL to query a database table and generate new tables or other results, this a a really handy thing. Choi has an example of a query on a simple table that would hard to do otherwise. The SQL table is held in memory and no actual database is generated, just a table corresponding to the Org table but you can make normal SQL queries on that table and export the results to your Org file.

For those who are familiar with SQL spells this is a tremendous capability. You can operate on “normal” Org tables in the same way you do on SQL database tables. Take a look at Choi’s post and his example to see how handy this can be.

Posted in General | Tagged , | Leave a comment

Racket and SICP

As I’ve written—seemingly hundreds of times—I’m a huge fan of Abelson and Sussman’s Structure and Interpretation of Computer Programs (SICP). In my opinion, it is one of the best—arguably the best—books on Computer Science. I read it relatively late in my career (I was already a senior developer and team lead) and it completely changed the way I thought of our discipline. I learned many, many things that I didn’t know or only dimly understood before.

When I worked through SICP, I used Guile Scheme to play with the examples and work through the problems. That was good but Guile isn’t the Scheme described and used in SICP. That was a version of MIT Scheme. For those of you who want to work through SICP in the original Scheme, Racket has two collections that offer SICP Scheme and the picture language from the book.

I don’t know that this is a big thing: after all, the book isn’t really about Scheme: it’s about computer science and just happens to use Scheme for its examples. Still, a lot of the examples in SICP would be difficult with a non-LISP language and if you consider SICP an historical as well as a Computer Science work, you might enjoy using the original version of Scheme as you read through the book. Happily, Racket makes this possible.

Posted in General | Tagged | Leave a comment

Denote Dynamic Blocks

For some time, Protesilaos Stavrou (Prot) has been working on an Emacs note taking application that he calls Denote. The system is vaguely reminiscent of a Zettlekasten and has a bunch of nice features. It doesn’t depend on Org mode but integrates nicely with it. You can even set up a Denote capture buffer in Org mode.

As I say, the project has been on-going for some time so there’s lots of information and videos about it. The basic idea is that each note is given a unique name that includes a fine grained time stamp, a title, some optional tags, and an extension. That uniqueness and predictability make it easier to organize your notes.

The purpose of this post is to describe Prot’s latest video reporting on an extension to Denote’s dynamic blocks. The TL;DR is that Denote has a special type of note—called a Meta note—that is denoted by the meta tag. The idea of a Meta note is that it contains information about a collection of other notes. That may include, for example, a commentary or summary of the affiliated notes but it’s also possible to (automatically) include links to those notes. The latest changes, described in the video, provide a way of directly including all or part of the associated notes in the Meta file.

I haven’t paid too much attention to Denote until I saw this video. I felt that Org met my note taking needs and didn’t see a reason to adopt a separate application just for notes. After watching Prot’s video, I may give it a try. I like what he’s done with dynamic blocks. Take a look at the video for the details. It’s only 11 minutes, 46 seconds long so it should be easy to fit in. It may convince you to try out the Denote note taking system.

Posted in General | Tagged | Leave a comment

Winner Mode

Ken Huang over at whatacold’s space has a very useful post on Emacs’ winner mode. I was familiar with the name “winner mode” long before I started using it but the name seemed slightly off-putting and offered no clue as to what it did so I ignored it. Later, I somehow discovered1 what it actually did and I’ve been a dedicated user ever since.

The TL;DR is that it will restore your previous window configuration(s). The typical use case is that you perform some temporary action, such as invoking HELP, and afterwards want to return your window configuration to what it was. Winner mode maintains a stack of window configurations so you can restore configurations older than the previous one.

You can also move forward to reestablish the last replaced configuration. The problem with that is that you can move forward only one configuration but I’ve never found that a problem because I almost never want to do that.

One potential problem that Huang points out is that moving back several configurations can be awkward because the default binding is Ctrl+c
, which is slightly hard to type. Huang offers a nice solution for this: a hydra that you invoke with Ctrl+c w and then simply type p to move backward for each configuration.

If you’re a winner-mode user, you may be interested in his hydra. If you want to see it in action, Huang has an embedded video demonstrating winner mode and the hydra. The video is just over 12 minutes so plan accordingly.

Footnotes:

1

Oh. It turns out it was yet more good advice from Phil.

Posted in General | Tagged | Leave a comment

Pike’s Rules Of Programming

I may have mentioned this before but someone recently posted Rob Pike’s 5 Rules of Programming. The rules are simple and beautiful, almost obvious, but very often ignored. The five rules can be condensed into three principles:

  1. Your intuition stinks. If you’re not measuring program performance, you’re flying blind.
  2. Complicated algorithms are generally not worth the overhead.
  3. Data structures, not code are the secret to good programs.

The five rules drill down on those principles a bit and are worth printing out and putting up besides your monitor. As I say, we all tend to forget them and it’s almost always to our detriment. When guys like Pike, Brooks, and Thompson recommend a course of action, it behooves us to pay attention.

Posted in General | Tagged | Leave a comment

Interactive Java

Those of you who have been around Irreal for awhile have heard me preach the gospel of interactive (or exploratory) programming before. I consider it the absolute best and most pleasing way to program. The problem is that it requires a REPL, which not every language offers.

Java is one of those languages that does have a REPL although you almost never hear about it. As far as I can tell, the REPL is merely a way of letting you type in a line input and get the corresponding output: not too useful.

Not too useful unless you’re using Musa Al-hassy’s REPL driven development package. It enables you to use interactive programming techniques with Java as well as several other languages.

Here he is putting together a Java-based photo display application using the interactive programming method. Notice how it’s easy to experiment by making a small change to see how things work before writing the more complex code that does what you want for the final application.

I don’t know Java at all so I can’t comment on whether or not is code is optimal or even good but I do know about interactive programming and can report that he’s captured the method very well. If you’re a Java programmer—or, really, a user of any other REPL enabled language—you should definitely take a look at this video. The video is only 10 minutes, 18 seconds so it should be easy to find some time for it.

Posted in General | Tagged | Leave a comment

Should I Learn Elisp?

Fate_sc over at the Emacs subreddit asks if he should bother to learn Elisp. He’s fairly new to Emacs and is willing to learn Elisp but wonders if it would be worth his while. You see this type of question a lot.

One of Fate_sc’s concerns is that Elisp is “not like” other programming languages and is therefore hard to learn. It’s true that Lisps are different from most other languages but that’s actually a good thing. It’s good because the language has virtually no syntax and is easy to learn. What does make it difficult is the huge run time library. There are hundreds of functions performing all sorts of tasks and in Lisp virtually all actions are realized through functions.

The thing is, though, you don’t have to learn the entire library to be productive. As I’ve said previously, even after more than 15 years I still don’t know all—or even a majority—of the available functions. But as with learning Org, there’s no need to master the whole library to be productive. You can, as Mike Zamansky is currently demonstrating over at C’est La Z, program significant functionality with just a little Emacs. In short, it’s a long journey but one in which you can be highly productive along the way.

The commenters to Fate_sc’s post all agree that it is worthwhile but that each user has to decide for themselves what level of mastery is appropriate for their needs. And it is, as I say, a lot like learning Org: you first learn just enough to make some simple configurations, then a simple editing function, and, then before you know it, you’ll be able to add significant functionality to your Emacs.

Update [2023-11-27 Mon 10:28]: Added link to the reddit post.

Posted in General | Tagged , | Leave a comment

Zamansky: Learning Elisp #14

Mike Zamansky is back with the next chapter in his Learning Emacs video series. The most recent episodes considered writing a framework to replace certain keywords with an emoji. That started with code to simply replace the keyword with the emoji and moved on to using overlays to display the emoji in the display without altering the underlying text.

The current video considers how to make that code into a minor mode. That turns out to be pretty simple. There’s a macro that handles most of the details for you. You just fill in some parameters and everything else is taken care of.

This is a short video—only 8 minutes, 32 seconds—but Zamansky promises to expand on it in coming episodes. I’ve known—in a vague way—for a long time that making a minor mode was pretty easy but I didn’t realize until this video how simple it is. Once you’ve written the code to do whatever it is the mode is supposed to do, making it into a minor mode boils down to a simple macro call.

I’m looking forward to the future videos that flesh out the process a bit more. Even if you don’t want to publish your minor mode, it can still be useful for streamlining your local workflow. If you do want to share, the process is pretty easy.

Posted in General | Tagged , | Leave a comment

Exiting Recursive Edits

Emacs Elements has an informative post on how to escape from a recursive edit. Unless you’re already an advanced user, you probably have only a vague notion of what a recursive edit is and you certainly aren’t going to be intentionally entering one. But, unfortunately, it’s fairly easy to stumble into one.

Even when you deliberately enter a recursive edit—the video has a typical use case—you still need to know how to exit to the main edit. The standard way to get out of a recursive edit is Ctrl+Alt+c but sometimes Emacs get wedged—especially when you inadvertently find yourself in a recursive edit—and you need to force an escape to the top level.

The video demonstrates several ways of doing this so you should definitely take a look but a good rule of thumb—although not a complete answer— is to try

  • Ctrl+g
  • Ctrl+]
  • Esc Esc Esc

in order.

There are, as I hinted, a few nuances so be sure to take a look at the video for the complete details. The video is only 8 minutes and 21 seconds so it should be easy to fit in.

Update [2023-11-23 Thu 11:41]: Existing → Exiting.

Posted in General | Tagged | Leave a comment

Editing LaTeX With Emacs

Michael Neuper has a very nice article on Efficient LaTeX Editing With Emacs. As far as I know, there’s only two reasonable ways of doing that:

  1. Org Mode
  2. AUCTeX

Org mode is good for what might be called “light weight” LaTeX. If there’s a minimum of mathematics and special formatting, Org is ideal. Its simple markup is easy to learn and you don’t to need to worry about the more difficult LaTeX syntax. The result is exported to LaTeX so you can add LaTeX formatting as needed and the resulting PDF is still produced by LaTeX so you get the beautiful typesetting that the TeX family promises.

If you need more heavy duty mathematics and formatting, it’s hard to beat AUCTeX. It is, after all, purpose built for writing LaTeX inside Emacs. Neuper concentrates on AUCTeX and shows how to augment it to obtain an efficient LaTeX writing environment.

For AUCTeX itself, he starts by showing how to get a live preview within Emacs. If you’re like me and like to see how the output of a long document is progressing as you write, this is a Godsend. A couple of keystrokes and the current document appears right there in a separate Emacs window. What could be better?

He also looks at using special symbols (in the LaTeX source) and folding. I don’t think those are as important as live preview but some may find them useful.

His next addition is CDLaTeX, which I’ve written about before. It provides some shortcuts for entering LaTeX commands and symbols. It’s also usable inside Org—or anywhere in Emacs, really—so it’s definitely worth knowing about if you write LaTeX, even in Org.

Next he looks at using LatexMK and LSP. Most TeX/LaTeX users know about using LatexMK to make sure forward references are resolved. I didn’t know there was as LSP engine for LaTeX but apparently there is. If you care about such things, Neuper shows you how to set it up.

Xenops is a package that I haven’t heard of before. It basically serves as a sort of in place replacement for live preview. Take a look at the animated GIF in Neuper’s post for a demonstration.

Finally, he considers YASnippet and Calc. Both of these are able to expand some simple text into more complicated LaTeX. The Calc example—also illustrated with an animated GIF—is especially revealing. I vaguely knew you could do this sort of thing but I’ve never seen it in action before. Very nice and very powerful.

If you write in LaTeX at all it’s definitely worth your while to take a look at Neuper’s post.

Posted in General | Tagged | Leave a comment