Revision: 1521 http://svn.sourceforge.net/geany/?rev=1521&view=rev Author: ntrel Date: 2007-05-11 04:58:56 -0700 (Fri, 11 May 2007)
Log Message: ----------- Load global tag files stored in ~/.geany/tags when needed.
Modified Paths: -------------- trunk/ChangeLog trunk/src/highlighting.c trunk/src/highlighting.h trunk/src/symbols.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-05-11 11:42:00 UTC (rev 1520) +++ trunk/ChangeLog 2007-05-11 11:58:56 UTC (rev 1521) @@ -2,6 +2,8 @@
* src/utils.c, src/utils.h, src/search.c: Move search_get_file_list() to utils.c. + * src/highlighting.c, src/highlighting.h, src/symbols.c: + Load global tag files stored in ~/.geany/tags when needed.
2007-05-10 Nick Treleaven nick.treleaven@btinternet.com
Modified: trunk/src/highlighting.c =================================================================== --- trunk/src/highlighting.c 2007-05-11 11:42:00 UTC (rev 1520) +++ trunk/src/highlighting.c 2007-05-11 11:58:56 UTC (rev 1521) @@ -423,7 +423,7 @@ }
-void styleset_common(ScintillaObject *sci, gint style_bits) +static void styleset_common(ScintillaObject *sci, gint style_bits, filetype_id ft_id) { static gboolean common_style_set_valid = FALSE;
@@ -436,6 +436,10 @@ common_style_set_valid = TRUE; }
+ // load global tags file for autocompletion, calltips, etc. + if (ft_id < GEANY_FILETYPES_ALL) + symbols_global_tags_loaded(ft_id); + SSM(sci, SCI_STYLECLEARALL, 0, 0);
// caret colour and width @@ -699,15 +703,14 @@
g_key_file_free(config); g_key_file_free(config_home); - - // load global tags file for C autocompletion - symbols_global_tags_loaded(GEANY_FILETYPES_C); }
void styleset_c(ScintillaObject *sci) { - styleset_common(sci, 5); + const filetype_id ft_id = GEANY_FILETYPES_C; + + styleset_common(sci, 5, ft_id); if (style_sets[GEANY_FILETYPES_C].styling == NULL) styleset_c_init();
SSM(sci, SCI_SETWORDCHARS, 0, (sptr_t) style_sets[GEANY_FILETYPES_C].wordchars); @@ -759,15 +762,14 @@
g_key_file_free(config); g_key_file_free(config_home); - - // load global tags file for C autocompletion - symbols_global_tags_loaded(GEANY_FILETYPES_CPP); }
void styleset_cpp(ScintillaObject *sci) { - styleset_common(sci, 5); + const filetype_id ft_id = GEANY_FILETYPES_CPP; + + styleset_common(sci, 5, ft_id); if (style_sets[GEANY_FILETYPES_CPP].styling == NULL) styleset_cpp_init();
SSM(sci, SCI_SETWORDCHARS, 0, (sptr_t) style_sets[GEANY_FILETYPES_CPP].wordchars); @@ -826,9 +828,6 @@ &style_sets[GEANY_FILETYPES_PASCAL].wordchars); filetypes_get_config(config, config_home, GEANY_FILETYPES_PASCAL);
- // load global tags file for PASCAL autocompletion - symbols_global_tags_loaded(GEANY_FILETYPES_PASCAL); - g_key_file_free(config); g_key_file_free(config_home); } @@ -836,7 +835,9 @@
void styleset_pascal(ScintillaObject *sci) { - styleset_common(sci, 5); + const filetype_id ft_id = GEANY_FILETYPES_PASCAL; + + styleset_common(sci, 5, ft_id); if (style_sets[GEANY_FILETYPES_PASCAL].styling == NULL) styleset_pascal_init();
SSM (sci, SCI_SETWORDCHARS, 0, (sptr_t) style_sets[GEANY_FILETYPES_PASCAL].wordchars); @@ -893,7 +894,9 @@
void styleset_makefile(ScintillaObject *sci) { - styleset_common(sci, 5); + const filetype_id ft_id = GEANY_FILETYPES_MAKE; + + styleset_common(sci, 5, ft_id); if (style_sets[GEANY_FILETYPES_MAKE].styling == NULL) styleset_makefile_init();
SSM (sci, SCI_SETLEXER, SCLEX_MAKEFILE, 0); @@ -939,7 +942,9 @@
void styleset_diff(ScintillaObject *sci) { - styleset_common(sci, 5); + const filetype_id ft_id = GEANY_FILETYPES_DIFF; + + styleset_common(sci, 5, ft_id); if (style_sets[GEANY_FILETYPES_DIFF].styling == NULL) styleset_diff_init();
SSM (sci, SCI_SETLEXER, SCLEX_DIFF, 0); @@ -979,9 +984,6 @@ &style_sets[GEANY_FILETYPES_LATEX].wordchars); filetypes_get_config(config, config_home, GEANY_FILETYPES_LATEX);
- // load global tags file for LaTeX autocompletion - symbols_global_tags_loaded(GEANY_FILETYPES_LATEX); - g_key_file_free(config); g_key_file_free(config_home); } @@ -989,7 +991,9 @@
void styleset_latex(ScintillaObject *sci) { - styleset_common(sci, 5); + const filetype_id ft_id = GEANY_FILETYPES_LATEX; + + styleset_common(sci, 5, ft_id); if (style_sets[GEANY_FILETYPES_LATEX].styling == NULL) styleset_latex_init();
SSM (sci, SCI_SETLEXER, SCLEX_LATEX, 0); @@ -1020,9 +1024,6 @@ &style_sets[GEANY_FILETYPES_PHP].wordchars); filetypes_get_config(config, config_home, GEANY_FILETYPES_PHP);
- // load global tags file for PHP autocompletion - symbols_global_tags_loaded(GEANY_FILETYPES_PHP); - g_key_file_free(config); g_key_file_free(config_home); } @@ -1030,7 +1031,9 @@
void styleset_php(ScintillaObject *sci) { - styleset_common(sci, 7); + const filetype_id ft_id = GEANY_FILETYPES_PHP; + + styleset_common(sci, 7, ft_id); // PHP doesn't have its own styling, so check wordchars to see if init was run if (style_sets[GEANY_FILETYPES_PHP].wordchars == NULL) styleset_php_init();
@@ -1060,9 +1063,6 @@ &style_sets[GEANY_FILETYPES_HTML].wordchars); filetypes_get_config(config, config_home, GEANY_FILETYPES_HTML);
- // load global tags file for HTML entities autocompletion - symbols_global_tags_loaded(GEANY_FILETYPES_HTML); - g_key_file_free(config); g_key_file_free(config_home); } @@ -1070,7 +1070,9 @@
void styleset_html(ScintillaObject *sci) { - styleset_common(sci, 7); + const filetype_id ft_id = GEANY_FILETYPES_HTML; + + styleset_common(sci, 7, ft_id); // HTML doesn't have its own styling, so check wordchars to see if init was run if (style_sets[GEANY_FILETYPES_HTML].wordchars == NULL) styleset_html_init();
@@ -1427,7 +1429,9 @@
void styleset_java(ScintillaObject *sci) { - styleset_common(sci, 5); + const filetype_id ft_id = GEANY_FILETYPES_JAVA; + + styleset_common(sci, 5, ft_id); if (style_sets[GEANY_FILETYPES_JAVA].styling == NULL) styleset_java_init();
SSM (sci, SCI_SETLEXER, SCLEX_CPP, 0); @@ -1527,7 +1531,9 @@
void styleset_perl(ScintillaObject *sci) { - styleset_common(sci, 5); + const filetype_id ft_id = GEANY_FILETYPES_PERL; + + styleset_common(sci, 5, ft_id); if (style_sets[GEANY_FILETYPES_PERL].styling == NULL) styleset_perl_init();
SSM (sci, SCI_SETLEXER, SCLEX_PERL, 0); @@ -1611,7 +1617,9 @@
void styleset_python(ScintillaObject *sci) { - styleset_common(sci, 5); + const filetype_id ft_id = GEANY_FILETYPES_PYTHON; + + styleset_common(sci, 5, ft_id); if (style_sets[GEANY_FILETYPES_PYTHON].styling == NULL) styleset_python_init();
SSM (sci, SCI_SETLEXER, SCLEX_PYTHON, 0); @@ -1697,7 +1705,9 @@
void styleset_ruby(ScintillaObject *sci) { - styleset_common(sci, 5); + const filetype_id ft_id = GEANY_FILETYPES_RUBY; + + styleset_common(sci, 5, ft_id); if (style_sets[GEANY_FILETYPES_RUBY].styling == NULL) styleset_ruby_init();
SSM (sci, SCI_SETLEXER, SCLEX_RUBY, 0); @@ -1777,7 +1787,9 @@
void styleset_sh(ScintillaObject *sci) { - styleset_common(sci, 5); + const filetype_id ft_id = GEANY_FILETYPES_SH; + + styleset_common(sci, 5, ft_id); if (style_sets[GEANY_FILETYPES_SH].styling == NULL) styleset_sh_init();
SSM (sci, SCI_SETLEXER, SCLEX_BASH, 0); @@ -1806,8 +1818,10 @@
void styleset_xml(ScintillaObject *sci) { - styleset_common(sci, 7); + const filetype_id ft_id = SCLEX_XML;
+ styleset_common(sci, 7, ft_id); + SSM (sci, SCI_SETLEXER, SCLEX_XML, 0);
// use the same colouring for HTML; XML and so on @@ -1926,7 +1940,9 @@
void styleset_docbook(ScintillaObject *sci) { - styleset_common(sci, 7); + const filetype_id ft_id = GEANY_FILETYPES_DOCBOOK; + + styleset_common(sci, 7, ft_id); if (style_sets[GEANY_FILETYPES_DOCBOOK].styling == NULL) styleset_docbook_init();
SSM (sci, SCI_SETLEXER, SCLEX_XML, 0); @@ -1979,6 +1995,8 @@
void styleset_none(ScintillaObject *sci) { + const filetype_id ft_id = GEANY_FILETYPES_ALL; + SSM(sci, SCI_SETLEXER, SCLEX_NULL, 0);
if (style_sets[GEANY_FILETYPES_ALL].styling == NULL) @@ -1986,7 +2004,7 @@
set_sci_style(sci, STYLE_DEFAULT, GEANY_FILETYPES_ALL, GCS_DEFAULT);
- styleset_common(sci, 5); + styleset_common(sci, 5, ft_id);
SSM(sci, SCI_SETWORDCHARS, 0, (sptr_t) common_style_set.wordchars); } @@ -2057,7 +2075,9 @@
void styleset_css(ScintillaObject *sci) { - styleset_common(sci, 5); + const filetype_id ft_id = GEANY_FILETYPES_CSS; + + styleset_common(sci, 5, ft_id); if (style_sets[GEANY_FILETYPES_CSS].styling == NULL) styleset_css_init();
SSM(sci, SCI_SETWORDCHARS, 0, (sptr_t) style_sets[GEANY_FILETYPES_CSS].wordchars); @@ -2117,7 +2137,9 @@
void styleset_conf(ScintillaObject *sci) { - styleset_common(sci, 5); + const filetype_id ft_id = GEANY_FILETYPES_CONF; + + styleset_common(sci, 5, ft_id); if (style_sets[GEANY_FILETYPES_CONF].styling == NULL) styleset_conf_init();
SSM (sci, SCI_SETLEXER, SCLEX_PROPERTIES, 0); @@ -2178,7 +2200,9 @@
void styleset_asm(ScintillaObject *sci) { - styleset_common(sci, 5); + const filetype_id ft_id = GEANY_FILETYPES_ASM; + + styleset_common(sci, 5, ft_id); if (style_sets[GEANY_FILETYPES_ASM].styling == NULL) styleset_asm_init();
SSM(sci, SCI_SETWORDCHARS, 0, (sptr_t) style_sets[GEANY_FILETYPES_ASM].wordchars); @@ -2252,7 +2276,9 @@
void styleset_fortran(ScintillaObject *sci) { - styleset_common(sci, 5); + const filetype_id ft_id = GEANY_FILETYPES_FORTRAN; + + styleset_common(sci, 5, ft_id); if (style_sets[GEANY_FILETYPES_FORTRAN].styling == NULL) styleset_fortran_init();
SSM(sci, SCI_SETWORDCHARS, 0, (sptr_t) style_sets[GEANY_FILETYPES_FORTRAN].wordchars); @@ -2350,7 +2376,9 @@
void styleset_sql(ScintillaObject *sci) { - styleset_common(sci, 5); + const filetype_id ft_id = GEANY_FILETYPES_SQL; + + styleset_common(sci, 5, ft_id); if (style_sets[GEANY_FILETYPES_SQL].styling == NULL) styleset_sql_init();
SSM(sci, SCI_SETWORDCHARS, 0, (sptr_t) style_sets[GEANY_FILETYPES_SQL].wordchars); @@ -2421,7 +2449,9 @@
void styleset_haskell(ScintillaObject *sci) { - styleset_common(sci, 5); + const filetype_id ft_id = GEANY_FILETYPES_HASKELL; + + styleset_common(sci, 5, ft_id); if (style_sets[GEANY_FILETYPES_HASKELL].styling == NULL) styleset_haskell_init();
SSM(sci, SCI_SETWORDCHARS, 0, (sptr_t) style_sets[GEANY_FILETYPES_HASKELL].wordchars); @@ -2496,7 +2526,9 @@
void styleset_caml(ScintillaObject *sci) { - styleset_common(sci, 5); + const filetype_id ft_id = GEANY_FILETYPES_CAML; + + styleset_common(sci, 5, ft_id); if (style_sets[GEANY_FILETYPES_CAML].styling == NULL) styleset_caml_init();
SSM(sci, SCI_SETWORDCHARS, 0, (sptr_t) style_sets[GEANY_FILETYPES_CAML].wordchars); @@ -2566,7 +2598,9 @@
void styleset_oms(ScintillaObject *sci) { - styleset_common(sci, 5); + const filetype_id ft_id = GEANY_FILETYPES_OMS; + + styleset_common(sci, 5, ft_id); if (style_sets[GEANY_FILETYPES_OMS].styling == NULL) styleset_oms_init();
SSM (sci, SCI_SETLEXER, SCLEX_OMS, 0); @@ -2637,7 +2671,9 @@
void styleset_tcl(ScintillaObject *sci) { - styleset_common(sci, 5); + const filetype_id ft_id = GEANY_FILETYPES_TCL; + + styleset_common(sci, 5, ft_id); if (style_sets[GEANY_FILETYPES_TCL].styling == NULL) styleset_tcl_init();
SSM(sci, SCI_SETWORDCHARS, 0, (sptr_t) style_sets[GEANY_FILETYPES_TCL].wordchars); @@ -2727,7 +2763,9 @@
void styleset_d(ScintillaObject *sci) { - styleset_common(sci, 5); + const filetype_id ft_id = GEANY_FILETYPES_D; + + styleset_common(sci, 5, ft_id); if (style_sets[GEANY_FILETYPES_D].styling == NULL) styleset_d_init();
SSM(sci, SCI_SETWORDCHARS, 0, (sptr_t) style_sets[GEANY_FILETYPES_D].wordchars); @@ -2789,7 +2827,9 @@
void styleset_ferite(ScintillaObject *sci) { - styleset_common(sci, 5); + const filetype_id ft_id = GEANY_FILETYPES_FERITE; + + styleset_common(sci, 5, ft_id); if (style_sets[GEANY_FILETYPES_FERITE].styling == NULL) styleset_ferite_init();
SSM(sci, SCI_SETWORDCHARS, 0, (sptr_t) style_sets[GEANY_FILETYPES_FERITE].wordchars); @@ -2874,7 +2914,9 @@
void styleset_vhdl(ScintillaObject *sci) { - styleset_common(sci, 5); + const filetype_id ft_id = GEANY_FILETYPES_VHDL; + + styleset_common(sci, 5, ft_id); if (style_sets[GEANY_FILETYPES_VHDL].styling == NULL) styleset_vhdl_init();
SSM(sci, SCI_SETWORDCHARS, 0, (sptr_t) style_sets[GEANY_FILETYPES_VHDL].wordchars); @@ -2939,7 +2981,9 @@
void styleset_js(ScintillaObject *sci) { - styleset_common(sci, 5); + const filetype_id ft_id = GEANY_FILETYPES_JS; + + styleset_common(sci, 5, ft_id); if (style_sets[GEANY_FILETYPES_JS].styling == NULL) styleset_js_init();
SSM(sci, SCI_SETWORDCHARS, 0, (sptr_t) style_sets[GEANY_FILETYPES_JS].wordchars); @@ -3034,7 +3078,9 @@
void styleset_lua(ScintillaObject *sci) { - styleset_common(sci, 5); + const filetype_id ft_id = GEANY_FILETYPES_LUA; + + styleset_common(sci, 5, ft_id); if (style_sets[GEANY_FILETYPES_LUA].styling == NULL) styleset_lua_init();
SSM(sci, SCI_SETWORDCHARS, 0, (sptr_t) style_sets[GEANY_FILETYPES_LUA].wordchars);
Modified: trunk/src/highlighting.h =================================================================== --- trunk/src/highlighting.h 2007-05-11 11:42:00 UTC (rev 1520) +++ trunk/src/highlighting.h 2007-05-11 11:58:56 UTC (rev 1521) @@ -35,8 +35,6 @@
void styleset_free_styles(void);
-void styleset_common(ScintillaObject *sci, gint style_bits); - void styleset_c(ScintillaObject *sci);
void styleset_cpp(ScintillaObject *sci);
Modified: trunk/src/symbols.c =================================================================== --- trunk/src/symbols.c 2007-05-11 11:42:00 UTC (rev 1520) +++ trunk/src/symbols.c 2007-05-11 11:58:56 UTC (rev 1521) @@ -76,8 +76,11 @@ {FALSE, "latex.tags"} };
+static gchar *user_tags_dir;
+ static void html_tags_loaded(); +static void load_user_tags(filetype_id ft_id);
// Ensure that the global tags file for the file_type_idx filetype is loaded. @@ -88,6 +91,8 @@
if (app->ignore_global_tags) return;
+ load_user_tags(file_type_idx); + switch (file_type_idx) { case GEANY_FILETYPES_PHP: @@ -824,3 +829,83 @@ } gtk_widget_destroy(dialog); } + + +/* Fills a hash table with filetype keys that hold a linked list of filenames. */ +static GHashTable *get_tagfile_hash(const GSList *file_list) +{ + const GSList *node; + GHashTable *hash = g_hash_table_new(NULL, NULL); + + for (node = file_list; node != NULL; node = g_slist_next(node)) + { + GList *fnames; + gchar *fname = node->data; + gchar *utf8_fname = utils_get_utf8_from_locale(fname); + filetype *ft = detect_global_tags_filetype(utf8_fname); + + g_free(utf8_fname); + + if (FILETYPE_ID(ft) < GEANY_FILETYPES_ALL) + { + fnames = g_hash_table_lookup(hash, ft); // may be NULL + fnames = g_list_append(fnames, fname); + g_hash_table_insert(hash, ft, fnames); + } + else + geany_debug("Unknown filetype for file '%s'.", fname); + } + return hash; +} + + +static GHashTable *init_user_tags() +{ + GSList *file_list; + GHashTable *lang_hash; + + user_tags_dir = g_strconcat(app->configdir, G_DIR_SEPARATOR_S, "tags", NULL); + file_list = utils_get_file_list(user_tags_dir, NULL, NULL); + lang_hash = get_tagfile_hash(file_list); + + // don't need to delete list contents because they are now used for hash contents + g_slist_free(file_list); + return lang_hash; +} + + +static void load_user_tags(filetype_id ft_id) +{ + static guchar tags_loaded[GEANY_FILETYPES_ALL] = {0}; + static GHashTable *lang_hash = NULL; + GList *fnames; + const GList *node; + const filetype *ft = filetypes[ft_id]; + + g_return_if_fail(ft_id < GEANY_FILETYPES_ALL); + + if (tags_loaded[ft_id]) + return; + tags_loaded[ft_id] = TRUE; // prevent reloading + + if (lang_hash == NULL) + lang_hash = init_user_tags(); + + fnames = g_hash_table_lookup(lang_hash, ft); + + for (node = fnames; node != NULL; node = g_list_next(node)) + { + const gint tm_lang = ft->lang; + gchar *fname; + + fname = g_strconcat(user_tags_dir, G_DIR_SEPARATOR_S, node->data, NULL); + tm_workspace_load_global_tags(fname, tm_lang); + geany_debug("Loaded %s (%s).", fname, ft->name); + g_free(fname); + } + g_list_foreach(fnames, (GFunc) g_free, NULL); + g_list_free(fnames); + g_hash_table_remove(lang_hash, (gpointer) ft); +} + +
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.