Formatting widgets

88 views
Skip to first unread message

Joe Armstrong

unread,
Jan 10, 2019, 4:22:51 AM1/10/19
to TiddlyWiki
I've been trying to format widget code in a way that (to my eye) is remotely readable:


This was my starting point (this code is taken from the comments plugin) and is in a single tiddler
<$set name="username" value={{$:/status/UserName}} emptyValue="(anonymous)">
<$set name="target" filter="[<currentTiddler>]">
<$action-createtiddler $basetitle={{{ [[Comment by ']addsuffix<username>addsuffix[' on ']addsuffix<currentTiddler>addsuffix[']] }}} role="comment" list=<<target>> text="" edit-mode="yes"/>
</$set>
</$set>
The filter is all one line which makes it very difficult to read and print.

Following a suggestion from Jeremy I changed this to:

<$set name="username" value={{$:/status/UserName}} emptyValue="(anonymous)">
<$set name="target" filter="[<currentTiddler>]">
<$action-createtiddler 
    $basetitle={{{ [[Comment by ']] +[addsuffix<username>] +[addsuffix[' on ' ]] +[addsuffix<currentTiddler>] +[addsuffix[']] }}} 
      role="comment" list=<<target>> text="" edit-mode="yes"/>
</$set>
</$set>

And this worked - the filter is still on one line but it is slightly more readable - I looked up the reference
for filters and whitespace includes newlines so I tried this:

<$set name="username" 
           value={{$:/status/UserName}} 
           emptyValue="(anonymous)">
  <$set name="target" 
             filter="[<currentTiddler>]">
    <$action-createtiddler 
        $basetitle={{{ [[Comment by ']] 
                                +[addsuffix<username>] 
                                +[addsuffix[' on ' ]] 
                                +[addsuffix<currentTiddler>] 
                                +[addsuffix[']] }}} 
        role="comment"
        list=<<target>> 
        text="" 
        edit-mode="yes"/>
    </$set>
</$set>

But this does not work - so what's gone wrong? can't I have newlines in filters

This page says I can


Can anybody suggest a formatting that works and that would look nice in
a printed media.

Cheers

/Joe



TonyM

unread,
Jan 10, 2019, 5:15:25 AM1/10/19
to TiddlyWiki
Joe,

Newlines in filters do not work, however if you passed fieldname="value" pairs to the create new tiddler action you could use newlines. That is do not use the triple curly braces. You may need more set widgets, but it would read better.

Alternatively you could define the filter in a (global) macro and place it in the create tiddler using the subfilter operator, after all you may want to use it more than once.

You could even move set widgets to macros if they define reusable variables, this would provide a tiddler of sharable settings and much simpler new tiddler code.

That should give you multiple avenues to write readable self documenting code.

I assume you are wrapping this in a trigger widget such as a button?

Regards
Tony

Joe Armstrong

unread,
Jan 10, 2019, 5:54:36 AM1/10/19
to TiddlyWiki


On Thursday, 10 January 2019 11:15:25 UTC+1, TonyM wrote:
Joe,

Newlines in filters do not work, however if you passed fieldname="value" pairs to the create new tiddler action you could use newlines. That is do not use the triple curly braces. You may need more set widgets, but it would read better.


Precisely - I have discovered this.

BUT The documentation says whitespace IS permitted


And I believed it,

(aside) since no working program would have used linefeeds adding them now should not break backwards
compatibility, but I'm no expert here
(/aside)

Now this not what the code does (which I have discovered through experimentation)

So either:

     1) the code is correct - and the documentation is buggy OR
     2) the documentation is correct and the code is buggy OR
     3) both are incorrect

As a point of principle I strongly believe 1) - why? - because the TW is a mature program.
Beginners (like me) read the documentation and believe it.

If I write according to the documentation it is my expectation that it should work according to the documentation.

Exactly this happened in the development of Erlang. The code and documentation differed.

In the beginning, code won and documentation lagged behind.

Later, when Erlang was mature I wrote a book and decided "the book is definitive" - if the behaviour
of the system differs from the book then the behaviour is wrong and it's a bug in the code.

I would like to see this change happening in the TW - remember a lot of potential users sill silently
give up when they fail to do something and will not shout their heads off like me.

It basically boils down to "who do you believe" the code or the documentation.

In a new system it's the code - in a mature system it's the documentation.

Getting both to agree is a long and painful process - so I don't underestimate the difficulty.

Been there done that - wrote the code - wrote the book :-)

Cheers

/Joe

Joe Armstrong

unread,
Jan 10, 2019, 5:59:37 AM1/10/19
to TiddlyWiki


On Thursday, 10 January 2019 11:15:25 UTC+1, TonyM wrote:
Joe,

Newlines in filters do not work, however if you passed fieldname="value" pairs to the create new tiddler action you could use newlines. That is do not use the triple curly braces. You may need more set widgets, but it would read better.

Alternatively you could define the filter in a (global) macro and place it in the create tiddler using the subfilter operator, after all you may want to use it more than once.

You could even move set widgets to macros if they define reusable variables, this would provide a tiddler of sharable settings and much simpler new tiddler code.

That should give you multiple avenues to write readable self documenting code.


It's the formatting of the code in printed media that concerns me.

I would actually like to see how these different ways of making a control would look on
paper - right now I think a lot of the code is pretty difficult to read - a bit of color coding and
indentation would help a lot to see the structure.
 

I assume you are wrapping this in a trigger widget such as a button?


Yes

I'm just trying to re-implement the comment plugin in as clear a way as possible (to my eye)
I'm just for the moment disregarding css and layout issues. 

It's just part of learning.

Regards
Tony

TonyM

unread,
Jan 10, 2019, 7:07:53 AM1/10/19
to TiddlyWiki
Always Learning yes,

I understand where you are coming from. In its defence the whitespace means something in filters, so I think for documentation line feeds and leading spaces should be ignored in the filter, not continue to act as broken whitespace. 

Perhaps you should request the documentation be fixed and non spaces get "eaten", including leading spaces on a line (so each item can be indented)

Regards
Tony

Joe Armstrong

unread,
Jan 10, 2019, 7:24:42 AM1/10/19
to TiddlyWiki
I was brought up on punched cards (80 cols) of which 9 were rarely used - so for me
lines longer than 71 characters are a big no no - and I do like the free use of
white space and newlines to encourage readable formatting.

71 character code also prints well in books and papers.

So writing filters become an art form (if I want them to be less than 71 characters) :-)

/Joe

TonyM

unread,
Jan 10, 2019, 7:31:10 AM1/10/19
to TiddlyWiki
Joe,

I first studied Cobol on in such a row format, but there is compelling reasons for clear code layout with any language.

Especially now that many compilers, interpreted and other systems eg html and CSS can mini-fy the source code to reduce its size for "deployment".

tony

Jeremy Ruston

unread,
Jan 10, 2019, 9:32:14 AM1/10/19
to tiddl...@googlegroups.com
Hi Joe

<$set name="username" 
           value={{$:/status/UserName}} 
           emptyValue="(anonymous)">
  <$set name="target" 
             filter="[<currentTiddler>]">
    <$action-createtiddler 
        $basetitle={{{ [[Comment by ']] 
                                +[addsuffix<username>] 
                                +[addsuffix[' on ' ]] 
                                +[addsuffix<currentTiddler>] 
                                +[addsuffix[']] }}} 
        role="comment"
        list=<<target>> 
        text="" 
        edit-mode="yes"/>
    </$set>
</$set>

But this does not work - so what's gone wrong? can't I have newlines in filters

Filters *do* allow newlines; the problem here is that the filtered attribute syntax doesn't permit newlines. The distinction sounds subtle, but you can see other examples of filters that do permit newlines: for example, $:/DefaultTiddlers can accommodate newlines between tiddler titles.

I think we can fix this without impairing backwards compatibility, and I've created a ticket here:


Best wishes

Jeremy



This page says I can


Can anybody suggest a formatting that works and that would look nice in
a printed media.

Cheers

/Joe



--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/d5ce8e72-1165-41b9-b398-b6f6becec82d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages