diff options
author | sabetts <sabetts> | 2003-05-27 07:51:03 +0000 |
---|---|---|
committer | sabetts <sabetts> | 2003-05-27 07:51:03 +0000 |
commit | 6cc80f10f7cb3de33626cf178bda532d741cf388 (patch) | |
tree | 87c04a9e6b4ecee8c49dcff7ad9be54b3fceb874 /src/completions.c | |
parent | 785627843a7aa83ebf451add7b9a97e0b800e390 (diff) | |
download | ratpoison-6cc80f10f7cb3de33626cf178bda532d741cf388.zip |
* src/editor.c (saved_command): new local global
(edit_binding): new typedef
(edit_binding): new struct
(edit_bindings): new local global
(input_line_new): new function
(input_line_free): likewise
(execute_edit_action): likewise
(editor_forward_char): likewise
(editor_backward_char): likewise
(editor_forward_word): likewise
(editor_backward_word): likewise
(editor_beginning_of_line): likewise
(editor_end_of_line): likewise
(editor_delete_char): likewise
(editor_backward_delete_char): likewise
(editor_kill_word): likewise
(editor_backward_kill_word): likewise
(editor_kill_line): likewise
(editor_backward_kill_line): likewise
(editor_history_previous): likewise
(editor_history_next): likewise
(editor_abort): likewise
(editor_no_action): likewise
(editor_insert): likewise
(editor_enter): likewise
(paste_cut_buffer): likewise
(paste_primary_selection): likewise
(editor_paste_selection): likewise
(editor_complete): likewise
(editor_forward_char): new prototype
(editor_backward_char): likewise
(editor_forward_word): likewise
(editor_backward_word): likewise
(editor_beginning_of_line): likewise
(editor_end_of_line): likewise
(editor_delete_char): likewise
(editor_backward_delete_char): likewise
(editor_kill_word): likewise
(editor_backward_kill_word): likewise
(editor_kill_line): likewise
(editor_paste_selection): likewise
(editor_abort): likewise
(editor_no_action): likewise
(editor_enter): likewise
(editor_history_previous): likewise
(editor_history_next): likewise
(editor_complete): likewise
(editor_backward_kill_line): likewise
* src/sbuf.h (sbuf): add node field.
* src/main.c (xrealloc): don't print debugger output
(init_defaults): init history_size
(main): initialize rp_selection
(main): load history
(clean_up): save history
* src/linkedlist.h (list_first): new macro
* src/input.h (free_history): remove prototype
(ring_bell): new function
* src/input.c: include unistd.h
(input_history): remove
(input_num_history_entries): likewise
(update_input_window): remove prompt, input, and input_len
arguments. add line argument.
(update_input_window): use line argument.
(ring_bell): new function
(get_input): take completion_fn argument. prototype and callers
updated.
(free_history): remove function
(get_more_input): take completion_fn argument. prototype and
callers updated. use line structure and its functionality.
* src/globals.h (MAX_FONT_WIDTH): new define
(rp_selection): new extern
* src/globals.c (rp_selection): new global
* src/completions.h (completions_new): new prototype
(completions_free): likewise
(completions_assign): likewise
(completions_update): likewise
(completions_next_completion): likewise
* src/completions.c (completions_new): new function
(completions_free): likewise
(completions_assign): likewise
(completions_update): likewise
(completions_next_completion): likewise
* src/Makefile.am (ratpoison_SOURCES): add editor.c editor.h
history.h and history.c
* src/data.h (rp_completions): new typedef
(rp_input_line): likewise
(completion_fn): likewise
(rp_defaults): new field, history_size
(rp_completions): new struct
(rp_input_line): new struct
* src/conf.h (MAX_HISTORY_SIZE): new define
(HISTORY_FILE): likewise
(VISUAL_BELL): likewise
(MODIFIER_PREFIX): set to RP_CONTROL_MASK
(INPUT_ABORT_MODIFIER): likewise
(INPUT_PREV_HISTORY_MODIFIER): likewise
(INPUT_NEXT_HISTORY_MODIFIER): likewise
(RESIZE_VGROW_MODIFIER): likewise
(RESIZE_VSHRINK_MODIFIER): likewise
(RESIZE_HGROW_MODIFIER): likewise
(RESIZE_HSHRINK_MODIFIER): likewise
* src/actions.c (trivial_completions): new function
(window_completions): likewise
(colon_completions): likewise
(exec_completions): likewise
(cmd_select): pass window_completions to get_input
(cmd_rename): pass trivial_completions to get_input
(cmd_colon): pass colon_completions to get_input and
get_more_input
(cmd_exec): pass exec_completions to get_input
(cmd_newwm): pass trivial_completions to get_input
(cmd_resize): convert the keysym modifier to something ratpoison
understands.
Diffstat (limited to 'src/completions.c')
-rw-r--r-- | src/completions.c | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/completions.c b/src/completions.c new file mode 100644 index 0000000..970897d --- /dev/null +++ b/src/completions.c @@ -0,0 +1,104 @@ +#include <string.h> + +#include "ratpoison.h" +#include "completions.h" + +rp_completions * +completions_new (completion_fn list_fn) +{ + rp_completions *c; + + c = (rp_completions *) xmalloc (sizeof(rp_completions)); + + INIT_LIST_HEAD (&c->completion_list); + c->complete_fn = list_fn; + c->last_match = NULL; + c->partial = NULL; + c->virgin = 1; + + return c; +} + +void +completions_free (rp_completions *c) +{ + struct sbuf *cur; + struct list_head *tmp, *iter; + + /* Clear our list */ + list_for_each_safe_entry (cur, iter, tmp, &c->completion_list, node) + { + list_del (&cur->node); + sbuf_free (cur); + } + + /* Free the partial string. */ + if (c->partial) + free (c->partial); +} + +void +completions_assign (rp_completions *c, struct list_head *new_list) +{ + struct sbuf *cur; + struct list_head *tmp, *iter; + + /* Clear our list */ + list_for_each_safe_entry (cur, iter, tmp, &c->completion_list, node) + { + list_del (&cur->node); + sbuf_free (cur); + } + + /* splice the list into completion_list. Note that we SHOULDN'T free + new_list, because they share the same memory. */ + INIT_LIST_HEAD (&c->completion_list); + list_splice (new_list, &c->completion_list); + + list_first (c->last_match, &c->completion_list, node); +} + +void +completions_update (rp_completions *c, char *partial) +{ + struct list_head *new_list; + + new_list = c->complete_fn (partial); + + c->virgin = 0; + if (c->partial) + free (c->partial); + c->partial = xstrdup (partial); + + completions_assign (c, new_list); +} + +/* Return a completed string that starts with partial. */ +char * +completions_next_completion (rp_completions *c, char *partial) +{ + struct sbuf *cur; + + if (c->virgin) + completions_update (c, partial); + + if (c->last_match == NULL) + return NULL; + + /* search forward from our last match through the list looking for + another match. */ + for (cur = list_next_entry (c->last_match, &c->completion_list, node); + cur != c->last_match; + cur = list_next_entry (cur, &c->completion_list, node)) + { + if (str_comp (sbuf_get (cur), c->partial, strlen (c->partial))) + { + /* We found a match so update our last_match pointer and + return the string. */ + c->last_match = cur; + return sbuf_get (cur); + } + } + + return NULL; +} |