Handle emacs' "-*- langname -*-"

This commit is contained in:
Yevgen Muntyan 2006-12-04 22:55:42 -06:00
parent aca8f50d41
commit db5bfe2d81
3 changed files with 41 additions and 12 deletions

View File

@ -645,9 +645,9 @@ moo_edit_get_editor (MooEdit *doc)
} }
typedef void (*SetVarFunc) (MooEdit *edit, typedef void (*SetVarFunc) (MooEdit *edit,
char *name, const char *name,
char *val); char *val);
static void static void
parse_mode_string (MooEdit *edit, parse_mode_string (MooEdit *edit,
@ -734,9 +734,9 @@ parse_kate_mode_string (MooEdit *edit,
static void static void
set_emacs_var (MooEdit *edit, set_emacs_var (MooEdit *edit,
char *name, const char *name,
char *val) char *val)
{ {
if (!g_ascii_strcasecmp (name, "mode")) if (!g_ascii_strcasecmp (name, "mode"))
{ {
@ -768,7 +768,16 @@ static void
parse_emacs_mode_string (MooEdit *edit, parse_emacs_mode_string (MooEdit *edit,
char *string) char *string)
{ {
parse_mode_string (edit, string, ":", set_emacs_var); MooLangMgr *mgr;
g_strstrip (string);
mgr = moo_editor_get_lang_mgr (edit->priv->editor);
if (_moo_lang_mgr_find_lang (mgr, string))
set_emacs_var (edit, "mode", string);
else
parse_mode_string (edit, string, ":", set_emacs_var);
} }

View File

@ -202,13 +202,33 @@ string_list_free (GSList *list)
MooLang * MooLang *
moo_lang_mgr_get_lang (MooLangMgr *mgr, moo_lang_mgr_get_lang (MooLangMgr *mgr,
const char *name) const char *name)
{
MooLang *lang;
g_return_val_if_fail (MOO_IS_LANG_MGR (mgr), NULL);
if (!name)
return NULL;
lang = _moo_lang_mgr_find_lang (mgr, name);
if (!lang)
g_warning ("could not find language '%s'", name);
return lang;
}
MooLang *
_moo_lang_mgr_find_lang (MooLangMgr *mgr,
const char *name)
{ {
char *id; char *id;
LangInfo *info; LangInfo *info;
g_return_val_if_fail (MOO_IS_LANG_MGR (mgr), NULL); g_return_val_if_fail (MOO_IS_LANG_MGR (mgr), NULL);
g_return_val_if_fail (name != NULL, NULL);
if (!name || !strcmp (name, MOO_LANG_NONE)) if (!strcmp (name, MOO_LANG_NONE))
return NULL; return NULL;
if (!g_ascii_strcasecmp (name, "c++")) if (!g_ascii_strcasecmp (name, "c++"))
@ -217,11 +237,8 @@ moo_lang_mgr_get_lang (MooLangMgr *mgr,
read_langs (mgr); read_langs (mgr);
id = _moo_lang_id_from_name (name); id = _moo_lang_id_from_name (name);
info = get_lang_info (mgr, id, FALSE); info = get_lang_info (mgr, id, FALSE);
if (!info)
g_warning ("could not find language '%s'", name);
g_free (id); g_free (id);
return info ? info->lang : NULL; return info ? info->lang : NULL;
} }

View File

@ -42,6 +42,9 @@ GSList *moo_lang_mgr_get_available_langs (MooLangMgr *mgr);
/* list must be freed together with content */ /* list must be freed together with content */
GSList *moo_lang_mgr_get_sections (MooLangMgr *mgr); GSList *moo_lang_mgr_get_sections (MooLangMgr *mgr);
MooLang *_moo_lang_mgr_find_lang (MooLangMgr *mgr,
const char *name);
MooTextStyleScheme *_moo_lang_mgr_get_active_scheme (MooLangMgr *mgr); MooTextStyleScheme *_moo_lang_mgr_get_active_scheme (MooLangMgr *mgr);
void _moo_lang_mgr_set_active_scheme (MooLangMgr *mgr, void _moo_lang_mgr_set_active_scheme (MooLangMgr *mgr,
const char *scheme_name); const char *scheme_name);