What does "counter: 0" mean in utop?

And when will it get incremented?

I googled but I didn’t get an explanation.


Gotta love Open Source Software for prominently surfacing information <1% of users even understand!

Had to search through the code in GitHub to figure this out, but I got it now.

Utop has a lot of shortcuts for power users built in which you can learn about by typing #utop_bindings;; and pressing enter. One of them is a macro system; a system for recording and playing back keystrokes. If you’ve never used one of these before, it’s sort of like copy and paste but instead of just letters it allows you to repeat shortcuts and stuff too. For example, if you just got done manually typing in a long array of integers but realized you forgot to type the semicolons between the numbers, you can record yourself pressing the shortcut to skip back one word, then typing the missing semicolon, then moving the cursor to before the semicolon, and then play back that recording as many times as you need, saving yourself a few keypresses.

The idea behind the counter is that sometimes you don’t want to do exactly the same thing for each playback; maybe on the first playback you want to type 20 somewhere, but on the next playback you want to type 21 instead, then on the next after that you want to type 22. That’s where the counter comes in.

You can press C-x C-k C-c to set the counter to any integer, then C-x C-k tab to insert the current value of the counter and increment it by 1. That way, if you want to type in a list that goes from 1 to 100, all you need to do is type in

C-x C-k C-c 1 enter [ C-x ( C-x C-k tab; C-x )

and then press C-x e 99 times! Then ], of course.

It’s a really niche feature and it’s very silly that it’s so prominent, but now you know.


Looks like some utop developer had a really persistent itch they had to scratch!

1 Like

What a detailed explanation! :clap:

This style of key bindings makes me suspect they were taken from Emacs… And it is true. Emacs uses the same key bindings, even has a very similar macro counter system. See Emacs documentation. Note that C-i is just another way to input TAB.

Bonus: I also discover that you can switch to a less-distracting prompt in utop via the command #utop_prompt_dummy;; or #utop_prompt_simple;;.


Another bonus:

  • You can set utop to use simple prompt by default in ~/.config/utop/init.ml.
  • You can enable syntax highlighting in utop in ~/.utoprc (not get why the developers choose to use a separate config file)

See the manual page of utop and utoprc.

man utop
man utoprc