Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Racket language support #166

Merged
merged 12 commits into from
Dec 26, 2022
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [1.5.0]
### Added
- Support for Racket

## [1.4.0]
### Added
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,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): CPP, Golang, Groovy, Kotlin, Java, JavaScript, TypeScript, Lua, CSharp, Prolog, Rust, Python, R, Wolfram Mathematica, Haskell, Scala, Shell & Powershell.
The following [languages are supported](#supported-programming-languages): CPP, Golang, Groovy, Kotlin, Java, JavaScript, TypeScript, Lua, CSharp, Prolog, Rust, Python, R, Wolfram Mathematica, Haskell, Scala, Racket, Shell & Powershell.


Python and Rust 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 Expand Up @@ -303,6 +303,16 @@ println("Hello, World!")
```
</details>

<details>
<summary>Racket</summary>

- Requirements: Racket is installed and the correct path is set in the settings.

```racket
"Hello, world!"
```
</details>

Squiggle: For Squiggle support take a look at the [Obsidian Squiggle plugin](https://github.com/jqhoogland/obsidian-squiggle) by @jqhoogland.

Support for the following is planned:
Expand Down
8 changes: 7 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import runAllCodeBlocks from './runAllCodeBlocks';

export const languageAliases = ["javascript", "typescript", "bash", "csharp", "wolfram", "nb", "wl", "hs", "py"] as const;
export const canonicalLanguages = ["js", "ts", "cs", "lua", "python", "cpp",
"prolog", "shell", "groovy", "r", "go", "rust", "java", "powershell", "kotlin", "mathematica", "haskell", "scala"] as const;
"prolog", "shell", "groovy", "r", "go", "rust", "java", "powershell", "kotlin", "mathematica", "haskell", "scala", "racket"] as const;
export const supportedLanguages = [...languageAliases, ...canonicalLanguages] as const;


Expand Down Expand Up @@ -330,6 +330,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.scalaPath, this.settings.scalaArgs, this.settings.scalaFileExtension, language, file);
});
} else if (language === "racket") {
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.racketPath, this.settings.racketArgs, this.settings.racketFileExtension, language, file);
});
}
}

Expand Down
12 changes: 11 additions & 1 deletion src/settings/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export interface ExecutorSettings {
scalaArgs: string;
scalaFileExtension: string;
scalaInject: string;
racketPath: string;
racketArgs: string;
racketFileExtension: string;
racketInject: string;

jsInteractive: boolean;
tsInteractive: boolean;
Expand All @@ -98,6 +102,7 @@ export interface ExecutorSettings {
mathematicaInteractive: boolean;
haskellInteractive: boolean;
scalaInteractive: boolean;
racketInteractive: boolean;
}


Expand Down Expand Up @@ -179,6 +184,10 @@ export const DEFAULT_SETTINGS: ExecutorSettings = {
scalaArgs: "",
scalaFileExtension: "scala",
scalaInject: "",
racketPath: "racket",
racketArgs: "",
racketFileExtension: "rkt",
racketInject: "#lang racket",

jsInteractive: true,
tsInteractive: false,
Expand All @@ -198,5 +207,6 @@ export const DEFAULT_SETTINGS: ExecutorSettings = {
kotlinInteractive: false,
mathematicaInteractive: false,
haskellInteractive: false,
scalaInteractive: false
scalaInteractive: false,
racketInteractive: false,
}
4 changes: 4 additions & 0 deletions src/settings/SettingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import makePythonSettings from "./per-lang/makePythonSettings";
import makeRSettings from "./per-lang/makeRSettings";
import makeRustSettings from "./per-lang/makeRustSettings";
import makeScalaSettings from "./per-lang/makeScalaSettings.js";
import makeRacketSettings from "./per-lang/makeRacketSettings.js";
import makeShellSettings from "./per-lang/makeShellSettings";
import makeTsSettings from "./per-lang/makeTsSettings";
import {ExecutorSettings} from "./Settings";
Expand Down Expand Up @@ -175,6 +176,9 @@ export class SettingsTab extends PluginSettingTab {
// ========== Scala ===========
makeScalaSettings(this, this.makeContainerFor("scala"));

// ========== Racket ===========
makeRacketSettings(this, this.makeContainerFor("racket"));

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

Expand Down
3 changes: 2 additions & 1 deletion src/settings/languageDisplayName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ export const DISPLAY_NAMES: Record<LanguageId, string> = {
rust: "Rust",
shell: "Shell",
ts: "Typescript",
scala: "Scala"
scala: "Scala",
racket: "Racket"
} as const;
27 changes: 27 additions & 0 deletions src/settings/per-lang/makeRacketSettings.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: 'Racket Settings' });
new Setting(containerEl)
.setName('racket path')
.setDesc("Path to your racket installation")
.addText(text => text
.setValue(tab.plugin.settings.racketPath)
.onChange(async (value) => {
const sanitized = tab.sanitizePath(value);
tab.plugin.settings.racketPath = sanitized;
console.log('racket path set to: ' + sanitized);
await tab.plugin.saveSettings();
}));
new Setting(containerEl)
.setName('Racket arguments')
.addText(text => text
.setValue(tab.plugin.settings.racketArgs)
.onChange(async (value) => {
tab.plugin.settings.racketArgs = value;
console.log('Racket args set to: ' + value);
await tab.plugin.saveSettings();
}));
tab.makeInjectSetting(containerEl, "racket");
}