Skip to content

Commit

Permalink
Merge pull request #299 from slar/zig
Browse files Browse the repository at this point in the history
Added zig support
  • Loading branch information
twibiral authored Dec 15, 2023
2 parents 9c70dba + 9cb62d6 commit 69249d7
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
9 changes: 8 additions & 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 All @@ -28,6 +28,13 @@ Take a look at the [changelog](CHANGELOG.md) to see what has changed in recent v
[![Buy us a coffee](https://img.shields.io/badge/-buy_us_a%C2%A0coffee-gray?logo=buy-me-a-coffee)](https://www.buymeacoffee.com/timwibiral)
</div>


## Featured In
[![Video by I Versus AI](https://img.youtube.com/vi/eQz4eAW3ZDk/0.jpg)](https://www.youtube.com/watch?v=eQz4eAW3ZDk)

"Escape ChatGPT. Make your own Code Interpreter EASY" by I Versus AI


## Supported programming languages 💻

<details>
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 @@ -128,6 +128,9 @@ export interface ExecutorSettings {
applescriptArgs: string;
applescriptFileExtension: string;
applescriptInject: string;
zigPath: string;
zigArgs: string;
zigInject: string;

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


Expand Down Expand Up @@ -290,6 +294,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 @@ -320,4 +327,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 @@ -218,6 +219,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 69249d7

Please sign in to comment.