Allow callers to override editor command

This commit is contained in:
Michael Grant
2026-09-14 05:35:00 +01:00
parent 59387debff
commit ea14195553
4 changed files with 8 additions and 7 deletions

View File

@@ -701,7 +701,7 @@ spawn_editor_finish(struct window_pane *wp)
struct spawn_editor_state * struct spawn_editor_state *
spawn_editor(struct client *c, const char *buf, size_t len, spawn_editor(struct client *c, const char *buf, size_t len,
spawn_finish_edit_cb cb, void *arg) const char *editor, spawn_finish_edit_cb cb, void *arg)
{ {
struct spawn_editor_state *es; struct spawn_editor_state *es;
struct spawn_context sc = { 0 }; struct spawn_context sc = { 0 };
@@ -715,13 +715,13 @@ spawn_editor(struct client *c, const char *buf, size_t len,
FILE *f; FILE *f;
char *cmd, *cause = NULL; char *cmd, *cause = NULL;
char path[] = _PATH_TMP "tmux.XXXXXXXX"; char path[] = _PATH_TMP "tmux.XXXXXXXX";
const char *editor;
int fd; int fd;
if (w->modal != NULL) if (w->modal != NULL)
return (NULL); return (NULL);
editor = options_get_string(global_options, "editor"); if (editor == NULL)
editor = options_get_string(global_options, "editor");
fd = mkstemp(path); fd = mkstemp(path);
if (fd == -1) if (fd == -1)
return (NULL); return (NULL);

2
tmux.h
View File

@@ -4211,7 +4211,7 @@ struct winlink *spawn_window(struct spawn_context *, char **);
struct window_pane *spawn_pane(struct spawn_context *, char **); struct window_pane *spawn_pane(struct spawn_context *, char **);
typedef void (*spawn_finish_edit_cb)(char *, size_t, void *); typedef void (*spawn_finish_edit_cb)(char *, size_t, void *);
struct spawn_editor_state *spawn_editor(struct client *, const char *, size_t, struct spawn_editor_state *spawn_editor(struct client *, const char *, size_t,
spawn_finish_edit_cb, void *); const char *, spawn_finish_edit_cb, void *);
void spawn_cancel_editor(struct spawn_editor_state *); void spawn_cancel_editor(struct spawn_editor_state *);
pid_t spawn_get_editor_pid(struct spawn_editor_state *); pid_t spawn_get_editor_pid(struct spawn_editor_state *);
void spawn_editor_finish(struct window_pane *); void spawn_editor_finish(struct window_pane *);

View File

@@ -606,7 +606,8 @@ window_buffer_start_edit(struct window_buffer_modedata *data,
ed->name = xstrdup(paste_buffer_name(pb)); ed->name = xstrdup(paste_buffer_name(pb));
ed->pb = pb; ed->pb = pb;
ed->editor = spawn_editor(c, buf, len, window_buffer_edit_close_cb, ed); ed->editor = spawn_editor(c, buf, len, NULL, window_buffer_edit_close_cb,
ed);
if (ed->editor == NULL) if (ed->editor == NULL)
window_buffer_finish_edit(ed); window_buffer_finish_edit(ed);
else { else {

View File

@@ -2104,8 +2104,8 @@ window_customize_start_edit(struct window_customize_modedata *data,
buf = "\n"; buf = "\n";
len = 1; len = 1;
} }
ed->editor = spawn_editor(c, buf, len, window_customize_edit_close_cb, ed->editor = spawn_editor(c, buf, len, NULL,
ed); window_customize_edit_close_cb, ed);
free(value); free(value);
if (ed->editor == NULL) if (ed->editor == NULL)
window_customize_finish_edit(ed); window_customize_finish_edit(ed);