Changeset a88f35a


Ignore:
Timestamp:
Jul 11, 2009, 1:14:36 PM (15 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
cf26b72
Parents:
0190c4d
git-author:
Nelson Elhage <nelhage@mit.edu> (06/20/09 23:45:56)
git-committer:
Nelson Elhage <nelhage@mit.edu> (07/11/09 13:14:36)
Message:
Give perl code more rope with respect to the editwin.

In particular, implement save_excursion and replace_region.
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • editwin.c

    r19a023f ra88f35a  
    99#define VALID_EXCURSION (0x9a2b4729)
    1010
    11 typedef struct oe_excursion_struct { /*noproto*/
     11typedef struct _owl_editwin_excursion { /*noproto*/
    1212  int valid;
    1313  int index;
     
    1515  int goal_column;
    1616  int lock;
    17   struct oe_excursion_struct *next;
     17  struct _owl_editwin_excursion *next;
    1818} oe_excursion;
    1919
     
    365365    oe_release_excursion(e, x);
    366366  }
     367}
     368
     369/* External interface to oe_save_excursion */
     370owl_editwin_excursion *owl_editwin_begin_excursion(owl_editwin *e)
     371{
     372  owl_editwin_excursion *x = owl_malloc(sizeof *x);
     373  oe_save_excursion(e, x);
     374  return x;
     375}
     376
     377void owl_editwin_end_excursion(owl_editwin *e, owl_editwin_excursion *x)
     378{
     379  oe_restore_excursion(e, x);
     380  owl_free(x);
    367381}
    368382
     
    565579}
    566580
     581int owl_editwin_replace_region(owl_editwin *e, char *s)
     582{
     583  oe_excursion x;
     584  oe_save_excursion(e, &x);
     585  int ret;
     586
     587  if(e->index > e->mark) {
     588    owl_editwin_exchange_point_and_mark(e);
     589  }
     590
     591  ret = owl_editwin_replace_internal(e, e->mark - e->index, s);
     592
     593  oe_restore_excursion(e, &x);
     594
     595  return ret;
     596}
     597
    567598/* replace 'replace' characters at the point with s, returning the change in size */
    568599int owl_editwin_replace(owl_editwin *e, int replace, char *s)
  • owl.h

    ra556caa ra88f35a  
    425425
    426426typedef struct _owl_editwin owl_editwin;
     427typedef struct _owl_editwin_excursion owl_editwin_excursion;
    427428
    428429typedef struct _owl_keybinding {
  • perlglue.xs

    r0190c4d ra88f35a  
    474474        OUTPUT:
    475475                RETVAL
     476
     477int
     478replace_region(string)
     479        char *string;
     480        CODE:
     481                RETVAL = owl_editwin_replace_region(owl_global_get_typwin(&g), string);
     482        OUTPUT:
     483                RETVAL
     484
     485SV *
     486save_excursion(sub)
     487        SV *sub;
     488        PROTOTYPE: &
     489        PREINIT:
     490                int count;
     491                owl_editwin_excursion *x;
     492        CODE:
     493        {
     494                x = owl_editwin_begin_excursion(owl_global_get_typwin(&g));
     495                count = call_sv(sub, G_SCALAR|G_EVAL|G_NOARGS);
     496                owl_editwin_end_excursion(owl_global_get_typwin(&g), x);
     497
     498                if(SvTRUE(ERRSV)) {
     499                        croak(NULL);
     500                }
     501
     502                SPAGAIN;
     503                if(count == 1)
     504                        RETVAL = SvREFCNT_inc(POPs);
     505                else
     506                        XSRETURN_UNDEF;
     507
     508        }
     509        OUTPUT:
     510                RETVAL
Note: See TracChangeset for help on using the changeset viewer.