Skip to content

Commit 9683388

Browse files
committed
Filer 1.6.0 WIP - new unarchive command
1 parent 786b4e6 commit 9683388

5 files changed

Lines changed: 79 additions & 9 deletions

File tree

‎jgclark.Filer/CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# What's changed in 📦 Filer plugin?
22
Please see the [Readme for this plugin](https://github.com/NotePlan/plugins/tree/main/jgclark.Filer) for more details, including the available settings.
33

4+
## [1.6.0] - 2026-05-01
5+
- new **/unarchive note keeping folder structure** command that reverses **/archive note keeping folder structure** by moving a note from `@Archive` back to its original folder path.
6+
47
## [1.5.3] - 2025-03-16
58
- fix: improvements to the **/move completed items to done section** command
69
- dev: added tests for its helper functions

‎jgclark.Filer/README.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ It has some settings, which you review and change by clicking on the '⚙️ Set
55

66
[<img width="200px" alt="Buy Me A Coffee" src="https://www.buymeacoffee.com/assets/img/guidelines/download-assets-sm-2.svg" />](https://www.buymeacoffee.com/revjgc)
77

8+
## /archive note keeping folder structure
9+
This command moves the current project note into NotePlan's special `@Archive` folder while keeping the same folder path under `@Archive`.
10+
11+
For example, `Projects/ClientA/Plan.md` becomes `@Archive/Projects/ClientA/Plan.md`.
12+
13+
## /unarchive note keeping folder structure
14+
This command is the inverse of the above. For example the filename changes from `@Archive/Projects/ClientA/Plan.md` to `Projects/ClientA/Plan.md`.
15+
816
## /move paragraph or selection
917
The **/move paragraph** command (aliased to **/mp** and **/fp**) quickly **files** (moves) lines to different notes in NotePlan, without having to lose your flow by switching to the other note. It works on any sort of lines, not just tasks.
1018

‎jgclark.Filer/plugin.json‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
"plugin.author": "jgclark",
99
"plugin.url": "https://noteplan.co/plugins/jgclark.Filer",
1010
"plugin.changelog": "https://github.com/NotePlan/plugins/blob/main/jgclark.Filer/CHANGELOG.md",
11-
"plugin.version": "1.5.3",
11+
"plugin.version": "1.6.0",
1212
"plugin.releaseStatus": "full",
13-
"plugin.lastUpdateInfo": "1.5.3: Improvements to the 'move completed items to done section' command.\n1.5.2: Allow customising the name of the 'Done' section heading used by the 'move completed items to done section' command. Improvements to the 'move completed items to done section' command.\n1.5.1: Fix 'Add date reference?' option so that when moving from calendar note the added date now correctly points to the source note's date, not always to today.\n1.5.0: New '/move completed items to done section' command that is more powerful than NP's built-in 'Move Completed to Bottom' menu action. It has two settings, which reveal its additional powers: Recreate existing section structure in Done section? (default: true). Only move completed items when whole section is complete? (default: false).\n1.4.1: Fix for /move paras command when moving to a note with a heading with trailing whitespace.\n1.4.0: \"/add sync'd copy to note\" now can work on a block of lines. Further bug fixes for some commands on notes with frontmatter.",
13+
"plugin.lastUpdateInfo": "1.6.0: New '/unarchive note keeping folder structure' command to move a note from @Archive back to its original folder path.\n1.5.3: Improvements to the 'move completed items to done section' command.\n1.5.2: Allow customising the name of the 'Done' section heading used by the 'move completed items to done section' command. Improvements to the 'move completed items to done section' command.\n1.5.1: Fix 'Add date reference?' option so that when moving from calendar note the added date now correctly points to the source note's date, not always to today.\n1.5.0: New '/move completed items to done section' command that is more powerful than NP's built-in 'Move Completed to Bottom' menu action. It has two settings, which reveal its additional powers: Recreate existing section structure in Done section? (default: true). Only move completed items when whole section is complete? (default: false).",
1414
"plugin.dependencies": [],
1515
"plugin.script": "script.js",
1616
"plugin.isRemote": "false",
@@ -34,6 +34,15 @@
3434
"description": "Move the current note to NotePlan's Archive, but keep the same folder structure for it inside the special @Archive folder",
3535
"jsFunction": "archiveNote"
3636
},
37+
{
38+
"name": "unarchive note keeping folder structure",
39+
"alias": [
40+
"uan",
41+
"unarchive"
42+
],
43+
"description": "Move the current note from NotePlan's Archive back to its original folder structure",
44+
"jsFunction": "unarchiveNote"
45+
},
3746
{
3847
"name": "copy note links",
3948
"alias": [

‎jgclark.Filer/src/archive.js‎

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
// ----------------------------------------------------------------------------
33
// Smarter archiving commands, part of Filer plugin
44
// Jonathan Clark
5-
// last updated 2025-09-06 for v1.3.2
5+
// last updated 2026-05-01 for v1.6.0, by @Cursor & @jgclark
66
// ----------------------------------------------------------------------------
77

88
import pluginJson from "../plugin.json"
9-
import { logDebug, logError, logWarn } from '@helpers/dev'
9+
import { clo, JSP, logDebug, logError, logWarn } from '@helpers/dev'
1010
import { displayTitle } from '@helpers/general'
1111
import { archiveNoteUsingFolder } from '@helpers/NPnote'
12+
import { showMessage } from '@helpers/userInput'
1213

1314
//-----------------------------------------------------------------------------
1415

@@ -19,7 +20,7 @@ import { archiveNoteUsingFolder } from '@helpers/NPnote'
1920
* @param {string?} archiveRootFolder optional; if not given, then use the built-in @Archive folder)
2021
* @returns {?string} newFilename, if success
2122
*/
22-
export function archiveNote(noteIn?: TNote, archiveRootFolder?: string): ?string {
23+
export async function archiveNote(noteIn?: TNote, archiveRootFolder?: string): ?string {
2324
try {
2425
let note: TNote | null
2526
if (noteIn && (typeof noteIn === "object")) {
@@ -38,11 +39,60 @@ export function archiveNote(noteIn?: TNote, archiveRootFolder?: string): ?string
3839
logDebug('archiveNote', `- Note -> ${newFilename}`)
3940
return newFilename
4041
} else {
41-
throw new Error(`archiveNote(): Failed when archiving '${displayTitle(note)}' to ${archiveRootFolder ?? '@Archive'}`)
42+
const _res = await showMessage(`Failed to move '${displayTitle(note)}' to the Archive. Please see log for details.`, 'OK, thanks', 'Archive Note')
43+
throw new Error(`Failed when archiving '${displayTitle(note)}' to ${archiveRootFolder ?? '@Archive'} folder.`)
4244
}
4345
}
4446
catch (error) {
45-
logError(pluginJson, `archiveNote(): ${error.message}`)
47+
logError(pluginJson, `archiveNote(): ${JSP(error)}`)
48+
return null
49+
}
50+
}
51+
52+
/**
53+
* Unarchive a note by moving it out of the special @Archive folder and restoring
54+
* its original folder path. If no TNote object is passed in, then unarchive
55+
* the note in the open Editor.
56+
* @param {TNote?} noteIn optional; if not given, then use the open Editor's note)
57+
* @returns {?string} newFilename, if success
58+
*/
59+
export async function unarchiveNote(noteIn?: TNote): ?string {
60+
try {
61+
let note: TNote | null
62+
if (noteIn && (typeof noteIn === 'object')) {
63+
// A note was passed in, so use it
64+
note = noteIn
65+
logDebug('unarchiveNote', `Note passed in: ${note.filename}`)
66+
} else {
67+
logDebug(pluginJson, `unarchiveNote(): starting for note open in Editor`)
68+
note = Editor.note ?? null
69+
}
70+
if (!note) {
71+
throw new Error("Couldn't get note, so stopping.")
72+
}
73+
if (note.type === 'Calendar') {
74+
logWarn(pluginJson, 'unarchiveNote(): Cannot unarchive a Calendar note, so stopping.')
75+
return null
76+
}
77+
78+
const currentFilename = note.filename
79+
if (!currentFilename.startsWith('@Archive/')) {
80+
const _res = await showMessage(`'${displayTitle(note)}' is not in the Archive, so cannot unarchive it.`, 'OK, thanks', 'Unarchive Note')
81+
throw new Error(`'${displayTitle(note)}' is not in @Archive, so cannot unarchive it.`)
82+
}
83+
84+
const filenameWithoutArchive = currentFilename.replace(/^@Archive\//, '')
85+
const destinationFolder = filenameWithoutArchive.includes('/') ? filenameWithoutArchive.split('/').slice(0, -1).join('/') : ''
86+
const newFilename = DataStore.moveNote(currentFilename, destinationFolder)
87+
if (newFilename) {
88+
logDebug('unarchiveNote', `- Note -> ${newFilename}`)
89+
return newFilename
90+
} else {
91+
throw new Error(`unarchiveNote(): Failed when unarchiving '${displayTitle(note)}' from @Archive`)
92+
}
93+
}
94+
catch (error) {
95+
logError(pluginJson, `unarchiveNote(): ${JSP(error)}`)
4696
return null
4797
}
4898
}

‎jgclark.Filer/src/index.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
// -----------------------------------------------------------------------------
44
// Plugin to help move selected pargraphs to other notes
55
// Jonathan Clark
6-
// Last updated 2025-12-16, for v1.5.0
6+
// Last updated 2026-05-01, for v1.6.0, by @Cursor
77
// -----------------------------------------------------------------------------
88

99
import pluginJson from '../plugin.json' // allow changes in plugin.json to trigger recompilation
1010
import { JSP, logDebug, logInfo, logError, logWarn, timer } from "@helpers/dev"
1111
import { editSettings } from '@helpers/NPSettings'
1212
import { showMessage } from '@helpers/userInput'
1313

14-
export { archiveNote } from './archive'
14+
export { archiveNote, unarchiveNote } from './archive'
1515
export { addIDAndAddToOtherNote } from './IDs'
1616
export { moveCompletedItemsToDoneSectionCommand } from './moveCompletedToDone'
1717
export {

0 commit comments

Comments
 (0)