#include "eel.h" keytable ruby_tab; /* * Get Ruby help using the Ruby ri command * ri must be installed on your path * The SHIFT-F1 key triggers the help. * Whatever is highlighted will be passed as the argument to ri, if * nothing is highighted then the preceding word is used, otherwise you will prompted for the string to lookup. * * if preceded by an argumnet (ALT-1) it will use gemri to lookup the help instead * * If there are multiple matches, a popup will let you select which one you want help on. * */ command ruby_help() on ruby_tab[NUMSHIFT(FKEY(1))] { char tag[TAGLEN]; char helpstr[70]; char cmd[10]; char *tag_pat= "[a-zA-Z_][a-zA-Z0-9_]*[!?=]?"; int oldpos= point; // find the function name to get help on, either use selected // region or previous word or prompt for it say(""); //fix_region(); if (is_highlight_on() && mark - point < sizeof(tag)){ grab(point, mark, tag); highlight_off(); }else if(!parse_string(-1, tag_pat, tag)){ get_string(tag, "Ruby Help: "); } if(has_arg) strcpy(cmd, "gemri"); else strcpy(cmd, "ri"); sprintf(helpstr, "%s -T %s", cmd, tag); pipe_text(NULL, "-rubyhelp", helpstr, NULL, PIPE_SYNCH|PIPE_CLEAR_BUF|PIPE_SKIP_SHELL , 0); // see if partial matches, and prompt for the actual one we want help on int oldbuf= bufnum; bufname= "-rubyhelp"; point= 0; if(re_search(RE_FORWARD, "More than one method matched")){ int tmpbuf= zap(_MATCH_BUF); // fill tmpbuf with list of matches move_by_lines(3); while(re_search(RE_FORWARD, "([^ ,]+),?\n?")){ int p1= find_group(1, 1); int p2= find_group(1, 0); // copy snippet names into MATCH_BUF buf_xfer(tmpbuf, p1, p2); buf_printf(tmpbuf, "\n"); } bufnum= oldbuf; buf_sort_and_uniq(tmpbuf); ungot_key = '?'; comp_read(tag, "Select Help on: ", general_matcher, MUST_MATCH | NONE_OK, ""); sprintf(helpstr, "%s -T %s", cmd, tag); pipe_text(NULL, "-rubyhelp", helpstr, NULL, PIPE_SYNCH|PIPE_CLEAR_BUF|PIPE_SKIP_SHELL , 0); }else bufnum= oldbuf; view_buffer("-rubyhelp", 0); delete_buffer("-rubyhelp"); point= oldpos; }