Changeset 7f0c26f


Ignore:
Timestamp:
Jul 11, 2009, 1:14:35 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:
a60edf2
Parents:
16cfd12a
git-author:
Nelson Elhage <nelhage@mit.edu> (07/07/09 22:49:07)
git-committer:
Nelson Elhage <nelhage@mit.edu> (07/11/09 13:14:35)
Message:
Implement a setable mark.
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • commands.c

    ra556caa r7f0c26f  
    879879                  OWL_CTX_EDIT,
    880880                  "replaces the text with the previous history",
     881                  "", ""),
     882
     883  OWLCMD_VOID_CTX("edit:set-mark", owl_editwin_set_mark,
     884                  OWL_CTX_EDIT,
     885                  "sets the mark",
     886                  "", ""),
     887
     888  OWLCMD_VOID_CTX("edit:exchange-point-and-mark", owl_editwin_exchange_point_and_mark,
     889                  OWL_CTX_EDIT,
     890                  "exchanges the point and the mark",
    881891                  "", ""),
    882892
  • editwin.c

    r16cfd12a r7f0c26f  
    9090}
    9191
     92static inline void oe_set_mark(owl_editwin *e, int mark)
     93{
     94  e->mark = mark;
     95}
     96
     97void owl_editwin_set_mark(owl_editwin *e)
     98{
     99  oe_set_mark(e, e->index);
     100  /* owl_function_makemsg("Mark set."); */
     101}
     102
    92103/* initialize the editwin e.
    93104 * 'win' is an already initialzed curses window that will be used by editwin
     
    101112  e->allocated=INCR;
    102113  oe_set_index(e, 0);
    103   e->mark = 0;
     114  oe_set_mark(e, -1);
    104115  e->goal_column = -1;
    105116  e->cursorx = -1;
     
    299310{
    300311  x->index = e->index;
     312  x->mark = e->mark;
    301313  x->goal_column = e->goal_column;
    302314  x->lock = e->lock;
     
    331343    oe_set_index(e, x->index);
    332344    e->goal_column = x->goal_column;
     345    e->mark = x->mark;
    333346    e->lock = x->lock;
    334347
     
    497510}
    498511
     512static inline void oe_fixup(int *target, int start, int end, int change) {
     513  if (*target > start) {
     514    if (*target < end)
     515      *target = end;
     516    else
     517      *target += change;
     518  }
     519}
     520
    499521/* replace count characters at the point with s, returning the change in size */
    500522static int owl_editwin_replace(owl_editwin *e, int replace, char *s)
     
    537559  e->index += strlen(s);
    538560
     561  /* fix up the mark */
     562  if (e->mark != -1)
     563    oe_fixup(&e->mark, start, end, change);
    539564  /* fix up any saved points after the replaced area */
    540   for (x = e->excursions; x != NULL; x = x->next)
    541     if (x->index > start) {
    542       if (x->index < end)
    543         x->index = end;
    544       else
    545         x->index += change;
    546     }
     565  for (x = e->excursions; x != NULL; x = x->next) {
     566    oe_fixup(&x->index, start, end, change);
     567    if (x->mark != -1)
     568      oe_fixup(&x->mark, start, end, change);
     569  }
    547570
    548571  return change;
     
    644667{
    645668  return g_utf8_get_char(e->buff + e->index);
     669}
     670
     671void owl_editwin_exchange_point_and_mark(owl_editwin *e) {
     672  int tmp;
     673
     674  if (e->mark != -1) {
     675    tmp = e->mark;
     676    owl_editwin_set_mark(e);
     677    oe_set_index(e, tmp);
     678  }
    646679}
    647680
  • keys.c

    rddf1835 r7f0c26f  
    8383
    8484  BIND_CMD("M-q",         "edit:fill-paragraph", "");
     85
     86  BIND_CMD("C-@",         "edit:set-mark", "");
     87  BIND_CMD("C-x C-x",     "edit:exchange-point-and-mark", "");
    8588
    8689  BIND_CMD("C-l",         "( edit:recenter ; redisplay )", "");
Note: See TracChangeset for help on using the changeset viewer.