Skip to content
Snippets Groups Projects
Commit 400e7e87 authored by David Hedbor's avatar David Hedbor
Browse files

Added lowercase, uppercase and capitalize. Fixed backward word.

Rev: lib/modules/Stdio.pmod/Readline.pike:1.12
parent fdf0693d
Branches
Tags
No related merge requests found
// $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,7 +545,7 @@ class InputController
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,6 +618,43 @@ class DefaultEditKeys
_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,13 +669,16 @@ class DefaultEditKeys
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,9 +697,10 @@ class DefaultEditKeys
{
_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,6 +753,12 @@ class DefaultEditKeys
({ "\\!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 }),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment