From bdc56f331bb5eb939f1b5064b3f1c7d749bdcad5 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Fri, 30 May 2003 21:06:10 +0000 Subject: [PATCH] * editcmd.c: Implement pasting the output of any external command. * editmenu.c: Add menu entries for that. * editcmddef.h: Add new command CK_ExtCmd. --- edit/ChangeLog | 7 +++++++ edit/edit.c | 4 ++++ edit/edit.h | 1 + edit/editcmd.c | 27 +++++++++++++++++++++++++++ edit/editcmddef.h | 1 + edit/editkeys.c | 2 ++ edit/editmenu.c | 8 ++++++++ 7 files changed, 50 insertions(+) diff --git a/edit/ChangeLog b/edit/ChangeLog index 9f12ee604..4c703ff28 100644 --- a/edit/ChangeLog +++ b/edit/ChangeLog @@ -1,3 +1,10 @@ +2003-05-30 Michal Szwaczko + + * editcmd.c: Implement pasting the output of any external + command. + * editmenu.c: Add menu entries for that. + * editcmddef.h: Add new command CK_ExtCmd. + 2003-04-04 Adam Byrtek * edit.c: Move edit_modification() before actions to provide diff --git a/edit/edit.c b/edit/edit.c index c0fb22a98..19729a906 100644 --- a/edit/edit.c +++ b/edit/edit.c @@ -2565,6 +2565,9 @@ int edit_execute_cmd (WEdit * edit, int command, int char_for_insertion) case CK_Sort: edit_sort_cmd (edit); break; + case CK_ExtCmd: + edit_ext_cmd (edit); + break; case CK_Mail: edit_mail_dialog (edit); break; @@ -2580,6 +2583,7 @@ int edit_execute_cmd (WEdit * edit, int command, int char_for_insertion) case CK_Ctags: case CK_Terminal: case CK_Terminal_App: + case CK_ExtCmd: #endif case CK_Complete: case CK_Cancel: diff --git a/edit/edit.h b/edit/edit.h index 151391b32..a70adec5a 100644 --- a/edit/edit.h +++ b/edit/edit.h @@ -232,6 +232,7 @@ void edit_move_display (WEdit * e, long line); void edit_word_wrap (WEdit * edit); unsigned char *edit_get_block (WEdit * edit, long start, long finish, int *l); int edit_sort_cmd (WEdit * edit); +int edit_ext_cmd (WEdit * edit); void edit_help_cmd (WEdit * edit); void edit_left_word_move (WEdit * edit, int s); void edit_right_word_move (WEdit * edit, int s); diff --git a/edit/editcmd.c b/edit/editcmd.c index 22eb0858b..a13873726 100644 --- a/edit/editcmd.c +++ b/edit/editcmd.c @@ -2347,6 +2347,33 @@ int edit_sort_cmd (WEdit * edit) return 0; } +int +edit_ext_cmd (WEdit *edit) +{ + char *exp; + int e; + + exp = + input_dialog (_("Paste output of external command"), + _("Enter shell command(s):"), NULL); + + if (!exp) + return 1; + + e = system (catstrs (exp, " ", " > ", home_dir, TEMP_FILE, 0)); + + if (e) { + edit_error_dialog (_("External command"), + get_sys_error (_("Cannot execute command"))); + return -1; + } + + edit->force |= REDRAW_COMPLETELY; + + edit_insert_file (edit, catstrs (home_dir, TEMP_FILE, 0)); + return 0; +} + /* if block is 1, a block must be highlighted and the shell command processes it. If block is 0 the shell command is a straight system command, that just produces some output which is to be inserted */ diff --git a/edit/editcmddef.h b/edit/editcmddef.h index 9a5a7a9da..9e7065369 100644 --- a/edit/editcmddef.h +++ b/edit/editcmddef.h @@ -92,6 +92,7 @@ #define CK_Match_Bracket 421 #define CK_Terminal 422 #define CK_Terminal_App 423 +#define CK_ExtCmd 424 #define CK_User_Menu 425 /* application control */ diff --git a/edit/editkeys.c b/edit/editkeys.c index 6d9334ccf..b9fc6c84e 100644 --- a/edit/editkeys.c +++ b/edit/editkeys.c @@ -69,6 +69,7 @@ static const long cooledit_key_map[] = { XCTRL ('f'), CK_Save_Block, KEY_F (1), CK_Help, ALT ('t'), CK_Sort, + ALT ('u'), CK_ExtCmd, ALT ('m'), CK_Mail, XCTRL ('z'), CK_Word_Left, XCTRL ('x'), CK_Word_Right, @@ -112,6 +113,7 @@ static long const emacs_key_map[] = { KEY_F (2), CK_Save, ALT ('p'), CK_Paragraph_Format, ALT ('t'), CK_Sort, + ALT ('u'), CK_ExtCmd, XCTRL ('a'), CK_Home, XCTRL ('e'), CK_End, XCTRL ('b'), CK_Left, diff --git a/edit/editmenu.c b/edit/editmenu.c index a4ad33061..8bbd43ec4 100644 --- a/edit/editmenu.c +++ b/edit/editmenu.c @@ -205,6 +205,12 @@ menu_sort_cmd (void) menu_cmd (CK_Sort); } +static void +menu_ext_cmd (void) +{ + menu_cmd (CK_ExtCmd); +} + static void menu_date_cmd (void) { @@ -353,6 +359,7 @@ static menu_entry CmdMenu[] = {' ', N_("Format p&aragraph M-p"), 'A', menu_format_paragraph}, {' ', N_("'ispell' s&pell check C-p"), 'P', menu_ispell_cmd}, {' ', N_("Sor&t... M-t"), 'T', menu_sort_cmd}, + {' ', N_("Paste o&utput of... M-u"), 'U', menu_ext_cmd}, {' ', N_("E&xternal Formatter F19"), 'C', menu_c_form_cmd}, {' ', N_("&Mail... "), 'M', menu_mail_cmd} }; @@ -376,6 +383,7 @@ static menu_entry CmdMenuEmacs[] = {' ', N_("Format p&aragraph M-p"), 'a', menu_format_paragraph}, {' ', N_("'ispell' s&pell check M-$"), 'P', menu_ispell_cmd}, {' ', N_("Sor&t... M-t"), 'T', menu_sort_cmd}, + {' ', N_("Paste o&utput of... M-u"), 'U', menu_ext_cmd}, {' ', N_("E&xternal Formatter F19"), 'C', menu_c_form_cmd}, {' ', N_("&Mail... "), 'M', menu_mail_cmd} };