# How can I create a tiddler that keeps track of recently closed tiddlers

Hi, I’m working on a tiddler that I’d like to put in the siebar that shows the last N tiddlers I’ve closed (the number N is any reasonable number. To simplify the question I’ll use 3 here).
I apologize if what I wrote seems long but I thought I’d explain in detail to avoid misunderstandings

How it would work:

1. I create a button similar to $:/core/ui/Buttons/close (you could also override it, but I prefer not) which has the exact same code except for two new actions it performs when closing the tiddler: • an $action-setfield which gives the name of the tiddler just closed to a field as a value
• another $action-setfield witch updates a value on a counter (and here I am having difficulty) 2. Another tiddler, the one I’m changing the fields to, (and the one I’m going to put in the SideBar) shows the titles of the last closed tiddlers as links, taking them from its fields. For now I accomplish this in this way: <$link to={{RecentlyClosed!!slot_1}}/><br>
<$link to={{RecentlyClosed!!slot_2}}/><br> <$link to={{RecentlyClosed!!slot_3}}/><br>


Btw I’m planning to make the list change order based on the counter, so to have the most recendly closed tiddler on the top and the least recently closed at the bottom. (although I have no idea how to do it, but one thing at a time)

So, here’s what happens:

1. - I click the custom button to close the tiddler

2. - the button as well as closing the tiddler performs these actions:

Assign-slot > The title of the tiddler closed is stored a field of the tiddler “RecentlyClosed” (the default field is “slot_1” because the default value of the counter field is “slot_1”)

\define Assign-slot()
<$action-setfield$tiddler="RecentlyClosed" $field={{RecentlyClosed!!counter}}$value={{!!title}}/>
\end


Update-slot > In order to store more titles, the next field (slot) that will hold the next title needs to be upgraded, so the “counter” field needs to be modified

\define Update-slot()
<$action-setfield$tiddler="RecentlyClosed" $field="counter"$value=???slot_2???/>
\end


Not knowing what to put as value I put some “???” in the code above.

But what this counter is supposed to do is:

• If its own value = “slot_1”, replace it with “slot_2”

• If its own value = “slot_2”, replace it with “slot_3”

• If its own value is different from “slot_1” and “slot_2”, replace it with “slot_1”
(in this way I take into account both “slot_3” and any possible error in the value of the field)

(It can also be done with more than 3 slots, the progression is simple.)

1. - Now that the title is stored and the counter field points to a different field, I can store titles up to the number N that I have chosen, to then be able to start the cycle again.

I think I should (maybe) use a filter operators so to use if-then-else logic, but I don’t know how to express what I wrote above (and I don’t know how to insert it instead of the ??? in the $value= of the Update-slot) How can I make this “counter” work? (or rather, the Update-slot) I think it is better to use a JSON or dictionary tiddler ( e.g. data tiddler). When a tiddler closed write the tiddler name as key and the time as value In the sidebar just show the JSON tiddler sorted by value (date) in reverse order! You can limit the number of key/values and when exceeded some max number, remove the oldest one! See the proof of concept in the next post. 1 Like This is a proof of concept 1. download RecentlyClosed.json (1.7 KB) 2. drag and drop into https://tiddlywiki.com 3. Open some tiddlers and try close them with new blue close button 4. In sidebar open Recently Closed tab The current solution only keeps the last 5 closed tiddler. Change the number as you like. 3 Likes I had read your first answer just before you posted the second one, and I was afraid that your solution might not work if timestamps were kept off (which I do). But now that I’ve tried the JSON you gave me, I find that it works wonderfully. You didn’t answer my question, but you did something better, you gave me a solution to the underlying problem. Thank you Mohammad! Edit: I've changed the title to something pertinent, now that my question no longer needs an answer. So if in the future someone finds this topic they will find what they are looking for better To use this in your work, I would recommend 1. move the local style I added in close02 to a stylesheet tiddler 2. hide the core close button from$:/ControlPanel → Appearance → Toolbars
3. use variables instead of hardcoded name for state tiddler

I think if I was doing this, I’d use a simple list field in a tiddler (e.g. Recently Closed) that just retains the last 3 closed tiddlers.

I think if I was doing this, I’d take the same approach as @Mohammad. Very good stuff.

There is another approach and that has being discussed before, get access to the history in $:/HistoryList install this on tiddlywiki.com and look at the history tab. • It still needs work because both original and drafts are listed which can cause version issues. • The history list is only since the last time the wiki was loaded. • It includes buttons direct to edit, close in story, copy tiddler title and change count. history-sidebar.json (2.8 KB) Imitation is the sincerest form of flattery? Still using your / @Mohammad’s button in the above package I created Open_Closed.json (795 Bytes) a variation on the side bar tab, with the following additional features; • Hide recently closed items now currently open •  Don’t list items now deleted • Save up to 50 recently closed tiddlers • Provide a range slider to limit the items listed • Provide a direct edit icon on items listed • Transclude the Open list below the closed items, One place to visit Possible futures • Use the All button Actions solution to add actions to buttons; • The default close button • The Close all Button • When closing from the Open list - Perhaps a message catcher on tm-close-* messages? • An Open all recently closed button to match the close all button for open tiddlers. • Extend to widows opened and closed (With target set/remembered) 2 Likes There is a way to flip upside down the list of closed tiddlers? (So to have the most recently closed on the top and the least recently closed at the bottom) In a filter you can use the reverse operator reverse[] ? Thanks for the answer TW_Tones (and your version of Recently Closed - Open/Closed, I tried it and really liked it!) I was able to reverse the list, but sadly not the slder which is found in your version, witch I started using (it’s very convenient). Which I believe is the most useful thing to reverse. Because right now if I reduce the number of tiddlers that can be displayed by the slider, only the least recently closed ones remain, while it would be convenient if only the most recently closed ones remained visible. Is there a way to do this? @Matteo I missed that, it is more intuitive the way you want. This order was dictated by @Mohammad’s list filter on the$:/state/recently-closed data tiddler.

The following filter seems to resolve this;
filter="[<rc-state>indexes[]has[title]] :sort:reverse[<rc-state>getindex<currentTiddler>] -[list<tv-story-list>] +[reverse[]]+[limit{Open/Closed!!limit}]"

• The reverse is before the limit
• My solution only adds  +[reverse[]] +[limit{Open/Closed!!limit}]
2 Likes