Skip to content

Commit

Permalink
Export some more functions to perl.
Browse files Browse the repository at this point in the history
get_region, combined with save_excursion, is a very convenient way for
perl to access a specified piece of the buffer.

In addition, provide methods to get information about the current
point and mark.
  • Loading branch information
nelhage committed Jul 11, 2009
1 parent cf26b72 commit d41294a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
35 changes: 32 additions & 3 deletions editwin.c
Expand Up @@ -58,7 +58,6 @@ static gunichar owl_editwin_get_char_at_point(owl_editwin *e);
static int owl_editwin_replace_internal(owl_editwin *e, int replace, char *s);
static char *oe_copy_buf(owl_editwin *e, char *buf, int len);
static int oe_copy_region(owl_editwin *e);
static int oe_display_column(owl_editwin *e);
static char *oe_chunk(owl_editwin *e, int start, int end);

#define INCR 4096
Expand Down Expand Up @@ -1112,7 +1111,7 @@ void owl_editwin_forward_paragraph(owl_editwin *e)
}
}

static int oe_display_column(owl_editwin *e)
int owl_editwin_current_column(owl_editwin *e)
{
oe_excursion x;
int lineindex;
Expand Down Expand Up @@ -1183,7 +1182,7 @@ void owl_editwin_fill_paragraph(owl_editwin *e)
/* Now go through inserting newlines as needed */
while(e->index < e->mark) {
/* if we've travelled too far, linewrap */
if (oe_display_column(e) >= e->fillcol)
if (owl_editwin_current_column(e) >= e->fillcol)
_owl_editwin_linewrap_word(e);
owl_editwin_point_move(e, 1);
}
Expand Down Expand Up @@ -1322,6 +1321,20 @@ char *owl_editwin_get_text(owl_editwin *e)
return(e->buff+e->lock);
}

char *owl_editwin_get_region(owl_editwin *e)
{
int start, end;
start = e->index;
end = e->mark;
if(start > end) {
int tmp = end;
end = start;
start = tmp;
}

return oe_chunk(e, start, end);
}

int owl_editwin_get_echochar(owl_editwin *e)
{
return e->echochar;
Expand All @@ -1348,6 +1361,22 @@ char *owl_editwin_text_after_point(owl_editwin *e)
return oe_chunk(e, e->index, e->bufflen);
}

/*
* The only guarantee made about these values is that comparisons
* between them, as well as comparison between multiple calls to these
* functions without modifying the editwin in-between, are meaningful.
*/

int owl_editwin_get_point(owl_editwin *e)
{
return e->index;
}

int owl_editwin_get_mark(owl_editwin *e)
{
return e->mark;
}


/*
* Local Variables:
Expand Down
3 changes: 2 additions & 1 deletion perl/lib/BarnOwl/Editwin.pm
Expand Up @@ -17,6 +17,7 @@ package BarnOwl::Editwin;
use base qw(Exporter);

our @EXPORT_OK = qw(text_before_point text_after_point replace
point_move replace_region save_excursion);
point_move replace_region get_region
save_excursion current_column point mark);

1;
33 changes: 33 additions & 0 deletions perlglue.xs
Expand Up @@ -482,6 +482,18 @@ replace_region(string)
OUTPUT:
RETVAL

char *
get_region()
PREINIT:
char *region;
CODE:
region = owl_editwin_get_region(owl_global_get_typwin(&g));
RETVAL = region;
OUTPUT:
RETVAL
CLEANUP:
owl_free(region);

SV *
save_excursion(sub)
SV *sub;
Expand All @@ -508,3 +520,24 @@ save_excursion(sub)
}
OUTPUT:
RETVAL

int
current_column()
CODE:
RETVAL = owl_editwin_current_column(owl_global_get_typwin(&g));
OUTPUT:
RETVAL

int
point()
CODE:
RETVAL = owl_editwin_get_point(owl_global_get_typwin(&g));
OUTPUT:
RETVAL

int
mark()
CODE:
RETVAL = owl_editwin_get_mark(owl_global_get_typwin(&g));
OUTPUT:
RETVAL

0 comments on commit d41294a

Please sign in to comment.