Which dependencies to install for Debian (probably incomplete)
[notion/jeffpc.git] / mod_query / main.c
blobb8337a41caa4a1e4e99568fc56b8c1e542488517
1 /*
2 * ion/mod_query/main.c
4 * Copyright (c) Tuomo Valkonen 1999-2009.
6 * See the included file LICENSE for details.
7 */
9 #include <libextl/readconfig.h>
10 #include <libextl/extl.h>
11 #include <libtu/minmax.h>
12 #include <ioncore/binding.h>
13 #include <ioncore/conf-bindings.h>
14 #include <ioncore/frame.h>
15 #include <ioncore/saveload.h>
16 #include <ioncore/bindmaps.h>
17 #include <ioncore/ioncore.h>
19 #include "query.h"
20 #include "edln.h"
21 #include "wedln.h"
22 #include "input.h"
23 #include "complete.h"
24 #include "history.h"
25 #include "exports.h"
26 #include "main.h"
29 /*{{{ Module information */
32 #include "../version.h"
34 char mod_query_ion_api_version[]=NOTION_API_VERSION;
37 /*}}}*/
40 /*{{{ Bindmaps */
43 WBindmap *mod_query_input_bindmap=NULL;
44 WBindmap *mod_query_wedln_bindmap=NULL;
47 /*}}}*/
50 /*{{{ Set & get */
53 ModQueryConfig mod_query_config={
54 250,
55 TRUE,
56 FALSE,
57 TRUE
61 /*EXTL_DOC
62 * Set module configuration. The following are supported:
64 * \begin{tabularx}{\linewidth}{lX}
65 * \tabhead{Field & Description}
66 * \var{autoshowcompl} & (boolean) Is auto-show-completions enabled?
67 * (default: true). \\
68 * \var{autoshowcompl_delay} & (integer) auto-show-completions delay
69 * in milliseconds (default: 250). \\
70 * \var{caseicompl} & (boolean) Turn some completions case-insensitive
71 * (default: false). \\
72 * \var{substrcompl} & (boolean) Complete on sub-strings in some cases
73 * (default: ftrue). \\
74 * \end{tabularx}
76 EXTL_EXPORT
77 void mod_query_set(ExtlTab tab)
79 ModQueryConfig *c=&mod_query_config;
81 extl_table_gets_b(tab, "autoshowcompl", &c->autoshowcompl);
82 extl_table_gets_b(tab, "caseicompl", &c->caseicompl);
83 extl_table_gets_b(tab, "substrcompl", &c->substrcompl);
85 if(extl_table_gets_i(tab, "autoshowcompl_delay",
86 &c->autoshowcompl_delay)){
87 c->autoshowcompl_delay=maxof(c->autoshowcompl_delay, 0);
91 /*EXTL_DOC
92 * Get module configuration. For more information see
93 * \fnref{mod_query.set}.
95 EXTL_SAFE
96 EXTL_EXPORT
97 ExtlTab mod_query_get()
99 ModQueryConfig *c=&mod_query_config;
100 ExtlTab tab=extl_create_table();
102 extl_table_sets_b(tab, "autoshowcompl", c->autoshowcompl);
103 extl_table_sets_i(tab, "autoshowcompl_delay", c->autoshowcompl_delay);
104 extl_table_sets_b(tab, "caseicompl", c->caseicompl);
105 extl_table_sets_b(tab, "substrcompl", c->substrcompl);
107 return tab;
111 /*}}}*/
114 /*{{{ Init & deinit */
117 static void load_history()
119 ExtlTab tab;
120 int i, n;
122 if(!extl_read_savefile("saved_queryhist", &tab))
123 return;
125 n=extl_table_get_n(tab);
127 for(i=n; i>=1; i--){
128 char *s=NULL;
129 if(extl_table_geti_s(tab, i, &s)){
130 mod_query_history_push(s);
131 free(s);
135 extl_unref_table(tab);
139 static void save_history()
141 ExtlTab tab=mod_query_history_table();
143 extl_write_savefile("saved_queryhist", tab);
145 extl_unref_table(tab);
149 static bool loaded_ok=FALSE;
151 void mod_query_deinit()
153 mod_query_unregister_exports();
155 if(mod_query_input_bindmap!=NULL){
156 ioncore_free_bindmap("WInput", mod_query_input_bindmap);
157 mod_query_input_bindmap=NULL;
160 if(mod_query_wedln_bindmap!=NULL){
161 ioncore_free_bindmap("WEdln", mod_query_wedln_bindmap);
162 mod_query_wedln_bindmap=NULL;
165 hook_remove(ioncore_snapshot_hook, save_history);
169 bool mod_query_init()
171 if(!mod_query_register_exports())
172 goto err;
174 mod_query_input_bindmap=ioncore_alloc_bindmap("WInput", NULL);
175 mod_query_wedln_bindmap=ioncore_alloc_bindmap("WEdln", NULL);
177 if(mod_query_wedln_bindmap==NULL ||
178 mod_query_input_bindmap==NULL){
179 goto err;
182 /*ioncore_read_config("cfg_query", NULL, TRUE);*/
184 load_history();
186 loaded_ok=TRUE;
188 hook_add(ioncore_snapshot_hook, save_history);
190 return TRUE;
192 err:
193 mod_query_deinit();
194 return FALSE;
198 /*}}}*/