summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorportix <portix@gmx.net>2014-02-26 11:40:31 +0100
committerportix <portix@gmx.net>2014-02-26 11:40:31 +0100
commitb42f01bdc5cbd16fc4b13c42d67691d453a9cf58 (patch)
treecdd915d889d3d4365cda8b7d09d7688babf827e3
parent0c70cca9525d790543a8de1ddd2ca74cc842f1d7 (diff)
downloaddwb-b42f01bdc5cbd16fc4b13c42d67691d453a9cf58.zip
dwbem: set ft=javascript if editor is vim
-rw-r--r--dwbem/dwbem.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/dwbem/dwbem.c b/dwbem/dwbem.c
index 98d8966d..ae360996 100644
--- a/dwbem/dwbem.c
+++ b/dwbem/dwbem.c
@@ -436,11 +436,19 @@ diff(const char *text1, const char *text2, char **ret, int ntf)
char *text2_new = g_strdup_printf("// THIS FILE WILL BE DISCARDED\n%s// THIS FILE WILL BE DISCARDED", text2);
if (g_file_set_contents(file1, text1, -1, &e) && g_file_set_contents(file2, text2_new, -1, &e))
{
- char *args[4];
- args[0] = (char *)m_diff;
- args[1] = file1;
- args[2] = file2;
- args[3] = NULL;
+ gboolean use_vim = strcmp(m_diff, "vimdiff") == 0;
+ int nargs = use_vim ? 6 : 4;
+ int argc = 0;
+
+ char *args[nargs];
+ args[argc++] = (char *)m_diff;
+ if (use_vim) {
+ args[argc++] = "-c";
+ args[argc++] = "set ft=javascript";
+ }
+ args[argc++] = file1;
+ args[argc++] = file2;
+ args[argc++] = NULL;
spawn_success = g_spawn_sync(NULL, args, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_CHILD_INHERITS_STDIN, NULL, NULL, NULL, NULL, NULL, NULL);
if (spawn_success)
@@ -473,10 +481,18 @@ edit(const char *text)
if (g_file_set_contents(file, text, -1, NULL))
{
- char *args[3];
- args[0] = (char*)m_editor;
- args[1] = file;
- args[2] = NULL;
+ gboolean use_vim = strcmp(m_editor, "vim") == 0;
+ int nargs = use_vim ? 5 : 3;
+ int argc = 0;
+
+ char *args[nargs];
+ args[argc++] = (char*)m_editor;
+ if (use_vim) {
+ args[argc++] = "-c";
+ args[argc++] = "set ft=javascript";
+ }
+ args[argc++] = file;
+ args[argc++] = NULL;
spawn_success = g_spawn_sync(NULL, args, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_CHILD_INHERITS_STDIN, NULL, NULL, NULL, NULL, NULL, NULL);
if (spawn_success)
@@ -545,7 +561,7 @@ set_loader(const char *name, const char *config, int flags)
}
if (! g_file_test(m_loader, G_FILE_TEST_EXISTS) )
{
- char *file_content = g_strdup_printf("//!javascript\n%s", script);
+ char *file_content = g_strdup_printf("//!javascript\n/*\n * AUTOGENERATED - DO NOT EDIT THIS FILE, USE dwbem -E <extension> INSTEAD!\n */\n\n%s", script);
g_file_set_contents(m_loader, file_content, -1, NULL);
g_free(file_content);
}