Skip to content

Commit bdb01a4

Browse files
ndemiancclaude
andcommitted
Atom++ M3: user init script (Atom-style hackability)
New extensions/atom-hackability/ — runs ~/.atom-plus-plus/init.js at startup with a small `atompp` convenience API (registerCommand, addStatusBarItem, onDidSave/Open, showMessage, getConfig, log — all auto-disposed on reload) plus the full `vscode` API and a file-scoped require. Live-reloadable via "Atom++: Reload Init Script" (no restart); "Atom++: Open Init Script" creates a commented template. Errors are caught and surfaced to an output channel so a broken init never breaks startup. Gated by atompp.init.enabled. Docs: note atom-hackability in CLAUDE.md layout; record init script under M3 in PLAN.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent f394679 commit bdb01a4

4 files changed

Lines changed: 191 additions & 1 deletion

File tree

‎CLAUDE.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ branding/icons/ app icon source PNG, generated .icns, 1024 png
3636
extensions/atom-npp-pack/ Notepad++ power-editing pack (plain JS, no build step)
3737
extensions/atom-ai/ native Claude AI (chat, inline completion, providers, edit-with-diff, LM provider)
3838
extensions/atom-themes/ signature One Dark / One Light themes (JSON, default via configurationDefaults)
39+
extensions/atom-hackability/ user init script (~/.atom-plus-plus/init.js) — runs your code at startup, live-reloadable
3940
patches/atom-core.patch our core source edits, applied on bootstrap
4041
scripts/ bootstrap.sh, apply-branding.mjs, run-dev.sh, build-macos.sh, make-dmg.sh, make-icon.sh
4142
vscode/ GITIGNORED upstream Code-OSS checkout (generated)

‎PLAN.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Build the Notepad++ Pack: macro record/replay, big-file mode, encoding/EOL contr
9898
Provider abstraction + BYO-key (Claude first), inline completions, codebase chat, accept/reject AI diffs. Direct-to-provider, no backend. *Exit test: tab-complete a function, ask the chat about your repo, refactor a file via AI diff — using your own API key.* Shipped: right-sidebar chat (opens by default), Codex-style composer with typewriter streaming, inline ghost-text completion, multi-file pinning + automatic ripgrep-based context retrieval, native LM provider.
9999

100100
**M3 — Hackability + Atom feel. — 🚧 IN PROGRESS**
101-
Settings UI, user init script, package generator + hot reload, theme studio, One Dark-derived default theme, VS Code/Atom settings import. *Exit test: import your current VS Code setup, write a tiny package, restyle a color live.* Done so far: **Atom++ One Dark / One Light** themes (`extensions/atom-themes/`), built from Atom's MIT palette and set as the default.
101+
Settings UI, user init script, package generator + hot reload, theme studio, One Dark-derived default theme, VS Code/Atom settings import. *Exit test: import your current VS Code setup, write a tiny package, restyle a color live.* Done so far: **Atom++ One Dark / One Light** themes (`extensions/atom-themes/`), built from Atom's MIT palette and set as the default; **user init script** (`extensions/atom-hackability/`) — `~/.atom-plus-plus/init.js` runs your code at startup with an `atompp` API + full `vscode`, live-reloadable without restart.
102102

103103
**M4 — Agentic AI + Mac polish + release prep.**
104104
Agentic multi-file tasks with approval gates; native menus, traffic-light polish, cold-start optimization; auto-update channel; final name + original logo + trademark check; first public/personal release. *Exit test: give it a multi-file goal and approve its plan; the app feels native and updates itself.*
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Atom++ — Hackability (M3, feature 1: user init script)
3+
*
4+
* Atom's signature "run my own code when the editor starts" hook. On startup we load
5+
* ~/.atom-plus-plus/init.js and run it with a small `atompp` convenience API plus the full
6+
* `vscode` API in scope. It is live-reloadable ("Atom++: Reload Init Script") — no restart.
7+
*
8+
* This runs the user's OWN file from their home directory (exactly like Atom). It is not
9+
* fetched or remote; errors are caught and surfaced so a broken init never breaks startup.
10+
*--------------------------------------------------------------------------------------------*/
11+
// @ts-check
12+
'use strict';
13+
14+
const vscode = require('vscode');
15+
const os = require('os');
16+
const fs = require('fs');
17+
const path = require('path');
18+
const { createRequire } = require('module');
19+
20+
const INIT_DIR = path.join(os.homedir(), '.atom-plus-plus');
21+
const INIT_PATH = path.join(INIT_DIR, 'init.js');
22+
23+
/** @type {vscode.OutputChannel} */
24+
let output;
25+
/** Disposables created by the *current* run of the init script (cleared on reload). */
26+
let userDisposables = [];
27+
28+
const TEMPLATE = `// Atom++ — User Init Script
29+
// This file runs every time Atom++ starts. Edit it, then run
30+
// "Atom++: Reload Init Script" from the Command Palette (no restart needed).
31+
//
32+
// Two things are in scope:
33+
// • atompp — a small convenience API (everything you register is auto-cleaned on reload)
34+
// • vscode — the full VS Code extension API (the escape hatch for anything else)
35+
//
36+
// Uncomment an example to try it, then reload:
37+
38+
// 1. A custom item in the status bar:
39+
// atompp.addStatusBarItem('🚀 init.js', 'Added from my init script');
40+
41+
// 2. A custom command (run it from the Command Palette):
42+
// atompp.registerCommand('myinit.hello', () => {
43+
// atompp.showMessage('Hello from your init script!');
44+
// });
45+
46+
// 3. React to saving a file:
47+
// atompp.onDidSave(doc => console.log('Saved:', doc.fileName));
48+
49+
// 4. Anything in the raw VS Code API:
50+
// vscode.window.showInformationMessage('Atom++ init script loaded.');
51+
`;
52+
53+
/** Build the friendly Atom++ API handed to the init script. Returns { api, subs }. */
54+
function makeApi() {
55+
/** @type {vscode.Disposable[]} */
56+
const subs = [];
57+
const track = (d) => { if (d && typeof d.dispose === 'function') { subs.push(d); } return d; };
58+
const api = {
59+
version: '0.1.0',
60+
/** The full VS Code API. */
61+
vscode,
62+
/** Disposables registered here are cleaned up automatically on the next reload. */
63+
subscriptions: subs,
64+
registerCommand: (id, fn) => track(vscode.commands.registerCommand(id, fn)),
65+
onDidSave: (fn) => track(vscode.workspace.onDidSaveTextDocument(fn)),
66+
onDidOpen: (fn) => track(vscode.workspace.onDidOpenTextDocument(fn)),
67+
onDidChangeEditor: (fn) => track(vscode.window.onDidChangeActiveTextEditor(fn)),
68+
addStatusBarItem: (text, tooltip, command) => {
69+
const item = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 0);
70+
item.text = String(text);
71+
if (tooltip) { item.tooltip = String(tooltip); }
72+
if (command) { item.command = command; }
73+
item.show();
74+
subs.push(item);
75+
return item;
76+
},
77+
showMessage: (m) => vscode.window.showInformationMessage(String(m)),
78+
showError: (m) => vscode.window.showErrorMessage(String(m)),
79+
getConfig: (section) => vscode.workspace.getConfiguration(section),
80+
log: (...args) => { output.appendLine(args.map((a) => (typeof a === 'string' ? a : JSON.stringify(a))).join(' ')); }
81+
};
82+
return { api, subs };
83+
}
84+
85+
/** Dispose everything the previous run created. */
86+
function disposeUser() {
87+
for (const d of userDisposables) { try { d.dispose(); } catch { /* ignore */ } }
88+
userDisposables = [];
89+
}
90+
91+
/**
92+
* Load and execute the init script. Returns true if it ran, false if skipped/missing.
93+
* @param {boolean} interactive Whether to surface success/errors to the user (vs silent on startup).
94+
*/
95+
function runInit(interactive) {
96+
if (!vscode.workspace.getConfiguration('atompp').get('init.enabled', true)) { return false; }
97+
if (!fs.existsSync(INIT_PATH)) {
98+
if (interactive) { vscode.window.showInformationMessage('Atom++: no init script yet. Use “Atom++: Open Init Script” to create one.'); }
99+
return false;
100+
}
101+
102+
disposeUser();
103+
let code;
104+
try { code = fs.readFileSync(INIT_PATH, 'utf8'); }
105+
catch (e) { output.appendLine('[init] could not read ' + INIT_PATH + ': ' + e); return false; }
106+
107+
const { api, subs } = makeApi();
108+
const initRequire = createRequire(INIT_PATH); // so the script can require() its own local/global modules
109+
try {
110+
// Run the user's code with atompp/vscode/require/console in scope.
111+
const fn = new Function('atompp', 'vscode', 'require', 'console', '__dirname', '__filename', code);
112+
fn(api, vscode, initRequire, console, INIT_DIR, INIT_PATH);
113+
userDisposables = subs;
114+
output.appendLine('[init] ran ' + INIT_PATH + ' (' + subs.length + ' disposable(s) registered)');
115+
if (interactive) { vscode.window.setStatusBarMessage('Atom++ init script reloaded', 2000); }
116+
return true;
117+
} catch (e) {
118+
const msg = (e && e.stack) ? e.stack : String(e);
119+
output.appendLine('[init] ERROR running init.js:\n' + msg);
120+
const pick = 'Show Log';
121+
vscode.window.showErrorMessage('Atom++ init script failed: ' + ((e && e.message) || e), pick)
122+
.then((c) => { if (c === pick) { output.show(true); } });
123+
return false;
124+
}
125+
}
126+
127+
async function openInit() {
128+
try {
129+
if (!fs.existsSync(INIT_DIR)) { fs.mkdirSync(INIT_DIR, { recursive: true }); }
130+
if (!fs.existsSync(INIT_PATH)) { fs.writeFileSync(INIT_PATH, TEMPLATE, 'utf8'); }
131+
} catch (e) {
132+
vscode.window.showErrorMessage('Atom++: could not create init script: ' + ((e && e.message) || e));
133+
return;
134+
}
135+
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(INIT_PATH));
136+
await vscode.window.showTextDocument(doc);
137+
}
138+
139+
function activate(context) {
140+
output = vscode.window.createOutputChannel('Atom++ Init');
141+
context.subscriptions.push(
142+
output,
143+
vscode.commands.registerCommand('atompp.init.edit', openInit),
144+
vscode.commands.registerCommand('atompp.init.reload', () => runInit(true)),
145+
{ dispose: disposeUser }
146+
);
147+
runInit(false);
148+
}
149+
150+
function deactivate() { disposeUser(); }
151+
152+
module.exports = { activate, deactivate };
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "atom-hackability",
3+
"displayName": "Atom++ Hackability",
4+
"description": "Atom-style hackability for Atom++ — a user init script that runs your own code at startup.",
5+
"publisher": "atompp",
6+
"version": "0.1.0",
7+
"license": "MIT",
8+
"engines": {
9+
"vscode": "^1.126.0"
10+
},
11+
"categories": [
12+
"Other"
13+
],
14+
"capabilities": {
15+
"untrustedWorkspaces": { "supported": true }
16+
},
17+
"activationEvents": [
18+
"onStartupFinished"
19+
],
20+
"main": "./extension.js",
21+
"contributes": {
22+
"commands": [
23+
{ "command": "atompp.init.edit", "title": "Open Init Script", "category": "Atom++" },
24+
{ "command": "atompp.init.reload", "title": "Reload Init Script", "category": "Atom++" }
25+
],
26+
"configuration": {
27+
"title": "Atom++ Hackability",
28+
"properties": {
29+
"atompp.init.enabled": {
30+
"type": "boolean",
31+
"default": true,
32+
"description": "Run your user init script (~/.atom-plus-plus/init.js) when Atom++ starts."
33+
}
34+
}
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)