Skip to content

Commit

Permalink
Added zig support
Browse files Browse the repository at this point in the history
  • Loading branch information
slar authored and Stig Larsson committed Oct 30, 2023
1 parent e3d9184 commit 9cb62d6
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The result is shown only after the execution is finished. It is not possible to
![Video that shows how the plugin works.](https://github.com/twibiral/obsidian-execute-code/blob/master/images/execute_code_example.gif?raw=true)


The following [languages are supported](#supported-programming-languages-): C, CPP, Dart, Golang, Groovy, Kotlin, Java, JavaScript, TypeScript, Lean, Lua, CSharp, Prolog, Rust, Python, R, Ruby, Wolfram Mathematica, Haskell, Scala, Racket, F#, Batch, Shell & Powershell, Octave, and Maxima.
The following [languages are supported](#supported-programming-languages-): C, CPP, Dart, Golang, Groovy, Kotlin, Java, JavaScript, TypeScript, Lean, Lua, CSharp, Prolog, Rust, Python, R, Ruby, Wolfram Mathematica, Haskell, Scala, Racket, F#, Batch, Shell & Powershell, Octave, Maxima and Zig.


Python, Rust, and Octave support embedded plots. All languages support ["magic" commands](#magic-commands-) that help you to access paths in obsidian or show images in your notes.
Expand Down
8 changes: 7 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import runAllCodeBlocks from './runAllCodeBlocks';
export const languageAliases = ["javascript", "typescript", "bash", "csharp", "wolfram", "nb", "wl", "hs", "py", "scpt"] as const;
export const canonicalLanguages = ["js", "ts", "cs", "lean", "lua", "python", "cpp", "prolog", "shell", "groovy", "r",
"go", "rust", "java", "powershell", "kotlin", "mathematica", "haskell", "scala", "racket", "fsharp", "c", "dart",
"ruby", "batch", "sql", "octave", "maxima", "applescript"] as const;
"ruby", "batch", "sql", "octave", "maxima", "applescript", "zig"] as const;
export const supportedLanguages = [...languageAliases, ...canonicalLanguages] as const;
export type LanguageId = typeof canonicalLanguages[number];

Expand Down Expand Up @@ -397,6 +397,12 @@ export default class ExecuteCodePlugin extends Plugin {
const transformedCode = await new CodeInjector(this.app, this.settings, language).injectCode(srcCode);
this.runCodeInShell(transformedCode, out, button, this.settings.applescriptPath, this.settings.applescriptArgs, this.settings.applescriptFileExtension, language, file);
})
} else if (language === "zig") {
button.addEventListener("click", async () => {
button.className = runButtonDisabledClass;
const transformedCode = await new CodeInjector(this.app, this.settings, language).injectCode(srcCode);
this.runCodeInShell(transformedCode, out, button, this.settings.zigPath, this.settings.zigArgs, "zig", language, file);
})
}

}
Expand Down
8 changes: 8 additions & 0 deletions src/settings/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ export interface ExecutorSettings {
applescriptArgs: string;
applescriptFileExtension: string;
applescriptInject: string;
zigPath: string;
zigArgs: string;
zigInject: string;

jsInteractive: boolean;
tsInteractive: boolean;
Expand Down Expand Up @@ -158,6 +161,7 @@ export interface ExecutorSettings {
octaveInteractive: boolean;
maximaInteractive: boolean;
applescriptInteractive: boolean;
zigInteractive: boolean;
}


Expand Down Expand Up @@ -288,6 +292,9 @@ export const DEFAULT_SETTINGS: ExecutorSettings = {
applescriptArgs: "",
applescriptFileExtension: "scpt",
applescriptInject: "",
zigPath: "zig",
zigArgs: "run",
zigInject: "",
jsInteractive: true,
tsInteractive: false,
csInteractive: false,
Expand Down Expand Up @@ -318,4 +325,5 @@ export const DEFAULT_SETTINGS: ExecutorSettings = {
octaveInteractive: false,
maximaInteractive: false,
applescriptInteractive: false,
zigInteractive: false,
}
4 changes: 4 additions & 0 deletions src/settings/SettingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import makeSQLSettings from "./per-lang/makeSQLSettings";
import makeOctaviaSettings from "./per-lang/makeOctaveSettings";
import makeMaximaSettings from "./per-lang/makeMaximaSettings";
import makeApplescriptSettings from "./per-lang/makeApplescriptSettings";
import makeZigSettings from "./per-lang/makeZigSettings";


/**
Expand Down Expand Up @@ -207,6 +208,9 @@ export class SettingsTab extends PluginSettingTab {
// ========== Applescript ============
makeApplescriptSettings(this, this.makeContainerFor("applescript"));

// ========== Zig ============
makeZigSettings(this, this.makeContainerFor("zig"));

this.focusContainer(this.plugin.settings.lastOpenLanguageTab || canonicalLanguages[0]);
}

Expand Down
1 change: 1 addition & 0 deletions src/settings/languageDisplayName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ export const DISPLAY_NAMES: Record<LanguageId, string> = {
octave: "Octave",
maxima: "Maxima",
applescript: "Applescript",
zig: "Zig",
} as const;
27 changes: 27 additions & 0 deletions src/settings/per-lang/makeZigSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Setting } from "obsidian";
import { SettingsTab } from "../SettingsTab";

export default (tab: SettingsTab, containerEl: HTMLElement) => {
containerEl.createEl('h3', { text: 'Zig Settings' });
new Setting(containerEl)
.setName('zig path')
.setDesc("Path to your zig installation")
.addText(text => text
.setValue(tab.plugin.settings.zigPath)
.onChange(async (value) => {
const sanitized = tab.sanitizePath(value);
tab.plugin.settings.zigPath = sanitized;
console.log('zig path set to: ' + sanitized);
await tab.plugin.saveSettings();
}));
new Setting(containerEl)
.setName('zig arguments')
.addText(text => text
.setValue(tab.plugin.settings.zigArgs)
.onChange(async (value) => {
tab.plugin.settings.zigArgs = value;
console.log('zig args set to: ' + value);
await tab.plugin.saveSettings();
}));
tab.makeInjectSetting(containerEl, "zig");
}

0 comments on commit 9cb62d6

Please sign in to comment.