SlickEdit Community

SlickEdit Product Discussion => SlickEdit® => SlickEdit User Macros => Topic started by: Graeme on December 20, 2018, 01:06:52 am

Title: cpp web search
Post by: Graeme on December 20, 2018, 01:06:52 am
These two macros allow searching the cplusplus (search_cpp_ref) website or the devdocs website for the word at the cursor.  In the case of devdocs it comes up with the cursor in a search box and you have to use Ctrl V (paste) <Enter> to do the search.  The word at the cursor is automatically copied to the clipboard before the devdocs web page is opened.  In the case of cplusplus.com if there are multiple possibilities then a google search result page appears, otherwise it goes straight to the information.  e.g. search for memcpy goes straight to the page but search for wait, presents a list of possibilities.

Code: [Select]
static _str get_search_cur_word()
{
   int start_col = 0;
   word := "";
   if (select_active2()) {
      if (!_begin_select_compare()&&!_end_select_compare()) {
         /* get text out of selection */
         last_col := 0;
         buf_id   := 0;
         _get_selinfo(start_col,last_col,buf_id);
         if (_select_type('','I')) ++last_col;
         if (_select_type()=='LINE') {
            get_line(auto line);
            word=line;
            start_col=0;
         } else {
            word=_expand_tabsc(start_col,last_col-start_col);
         }
         _deselect();
      }else{
         deselect();
         word=cur_word(start_col,'',1);
      }
   }else{
      word=cur_word(start_col,'',1);
   }
   return word;
}


_command void search_cpp_ref() name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_EDITORCTL)
{
   _str sw = get_search_cur_word();
   if (sw == '')
      return;

   goto_url("http://www.google.com/search?q=" :+ sw :+ "&as_sitesearch=cplusplus.com&btnI");
}

_command void search_devdocs_cpp() name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_EDITORCTL)
{
   _str sw = get_search_cur_word();
   if (sw == '')
      return;

   push_clipboard_itype('CHAR','',1,true);
   append_clipboard_text(sw);
   goto_url("https://devdocs.io/cpp/");
}
Title: Re: cpp web search
Post by: Graeme on December 20, 2018, 08:20:24 pm
oops, left off the get-search-cur-word function.  I'll post it soon.
[fixed]