TiddlyWiki / TiddlyWiki5

A self-contained JavaScript wiki for the browser, Node.js, AWS Lambda etc.
https://tiddlywiki.com/
Other
8.08k stars 1.19k forks source link

[IDEA] Add macro operator #8732

Open Leilei332 opened 2 weeks ago

Leilei332 commented 2 weeks ago

The current implementation of using macros in filters isn't good enough:

<$list filter="[<mymacro param:'value'>]">
...
</$list>

It isn't able to use variables or textreference as a parameter of the macro. I think we had better introduce a macro operator so that variables and textreference can be used as parameter (like the function operator). For example

<$list filter="[macro[mymacro],[value]]">
...
</$list>

<$let template="DDth MMM YYYY">
<!-- variables and textreference are allowed -->
{{{ [macro[now],<template>] }}}
{{{ [macro[now],{$:/config/NewJournal/Title}] }}}
</$let>
pmario commented 2 weeks ago

It would be sensible to name it procedure or proc and allow \procedure definitions and may be \defines too.

The most generic way would be transclude[variable],[param1] and so on. But we already have a transcludes operator so this will be very error prone.

Leilei332 commented 2 weeks ago

As is described in docs:

Procedure calls can be used in filters. The text is not wikified which again means that the parameters will be ignored.

So it isn't encouraged to use procedure with parameters in filters. IMO the operator should not support macros or procedures defined in tiddlers, it only makes sense to support javascript macros in filters.

Jermolene commented 2 weeks ago

Hi @Leilei332 might another possibility be to update the existing function operator to be able to work with JS macros? At the moment, [function[now]] is broken.

Leilei332 commented 2 weeks ago

If we decided to extend the function operator to support javascript macros, we need to deal with the conflict of functions defined in tiddlers and javascript macros:

  1. Disallow functions which has the same name as a core javascript macro
  2. Allow overriding javascript macros
Jermolene commented 2 weeks ago

Hi @Leilei332 I guess we already have the same conflict between functions and JS macros when using the <<name>> syntax, so perhaps we can make things consistent.

Leilei332 commented 2 days ago

I think we may add some documention on overriding core javascript macros. (Perhaps the name Javascript macros can be changed to Javascript functions)

Jermolene commented 1 hour ago

Hi @Leilei332 thank you, that is an excellent idea