1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
/*
* weechat-aspell-completion.c - completion for aspell commands
*
* Copyright (C) 2013-2015 Sébastien Helleu <flashcode@flashtux.org>
*
* This file is part of WeeChat, the extensible chat client.
*
* WeeChat is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* WeeChat is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WeeChat. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "../weechat-plugin.h"
#include "weechat-aspell.h"
/*
* Adds aspell langs (all langs, even for dictionaries not installed) to
* completion list.
*/
int
weechat_aspell_completion_langs_cb (void *data, const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
int i;
/* make C compiler happy */
(void) data;
(void) completion_item;
(void) buffer;
for (i = 0; aspell_langs[i].code; i++)
{
weechat_hook_completion_list_add (completion,
aspell_langs[i].code,
0, WEECHAT_LIST_POS_SORT);
}
return WEECHAT_RC_OK;
}
/*
* Adds a dictionary to completion when using enchant.
*/
#ifdef USE_ENCHANT
void
weechat_aspell_completion_enchant_add_dict_cb (const char *lang_tag,
const char *provider_name,
const char *provider_desc,
const char *provider_file,
void *user_data)
{
/* make C compiler happy */
(void) provider_name;
(void) provider_desc;
(void) provider_file;
weechat_hook_completion_list_add ((struct t_gui_completion *)user_data,
lang_tag, 0, WEECHAT_LIST_POS_SORT);
}
#endif /* USE_ENCHANT */
/*
* Adds aspell dictionaries (only installed dictionaries) to completion list.
*/
int
weechat_aspell_completion_dicts_cb (void *data,
const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
#ifndef USE_ENCHANT
struct AspellConfig *config;
AspellDictInfoList *list;
AspellDictInfoEnumeration *elements;
const AspellDictInfo *dict;
#endif /* USE_ENCHANT */
/* make C compiler happy */
(void) data;
(void) completion_item;
(void) buffer;
#ifdef USE_ENCHANT
enchant_broker_list_dicts (broker,
weechat_aspell_completion_enchant_add_dict_cb,
completion);
#else
config = new_aspell_config ();
list = get_aspell_dict_info_list (config);
elements = aspell_dict_info_list_elements (list);
while ((dict = aspell_dict_info_enumeration_next (elements)) != NULL)
{
weechat_hook_completion_list_add (completion, dict->name,
0, WEECHAT_LIST_POS_SORT);
}
delete_aspell_dict_info_enumeration (elements);
delete_aspell_config (config);
#endif /* USE_ENCHANT */
return WEECHAT_RC_OK;
}
/*
* Hooks completions.
*/
void
weechat_aspell_completion_init ()
{
weechat_hook_completion ("aspell_langs",
N_("list of all languages supported by aspell"),
&weechat_aspell_completion_langs_cb, NULL);
weechat_hook_completion ("aspell_dicts",
N_("list of aspell installed dictionaries"),
&weechat_aspell_completion_dicts_cb, NULL);
}
|