lifelike / decide-mode

Random decisions for emacs, with functions and a minor mode. Roll various types of dice etc.
49 stars 12 forks source link

Allow for configurable reporting #9

Closed dustinlacewell closed 2 weeks ago

dustinlacewell commented 6 years ago

Currently the output of rolls is inserted into the buffer. It would be nice if the reporting mechanism was configurable. A simple defvar taking a function that accepts the result should suffice, but I'm open to other ideas.

lifelike commented 6 years ago

The heuristics now is to put in mini buffer if the buffer is read-only, otherwise insert in buffer. It shiuld be possible to expand that to allow a custom function instead yes, and some options for how to format some results could be useful.

lifelike commented 5 years ago

I have been thinking more about this, and my current working theory is that it would be nice to configure this per major-mode. Put an alist there with some modes and what default function to use, and then have some variable the user can set to override the default either in some mode or globally.

lifelike commented 2 months ago

5+ years later... This is what I am planning to implement (and try out a bit on some branch before pushing for real): A buffer-local variable decide-format-output. If it is set to a string it is used as the format string, and can use %1$s and %2$s to refer to "what is being generated" and "the result". If it is set to a function it will be passed those two strings and the function can do whatever it want and then return a string to be printed.

I had some more ideas, but I think this design will support most cases, and it makes it easy to configure it for different major-modes or even individual buffers.

Mostly this is because I realized in some org-mode buffers I want to just have the result printed, and that will be solved by just setting decide-format-output to "%2$s" for those buffers; or maybe something like "%2$s" to add a bit of styling to the output. But it can be good to have the ability to use a function for more advanced cases.

lifelike commented 2 weeks ago

In 0.10.0 this can be configured using decide-format-output.