1 <!-- ##### SECTION Title ##### -->
2 Automatic String Completion
4 <!-- ##### SECTION Short_Description ##### -->
5 support for automatic completion using a group of target strings.
7 <!-- ##### SECTION Long_Description ##### -->
9 #GCompletion provides support for automatic completion of a string using
10 any group of target strings. It is typically used for file name completion
11 as is common in many UNIX shells.
14 A #GCompletion is created using g_completion_new().
15 Target items are added and removed with
16 g_completion_add_items(), g_completion_remove_items() and
17 g_completion_clear_items().
18 A completion attempt is requested with g_completion_complete().
19 When no longer needed, the #GCompletion is freed with g_completion_free().
22 Items in the completion can be simple strings (e.g. filenames),
23 or pointers to arbitrary data structures. If data structures are used
24 you must provide a #GCompletionFunc in g_completion_new(),
25 which retrieves the item's string from the data structure.
26 You can change the way in which strings are compared by setting
27 a different #GCompletionStrncmpFunc in g_completion_set_compare().
30 <!-- ##### SECTION See_Also ##### -->
35 <!-- ##### STRUCT GCompletion ##### -->
37 The data structure used for automatic completion.
40 @items: list of target items (strings or data structures).
41 @func: function which is called to get the string associated with a target
42 item. It is %NULL if the target items are strings.
43 @prefix: the last prefix passed to g_completion_complete().
44 @cache: the list of items which begin with @prefix.
47 <!-- ##### FUNCTION g_completion_new ##### -->
49 Creates a new #GCompletion.
52 @func: the function to be called to return the string representing an item
53 in the #GCompletion, or %NULL if strings are going to be used as the
55 @Returns: the new #GCompletion.
58 <!-- ##### USER_FUNCTION GCompletionFunc ##### -->
60 Specifies the type of the function passed to g_completion_new().
61 It should return the string corresponding to the given target item.
62 This is used when you use data structures as #GCompletion items.
65 @Param1: the completion item.
66 @Returns: the string corresponding to the item.
69 <!-- ##### FUNCTION g_completion_add_items ##### -->
71 Adds items to the #GCompletion.
74 @cmp: the #GCompletion.
75 @items: the list of items to add.
78 <!-- ##### FUNCTION g_completion_remove_items ##### -->
80 Removes items from a #GCompletion.
83 @cmp: the #GCompletion.
84 @items: the items to remove.
87 <!-- ##### FUNCTION g_completion_clear_items ##### -->
89 Removes all items from the #GCompletion.
92 @cmp: the #GCompletion.
95 <!-- ##### FUNCTION g_completion_complete ##### -->
97 Attempts to complete the string @prefix using the #GCompletion target items.
100 @cmp: the #GCompletion.
101 @prefix: the prefix string, typically typed by the user, which is compared
102 with each of the items.
103 @new_prefix: if non-%NULL, returns the longest prefix which is common to all
104 items that matched @prefix, or %NULL if no items matched @prefix.
105 This string should be freed when no longer needed.
106 @Returns: the list of items whose strings begin with @prefix. This should
110 <!-- ##### FUNCTION g_completion_set_compare ##### -->
112 Sets the function to use for string comparisons. The default
113 string comparison function is <function>strncmp()</function>.
116 @cmp: a #GCompletion.
117 @strncmp_func: the string comparison function.
120 <!-- ##### USER_FUNCTION GCompletionStrncmpFunc ##### -->
122 Specifies the type of the function passed to g_completion_set_compare().
123 This is used when you use strings as #GCompletion items.
126 @s1: string to compare with @s2.
127 @s2: string to compare with @s1.
128 @n: maximal number of bytes to compare.
129 @Returns: an integer less than, equal to, or greater than zero if the
130 first @n bytes of @s1 is found, respectively, to be less than, to match,
131 or to be greater than the first @n bytes of @s2.
134 <!-- ##### FUNCTION g_completion_free ##### -->
136 Frees all memory used by the #GCompletion.
139 @cmp: the #GCompletion.