-
-
Notifications
You must be signed in to change notification settings - Fork 74
Fix/paredit config config per doc #2730
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
1b3f77f
9ecd944
51a53bc
4a6e34d
9114499
a99aa61
bb87eaa
b4900ed
c65698b
306397a
143990f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "emacs-mcx": patch | ||
| --- | ||
|
|
||
| Paredit config effective per document rather than globally |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,31 @@ | ||
| import * as paredit from "paredit.js"; | ||
| import { TextDocument, Selection, Range, TextEditor, Position } from "vscode"; | ||
| import * as vscode from "vscode"; | ||
| import { EmacsCommand } from "."; | ||
| import { KillYankCommand } from "./kill"; | ||
| import { AppendDirection } from "../kill-yank"; | ||
| import { revealPrimaryActive } from "./helpers/reveal"; | ||
| import { MessageManager } from "../message"; | ||
| import { Logger } from "../logger"; | ||
|
|
||
| const logger = Logger.get("paredit"); | ||
|
|
||
| type PareditNavigatorFn = (ast: paredit.AST, idx: number) => number; | ||
|
|
||
| function getPareditParenthesesConfig(document: vscode.TextDocument): { [key: string]: string } { | ||
| const config = vscode.workspace.getConfiguration("emacs-mcx", document); | ||
| const parentheses = config.get<{ [key: string]: string | null }>("paredit.parentheses", {}); | ||
whitphx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // parentheses[open] can be null to explicitly disable a pair | ||
| const filteredParentheses: { [key: string]: string } = {}; | ||
| for (const open in parentheses) { | ||
| const close = parentheses[open]; | ||
| if (close != null) { | ||
| filteredParentheses[open] = close; | ||
| } | ||
| } | ||
| return filteredParentheses; | ||
| } | ||
|
|
||
| // Languages in which semicolon represents comment | ||
| const languagesSemicolonComment = new Set(["clojure", "lisp", "scheme"]); | ||
|
|
||
|
|
@@ -19,8 +37,13 @@ const makeSexpTravelFunc = (doc: TextDocument, pareditNavigatorFn: PareditNaviga | |
| // However, in other languages, semicolon should be treated as one entity, but not comment for convenience. | ||
| // To do so, ";" is replaced with another character which is not treated as comment by paredit.js | ||
| // if the document is not lisp or lisp-like languages. | ||
| src = src.split(";").join("_"); // split + join = replaceAll | ||
| src = src.replaceAll(";", "_"); | ||
| } | ||
|
|
||
| const parentheses = getPareditParenthesesConfig(doc); | ||
| logger.debug(`Using paredit parentheses: ${JSON.stringify(parentheses)}`); | ||
| paredit.reader.setParentheses(parentheses); | ||
whitphx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const ast = paredit.parse(src); | ||
|
|
||
| return (position: Position, repeat: number): Position => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.