The init file
When Pulsar finishes loading, it will evaluate init.js in your ~/.pulsar %USERPROFILE%\.pulsar directory, giving you a chance to run JavaScript code to make customizations. Code in this file has full access to Pulsar’s API. If customizations become extensive, consider creating a package, which we will cover in Package: Word count.
You can open the init.js file in an editor from the Atom > Init ScriptFile > Init ScriptEdit > Init Script menu.
For example, if you have the Audio Beep configuration setting enabled, you could add the following code to your init.js file to have Pulsar greet you with an audio beep every time it loads:
atom.beep();
Because init.js provides access to Pulsar’s API, you can use it to implement useful commands without creating a new package or extending an existing one. Here’s a command which uses the Selection and Clipboard APIs to construct a Markdown link from the selected text and the clipboard contents as the URL:
atom.commands.add("atom-text-editor", "markdown:paste-as-link", () => {
let clipboardText, editor, selection;
if (!(editor = atom.workspace.getActiveTextEditor())) {
return;
}
selection = editor.getLastSelection();
clipboardText = atom.clipboard.read();
return selection.insertText(
`[${selection.getText()}](${clipboardText})`
);
});
Once you’ve saved your init file and reloaded Pulsar, use the command palette to execute the new command, Markdown: Paste As Link, by name. And if you’d like to trigger the command via a keyboard shortcut, you can define a keybinding for the command.