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).
This commit is contained in:
Jiří Techet 2016-02-13 01:43:35 +01:00
parent 77f6e98de8
commit 5030f7f3da
5 changed files with 14 additions and 27 deletions

View File

@ -202,7 +202,7 @@ static GeanyFiletype *filetype_new(void)
GeanyFiletype *ft = g_new0(GeanyFiletype, 1); GeanyFiletype *ft = g_new0(GeanyFiletype, 1);
ft->group = GEANY_FILETYPE_GROUP_NONE; 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 */ /* pattern must not be null */
ft->pattern = g_new0(gchar*, 1); ft->pattern = g_new0(gchar*, 1);
ft->indent_width = -1; ft->indent_width = -1;

View File

@ -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 /* the check for tag_lang == lang is necessary to avoid wrong type colouring of
* e.g. PHP classes in C++ files * e.g. PHP classes in C++ files
* lang = -2 disables the check */ * lang = TM_PARSER_NONE disables the check */
if (tag->name && (tag_lang == lang || lang == -2 || if (tag->name && (tag_lang == lang || lang == TM_PARSER_NONE ||
(lang == TM_PARSER_CPP && tag_lang == TM_PARSER_C))) (lang == TM_PARSER_CPP && tag_lang == TM_PARSER_C)))
{ {
if (j != 0) if (j != 0)

View File

@ -10,18 +10,11 @@
#ifndef TM_PARSER_H #ifndef TM_PARSER_H
#define 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 */ /* keep in sync with ctags/parsers.h */
typedef enum typedef enum
{ {
TM_PARSER_NONE = LANG_IGNORE, TM_PARSER_NONE = -2, /* keep in sync with ctags LANG_IGNORE */
TM_PARSER_AUTO = LANG_AUTO,
TM_PARSER_C = 0, TM_PARSER_C = 0,
TM_PARSER_CPP, TM_PARSER_CPP,
TM_PARSER_JAVA, TM_PARSER_JAVA,

View File

@ -34,6 +34,7 @@
#define LIBCTAGS_DEFINED #define LIBCTAGS_DEFINED
#include "tm_source_file.h" #include "tm_source_file.h"
#include "tm_tag.h" #include "tm_tag.h"
#include "tm_parser.h"
typedef struct typedef struct
{ {
@ -193,7 +194,7 @@ static gboolean tm_source_file_init(TMSourceFile *source_file, const char *file_
} }
if (name == NULL) if (name == NULL)
source_file->lang = LANG_AUTO; source_file->lang = TM_PARSER_NONE;
else else
source_file->lang = getNamedLanguage(name); 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 /** Initializes a TMSourceFile structure and returns a pointer to it. The
* TMSourceFile has to be added to TMWorkspace to start its parsing. * TMSourceFile has to be added to TMWorkspace to start its parsing.
* @param file_name The file name. * @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. * @return The created unparsed TMSourceFile object.
* */ * */
GEANY_API_SYMBOL GEANY_API_SYMBOL
@ -297,7 +298,7 @@ gboolean tm_source_file_parse(TMSourceFile *source_file, guchar* text_buf, gsize
return FALSE; return FALSE;
} }
if (source_file->lang == LANG_IGNORE) if (source_file->lang == TM_PARSER_NONE)
{ {
tm_tags_array_free(source_file->tags_array, FALSE); tm_tags_array_free(source_file->tags_array, FALSE);
return 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; TagEntrySetArglistFunction = tm_source_file_set_tag_arglist;
} }
current_source_file = source_file; current_source_file = source_file;
if (LANG_AUTO == source_file->lang) if (! LanguageTable [source_file->lang]->enabled)
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)
{ {
#ifdef TM_DEBUG #ifdef TM_DEBUG
g_warning("ignoring %s (language disabled)\n", file_name); 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. /* Gets the language index for \a name.
@param name The language 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) gint tm_source_file_get_named_lang(const gchar *name)
{ {

View File

@ -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. 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 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 other tag arrays pointing to these tags should be rebuilt as well. All sorting
information is also lost. The language parameter is automatically detected information is also lost.
the first time the file is parsed if it is set to LANG_AUTO.
@param source_file The source file to update with a buffer. @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 @param text_buf A text buffer. The user should take care of allocate and free it after
the use here. 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) 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; return TRUE;
/* Accept CPP tags for C lang and vice versa */ /* Accept CPP tags for C lang and vice versa */
else if (lang == TM_PARSER_C && other == TM_PARSER_CPP) else if (lang == TM_PARSER_C && other == TM_PARSER_CPP)