Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: Jiří Techet techet@gmail.com Date: Fri, 26 Feb 2016 00:09:59 UTC Commit: 5030f7f3da945c0caeb42e090991ad362d30a743 https://github.com/geany/geany/commit/5030f7f3da945c0caeb42e090991ad362d30a7...
Log Message: ----------- Cleanup NONE/AUTO filetype definitions
At the moment the Geany code uses arbitrary combination of the following synonyms
TM_PARSER_NONE / LANG_IGNORE / -2 TM_PARSER_AUTO / LANG_AUTO / -1
Especially using just the numbers makes things very confusing.
In the Geany code this patch replaces all occurrences of -2 and LANG_IGNORE with TM_PARSER_NONE. It also removes LANG_IGNORE from the header which isn't needed any more.
In addition, TM_PARSER_AUTO/LANG_AUTO shouldn't be used at all. We want filetype detection based on Geany's definitions and not based on the hard-coded ctags definitions. Remove it completely.
Finally, as it's clearer now what the constants mean, the patch fixes the implementation of langs_compatible() (tag or file can never be of type AUTO but we should rather check for NONE filetypes which we should consider incompatible between each other).
Modified Paths: -------------- src/filetypes.c src/symbols.c tagmanager/src/tm_parser.h tagmanager/src/tm_source_file.c tagmanager/src/tm_workspace.c
Modified: src/filetypes.c 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -202,7 +202,7 @@ static GeanyFiletype *filetype_new(void) GeanyFiletype *ft = g_new0(GeanyFiletype, 1);
ft->group = GEANY_FILETYPE_GROUP_NONE; - ft->lang = -2; /* assume no tagmanager parser */ + ft->lang = TM_PARSER_NONE; /* assume no tagmanager parser */ /* pattern must not be null */ ft->pattern = g_new0(gchar*, 1); ft->indent_width = -1;
Modified: src/symbols.c 4 lines changed, 2 insertions(+), 2 deletions(-) =================================================================== @@ -295,8 +295,8 @@ GString *symbols_find_typenames_as_string(gint lang, gboolean global)
/* the check for tag_lang == lang is necessary to avoid wrong type colouring of * e.g. PHP classes in C++ files - * lang = -2 disables the check */ - if (tag->name && (tag_lang == lang || lang == -2 || + * lang = TM_PARSER_NONE disables the check */ + if (tag->name && (tag_lang == lang || lang == TM_PARSER_NONE || (lang == TM_PARSER_CPP && tag_lang == TM_PARSER_C))) { if (j != 0)
Modified: tagmanager/src/tm_parser.h 9 lines changed, 1 insertions(+), 8 deletions(-) =================================================================== @@ -10,18 +10,11 @@ #ifndef TM_PARSER_H #define TM_PARSER_H
-#ifndef LIBCTAGS_DEFINED -/* from ctags/parse.h */ -# define LANG_AUTO (-1) -# define LANG_IGNORE (-2) -#endif -
/* keep in sync with ctags/parsers.h */ typedef enum { - TM_PARSER_NONE = LANG_IGNORE, - TM_PARSER_AUTO = LANG_AUTO, + TM_PARSER_NONE = -2, /* keep in sync with ctags LANG_IGNORE */ TM_PARSER_C = 0, TM_PARSER_CPP, TM_PARSER_JAVA,
Modified: tagmanager/src/tm_source_file.c 19 lines changed, 6 insertions(+), 13 deletions(-) =================================================================== @@ -34,6 +34,7 @@ #define LIBCTAGS_DEFINED #include "tm_source_file.h" #include "tm_tag.h" +#include "tm_parser.h"
typedef struct { @@ -193,7 +194,7 @@ static gboolean tm_source_file_init(TMSourceFile *source_file, const char *file_ }
if (name == NULL) - source_file->lang = LANG_AUTO; + source_file->lang = TM_PARSER_NONE; else source_file->lang = getNamedLanguage(name);
@@ -203,7 +204,7 @@ static gboolean tm_source_file_init(TMSourceFile *source_file, const char *file_ /** Initializes a TMSourceFile structure and returns a pointer to it. The * TMSourceFile has to be added to TMWorkspace to start its parsing. * @param file_name The file name. - * @param name Name of the used programming language, NULL for autodetection. + * @param name Name of the used programming language, NULL to disable parsing. * @return The created unparsed TMSourceFile object. * */ GEANY_API_SYMBOL @@ -297,7 +298,7 @@ gboolean tm_source_file_parse(TMSourceFile *source_file, guchar* text_buf, gsize return FALSE; } - if (source_file->lang == LANG_IGNORE) + if (source_file->lang == TM_PARSER_NONE) { tm_tags_array_free(source_file->tags_array, FALSE); return FALSE; @@ -342,15 +343,7 @@ gboolean tm_source_file_parse(TMSourceFile *source_file, guchar* text_buf, gsize TagEntrySetArglistFunction = tm_source_file_set_tag_arglist; } current_source_file = source_file; - if (LANG_AUTO == source_file->lang) - source_file->lang = getFileLanguage (file_name); - if (source_file->lang == LANG_IGNORE) - { -#ifdef TM_DEBUG - g_warning("ignoring %s (unknown language)\n", file_name); -#endif - } - else if (! LanguageTable [source_file->lang]->enabled) + if (! LanguageTable [source_file->lang]->enabled) { #ifdef TM_DEBUG g_warning("ignoring %s (language disabled)\n", file_name); @@ -422,7 +415,7 @@ const gchar *tm_source_file_get_lang_name(gint lang)
/* Gets the language index for \a name. @param name The language name. - @return The language index, or -2. + @return The language index, or TM_PARSER_NONE. */ gint tm_source_file_get_named_lang(const gchar *name) {
Modified: tagmanager/src/tm_workspace.c 7 lines changed, 4 insertions(+), 3 deletions(-) =================================================================== @@ -193,8 +193,7 @@ void tm_workspace_add_source_file_noupdate(TMSourceFile *source_file) you're editing. It's useful for a "real-time" updating of the tags. The tags array and the tags themselves are destroyed and re-created, hence any other tag arrays pointing to these tags should be rebuilt as well. All sorting - information is also lost. The language parameter is automatically detected - the first time the file is parsed if it is set to LANG_AUTO. + information is also lost. @param source_file The source file to update with a buffer. @param text_buf A text buffer. The user should take care of allocate and free it after the use here. @@ -688,7 +687,9 @@ gboolean tm_workspace_create_global_tags(const char *pre_process, const char **i
static gboolean langs_compatible(langType lang, langType other) { - if (lang == other || lang == -1 || other == -1) + if (lang == TM_PARSER_NONE || other == TM_PARSER_NONE) + return FALSE; + if (lang == other) return TRUE; /* Accept CPP tags for C lang and vice versa */ else if (lang == TM_PARSER_C && other == TM_PARSER_CPP)
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).