~ubuntu-branches/ubuntu/natty/geany/natty

« back to all changes in this revision

Viewing changes to src/filetypes.c

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2010-08-07 03:23:12 UTC
  • mfrom: (1.4.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20100807032312-ot70ac9d50cn79we
Tags: upstream-0.19
ImportĀ upstreamĀ versionĀ 0.19

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *      along with this program; if not, write to the Free Software
19
19
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
20
 *
21
 
 * $Id: filetypes.c 4630 2010-01-31 21:54:47Z eht16 $
 
21
 * $Id: filetypes.c 4803 2010-04-06 16:37:27Z ntrel $
22
22
 */
23
23
 
24
24
/**
26
26
 * Filetype detection, file extensions and filetype menu items.
27
27
 */
28
28
 
 
29
/* Note: we use filetype_id for some function arguments, but GeanyFiletype is better; we should
 
30
 * only use GeanyFiletype for API functions. */
 
31
 
29
32
#include <string.h>
30
33
#include <glib/gstdio.h>
31
34
 
60
63
#ifdef HAVE_REGCOMP
61
64
        regex_t         error_regex;
62
65
        gboolean        error_regex_compiled;
 
66
        gchar           *last_string; /* last one compiled */
63
67
#endif
 
68
        gboolean        custom;
64
69
}
65
70
GeanyFiletypePrivate;
66
71
 
112
117
        ft->lang = -2;
113
118
        ft->name = g_strdup(_("None"));
114
119
        ft->title = g_strdup(_("None"));
115
 
        ft->extension = g_strdup("*");
 
120
        ft->extension = NULL;
116
121
        ft->pattern = utils_strv_new("*", NULL);
117
122
        ft->comment_open = NULL;
118
123
        ft->comment_close = NULL;
375
380
        ft->comment_close = NULL;
376
381
        ft->group = GEANY_FILETYPE_GROUP_MISC;
377
382
 
 
383
#define TXT2TAGS
 
384
        ft = filetypes[GEANY_FILETYPES_TXT2TAGS];
 
385
        ft->lang = 37;
 
386
        ft->name = g_strdup("Txt2tags");
 
387
        filetype_make_title(ft, TITLE_SOURCE_FILE);
 
388
        ft->extension = g_strdup("t2t");
 
389
        ft->pattern = utils_strv_new("*.t2t", "*.txt2tags", NULL);
 
390
        ft->comment_open = NULL;
 
391
        ft->comment_close = NULL;
 
392
        ft->group = GEANY_FILETYPE_GROUP_MISC;
 
393
 
 
394
#define ABC
 
395
        ft = filetypes[GEANY_FILETYPES_ABC];
 
396
        ft->lang = 38;
 
397
        ft->name = g_strdup("Abc");
 
398
        filetype_make_title(ft, TITLE_SOURCE_FILE);
 
399
        ft->extension = g_strdup("abc");
 
400
        ft->pattern = utils_strv_new("*.abc", "*.abp", NULL);
 
401
        ft->comment_open = NULL;
 
402
        ft->comment_close = NULL;
 
403
        ft->group = GEANY_FILETYPE_GROUP_MISC;
 
404
 
378
405
#define SH
379
406
        ft = filetypes[GEANY_FILETYPES_SH];
380
407
        ft->lang = 16;
478
505
        ft->comment_close = NULL;
479
506
        ft->group = GEANY_FILETYPE_GROUP_COMPILED;
480
507
 
 
508
#define VERILOG
 
509
        ft = filetypes[GEANY_FILETYPES_VERILOG];
 
510
        ft->lang = 39;
 
511
        ft->name = g_strdup("Verilog");
 
512
        filetype_make_title(ft, TITLE_SOURCE_FILE);
 
513
        ft->extension = g_strdup("v");
 
514
        ft->pattern = utils_strv_new("*.v", "*.verilog", NULL);
 
515
        ft->comment_open = g_strdup("/*");
 
516
        ft->comment_close = g_strdup("*/");
 
517
        ft->group = GEANY_FILETYPE_GROUP_COMPILED;
 
518
 
481
519
#define DIFF
482
520
        ft = filetypes[GEANY_FILETYPES_DIFF];
483
521
        ft->lang = 20;
536
574
 
537
575
#define R
538
576
        ft = filetypes[GEANY_FILETYPES_R];
539
 
        ft->lang = 34;
 
577
        ft->lang = 40;
540
578
        ft->name = g_strdup("R");
541
579
        ft->title = g_strdup_printf(_("%s script file"), "R");
542
580
        ft->extension = g_strdup("R");
620
658
        GeanyFiletype *ft = g_new0(GeanyFiletype, 1);
621
659
 
622
660
        ft->lang = -2;  /* assume no tagmanager parser */
623
 
        ft->programs = g_new0(struct build_programs, 1);
624
 
        ft->actions = g_new0(struct build_actions, 1);
 
661
        ft->project_list_entry = -1; /* no entry */
625
662
 
626
663
        ft->priv = g_new0(GeanyFiletypePrivate, 1);
627
664
        return ft;
656
693
}
657
694
 
658
695
 
 
696
static void add_custom_filetype(const gchar *filename)
 
697
{
 
698
        gchar *fn = utils_strdupa(strstr(filename, ".") + 1);
 
699
        gchar *dot = g_strrstr(fn, ".conf");
 
700
        GeanyFiletype *ft;
 
701
 
 
702
        g_return_if_fail(dot);
 
703
 
 
704
        *dot = 0x0;
 
705
 
 
706
        if (g_hash_table_lookup(filetypes_hash, fn))
 
707
                return;
 
708
 
 
709
        ft = filetype_new();
 
710
        ft->name = g_strdup(fn);
 
711
        filetype_make_title(ft, TITLE_FILE);
 
712
        ft->pattern = g_new0(gchar*, 1);
 
713
        ft->group = GEANY_FILETYPE_GROUP_CUSTOM;
 
714
        ft->priv->custom = TRUE;
 
715
        filetype_add(ft);
 
716
        geany_debug("Added filetype %s (%d).", ft->name, ft->id);
 
717
}
 
718
 
 
719
 
 
720
static void init_custom_filetypes(const gchar *path)
 
721
{
 
722
        GDir *dir;
 
723
        const gchar *filename;
 
724
 
 
725
        g_return_if_fail(path);
 
726
 
 
727
        dir = g_dir_open(path, 0, NULL);
 
728
        if (dir == NULL)
 
729
                return;
 
730
 
 
731
        foreach_dir(filename, dir)
 
732
        {
 
733
                const gchar prefix[] = "filetypes.";
 
734
 
 
735
                if (g_str_has_prefix(filename, prefix) &&
 
736
                        g_str_has_suffix(filename + strlen(prefix), ".conf"))
 
737
                {
 
738
                        add_custom_filetype(filename);
 
739
                }
 
740
        }
 
741
        g_dir_close(dir);
 
742
}
 
743
 
 
744
 
659
745
/* Create the filetypes array and fill it with the known filetypes. */
660
746
void filetypes_init_types()
661
747
{
679
765
        {
680
766
                filetype_add(filetypes[ft_id]);
681
767
        }
 
768
        init_custom_filetypes(app->datadir);
 
769
        init_custom_filetypes(utils_build_path(app->configdir, GEANY_FILEDEFS_SUBDIR, NULL));
682
770
}
683
771
 
684
772
 
698
786
                 * The user can do this manually with 'Tools->Reload Configuration' */
699
787
                filetypes_load_config(GEANY_FILETYPES_NONE, TRUE);
700
788
 
701
 
                documents_foreach(i)
 
789
                foreach_document(i)
702
790
                        document_reload_config(documents[i]);
703
791
        }
704
792
}
739
827
        create_sub_menu(filetype_menu, GEANY_FILETYPE_GROUP_SCRIPT, _("_Scripting Languages"));
740
828
        create_sub_menu(filetype_menu, GEANY_FILETYPE_GROUP_MARKUP, _("_Markup Languages"));
741
829
        create_sub_menu(filetype_menu, GEANY_FILETYPE_GROUP_MISC, _("M_iscellaneous Languages"));
 
830
        create_sub_menu(filetype_menu, GEANY_FILETYPE_GROUP_CUSTOM, _("_Custom Filetypes"));
742
831
 
743
832
        /* Append all filetypes to the filetype menu */
744
833
        foreach_slist(node, filetypes_by_title)
745
834
        {
746
835
                GeanyFiletype *ft = node->data;
747
836
 
748
 
                if (ft->id != GEANY_FILETYPES_NONE)
 
837
                if (ft->group != GEANY_FILETYPE_GROUP_NONE)
749
838
                        create_radio_menu_item(group_menus[ft->group], ft);
 
839
                else
 
840
                        create_radio_menu_item(filetype_menu, ft);
750
841
        }
751
 
        create_radio_menu_item(filetype_menu, filetypes[GEANY_FILETYPES_NONE]);
752
842
}
753
843
 
754
844
 
755
845
void filetypes_init()
756
846
{
757
847
        filetypes_init_types();
 
848
 
758
849
        create_set_filetype_menu();
759
850
        setup_config_file_menus();
760
851
}
871
962
 
872
963
                if (strncmp(tmp, "env ", 4) == 0 && strlen(tmp) > 4)
873
964
                {       /* skip "env" and read the following interpreter */
874
 
                        basename_interpreter +=4;
 
965
                        basename_interpreter += 4;
875
966
                }
876
967
 
877
968
                if (strncmp(basename_interpreter, "sh", 2) == 0)
976
1067
#ifdef HAVE_PLUGINS
977
1068
/* Currently only used by external plugins (e.g. geanyprj). */
978
1069
/**
979
 
 *  Detect filetype based on a shebang line in the file, or the filename extension.
 
1070
 *  Detects filetype based on a shebang line in the file or the filename extension.
980
1071
 *
981
1072
 *  @param utf8_filename The filename in UTF-8 encoding.
982
1073
 *
1083
1174
        g_free(ft->comment_open);
1084
1175
        g_free(ft->comment_close);
1085
1176
        g_free(ft->context_action_cmd);
1086
 
        g_free(ft->programs->compiler);
1087
 
        g_free(ft->programs->linker);
1088
 
        g_free(ft->programs->run_cmd);
1089
 
        g_free(ft->programs->run_cmd2);
1090
 
        g_free(ft->programs);
1091
 
        g_free(ft->actions);
 
1177
        g_free(ft->filecmds);
 
1178
        g_free(ft->ftdefcmds);
 
1179
        g_free(ft->execcmds);
1092
1180
        set_error_regex(ft, NULL);
1093
1181
 
1094
1182
        g_strfreev(ft->pattern);
1160
1248
                filetypes[ft_id]->context_action_cmd = result;
1161
1249
        }
1162
1250
 
 
1251
        result = utils_get_setting_string(configh, "settings", "tag_parser", NULL);
 
1252
        if (!result)
 
1253
                result = utils_get_setting_string(config, "settings", "tag_parser", NULL);
 
1254
        if (result)
 
1255
        {
 
1256
                ft->lang = tm_source_file_get_named_lang(result);
 
1257
                if (ft->lang < 0)
 
1258
                        geany_debug("Cannot find tag parser '%s' for custom filetype '%s'.", result, ft->name);
 
1259
                g_free(result);
 
1260
        }
 
1261
 
 
1262
        result = utils_get_setting_string(configh, "settings", "lexer_filetype", NULL);
 
1263
        if (!result)
 
1264
                result = utils_get_setting_string(config, "settings", "lexer_filetype", NULL);
 
1265
        if (result)
 
1266
        {
 
1267
                ft->lexer_filetype = filetypes_lookup_by_name(result);
 
1268
                if (!ft->lexer_filetype)
 
1269
                        geany_debug("Cannot find lexer filetype '%s' for custom filetype '%s'.", result, ft->name);
 
1270
                g_free(result);
 
1271
        }
 
1272
 
1163
1273
        /* read build settings */
1164
 
        result = g_key_file_get_string(configh, "build_settings", "compiler", NULL);
1165
 
        if (result == NULL) result = g_key_file_get_string(config, "build_settings", "compiler", NULL);
1166
 
        if (G_LIKELY(result != NULL))
1167
 
        {
1168
 
                filetypes[ft_id]->programs->compiler = result;
1169
 
                filetypes[ft_id]->actions->can_compile = TRUE;
1170
 
        }
1171
 
 
1172
 
        result = g_key_file_get_string(configh, "build_settings", "linker", NULL);
1173
 
        if (result == NULL) result = g_key_file_get_string(config, "build_settings", "linker", NULL);
1174
 
        if (result != NULL)
1175
 
        {
1176
 
                filetypes[ft_id]->programs->linker = result;
1177
 
                filetypes[ft_id]->actions->can_link = TRUE;
1178
 
        }
1179
 
 
1180
 
        result = g_key_file_get_string(configh, "build_settings", "run_cmd", NULL);
1181
 
        if (result == NULL) result = g_key_file_get_string(config, "build_settings", "run_cmd", NULL);
1182
 
        if (G_LIKELY(result != NULL))
1183
 
        {
1184
 
                filetypes[ft_id]->programs->run_cmd = result;
1185
 
                filetypes[ft_id]->actions->can_exec = TRUE;
1186
 
        }
1187
 
 
1188
 
        result = g_key_file_get_string(configh, "build_settings", "run_cmd2", NULL);
1189
 
        if (result == NULL) result = g_key_file_get_string(config, "build_settings", "run_cmd2", NULL);
1190
 
        if (result != NULL)
1191
 
        {
1192
 
                filetypes[ft_id]->programs->run_cmd2 = result;
1193
 
                filetypes[ft_id]->actions->can_exec = TRUE;
1194
 
        }
1195
 
 
1196
 
        result = g_key_file_get_string(configh, "build_settings", "error_regex", NULL);
1197
 
        if (result == NULL) result = g_key_file_get_string(config, "build_settings", "error_regex", NULL);
1198
 
        if (result != NULL)
1199
 
        {
1200
 
                set_error_regex(ft, result);
1201
 
        }
 
1274
        build_load_menu(config, GEANY_BCS_FT, (gpointer)ft);
 
1275
        build_load_menu(configh, GEANY_BCS_HOME_FT, (gpointer)ft);
1202
1276
}
1203
1277
 
1204
1278
 
1205
1279
/* simple wrapper function to print file errors in DEBUG mode */
1206
1280
static void load_system_keyfile(GKeyFile *key_file, const gchar *file, GKeyFileFlags flags,
1207
 
                                                                G_GNUC_UNUSED GError **just_for_compatibility)
 
1281
                GeanyFiletype *ft)
1208
1282
{
1209
1283
        GError *error = NULL;
1210
1284
        gboolean done = g_key_file_load_from_file(key_file, file, flags, &error);
1211
 
        if (G_UNLIKELY(! done) && G_UNLIKELY(error != NULL))
 
1285
 
 
1286
        if (error != NULL)
1212
1287
        {
1213
 
                geany_debug("Failed to open %s (%s)", file, error->message);
 
1288
                if (!done && !ft->priv->custom)
 
1289
                        geany_debug("Failed to open %s (%s)", file, error->message);
 
1290
 
1214
1291
                g_error_free(error);
1215
1292
                error = NULL;
1216
1293
        }
1224
1301
{
1225
1302
        GKeyFile *config, *config_home;
1226
1303
        GeanyFiletypePrivate *pft;
 
1304
        GeanyFiletype *ft;
1227
1305
 
1228
1306
        g_return_if_fail(ft_id >= 0 && ft_id < (gint) filetypes_array->len);
1229
1307
 
1230
 
        pft = filetypes[ft_id]->priv;
 
1308
        ft = filetypes[ft_id];
 
1309
        pft = ft->priv;
1231
1310
 
1232
1311
        /* when reloading, proceed only if the settings were already loaded */
1233
1312
        if (reload && G_UNLIKELY(! pft->keyfile_loaded))
1248
1327
                gchar *f = g_strconcat(app->configdir,
1249
1328
                        G_DIR_SEPARATOR_S GEANY_FILEDEFS_SUBDIR G_DIR_SEPARATOR_S "filetypes.", ext, NULL);
1250
1329
 
1251
 
                load_system_keyfile(config, f0, G_KEY_FILE_KEEP_COMMENTS, NULL);
 
1330
                load_system_keyfile(config, f0, G_KEY_FILE_KEEP_COMMENTS, ft);
1252
1331
                g_key_file_load_from_file(config_home, f, G_KEY_FILE_KEEP_COMMENTS, NULL);
1253
1332
 
1254
1333
                g_free(ext);
1267
1346
gchar *filetypes_get_conf_extension(gint filetype_idx)
1268
1347
{
1269
1348
        gchar *result;
 
1349
        GeanyFiletype *ft = filetypes[filetype_idx];
 
1350
 
 
1351
        if (ft->priv->custom)
 
1352
                return g_strconcat(ft->name, ".conf", NULL);
1270
1353
 
1271
1354
        /* Handle any special extensions different from lowercase filetype->name */
1272
1355
        switch (filetype_idx)
1274
1357
                case GEANY_FILETYPES_CPP: result = g_strdup("cpp"); break;
1275
1358
                case GEANY_FILETYPES_CS: result = g_strdup("cs"); break;
1276
1359
                case GEANY_FILETYPES_MAKE: result = g_strdup("makefile"); break;
1277
 
                default: result = g_ascii_strdown(filetypes[filetype_idx]->name, -1); break;
 
1360
                default: result = g_ascii_strdown(ft->name, -1); break;
1278
1361
        }
1279
1362
        return result;
1280
1363
}
1284
1367
{
1285
1368
        gchar *conf_prefix = g_strconcat(app->configdir,
1286
1369
                G_DIR_SEPARATOR_S GEANY_FILEDEFS_SUBDIR G_DIR_SEPARATOR_S "filetypes.", NULL);
1287
 
        gint i;
 
1370
        guint i;
1288
1371
 
1289
 
        for (i = 1; i < GEANY_MAX_BUILT_IN_FILETYPES; i++)
 
1372
        for (i = 1; i < filetypes_array->len; i++)
1290
1373
        {
1291
 
                struct build_programs *bp = filetypes[i]->programs;
1292
1374
                GKeyFile *config_home;
1293
1375
                gchar *fname, *ext, *data;
1294
1376
 
1295
 
                if (! bp->modified)
1296
 
                        continue;
1297
 
 
1298
 
                ext = filetypes_get_conf_extension(i);
1299
 
                fname = g_strconcat(conf_prefix, ext, NULL);
1300
 
                g_free(ext);
1301
 
 
1302
 
                config_home = g_key_file_new();
1303
 
                g_key_file_load_from_file(config_home, fname, G_KEY_FILE_KEEP_COMMENTS, NULL);
1304
 
 
1305
 
                if (NZV(bp->compiler))
1306
 
                        g_key_file_set_string(config_home, "build_settings", "compiler", bp->compiler);
1307
 
                if (NZV(bp->linker))
1308
 
                        g_key_file_set_string(config_home, "build_settings", "linker", bp->linker);
1309
 
                if (NZV(bp->run_cmd))
1310
 
                        g_key_file_set_string(config_home, "build_settings", "run_cmd", bp->run_cmd);
1311
 
                if (NZV(bp->run_cmd2))
1312
 
                        g_key_file_set_string(config_home, "build_settings", "run_cmd2", bp->run_cmd2);
1313
 
 
1314
 
                data = g_key_file_to_data(config_home, NULL, NULL);
1315
 
                utils_write_file(fname, data);
1316
 
                g_free(data);
1317
 
                g_key_file_free(config_home);
1318
 
                g_free(fname);
 
1377
                if (filetypes[i]->home_save_needed)
 
1378
                {
 
1379
                        ext = filetypes_get_conf_extension(i);
 
1380
                        fname = g_strconcat(conf_prefix, ext, NULL);
 
1381
                        g_free(ext);
 
1382
                        config_home = g_key_file_new();
 
1383
                        g_key_file_load_from_file(config_home, fname, G_KEY_FILE_KEEP_COMMENTS, NULL);
 
1384
                        build_save_menu(config_home, (gpointer)(filetypes[i]), GEANY_BCS_HOME_FT);
 
1385
                        data = g_key_file_to_data(config_home, NULL, NULL);
 
1386
                        utils_write_file(fname, data);
 
1387
                        g_free(data);
 
1388
                        g_key_file_free(config_home);
 
1389
                        g_free(fname);
 
1390
                }
1319
1391
        }
1320
1392
        g_free(conf_prefix);
1321
1393
}
1365
1437
}
1366
1438
 
1367
1439
 
1368
 
/* Indicates whether there is a tag parser for the filetype or not. */
 
1440
/* Indicates whether there is a tag parser for the filetype or not.
 
1441
 * Only works for custom filetypes if the filetype settings have been loaded. */
1369
1442
gboolean filetype_has_tags(GeanyFiletype *ft)
1370
1443
{
1371
1444
        g_return_val_if_fail(ft != NULL, FALSE);
1374
1447
}
1375
1448
 
1376
1449
 
1377
 
/** Find a filetype pointer from its @a name field.
 
1450
/** Finds a filetype pointer from its @a name field.
1378
1451
 * @param name Filetype name.
1379
1452
 * @return The filetype found, or @c NULL.
1380
1453
 *
1401
1474
}
1402
1475
 
1403
1476
 
1404
 
static void compile_regex(GeanyFiletype *ft, regex_t *regex)
 
1477
static void compile_regex(GeanyFiletype *ft, regex_t *regex, gchar *regstr)
1405
1478
{
1406
 
        gint retval = regcomp(regex, ft->error_regex_string, REG_EXTENDED);
 
1479
        gint retval = regcomp(regex, regstr, REG_EXTENDED);
1407
1480
 
1408
1481
        ft->priv->error_regex_compiled = (retval == 0); /* prevent recompilation */
1409
1482
 
1422
1495
gboolean filetypes_parse_error_message(GeanyFiletype *ft, const gchar *message,
1423
1496
                gchar **filename, gint *line)
1424
1497
{
 
1498
        gchar *regstr;
 
1499
        gchar **tmp;
 
1500
        GeanyDocument *doc;
 
1501
#ifdef HAVE_REGCOMP
 
1502
        regex_t *regex;
 
1503
        regmatch_t pmatch[3];
 
1504
#endif
 
1505
        if (ft == NULL)
 
1506
        {
 
1507
                doc = document_get_current();
 
1508
                if (doc != NULL)
 
1509
                        ft = doc->file_type;
 
1510
        }
 
1511
        tmp = build_get_regex(build_info.grp, ft, NULL);
 
1512
        if (tmp == NULL)
 
1513
                return FALSE;
 
1514
        regstr = *tmp;
1425
1515
#ifndef HAVE_REGCOMP
1426
 
        if (!NZV(ft->error_regex_string))
 
1516
        if (!NZV(regstr))
1427
1517
                geany_debug("No regex support - maybe you should configure with --enable-gnu-regex!");
1428
1518
        return FALSE;
1429
1519
#else
1430
 
        regex_t *regex = &ft->priv->error_regex;
1431
 
        regmatch_t pmatch[3];
 
1520
        regex = &ft->priv->error_regex;
1432
1521
 
1433
1522
        *filename = NULL;
1434
1523
        *line = -1;
1435
1524
 
1436
 
        if (!NZV(ft->error_regex_string))
 
1525
        if (!NZV(regstr))
1437
1526
                return FALSE;
1438
1527
 
1439
 
        if (!ft->priv->error_regex_compiled)
1440
 
                compile_regex(ft, regex);
 
1528
        if (!ft->priv->error_regex_compiled || regstr != ft->priv->last_string)
 
1529
        {
 
1530
                compile_regex(ft, regex, regstr);
 
1531
                ft->priv->last_string = regstr;
 
1532
        }
1441
1533
        if (!ft->priv->error_regex_compiled)    /* regex error */
1442
1534
                return FALSE;
1443
1535
 
1487
1579
                "filetype_extensions.conf", NULL);
1488
1580
        gchar *userconfigfile = g_strconcat(app->configdir, G_DIR_SEPARATOR_S,
1489
1581
                "filetype_extensions.conf", NULL);
1490
 
        gchar **list;
1491
1582
        GKeyFile *sysconfig = g_key_file_new();
1492
1583
        GKeyFile *userconfig = g_key_file_new();
1493
1584
 
1499
1590
        {
1500
1591
                gboolean userset =
1501
1592
                        g_key_file_has_key(userconfig, "Extensions", filetypes[i]->name, NULL);
1502
 
                list = g_key_file_get_string_list(
 
1593
                gchar **list = g_key_file_get_string_list(
1503
1594
                        (userset) ? userconfig : sysconfig, "Extensions", filetypes[i]->name, &len, NULL);
 
1595
 
1504
1596
                if (G_LIKELY(list) && G_LIKELY(len > 0))
1505
1597
                {
1506
1598
                        g_strfreev(filetypes[i]->pattern);
1507
1599
                        filetypes[i]->pattern = list;
1508
1600
                }
1509
 
                else g_strfreev(list);
 
1601
                else
 
1602
                        g_strfreev(list);
1510
1603
        }
1511
1604
 
1512
1605
        g_free(sysconfigfile);
1513
1606
        g_free(userconfigfile);
1514
1607
        g_key_file_free(sysconfig);
1515
1608
        g_key_file_free(userconfig);
 
1609
 
 
1610
        foreach_document(i)
 
1611
        {
 
1612
                GeanyDocument *doc = documents[i];
 
1613
                if (doc->file_type->id != GEANY_FILETYPES_NONE)
 
1614
                        continue;
 
1615
                document_set_filetype(doc, filetypes_detect_from_document(doc));
 
1616
        }
1516
1617
}
1517
1618
 
1518
1619
 
1527
1628
{
1528
1629
        return (idx >= 0 && idx < (gint) filetypes_array->len) ? filetypes[idx] : NULL;
1529
1630
}
 
1631
 
 
1632
 
 
1633
void filetypes_reload(void)
 
1634
{
 
1635
        guint i;
 
1636
        GeanyDocument *current_doc;
 
1637
 
 
1638
        /* save possibly changed commands before re-reading them */
 
1639
        filetypes_save_commands();
 
1640
 
 
1641
        /* reload filetype configs */
 
1642
        for (i = 0; i < filetypes_array->len; i++)
 
1643
        {
 
1644
                /* filetypes_load_config() will skip not loaded filetypes */
 
1645
                filetypes_load_config(i, TRUE);
 
1646
        }
 
1647
        /* update document styling */
 
1648
        current_doc = document_get_current();
 
1649
        foreach_document(i)
 
1650
        {
 
1651
                if (current_doc != documents[i])
 
1652
                        document_reload_config(documents[i]);
 
1653
        }
 
1654
        /* process the current document at last */
 
1655
        document_reload_config(current_doc);
 
1656
}
 
1657
 
 
1658