Exporting Clock Tables

After watching Jake B’s video on Org Clock Tables and Irreal’s commentary on it, The Emacs Cat decided to share how he uses clock tables. His use is very idiosyncratic and fashioned for his specific circumstances. The TL;DR is that his employer not only requires a periodic report of time spent on various tasks but requires a very specific format for the report that must be delivered in MS Word.

Putting aside, for the moment, the indignity of having to use Word, the stumbling block to simply using the Clock Table output is that requirement for a specific format. All the necessary data is there but in the wrong format.

It turns out that Org has the org-clock-get-table-data function that gathers the data for the Clock Table report and delivers it as an easily parsable list. Part of his employer’s specific format is that dates must be of the form DD.MM.YYYY and the times must be zero padded on the left and have different lengths depending on the context. Once he had raw data, it was easy to format appropriately and produce the required report. That leaves only delivering it as a Word doc. Of course, once more Emacs has us covered and he simply exported his results as an ODT file.

The other nice thing is that he did his development right in his time tracking Org file using source blocks. He was able to experiment with various approaches and see the data that org-clock-get-table-data returned. It’s a really nice post and serves as a how-to for anyone who needs to produce custom time reports.

Posted in General | Tagged , | Leave a comment

Zamansky: Learning Elisp #5

Mike Zamansky is back with the fifth episode of his Learning Elisp Video series. I say “episode” rather than “video” because he’s split Learning Elisp #5 into two videos. That was to prevent a single, overly long video. As it is, the two videos run 14 minutes, 4 seconds and 12 minutes, 55 seconds.

The theme of the first video is conditional statements: if statements and the like. As Zamansky points out, the Elisp if statement is pretty much like the if statements of other languages but with a bit less syntactic sugar. You can, of course, chain these if statements as you do in other languages but Elisp has a better way: the cond statement that lets you test sequential conditions and perform the action associated with the first condition that returns t.

He uses the cond statement to expand his rot13 function to deal with capital letters and characters that aren’t a letter. At this point, he’s got a reasonable rot13 function.

The second video has two main themes. The first is how to make his rot13 function accessible from the Emacs “command line” (via Meta+x) and assign it to a key sequence short cut. This mainly involves the (interactive) declaration.

The second theme is applying rot13 to arbitrary text in the current buffer without actually typing the text in. He begins with showing how to apply it to the word at point and the entire line at point. No doubt he’ll expand on this in subsequent videos to provide a flexible rot13 like the built-in version.

At this point, his Learning Elisp series is beginning to show how to use Elisp to build useful functions for actual use in Emacs. If you’re new to Elisp, this is a very useful series to follow.

Posted in General | Tagged | Leave a comment

Scanning QR/Bar Codes with Emacs

If you’re like me, every once in a while you need to scan a QR code—or even a bar code. Not often but every once in a while. There are all kinds of apps to do that, especially on our phones but, of course, the true and faithful Emacser wants to do it from within Emacs. Álvaro Ramírez to the rescue.

You can probably guess that this is another functionality he’s folded into his dwim-shell-command framework. The secret sauce is the zbarimg utility, which is available on all three of the major platforms. Ramírez recommends macOS users simply download it from Homebrew. There are binaries for many systems at the Zbar GitHub site.

This is, as I say, not something that you’re going to use every day so it make sense to give it an easy-to-remember name as Ramírez does. Of course, that’s a lot easier if you have his dwim-shell-command framework installed. Doing so not only gives you an easy-to-remember name but also arranges for it to work seamlessly with dired.

Posted in General | Tagged | Leave a comment

Prot On Writing A Custom Mode Line

Protesilaos Stavrou (Prot) has a really interesting video on writing a custom mode line. If you’re like me, your mode line customizations are limited to adding the line and column indicators and using diminish to inhibit displaying various minor modes. You can, of course, do more but the details of making a custom mode line are surprisingly fussy.

Prot’s video shows us how to do it. He starts by showing us his custom mode line. It has some nice features. One thing I liked is that only the window with focus has the full mode line. The other windows have an abbreviated mode line showing only the buffer name and its major mode. That makes it easy to tell which window has focus so he doesn’t need to change the background as the default mode line does.

Prot has some idiosyncratic notions of what should be on the mode line—he doesn’t like the line and column indicators, for example—but that’s why, after all, you have custom mode lines. His video is not about how to reproduce his mode line; it’s about how to make your own.

As I said, the process can be a bit fussy and there are all kinds of gotchas but once you know a few rules it’s pretty easy to build your own. The nice thing is you can display your candidate mode line as you build it without having to restart Emacs.

As usual, Prot provides links to his own configuration so you can copy some or all of what he did. He also provides a copy of the intermediate code he used while developing his sample mode line so you don’t have worry about copying it down from the video. The runtime is 41 minutes 53 seconds so you’ll have to schedule some time but if you’ve ever wanted to customize your mode line, it will be well worth your time.

Posted in General | Tagged | Leave a comment

Emacs 29.1 Released

Eli Zaretskii writes to announce that Emacs 29.1 has been released and is available in the usual places. As usual, I compiled it from source so I don’t know if the prebuilt distributions have been released yet.

In any event, this post is being written with the new version so there are no obvious nasty surprises. As usual, many thanks to Zaretskii and everyone else who worked so hard to bring this new release to us. These guys are heroes who don’t get nearly enough recognition for what they do. If you run into any of them, be sure to buy them a beer.

Posted in General | Tagged | Leave a comment

Composing Avy

A couple of years ago Karthik Chikmagalur published a long, dense post on how Avy can do anything. For some reason—I no longer remember why—I never added his post to my blog queue. Recently his comment to my post Emacs Elements on Avy reacquainted me with his post and I’m astounded that I didn’t write about such a rich and useful post.

I’ve written many times about how Avy is one of my most-used commands. It makes it almost trivially easy to move around in the text on the screen. Avy has several commands—more than appear in the documentation. One of Karthik’s two main points is that there are too many commands to remember or bind so you should settle on just one and use it for everything. There’s some merit to that idea. He uses avy-goto-char-timer, which can, indeed, perform most of the tasks of the other commands. I use it everyday but my most used Avy command is avy-goto-word-1, which I like because it considers only letters beginning words and thus reduces the number of targets. As a practical matter, I restrict myself to those two Avy commands.

His second main point is that Avy is much more general and useful than you thought. After you select a target, the default action is to jump to that location but other actions are possible. There are several alternative actions, which you can see by typing ? when the list of targets appears.

But wait. There’s more. You can also easily add your own actions as Karthik demonstrates. His post shows several such actions with the code to achieve them. He also has a link to a file with all the code if you want to steal some or all of them.

This is a really good post and worth your time to read even though it is long. And, as I said in my Emacs Elements on Avy post, if you aren’t using Avy, you’re working too hard.

Posted in General | Tagged | Leave a comment

Config File Languages

Joe Marshall over at Abstract Heresies has a short allegory on designing configuration file languages. We’ve probably all been there. It starts off simple: he just wants a configuration file that handles key/value pairs. But then he finds he needs a bit more flexibility—Marshall’s example is getting a value from an environment variable—so his key/value scheme added an escape sequence to deal with this case. In the way of entropy everywhere, it just goes on and on.

Pretty soon, he realizes that what’s really going on is that he’s designing a crappy configuration language on the fly rather than designing a good one from the outset. As I said, we’ve all been there.

His last paragraph sums up the point:

If we had some forethought, we would have realized that we were designing a language and we would have put the effort into making it a good one. If we’re lazy, we’d just pick an existing good language. Like Lisp.

That brings us to Emacs. The Emacs configuration file is written in the same language that most of the rest of Emacs is: Elisp. That means that the configuration can be as rich as desired, including even adding or rewriting entire functions. That’s the real secret to Emacs’s famous extensibility: You can add to the core body of code right in the configuration file.

Sadly, not every application has the advantage of being written in a Lisp dialect but you can still leverage the advantages of Lisp by using Lisp for the configuration file. A great example of this is Guile, a Scheme-based extension language that can be linked into applications written in another language.

With a little planning, you can avoid the descent into despair of Marshall’s apocryphal developer.

UPDATE [2023-07-28 Fri 15:25]: Added link to Marshall’s post.

Posted in General | Tagged , | Leave a comment

Eshell Configuration

Another video from Emacs Elements. This time it’s about Eshell configuration. I love Eshell and use it all the time. It’s mostly like a standard Unix shell but there are some surprises. The major surprise, of course, is that you can’t create pipelines the way you can in, say, Bash or Zshell. But there are some other gotchas. One of them is setting aliases.

It’s really easy to set an alias with Eshell—arguably easier than in any of the Unix shells—but it is different so it’s nice that the video discusses how to set and use them. Best of all, they’re stored in a plain text file that you can edit by hand if you’re inclined.

One of the other things the video mentions is some Elisp to provide a clear command for Eshell. You can type clear and it will blank the screen but the cursor is left in the wrong place and you can scroll backward to all the text you thought you were clearing. I combined that code with alias to make a real clear command. I modified the code a bit to

(defun eshell-clear-buffer ()
  "Clear the current Eshell buffer."
  (interactive)
  (let ((inhibit-read-only t))
    (erase-buffer)
    (eshell-send-input)))

and then set an alias to clear with

alias clear '(eshell-clear-buffer)

That solves a longstanding problem with my Eshell use so I was happy to discover it.

The video covers a few other subjects as well. You’ll learn how to set up Eshell to imitate Plan 9’s shell behavior, how to open files in Eshell, and where Eshell hides all your settings.

Finally, he strongly recommends Mickey’s article Mastering Eshell to learn everything you need to know about Eshell to use it effectively.

UPDATE [2023-08-14 Mon 16:15]: shell-send-inputeshell-send-input

Posted in General | Tagged | Leave a comment

Zamansky: Elisp 4

Mike Zamansky is back with the fourth video in his Learning Elisp series. In this video, Zamansky begins building some real functions by considering the rot13 utility. Rot13 is a simple function built into Emacs and other utilities mainly as a way of protecting those with delicate sensibilities from potentially upsetting material. The idea is that each letter of some text is rotated to the right by 13 letters with the appropriate wrap around. If you apply it again, you get the original text back.

It’s conceptually simple but there are a bunch of annoying details such as the fact that the lower case a is not 0 or 1 but 97. There are some other wrinkles as well that the video explores as Zamansky develops the material.

He begins with a lengthy detour into the history of Usenet and the genesis of rot13 as a way of sparing the faint of heart from possibly disturbing material. The text was “encrypted” with rot13 which served as a warning of dangerous material ahead. Those who felt up to it could “decrypt” the offensive material to see the joke or whatever it was.

In his preliminary version of rot13, Zamansky introduces the mapcar function as a way of operating on each character of a string and of anonymous functions as a way of providing a one off function that isn’t worth cluttering up the name space with.

The video is 34 minutes, 12 seconds but Zamansky provides links to skip over the Usenet history if you’re not interested. If you weren’t around in the days of Usenet, I recommend watching it to get a better idea of the context in which rot13 made sense.

Posted in General | Tagged | Leave a comment

Implementing Emacs Threads

Two or three weeks ago in the comments to my post How Many Years Have You Been Using Emacs? I opined that the biggest thing missing from Emacs was a decent threading model. I also admitted that it was a very hard problem and one that I was glad I didn’t have to solve.

Dickmao is a braver soul and decided to try a proof of concept. After all, he said, how hard could it be? The problem with implementing threads in Emacs is that historically there was no lexical binding; all the non-local symbols were dynamically bound globals.

Dickmao’s idea was simple: give each thread its own obarray so that it would have its own copy of each symbol. It didn’t take any time at all for things to blow up. He immediately encountered a static buffer in the print routine. He played wack-a-mole for a while but there always seemed to be another problem.

He explains all this in his video. After you watch it, you will have a much better understanding of the problem with threads in Emacs. The video is only 4 minutes, 12 seconds so it should be easy to fit in.

Posted in General | Tagged | Leave a comment