diff --git a/CMakeLists.txt b/CMakeLists.txt
index f381d97..a85f935 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -43,7 +43,7 @@ OPTION(DISABLE_NLS "Disable Native Language Support")
OPTION(DISABLE_GNUTLS "Disable SSLv3/TLS connection support")
OPTION(DISABLE_LARGEFILE "Disable Large File Support")
OPTION(DISABLE_ALIAS "Disable Alias plugin")
-OPTION(DISABLE_ASPELL "Disable Aspell plugin")
+OPTION(DISABLE_SPELL "Disable Spell plugin")
OPTION(DISABLE_CHARSET "Disable Charset plugin")
OPTION(ENABLE_DEMO "Enable Demo plugin")
OPTION(DISABLE_FIFO "Disable FIFO plugin")
diff --git a/Makefile.am b/Makefile.am
index 5e31593..d0cf371 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -26,6 +26,7 @@ EXTRA_DIST = CMakeLists.txt \
cmake/cmake_uninstall.cmake.in \
cmake/FindAsciidoc.cmake \
cmake/FindAspell.cmake \
+ cmake/FindENCHANT.cmake \
cmake/FindGettext.cmake \
cmake/FindGnuTLS.cmake \
cmake/FindIconv.cmake \
diff --git a/cmake/FindENCHANT.cmake b/cmake/FindENCHANT.cmake
new file mode 100644
index 0000000..9c13c48
--- /dev/null
+++ b/cmake/FindENCHANT.cmake
@@ -0,0 +1,44 @@
+# - Try to find the Enchant spell checker
+# Once done this will define
+#
+# ENCHANT_FOUND - system has ENCHANT
+# ENCHANT_INCLUDE_DIR - the ENCHANT include directory
+# ENCHANT_LIBRARIES - Link these to use ENCHANT
+# ENCHANT_DEFINITIONS - Compiler switches required for using ENCHANT
+
+# Copyright (c) 2006, Zack Rusin, <zack@kde.org>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+
+if (ENCHANT_INCLUDE_DIR AND ENCHANT_LIBRARIES)
+
+ # in cache already
+ set(ENCHANT_FOUND TRUE)
+
+else (ENCHANT_INCLUDE_DIR AND ENCHANT_LIBRARIES)
+ if (NOT WIN32)
+ # use pkg-config to get the directories and then use these values
+ # in the FIND_PATH() and FIND_LIBRARY() calls
+ find_package(PkgConfig)
+ pkg_check_modules(PC_ENCHANT QUIET enchant)
+ set(ENCHANT_DEFINITIONS ${PC_ENCHANT_CFLAGS_OTHER})
+ endif (NOT WIN32)
+
+ find_path(ENCHANT_INCLUDE_DIR
+ NAMES enchant++.h
+ HINTS ${PC_ENCHANT_INCLUDEDIR}
+ ${PC_ENCHANT_INCLUDE_DIRS}
+ PATH_SUFFIXES enchant )
+
+ find_library(ENCHANT_LIBRARIES NAMES enchant
+ HINTS ${PC_ENCHANT_LIBDIR}
+ ${PC_ENCHANT_LIBRARY_DIRS} )
+
+ include(FindPackageHandleStandardArgs)
+ find_package_handle_standard_args(ENCHANT DEFAULT_MSG ENCHANT_INCLUDE_DIR ENCHANT_LIBRARIES )
+
+ mark_as_advanced(ENCHANT_INCLUDE_DIR ENCHANT_LIBRARIES)
+
+endif (ENCHANT_INCLUDE_DIR AND ENCHANT_LIBRARIES)
diff --git a/configure.in b/configure.in
index 23274d6..324630b 100644
--- a/configure.in
+++ b/configure.in
@@ -96,7 +96,7 @@ AH_VERBATIM([WEECHAT_SHAREDIR], [#undef WEECHAT_SHAREDIR])
AH_VERBATIM([HAVE_GNUTLS], [#undef HAVE_GNUTLS])
AH_VERBATIM([HAVE_FLOCK], [#undef HAVE_FLOCK])
AH_VERBATIM([PLUGIN_ALIAS], [#undef PLUGIN_ALIAS])
-AH_VERBATIM([PLUGIN_ASPELL], [#undef PLUGIN_ASPELL])
+AH_VERBATIM([PLUGIN_SPELL], [#undef PLUGIN_SPELL])
AH_VERBATIM([PLUGIN_CHARSET], [#undef PLUGIN_CHARSET])
AH_VERBATIM([PLUGIN_DEMO], [#undef PLUGIN_DEMO])
AH_VERBATIM([PLUGIN_FIFO], [#undef PLUGIN_FIFO])
@@ -120,7 +120,7 @@ AC_ARG_ENABLE(qt, [ --enable-qt turn on Qt interface (def
AC_ARG_ENABLE(gnutls, [ --disable-gnutls turn off gnutls support (default=compiled if found)],enable_gnutls=$enableval,enable_gnutls=yes)
AC_ARG_ENABLE(largefile, [ --disable-largefile turn off Large File Support (default=on)],enable_largefile=$enableval,enable_largefile=yes)
AC_ARG_ENABLE(alias, [ --disable-alias turn off Alias plugin (default=compiled)],enable_alias=$enableval,enable_alias=yes)
-AC_ARG_ENABLE(aspell, [ --disable-aspell turn off Aspell plugin (default=compiled)],enable_aspell=$enableval,enable_aspell=yes)
+AC_ARG_ENABLE(spell, [ --disable-spell turn off Spell plugin (default=compiled)],enable_spell=$enableval,enable_spell=yes)
AC_ARG_ENABLE(charset, [ --disable-charset turn off Charset plugin (default=compiled if found)],enable_charset=$enableval,enable_charset=yes)
AC_ARG_ENABLE(demo, [ --enable-demo turn on Demo plugin (default=off)],enable_demo=$enableval,enable_demo=no)
AC_ARG_ENABLE(fifo, [ --disable-fifo turn off Fifo plugin (default=compiled)],enable_fifo=$enableval,enable_fifo=yes)
@@ -295,36 +295,41 @@ else
not_asked="$not_asked alias"
fi
-# ---------------------------------- aspell ------------------------------------
+# ---------------------------------- spelling ----------------------------------
-if test "x$enable_aspell" = "xyes" ; then
- ASPELL_CFLAGS=""
- ASPELL_LFLAGS=""
+if test "x$enable_spell" = "xyes" ; then
+ # Check ENCHANT is available
+ PKG_CHECK_MODULES(ENCHANT, [enchant], [CFLAGS="$CFLAGS -DUSE_ENCHANT"],
+ # otherwise Check ASPELL is available
+ [
+ ASPELL_CFLAGS=""
+ ASPELL_LFLAGS=""
- AC_CHECK_HEADER(aspell.h,ac_found_aspell_header="yes",ac_found_aspell_header="no")
- AC_CHECK_LIB(aspell,new_aspell_speller,ac_found_aspell_lib="yes",ac_found_aspell_lib="no")
+ AC_CHECK_HEADER(aspell.h,ac_found_aspell_header="yes",ac_found_aspell_header="no")
+ AC_CHECK_LIB(aspell,new_aspell_speller,ac_found_aspell_lib="yes",ac_found_aspell_lib="no")
- AC_MSG_CHECKING(for aspell headers and librairies)
- if test "x$ac_found_aspell_header" = "xno" -o "x$ac_found_aspell_lib" = "xno" ; then
- AC_MSG_RESULT(no)
- AC_MSG_WARN([
+ AC_MSG_CHECKING(for aspell headers and librairies)
+ if test "x$ac_found_aspell_header" = "xno" -o "x$ac_found_aspell_lib" = "xno" ; then
+ AC_MSG_RESULT(no)
+ AC_MSG_WARN([
*** Aspell headers and/or libraries couldn't be found on your system.
*** Try to install them with your software package manager.
*** WeeChat will be built without Aspell support.])
- enable_aspell="no"
- not_found="$not_found aspell"
- else
- AC_MSG_RESULT(yes)
- ASPELL_LFLAGS="$ASPELL_LFLAGS -laspell"
+ enable_spell="no"
+ not_found="$not_found spell"
+ else
+ AC_MSG_RESULT(yes)
+ ASPELL_LFLAGS="$ASPELL_LFLAGS -laspell"
+ fi
fi
else
- not_asked="$not_asked aspell"
+ not_asked="$not_asked spell"
fi
-if test "x$enable_aspell" = "xyes" ; then
+if test "x$enable_spell" = "xyes" ; then
AC_SUBST(ASPELL_CFLAGS)
AC_SUBST(ASPELL_LFLAGS)
- AC_DEFINE(PLUGIN_ASPELL)
+ AC_DEFINE(PLUGIN_SPELL)
fi
# --------------------------------- charset ------------------------------------
@@ -920,7 +925,7 @@ AM_CONDITIONAL(GUI_WXWIDGETS, test "$enable_wxwidgets" = "yes")
AM_CONDITIONAL(GUI_GTK, test "$enable_gtk" = "yes")
AM_CONDITIONAL(GUI_QT, test "$enable_qt" = "yes")
AM_CONDITIONAL(PLUGIN_ALIAS, test "$enable_alias" = "yes")
-AM_CONDITIONAL(PLUGIN_ASPELL, test "$enable_aspell" = "yes")
+AM_CONDITIONAL(PLUGIN_SPELL, test "$enable_spell" = "yes")
AM_CONDITIONAL(PLUGIN_CHARSET, test "$enable_charset" = "yes")
AM_CONDITIONAL(PLUGIN_DEMO, test "$enable_demo" = "yes")
AM_CONDITIONAL(PLUGIN_FIFO, test "$enable_fifo" = "yes")
@@ -995,8 +1000,8 @@ listplugins=""
if test "x$enable_alias" = "xyes"; then
listplugins="$listplugins alias"
fi
-if test "x$enable_aspell" = "xyes"; then
- listplugins="$listplugins aspell"
+if test "x$enable_spell" = "xyes"; then
+ listplugins="$listplugins spell"
fi
if test "x$enable_charset" = "xyes"; then
listplugins="$listplugins charset"
diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt
index 278374a..6003727 100644
--- a/src/plugins/CMakeLists.txt
+++ b/src/plugins/CMakeLists.txt
@@ -31,13 +31,19 @@ IF(NOT DISABLE_ALIAS)
ADD_SUBDIRECTORY( alias )
ENDIF(NOT DISABLE_ALIAS)
-IF(NOT DISABLE_ASPELL)
- # Check for aspell libraries
- FIND_PACKAGE(Aspell)
- IF(ASPELL_FOUND)
+IF(NOT DISABLE_SPELL)
+ # Check for enchant libraries
+ FIND_PACKAGE(ENCHANT)
+ IF(ENCHANT_FOUND)
ADD_SUBDIRECTORY( aspell )
- ENDIF(ASPELL_FOUND)
-ENDIF(NOT DISABLE_ASPELL)
+ ELSE(ENCHANT_FOUND)
+ # Check for aspell libraries
+ FIND_PACKAGE(Aspell)
+ IF(ASPELL_FOUND)
+ ADD_SUBDIRECTORY( aspell )
+ ENDIF(ASPELL_FOUND)
+ ENDIF(ENCHANT_FOUND)
+ENDIF(NOT DISABLE_SPELL)
IF(NOT DISABLE_CHARSET)
# Check for iconv support.
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index 4fa2fbf..3efb5e7 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -30,7 +30,7 @@ if PLUGIN_ALIAS
alias_dir = alias
endif
-if PLUGIN_ASPELL
+if PLUGIN_SPELL
aspell_dir = aspell
endif
diff --git a/src/plugins/aspell/CMakeLists.txt b/src/plugins/aspell/CMakeLists.txt
index 1141ccd..8a223e5 100644
--- a/src/plugins/aspell/CMakeLists.txt
+++ b/src/plugins/aspell/CMakeLists.txt
@@ -20,9 +20,15 @@ weechat-aspell-config.c weechat-aspell-config.h
weechat-aspell-speller.c weechat-aspell-speller.h)
SET_TARGET_PROPERTIES(aspell PROPERTIES PREFIX "")
-IF(ASPELL_FOUND)
- INCLUDE_DIRECTORIES(${ASPELL_INCLUDE_PATH})
- TARGET_LINK_LIBRARIES(aspell ${ASPELL_LIBRARY})
-ENDIF(ASPELL_FOUND)
+IF(ENCHANT_FOUND)
+ INCLUDE_DIRECTORIES(${ENCHANT_INCLUDE_DIR})
+ TARGET_LINK_LIBRARIES(aspell ${ENCHANT_LIBRARIES})
+ ADD_DEFINITIONS(-DUSE_ENCHANT)
+ELSE(ENCHANT_FOUND)
+ IF(ASPELL_FOUND)
+ INCLUDE_DIRECTORIES(${ASPELL_INCLUDE_PATH})
+ TARGET_LINK_LIBRARIES(aspell ${ASPELL_LIBRARY})
+ ENDIF(ASPELL_FOUND)
+ENDIF(ENCHANT_FOUND)
INSTALL(TARGETS aspell LIBRARY DESTINATION lib/${PROJECT_NAME}/plugins)
diff --git a/src/plugins/aspell/Makefile.am b/src/plugins/aspell/Makefile.am
index 942fa11..95a765e 100644
--- a/src/plugins/aspell/Makefile.am
+++ b/src/plugins/aspell/Makefile.am
@@ -14,7 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(ASPELL_CFLAGS)
+INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(ASPELL_CFLAGS) $(ENCHANT_CFLAGS)
libdir = ${weechat_libdir}/plugins
@@ -27,6 +27,6 @@ aspell_la_SOURCES = weechat-aspell.c \
weechat-aspell-speller.c \
weechat-aspell-speller.h
aspell_la_LDFLAGS = -module
-aspell_la_LIBADD = $(ASPELL_LFLAGS)
+aspell_la_LIBADD = $(ASPELL_LFLAGS) $(ENCHANT_LIBS)
EXTRA_DIST = CMakeLists.txt
diff --git a/src/plugins/aspell/weechat-aspell-config.c b/src/plugins/aspell/weechat-aspell-config.c
index 4d68f4b..0aaf4c1 100644
--- a/src/plugins/aspell/weechat-aspell-config.c
+++ b/src/plugins/aspell/weechat-aspell-config.c
@@ -208,7 +208,7 @@ weechat_aspell_config_dict_create_option (void *data,
{
weechat_printf (NULL,
_("%s%s: error creating aspell dictionary \"%s\" => \"%s\""),
- weechat_prefix ("error"), ASPELL_PLUGIN_NAME,
+ weechat_prefix ("error"), SPELL_PLUGIN_NAME,
option_name, value);
}
else
@@ -253,7 +253,7 @@ weechat_aspell_config_init ()
{
struct t_config_section *ptr_section;
- weechat_aspell_config_file = weechat_config_new (ASPELL_CONFIG_NAME,
+ weechat_aspell_config_file = weechat_config_new (SPELL_CONFIG_NAME,
NULL, NULL);
if (!weechat_aspell_config_file)
return 0;
diff --git a/src/plugins/aspell/weechat-aspell-config.h b/src/plugins/aspell/weechat-aspell-config.h
index 6f8fc3a..5d9a49e 100644
--- a/src/plugins/aspell/weechat-aspell-config.h
+++ b/src/plugins/aspell/weechat-aspell-config.h
@@ -20,7 +20,7 @@
#ifndef __WEECHAT_ASPELL_CONFIG_H
#define __WEECHAT_ASPELL_CONFIG_H 1
-#define ASPELL_CONFIG_NAME "aspell"
+#define SPELL_CONFIG_NAME "spell"
extern struct t_config_option *weechat_aspell_config_look_color;
diff --git a/src/plugins/aspell/weechat-aspell-speller.c b/src/plugins/aspell/weechat-aspell-speller.c
index 76fbb98..fac719d 100644
--- a/src/plugins/aspell/weechat-aspell-speller.c
+++ b/src/plugins/aspell/weechat-aspell-speller.c
@@ -30,6 +30,9 @@
struct t_aspell_speller *weechat_aspell_spellers = NULL;
struct t_aspell_speller *last_weechat_aspell_speller = NULL;
+#ifdef USE_ENCHANT
+extern EnchantBroker *broker;
+#endif
/*
* weechat_aspell_speller_exists: return 1 if an aspell dict exists for a lang,
@@ -39,6 +42,9 @@ struct t_aspell_speller *last_weechat_aspell_speller = NULL;
int
weechat_aspell_speller_exists (const char *lang)
{
+#ifdef USE_ENCHANT
+ return enchant_broker_dict_exists(broker, lang);
+#else
struct AspellConfig *config;
AspellDictInfoList *list;
AspellDictInfoEnumeration *el;
@@ -64,6 +70,7 @@ weechat_aspell_speller_exists (const char *lang)
delete_aspell_config (config);
return rc;
+#endif
}
/*
@@ -90,7 +97,7 @@ weechat_aspell_speller_check_dictionaries (const char *dict_list)
weechat_printf (NULL,
_("%s: warning: dictionary \"%s\" is not "
"available on your system"),
- ASPELL_PLUGIN_NAME, argv[i]);
+ SPELL_PLUGIN_NAME, argv[i]);
}
}
weechat_string_free_split (argv);
@@ -126,8 +133,12 @@ struct t_aspell_speller *
weechat_aspell_speller_new (const char *lang)
{
struct t_aspell_speller *new_speller;
+#ifdef USE_ENCHANT
+ EnchantDict *ret;
+#else
AspellConfig *config;
AspellCanHaveError *ret;
+#endif
if (!lang)
return NULL;
@@ -136,9 +147,20 @@ weechat_aspell_speller_new (const char *lang)
{
weechat_printf (NULL,
"%s: creating new speller for lang \"%s\"",
- ASPELL_PLUGIN_NAME, lang);
+ SPELL_PLUGIN_NAME, lang);
}
+#ifdef USE_ENCHANT
+ ret = enchant_broker_request_dict (broker, lang);
+ if (!ret)
+ {
+ weechat_printf (NULL,
+ "%s%s: error: %s",
+ weechat_prefix ("error"), SPELL_PLUGIN_NAME,
+ lang);
+ return NULL;
+ }
+#else
/* create a speller instance for the newly created cell */
config = new_aspell_config();
aspell_config_replace (config, "lang", lang);
@@ -149,24 +171,29 @@ weechat_aspell_speller_new (const char *lang)
{
weechat_printf (NULL,
"%s%s: error: %s",
- weechat_prefix ("error"), ASPELL_PLUGIN_NAME,
+ weechat_prefix ("error"), SPELL_PLUGIN_NAME,
aspell_error_message (ret));
delete_aspell_config (config);
delete_aspell_can_have_error (ret);
return NULL;
}
-
+#endif
+
/* create and add a new speller cell */
new_speller = malloc (sizeof (*new_speller));
if (!new_speller)
{
weechat_printf (NULL,
_("%s%s: not enough memory to create new speller"),
- weechat_prefix ("error"), ASPELL_PLUGIN_NAME);
+ weechat_prefix ("error"), SPELL_PLUGIN_NAME);
return NULL;
}
+#ifdef USE_ENCHANT
+ new_speller->speller = ret;
+#else
new_speller->speller = to_aspell_speller (ret);
+#endif
new_speller->lang = strdup (lang);
/* add speller to list */
@@ -178,8 +205,10 @@ weechat_aspell_speller_new (const char *lang)
weechat_aspell_spellers = new_speller;
last_weechat_aspell_speller = new_speller;
+#ifndef USE_ENCHANT
/* free config */
delete_aspell_config (config);
+#endif
return new_speller;
}
@@ -198,14 +227,18 @@ weechat_aspell_speller_free (struct t_aspell_speller *speller)
{
weechat_printf (NULL,
"%s: removing speller for lang \"%s\"",
- ASPELL_PLUGIN_NAME, speller->lang);
+ SPELL_PLUGIN_NAME, speller->lang);
}
/* free data */
if (speller->speller)
{
+#ifdef USE_ENCHANT
+ enchant_broker_free_dict(broker, speller->speller);
+#else
aspell_speller_save_all_word_lists (speller->speller);
delete_aspell_speller (speller->speller);
+#endif
}
if (speller->lang)
free (speller->lang);
diff --git a/src/plugins/aspell/weechat-aspell-speller.h b/src/plugins/aspell/weechat-aspell-speller.h
index 6466409..af53974 100644
--- a/src/plugins/aspell/weechat-aspell-speller.h
+++ b/src/plugins/aspell/weechat-aspell-speller.h
@@ -22,7 +22,11 @@
struct t_aspell_speller
{
+#ifdef USE_ENCHANT
+ EnchantDict *speller; /* enchant speller */
+#else
AspellSpeller *speller; /* aspell speller */
+#endif
char *lang; /* language */
struct t_aspell_speller *prev_speller; /* pointer to next speller */
diff --git a/src/plugins/aspell/weechat-aspell.c b/src/plugins/aspell/weechat-aspell.c
index 8c3d758..e9125a7 100644
--- a/src/plugins/aspell/weechat-aspell.c
+++ b/src/plugins/aspell/weechat-aspell.c
@@ -31,7 +31,7 @@
#include "weechat-aspell-speller.h"
-WEECHAT_PLUGIN_NAME(ASPELL_PLUGIN_NAME);
+WEECHAT_PLUGIN_NAME(SPELL_PLUGIN_NAME);
WEECHAT_PLUGIN_DESCRIPTION("Aspell plugin for WeeChat");
WEECHAT_PLUGIN_AUTHOR("FlashCode <flashcode@flashtux.org>");
WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION);
@@ -42,6 +42,10 @@ struct t_weechat_plugin *weechat_aspell_plugin = NULL;
char *aspell_last_modifier_string = NULL; /* last str. received by modifier */
char *aspell_last_modifier_result = NULL; /* last str. built by modifier */
+#ifdef USE_ENCHANT
+EnchantBroker *broker;
+#endif
+
/* aspell supported langs (updated on of 2008-10-17) */
struct t_aspell_code langs_avail[] =
{
@@ -251,10 +255,10 @@ weechat_aspell_set_dict (struct t_gui_buffer *buffer, const char *value)
{
if (value && value[0])
weechat_printf (NULL, "%s: \"%s\" => %s",
- ASPELL_PLUGIN_NAME, name, value);
+ SPELL_PLUGIN_NAME, name, value);
else
weechat_printf (NULL, _("%s: \"%s\" removed"),
- ASPELL_PLUGIN_NAME, name);
+ SPELL_PLUGIN_NAME, name);
}
free (name);
@@ -393,6 +397,55 @@ weechat_aspell_iso_to_country (const char *code)
return strdup ("Unknown");
}
+#ifdef USE_ENCHANT
+void EnchantDictDescribe(const char * const lang_tag,
+ const char * const provider_name,
+ const char * const provider_desc,
+ const char * const provider_file,
+ void * user_data)
+{
+ char *country, *lang, *pos;
+ char buffer[192];
+ (void)provider_name;
+ (void)provider_desc;
+ (void)provider_file;
+ (void)user_data;
+
+ country = NULL;
+ pos = strchr (lang_tag, '_');
+ if (!pos)
+ pos = strchr (lang_tag, '-');
+
+ if (pos)
+ {
+ pos[0] = '\0';
+ lang = weechat_aspell_iso_to_lang ((char*)lang_tag);
+ pos[0] = '_';
+ country = weechat_aspell_iso_to_country (pos + 1);
+ }
+ else
+ lang = weechat_aspell_iso_to_lang ((char*)lang_tag);
+
+ if (pos)
+ {
+ snprintf (buffer, sizeof (buffer), "%-22s %s (%s)",
+ lang_tag, lang, country);
+ }
+ else
+ {
+ snprintf (buffer, sizeof (buffer), "%-22s %s",
+ lang_tag, lang);
+ }
+
+ weechat_printf (NULL, " %s", buffer);
+
+ if (lang)
+ free (lang);
+ if (country)
+ free (country);
+}
+#endif
+
/*
* weechat_aspell_speller_list_dicts: list all aspell dict installed on system
* and display them
@@ -401,6 +454,7 @@ weechat_aspell_iso_to_country (const char *code)
void
weechat_aspell_speller_list_dicts ()
{
+#ifndef USE_ENCHANT
char *country, *lang, *pos;
char buffer[192];
struct AspellConfig *config;
@@ -411,13 +465,18 @@ weechat_aspell_speller_list_dicts ()
config = new_aspell_config();
list = get_aspell_dict_info_list (config);
el = aspell_dict_info_list_elements (list);
-
+
+#endif
+
weechat_printf (NULL, "");
weechat_printf (NULL,
- /* TRANSLATORS: %s is "aspell" */
+ /* TRANSLATORS: %s is "spell" */
_( "%s dictionaries list:"),
- ASPELL_PLUGIN_NAME);
-
+ SPELL_PLUGIN_NAME);
+
+#ifdef USE_ENCHANT
+ enchant_broker_list_dicts(broker, EnchantDictDescribe, NULL);
+#else
while ((dict = aspell_dict_info_enumeration_next (el)))
{
country = NULL;
@@ -470,6 +529,7 @@ weechat_aspell_speller_list_dicts ()
delete_aspell_dict_info_enumeration (el);
delete_aspell_config (config);
+#endif
}
/*
@@ -490,7 +550,7 @@ weechat_aspell_add_word (const char *lang, const char *word)
weechat_printf (NULL,
_("%s: error: dictionary \"%s\" is not "
"available on your system"),
- ASPELL_PLUGIN_NAME, lang);
+ SPELL_PLUGIN_NAME, lang);
return;
}
new_speller = weechat_aspell_speller_new (lang);
@@ -499,21 +559,25 @@ weechat_aspell_add_word (const char *lang, const char *word)
ptr_speller = new_speller;
}
+#ifdef USE_ENCHANT
+ enchant_dict_add(ptr_speller->speller, word, strlen(word));
+#else
if (aspell_speller_add_to_personal (ptr_speller->speller,
word,
strlen (word)) == 1)
{
weechat_printf (NULL,
_("%s: word \"%s\" added to personal dictionary"),
- ASPELL_PLUGIN_NAME, word);
+ SPELL_PLUGIN_NAME, word);
}
else
{
weechat_printf (NULL,
_("%s%s: failed to add word to personal "
"dictionary"),
- weechat_prefix ("error"), ASPELL_PLUGIN_NAME);
+ weechat_prefix ("error"), SPELL_PLUGIN_NAME);
}
+#endif
if (new_speller)
weechat_aspell_speller_free (new_speller);
@@ -644,7 +708,11 @@ weechat_aspell_check_word (struct t_gui_buffer *buffer, const char *word)
for (ptr_speller = weechat_aspell_spellers; ptr_speller;
ptr_speller = ptr_speller->next_speller)
{
+#ifdef USE_ENCHANT
+ if (enchant_dict_check(ptr_speller->speller, word, strlen(word)) == 0)
+#else
if (aspell_speller_check (ptr_speller->speller, word, -1) == 1)
+#endif
{
rc = 1;
break;
@@ -870,7 +938,7 @@ weechat_aspell_command_cb (void *data, struct t_gui_buffer *buffer,
_("%s%s: no dictionary on this buffer for "
"adding word"),
weechat_prefix ("error"),
- ASPELL_PLUGIN_NAME);
+ SPELL_PLUGIN_NAME);
}
else if (weechat_aspell_spellers->next_speller)
{
@@ -878,7 +946,7 @@ weechat_aspell_command_cb (void *data, struct t_gui_buffer *buffer,
_("%s%s: many dictionaries are defined for "
"this buffer, please specify dictionary"),
weechat_prefix ("error"),
- ASPELL_PLUGIN_NAME);
+ SPELL_PLUGIN_NAME);
}
else
weechat_aspell_add_word (weechat_aspell_spellers->lang,
@@ -945,6 +1013,13 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
(void) argv;
weechat_plugin = plugin;
+
+#ifdef USE_ENCHANT
+ /* acquire enchant broker */
+ broker = enchant_broker_init();
+ if (!broker)
+ return WEECHAT_RC_ERROR;
+#endif
if (!weechat_aspell_config_init ())
return WEECHAT_RC_ERROR;
@@ -952,26 +1027,26 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
if (weechat_aspell_config_read () < 0)
return WEECHAT_RC_ERROR;
- /* command /aspell */
- weechat_hook_command ("aspell",
- N_("aspell plugin configuration"),
+ /* command /spell */
+ weechat_hook_command ("spell",
+ N_("spell plugin configuration"),
N_("dictlist | enable lang | disable | "
"addword [lang] word"),
N_("dictlist: show installed dictionaries\n"
- " enable: enable aspell on current buffer\n"
- " disable: disable aspell on current buffer\n"
- " addword: add a word in your personal aspell "
+ " enable: enable spell on current buffer\n"
+ " disable: disable spell on current buffer\n"
+ " addword: add a word in your personal spell "
"dictionary\n"
"\n"
"Input line beginning with a '/' is not checked, "
"except for some commands."),
"dictlist"
- " || enable %(aspell_langs)"
+ " || enable %(spell_langs)"
" || disable"
" || addword",
&weechat_aspell_command_cb, NULL);
- weechat_hook_completion ("aspell_langs",
- N_("list of supported langs for aspell"),
+ weechat_hook_completion ("spell_langs",
+ N_("list of supported langs for spell"),
&weechat_aspell_completion_langs_cb, NULL);
/* callback for buffer_switch */
@@ -981,7 +1056,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
/* callback for spell checking input text */
weechat_hook_modifier ("input_text_display",
&weechat_aspell_modifier_cb, NULL);
-
+
+
weechat_aspell_create_spellers (weechat_current_buffer ());
return WEECHAT_RC_OK;
@@ -1007,6 +1083,11 @@ weechat_plugin_end (struct t_weechat_plugin *plugin)
free (aspell_last_modifier_result);
weechat_aspell_config_free ();
+
+#ifdef USE_ENCHANT
+ /* release enchant broker */
+ enchant_broker_free (broker);
+#endif
return WEECHAT_RC_OK;
}
diff --git a/src/plugins/aspell/weechat-aspell.h b/src/plugins/aspell/weechat-aspell.h
index 763652b..038dcaa 100644
--- a/src/plugins/aspell/weechat-aspell.h
+++ b/src/plugins/aspell/weechat-aspell.h
@@ -20,10 +20,14 @@
#ifndef __WEECHAT_ASPELL_H
#define __WEECHAT_ASPELL_H 1
-#include <aspell.h>
+#ifdef USE_ENCHANT
+# include <enchant.h>
+#else
+# include <aspell.h>
+#endif
#define weechat_plugin weechat_aspell_plugin
-#define ASPELL_PLUGIN_NAME "aspell"
+#define SPELL_PLUGIN_NAME "spell"
struct t_aspell_code
{