Access the not-yet-created $action-createtiddler title ?

102 views
Skip to first unread message

Mat

unread,
Jul 1, 2020, 10:36:55 AM7/1/20
to TiddlyWiki
<$action-createtiddler $basetitle="New Tiddler" ... />

gives, for example, "New Tiddler 2" if there is already a "New Tiddler 1" and(!) "New Tiddler 3".

I.e it takes the lowest available number.

How can I tell what this new title or number is before it is created?

It "feels" like there should be some ready made mechanism, kind of like the qualify macro that takes a title and spits out a hypothetical next title. Presumably there is such a mechanism inside the action-createtiddler widget.

Thanks!

<:-)

Mark S.

unread,
Jul 1, 2020, 11:10:32 AM7/1/20
to TiddlyWiki
AFAIK, you can only get the title after it's been made. Which makes sense.

Why do you need it in advance?

Different ideas

* Make an routine that creates the new tiddler,  displays the name, and deletes the tiddler -- now you know what the tiddler would do
* Make a routine that adds or increments a number. Harder to do, because we don't really have good regexp splitting tools. Ah-hem.
* Use a routine that generates a guaranteed-to-be-unique name (e.g. datestamp) and use that for the basetitle.

Mat

unread,
Jul 1, 2020, 11:46:19 AM7/1/20
to tiddl...@googlegroups.com
Thanks for replying Mark. 

This is for EditorMagic (which will get a public status update later today. It's getting good but still has big problems) and it would be neat if the two tools therein that rely on what I'm asking about in the OP here would work properly.

Here's the idea, albeit simplified:

As anyone, understandably, have forgotten by now, EditorMagic is a set of tools in the editor. Among these, there should be a possibility to create another, new, tiddler - directly from within the current editor - and and have that new tiddler be transcluded into the current one. The title for the new tiddler is by default "current tiddler N" (like with "New Tiddler N"). I.e if the current tiddler is titled Foo, then what should end up in the current tiddlers text is {{Foo 1}}..

So, here's my current (flawed) solution. Imagine that it is an EditViewTemplate, i.e accessible in edit mode:

<$edit-text tiddler="temp" />

<$button>
  Insert as transclusion
  <$action-createtiddler  $basetitle=<
<currentTiddler>>  text={{temp}} />
  <$wikify name=newest-tid
    text={{{ [prefix
<currentTiddler>!sort[created]first[]] }}}
  >
    <$action-setfield
       $tiddler=<
<currentTiddler>>
       text=<
<some macro call to wrap Newest-tid in transclusion braces. This is not the problem.>> />
  </$wikify>
  <$action-deletetiddler $tiddler="temp"/>
</$button>

I suspect that the action-createtiddler is not finished by the time that wikify does its thing. So wikify doesn't get the new title, in spite of my hackey filter. If "newest-tid" could instead be named "Foo n" indenpendently of if it exists, then this would be solved because that is the string to insert even if the tiddler doesn't yet exist for another second.

Of course, the real problem might be why action-createtiddler is not finished before the next widget is executed, but I believe that is a known bug or flaw in TW. (Right?)

I'd love to hear if you have better strategy than the above hack. It doesn't have to be perfect, just work, because the goal is to make EditorMagic good enough to convey the concept properly not to have it perfect.

Thanks!

<:-)

Eric Shulman

unread,
Jul 1, 2020, 12:30:36 PM7/1/20
to tiddl...@googlegroups.com
On Wednesday, July 1, 2020 at 8:46:19 AM UTC-7, Mat wrote:
So, here's my current (flawed) solution. Imagine that it is an EditViewTemplate, i.e accessible in edit mode:
<$edit-text tiddler="temp" />
<$button>
  Insert as transclusion
  <$action-createtiddler  $basetitle=<
<currentTiddler>>  text={{temp}} />
  <$wikify name=newest-tid
    text={{{ [prefix
<currentTiddler>!sort[created]first[]] }}}
  >
    <$action-setfield
       $tiddler=<
<currentTiddler>>
       text=<
<some macro call to wrap Newest-tid in transclusion braces. This is not the problem.>> />
  </$wikify>
  <$action-deletetiddler $tiddler="temp"/>
</$button>
I suspect that the action-createtiddler is not finished by the time that wikify does its thing. So wikify doesn't get the new title, in spite of my hackey filter.

There's a little trick that might solve your problem...

Leave the first part (the $action-createtiddler) in the body of the button widget as it is now, but...
move the rest of the actions into an actions="..." parameter.  Like this:
<$edit-text tiddler="temp" /><br>
<$button actions="""
   <$vars transclusion={{{ [prefix<currentTiddler>!sort[created]first[]addprefix[{{]addsuffix[}}]] }}}>
   <$action-setfield $tiddler=<<currentTiddler>> text={{{ [<currentTiddler>get[text]addsuffix<transclusion>] }}}/>
   <$action-deletetiddler $tiddler="temp"/>
   </$vars>
   """>
   Insert as transclusion
   <$action-createtiddler  $basetitle=<<currentTiddler>>  text={{temp}} />
</$button><br>

When the button is pressed, the $action-createtiddler is invoked first and then the actions="..." is fired off separately, after the createtiddler is done.

Put the above code into a tiddler named "MakeTransclusion", then create another tiddler called "MyTiddler" containing:
{{||MakeTransclusion}}

Then, while viewing MyTiddler, enter something into the $edit-text input field and press the button.
This will create "MyTiddler 1" containing the entered text, and append the contents of MyTiddler
with the transclusion {{MyTiddler 1}}.

enjoy,
-e

Saq Imtiaz

unread,
Jul 1, 2020, 12:34:43 PM7/1/20
to TiddlyWiki
Try this. Move the following to a macro and call it via the actions attribute on the button:

<$wikify name=newest-tid
text={{{ [prefix<currentTiddler>!sort[created]first[]] }}}
>
<$action-setfield
$tiddler=<<currentTiddler>>
text=<<some macro call to wrap Newest-tid in transclusion braces. This is not the problem.>> />
</$wikify>

Also are you sure you can't use set/vars instead of wikify?

Saq Imtiaz

unread,
Jul 1, 2020, 12:57:35 PM7/1/20
to TiddlyWiki
Essentially the same thing Eric has recommended. I'm on my phone and didn't see that he had replied.

Eric Shulman

unread,
Jul 1, 2020, 2:25:52 PM7/1/20
to tiddl...@googlegroups.com
Here's an updated version that works as an EditTemplate:

<style>.edit100 { width:100%; }</style>
<$edit-text tiddler="temp" tag="textarea" minHeight="5em" class="edit100"
   default="" placeholder="Enter content to be transcluded" />
<br>
<$button actions="""
   <$vars target={{{ [
<currentTiddler>removeprefix[Draft of ']removesuffix[']] }}}>
   <$vars transclusion={{{ [prefix
<target>!sort[created]first[]addprefix[{{]addsuffix[}}]] }}}>
   <$action-setfield $tiddler=<
<currentTiddler>> text={{{ [<currentTiddler>{!!text}addsuffix<transclusion>] }}}/>

   <$action-deletetiddler $tiddler="temp"/>
   </$vars>
   </$vars>
   """>
   Insert as transclusion
   <$vars target={{{ [
<currentTiddler>removeprefix[Draft of ']removesuffix[']] }}}>
   <$action-createtiddler  $basetitle=<
<target>>  text={{temp}} />
   </$vars>
</$button>

1) Put the above code into a tiddler (e.g., "MakeTransclusion")
2) Tag that tiddler with $:/tags/EditTemplate
3) Add a field named "list-after", with a value of "$:/core/ui/EditTemplate/body"

Notes:
* The "target" variable is the name of the tiddler to create, derived from the current *draft* title (e.g, "Draft of 'SomeTiddler'").
* The "transclusion" variable finds the newest target tiddler and adds the "{{" and "}}" to make the transclusion syntax.
* This is then appended to the current "Draft of 'SomeTiddler'" content.
* I added a little CSS classname to the $edit-text widget so it would use 100% width (and have a minimum height of 5em)
* The "list-after" field puts the textarea input and button following the normal body textarea input.

I've tested this on http://TiddlyWiki.com, and it works.

enjoy,
-e

Mat

unread,
Jul 3, 2020, 1:10:42 PM7/3/20
to TiddlyWiki
Just wanted to say thank you and that I did use this.

A note: Instead of doing:

removeprefix[Draft of ']removesuffix[']

I think it is even better with:

get[draft.of]
 
<:-)

Saq Imtiaz

unread,
Jul 3, 2020, 1:22:21 PM7/3/20
to TiddlyWiki
FYI you can also get the title in advance using the unusedtitle macro. The title it returns will be the same that is used by action-createtiddler if you give both the same basetitle.

<$vars newtitle=<<unusedtitle mybase>> >.....

or <$macrocall $name="unusedtitle" baseName="foo"/>

Mat

unread,
Jul 3, 2020, 2:14:02 PM7/3/20
to TiddlyWiki
[...] the unusedtitle macro.

Aha, there is such a thing after all! Excellent! Thanks Saq!

<:-)

TW Tones

unread,
Jul 3, 2020, 8:24:46 PM7/3/20
to TiddlyWiki
Saq, 

I don't know how I missed that unusedtitle macro.

Of course it returns only one at a time, the same title until the new title is used.

But the truth is any macro that can return a suitable, unique and unused title can be fed into a new tiddler action would prove useful.

I can imagine one that generates titles for "subtiddlers" and those in another namespace.

Regards
Tony


Reply all
Reply to author
Forward
0 new messages