1. Auto-completion in ed.ex
Can anyone please tell me whether it's easy to tweak ed.ex such that when I
type "if" (and press Enter), it will automatically complete the construct:
if then
else
end if
Oh, and if it is easy, can someone please tell me how to do it?
Thank you
Alex Caracatsanis
2. Re: Auto-completion in ed.ex
Alex Caracatsanis wrote:
>
> Can anyone please tell me whether it's easy to tweak ed.ex such that when I
> type "if" (and press Enter), it will automatically complete the construct:
> }}}
<eucode>
> if then
>
> else
>
> end if
> </eucode>
{{{
> Oh, and if it is easy, can someone please tell me how to do it?
>
> Thank you
>
> Alex Caracatsanis
Short answer... yes, it can be done, but I doubt its worth
doing to save only 4 keystrokes.
Ed.ex almost does that now: Expandable words which are found
in the constant expand_word are automatically completed after
the word is typed and a space is entered.
if<space> currently expands to:
if then
end if
Do you really want to change that so that every if statement
expands to an "if then else end if" construct? Or is it you
just want to differentiate a new "if then else end if" construct
by use of the enter key in lieu of the space key?
-- make sure this constant at line 153 is set to true.
constant WANT_AUTO_COMPLETE = TRUE -- FALSE if you don't want
-- auto-completion of Euphoria statements
-- The relevant code starts at line 1,970 with the comment:
-- expandable words & corresponding text
constant expand_word = {"if", "for", "while", "elsif",
"procedure", "type", "function"},
expand_text = {" then", "= to by do", " do", " then",
"()", "()", "()"
}
procedure try_auto_complete(char key)
-- check for a keyword that can be automatically completed
sequence word, this_line, white_space, leading_white, begin
natural first_non_blank, wordnum
if key = ' ' then
insert(key)
end if
this_line = buffer[b_line]
white_space = this_line = ' ' or this_line = '\t'
first_non_blank = find(0, white_space) -- there's always '\n' at end
leading_white = this_line[1..first_non_blank - 1]
if auto_complete and first_non_blank < b_col - 2 then
if not find(0, white_space[b_col..length(white_space)-1]) then
word = this_line[first_non_blank..b_col - 1 - (key = ' ')]
wordnum = find(word, expand_word)
if key = CR and equal(word, "else") then
leading_white &= '\t'
elsif wordnum > 0 then
sound(1000)
-- expandable word (only word on line)
begin = expand_text[wordnum] & CR & leading_white
if equal(word, "elsif") then
insert_string(begin & '\t')
elsif find(word, {"function", "type"}) then
insert_string(begin & CR &
leading_white & "\treturn" & CR &
"end " & expand_word[wordnum])
else
insert_string(begin & '\t' & CR &
leading_white &
"end " & expand_word[wordnum])
end if
delay(0.07) -- or beep is too short
sound(0)
end if
end if
end if
if key = CR then
if b_col >= first_non_blank then
buffer[b_line] = buffer[b_line][1..b_col-1] & leading_white &
buffer[b_line][b_col..length(buffer[b_line])]
insert(CR)
skip_white()
else
insert(CR)
end if
end if
end procedure
Ken Rhodes
Folding at Home: http://folding.stanford.edu/
100% MicroSoft Free
SuSE Linux 10.3
No AdWare, SpyWare, or Viruses!
Life is Good,