Add emacs support, as per user requests. :) (#1633)

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: N. Taylor Mullen <ntaylormullen@google.com>
Co-authored-by: Jacob Richman <jacob314@gmail.com>
Co-authored-by: matt korwel <matt.korwel@gmail.com>
Co-authored-by: matt korwel <mattkorwel@google.com>
This commit is contained in:
Paige Bailey 2025-07-31 15:46:04 -07:00 committed by GitHub
parent 574015edd9
commit 37a3f1e6b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 37 additions and 2 deletions

View File

@ -23,6 +23,7 @@ export const EDITOR_DISPLAY_NAMES: Record<EditorType, string> = {
windsurf: 'Windsurf',
cursor: 'Cursor',
vim: 'Vim',
emacs: 'Emacs',
neovim: 'Neovim',
};

View File

@ -70,6 +70,7 @@ describe('editor utils', () => {
{ editor: 'vim', commands: ['vim'], win32Commands: ['vim'] },
{ editor: 'neovim', commands: ['nvim'], win32Commands: ['nvim'] },
{ editor: 'zed', commands: ['zed', 'zeditor'], win32Commands: ['zed'] },
{ editor: 'emacs', commands: ['emacs'], win32Commands: ['emacs.exe'] },
];
for (const { editor, commands, win32Commands } of testCases) {
@ -297,6 +298,14 @@ describe('editor utils', () => {
});
}
it('should return the correct command for emacs', () => {
const command = getDiffCommand('old.txt', 'new.txt', 'emacs');
expect(command).toEqual({
command: 'emacs',
args: ['--eval', '(ediff "old.txt" "new.txt")'],
});
});
it('should return null for an unsupported editor', () => {
// @ts-expect-error Testing unsupported editor
const command = getDiffCommand('old.txt', 'new.txt', 'foobar');
@ -372,7 +381,7 @@ describe('editor utils', () => {
});
}
const execSyncEditors: EditorType[] = ['vim', 'neovim'];
const execSyncEditors: EditorType[] = ['vim', 'neovim', 'emacs'];
for (const editor of execSyncEditors) {
it(`should call execSync for ${editor} on non-windows`, async () => {
Object.defineProperty(process, 'platform', { value: 'linux' });
@ -425,6 +434,15 @@ describe('editor utils', () => {
expect(allowEditorTypeInSandbox('vim')).toBe(true);
});
it('should allow emacs in sandbox mode', () => {
process.env.SANDBOX = 'sandbox';
expect(allowEditorTypeInSandbox('emacs')).toBe(true);
});
it('should allow emacs when not in sandbox mode', () => {
expect(allowEditorTypeInSandbox('emacs')).toBe(true);
});
it('should allow neovim in sandbox mode', () => {
process.env.SANDBOX = 'sandbox';
expect(allowEditorTypeInSandbox('neovim')).toBe(true);
@ -490,6 +508,12 @@ describe('editor utils', () => {
expect(isEditorAvailable('vim')).toBe(true);
});
it('should return true for emacs when installed and in sandbox mode', () => {
(execSync as Mock).mockReturnValue(Buffer.from('/usr/bin/emacs'));
process.env.SANDBOX = 'sandbox';
expect(isEditorAvailable('emacs')).toBe(true);
});
it('should return true for neovim when installed and in sandbox mode', () => {
(execSync as Mock).mockReturnValue(Buffer.from('/usr/bin/nvim'));
process.env.SANDBOX = 'sandbox';

View File

@ -13,7 +13,8 @@ export type EditorType =
| 'cursor'
| 'vim'
| 'neovim'
| 'zed';
| 'zed'
| 'emacs';
function isValidEditorType(editor: string): editor is EditorType {
return [
@ -24,6 +25,7 @@ function isValidEditorType(editor: string): editor is EditorType {
'vim',
'neovim',
'zed',
'emacs',
].includes(editor);
}
@ -59,6 +61,7 @@ const editorCommands: Record<
vim: { win32: ['vim'], default: ['vim'] },
neovim: { win32: ['nvim'], default: ['nvim'] },
zed: { win32: ['zed'], default: ['zed', 'zeditor'] },
emacs: { win32: ['emacs.exe'], default: ['emacs'] },
};
export function checkHasEditorType(editor: EditorType): boolean {
@ -73,6 +76,7 @@ export function allowEditorTypeInSandbox(editor: EditorType): boolean {
if (['vscode', 'vscodium', 'windsurf', 'cursor', 'zed'].includes(editor)) {
return notUsingSandbox;
}
// For terminal-based editors like vim and emacs, allow in sandbox.
return true;
}
@ -141,6 +145,11 @@ export function getDiffCommand(
newPath,
],
};
case 'emacs':
return {
command: 'emacs',
args: ['--eval', `(ediff "${oldPath}" "${newPath}")`],
};
default:
return null;
}
@ -190,6 +199,7 @@ export async function openDiff(
});
case 'vim':
case 'emacs':
case 'neovim': {
// Use execSync for terminal-based editors
const command =