[2856] in BarnOwl Developers
[PATCH] Replace per-editwin killbuf with a global one.
daemon@ATHENA.MIT.EDU (Adam Glasgall)
Tue Jan 4 21:47:27 2011
From: Adam Glasgall <adam@crossproduct.net>
To: barnowl-dev@mit.edu
Cc: Adam Glasgall <adam@crossproduct.net>
Date: Tue, 4 Jan 2011 21:47:10 -0500
Right now, the kill buffer is part of a struct _owl_editwin, which
means that it goes away when the editwin does - rather inconvenient if
you realize mid-paragraph that you're sending to the wrong class. This
patch adds a global for the killbuf (and its accessors), modifies the
editwin kill/yank functions to use it, and removes the old per-editwin
killbuf.
---
editwin.c | 20 +++++++++-----------
global.c | 9 +++++++++
owl.h | 1 +
3 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/editwin.c b/editwin.c
index 62600e1..5bc9d1f 100644
--- a/editwin.c
+++ b/editwin.c
@@ -23,7 +23,6 @@ struct _owl_editwin { /*noproto*/
int allocated;
int index;
int mark;
- char *killbuf;
int goal_column;
int topindex;
int column;
@@ -87,7 +86,6 @@ static void _owl_editwin_delete(owl_editwin *e)
g_object_unref(e->win);
}
owl_free(e->buff);
- owl_free(e->killbuf);
/* just in case someone forgot to clean up */
while (e->excursions) {
oe_release_excursion(e, e->excursions);
@@ -131,9 +129,6 @@ static void _owl_editwin_init(owl_editwin *e,
e->allocated=INCR;
oe_set_index(e, 0);
oe_set_mark(e, -1);
- if (e->killbuf != NULL)
- owl_free(e->killbuf);
- e->killbuf = NULL;
e->goal_column = -1;
e->column = -1;
e->topindex = 0;
@@ -1065,21 +1060,24 @@ void owl_editwin_delete_to_endofline(owl_editwin *e)
void owl_editwin_yank(owl_editwin *e)
{
- if (e->killbuf != NULL)
- owl_editwin_replace(e, 0, e->killbuf);
+ char *killbuf = owl_global_get_kill_buffer(&g);
+
+ if (killbuf != NULL)
+ owl_editwin_replace(e, 0, killbuf);
}
static const char *oe_copy_buf(owl_editwin *e, const char *buf, int len)
{
char *p;
+ char *killbuf = owl_global_get_kill_buffer(&g);
p = owl_malloc(len + 1);
if (p != NULL) {
- owl_free(e->killbuf);
- e->killbuf = p;
- memcpy(e->killbuf, buf, len);
- e->killbuf[len] = 0;
+ owl_free(killbuf);
+ memcpy(p, buf, len);
+ p[len] = 0;
+ owl_global_set_kill_buffer(&g,p);
}
return p;
diff --git a/global.c b/global.c
index c5dc49f..9bab3ac 100644
--- a/global.c
+++ b/global.c
@@ -124,6 +124,7 @@ void owl_global_init(owl_global *g) {
owl_list_create(&(g->psa_list));
g->timerlist = NULL;
g->interrupted = FALSE;
+ g->kill_buffer = NULL;
}
static void _owl_global_init_windows(owl_global *g)
@@ -988,3 +989,11 @@ FILE *owl_global_get_debug_file_handle(owl_global *g) {
}
return g->debug_file;
}
+
+char *owl_global_get_kill_buffer(owl_global *g) {
+ return g->kill_buffer;
+}
+
+void owl_global_set_kill_buffer(owl_global *g,char *kill) {
+ g->kill_buffer = kill;
+}
diff --git a/owl.h b/owl.h
index 801bae0..8439edd 100644
--- a/owl.h
+++ b/owl.h
@@ -650,6 +650,7 @@ typedef struct _owl_global {
int load_initial_subs;
volatile sig_atomic_t interrupted;
FILE *debug_file;
+ char *kill_buffer;
} owl_global;
/* globals */
--
1.7.1