[neomutt-devel] Expandos not Strings

Richard Russon rich at flatcap.org
Mon Mar 25 13:11:07 CET 2024


Hi devs!

The very early adopters among you, may have noticed some new code that landed in `main`.
All the config format strings have become Expandos -- a new config type.
e.g. `$index_format`, `$attribution_intro`

Many thanks to Tóth János (@g0mb4) for his six months' of dedication to make this happen.

## The Past

Historically, these format strings had a lot of problems.

- They're not validated
  You can set `$index_format` to anything you like.
  You'll never see an error message.

- Parsed every time they're used
  If you have 50 lines in your Index, `$index_format` will be parsed 50 times.
  There's no way to any errors, so they're just ignored.

- Massive duplication of formatting code
  Each one of the >200 expandos has to do its own formatting.

- Rely on enormous callback functions
  The callbacks are some of the largest functions in NeoMutt.
  `index_format_str()` is 1085 lines.

- Untestable
  Even simple format strings have too many dependencies to be tested.

- Not extendable
  Expandos are all of the form %X (with a few exceptions).
  Many of the letters match their meaning, but so many don't.
  Plus, for complicated format strings like `$index_format` we're running out of letters.

## The Present

We have a new config type: Expando.

For a technical overview, see: https://github.com/neomutt/neomutt/pull/4202

- They've validated
  Syntax errors, or expandos that don't exist will be reported.

- Parsed once
  The format string is parsed into a tree of Expando Nodes.
  The renderer takes this tree and populates it with data.

- Centralised formatting code
  The render function asks for some data and formats it, itself.

- Small callback functions
  Each callback is responsible for getting one piece of data.

- Testable (unit tests)
  The parsing code is thoroughly tested.
  The render code is tested.

- Extendable
  The Expando definitions are easily extendable.
  They already include long names, e.g. `%l` is equivalent to `%{lines}`
  (This will be implemented soon)


It's a LOT of new code.
If you find any problems, please let me know as soon as possible.

Cheers,
    FlatCap / Rich
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://mailman.neomutt.org/pipermail/neomutt-devel-neomutt.org/attachments/20240325/cd4b4785/attachment.sig>


More information about the neomutt-devel mailing list