/* Pull Completion for Epsilon Version 10. * control-Up and control-Down fetch the previous or next match for the * word preceding the insertion point. * Author Jim Morris, splash@wolfman.com */ #include "eel.h" /* standard definitions */ #define IDENT_PATTERN "[a-zA-Z0-9_\xC0-\xD6\xD8-\xF6\xF8-\xFF]+" // Matches an identifier. int comp_last_pos= -1; int comp_last_match_s= -1; int comp_last_match_e= -1; int comp_last_dir= 0; // handles both directions int comp_find(int dir) { char lword[FNAMELEN], fword[FNAMELEN]; int cont= 0; int oldpos= point; say(""); if(point == comp_last_pos){ // continuing, so find next occurence undo_op(1); // undo the last match oldpos= point; cont= 1; } // create match text by selecting the preceding identifier if (!parse_string(-1, IDENT_PATTERN, lword)){ comp_last_pos= -1; point= oldpos; maybe_ding(1); say("No Identifier at cursor"); return 0; } if(cont == 0){ point = (dir == -1) ? matchend : matchstart; // start search from just before or after current identifier }else{ point = (dir == comp_last_dir) ? comp_last_match_e : comp_last_match_s; // start search from last match } // search for a match do{ if (!search(dir, lword)){ comp_last_pos= -1; point= oldpos; maybe_ding(1); say("No Match"); return 0; } } while(oldpos == matchstart || oldpos == matchend); // don't match itself comp_last_match_s= matchstart; comp_last_match_e= matchend; comp_last_dir= dir; // on finding a match copy the entire word if (!parse_string(1, IDENT_PATTERN, fword)){ comp_last_pos= -1; point= oldpos; maybe_ding(1); say("No Identifier copied"); return 0; } // insert found text appending as much as needed to complete point= oldpos; if(dir == -1) stuff(fword+strlen(lword)); // fill in rest of word else stuff(fword); comp_last_pos= point; return 1; } command comp_find_prev() on reg_tab[NUMCTRL(KEYUP)] { comp_find(-1); } command comp_find_next() on reg_tab[NUMCTRL(KEYDOWN)] { comp_find(1); }