reddit / emacs

Interactive development of `(interactive)` functions? (specifically for`org-export-define-backend`)

m518xt · 2022-09-22 02:24
I 'm trying to work on an export backend for org - starting with the [write up](https://www.reddit.com/r/emacs/comments/swvbmm/you_want_to_write_a_custom_org_backend_lets_write/) from u/tonyaldon In particular I'm trying to export tables, so I need to build `table`, `table-row` and `table-cell` functionality. However, I'm not sure what the best way to interactively explore the functions and their arguments. To run my function I (naturally) open my sample org file and `M-x myfunc RET`. Currently I'm using `(message ...)`\-type lines, but printing values doesn't feel very *lispy*. Is there a better way to develop these sort of backends/interactive functions using the REPL functionality of `ielm` (or something else?)
ieure · 2022-09-22 03:38
There are several tools you might find useful. ielm is honestly great, and might be the simplest to apply to your situation. In an ielm buffer, you can hit `C-c C-b` to set the working buffer -- that's the one which all exprs entered into ielm get evaluted in the context of. So you can do that to make an Org buffer your working one, and invoke your core with `(my/command arg arg...)`, or whatever you like. And you get history, and can examine what it evaluates to in ielm. [ERT](https://www.gnu.org/software/emacs/manual/html_mono/ert.html) is another option, and would be useful if you require enough setup or fixtures to warrant making that stuff programmatic. Last, and far from least, there's [edebug](https://www.gnu.org/software/emacs/manual/html_node/elisp/Edebug.html), Emacs' built-in single-stepping source debugger. It's drop dead simple to use: find the function to step through, and press `C-u C-M-x` with point in it. Next time it's called, you'll get dropped into the debugger, where `n` or `SPC` will eval the form at point and show the result in the echo area.
arthurno1 · 2022-09-22 12:01
You can use edebug instead of printing values with message. It will make your life easier. See shortcuts for edebug in the manual.
m518xt · 2022-09-23 06:14
Thanks for this. Doesn't get me all the way, but a definite up-vote earner just for highlighting `C-c C-b`! edebug was another great reminder.
m518xt · 2022-09-23 06:16
Great suggestion. Thanks.
deaddyfreddy · 2022-09-26 17:28
> Currently I'm using (message ...)-type lines, but printing values doesn't feel very lispy. `(defvar my-global-name some-local-argument-or-binding)`, the only drawback is it litters the global namespace, so be careful to not redefine something not related to your code