Changeset d2fd2f7


Ignore:
Timestamp:
Sep 18, 2010, 5:07:40 PM (11 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.7, release-1.8, release-1.9
Children:
dcd48ad
Parents:
b6cf72f
git-author:
David Benjamin <davidben@mit.edu> (08/22/10 04:05:20)
git-committer:
David Benjamin <davidben@mit.edu> (09/18/10 17:07:40)
Message:
Add popless:start-search and bind to / and ?

The command line is considerably friendlier when it knows it's
searching.
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • commands.c

    rb6cf72f rd2fd2f7  
    10131013                  "default searches are done forwards; if -r is used the search\n"
    10141014                  "is performed backwards"),
     1015
     1016  OWLCMD_ARGS_CTX("popless:start-search", owl_viewwin_command_start_search, OWL_CTX_POPLESS,
     1017                  "starts a command line to search for particular string",
     1018                  "popless:search [-r] [inital-value]",
     1019                  "Initializes the command-line to search for initial-value. If\n"
     1020                  "-r is used, the search will be performed backwards."),
    10151021
    10161022  OWLCMD_ALIAS("webzephyr", "zwrite daemon.webzephyr -c webzephyr -i"),
  • keys.c

    rb6cf72f rd2fd2f7  
    215215  BIND_CMD("M-x",         "popless:start-command",  "start a new command");
    216216
    217   BIND_CMD("/",   "popless:start-command popless:search ", "start a search command");
    218   BIND_CMD("?",   "popless:start-command popless:search -r ", "start a reverse search command");
     217  BIND_CMD("/",   "popless:start-search", "start a search command");
     218  BIND_CMD("?",   "popless:start-search -r", "start a reverse search command");
    219219  BIND_CMD("n",   "popless:search", "find next occurrence of search");
    220220  BIND_CMD("N",   "popless:search -r", "find previous occurrence of search");
  • viewwin.c

    rb6cf72f rd2fd2f7  
    163163  if (!owl_viewwin_search(v, owl_global_get_search_re(&g), mode, direction))
    164164    owl_function_error("No more matches");
     165  return NULL;
     166}
     167
     168typedef struct _owl_viewwin_search_data { /*noproto*/
     169  owl_viewwin *v;
     170  int direction;
     171} owl_viewwin_search_data;
     172
     173static void owl_viewwin_callback_search(owl_editwin *e)
     174{
     175  const char *line = owl_editwin_get_text(e);
     176  owl_viewwin_search_data *data = owl_editwin_get_cbdata(e);
     177  owl_function_set_search(line);
     178  if (!owl_viewwin_search(data->v, owl_global_get_search_re(&g),
     179                          OWL_SEARCH_MATCH_CURRENT, data->direction))
     180    owl_function_error("No matches");
     181}
     182
     183char *owl_viewwin_command_start_search(owl_viewwin *v, int argc, const char *const *argv, const char *buff)
     184{
     185  int direction;
     186  const char *buffstart;
     187  owl_editwin *tw;
     188  owl_context *ctx;
     189  owl_viewwin_search_data *data;
     190
     191  direction=OWL_DIRECTION_DOWNWARDS;
     192  buffstart=skiptokens(buff, 1);
     193  if (argc>1 && !strcmp(argv[1], "-r")) {
     194    direction=OWL_DIRECTION_UPWARDS;
     195    buffstart=skiptokens(buff, 2);
     196  }
     197
     198  /* TODO: Add a search history? */
     199  tw = owl_viewwin_set_typwin_active(v, NULL);
     200  owl_editwin_set_locktext(tw, (direction == OWL_DIRECTION_DOWNWARDS) ? "/" : "?");
     201  owl_editwin_insert_string(tw, buffstart);
     202
     203  data = owl_malloc(sizeof(owl_viewwin_search_data));
     204  data->v = v;
     205  data->direction = direction;
     206
     207  ctx = owl_editcontext_new(OWL_CTX_EDITLINE, tw, "editline");
     208  ctx->deactivate_cb = owl_viewwin_deactivate_editcontext;
     209  ctx->cbdata = v;
     210  owl_global_push_context_obj(&g, ctx);
     211  owl_editwin_set_callback(tw, owl_viewwin_callback_search);
     212  owl_editwin_set_cbdata(tw, data, owl_free);
    165213  return NULL;
    166214}
Note: See TracChangeset for help on using the changeset viewer.