Branch: Tag:

1999-04-25

1999-04-25 08:29:28 by David Hedbor <david@hedbor.org>

Added lowercase, uppercase and capitalize. Fixed backward word.

Rev: lib/modules/Stdio.pmod/Readline.pike:1.12

1: - // $Id: Readline.pike,v 1.11 1999/04/12 02:23:12 hubbe Exp $ + // $Id: Readline.pike,v 1.12 1999/04/25 08:29:28 neotron Exp $      class OutputController   {
545:      class DefaultEditKeys   { -  static private multiset word_break_chars = mkmultiset("\t \n\r/*?_-.[]~&;\!#$%^(){}<>"/""); +  static private multiset word_break_chars = mkmultiset("\t \n\r/*?_-.[]~&;\!#$%^(){}<>\""/"");    static object _readline;       void self_insert_command(string str)
618:    _readline->insert(reverse(c), p-1);    }    +  array find_word_to_manipulate() +  { +  int p = _readline->getcursorpos(); +  int ep; +  string line = _readline->gettext(); +  while(word_break_chars[ line[p..p] ] && p < strlen(line)) +  p++; +  if(p >= strlen(line)) { +  _readline->setcursorpos(p); +  return ({ 0, 0 }); +  } +  ep = forward_find_word(); +  _readline->delete(p, ep); +  return ({ line[p..ep-1], p }); +  } +  +  void capitalize_word() +  { +  [string word, string pos]= find_word_to_manipulate(); +  if(word) +  _readline->insert(String.capitalize(lower_case(word)), pos); +  } +  +  void upper_case_word() +  { +  [string word, string pos]= find_word_to_manipulate(); +  if(word) +  _readline->insert(upper_case(word), pos); +  } +  +  void lower_case_word() +  { +  [string word, string pos]= find_word_to_manipulate(); +  if(word) +  _readline->insert(lower_case(word), pos); +  } +     int forward_find_word()    {    int p, n;
632:       int backward_find_word()    { -  int p = _readline->getcursorpos() , n; +  int p = _readline->getcursorpos()-1;    string line = _readline->gettext();    if(p >= strlen(line)) p = strlen(line) - 1; -  for(; p >= 0; p--) { +  while(word_break_chars[ line[p..p] ] && p >= 0) +  // find first "non break char" +  p--; +  for(;p >= 0; p--)    if(word_break_chars[ line[p..p] ]) { -  if(n) break; -  } else n = 1; +  p++; // We want to be one char before the break char. +  break;    }    return p;    }
657:    {    _readline->delete(_readline->getcursorpos(), forward_find_word());    } +     void backward_delete_word()    { -  int sp = backward_find_word() + 1; +  int sp = backward_find_word();    int ep = _readline->getcursorpos();    if((ep - sp) == 0)    sp--;
712:    ({ "\\!kd", down_history }),    ({ "\\!kr", forward_char }),    ({ "\\!kl", backward_char }), +  ({ "^[C", capitalize_word }), +  ({ "^[c", capitalize_word }), +  ({ "^[U", upper_case_word }), +  ({ "^[u", upper_case_word }), +  ({ "^[L", lower_case_word }), +  ({ "^[l", lower_case_word }),    ({ "^[D", forward_delete_word }),    ({ "^[^H", backward_delete_word }),    ({ "^[^?", backward_delete_word }),