/*
- * Copyright Neil Brown ©2020-2021 <neil@brown.name>
+ * Copyright Neil Brown ©2020-2023 <neil@brown.name>
* May be distributed under terms of GPLv2 - see file:COPYING
*
* aspell: edlib interface for aspell library.
#include <aspell.h>
#include <wctype.h>
+#define PANE_DATA_TYPE struct aspell_data
#include "core.h"
-static AspellConfig *spell_config;
-
struct aspell_data {
AspellSpeller *speller safe;
+ bool need_save;
};
+#include "core-pane.h"
+
+static AspellConfig *spell_config;
static int trim(const char *safe *wordp safe)
{
LOG("Cannot create speller: %s", aspell_error_message(ret));
return Efail;
}
- alloc(as, pane);
+ p = pane_register(ci->focus, 0, &aspell_handle.c);
+ if (!p)
+ return Efail;
+ as = p->data;
as->speller = safe_cast to_aspell_speller(ret);
- p = pane_register(ci->focus, 0, &aspell_handle.c, as);
- if (p) {
- call("doc:request:aspell:check", p);
- call("doc:request:aspell:suggest", p);
- call("doc:request:aspell:set-dict", p);
- call("doc:request:aspell:add-word", p);
- }
+
+ call("doc:request:aspell:check", p);
+ call("doc:request:aspell:suggest", p);
+ call("doc:request:aspell:set-dict", p);
+ call("doc:request:aspell:add-word", p);
+ call("doc:request:aspell:save", p);
+
return 1;
}
-DEF_CMD(aspell_close)
+DEF_CMD_CLOSED(aspell_close)
{
struct aspell_data *as = ci->home->data;
+ if (as->need_save)
+ aspell_speller_save_all_word_lists(as->speller);
delete_aspell_speller(as->speller);
return 1;
}
if (rv != Efallthrough)
return rv;
- call_comm("doc:attach-helper", ci->focus, &aspell_attach_helper);
+ call_comm("doc:get-doc", ci->focus, &aspell_attach_helper);
return call("doc:notify:aspell:check", ci->focus, 0, NULL, ci->str);
}
if (rv != Efallthrough)
return rv;
- call_comm("doc:attach-helper", ci->focus, &aspell_attach_helper);
+ call_comm("doc:get-doc", ci->focus, &aspell_attach_helper);
return call_comm("doc:notify:aspell:suggest", ci->focus, ci->comm2,
0, NULL, ci->str);
}
+DEF_CMD(aspell_save)
+{
+ struct aspell_data *as = ci->home->data;
+ if (as->need_save) {
+ as->need_save = False;
+ aspell_speller_save_all_word_lists(as->speller);
+ }
+ return Efalse;
+}
+
+DEF_CMD(aspell_do_save)
+{
+ aspell_save_func(ci);
+ return 1;
+}
+
+DEF_CMD(spell_save)
+{
+ return call_comm("doc:notify:aspell:save", ci->focus, ci->comm2,
+ ci->num, NULL, ci->str);
+}
+
DEF_CMD(aspell_add)
{
struct aspell_data *as = ci->home->data;
if (!len)
return Efail;
- if (ci->num == 1)
+ if (ci->num == 1) {
aspell_speller_add_to_personal(as->speller, word, len);
- else
+ if (as->need_save)
+ call_comm("event:free", ci->home, &aspell_save);
+ as->need_save = True;
+ call_comm("event:timer", ci->home, &aspell_save, 30*1000);
+ } else
aspell_speller_add_to_session(as->speller, word, len);
call("doc:notify:spell:dict-changed", ci->home);
return 1;
DEF_CMD(spell_add)
{
int rv = call_comm("doc:notify:aspell:add-word", ci->focus, ci->comm2,
- 0, NULL, ci->str);
+ ci->num, NULL, ci->str);
if (rv != Efallthrough)
return rv;
- call_comm("doc:attach-helper", ci->focus, &aspell_attach_helper);
+ call_comm("doc:get-doc", ci->focus, &aspell_attach_helper);
return call_comm("doc:notify:aspell:add-word", ci->focus, ci->comm2,
- 0, NULL, ci->str);
+ ci->num, NULL, ci->str);
}
DEF_CMD(aspell_set_dict)
if (!lang)
return Enoarg;
- LOG("lang = %s", lang);
conf2 = aspell_config_clone(spell_config);
aspell_config_replace(conf2, "lang", lang);
ret = new_aspell_speller(conf2);
ksuffix(ci, "interactive-cmd-dict-"));
if (ret != Efallthrough)
return ret;
- call_comm("doc:attach-helper", ci->focus, &aspell_attach_helper);
+ call_comm("doc:get-doc", ci->focus, &aspell_attach_helper);
return call("doc:notify:aspell:set-dict", ci->focus, 0, NULL,
ksuffix(ci, "interactive-cmd-dict-"));
}
0, NULL, "Spell:NextWord");
call_comm("global-set-command", ed, &spell_add,
0, NULL, "Spell:AddWord");
+ call_comm("global-set-command", ed, &spell_save,
+ 0, NULL, "Spell:Save");
- call_comm("global-set-command", ed, &spell_dict,
- 0, NULL, "interactive-cmd-dict-",
- 0, NULL, "interactive-cmd-dict-~");
+ call_comm("global-set-command-prefix", ed, &spell_dict,
+ 0, NULL, "interactive-cmd-dict-");
aspell_map = key_alloc();
key_add(aspell_map, "Close", &aspell_close);
- key_add(aspell_map, "Free", &edlib_do_free);
key_add(aspell_map, "aspell:check", &aspell_check);
key_add(aspell_map, "aspell:suggest", &aspell_suggest);
key_add(aspell_map, "aspell:set-dict", &aspell_set_dict);
key_add(aspell_map, "aspell:add-word", &aspell_add);
+ key_add(aspell_map, "aspell:save", &aspell_do_save);
}