From c21308b5bc0f8a87391ef6800edabe420b6e9c84 Mon Sep 17 00:00:00 2001 From: "Yuichiro Tachibana (Tsuchiya)" Date: Wed, 10 Jan 2024 16:07:27 +0900 Subject: [PATCH 01/17] Add git submodule paredit.js --- .gitmodules | 3 +++ vendor/paredit.js | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 vendor/paredit.js diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000..552cdda7b0 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vendor/paredit.js"] + path = vendor/paredit.js + url = https://github.com/whitphx/paredit.js.git diff --git a/vendor/paredit.js b/vendor/paredit.js new file mode 160000 index 0000000000..dfa2fae6da --- /dev/null +++ b/vendor/paredit.js @@ -0,0 +1 @@ +Subproject commit dfa2fae6da47d306c42e38848d36789cf6da0fed From 436928502628daae84243a30b31127e84357d6a3 Mon Sep 17 00:00:00 2001 From: "Yuichiro Tachibana (Tsuchiya)" Date: Wed, 10 Jan 2024 16:08:11 +0900 Subject: [PATCH 02/17] Configure linters to ignore the vendor dir --- .eslintignore | 1 + .lintstagedrc.json | 4 ++-- .prettierignore | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.eslintignore b/.eslintignore index ea0ac5645e..53574307cf 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ src/vs/ +vendor/ diff --git a/.lintstagedrc.json b/.lintstagedrc.json index 2a1525c7ad..89d43ebdbd 100644 --- a/.lintstagedrc.json +++ b/.lintstagedrc.json @@ -1,4 +1,4 @@ { - "*.{js,ts}": "eslint --cache --fix", - "*.{js,ts,md,json,yml}": "prettier --write" + "!(vendor)/**/*.{js,ts}": "eslint --cache --fix", + "!(vendor)/**/*.{js,ts,md,json,yml}": "prettier --write" } diff --git a/.prettierignore b/.prettierignore index c204f27001..e8e1e3d18f 100644 --- a/.prettierignore +++ b/.prettierignore @@ -4,3 +4,4 @@ dist out src/vs/ keybindings.json +vendor/ From 6167e4d759614a7ea45ea6b552c7e888014b1ec7 Mon Sep 17 00:00:00 2001 From: "Yuichiro Tachibana (Tsuchiya)" Date: Wed, 10 Jan 2024 16:08:32 +0900 Subject: [PATCH 03/17] Install the local paredit.js --- package.json | 2 +- yarn.lock | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 3436b48979..48b69e3489 100644 --- a/package.json +++ b/package.json @@ -6695,7 +6695,7 @@ "webpack-cli": "^5.1.4" }, "dependencies": { - "paredit.js": "^0.4.0", + "paredit.js": "./vendor/paredit.js", "winston": "^3.11.0", "winston-console-for-electron": "^0.0.7" } diff --git a/yarn.lock b/yarn.lock index e95efa3fe9..031e9564a8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3104,10 +3104,8 @@ pako@~1.0.2: resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf" integrity sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw== -paredit.js@^0.4.0: +paredit.js@./vendor/paredit.js: version "0.4.0" - resolved "https://registry.yarnpkg.com/paredit.js/-/paredit.js-0.4.0.tgz#a4bb7eeef8d4e5601d2dcc3f7929e5fea1e4f240" - integrity sha512-Zw1yo0DzKOjoI/VNoHINrJ9zis2it188XJRdjt2yAusSqr4Ch2Vq0hbzpqKEa+BMtWBHCVlfzpgXpM5b1TPVbA== dependencies: ace.improved ">=0.1.4" From 35ca9abee1a976efca6b31b6933803926132f441 Mon Sep 17 00:00:00 2001 From: "Yuichiro Tachibana (Tsuchiya)" Date: Wed, 10 Jan 2024 17:33:47 +0900 Subject: [PATCH 04/17] Implement the `emacs-mcx.paredit.parentheses` config --- package.json | 10 ++++++++++ src/configuration/configuration.ts | 9 ++++++++- src/configuration/iconfiguration.ts | 9 +++++++++ vendor/paredit.js | 2 +- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 48b69e3489..ead85e9e27 100644 --- a/package.json +++ b/package.json @@ -97,6 +97,16 @@ "default": true, "description": "When true, line-move moves point by visual lines (same as an Emacs variable line-move-visual)." }, + "emacs-mcx.paredit.parentheses": { + "type": "object", + "patternProperties": { + "^\\S$": { + "type": "string", + "pattern": "^\\S$" + } + }, + "default": {"[": "]", "(": ")", "{": "}"} + }, "emacs-mcx.debug.silent": { "type": "boolean", "description": "If true, all logs are suppressed.", diff --git a/src/configuration/configuration.ts b/src/configuration/configuration.ts index dc2cd97ee0..631cc73cce 100644 --- a/src/configuration/configuration.ts +++ b/src/configuration/configuration.ts @@ -4,7 +4,8 @@ import { Logger } from "../logger"; import * as vscode from "vscode"; -import { IConfiguration, IDebugConfiguration } from "./iconfiguration"; +import { IConfiguration, IDebugConfiguration, IPareditConfiguration } from "./iconfiguration"; +import * as paredit from "paredit.js"; export class Configuration implements IConfiguration, vscode.Disposable { /** @@ -40,6 +41,10 @@ export class Configuration implements IConfiguration, vscode.Disposable { public lineMoveVisual = true; + public paredit: IPareditConfiguration = { + parentheses: { "[": "]", "(": ")", "{": "}" }, + }; + public debug: IDebugConfiguration = { silent: false, loggingLevelForAlert: "error", @@ -77,6 +82,8 @@ export class Configuration implements IConfiguration, vscode.Disposable { } Logger.configChanged(this); + + paredit.reader.setParentheses(this.paredit.parentheses); } private static unproxify(obj: { [key: string]: unknown }) { diff --git a/src/configuration/iconfiguration.ts b/src/configuration/iconfiguration.ts index 97cdde735b..ae11d34ba1 100644 --- a/src/configuration/iconfiguration.ts +++ b/src/configuration/iconfiguration.ts @@ -1,3 +1,7 @@ +export interface IPareditConfiguration { + parentheses: { [key: string]: string }; +} + export interface IDebugConfiguration { /** * Boolean indicating whether all logs should be suppressed @@ -39,6 +43,11 @@ export interface IConfiguration { */ lineMoveVisual: boolean; + /** + * Paredit configuration + */ + paredit: IPareditConfiguration; + /** * Extension debugging settings */ diff --git a/vendor/paredit.js b/vendor/paredit.js index dfa2fae6da..a6f9bd3085 160000 --- a/vendor/paredit.js +++ b/vendor/paredit.js @@ -1 +1 @@ -Subproject commit dfa2fae6da47d306c42e38848d36789cf6da0fed +Subproject commit a6f9bd3085e8bd73932d5de2b7f38a228baf4915 From 09e2994c4e856dfeb79512c4369ca09d8a7aaf6d Mon Sep 17 00:00:00 2001 From: "Yuichiro Tachibana (Tsuchiya)" Date: Thu, 11 Jan 2024 00:52:25 +0900 Subject: [PATCH 05/17] Add tests --- src/test/suite/commands/paredit.test.ts | 48 +++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/test/suite/commands/paredit.test.ts b/src/test/suite/commands/paredit.test.ts index 1d6d488ea9..91064318d2 100644 --- a/src/test/suite/commands/paredit.test.ts +++ b/src/test/suite/commands/paredit.test.ts @@ -1,4 +1,6 @@ import assert from "assert"; +import * as vscode from "vscode"; +import * as sinon from "sinon"; import { Selection, TextEditor } from "vscode"; import { EmacsEmulator } from "../../../emulator"; import { KillRing } from "../../../kill-yank/kill-ring"; @@ -11,6 +13,7 @@ import { clearTextEditor, assertSelectionsEqual, } from "../utils"; +import { Configuration } from "../../../configuration/configuration"; suite("paredit commands", () => { let activeTextEditor: TextEditor; @@ -64,6 +67,51 @@ suite("paredit commands", () => { }); }); +suite("Parentheses config", () => { + let activeTextEditor: TextEditor; + let emulator: EmacsEmulator; + let getConfigurationStub: sinon.SinonStub; + + setup(async () => { + const initialText = "<<>>"; + + activeTextEditor = await setupWorkspace(initialText); + emulator = new EmacsEmulator(activeTextEditor); + + getConfigurationStub = sinon.stub(vscode.workspace, "getConfiguration"); + }); + teardown(async () => { + getConfigurationStub.restore(); + Configuration.reload(); + await cleanUpWorkspace(); + }); + + function mockPareditConfig(parentheses: Record) { + getConfigurationStub.returns({ + paredit: { + parentheses, + }, + }); + Configuration.reload(); + } + + test("forwardSexp", async () => { + mockPareditConfig({ "(": ")" }); + setEmptyCursors(activeTextEditor, [0, 1]); + await emulator.runCommand("paredit.forwardSexp"); + assertCursorsEqual(activeTextEditor, [0, 4]); + await emulator.runCommand("paredit.forwardSexp"); + assertCursorsEqual(activeTextEditor, [0, 4]); + + mockPareditConfig({ "<": ">" }); + setEmptyCursors(activeTextEditor, [0, 1]); + await emulator.runCommand("paredit.forwardSexp"); + assertCursorsEqual(activeTextEditor, [0, 3]); + await emulator.runCommand("paredit.forwardSexp"); + assertCursorsEqual(activeTextEditor, [0, 3]); + }); +}); + suite("paredit.kill-sexp", () => { const initialText = `( ( From c19bd81c61e1a21a94e15c0b4ab922ca3b069863 Mon Sep 17 00:00:00 2001 From: "Yuichiro Tachibana (Tsuchiya)" Date: Thu, 11 Jan 2024 00:55:06 +0900 Subject: [PATCH 06/17] Apply formatter to package.json --- package.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index ead85e9e27..08d61b1b71 100644 --- a/package.json +++ b/package.json @@ -105,7 +105,11 @@ "pattern": "^\\S$" } }, - "default": {"[": "]", "(": ")", "{": "}"} + "default": { + "[": "]", + "(": ")", + "{": "}" + } }, "emacs-mcx.debug.silent": { "type": "boolean", From 790e1807b60c65c1bbb3a3d26c89b973609d7135 Mon Sep 17 00:00:00 2001 From: "Yuichiro Tachibana (Tsuchiya)" Date: Thu, 11 Jan 2024 00:58:40 +0900 Subject: [PATCH 07/17] Fix the CI to checkout submodules --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1bc5515db9..b5ab0d9e39 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,6 +21,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + submodules: recursive - name: Install Node.js uses: actions/setup-node@v4 with: From 32c3112754f4b03e90dc1f4a77a25fd8abd3ccac Mon Sep 17 00:00:00 2001 From: "Yuichiro Tachibana (Tsuchiya)" Date: Thu, 11 Jan 2024 14:43:23 +0900 Subject: [PATCH 08/17] Fix lint staged config --- .lintstagedrc.json | 4 ---- lint-staged.config.mjs | 9 +++++++++ 2 files changed, 9 insertions(+), 4 deletions(-) delete mode 100644 .lintstagedrc.json create mode 100644 lint-staged.config.mjs diff --git a/.lintstagedrc.json b/.lintstagedrc.json deleted file mode 100644 index 89d43ebdbd..0000000000 --- a/.lintstagedrc.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "!(vendor)/**/*.{js,ts}": "eslint --cache --fix", - "!(vendor)/**/*.{js,ts,md,json,yml}": "prettier --write" -} diff --git a/lint-staged.config.mjs b/lint-staged.config.mjs new file mode 100644 index 0000000000..5777439e64 --- /dev/null +++ b/lint-staged.config.mjs @@ -0,0 +1,9 @@ +import micromatch from "micromatch"; + +export default { + "*.{js,ts,mjs,mts}": "eslint --cache --fix", + "*.{js,ts,mjs,mts,md,json,yml}": (files) => { + const match = micromatch.not(files, "vendor/"); + return `prettier --write ${match.join(" ")}`; + }, +}; From 756623923d248c218d98c790f29fb3401d1444b0 Mon Sep 17 00:00:00 2001 From: "Yuichiro Tachibana (Tsuchiya)" Date: Thu, 11 Jan 2024 14:54:36 +0900 Subject: [PATCH 09/17] Update README.md --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 1bb7c8518c..ace2c4840b 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,18 @@ Set `false` when `M-` conflicts with some other necessary commands. See h When true, line-move moves point by visual lines (same as an Emacs variable line-move-visual). +### `emacs-mcx.paredit.parentheses` + +Key-value pairs of parentheses like the following example to be used in the ParEdit commands. + +```json +{ + "[": "]", + "(": ")", + "{": "}" +} +``` + ### `emacs-mcx.debug.*` Configurations for debugging. From 55747e29a044cdcb9ebdd52244c3503aaa4f5c2b Mon Sep 17 00:00:00 2001 From: "Yuichiro Tachibana (Tsuchiya)" Date: Thu, 11 Jan 2024 15:35:13 +0900 Subject: [PATCH 10/17] Update .vscodeignore --- .vscodeignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.vscodeignore b/.vscodeignore index d4313bc9b8..d05ca13937 100644 --- a/.vscodeignore +++ b/.vscodeignore @@ -8,6 +8,7 @@ out/ src/ keybinding-generator/ scripts/ +vendor/ .gitignore .eslintignore .prettierignore @@ -26,5 +27,5 @@ yarn-debug.log* yarn-error.log* lerna-debug.log* .husky -.lintstagedrc.json +lint-staged.config.mjs .git-blame-ignore-revs From 20f2adc6d193339bb230e88269fdf653a89616f3 Mon Sep 17 00:00:00 2001 From: "Yuichiro Tachibana (Tsuchiya)" Date: Thu, 11 Jan 2024 18:36:04 +0900 Subject: [PATCH 11/17] Fix lint-staged.config.mjs --- lint-staged.config.mjs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lint-staged.config.mjs b/lint-staged.config.mjs index 5777439e64..86fe79d5c6 100644 --- a/lint-staged.config.mjs +++ b/lint-staged.config.mjs @@ -1,9 +1,9 @@ import micromatch from "micromatch"; export default { - "*.{js,ts,mjs,mts}": "eslint --cache --fix", - "*.{js,ts,mjs,mts,md,json,yml}": (files) => { + "*.{js,ts,mjs,mts}": (files) => { const match = micromatch.not(files, "vendor/"); - return `prettier --write ${match.join(" ")}`; + return `eslint --cache --fix ${match.join(" ")}`; }, + "*.{js,ts,mjs,mts,md,json,yml}": "prettier --write", }; From 657b86fff1b736ea078e5b7cdd1e434d5a7ae257 Mon Sep 17 00:00:00 2001 From: "Yuichiro Tachibana (Tsuchiya)" Date: Thu, 11 Jan 2024 18:59:42 +0900 Subject: [PATCH 12/17] Fix lint-staged config --- lint-staged.config.js | 16 ++++++++++++++++ lint-staged.config.mjs | 9 --------- 2 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 lint-staged.config.js delete mode 100644 lint-staged.config.mjs diff --git a/lint-staged.config.js b/lint-staged.config.js new file mode 100644 index 0000000000..a462b6abed --- /dev/null +++ b/lint-staged.config.js @@ -0,0 +1,16 @@ +/* eslint-env node */ +/* eslint-disable @typescript-eslint/no-var-requires */ + +const path = require("path"); +const micromatch = require("micromatch"); + +module.exports = { + "*.{js,ts,mjs,mts}": (files) => { + const match = micromatch.not(files, path.join(__dirname, "./vendor/*")); + return `eslint --cache --fix ${match.join(" ")}`; + }, + "*.{js,ts,mjs,mts,md,json,yml}": (files) => { + const match = micromatch.not(files, path.join(__dirname, "./vendor/*")); + return `prettier --write ${match.join(" ")}`; + }, +}; diff --git a/lint-staged.config.mjs b/lint-staged.config.mjs deleted file mode 100644 index 86fe79d5c6..0000000000 --- a/lint-staged.config.mjs +++ /dev/null @@ -1,9 +0,0 @@ -import micromatch from "micromatch"; - -export default { - "*.{js,ts,mjs,mts}": (files) => { - const match = micromatch.not(files, "vendor/"); - return `eslint --cache --fix ${match.join(" ")}`; - }, - "*.{js,ts,mjs,mts,md,json,yml}": "prettier --write", -}; From 42f90344232cec6c1cf5c11dcd1314566bf0db49 Mon Sep 17 00:00:00 2001 From: "Yuichiro Tachibana (Tsuchiya)" Date: Thu, 11 Jan 2024 19:02:36 +0900 Subject: [PATCH 13/17] Fix lint-staged config --- lint-staged.config.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lint-staged.config.js b/lint-staged.config.js index a462b6abed..787934db75 100644 --- a/lint-staged.config.js +++ b/lint-staged.config.js @@ -7,10 +7,16 @@ const micromatch = require("micromatch"); module.exports = { "*.{js,ts,mjs,mts}": (files) => { const match = micromatch.not(files, path.join(__dirname, "./vendor/*")); + if (match.length === 0) { + return ""; + } return `eslint --cache --fix ${match.join(" ")}`; }, "*.{js,ts,mjs,mts,md,json,yml}": (files) => { const match = micromatch.not(files, path.join(__dirname, "./vendor/*")); + if (match.length === 0) { + return ""; + } return `prettier --write ${match.join(" ")}`; }, }; From 34da13d0001143c2ce93a6adcab1e5f073552cf6 Mon Sep 17 00:00:00 2001 From: "Yuichiro Tachibana (Tsuchiya)" Date: Thu, 11 Jan 2024 19:10:04 +0900 Subject: [PATCH 14/17] Fix lint-staged config --- lint-staged.config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lint-staged.config.js b/lint-staged.config.js index 787934db75..9d0bec4956 100644 --- a/lint-staged.config.js +++ b/lint-staged.config.js @@ -8,14 +8,14 @@ module.exports = { "*.{js,ts,mjs,mts}": (files) => { const match = micromatch.not(files, path.join(__dirname, "./vendor/*")); if (match.length === 0) { - return ""; + return []; } return `eslint --cache --fix ${match.join(" ")}`; }, "*.{js,ts,mjs,mts,md,json,yml}": (files) => { const match = micromatch.not(files, path.join(__dirname, "./vendor/*")); if (match.length === 0) { - return ""; + return []; } return `prettier --write ${match.join(" ")}`; }, From d357dbc1e5a490ea2e34c84485b82c00dc0c0ff4 Mon Sep 17 00:00:00 2001 From: "Yuichiro Tachibana (Tsuchiya)" Date: Thu, 11 Jan 2024 19:12:59 +0900 Subject: [PATCH 15/17] Fix .vscodeignore --- .vscodeignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscodeignore b/.vscodeignore index d05ca13937..f245964935 100644 --- a/.vscodeignore +++ b/.vscodeignore @@ -27,5 +27,5 @@ yarn-debug.log* yarn-error.log* lerna-debug.log* .husky -lint-staged.config.mjs +lint-staged.config.js .git-blame-ignore-revs From 2936b81409d176c0cfc87d0aaec11978b4008f03 Mon Sep 17 00:00:00 2001 From: "Yuichiro Tachibana (Tsuchiya)" Date: Thu, 11 Jan 2024 19:15:47 +0900 Subject: [PATCH 16/17] Update .vscodeignore --- .vscodeignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.vscodeignore b/.vscodeignore index f245964935..9e46bb56c4 100644 --- a/.vscodeignore +++ b/.vscodeignore @@ -29,3 +29,6 @@ lerna-debug.log* .husky lint-staged.config.js .git-blame-ignore-revs +.eslintcache +.gitmodules +.nvmrc From 809ef257ca8f53bc5f298b21e5ad800b586ba77f Mon Sep 17 00:00:00 2001 From: "Yuichiro Tachibana (Tsuchiya)" Date: Thu, 11 Jan 2024 19:21:41 +0900 Subject: [PATCH 17/17] Update --- src/configuration/configuration.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/configuration/configuration.ts b/src/configuration/configuration.ts index 631cc73cce..5c8de054b3 100644 --- a/src/configuration/configuration.ts +++ b/src/configuration/configuration.ts @@ -83,6 +83,7 @@ export class Configuration implements IConfiguration, vscode.Disposable { Logger.configChanged(this); + // Update configs in the third-party libraries. paredit.reader.setParentheses(this.paredit.parentheses); }