Skip to content

Add Emacs-style send-to-REPL commands with keybindings - #19

Open
d-torrance wants to merge 1 commit into
Macaulay2:developmentfrom
d-torrance:send-to-program
Open

Add Emacs-style send-to-REPL commands with keybindings#19
d-torrance wants to merge 1 commit into
Macaulay2:developmentfrom
d-torrance:send-to-program

Conversation

@d-torrance

@d-torrance d-torrance commented May 29, 2026

Copy link
Copy Markdown
Member

Adds six commands mirroring the Macaulay2 Emacs major mode, each sending a different slice of the editor to the M2 REPL:

  • Send Line to M2 REPL — sends the current line and advances the cursor down
  • Send Region to M2 REPL — sends the active selection
  • Send Buffer to M2 REPL — sends the entire document
  • Send Everything Above Point to M2 REPL — sends from the start of the buffer to the cursor
  • Send Everything Below Point to M2 REPL — sends from the cursor to the end of the buffer
  • Send Paragraph to M2 REPL — sends the current paragraph and advances the cursor past it

Paragraph detection follows Emacs forward-paragraph/backward-paragraph semantics: paragraphs are delimited by blank lines. When the cursor is on a blank line, the next paragraph below is targeted; if only whitespace remains below, the previous paragraph above is used instead.

All send commands (including the existing Shift+Enter / Ctrl+Enter bindings) briefly highlight the range being sent for 300 ms using the editor.selectionHighlightBackground theme color. The flash is suppressed when editor.renderLineHighlight is "none" or "gutter", respecting the user's existing editor highlight preferences.

The paragraph boundary logic is extracted into a pure exported function getParagraphLineRange, covered by 11 unit tests.

Edit: An earlier iteration of this PR added Emacs-like keybindings for each of these functions, but they were later removed.

AI Disclosure

This was all Claude

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds six Emacs-style send-to-REPL commands (line, region, buffer, above, below, paragraph) with Ctrl+C-prefixed chord keybindings, and introduces a 300 ms range flash highlight to all send operations. A pure getParagraphLineRange helper implements Emacs-style paragraph boundary detection and is covered by 11 new unit tests.

Changes:

  • New executeLine/Region/Buffer/Above/Below/ParagraphInWebview functions plus a shared flashRange helper in src/backend/repl.ts, with corresponding command registrations and decoration cleanup in deactivate.
  • New command and chord keybinding contributions in package.json (six new commands, all bound under editorTextFocus && editorLangId == macaulay2).
  • Exported getParagraphLineRange and a new "Send Paragraph to REPL" test suite covering 11 boundary cases.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/backend/repl.ts Adds six new send commands, the flashRange decoration helper, the exported getParagraphLineRange helper, command registrations, and decoration disposal on deactivate. Refactors existing send-to-terminal/webview to use range-based highlighting.
package.json Adds six new macaulay2.send*ToREPL command contributions and ctrl+c-prefixed chord keybindings scoped to Macaulay2 editors.
src/backend/test/extension.test.ts Imports getParagraphLineRange and adds an 11-case suite covering paragraph boundary detection (mid-paragraph, blank lines, top/bottom of file, all-blank buffer, etc.).
Comments suppressed due to low confidence (1)

src/backend/repl.ts:868

  • executeSelectionInTerminal and executeSelectionInWebview now always execute cursorMove "down" after sending, including when a multi-line selection is active. Previously (via the removed getSelectedM2Code path), Shift+Enter / Ctrl+Enter with a selection did not move the cursor. Moving the cursor down by one line after the user has selected a region is unexpected and changes the long-standing behavior of these existing keybindings. Consider only advancing the cursor when the selection is empty (i.e., the "send current line" path), matching Emacs forward-line semantics, e.g. wrap the cursorMove call in if (selection.isEmpty) { ... }.
  executeCodeInTerminal(editor.document.getText(range));
  vscode.commands.executeCommand("cursorMove", {
    to: "down",
    by: "line",
    value: 1,
  });

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread package.json Outdated
Comment thread src/backend/repl.ts Outdated
Adds six commands mirroring the Macaulay2 Emacs major mode, each
sending a different slice of the editor to the M2 REPL:

  C-c C-j  sendLineToREPL     current line (advances cursor)
  C-c C-r  sendRegionToREPL   active selection
  C-c C-b  sendBufferToREPL   entire document
  C-c C-up    sendAboveToREPL everything from start to cursor
  C-c C-down  sendBelowToREPL everything from cursor to end
  C-c C-p  sendParagraphToREPL current paragraph (advances past it)

Paragraph detection follows Emacs forward/backward-paragraph semantics:
blank lines are delimiters; cursor on a blank line targets the next
paragraph below, falling back to the previous one if only whitespace
remains below. The paragraph boundary logic is extracted into
getParagraphLineRange, a pure exported function covered by 11 unit tests.

All send commands (including the existing sendToWebview/sendToTerminal)
briefly highlight the exact range being sent for 300 ms using
editor.selectionHighlightBackground. The flash is suppressed when
editor.renderLineHighlight is "none" or "gutter".

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants