RSSAmplifier

Blog

zck.org

The personal site of Zachary Kanfer.

zck.orgRSS feed ↗29 posts

Latest posts

Less: a Survival Guide

I noticed recently that I was having trouble moving around in less . I could arrow up and down, but that took a lot of work. I could hit space to go a whole screen down, but unlike in a web browser, shift-space also scrolls down. How could I scroll up a screen? On some terminals, Page Up and Page Down work, but not in others. It's a confusing mess. So, after years and years of using less , I…

Formuladle!

New year, new Numberdle variant! Ladle out some soup with Formuladle !

Factordle!

Didn't like Rationerdle, but still want a number-focused variant of Wordle? Well, try Factordle !

Numberdle!

Like Wordle, but prefer numbers to words? Well, check out my new game, Rationerdle !

Easily repeat Emacs functions: a repeat post

"Winning takes talent, to repeat takes character." – John Wooden Remember Emacs's transient maps? I posted about them all the way back in 2016 . Transient maps temporarily add a keymap that is active only for a single keypress. It enables things like repeating commands, or making a set of similar commands easier to call one after another. Well, times have changed. In 2022, Emacs 28.1 was…

Announcing caser.el, a package to camelCase, dash-case, and snake_case text

Now announcing the v0.1 release of caser.el! This package contains functions to change text from camelCase to dash-case to snake_case and back. Caser.el supports any language Emacs does. It is tested on English, Icelandic, German, and Korean. A more full description is found at its repository , and can be installed from Melpa . Its current build status is .

Automatially Balance Your Emacs Windows

Emacs windows easily get unbalanced. After calling split-window-right twice, there are three windows. Rather than being all the same size, two of them take up a quarter of the frame each, and the third is half as big as the frame. Or, if there are already three equally-sized windows, closing one window leaves one of the remaining windows twice as big as the other. To me, that's unbalanced. I want…

An Improved Emacs Search

Emacs's incremental search is very powerful. Rather than wait to show results until the search query is completely typed, it immediately begins searching once the first character is typed, updating the search as more letters are pressed. This makes it very responsive, and provides answers immediately. But not everything is great about it. By default, the incremental search doesn't provide any…

Nix Development Shells

I recently wanted to develop some Emacs code. But I didn't want to do the work of finding all the different dependencies needed to install them. I'm running NixOS, so luckily, there is a command for that. nix develop nixpkgs#emacs nix develop will open a shell with all the dependencies needed to develop that package. This is a flake-based command, so I believe it needs to be building a flake. As…

Simple tricks with Imagemagick

Imagemagick is a powerful tool to manipulate images on the command line. It can do things like add a border, crop an image, or convert an image from one format to another. But because it has so many features, it's difficult to figure out how to do the thing you want to do. Here are some things I've done with it, for my own reference. Maybe it's useful to you too. Most of these examples use this…

Re-move files in Emacs

Back in 2016, I wrote an Emacs function to move files in Emacs. After my work agreed to sign the employer disclaimer , I'm able to contribute to Emacs again. So I did. After some discussion, the function was accepted into Emacs. There were a few changes, including renaming it to rename-visited-file . If you build Emacs from source, the function is now in the Emacs git repository. If you don't…

Testing buffer-modifying Emacs code (again)

There are no straight lines in nature. - Antoni Gaudí I previously published an article about testing buffer-modifying code: functions whose behavior is not encapsulated by their return value, like upcase-word or isearch-forward . Instead, they are called to modify the current buffer. We might want to test upcase-word as follows. (should (equal (with-temp-buffer (insert "hi there") (goto-char…

Change Emacs's Default Behavior

People say you should leave Emacs's defaults unchanged. Emacs is unbelievably customizable. Nearly any key can be changed. But there's advice given to rely on the defaults; they have been honed over years and years to be the best for everyone. I disagree. What's best for everyone might not be best for you. For example, C-z minimizes the Emacs frame. But I've never used it on purpose. I'd hit it by…

Have Emacs questions? Ask emacs!

Anyone who works with Emacs has many questions about it. I've been using Emacs for over fifteen years. Packages I've created have over 50,000 downloads, I've presented at EmacsConf 2020, and I co-organize EmacsNYC. Over all this time learning about Emacs, I've had a lot of questions. It turns out that the best place to ask questions about Emacs…is Emacs! Here's five ways to ask Emacs questions.…

Magic Strings

One piece of programming advice is that one shouldn't use numbers in code unless they're stored in a variable or constant . Using a number as a bare value – often called a "magic number" – gives no context as to why that number is being used. totalWidth = getSize() + 272; Why 272 ? Why not 113 ? Instead, one is encouraged to use constants. final int WINDOW_PADDING = 272;totalWidth =…

Hide Emacs's Customize

If you don't actively use Emacs's customize functionality, it can be frustating when Emacs changes the custom-set-variables block in your init file. For example, when version controlling your init file, you have to skip over these diffs. So, instead of letting customize make changes to your init file, we can redirect it elsewhere. (setq custom-file "~/.emacs.d/custom.el")(when (file-exists-p…

Fixing Firefox 89's right-click menu on macOS

Firefox 89 changed right-click functionality on macOS. Previously, in a right click menu, typing a letter triggered an option in the menu. For example, rightclicking on a link and pressing t would open the link in a new tab. But with the June 1 release , that is no longer the case. Now, pressing a letter highlights a menu item, but does not trigger it. It even highlights a different menu item from…

Easy Quil screenshots

When I started making generative art, I was excited to share the art I made. I took screenshots and manually cropped them to only the part of the desktop containing the art. As you might imagine, this process was completely foolproof , not to mention quick and easy. No, wait. It was error-prone, boring and repetitive. But computers can do boring repetitive tasks for us! And whenever my computer…

!!Con 2021: Making Music! In Emacs?!

I presented Making Music! In Emacs!? at !!Con 2021 . If you enjoyed this talk, you might appreciate EmacsNYC , a meetup I co-organize. Abstract During quarantine, I found myself spending time with an Android app. One of the features this app has is composing looping music. As with many programs, I wondered how much better this feature would be, if only it was inside Emacs. This talk explains how I…

Use vectors in your generative art

Quil is a great library to make generative art with. As might be expected for a library that allows for points to be graphed, many functions expect one or more points to be passed to it. For example, point , vertex , and triangle all take these x and y values. Quad even takes a whopping eight values, representing four points! Working this way, it's easy to do simple things. Most code I've seen…

EmacsConf 2020 talk: WAVEing at Repetitive Repetitive Repetitive Music

I presented WAVEing at Repetitive Repetitive Repetitive Music at EmacsConf 2020 . Video can be found at this EmacsConf page . If you enjoyed my talk, you might appreciate EmacsNYC , a meetup I co-organize. Abstract During quarantine, I found myself spending time with an Android app. One of the features this app has is composing music that loops endlessly. As with many things, I wondered how much…

Reduce your Emacs config (by contributing it upstream)

One programming aphorism is that the less code you have, the fewer places there are for bugs to hide. Bill Gates is quoted as saying "Measuring programming progress by lines of code is like measuring aircraft building progress by weight". So when solving a given problem, it's better to have less code. But wait! Even my Emacs config is over 1400 lines! That's a lot of places bugs could be…

An open letter to the two gentlemen wearing MAGA hats at the women's march

To the two gentlemen wearing Make America Great Again hats at the women's march: Hi. We met at the Women's March in NYC. When I first saw you, you were in a heated discussion about abortion. It seemed out-of-place, so I went up to talk to you, wanting both to see why you were there and to keep the situation from escalating. After talking to you, I don't understand your reasons for coming, as your…

Testing Emacs code that modifies buffers

2022 Update : I have since made an improved version of the code in this article. This article is still useful to read as motivation for the problem. I was writing some functions to change variable names from camelCase to snake_case , and back again. (For some reason, Java code uses camelCase , and SQL colmns are named with snake_case ) Because this was nontrivial code, I wanted to test it. If the…

Presenting zpresent, a presentation framework for Emacs

Once in a while, I give a presentation. Not too often. You probably do give more than I do. It's not a competition. Presentations are a pain to make. "Traditional" presentation software requires you to simultaneously create content and determine its layout. So when you're thinking about how to phrase your seventeenth slide about the proper kind of switch to use in your mechanical keyboard Cherry…

Move files in Emacs

Emacs's default way to write a file to a different location is #'write-file . This function saves the buffer to a new location, but leaves the old file where it was. But sometimes we want to move a file, so the old file is gone! There are two built-in functions with similar purpose. #'rename-file #'dired-do-rename Neither of these are great for this use case. The existing functions don't default…

Easily repeat Emacs functions

Sometimes you want to repeat an Emacs function, even when calling it originally took a few keystrokes. Here's how to make it easily repeatable. Say we have a simple function that inserts "here": (defun insert-here () (interactive) (insert "here")) And bind it to C-c h h : (global-set-key (kbd "C-c h h") #'insert-here) This works; every time we type C-c h h , we insert "here" into the buffer. But…

balanced delimiters

This week's Coding for Interviews newsletter, as usual, included a challenge. This week's was to parse a string, determining whether all the delimiters (parentheses, curly, and square braces) it contains are balanced. For example, the string Math.min(3, 7) is balanced, while Math.min(3, )) is not. Since I'm a big fan of Lisp, I'm writing my solution in Arc , a modern Lisp. As we all know, Lisp has…

Winning the #008000 jacket: code golf

My job recently had a code golf challenge: the shortest code wins. The task was to write k-means : take a set of data and reduce it to k points. There are many algorithms to do this, but the specific algorithm for this challenge was to, until you had few enough data points, find the two closest points and merge them. First, my winning 227-character entry: (def d(p q)(apply +(map(fn(m n)(expt(- m…