diff options
author | Bernhard R. Link <brlink@debian.org> | 2008-06-09 23:50:27 +0200 |
---|---|---|
committer | Shawn <sabetts@juicebox.(none)> | 2008-10-22 14:17:43 -0700 |
commit | d801644502adf42570e9a5b75fcaa013f613fc5a (patch) | |
tree | a30537a038c36c0effc0ab0f6f9f6565a206b558 | |
parent | 22cea909c3d1b695424ef85153917b00bfb1261c (diff) | |
download | ratpoison-d801644502adf42570e9a5b75fcaa013f613fc5a.zip |
define different history types and use them
(implementation does not separate them yet, though)
-rw-r--r-- | src/actions.c | 41 | ||||
-rw-r--r-- | src/data.h | 1 | ||||
-rw-r--r-- | src/editor.c | 11 | ||||
-rw-r--r-- | src/editor.h | 2 | ||||
-rw-r--r-- | src/history.c | 25 | ||||
-rw-r--r-- | src/history.h | 16 | ||||
-rw-r--r-- | src/input.c | 8 | ||||
-rw-r--r-- | src/input.h | 4 | ||||
-rw-r--r-- | src/ratpoison.h | 2 |
9 files changed, 66 insertions, 44 deletions
diff --git a/src/actions.c b/src/actions.c index 678ec70..df075d9 100644 --- a/src/actions.c +++ b/src/actions.c @@ -1322,7 +1322,8 @@ cmd_select (int interactive, struct cmdarg **args) /* FIXME: This is manually done because of the kinds of things select accepts. */ if (args[0] == NULL) - str = get_input (MESSAGE_PROMPT_SWITCH_TO_WINDOW, window_completions); + str = get_input (MESSAGE_PROMPT_SWITCH_TO_WINDOW, hist_SELECT, + window_completions); else str = xstrdup (ARG_STRING(0)); @@ -1462,14 +1463,14 @@ frame_selector_match (char ch) } static cmdret * -read_string (struct argspec *spec, struct sbuf *s, completion_fn fn, struct cmdarg **arg) +read_string (struct argspec *spec, struct sbuf *s, int history_id, completion_fn fn, struct cmdarg **arg) { char *input; if (s) input = xstrdup (sbuf_get(s)); else - input = get_input (spec->prompt, fn); + input = get_input (spec->prompt, history_id, fn); if (input) { @@ -1490,7 +1491,7 @@ read_keymap (struct argspec *spec, struct sbuf *s, struct cmdarg **arg) if (s) input = xstrdup (sbuf_get (s)); else - input = get_input (spec->prompt, keymap_completions); + input = get_input (spec->prompt, hist_KEYMAP, keymap_completions); if (input) { @@ -1516,7 +1517,7 @@ read_keydesc (struct argspec *spec, struct sbuf *s, struct cmdarg **arg) if (s) input = xstrdup (sbuf_get (s)); else - input = get_input (spec->prompt, trivial_completions); + input = get_input (spec->prompt, hist_KEY, trivial_completions); if (input) { @@ -1611,7 +1612,7 @@ colon_completions (char* str) static cmdret * read_command (struct argspec *spec, struct sbuf *s, struct cmdarg **arg) { - return read_string (spec, s, colon_completions, arg); + return read_string (spec, s, hist_COMMAND, colon_completions, arg); } static struct list_head * @@ -1677,7 +1678,7 @@ exec_completions (char *str) static cmdret * read_shellcmd (struct argspec *spec, struct sbuf *s, struct cmdarg **arg) { - return read_string (spec, s, exec_completions, arg); + return read_string (spec, s, hist_SHELLCMD, exec_completions, arg); } /* Return NULL on abort/failure. */ @@ -1804,7 +1805,7 @@ read_window (struct argspec *spec, struct sbuf *s, struct cmdarg **arg) if (s) name = xstrdup (sbuf_get (s)); else - name = get_input (spec->prompt, window_completions); + name = get_input (spec->prompt, hist_WINDOW, window_completions); if (name) { @@ -1877,7 +1878,7 @@ read_gravity (struct argspec *spec, struct sbuf *s, struct cmdarg **arg) if (s) input = xstrdup (sbuf_get(s)); else - input = get_input (spec->prompt , trivial_completions); + input = get_input (spec->prompt, hist_GRAVITY, trivial_completions); if (input) { @@ -1928,7 +1929,7 @@ read_group (struct argspec *spec, struct sbuf *s, struct cmdarg **arg) if (s) input = xstrdup (sbuf_get(s)); else - input = get_input (spec->prompt , group_completions); + input = get_input (spec->prompt, hist_GROUP, group_completions); if (input) { @@ -1984,7 +1985,7 @@ read_hook (struct argspec *spec, struct sbuf *s, struct cmdarg **arg) if (s) input = xstrdup (sbuf_get(s)); else - input = get_input (spec->prompt , hook_completions); + input = get_input (spec->prompt, hist_HOOK, hook_completions); if (input) { @@ -2052,7 +2053,7 @@ read_variable (struct argspec *spec, struct sbuf *s, struct cmdarg **arg) if (s) input = xstrdup (sbuf_get(s)); else - input = get_input (spec->prompt , var_completions); + input = get_input (spec->prompt, hist_VARIABLE, var_completions); if (input) { @@ -2083,7 +2084,8 @@ read_number (struct argspec *spec, struct sbuf *s, struct cmdarg **arg) if (s) input = xstrdup (sbuf_get(s)); else - input = get_input (spec->prompt , trivial_completions); + /* numbers should perhaps be more fine grained, or hist_NONE */ + input = get_input (spec->prompt, hist_OTHER, trivial_completions); if (input) { @@ -2108,7 +2110,7 @@ read_arg (struct argspec *spec, struct sbuf *s, struct cmdarg **arg) case arg_STRING: case arg_REST: case arg_RAW: - ret = read_string (spec, s, trivial_completions, arg); + ret = read_string (spec, s, hist_OTHER, trivial_completions, arg); break; case arg_KEYMAP: ret = read_keymap (spec, s, arg); @@ -2520,9 +2522,10 @@ cmd_colon (int interactive, struct cmdarg **args) char *input; if (args[0] == NULL) - input = get_input (MESSAGE_PROMPT_COMMAND, colon_completions); + input = get_input (MESSAGE_PROMPT_COMMAND, hist_COMMAND, colon_completions); else - input = get_more_input (MESSAGE_PROMPT_COMMAND, ARG_STRING(0), colon_completions); + input = get_more_input (MESSAGE_PROMPT_COMMAND, ARG_STRING(0), hist_COMMAND, + colon_completions); /* User aborted. */ if (input == NULL) @@ -5598,7 +5601,7 @@ cmd_prompt (int interactive, struct cmdarg **args) char *query, *output, *prefix; if (args[0] == NULL) - output = get_input(MESSAGE_PROMPT_COMMAND, trivial_completions); + output = get_input(MESSAGE_PROMPT_COMMAND, hist_PROMPT, trivial_completions); else { prefix = strchr (ARG_STRING(0), ':'); @@ -5608,12 +5611,12 @@ cmd_prompt (int interactive, struct cmdarg **args) query = xmalloc (prefix - ARG_STRING(0) + 1); strncpy (query, ARG_STRING(0), prefix - ARG_STRING(0)); query[prefix - ARG_STRING(0)] = 0; /* null terminate */ - output = get_more_input (query, prefix, trivial_completions); + output = get_more_input (query, prefix, hist_PROMPT, trivial_completions); free (query); } else { - output = get_input (ARG_STRING(0), trivial_completions); + output = get_input (ARG_STRING(0), hist_PROMPT, trivial_completions); } } ret = cmdret_new (RET_SUCCESS, "%s", output); @@ -359,6 +359,7 @@ struct rp_input_line int size; rp_completions *compl; Atom selection; + int history_id; }; /* The hook dictionary. */ diff --git a/src/editor.c b/src/editor.c index 21fbe63..b2a72f9 100644 --- a/src/editor.c +++ b/src/editor.c @@ -102,13 +102,14 @@ static edit_binding edit_bindings[] = { {0, 0}, 0} }; rp_input_line * -input_line_new (char *prompt, char *preinput, completion_fn fn) +input_line_new (char *prompt, char *preinput, int history_id, completion_fn fn) { rp_input_line *line; line = xmalloc (sizeof (rp_input_line)); line->prompt = prompt; line->compl = completions_new (fn); + line->history_id = history_id; /* Allocate some memory to start with */ line->size = strlen (preinput) + 100; @@ -358,7 +359,7 @@ static edit_status editor_history_previous (rp_input_line *line) { #ifdef HAVE_HISTORY - char *entry = history_previous (); + const char *entry = history_previous (line->history_id); if (entry) { @@ -395,7 +396,7 @@ static edit_status editor_history_next (rp_input_line *line) { #ifdef HAVE_HISTORY - char *entry = history_next (); + const char *entry = history_next (line->history_id); if (entry) { @@ -473,7 +474,7 @@ editor_enter (rp_input_line *line) line->buffer[line->length] = '\0'; #ifdef HAVE_HISTORY - result = history_expand_line (line->buffer, &expansion); + result = history_expand_line (line->history_id, line->buffer, &expansion); PRINT_DEBUG (("History Expansion - result: %d\n", result)); PRINT_DEBUG (("History Expansion - expansion: \'%s\'\n", expansion)); @@ -486,7 +487,7 @@ editor_enter (rp_input_line *line) } else /* result == 0 || result == 1 */ { - history_add (expansion); + history_add (line->history_id, expansion); free (line->buffer); line->buffer = expansion; } diff --git a/src/editor.h b/src/editor.h index b2cf558..f3ffa31 100644 --- a/src/editor.h +++ b/src/editor.h @@ -36,7 +36,7 @@ edit_status }; /* Input line functions */ -rp_input_line *input_line_new (char *prompt, char *preinput, completion_fn fn); +rp_input_line *input_line_new (char *prompt, char *preinput, int history_id, completion_fn fn); void input_line_free (rp_input_line *line); edit_status execute_edit_action (rp_input_line *line, KeySym ch, unsigned int modifier, char *keysym_buf); diff --git a/src/history.c b/src/history.c index 4ec8b2e..28292f6 100644 --- a/src/history.c +++ b/src/history.c @@ -82,9 +82,14 @@ history_reset (void) } void -history_add (char *item) +history_add (int history_id, char *item) { - HIST_ENTRY *h = history_get (history_length); + HIST_ENTRY *h; + + if (history_id == hist_NONE) + return; + + h = history_get (history_length); if (item == NULL || *item == '\0' || isspace (*item) || (h != NULL && !strcmp (h->line, item))) return; @@ -93,27 +98,33 @@ history_add (char *item) add_history (item); } -char * -history_previous (void) +const char * +history_previous (int history_id) { HIST_ENTRY *h = NULL; + if (history_id == hist_NONE) + return NULL; + h = previous_history(); return h ? h->line : NULL; } -char * -history_next (void) +const char * +history_next (int history_id) { HIST_ENTRY *h = NULL; + if (history_id == hist_NONE) + return NULL; + h = next_history(); return h ? h->line : NULL; } -int history_expand_line (char *string, char **output) +int history_expand_line (int history_id, char *string, char **output) { return history_expand (string, output); } diff --git a/src/history.h b/src/history.h index b133df1..f6b6dd9 100644 --- a/src/history.h +++ b/src/history.h @@ -21,13 +21,21 @@ #ifndef _RATPOISON_HISTORY_H #define _RATPOISON_HISTORY_H 1 +enum { hist_NONE=0, hist_COMMAND, hist_SHELLCMD, + hist_SELECT, hist_KEYMAP, hist_KEY, + hist_WINDOW, hist_GRAVITY, hist_GROUP, + hist_HOOK, hist_VARIABLE, hist_PROMPT, + hist_OTHER, + /* must be last, do not use, for length only: */ + hist_COUNT}; + void history_load (void); void history_save (void); void history_resize (int size); void history_reset (void); -void history_add (char *item); -char *history_next (void); -char *history_previous (void); -int history_expand_line (char *string, char **output); +void history_add (int, char *item); +const char *history_next (int); +const char *history_previous (int); +int history_expand_line (int, char *string, char **output); #endif /* ! _RATPOISON_HISTORY_H */ diff --git a/src/input.c b/src/input.c index c92acd8..db36ba7 100644 --- a/src/input.c +++ b/src/input.c @@ -515,13 +515,13 @@ ring_bell (void) } char * -get_input (char *prompt, completion_fn fn) +get_input (char *prompt, int history_id, completion_fn fn) { - return get_more_input (prompt, "", fn); + return get_more_input (prompt, "", history_id, fn); } char * -get_more_input (char *prompt, char *preinput, +get_more_input (char *prompt, char *preinput, int history_id, completion_fn compl_fn) { /* Emacs 21 uses a 513 byte string to store the keysym name. */ @@ -542,7 +542,7 @@ get_more_input (char *prompt, char *preinput, #endif /* HAVE_READLINE_HISTORY_H */ /* Create our line structure */ - line = input_line_new (prompt, preinput, compl_fn); + line = input_line_new (prompt, preinput, history_id, compl_fn); /* We don't want to draw overtop of the program bar. */ hide_bar (s); diff --git a/src/input.h b/src/input.h index 1a421c3..5beb96e 100644 --- a/src/input.h +++ b/src/input.h @@ -24,8 +24,8 @@ char *keysym_to_string (KeySym keysym, unsigned int modifier); int cook_keycode (XKeyEvent *ev, KeySym *keysym, unsigned int *mod, char *keysym_name, int len, int ignore_bad_mods); -char *get_input (char *prompt, completion_fn fn); -char *get_more_input (char *prompt, char *preinput, completion_fn fn); +char *get_input (char *prompt, int history_id, completion_fn fn); +char *get_more_input (char *prompt, char *preinput, int history_id, completion_fn fn); void read_any_key (void); int read_single_key (KeySym *keysym, unsigned int *modifiers, char *keysym_name, int len); int read_key (KeySym *keysym, unsigned int *modifiers, char *keysym_name, int len); diff --git a/src/ratpoison.h b/src/ratpoison.h index b0690f6..8004d36 100644 --- a/src/ratpoison.h +++ b/src/ratpoison.h @@ -82,9 +82,7 @@ extern XGCValues gv; #include "screen.h" #include "group.h" #include "editor.h" -#ifdef HAVE_HISTORY #include "history.h" -#endif /* HAVE_HISTORY */ #include "completions.h" #include "hook.h" #include "xinerama.h" |