mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Editor: Using preferences compose.editor
compose.editor is the path to the executable ( default /usr/bin/vim )
This commit is contained in:
parent
35b0b0f194
commit
9f32b2afb2
@ -9346,19 +9346,29 @@ cmd_editor(ProfWin* window, const char* const command, gchar** args)
|
|||||||
G_FILE_CREATE_PRIVATE, NULL,
|
G_FILE_CREATE_PRIVATE, NULL,
|
||||||
&creation_error);
|
&creation_error);
|
||||||
if ( creation_error ) {
|
if ( creation_error ) {
|
||||||
cons_show("Editor: Error during file creation");
|
cons_show_error("Editor: Error during file creation");
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
g_object_unref(fos);
|
g_object_unref(fos);
|
||||||
|
|
||||||
|
char* editor = prefs_get_string(PREF_COMPOSE_EDITOR);
|
||||||
|
if (!g_file_test(editor, G_FILE_TEST_EXISTS)) {
|
||||||
|
cons_show_error("Editor: editor %s not exists", editor);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
// Fork / exec
|
// Fork / exec
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if( pid == 0 ) {
|
if( pid == 0 ) {
|
||||||
int x = execl("/usr/bin/sensible-editor", "/usr/bin/sensible-editor", g_file_get_path(file), (char *) NULL);
|
int x = execl(editor, editor, g_file_get_path(file), (char *) NULL);
|
||||||
if ( x == -1 ) {
|
if ( x == -1 ) {
|
||||||
cons_show_error("Failed to exec sensible-editor");
|
cons_show_error("Failed to exec %s", editor);
|
||||||
}
|
}
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
} else {
|
} else {
|
||||||
|
if ( pid == -1 ) {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
int status = 0;
|
int status = 0;
|
||||||
waitpid(pid, &status, 0);
|
waitpid(pid, &status, 0);
|
||||||
int fd_input_file = open(g_file_get_path(file), O_RDONLY);
|
int fd_input_file = open(g_file_get_path(file), O_RDONLY);
|
||||||
@ -9366,12 +9376,12 @@ cmd_editor(ProfWin* window, const char* const command, gchar** args)
|
|||||||
char buf[COUNT];
|
char buf[COUNT];
|
||||||
ssize_t size_read = read(fd_input_file, buf, COUNT);
|
ssize_t size_read = read(fd_input_file, buf, COUNT);
|
||||||
if(size_read > 0 && size_read <= COUNT ) {
|
if(size_read > 0 && size_read <= COUNT ) {
|
||||||
buf[size_read-1] = '\0';
|
buf[size_read-1] = '\0';
|
||||||
GString* text = g_string_new(buf);
|
GString* text = g_string_new(buf);
|
||||||
ProfWin* win = wins_get_current();
|
ProfWin* win = wins_get_current();
|
||||||
win_println(win, THEME_DEFAULT, "!", "EDITOR PREVIEW: %s", text->str);
|
win_println(win, THEME_DEFAULT, "!", "EDITOR PREVIEW: %s", text->str);
|
||||||
rl_insert_text(text->str);
|
rl_insert_text(text->str);
|
||||||
g_string_free(text, TRUE);
|
g_string_free(text, TRUE);
|
||||||
}
|
}
|
||||||
close(fd_input_file);
|
close(fd_input_file);
|
||||||
ui_redraw();
|
ui_redraw();
|
||||||
|
@ -1868,6 +1868,7 @@ _get_group(preference_t pref)
|
|||||||
case PREF_TITLEBAR_MUC_TITLE_JID:
|
case PREF_TITLEBAR_MUC_TITLE_JID:
|
||||||
case PREF_TITLEBAR_MUC_TITLE_NAME:
|
case PREF_TITLEBAR_MUC_TITLE_NAME:
|
||||||
case PREF_SLASH_GUARD:
|
case PREF_SLASH_GUARD:
|
||||||
|
case PREF_COMPOSE_EDITOR:
|
||||||
return PREF_GROUP_UI;
|
return PREF_GROUP_UI;
|
||||||
case PREF_STATES:
|
case PREF_STATES:
|
||||||
case PREF_OUTTYPE:
|
case PREF_OUTTYPE:
|
||||||
@ -2189,6 +2190,8 @@ _get_key(preference_t pref)
|
|||||||
return "url.open.cmd";
|
return "url.open.cmd";
|
||||||
case PREF_URL_SAVE_CMD:
|
case PREF_URL_SAVE_CMD:
|
||||||
return "url.save.cmd";
|
return "url.save.cmd";
|
||||||
|
case PREF_COMPOSE_EDITOR:
|
||||||
|
return "compose.editor";
|
||||||
default:
|
default:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -2326,6 +2329,8 @@ _get_default_string(preference_t pref)
|
|||||||
return "xdg-open";
|
return "xdg-open";
|
||||||
case PREF_URL_OPEN_CMD:
|
case PREF_URL_OPEN_CMD:
|
||||||
return "xdg-open %u";
|
return "xdg-open %u";
|
||||||
|
case PREF_COMPOSE_EDITOR:
|
||||||
|
return "/usr/bin/vim";
|
||||||
case PREF_URL_SAVE_CMD:
|
case PREF_URL_SAVE_CMD:
|
||||||
return NULL; // Default to built-in method.
|
return NULL; // Default to built-in method.
|
||||||
default:
|
default:
|
||||||
|
@ -173,6 +173,7 @@ typedef enum {
|
|||||||
PREF_MAM,
|
PREF_MAM,
|
||||||
PREF_URL_OPEN_CMD,
|
PREF_URL_OPEN_CMD,
|
||||||
PREF_URL_SAVE_CMD,
|
PREF_URL_SAVE_CMD,
|
||||||
|
PREF_COMPOSE_EDITOR,
|
||||||
} preference_t;
|
} preference_t;
|
||||||
|
|
||||||
typedef struct prof_alias_t
|
typedef struct prof_alias_t
|
||||||
|
Loading…
Reference in New Issue
Block a user