Update the patch to sync with branch committed and pushed. - pkgsrc-localpatches - leot's pkgsrc LOCALPATCHES
 (HTM) hg clone https://bitbucket.org/iamleot/pkgsrc-localpatches
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
 (DIR) changeset 11fdbb5d1c9d59e090529b37d3cb1c58c6ced6d3
 (DIR) parent a04c4611af5d4b1a7a5c5512a10de44faf9c3899
 (HTM) Author: Leonardo Taccari <iamleot@gmail.com>
       Date:   Fri, 19 Oct 2018 14:32:37 
       
       Update the patch to sync with branch committed and pushed.
       
       Diffstat:
        wip/vimb3-git/patch-normal_view_support.patch |  318 +++++++++++++++++++++++--
        1 files changed, 282 insertions(+), 36 deletions(-)
       ---
       diff -r a04c4611af5d -r 11fdbb5d1c9d wip/vimb3-git/patch-normal_view_support.patch
       --- a/wip/vimb3-git/patch-normal_view_support.patch     Wed Oct 17 22:37:02 2018 +0200
       +++ b/wip/vimb3-git/patch-normal_view_support.patch     Fri Oct 19 14:32:37 2018 +0200
       @@ -1,46 +1,42 @@
       -Add experimental support for `gf' command.
       +Sync with iamleot/vimb/view_source_support commits.
        
       ---- src/normal.c.orig
       -+++ src/normal.c
       -@@ -74,6 +74,7 @@ static VbResult normal_search(Client *c, const NormalCmdInfo *info);
       - static VbResult normal_search_selection(Client *c, const NormalCmdInfo *info);
       - static VbResult normal_view_inspector(Client *c, const NormalCmdInfo *info);
       - static VbResult normal_view_source(Client *c, const NormalCmdInfo *info);
       -+static void resume_normal_view_editor(GPid pid, int status, char *file);
       - static VbResult normal_yank(Client *c, const NormalCmdInfo *info);
       - static VbResult normal_zoom(Client *c, const NormalCmdInfo *info);
       +diff --git src/command.c src/command.c
       +index 118881f..41ce87b 100644
       +--- src/command.c
       ++++ src/command.c
       +@@ -30,6 +30,7 @@
       + #endif
       + #include "command.h"
       + #include "history.h"
       ++#include "util.h"
       + #include "main.h"
         
       -@@ -743,8 +744,76 @@ static VbResult normal_view_inspector(Client *c, const NormalCmdInfo *info)
       - 
       - static VbResult normal_view_source(Client *c, const NormalCmdInfo *info)
       - {
       --    /* TODO the source mode isn't supported anymore use external editor for this */
       + /**
       +@@ -260,3 +261,62 @@ gboolean command_queue(Client *c, const Arg *arg)
       +     return res;
       + }
       + #endif
       ++
       ++gboolean command_spawn_editor(Client *c, const Arg *arg,
       ++    GChildWatchFunc callback, gpointer data)
       ++{
        +    char **argv = NULL, *file_path = NULL;
        +    char *command = NULL;
        +    int argc;
        +    GPid pid;
        +    gboolean success;
       -+    const char *text = NULL, *editor_command;
       -+    GVariant *jsreturn;
       ++    char *editor_command;
        +    GError *error = NULL;
        +
        +    /* get the editor command */
        +    editor_command = GET_CHAR(c, "editor-command");
        +    if (!editor_command || !*editor_command) {
        +        vb_echo(c, MSG_ERROR, TRUE, "No editor-command configured");
       -+        return RESULT_ERROR;
       ++        return FALSE;
        +    }
        +
       -+    /* get the selected input element */
       -+    jsreturn = ext_proxy_eval_script_sync(c, "document.documentElement.innerHTML");
       -+    g_variant_get(jsreturn, "(bs)", &success, &text);
       -+
       -+    if (!success || !text) {
       -+        return RESULT_ERROR;
       -+    }
       -+
       -+    /* create a temp file to pass text to editor */
       -+    if (!util_create_tmp_file(text, &file_path)) {
       ++    /* create a temp file to pass text in/to editor */
       ++    if (!util_create_tmp_file(arg->s, &file_path)) {
        +        goto error;
        +    }
        +
       @@ -63,27 +59,277 @@
        +    }
        +    g_strfreev(argv);
        +
       -+    /* watch the editor process */
       -+    char *file = g_strdup(file_path);
       ++    EditorData *ed = g_slice_new0(EditorData);
       ++    ed->file = file_path;
       ++    ed->c    = c;
       ++    ed->data = data;
        +
       -+    g_child_watch_add(pid, (GChildWatchFunc)resume_normal_view_editor, file);
       ++    /* watch the editor process */
       ++    g_child_watch_add(pid, callback, ed);
        +
       -     return RESULT_COMPLETE;
       ++    return TRUE;
        +
        +error:
        +    unlink(file_path);
        +    g_free(file_path);
        +    g_strfreev(argv);
       ++    return FALSE;
       ++}
       +diff --git src/command.h src/command.h
       +index c3f8b68..6483a50 100644
       +--- src/command.h
       ++++ src/command.h
       +@@ -43,11 +43,18 @@ enum {
       + };
       + #endif
       + 
       ++typedef struct {
       ++    Client   *c;
       ++    char     *file;
       ++    gpointer *data;
       ++} EditorData;
       ++
       + gboolean command_search(Client *c, const Arg *arg, bool commit);
       + gboolean command_yank(Client *c, const Arg *arg, char buf);
       + gboolean command_save(Client *c, const Arg *arg);
       + #ifdef FEATURE_QUEUE
       + gboolean command_queue(Client *c, const Arg *arg);
       + #endif
       ++gboolean command_spawn_editor(Client *c, const Arg *arg, GChildWatchFunc callback, gpointer data);
       + 
       + #endif /* end of include guard: _COMMAND_H */
       +diff --git src/input.c src/input.c
       +index ac6db07..a0646ae 100644
       +--- src/input.c
       ++++ src/input.c
       +@@ -22,6 +22,7 @@
       + #include <string.h>
       + 
       + #include "ascii.h"
       ++#include "command.h"
       + #include "config.h"
       + #include "input.h"
       + #include "main.h"
       +@@ -31,13 +32,11 @@
       + #include "ext-proxy.h"
       + 
       + typedef struct {
       +-    Client *c;
       +-    char   *file;
       +     char   *element_id;
       +     unsigned long element_map_key;
       +-} EditorData;
       ++} ElementEditorData;
       + 
       +-static void resume_editor(GPid pid, int status, EditorData *data);
       ++static void resume_editor(GPid pid, int status, gpointer data);
       + 
       + /**
       +  * Function called when vimb enters the input mode.
       +@@ -111,25 +110,14 @@ VbResult input_keypress(Client *c, int key)
       + VbResult input_open_editor(Client *c)
       + {
       +     static unsigned long element_map_key = 0;
       +-    char *element_id = NULL, *command = NULL;
       +-    char **argv = NULL, *file_path = NULL;
       +-    const char *text = NULL, *id = NULL, *editor_command;
       +-    int argc;
       +-    GPid pid;
       ++    char *element_id = NULL;
       ++    char *text = NULL, *id = NULL;
       +     gboolean success;
       +     GVariant *jsreturn;
       +     GVariant *idreturn;
       +-    GError *error = NULL;
       + 
       +     g_assert(c);
       + 
       +-    /* get the editor command */
       +-    editor_command = GET_CHAR(c, "editor-command");
       +-    if (!editor_command || !*editor_command) {
       +-        vb_echo(c, MSG_ERROR, TRUE, "No editor-command configured");
       +-        return RESULT_ERROR;
       +-    }
       +-
       +     /* get the selected input element */
       +     jsreturn = ext_proxy_eval_script_sync(c, "vimb_input_mode_element.value");
       +     g_variant_get(jsreturn, "(bs)", &success, &text);
       +@@ -150,78 +138,53 @@ VbResult input_open_editor(Client *c)
       +         element_id = g_strdup(id);
       +     }
       + 
       +-    /* create a temp file to pass text to and from editor */
       +-    if (!util_create_tmp_file(text, &file_path)) {
       +-        goto error;
       +-    }
       +-
       +-    /* spawn editor */
       +-    command = g_strdup_printf(editor_command, file_path);
       +-    if (!g_shell_parse_argv(command, &argc, &argv, NULL)) {
       +-        g_critical("Could not parse editor-command '%s'", command);
       +-        goto error;
       +-    }
       +-
       +-    success = g_spawn_async(
       +-        NULL, argv, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
       +-        NULL, NULL, &pid, &error
       +-    );
       +-
       +-    if (!success) {
       +-        g_warning("Could not spawn editor-command: %s", error->message);
       +-        g_error_free(error);
       +-        goto error;
       +-    }
       +-    g_strfreev(argv);
       ++    /* watch the editor process */
       ++    ElementEditorData *data = g_slice_new0(ElementEditorData);
       ++    data->element_id        = element_id;
       ++    data->element_map_key   = element_map_key;
       + 
       +     /* disable the active element */
       +     ext_proxy_lock_input(c, element_id);
       + 
       +-    /* watch the editor process */
       +-    EditorData *data = g_slice_new0(EditorData);
       +-    data->file            = file_path;
       +-    data->c               = c;
       +-    data->element_id      = element_id;
       +-    data->element_map_key = element_map_key;
       +-
       +-    g_child_watch_add(pid, (GChildWatchFunc)resume_editor, data);
       ++    if (!command_spawn_editor(c, &((Arg){0, text}), resume_editor, data)) {
       ++      goto error;
       ++    }
       + 
       +     return RESULT_COMPLETE;
       + 
       + error:
       +-    unlink(file_path);
       +-    g_free(file_path);
       +-    g_strfreev(argv);
       +     g_free(element_id);
       +     return RESULT_ERROR;
       + }
       + 
       +-static void resume_editor(GPid pid, int status, EditorData *data)
       ++static void resume_editor(GPid pid, int status, gpointer edata)
       + {
       +     char *text, *escaped;
       +     char *jscode;
       +     char *jscode_enable;
       ++    EditorData *ed = edata;
       ++    ElementEditorData *eed = (ElementEditorData *)(ed->data);
       + 
       +     g_assert(pid);
       +-    g_assert(data);
       +-    g_assert(data->c);
       +-    g_assert(data->file);
       ++    g_assert(ed);
       ++    g_assert(ed->c);
       ++    g_assert(ed->file);
       + 
       +     if (status == 0) {
       +         /* get the text the editor stored */
       +-        text = util_get_file_contents(data->file, NULL);
       ++        text = util_get_file_contents(ed->file, NULL);
       + 
       +         if (text) {
       +             escaped = util_strescape(text, NULL);
       + 
       +             /* put the text back into the element */
       +-            if (data->element_id && strlen(data->element_id) > 0) {
       +-                jscode = g_strdup_printf("document.getElementById(\"%s\").value=\"%s\"", data->element_id, escaped);
       ++            if (eed->element_id && strlen(eed->element_id) > 0) {
       ++                jscode = g_strdup_printf("document.getElementById(\"%s\").value=\"%s\"", eed->element_id, escaped);
       +             } else {
       +-                jscode = g_strdup_printf("vimb_editor_map.get(\"%lu\").value=\"%s\"", data->element_map_key, escaped);
       ++                jscode = g_strdup_printf("vimb_editor_map.get(\"%lu\").value=\"%s\"", eed->element_map_key, escaped);
       +             }
       + 
       +-            ext_proxy_eval_script(data->c, jscode, NULL);
       ++            ext_proxy_eval_script(ed->c, jscode, NULL);
       + 
       +             g_free(jscode);
       +             g_free(escaped);
       +@@ -229,17 +192,18 @@ static void resume_editor(GPid pid, int status, EditorData *data)
       +         }
       +     }
       + 
       +-    if (data->element_id && strlen(data->element_id) > 0) {
       +-        ext_proxy_unlock_input(data->c, data->element_id);
       ++    if (eed->element_id && strlen(eed->element_id) > 0) {
       ++        ext_proxy_unlock_input(ed->c, eed->element_id);
       +     } else {
       +         jscode_enable = g_strdup_printf(JS_FOCUS_EDITOR_MAP_ELEMENT,
       +-                data->element_map_key, data->element_map_key);
       +-        ext_proxy_eval_script(data->c, jscode_enable, NULL);
       ++                eed->element_map_key, eed->element_map_key);
       ++        ext_proxy_eval_script(ed->c, jscode_enable, NULL);
       +         g_free(jscode_enable);
       +     }
       +-    g_unlink(data->file);
       +-    g_free(data->file);
       +-    g_free(data->element_id);
       +-    g_slice_free(EditorData, data);
       ++    g_unlink(ed->file);
       ++    g_free(ed->file);
       ++    g_free(eed->element_id);
       ++    g_slice_free(ElementEditorData, eed);
       ++    g_slice_free(EditorData, ed);
       +     g_spawn_close_pid(pid);
       + }
       +diff --git src/normal.c src/normal.c
       +index 02ba27b..5ceb862 100644
       +--- src/normal.c
       ++++ src/normal.c
       +@@ -76,6 +76,7 @@ static VbResult normal_view_inspector(Client *c, const NormalCmdInfo *info);
       + static VbResult normal_view_source(Client *c, const NormalCmdInfo *info);
       + static VbResult normal_yank(Client *c, const NormalCmdInfo *info);
       + static VbResult normal_zoom(Client *c, const NormalCmdInfo *info);
       ++static void resume_editor(GPid pid, int status, gpointer edata);
       + 
       + static struct {
       +     NormalCommand func;
       +@@ -743,8 +744,42 @@ static VbResult normal_view_inspector(Client *c, const NormalCmdInfo *info)
       + 
       + static VbResult normal_view_source(Client *c, const NormalCmdInfo *info)
       + {
       +-    /* TODO the source mode isn't supported anymore use external editor for this */
       ++    gboolean success;
       ++    char *text = NULL;
       ++    GVariant *jsreturn;
       ++
       ++    /* get the selected input element */
       ++    jsreturn = ext_proxy_eval_script_sync(c, "document.documentElement.innerHTML");
       ++    g_variant_get(jsreturn, "(bs)", &success, &text);
       ++
       ++    if (!success || !text) {
       ++        goto error;
       ++    }
       ++
       ++    if (!command_spawn_editor(c, &((Arg){0, text}), resume_editor, NULL)) {
       ++      goto error;
       ++    }
       ++
       +     return RESULT_COMPLETE;
       ++
       ++error:
       ++    g_free(text);
        +    return RESULT_ERROR;
        +}
        +
       -+static void resume_normal_view_editor(GPid pid, int status, char *file)
       ++static void resume_editor(GPid pid, int status, gpointer edata)
        +{
       ++    EditorData *ed = edata;
       ++
        +    g_assert(pid);
       -+    g_assert(file);
       ++    g_assert(ed);
       ++    g_assert(ed->c);
       ++    g_assert(ed->file);
        +
       -+    unlink(file);
       -+    g_free(file);
       ++    unlink(ed->file);
       ++    g_free(ed->file);
       ++    g_slice_free(EditorData, ed);
        +    g_spawn_close_pid(pid);
         }