[2860] in BarnOwl Developers
Re: [PATCH] Replace per-editwin killbuf with a global one.
daemon@ATHENA.MIT.EDU (Nelson Elhage)
Wed Jan 5 10:11:56 2011
In-Reply-To: <1294195630-770-1-git-send-email-adam@crossproduct.net>
Date: Wed, 5 Jan 2011 10:11:54 -0500
From: Nelson Elhage <nelhage@nelhage.com>
To: Adam Glasgall <adam@crossproduct.net>
Cc: barnowl-dev@mit.edu
Looks good, thanks! Pushed.
- Nelson
On Tue, Jan 4, 2011 at 9:47 PM, Adam Glasgall <adam@crossproduct.net> wrote=
:
> 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.
> ---
> =C2=A0editwin.c | =C2=A0 20 +++++++++-----------
> =C2=A0global.c =C2=A0| =C2=A0 =C2=A09 +++++++++
> =C2=A0owl.h =C2=A0 =C2=A0 | =C2=A0 =C2=A01 +
> =C2=A03 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*/
> =C2=A0 int allocated;
> =C2=A0 int index;
> =C2=A0 int mark;
> - =C2=A0char *killbuf;
> =C2=A0 int goal_column;
> =C2=A0 int topindex;
> =C2=A0 int column;
> @@ -87,7 +86,6 @@ static void _owl_editwin_delete(owl_editwin *e)
> =C2=A0 =C2=A0 g_object_unref(e->win);
> =C2=A0 }
> =C2=A0 owl_free(e->buff);
> - =C2=A0owl_free(e->killbuf);
> =C2=A0 /* just in case someone forgot to clean up */
> =C2=A0 while (e->excursions) {
> =C2=A0 =C2=A0 oe_release_excursion(e, e->excursions);
> @@ -131,9 +129,6 @@ static void _owl_editwin_init(owl_editwin *e,
> =C2=A0 e->allocated=3DINCR;
> =C2=A0 oe_set_index(e, 0);
> =C2=A0 oe_set_mark(e, -1);
> - =C2=A0if (e->killbuf !=3D NULL)
> - =C2=A0 =C2=A0owl_free(e->killbuf);
> - =C2=A0e->killbuf =3D NULL;
> =C2=A0 e->goal_column =3D -1;
> =C2=A0 e->column =3D -1;
> =C2=A0 e->topindex =3D 0;
> @@ -1065,21 +1060,24 @@ void owl_editwin_delete_to_endofline(owl_editwin =
*e)
>
> =C2=A0void owl_editwin_yank(owl_editwin *e)
> =C2=A0{
> - =C2=A0if (e->killbuf !=3D NULL)
> - =C2=A0 =C2=A0owl_editwin_replace(e, 0, e->killbuf);
> + =C2=A0char *killbuf =3D owl_global_get_kill_buffer(&g);
> +
> + =C2=A0if (killbuf !=3D NULL)
> + =C2=A0 =C2=A0owl_editwin_replace(e, 0, killbuf);
> =C2=A0}
>
> =C2=A0static const char *oe_copy_buf(owl_editwin *e, const char *buf, int=
len)
> =C2=A0{
> =C2=A0 char *p;
> + =C2=A0char *killbuf =3D owl_global_get_kill_buffer(&g);
>
> =C2=A0 p =3D owl_malloc(len + 1);
>
> =C2=A0 if (p !=3D NULL) {
> - =C2=A0 =C2=A0owl_free(e->killbuf);
> - =C2=A0 =C2=A0e->killbuf =3D p;
> - =C2=A0 =C2=A0memcpy(e->killbuf, buf, len);
> - =C2=A0 =C2=A0e->killbuf[len] =3D 0;
> + =C2=A0 =C2=A0owl_free(killbuf);
> + =C2=A0 =C2=A0memcpy(p, buf, len);
> + =C2=A0 =C2=A0p[len] =3D 0;
> + =C2=A0 =C2=A0owl_global_set_kill_buffer(&g,p);
> =C2=A0 }
>
> =C2=A0 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) {
> =C2=A0 owl_list_create(&(g->psa_list));
> =C2=A0 g->timerlist =3D NULL;
> =C2=A0 g->interrupted =3D FALSE;
> + =C2=A0g->kill_buffer =3D NULL;
> =C2=A0}
>
> =C2=A0static void _owl_global_init_windows(owl_global *g)
> @@ -988,3 +989,11 @@ FILE *owl_global_get_debug_file_handle(owl_global *g=
) {
> =C2=A0 }
> =C2=A0 return g->debug_file;
> =C2=A0}
> +
> +char *owl_global_get_kill_buffer(owl_global *g) {
> + =C2=A0return g->kill_buffer;
> +}
> +
> +void owl_global_set_kill_buffer(owl_global *g,char *kill) {
> + =C2=A0g->kill_buffer =3D 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 {
> =C2=A0 int load_initial_subs;
> =C2=A0 volatile sig_atomic_t interrupted;
> =C2=A0 FILE *debug_file;
> + =C2=A0char *kill_buffer;
> =C2=A0} owl_global;
>
> =C2=A0/* globals */
> --
> 1.7.1
>
>