Merge pull request #1014 from b4n/streamline-builtin-tags

Streamline builtin tags
This commit is contained in:
Colomban Wendling 2016-05-15 15:58:05 +02:00
commit 9681888806
11 changed files with 14 additions and 163 deletions

View File

@ -73,11 +73,11 @@ filetypes = \
filedefs/filetypes.zephir
tagfiles = \
tags/c99.tags \
tags/php.tags \
tags/python.tags \
tags/pascal.tags \
tags/html_entities.tags
tags/std99.c.tags \
tags/std.php.tags \
tags/std.py.tags \
tags/std.pas.tags \
tags/entities.html.tags
template_files = \
templates/files/file.html \

View File

@ -1,5 +1,4 @@
# each of the following lines represent a html entity
# used in HTML and PHP files when typing &...
#format=tagmanager
Á
á
Â

View File

@ -2076,56 +2076,16 @@ gchar *editor_get_calltip_text(GeanyEditor *editor, const TMTag *tag)
}
/* HTML entities auto completion from html_entities.tags text file */
static gboolean
autocomplete_html(ScintillaObject *sci, const gchar *root, gsize rootlen)
{
guint i;
gboolean found = FALSE;
GString *words;
const gchar **entities = symbols_get_html_entities();
if (*root != '&' || entities == NULL)
return FALSE;
words = g_string_sized_new(500);
for (i = 0; ; i++)
{
if (entities[i] == NULL)
break;
else if (entities[i][0] == '#')
continue;
if (! strncmp(entities[i], root, rootlen))
{
if (words->len)
g_string_append_c(words, '\n');
g_string_append(words, entities[i]);
found = TRUE;
}
}
if (found)
show_autocomplete(sci, rootlen, words);
g_string_free(words, TRUE);
return found;
}
/* Current document & global tags autocompletion */
static gboolean
autocomplete_tags(GeanyEditor *editor, const gchar *root, gsize rootlen)
autocomplete_tags(GeanyEditor *editor, GeanyFiletype *ft, const gchar *root, gsize rootlen)
{
GPtrArray *tags;
GeanyDocument *doc;
gboolean found;
g_return_val_if_fail(editor, FALSE);
doc = editor->document;
tags = tm_workspace_find_prefix(root, doc->file_type->lang, editor_prefs.autocompletion_max_entries);
tags = tm_workspace_find_prefix(root, ft->lang, editor_prefs.autocompletion_max_entries);
found = tags->len > 0;
if (found)
show_tags_list(editor, tags, rootlen);
@ -2164,7 +2124,7 @@ static gboolean autocomplete_check_html(GeanyEditor *editor, gint style, gint po
tmp = strchr(root, '&');
if (tmp != NULL)
{
return autocomplete_html(editor->sci, tmp, strlen(tmp));
return autocomplete_tags(editor, filetypes_index(GEANY_FILETYPES_HTML), tmp, strlen(tmp));
}
}
return FALSE;
@ -2338,7 +2298,7 @@ gboolean editor_start_auto_complete(GeanyEditor *editor, gint pos, gboolean forc
{
/* complete tags, except if forcing when completion is already visible */
if (!(force && SSM(sci, SCI_AUTOCACTIVE, 0, 0)))
ret = autocomplete_tags(editor, root, rootlen);
ret = autocomplete_tags(editor, editor->document->file_type, root, rootlen);
/* If forcing and there's nothing else to show, complete from words in document */
if (!ret && (force || editor_prefs.autocomplete_doc_words))

View File

@ -64,36 +64,6 @@
#include <stdlib.h>
static gchar **html_entities = NULL;
typedef struct
{
gboolean tags_loaded;
const gchar *tag_file;
} TagFileInfo;
/* Check before adding any more tags files, usually they should be downloaded separately. */
enum /* Geany tag files */
{
GTF_C,
GTF_PASCAL,
GTF_PHP,
GTF_HTML_ENTITIES,
GTF_LATEX,
GTF_PYTHON,
GTF_MAX
};
static TagFileInfo tag_file_info[GTF_MAX] =
{
{FALSE, "c99.tags"},
{FALSE, "pascal.tags"},
{FALSE, "php.tags"},
{FALSE, "html_entities.tags"},
{FALSE, "latex.tags"},
{FALSE, "python.tags"}
};
static GPtrArray *top_level_iter_names = NULL;
enum
@ -138,7 +108,6 @@ static struct
}
symbol_menu;
static void html_tags_loaded(void);
static void load_user_tags(GeanyFiletypeID ft_id);
/* get the tags_ignore list, exported by tagmanager's options.c */
@ -201,9 +170,6 @@ static gboolean symbols_load_global_tags(const gchar *tags_file, GeanyFiletype *
* This provides autocompletion, calltips, etc. */
void symbols_global_tags_loaded(guint file_type_idx)
{
TagFileInfo *tfi;
gint tag_type;
/* load ignore list for C/C++ parser */
if ((file_type_idx == GEANY_FILETYPES_C || file_type_idx == GEANY_FILETYPES_CPP) &&
c_tags_ignore == NULL)
@ -219,55 +185,14 @@ void symbols_global_tags_loaded(guint file_type_idx)
load_user_tags(file_type_idx);
switch (file_type_idx)
{
case GEANY_FILETYPES_PHP:
case GEANY_FILETYPES_HTML:
html_tags_loaded();
}
switch (file_type_idx)
{
case GEANY_FILETYPES_CPP:
symbols_global_tags_loaded(GEANY_FILETYPES_C); /* load C global tags */
/* no C++ tagfile yet */
return;
case GEANY_FILETYPES_C: tag_type = GTF_C; break;
case GEANY_FILETYPES_PASCAL:tag_type = GTF_PASCAL; break;
case GEANY_FILETYPES_PHP: tag_type = GTF_PHP; break;
case GEANY_FILETYPES_LATEX: tag_type = GTF_LATEX; break;
case GEANY_FILETYPES_PYTHON:tag_type = GTF_PYTHON; break;
default:
return;
}
tfi = &tag_file_info[tag_type];
if (! tfi->tags_loaded)
{
gchar *fname = g_build_filename(app->datadir, GEANY_TAGS_SUBDIR, tfi->tag_file, NULL);
symbols_load_global_tags(fname, filetypes[file_type_idx]);
tfi->tags_loaded = TRUE;
g_free(fname);
}
}
/* HTML tagfile is just a list of entities for autocompletion (e.g. '&amp;') */
static void html_tags_loaded(void)
{
TagFileInfo *tfi;
if (cl_options.ignore_global_tags)
return;
tfi = &tag_file_info[GTF_HTML_ENTITIES];
if (! tfi->tags_loaded)
{
gchar *file = g_build_filename(app->datadir, GEANY_TAGS_SUBDIR, tfi->tag_file, NULL);
html_entities = utils_read_file_in_array(file);
tfi->tags_loaded = TRUE;
g_free(file);
break;
case GEANY_FILETYPES_PHP:
symbols_global_tags_loaded(GEANY_FILETYPES_HTML); /* load HTML global tags */
break;
}
}
@ -326,15 +251,6 @@ const gchar *symbols_get_context_separator(gint ft_id)
}
const gchar **symbols_get_html_entities(void)
{
if (html_entities == NULL)
html_tags_loaded(); /* if not yet created, force creation of the array but shouldn't occur */
return (const gchar **) html_entities;
}
/* sort by name, then line */
static gint compare_symbol(const TMTag *tag_a, const TMTag *tag_b)
{
@ -2634,7 +2550,6 @@ void symbols_finalize(void)
{
guint i;
g_strfreev(html_entities);
g_strfreev(c_tags_ignore);
for (i = 0; i < G_N_ELEMENTS(symbols_icons); i++)

View File

@ -52,8 +52,6 @@ void symbols_global_tags_loaded(guint file_type_idx);
GString *symbols_find_typenames_as_string(TMParserType lang, gboolean global);
const gchar **symbols_get_html_entities(void);
gboolean symbols_recreate_tag_list(GeanyDocument *doc, gint sort_mode);
gint symbols_generate_global_tags(gint argc, gchar **argv, gboolean want_preprocess);

View File

@ -1060,25 +1060,6 @@ GIOChannel *utils_set_up_io_channel(
}
gchar **utils_read_file_in_array(const gchar *filename)
{
gchar **result = NULL;
gchar *data;
g_return_val_if_fail(filename != NULL, NULL);
g_file_get_contents(filename, &data, NULL, NULL);
if (data != NULL)
{
result = g_strsplit_set(data, "\r\n", -1);
g_free(data);
}
return result;
}
/* Contributed by Stefan Oltmanns, thanks.
* Replaces \\, \r, \n, \t and \uXXX by their real counterparts.
* keep_backslash is used for regex strings to leave '\\' and '\?' in place */

View File

@ -289,8 +289,6 @@ gchar *utils_get_current_time_string(void);
GIOChannel *utils_set_up_io_channel(gint fd, GIOCondition cond, gboolean nblock,
GIOFunc func, gpointer data);
gchar **utils_read_file_in_array(const gchar *filename);
gboolean utils_str_replace_escape(gchar *string, gboolean keep_backslash);
gboolean utils_wrap_string(gchar *string, gint wrapstart);