abudden  committed 3c47d78

Added (default) option to skip keywords reserved for a given language.

Only a subset of the programming languages have their reserved words defined
at the moment. I've added the lists of reserved keywords for C++, Python, Java
and C#. Others can be added fairly easily, but require a bit of web-trawling
to get hold of the lists.

  • Participants
  • Parent commits f660461

Comments (0)

Files changed (8)

File doc/TagHighlight.txt

 		Option Type: List
 		Default: [] (no patterns)
+	SkipReservedKeywords                 *TagHL-SkipReservedKeywords*
+		This option stops TagHighlight from overriding keywords that are
+		reserved words in the programming language in which they are found.
+		There may be situations in which (for example) ctags includes "bool"
+		in its list of tags for some C++ source code and TagHighlight will
+		then overwrite the default highlighting of "bool" with whatever ctags
+		says that tag type is.  By default, any keywords that match those in
+		the language definition file will be ignored by TagHighlight.  If you
+		want TagHighlight to take over the highlighting of keywords (assuming
+		there is a custom definition somewhere that ctags can find it), set
+		this option to False or 0 and the reserved keywords will be included.
+		If you find that reserved keywords aren't skipped with your chosen
+		programming language, it may be that TagHighlight doesn't know about
+		the reserved keywords for your language.  Please feel free to add them
+		to the language definition file and send me a patch (see the bit about
+		ReservedKeywords in |TagHighlight-adding|) or send me a list of the
+		keywords and I'll do this myself.
+		Note that the same effect can be achieved somewhat more laboriously
+		using |TagHL-SkipPatterns| (useful if you only want to skip a subset
+		of the reserved keywords).
+		Option Type: Boolean
+		Default: True (don't include reserved keywords)
 	SkipVimKeywords                      *TagHL-SkipVimKeywords*
 		As well as being unable to use "syn keyword" for tag names that
 		contain non-keyword characters, Vim also cannot use "syn keyword" to
 	5.  Optionally, add other fields as required:
+		ReservedKeywords - This is a list of predefined keywords for a given
+		                   language - those keywords that are typically
+		                   designated 'reserved words' in the language
+		                   documentation.  This is used when a user specifies
+		                   the |TagHL-SkipReservedKeywords| option.  This
+		                   option can either be specified as a list of
+		                   comma-separated keywords on a single line, as a
+		                   list of keywords one per line or (more
+		                   conveniently) as a list of keywords with several
+		                   per-line separated by spaces:
+                            # Example 1:
+							ReservedKeywords:bool,asm,break,case
+							# Example 2:
+							ReservedKeywords:
+								bool
+								asm
+								break
+								case
+							# Example 3:
+							ReservedKeywords:
+								bool asm break
+								case
+						   See the examples in the existing language
+						   definitions for details.
 		SkipList -  Any specific ctags "kinds" (single characters referring
 					to types of tags) that you want to omit from the types
 					file.  For example, for C code, function prototypes are
 	Suggestions for Improvement and Testing:
+		Alan Warren - Suggestions for Improvement
 		Alexey Radkov - Suggestions for Improvement
 		Hong Xu - Suggestions for Improvement
 		Marcus Martin - Testing & Suggestions
 							 option implementation.  Added option to only
 							 generate the tags file if one is not present or
 							 to only generate types file if one IS present
-							 (thanks to Ali Hamdi for the suggestion).
+							 (thanks to Ali Hamdi for the suggestion).  Added
+							 CtagsExtraArguments and clarified what is meant
+							 by CtagsArguments (thanks to Alan Warren for the
+							 suggestion).  Added support for skipping reserved
+							 keywords for given languages when generating
+							 types files.  Initially the reserved keywords
+							 have been recorded for C++, Python, Java and C#.
+							 Thanks to Alexey Radkov and Alan Warren for the
+							 suggestions.
 2.1.5: 20th February 2012  : Added support for Scala (thanks to Lee Gauthier).

File plugin/TagHighlight/data/languages/c.txt

+# Note that these keywords are for C++ - TagHighlight does not
+# distinguish between C and C++ so uses the (longer) C++ list here.
+# Taken from
+	alignas alignof and and_eq asm auto bitand bitor bool break
+	case catch char char16_t char32_t class compl const constexpr
+	const_cast continue decltype default delete do double dynamic_cast
+	else enum explicit export extern false float for friend goto if
+	inline int long mutable namespace new noexcept not not_eq nullptr
+	operator or or_eq private protected public register reinterpret_cast
+	return short signed sizeof static static_assert static_cast
+	struct switch template this thread_local throw true try typedef
+	typeid typename union unsigned using virtual void volatile wchar_t
+	while xor xor_eq
 # vim: ff=unix:noet

File plugin/TagHighlight/data/languages/csharp.txt

+# From:
+	abstract event new struct as explicit null switch base
+	extern object this bool false operator throw break finally
+	out true byte fixed override try case float params typeof
+	catch for private uint char foreach protected ulong checked
+	goto public unchecked class if readonly unsafe const implicit
+	ref ushort continue in return using decimal int sbyte virtual
+	default interface sealed volatile delegate internal short void
+	do is sizeof while double lock stackalloc else long static
+	enum namespace string
 # vim: ff=unix:noet

File plugin/TagHighlight/data/languages/java.txt

+# From:
+	abstract continue for new switch assert default goto package
+	synchronized boolean do if private this break double
+	implements protected throw byte else import public throws
+	case enum instanceof return transient catch extends int short
+	try char final interface static void class finally long
+	strictfp volatile const float native super while
 # vim: ff=unix:noet

File plugin/TagHighlight/data/languages/python.txt

+# Keywords taken from:
+	and del from not while as elif global or with assert else
+	if pass yield break except import print class exec in raise
+	continue finally is return def for lambda try
 # vim: ff=unix:noet

File plugin/TagHighlight/data/options.txt

 	Help:List of (Python) regular expressions to match against keywords which should be excluded from the types file.
+	CommandLineSwitches:--skip-reserved-keywords
+	VimOptionMap:SkipReservedKeywords
+	Type:bool
+	Default:True
+	Help:Don't highlight keywords that are reserved in a given language.

File plugin/TagHighlight/module/

         keycommand = keystarter
         for keyword in tags[thisType]:
             skip_this = False
+            if options['skip_reserved_keywords']:
+                if keyword in language_handler['ReservedKeywords']:
+                    Debug('Skipping reserved word ' + keyword, 'Information')
+                    # Ignore this keyword
+                    continue
             for pattern in patternREs:
                 if != None:
                     skip_this = True

File plugin/TagHighlight/module/

         for language_file in GlobData('languages/*.txt'):
             language_dict = LoadDataFile(language_file, language_list_entries)
             language_dict['Filename'] = language_file
+            if 'ReservedKeywords' in language_dict:
+                # This is some weird python magic that takes a list of
+                # strings containing space-separated items and produces
+                # a single list of those items.
+                language_dict['ReservedKeywords'] = \
+                        [item for sublist in language_dict['ReservedKeywords'] for item in sublist.split(' ')]
+            else:
+                language_dict['ReservedKeywords'] = []
             language_dict = self.VerifyLanguage(language_dict)
             self.registry[language_dict['FriendlyName']] = language_dict