Archiving Cancelled Items

Being new to scripting and plug-ins, I am having problems setting up something to archive my cancelled items, I want them to go into a specific Cancelled header section (like Archive done). I looked at Jesse’s archive done code and tried to copy it into a new main.js for a plug-in but it does not work. Do I need to do something else in addition to main.js?

Many thanks.

// MB Testing cancelled items
define(function(require, exports, module) {
	'use strict';

	var Extensions = require('ft/core/extensions').Extensions;

		name: 'archive @cancelled',
		description: 'Move @cancelled items to its own header section.',
		performCommand: function (editor, options) {
			var tree = editor.tree();


			var archiveNode = tree.evaluateNodePath("//@line:text = cancelled")[0];
			if (!archiveNode) {
				archiveNode = createArchiveNode(tree);

			Node.commonAncestorsForNodes(tree.evaluateNodePath("//@cancelled except //@line:text = Archive//@cancelled")).forEachNodeInSet(function(node) {
				archiveNode.insertChildBefore(node, archiveNode.firstChild);


The first goal is for your .ftplugin to show up (without error messages) in FoldingText > Plug-In Manager ( ⌘, )

To go to that stage, you need to add a package.json file to the .ftplugin folder which you have created.

(see file:///Applications/

( FoldingText > Help > Software Development Kit > Documentation )

Yes, I did do that already but I don’t have a Github presence as homepage, just a generic site which is not being used, is that important? No errors when looking at plugin but it doesn’t do what I want (the tagged cancelled items just stay where they are) which is why I assumed there was something else missing.

I think the key may be that the section of Jesse’s todomode.js which you are copying uses some functions whose definitions you haven’t included:

function createArchiveNode() is defined before your excision,

and similarly using Node.commonAncestorsForNodes() depends on the
Node = require('ft/core/node').Node, in Jesse’s variable declarations.

(both towards the top of the page)

Your script is unable to evaluate calls to those functions because it doesn’t yet have access to their definitions.

For a more simply customisable approach, you could look at the script below, and perhaps uncomment the line:

-- property precOptions : {archivetags:{"cancelled"}}

If you want to bypass the menu and make it work only with @cancelled tags.

This is great, thanks, it works a treat!

I can’t get the plugin to work yet, guess I need to understand how to run a debug, I’ll have a go :smile:

Fixed it, typo as it was case sensitive and I had tagged with @Cancelled and not @cancelled :wink:

(I still can’t work out how to run a debug calling the plugin with text but am working on it).

Debugging with text:

  • Fire up the SDK version of the editor and paste some text into it,
  • place a debugger; statement somewhere in the code,
  • launch the code (either with a plugin keystroke, or, in the case of an applescript, by replacing the word evaluate with debug).