Automatically Append Text to Existing tiddler Content Upon Editing

258 views
Skip to first unread message

MHill

unread,
Jun 7, 2011, 3:25:46 PM6/7/11
to TiddlyWiki
I am hoping someone can tell me how to achieve the following behavior
in Tiddlywiki:

When I click the Edit link on a tiddler that already contains some
content, a couple of newlines and '[current date/time]: ' are
automatically appended in the edit box before I begin typing.

For example, if an existing tiddler contains the following text:

"This is the first comment."

clicking edit would open the edit box containing the following:

"This it the first comment.

[2011-06-07 1:30 PM]: "

and the edit cursor would be positioned at the end of the original +
automatically added text.

Also, if the tiddler does not yet contain any text, the same would
happen with the exception of the 2 newline characters.

Thanks.

Eric Shulman

unread,
Jun 7, 2011, 7:21:06 PM6/7/11
to TiddlyWiki
> a couple of newlines and '[current date/time]: ' are
> automatically appended in the edit box before I begin typing.

While not exactly as you describe, you might try either of these:

http://www.TiddlyTools.com/#CommentPlugin
http://www.TiddlyTools.com/#CommentPluginInfo

http://www.TiddlyTools.com/#QuickNotePlugin
http://www.TiddlyTools.com/#QuickNotePluginInfo

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios
----------
Was this answer useful? If so, please help support TiddlyTools:

TiddlyTools direct contributions: (paypal)
http://www.TiddlyTools.com/#Donate
UnaMesa tax-deductible contributions:
http://about.unamesa.org/Participate (paypal)
TiddlyWiki consulting:
http://www.TiddlyTools.com/#ELSDesignStudios
http://www.TiddlyTools.com/#Contact

MHill

unread,
Jun 8, 2011, 2:05:04 PM6/8/11
to TiddlyWiki
Thanks Eric, but, as you said, not exactly what I'm looking for. I'm
new to Tiddlywiki, so I'm not even sure if this type of automatic
behavior can be provided by a plugin. Perhaps I need to just edit the
script code within my TW HTML file?

On Jun 7, 6:21 pm, Eric Shulman <elsdes...@gmail.com> wrote:
> > a couple of newlines and '[current date/time]: ' are
> > automatically appended in the edit box before I begin typing.
>
> While not exactly as you describe, you might try either of these:
>
> http://www.TiddlyTools.com/#CommentPluginhttp://www.TiddlyTools.com/#CommentPluginInfo
>
> http://www.TiddlyTools.com/#QuickNotePluginhttp://www.TiddlyTools.com/#QuickNotePluginInfo

PMario

unread,
Jun 9, 2011, 3:29:49 AM6/9/11
to TiddlyWiki
On Jun 8, 8:05 pm, MHill <b.martin.h...@gmail.com> wrote:
> Thanks Eric, but, as you said, not exactly what I'm looking for. I'm
> new to Tiddlywiki, so I'm not even sure if this type of automatic
> behavior can be provided by a plugin. ...
Allmost anything can be done with plugins and TW. But at the moment
there is no plugin (I know of) that does what you describe.

> ... Perhaps I need to just edit the
> script code within my TW HTML file?
You shouldn't directly edit the HTML file. TW has its own plugin
system. Plugins are also tiddlers, with a special tag "systemConfig".
They are initialized by the TW core at startup.

Digging into TW leads to, HTML, JavaScript and CSS. If you are
familiar with these topics it will be possible to point you into the
right directions.

If not, it would help, to just describe your usecase a little bit more
in detail. May be there is allready an existing plugin, that could be
used, or easily adjusted :)

-m

MHill

unread,
Jun 9, 2011, 11:45:23 AM6/9/11
to TiddlyWiki
Thanks for the comments PMario. There's really not anything more to my
use case than what I put in my original post. I am familiar with HTML/
JS/CSS, but my issue (at the moment at least) is having the time to
create a plugin that behaves as I would like. Perhaps I could use the
default tiddler code as a baseline, tweak it, and call it a new
plugin. I would just need to change the tiddler code to automatically
append the desired text (i.e., '[date/time]: ') to the existing
content when it goes into edit mode.

axs

unread,
Jun 9, 2011, 12:36:54 PM6/9/11
to tiddl...@googlegroups.com
Hi MHill,

The following code will do what you want (except that the time is in a 24-hr format) for the case of editing an existing tiddler:


config.commands.editTiddler.handler_old = config.commands.editTiddler.handler;
config.commands.editTiddler.handler = function(evt,src,title){
config.commands.editTiddler.handler_old.call(this,evt,src,title);
var text = jQuery(story.getTiddler(title)).find('textarea[edit=text]');
var leadingNewline = text.val() ? '\n\n' : '' ;
text.val(text.val() + leadingNewline + '[' + (new Date().formatString('YYYY-0MM-0DD hh:mm')) + '] ');
}


Put that in a tiddler, name it whatever you want, and tag it with 'systemConfig'. Restart TW and edit.

Regards,
axs

PMario

unread,
Jun 9, 2011, 3:13:03 PM6/9/11
to TiddlyWiki
axs,
cool hack :)

On Jun 9, 6:36 pm, axs <alexst...@gmail.com> wrote:
> Hi MHill,
>
> The following code will do what you want (except that the time is in a 24-hr
> format) for the case of editing an existing tiddler:
DateFormats are described here
http://tiddlywiki.tiddlyspace.com/#%5B%5BDate%20Formats%5D%5D

> config.commands.editTiddler.handler_old =
> config.commands.editTiddler.handler;
> config.commands.editTiddler.handler = function(evt,src,title){
> config.commands.editTiddler.handler_old.call(this,evt,src,title);
> var text = jQuery(story.getTiddler(title)).find('textarea[edit=text]');
> var leadingNewline = text.val() ? '\n\n' : '' ;
> text.val(text.val() + leadingNewline + '[' + (new
> Date().formatString('YYYY-0MM-0DD hh:mm')) + '] ');
> }
Seems to work. But there are some little problems.
If you have a TW, that is "readOnly" eg: If it is stored on a server,
the editTiddler command is treated as a "view" command by the TW core.
See "view" at TW site [1].

But if editTiddler command is hijacked with the above function "view"
will still add the Date.
If a user now copy/pastes the content it will be something different,
than the original. Which IMO will be very confusing.

Using some parts from above, I created an AddNowCommand [2], which can
be added to the ToolbarCommands tiddler of your TW.
If you need a new tiddler with Date and time use the
<<newTiddler ....>> macro seen at [3]

I did some basic testing with TiddlySpace and hoster. Vanilla TW will
need testing :)

have fun!
mario

[1] http://www.tiddlywiki.com/
[2] http://hoster.peermore.com/recipes/TeamWork/tiddlers.wiki#AddNowCommand
[3] http://hoster.peermore.com/recipes/TeamWork/tiddlers.wiki#%5b%5bNewTiddler%20with%20DateAndTime%5d%5d

axs

unread,
Jun 9, 2011, 4:50:17 PM6/9/11
to tiddl...@googlegroups.com
Good catch, PMario. and nice plugin. I never use my TW's in readonly mode, so I didn't even think of that. I'll update my code with your improvements, in case someone wants to have this work with the regular edit command:


config.commands.editTiddler.handler_old = config.commands.editTiddler.handler;
config.commands.editTiddler.handler = function(evt,src,title){
config.commands.editTiddler.handler_old.call(this,evt,src,title);
var tiddlerElem = story.getTiddler(title);

if(!readOnly && !!~jQuery(tiddlerElem).attr('tags').indexOf('systemConfig') ){ return; }

var text = jQuery(tiddlerElem).find('textarea[edit=text]');
var leadingNewline = text.val() ? '\n\n' : '' ;
text.val(text.val() + leadingNewline + '[' + (new Date().formatString('YYYY-0MM-0DD hh:mm')) + '] ');
}


There may be other issues that come out in actual use. I'll try to address them in this thread if anyone uses this code.

Regards,
axs

Alex Hough

unread,
Jun 9, 2011, 5:26:43 PM6/9/11
to tiddl...@googlegroups.com
It's a good idea...
I find my self using tiddlers a bit like this, just adding stuff at
the top, editing the good stuff up from the bottom.

thanks Mario and asx

best wishes

ALex

> --
> You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
> To post to this group, send email to tiddl...@googlegroups.com.
> To unsubscribe from this group, send email to tiddlywiki+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/tiddlywiki?hl=en.
>
>

MHill

unread,
Jun 9, 2011, 6:32:38 PM6/9/11
to TiddlyWiki
Thanks axs! Works like a charm for me since I too don't anticipate
using TW in readonly mode. Maybe you should publish your work as a new
plugin for others to use too.

And thanks to Mario for the date format link. I used it to tweak
things to my liking.

HansBKK

unread,
Jun 9, 2011, 11:58:54 PM6/9/11
to TiddlyWiki
Just to put in my two cents regarding the idea of "hotkeys"
manipulating applications and "hotstrings" (like your timestamp). I
apologize in advance for straying from the purpose of the list, but
thought this might be helpful.

I prefer implementing these at the level of the OS rather than inside
a given app. The advantage of course is that I have the same
datestamps and timestamps (and any other commonly used boilerplate
hotstrings) available across all my applications.

I didn't see if you mentioned your platform, but if it's windoze, I
highly recommend AutoHotKey.

Here's the relevant bits from my "hotstrings.ahk", which I have set to
always active in the background. To use any of the strings, I just
type e.g. "ids" and press ids followed by tab or enter and get
"2011-06-10", idts gives me "2011-06-10T10:48+7", dth is:
10:49 Friday, 10 June, 2011 - Hans Henderson - ha...@pobox.com

====================
;date/time-stamp + HH
::dth::
FormatTime, TimeString, YYYYMMDDHH24MISS, HH:mm dddd, d MMMM, yyyy
SendInput, %TimeString% - Hans Henderson - ha...@pobox.com
return

;date/time-stamp
::dts::
FormatTime, TimeString, YYYYMMDDHH24MISS, HH:mm dddd, d MMMM, yyyy
SendInput, %TimeString%
return

;date-stamp (human-readable)
::ds::
FormatTime, TimeString, YYYYMMDD, dddd, d MMMM, yyyy
SendInput, %TimeString%
return

;time-stamp (human-readable)
::ts::
FormatTime, TimeString, HHmm, HH:mm
SendInput, %TimeString%
return

;ISO date-stamp
::ids::
FormatTime, TimeString, YYYYMMDD, yyyy-MM-dd
SendInput, %TimeString%
return

;ISO date/time-stamp
::idts::
FormatTime, TimeString, YYYYMMDDHH24MISS, yyyy-MM-ddTHH:mm
SendInput, %TimeString%{+}7
return
==================================

And a link to a relevant spot in the AHK docs:

http://www.autohotkey.com/docs/Hotstrings.htm

PMario

unread,
Jun 10, 2011, 3:59:44 AM6/10/11
to TiddlyWiki
Hi Alex,
I also like to add newer stuff on top of a text.
I'll try to make the "addNow" command configurable and add some more
documentation :)
-m
Message has been deleted

Tobias Beer

unread,
Jun 10, 2011, 5:39:31 AM6/10/11
to TiddlyWiki
There you go, a quick-shot called AppendOnEditPlugin...

http://pastebin.com/VxE2G0GS

Cheers, Tobias.

PMario

unread,
Jun 10, 2011, 12:06:18 PM6/10/11
to TiddlyWiki
@Alex,

Try the newes version now.
Older Versions can be accessed via "revisions" tab.

http://hoster.peermore.com/recipes/TeamWork/tiddlers.wiki#AddNowCommand

have fun!
Feedback is very welcome !!
-m

PMario

unread,
Jun 10, 2011, 12:09:16 PM6/10/11
to TiddlyWiki
accidentally addNow also works in edit mode now :)
-m

Alex Hough

unread,
Jun 10, 2011, 3:36:08 PM6/10/11
to tiddl...@googlegroups.com
@Mario

I will check it out.
I have a slice of non-tiddly time (~TiddlyTime) to get though over the
next few days :(

Alex

On 10 June 2011 17:09, PMario <pmar...@gmail.com> wrote:
> accidentally addNow also works in edit mode now :)
> -m
>

Reply all
Reply to author
Forward
0 new messages