TiddlyWiki5 icon indicating copy to clipboard operation
TiddlyWiki5 copied to clipboard

Empty Define breaks subsequent macros

Open AnthonyMuscio opened this issue 5 years ago • 11 comments

If in a tiddler one does this

\define empty-macro() \define valid-macro() any content \define multi-line-macro() Content of valid macro \end

The empty-macro will cause the remainder of the tiddlers macro definitions not be recognised.

This is hard to debug, so could we fix the "fault" caused by empty macros?

Thanks Tony

AnthonyMuscio avatar Jun 25 '19 03:06 AnthonyMuscio

You are right. The empty-macro() is not recognized in the right way. The parse-tree looks like this:

[
    {
        "type": "set",
        "attributes": {
            "name": {
                "type": "string",
                "value": "empty-macro"
            },
            "value": {
                "type": "string",
                "value": "\\define valid-macro() any content\n\n\\define multi-line-macro()\nContent of valid macro"
            }
        },

pmario avatar Jun 25 '19 08:06 pmario

If you add a character "." to the empty-macro it works as expected.

\define empty-macro() . 
\define valid-macro() any content
\define multi-line-macro()
Content of valid macro
\end
[
    {
        "type": "set",
        "attributes": {
            "name": {
                "type": "string",
                "value": "empty-macro"
            },
            "value": {
                "type": "string",
                "value": "."
            }
        },

pmario avatar Jun 25 '19 08:06 pmario

What's the purpose of the empty-macro?

pmario avatar Jun 25 '19 08:06 pmario

The empty macro is never something I intended to do but it has happened a few times as I have tried to build more complex macros. When macros are used as variables I try and define them so they can be referenced inside another macro but sometimes I slip up.

It would never be a problem if it was not so easy to overlook and the symptoms quite odd.

It would just be nice if it failed more gracefully if not with a message.

Regards Tony

AnthonyMuscio avatar Jun 25 '19 09:06 AnthonyMuscio

The empty macro is never something I intended to do but it has happened a few times as I have tried to build more complex macros.

Yes, this happens to me too. I think it is a matter of personality (scattered multi-tasking vs focussed).

twMat avatar Jun 25 '19 13:06 twMat

duplicate of: Bug: empty macro definitions don't parse as expected #3460

pmario avatar Dec 09 '23 22:12 pmario

Close in favour of the duplicate #3460 but I hope it is addressed. Another use case is coding with the output preview displayed. In some cases this can give invalid values and generate list of all tiddlers and other time consuming artifacts.

AnthonyMuscio avatar Dec 13 '23 06:12 AnthonyMuscio

This seems like a different issue than #3460. I created a PR for it at #7911 and it does not address this issue.

To me, the OP looks like a set of valid nested macros:

\define empty-macro()
\define valid-macro() any content
\define multi-line-macro()
Content of valid macro
\end

How can the above be distinguished from nested macros (empty-macro is the outer macro terminated by the \end)?

btheado avatar Dec 27 '23 03:12 btheado

I believe the rule is to nest "macros" you need to name the outer macros in the \end

Your example does not use this suggested approach, but still works. but possibly not in all cases.

  • You don't have an empty macro, you have a parent macro.
\define empty-macro()
\define valid-macro() any content
\define multi-line-macro()
Content of valid macro
\end multi-line-macro
this is not empty it is a parent.
\end empty-macro

<<empty-macro>>
  • In fact you must close the parent macro or and multiline inner macros otherwise it is ambiguous.

However I would also point out you are using the deprecated \define macro not the current \procedure or very useful \function or the new custom \widgets.

Note that this Issue was raised in AnthonyMuscio opened this issue on Jun 25, 2019

  • A few years now.

But the problem remains is still not resolved in two cases;

\define empty-macro()

\end

\define empty-macro()
\end

The above will "break" subsequent macros.

And the same happens with the new \procedures as well.

AnthonyMuscio avatar Dec 27 '23 03:12 AnthonyMuscio

The rule is to nest "macros" you need to name the outer macros in the \end

Your example does not use this suggested approach, but still works. but possibly not in all cases.

  • You don't have an empty macro, you have a parent macro.
\define empty-macro()
\define valid-macro() any content
\define multi-line-macro()
Content of valid macro
\end multi-line-macro
this is not empty it is a parent.
\end empty-macro

<<empty-macro>>
  • In fact you must close the parent macro or and multipline inner macros otherwise it is ambiguous.

However I would also point out you are using the deprecated \define macro not the current \procedure or very useful \function or the new custom \widgets.

Note that this Issue was raised in AnthonyMuscio opened this issue on Jun 25, 2019

  • A few years now.

But the reason is still not resolved in two cases;

\define empty-macro()

\end

\define empty-macro()
\end

The above will "break" subsequent macros. including for \procedures

AnthonyMuscio avatar Dec 27 '23 03:12 AnthonyMuscio

Hi @btheado as @AnthonyMuscio says, I think the example in the OP is missing an \end. As far as I can tell it is processed exactly as expected.

But the reason is still not resolved in two cases;

@AnthonyMuscio that's the issue in #3460 which remains unfixed at the moment.

Jermolene avatar Dec 27 '23 14:12 Jermolene