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,
char *name,
char *val);
typedef void (*SetVarFunc) (MooEdit *edit,
const char *name,
char *val);
static void
parse_mode_string (MooEdit *edit,
@ -734,9 +734,9 @@ parse_kate_mode_string (MooEdit *edit,
static void
set_emacs_var (MooEdit *edit,
char *name,
char *val)
set_emacs_var (MooEdit *edit,
const char *name,
char *val)
{
if (!g_ascii_strcasecmp (name, "mode"))
{
@ -768,7 +768,16 @@ static void
parse_emacs_mode_string (MooEdit *edit,
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 *
moo_lang_mgr_get_lang (MooLangMgr *mgr,
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;
LangInfo *info;
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;
if (!g_ascii_strcasecmp (name, "c++"))
@ -217,11 +237,8 @@ moo_lang_mgr_get_lang (MooLangMgr *mgr,
read_langs (mgr);
id = _moo_lang_id_from_name (name);
info = get_lang_info (mgr, id, FALSE);
if (!info)
g_warning ("could not find language '%s'", name);
g_free (id);
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 */
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);
void _moo_lang_mgr_set_active_scheme (MooLangMgr *mgr,
const char *scheme_name);