Re: [Evolution] [PATCH][BUILD] make external editor plugin pass cursor pos to vim
- From: "Bharath Acharya" <abharath novell com>
- To: <jreidthompson nc rr com>
- Cc: evolution-list gnome org
- Subject: Re: [Evolution] [PATCH][BUILD] make external editor plugin pass cursor pos to vim
- Date: Tue, 16 Jun 2009 21:18:47 -0600
Hello Reid,
Nice work. We'll fix the other minor issues. Let us track this on
bugzilla.gnome Do file a bug for this and Cc me in there. TIA
Regards,
--Bharath
On Tue, 2009-06-16 at 15:40 -0400, Reid Thompson wrote:
This appears to work for me, opening the email in gvim with the cursor
properly located.
Along with a review, it likely needs a 'quickfix' with regard to the
htmlengine.h include. I'm not familiar enough with the build environment
to know if there is a more proper/correct way of getting it included.
There is also a single change to mono-plugin.c that I had to make in order to
get mono-plugin.c to compile.
Signed-off-by: Reid Thompson <jreidthompson nc rr com>
---
plugins/external-editor/external-editor.c | 66 ++++++++++++++++++++++++++++-
plugins/mono/mono-plugin.c | 2 +-
2 files changed, 66 insertions(+), 2 deletions(-)
diff --git a/plugins/external-editor/external-editor.c b/plugins/external-editor/external-editor.c
index a7f06b6..0ed4d8f 100644
--- a/plugins/external-editor/external-editor.c
+++ b/plugins/external-editor/external-editor.c
@@ -34,6 +34,8 @@
#include <e-msg-composer.h>
#include <camel/camel-mime-filter-tohtml.h>
+#include "/media/disk-1/home/evo-src/git/gtkhtml/gtkhtml/htmlengine.h"
+
#include <glib/gi18n-lib.h>
#include <glib-object.h>
#include <glib.h>
@@ -62,6 +64,7 @@ static void ee_editor_immediate_launch_changed (GtkWidget *checkbox);
static void async_external_editor (EMsgComposer *composer);
static gboolean editor_running (void);
static gboolean key_press_cb(GtkWidget * widget, GdkEventKey * event, EMsgComposer *composer);
+static gint numlines(gchar *text, gint pos);
/* used to track when the external editor is active */
static GThread *editor_thread;
@@ -214,8 +217,19 @@ async_external_editor (EMsgComposer *composer)
GConfClient *gconf;
gchar *editor_cmd_line = NULL;
gint fd;
+ GtkHTML *html;
+ GtkhtmlEditor *editor;
+ gint cursor_position = 0;
+ gint cursor_offset = 0;
+ gint lineno = 0;
+ gchar *contents;
+ gchar *linenostr;
+ gchar *cursor_offsetstr;
+ gsize length = 0;
- fd = g_file_open_tmp (NULL, &filename, NULL);
+
+ /* prefix temp files with evo so .*vimrc can be setup to recognize them */
+ fd = g_file_open_tmp ("evoXXXXXX", &filename, NULL);
if (fd > 0) {
close (fd);
/* Push the text (if there is one) from the composer to the file */
@@ -242,6 +256,35 @@ async_external_editor (EMsgComposer *composer)
}
g_object_unref (gconf);
+ /* if gvim is editor, configure editor_cmd_line to pass cursor location */
+ if (g_strrstr(editor_cmd_line, "vim") != NULL)
+ {
+ editor = GTKHTML_EDITOR (composer);
+ html = gtkhtml_editor_get_html (editor);
+ cursor_position = html->engine->cursor->position;
+ cursor_offset = html->engine->cursor->offset;
+
+ /* increment 1 so that entering vim insert mode places you in the same
+ * entry position you were at in the html */
+ ++cursor_offset;
+
+ /* calculate the line number that the cursor is in */
+ contents = gtkhtml_editor_get_text_plain (editor, &length);
+ lineno = numlines(contents, cursor_position);
+ g_free(contents);
+
+ /* setup the editor_cmd_line */
+ editor_cmd_line = g_strconcat(editor_cmd_line, " \"+call cursor(", NULL);
+ linenostr = g_strdup_printf("%d", lineno);
+ editor_cmd_line = g_strconcat(editor_cmd_line, linenostr, NULL);
+ editor_cmd_line = g_strconcat(editor_cmd_line, ",", NULL);
+ cursor_offsetstr = g_strdup_printf("%d", cursor_offset);
+ editor_cmd_line = g_strconcat(editor_cmd_line, cursor_offsetstr, NULL);
+ editor_cmd_line = g_strconcat(editor_cmd_line, ")\"", NULL);
+ g_free(linenostr);
+ g_free(cursor_offsetstr);
+ }
+
editor_cmd_line = g_strconcat(editor_cmd_line, " ", filename, NULL);
if (!g_spawn_command_line_sync(editor_cmd_line, NULL, NULL, &status, NULL))
@@ -393,3 +436,24 @@ e_plugin_ui_init (GtkUIManager *manager, EMsgComposer *composer)
return TRUE;
}
+
+static gint
+numlines(gchar *text, gint pos)
+{
+ gint ctr = 0;
+ gint lineno = 0;
+
+ for (ctr = 0; ctr <= pos; ++ctr)
+ {
+ if (text[ctr] == '\n')
+ {
+ ++lineno;
+ }
+ }
+ if (lineno > 0)
+ {
+ ++lineno;
+ }
+
+ return(lineno);
+}
diff --git a/plugins/mono/mono-plugin.c b/plugins/mono/mono-plugin.c
index 76b1e42..86bbb43 100644
--- a/plugins/mono/mono-plugin.c
+++ b/plugins/mono/mono-plugin.c
@@ -159,7 +159,7 @@ epm_invoke(EPlugin *ep, const gchar *name, gpointer data)
if (res) {
gpointer *p = mono_object_unbox(res);
- d(printf("mono method returned '%p' %ld\n", *p, (long gint)*p));
+ d(printf("mono method returned '%p' %ld\n", *p, (long int)*p));
return *p;
} else
return NULL;
--
1.6.0.6
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]