Skip to content

Commit

Permalink
Cleanup NONE/AUTO filetype definitions
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
techee committed Feb 26, 2016
1 parent 77f6e98 commit 5030f7f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/filetypes.c
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/symbols.c
Expand Up @@ -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)
Expand Down
9 changes: 1 addition & 8 deletions tagmanager/src/tm_parser.h
Expand Up @@ -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,
Expand Down
19 changes: 6 additions & 13 deletions tagmanager/src/tm_source_file.c
Expand Up @@ -34,6 +34,7 @@
#define LIBCTAGS_DEFINED
#include "tm_source_file.h"
#include "tm_tag.h"
#include "tm_parser.h"

typedef struct
{
Expand Down Expand Up @@ -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);

Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down
7 changes: 4 additions & 3 deletions tagmanager/src/tm_workspace.c
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5030f7f

Please sign in to comment.