koldfront

Saving and restoring an Emacs macro #emacs

🕧︎ - 2025-04-18
Emacs logo

From time to time I add domains to a configuration file, header_checks, for my mail server, Postfix, to block them as spam.

To do this, I copy the email-address from a spam email, paste it into the configuration file, and modify it to escape the . and remove up until the @.

Doing that for a lot of spam is of course tedious, and so I usually create a macro in Emacs to do the pasting and massaging.

However, creating that macro is a bit tedious and that makes me not do it for the first couple of spams. Until I get too annoyed. So it keeps me from updating the checks. Not great.

Emacs is capable of generating the lisp code corresponding to a macro, so I thought "Hah, I will save the macro in a comment in the file, then I can evaluate it when I'm updating the file, and I don't have to record the macro every time!"

Alas, the command M-x insert-kdb-macro RET inserted some code that gave an error when evaluated - how odd?!

At first I assumed I was doing something wrong - the documentation only mentions saving a named macro and I was saving the last, unnamed one - but after looking at the lisp code of the function insert-kbd-macro (Emacs makes this easy), it was clear to me that it was supposed to work: it contains specific code to handle the last macro case.

I also tried an earlier version of Emacs (I usually run a development version), the one in Debian stable - version 28.2, and there the code generated was different, and, even more interestingly, worked!

So, I created a bug report for Emacs (#77317) and was swiftly told by one of the current Emacs maintainers that the documentation only says it works for named macros.

I argued that the function specifically has a branch for the last (and unnamed) keyboard macro, and that the functionality was broken in 2022, and Cc'ed the previous Emacs maintainer who made the breaking change (which was an improvement to the other branch of the function).

He asked for an explanation of my use case, and after I supplied that, he made a change to fix the problem, which I tested swiftly; it worked, and pushed it to the development version of Emacs a couple of days later.

Nice!

So, now I could easily generate the code to restore the macro and put it in a comment in the file.

Shortly after it hit me: Emacs can evaluate code from a file when loading it, I could have it restore the macro automatically on opening the file!

A quick 3 lines at the bottom of the file later:

# Local Variables:
# eval: (setq last-kbd-macro (kmacro--keys (kmacro "| C-y M-<left> <left> [ <right> ] C-r @ <right> M-<backspace> C-s ) <left>")))
# End:

and now, more than ever, Bob is indeed my uncle!

Upgrading the hat shelf server #hardware

🕗︎ - 2025-04-04
nvme temperature graph for the pas week, showing a jump up after the upgrade from around 50° to around 60°

It has been almost 6 years since I last upgraded my home server (except for the nvme).

Last time I went for a very low power CPU, an AMD Ryzen 5 2400GE (35W, 4/8 cores), and 64 GB of memory.

This time I switched to an AMD Ryzen 9 7900 (65W, 12/24 cores) and 128 GB of memory. The new motherboard has an AM5 socket (up from AM4) and uses DDR5 RAM (up from DDR4). It has two empty RAM slots left, so I can bump it further, and it also has an extra M.2 slot for another nvme. The ethernet port is 2.5 Gbit/s, but it's the only such on my home network, so that part isn't of much use.

CPU temperature graph for the past week, also showing a jump up

Even though the new motherboard (a Gigabyte B650M D3HP) is also a micro ATX, it was slightly longer than the old one, so I could not put the power supply in the same place as before. I managed to squeeze it in above the CPU cooler, but it covers ¾ of it, which is not ideal, as the fan is making a lot of noise now, where before it was almost completely silent.

Switching over was more of a faff than I expected - at first I had to guess that "CSM" is something I need to fiddle with to have the machine boot from the nvme at all.

CPU frequency graph for the last week, showing a nice jump up

More annoyingly, as soon as I had configured the BIOS for booting, the system stopped showing anything on the screen. The machine boots fine, but nothing appears on the monitor. I even tried connecting it with different cables ports, and to another screen.

After fighting with that for too long, I eventually connected the nvme (via a usb-enclosure) to my laptop, edited the /etc/network/interfaces file, updating the network interface name, and then put the machine back on the hat shelf.

Memory graph for the past week, showing the doubling but only slowly is more memory used now

The temperatures have gone up quite a bit - I'm thinking it is not ideal to have the CPU cooler blocked, so I am going to try pulling out the optical drive and repositioning the power supply at some point.

Besides the number of cores and the amount of CPU cache, the clock frequency is also up from around 1.8 GHz to 3.0 GHz, so all in all the server is more snappy now.

I haven't adjusted the configuration of PostgreSQL to use more memory, so the graph is only slowly showing the doubling making a difference.

Duration on thumbnails on my desktop

🕞︎ - 2025-03-08
Screenshot of folder with two video thumbnails with their duration shown in the corner

I was looking at a folder full of videos, trying to decide which one to watch. The title and the thumbnail help me decide, but a third criteria popped up in my head - how long is the video?

So I was annoyed that this piece of information wasn't readily available.

But why not do something about that?

On my computer it turns out the thumbnails that the file manager (Nemo) shows are generated by totem-video-thumbnailer, via a configuration file in /usr/share/thumbnailers, so I set out to make a wrapper, that would put the duration into the thumbnail.

Here is the script:

#!/bin/bash

# video-duration-thumbnailer - wrapper for totem-video-thumbnailer
#
#    Adds duration to the thumbnail.
#
#    Put this script somewhere, edit
#    /usr/share/thumbnailers/totem.thumbnailer changing
#    "Exec=/usr/bin/totem-video-thumbnailer -s %s %u %o" to
#    'Exec=YOURPATH/video-duration-thumbnailer -s %s %u %o'
#
#    Thanks to Klaus for the Python snippet for url decoding.
#
# Copyright (C) 2025. Under GPLv2. By Adam Sjøgren <asjo@koldfront.dk>

INPUT=$3
OUTPUT=$4

# Run the original thumbnailer:
/usr/bin/totem-video-thumbnailer "$@"

# If possible, overlay duration:
if echo "$INPUT" | grep --quiet 'file://'; then
    FILE=$(echo "$INPUT" | python -c 'import sys; from urllib.parse import unquote; print(unquote(sys.stdin.read().strip()))')

    DURATION=$(ffprobe -i "$FILE" -show_entries format=duration -v quiet -of csv="p=0" -sexagesimal | cut -d. -f 1)

    TMPFILE=$(mktemp -t vtt-XXXXXX)
    convert "$OUTPUT" -gravity SouthEast -font DejaVu-Sans-Condensed -pointsize 24 -fill white -stroke gray -annotate +2+2 "$DURATION" "$TMPFILE"
    mv "$TMPFILE" "$OUTPUT"
fi

And now when I look at a folder of videos the duration is shown (after pressing Ctrl-R to update the thumbnails)!

I ❤️ Free Software #free software #ilovefs

🕗︎ - 2025-02-14
Use Study Share Improve

GNU Emacs, Debian GNU/Linux, Linux, Gnus, X.Org, Postfix, GHC, PostgreSQL, OpenSSH, Firefox, Apache, ejabberd, Dovecot, git, GnuPG, XMonad, jabber.el, Magit, rdiff-backup, LaTeX, Gimp, VLC, Syncthing, Sakura, chrony, Fail2ban, WeeWX, DejaVu fonts, ripgrep, lirc, MPD Flameshot, lots of GNU, the list goes on and on - thanks everybody!

New HTML elements #html

🕘︎ - 2024-11-15

A couple of days ago I used the details HTML element in anger for the first time, yay.

Recently I learned about the datalist element as well - both quite useful.

So, what other elements and attributes have been added to HTML during the past 10-15 odd years I looked away and didn't read the specifications?

Trentemøller, Pumpehuset #music

🕐︎ - 2024-11-03
The band in silhoutte

I caught the third in a row sold out Trentemøller concert in Pumpehuset, Copenhagen last night.

I was not that familiar with the music, but it was nevertheless an enjoyable concert - if you get the chance, go see them!

.... and don't let the name of the new album "Dreamweaver" fool you - it's not about Macromedia and late 90s shoddy web-technology, as far as I can tell!

RacketCon 14: Keynote presentation #programming #emacs

🕧︎ - 2024-11-03
Abelson & Sussman

The keynote presentation at RacketCon 14 was given by Hal Abelson and Gerald Sussman of "Structure and Interpretation of Computer Programs"-fame - often the book is just referred to as "SICP", which turned 40 this year.

(I'm sort of ashamed to admit that I never read it, but hey.)

During the questions after the keynote speeches I picked up a set of quotes about Emacs from Sussman:

"If I was starting again, I'm gonna say something nasty, if I was starting again, making the software for SICM, I would probably be using Julia."

"Which is basically a Scheme, with a syntax. I hate syntax, I'd rather use Lisp syntax. But I'd be using Julia, since it's even better at numerical chrunching on very, very large scales."

Another snapshot of Abelson and Sussman from the lecture

"Racket is a wonderful thing, but it has one problem for me. It doesn't play well with my most famous and favourite interface in the world, which is Emacs."

"By contrast, I know it does have an Emacs interface, but when I have tried it, it doesn't play well with Emacs. And I live in Emacs. I hardly touch a computer to do anything else than Emacs."

"The real thing I love is Emacs."

Statler & Waldorf at the keyboard

The lectures were given remotely, which gave a couple of fun moments reminding me of the Statler & Waldorf Muppet Show videos.

The video ends with a nice surprise gift for the two presenters and authors - check it out - with Abelson telling the surprise party that they are in the middle of a lecture, but do come in and say hello to everybody at the conference.

Lille langebro

Wednesday

The wedding of Mary Donaldson and Prince Frederik of Denmark (21).

Saturday

WorldWideWeb (34).

Sunday

Per Rossing (63).

Andita dwi Meirna (48).

Riot in Copenhagen; Police shoots directly at people; 11 wounded (32).

Stig Pedersen (60).

Walther Frederiksen (105).

2025-05-19

Flemming Quist Møller (83).

libera.chat (4).

2025-05-20

World Bee Day (12).

2025-05-21

Jacob Bunk Nielsen (46).

2025-05-22

Richard Wagner (212).

World Biodiversity Day (25).

2025-05-23

Carl von Linné (318).

Bonnie and Clyde killed (91).

2025-05-24

Gabriel Daniel Fahrenheit (339).

Queen Victoria (206).

Bob Dylan (84).

2025-05-25

Jazz trumpeter Miles Davis (99).

Towel day.

2025-05-26

Kong Frederik (57).

2025-05-28

John Berchtold (42).

Mathias Rust lands on the Red Square (38).

2025-05-29

Bob Hope (122).

2025-05-31

Clint Eastwood (95).

World Smokefree Day (38).