# HG changeset patch # User zas_ # Date 1210927027 0 # Node ID dd5d7fe9458f9ad8305f8ab58f336ebd2e80cc3b # Parent a074514d418ef2486b6a9cddec26635df413d9d3 Improve editors a bit: - allow whitespaces before and after %v, %V, %w - allow % escaping using %% (mandatory to use shell commands than contain % characters) - display a dialog on execution if a syntax error is detected (only for generic editors) - update README editors section diff -r a074514d418e -r dd5d7fe9458f README --- a/README Wed May 14 18:12:11 2008 +0000 +++ b/README Fri May 16 08:37:07 2008 +0000 @@ -392,8 +392,7 @@ %f Replaced with list of selected files, may occur once. %p Command is run once for each selected file, may occur multiple times. - none When neither %f or %p exist, list of files is appended to command. - + Use of the following to display output window for the command: %v Display result of command in output window, must occur as first two @@ -406,6 +405,10 @@ %w Prevent full screen from deactivating when command is executed, must occur as the first two characters. + %% This will be replaced by one '%'. This is the way to escape '%'. + + %d This only makes sense for external commands like copy or move as this + is replaced by the destination. ======== Overlay Info [section:overlay] diff -r a074514d418e -r dd5d7fe9458f src/editors.c --- a/src/editors.c Wed May 14 18:12:11 2008 +0000 +++ b/src/editors.c Fri May 16 08:37:07 2008 +0000 @@ -14,14 +14,14 @@ #include "main.h" #include "editors.h" +#include "debug.h" +#include "filedata.h" +#include "filefilter.h" #include "utilops.h" #include "ui_fileops.h" #include "ui_spinner.h" #include "ui_utildlg.h" -#include "filedata.h" -#include "filefilter.h" - #include @@ -392,7 +392,9 @@ flags |= EDITOR_ERROR_EMPTY; goto err; } - + + /* skip leading whitespaces if any */ + while (g_ascii_isspace(*p)) p++; /* global flags */ while (*p == '%') @@ -411,9 +413,15 @@ flags |= EDITOR_VERBOSE_MULTI; p++; break; + default: + flags |= EDITOR_ERROR_SYNTAX; + goto err; } } + /* skip whitespaces if any */ + while (g_ascii_isspace(*p)) p++; + /* command */ while (*p) @@ -450,6 +458,7 @@ { case 'd': flags |= EDITOR_DEST; + /* fall through */ case 'p': flags |= EDITOR_FOR_EACH; if (flags & EDITOR_SINGLE_COMMAND) @@ -465,7 +474,9 @@ flags |= EDITOR_ERROR_NO_FILE; goto err; } - pathl = editor_command_path_parse((FileData *)list->data, (*p == 'd') ? PATH_DEST : PATH_FILE, extensions); + pathl = editor_command_path_parse((FileData *)list->data, + (flags & EDITOR_DEST) ? PATH_DEST : PATH_FILE, + extensions); if (!pathl) { flags |= EDITOR_ERROR_NO_FILE; @@ -515,6 +526,10 @@ } } break; + case '%': + /* %% = % escaping */ + if (output) result = g_string_append_c(result, *p); + break; default: flags |= EDITOR_ERROR_SYNTAX; goto err; @@ -798,6 +813,16 @@ command = g_locale_from_utf8(options->editor_command[n], -1, NULL, NULL, NULL); error = editor_command_start(command, options->editor_name[n], list, cb, data); g_free(command); + + if (n < GQ_EDITOR_GENERIC_SLOTS && (error & EDITOR_ERROR_SYNTAX)) + { + gchar *text = g_strdup_printf(_("Syntax error in the editor template \"%s\":\n%s"), + options->editor_name[n], options->editor_command[n]); + + file_util_warning_dialog(_("Invalid editor command"), text, GTK_STOCK_DIALOG_ERROR, NULL); + g_free(text); + } + return error; }