abudden avatar abudden committed 3d8e6bf

Fixed a major bug with a misnamed variable and attempted to improve RunShellCommand for space issues.

Comments (0)

Files changed (8)

autoload/TagHighlight/RunPythonScript.vim

 " Tag Highlighter:
 "   Author:  A. S. Budden <abudden _at_ gmail _dot_ com>
-"   Date:    26/07/2011
+"   Date:    27/07/2011
 " Copyright: Copyright (C) 2009-2011 A. S. Budden
 "            Permission is hereby granted to use and distribute this code,
 "            with or without modifications, provided that this copyright
 	let syscmd = ""
 	for arg in a:args
 		if len(syscmd) > 0
-			let syscmd += " "
+			let syscmd .= " "
 		endif
-		let syscmd += shellescape(arg)
+		if stridx(arg, " ") != -1
+			let syscmd .= shellescape(arg)
+		else
+			let syscmd .= arg
+		endif
 	endfor
-	return system(syscmd)
+	echomsg syscmd
+	let result = system(syscmd)
+	echo result
+	return result
 endfunction
 
 function! TagHighlight#RunPythonScript#RunGenerator(options)
 	elseif index(["python","compiled"], s:python_variant) != -1
 		let args = s:python_cmd[:]
 		" We're calling the script externally, build a list of arguments
-		for option in g:TagHighlightPrivate['ScriptOptions']
+		for option in g:TagHighlightPrivate['PluginOptions']
 			if has_key(option, 'VimOptionMap') && 
 						\ has_key(option, 'CommandLineSwitches') &&
 						\ has_key(a:options, option['VimOptionMap'])
 				else
 					let switch = option['CommandLineSwitches']
 				endif
+				if switch[:1] == "--"
+					let as_one = 1
+				elseif switch[:0] == "-"
+					let as_one = 0
+				else
+					echoerr "Invalid configuration for option " . option['VimOptionMap']
+				endif
 				" We can handle this one automatically
 				if option['Type'] == 'bool'
 					if ((a:options[option['VimOptionMap']] && option['Default'] == 'False')
 						let args += [switch]
 					endif
 				elseif option['Type'] == 'string'
-					let args += [switch . '=' . a:options[option['VimOptionMap']]]
+					if as_one == 1
+						let args += [switch . '=' . a:options[option['VimOptionMap']]]
+					else
+						let args += [switch, a:options[option['VimOptionMap']]]
+					endif
 				elseif option['Type'] == 'list'
 					for entry in a:options[option['VimOptionMap']]
-						let args += [switch . '=' . entry]
+						if as_one == 1
+							let args += [switch . '=' . entry]
+						else
+							let args += [switch, entry]
+						endif
 					endfor
 				endif
 			endif
 	else
 		return 'None'
 	endif
-	let file_exe = substitute(file_exe, '\\', '/', 'g')
+	"let file_exe = substitute(file_exe, '\\', '/', 'g')
 	return file_exe
 endfunction
 
 
 	" If we've run before and nothing has changed, just return
 	if s:python_variant != 'None'
-		if forced_variant == s:stored_forced_variant && s:stored_variant_priority == variant_priority
+		if forced_variant == s:stored_forced_variant
+					\ && s:stored_variant_priority == variant_priority
+					\ && s:python_path == TagHighlight#Option#GetOption("PathToPython")
 			return s:python_variant
 		endif
 	endif
 
 	let s:python_variant = 'None'
+	let s:python_cmd = []
+	let s:python_path = ""
+
 	" Make sure that the user specified variant is supported
 	if index(supported_variants, forced_variant) == -1
 		let forced_variant = 'None'
 	if s:python_variant != 'None'
 		" Consider checking that it's valid
 		if TagHighlight#Debug#GetDebugLevelName() == 'Information'
+			echomsg "Python variant is " . s:python_variant
+			echomsg "Python Command is " . join(s:python_cmd, " ")
+			echomsg "Python Path is " . s:python_path
 			let pyversion = TagHighlight#RunPythonScript#GetPythonVersion()
 			call TagHighlight#Debug#Print("Python version reported as: " . pyversion,
 						\ 'Information')

doc/TagHighlight.txt

 ==============================================================================
 7. TagHighlight History                *TagHighlight-history*               {{{1
 
+2.0.4: 27th July 2011      : Fixed bug in python interface (old variable
+                             name); renamed ctags interface python code to
+                             avoid potential issues with other plugins
+                             thinking that ctags.py is actually ctags.
+                             Further improvements to handling paths with
+                             spaces.
+
 2.0.3: 26th July 2011      : Added missing documentation to zip file!
 
 2.0.2: 26th July 2011      : Improved Linux compiled version support.

plugin/TagHighlight/TagHighlight.py

 def main():
     from module.cmd import ProcessCommandLine
     from module.worker import RunWithOptions
-
     options = ProcessCommandLine()
     RunWithOptions(options)
 

plugin/TagHighlight/data/options.txt

 	Default:[]
 	Help:List of files for which the type reading should be disabled
 
-debug_level:
-	VimOptionMap:DebugLevel
-	Type:string
-	Default:Error
-	Help:Debug level for printing (how much debug output to produce)
-
 def_dir_mode_priority:
 	VimOptionMap:DefaultDirModePriority
 	Type:list
 # Python script options: #
 ##########################
 
+debug_level:
+	CommandLineSwitches:--debug
+	VimOptionMap:DebugLevel
+	Type:string
+	Default:Error
+	Help:Debug level for printing (how much debug output to produce)
+
 source_root:
 	CommandLineSwitches:-d,--source-root
 	VimOptionMap:SourceDir

plugin/TagHighlight/module/ctags.py

-#!/usr/bin/env python
-# Tag Highlighter:
-#   Author:  A. S. Budden <abudden _at_ gmail _dot_ com>
-#   Date:    25/07/2011
-# Copyright: Copyright (C) 2009-2011 A. S. Budden
-#            Permission is hereby granted to use and distribute this code,
-#            with or without modifications, provided that this copyright
-#            notice is copied with it. Like anything else that's free,
-#            the TagHighlight plugin is provided *as is* and comes with no
-#            warranty of any kind, either expressed or implied. By using
-#            this plugin, you agree that in no event will the copyright
-#            holder be liable for any damages resulting from the use
-#            of this software.
-
-# ---------------------------------------------------------------------
-from __future__ import print_function
-import subprocess
-import os
-import re
-import glob
-from .utilities import DictDict
-from .languages import Languages
-
-field_processor = re.compile(
-r'''
-    ^                 # Start of the line
-    (?P<keyword>.*?)  # Capture the first field: everything up to the first tab
-    \t                # Field separator: a tab character
-    .*?               # Second field (uncaptured): everything up to the next tab
-    \t                # Field separator: a tab character
-    (?P<search>.*?)   # Any character at all, but as few as necessary (i.e. catch everything up to the ;")
-    ;"                # The end of the search specifier (see http://ctags.sourceforge.net/FORMAT)
-    (?=\t)            # There MUST be a tab character after the ;", but we want to match it with zero width
-    .*\t              # There can be other fields before "kind", so catch them here.
-                      # Also catch the tab character from the previous line as there MUST be a tab before the field
-    (kind:)?          # This is the "kind" field; "kind:" is optional
-    (?P<kind>\w)      # The kind is a single character: catch it
-    (\t|$)            # It must be followed either by a tab or by the end of the line
-    .*                # If it is followed by a tab, soak up the rest of the line; replace with the syntax keyword line
-''', re.VERBOSE)
-field_const = re.compile(r'\bconst\b')
-
-def GenerateTags(options):
-    print("Generating Tags")
-
-    args = GetCommandArgs(options)
-
-    os.chdir(options['source_root'])
-
-    ctags_cmd = [options['ctags_exe_full']] + args
-
-    #subprocess.call(" ".join(ctags_cmd), shell = (os.name != 'nt'))
-    # shell=True stops the command window popping up
-    process = subprocess.Popen(ctags_cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE)#, shell=True)
-    (sout, serr) = process.communicate()
-
-    tagFile = open(os.path.join(options['ctags_file_dir'], options['ctags_file']), 'r')
-    tagLines = [line.strip() for line in tagFile]
-    tagFile.close()
-
-    # Also sort the file a bit better (tag, then kind, then filename)
-    tagLines.sort(key=ctags_key)
-
-    tagFile = open(os.path.join(options['ctags_file_dir'],options['ctags_file']), 'w')
-    for line in tagLines:
-        tagFile.write(line + "\n")
-    tagFile.close()
-
-def ParseTags(options):
-    """Function to parse the tags file and generate a dictionary containing language keys.
-
-    Each entry is a list of tags with all the required details.
-    """
-    languages = options['language_handler']
-    kind_list = languages.GetKindList()
-
-    # Language: {Type: set([keyword, keyword, keyword])}
-    ctags_entries = DictDict()
-
-    lineMatchers = {}
-    for key in languages.GetAllLanguages():
-        lineMatchers[key] = re.compile(
-                r'^.*?\t[^\t]*\.(?P<extension>' +
-                languages.GetLanguageHandler(key)['PythonExtensionMatcher'] +
-                ')\t')
-
-    p = open(os.path.join(options['ctags_file_dir'],options['ctags_file']), 'r')
-    while 1:
-        try:
-            line = p.readline()
-        except UnicodeDecodeError:
-            continue
-        if not line:
-            break
-
-        for key, lineMatcher in list(lineMatchers.items()):
-            if lineMatcher.match(line):
-                # We have a match
-                m = field_processor.match(line.strip())
-                if m is not None:
-                    try:
-                        short_kind = 'ctags_' + m.group('kind')
-                        kind = kind_list[key][short_kind]
-                        keyword = m.group('keyword')
-                        if options['parse_constants'] and \
-                                (key == 'c') and \
-                                (kind == 'CTagsGlobalVariable'):
-                            if field_const.search(m.group('search')) is not None:
-                                kind = 'CTagsConstant'
-                        if short_kind not in languages.GetLanguageHandler(key)['SkipList']:
-                            ctags_entries[key][kind].add(keyword)
-                    except KeyError:
-                        print("Unrecognised kind '{kind}' for language {language}".format(kind=m.group('kind'), language=key))
-    p.close()
-
-    return ctags_entries
-
-def GetCommandArgs(options):
-    args = []
-
-    ctags_languages = [l['CTagsName'] for l in options['language_handler'].GetAllLanguageHandlers()]
-    if 'c' in ctags_languages:
-        ctags_languages.append('c++')
-    args += ["--languages=" + ",".join(ctags_languages)]
-
-    if options['ctags_file']:
-        args += ['-f', os.path.join(options['ctags_file_dir'], options['ctags_file'])]
-
-    if not options['include_docs']:
-        args += ["--exclude=docs", "--exclude=Documentation"]
-
-    if options['include_locals']:
-        kinds = options['language_handler'].GetKindList()
-        def FindLocalVariableKinds(language_kinds):
-            """Finds the key associated with a value in a dictionary.
-
-            Assumes presence has already been checked."""
-            return "".join(key[-1] for key,val in language_kinds.items() if val == 'CTagsLocalVariable')
-
-        for language in ctags_languages:
-            if language in kinds and 'CTagsLocalVariable' in kinds[language].values():
-                args += ['--{language}-kinds=+{kind}'.format(language=language,
-                    kind=FindLocalVariableKinds(kinds[language]))]
-
-    # Must be last as it includes the file list:
-    if options['recurse']:
-        args += ['--recurse']
-        args += ['.']
-    else:
-        args += glob.glob(os.path.join(options['source_root'],'*'))
-
-    return args
-
-key_regexp = re.compile('^(?P<keyword>.*?)\t(?P<remainder>.*\t(?P<kind>[a-zA-Z])(?:\t|$).*)')
-
-def ctags_key(ctags_line):
-    match = key_regexp.match(ctags_line)
-    if match is None:
-        return ctags_line
-    return match.group('keyword') + match.group('kind') + match.group('remainder')

plugin/TagHighlight/module/ctags_interface.py

+#!/usr/bin/env python
+# Tag Highlighter:
+#   Author:  A. S. Budden <abudden _at_ gmail _dot_ com>
+#   Date:    25/07/2011
+# Copyright: Copyright (C) 2009-2011 A. S. Budden
+#            Permission is hereby granted to use and distribute this code,
+#            with or without modifications, provided that this copyright
+#            notice is copied with it. Like anything else that's free,
+#            the TagHighlight plugin is provided *as is* and comes with no
+#            warranty of any kind, either expressed or implied. By using
+#            this plugin, you agree that in no event will the copyright
+#            holder be liable for any damages resulting from the use
+#            of this software.
+
+# ---------------------------------------------------------------------
+from __future__ import print_function
+import subprocess
+import os
+import re
+import glob
+from .utilities import DictDict
+from .languages import Languages
+
+field_processor = re.compile(
+r'''
+    ^                 # Start of the line
+    (?P<keyword>.*?)  # Capture the first field: everything up to the first tab
+    \t                # Field separator: a tab character
+    .*?               # Second field (uncaptured): everything up to the next tab
+    \t                # Field separator: a tab character
+    (?P<search>.*?)   # Any character at all, but as few as necessary (i.e. catch everything up to the ;")
+    ;"                # The end of the search specifier (see http://ctags.sourceforge.net/FORMAT)
+    (?=\t)            # There MUST be a tab character after the ;", but we want to match it with zero width
+    .*\t              # There can be other fields before "kind", so catch them here.
+                      # Also catch the tab character from the previous line as there MUST be a tab before the field
+    (kind:)?          # This is the "kind" field; "kind:" is optional
+    (?P<kind>\w)      # The kind is a single character: catch it
+    (\t|$)            # It must be followed either by a tab or by the end of the line
+    .*                # If it is followed by a tab, soak up the rest of the line; replace with the syntax keyword line
+''', re.VERBOSE)
+field_const = re.compile(r'\bconst\b')
+
+def GenerateTags(options):
+    print("Generating Tags")
+
+    args = GetCommandArgs(options)
+
+    os.chdir(options['source_root'])
+
+    ctags_cmd = [options['ctags_exe_full']] + args
+
+    #subprocess.call(" ".join(ctags_cmd), shell = (os.name != 'nt'))
+    # shell=True stops the command window popping up
+    process = subprocess.Popen(ctags_cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE)#, shell=True)
+    (sout, serr) = process.communicate()
+
+    tagFile = open(os.path.join(options['ctags_file_dir'], options['ctags_file']), 'r')
+    tagLines = [line.strip() for line in tagFile]
+    tagFile.close()
+
+    # Also sort the file a bit better (tag, then kind, then filename)
+    tagLines.sort(key=ctags_key)
+
+    tagFile = open(os.path.join(options['ctags_file_dir'],options['ctags_file']), 'w')
+    for line in tagLines:
+        tagFile.write(line + "\n")
+    tagFile.close()
+
+def ParseTags(options):
+    """Function to parse the tags file and generate a dictionary containing language keys.
+
+    Each entry is a list of tags with all the required details.
+    """
+    languages = options['language_handler']
+    kind_list = languages.GetKindList()
+
+    # Language: {Type: set([keyword, keyword, keyword])}
+    ctags_entries = DictDict()
+
+    lineMatchers = {}
+    for key in languages.GetAllLanguages():
+        lineMatchers[key] = re.compile(
+                r'^.*?\t[^\t]*\.(?P<extension>' +
+                languages.GetLanguageHandler(key)['PythonExtensionMatcher'] +
+                ')\t')
+
+    p = open(os.path.join(options['ctags_file_dir'],options['ctags_file']), 'r')
+    while 1:
+        try:
+            line = p.readline()
+        except UnicodeDecodeError:
+            continue
+        if not line:
+            break
+
+        for key, lineMatcher in list(lineMatchers.items()):
+            if lineMatcher.match(line):
+                # We have a match
+                m = field_processor.match(line.strip())
+                if m is not None:
+                    try:
+                        short_kind = 'ctags_' + m.group('kind')
+                        kind = kind_list[key][short_kind]
+                        keyword = m.group('keyword')
+                        if options['parse_constants'] and \
+                                (key == 'c') and \
+                                (kind == 'CTagsGlobalVariable'):
+                            if field_const.search(m.group('search')) is not None:
+                                kind = 'CTagsConstant'
+                        if short_kind not in languages.GetLanguageHandler(key)['SkipList']:
+                            ctags_entries[key][kind].add(keyword)
+                    except KeyError:
+                        print("Unrecognised kind '{kind}' for language {language}".format(kind=m.group('kind'), language=key))
+    p.close()
+
+    return ctags_entries
+
+def GetCommandArgs(options):
+    args = []
+
+    ctags_languages = [l['CTagsName'] for l in options['language_handler'].GetAllLanguageHandlers()]
+    if 'c' in ctags_languages:
+        ctags_languages.append('c++')
+    args += ["--languages=" + ",".join(ctags_languages)]
+
+    if options['ctags_file']:
+        args += ['-f', os.path.join(options['ctags_file_dir'], options['ctags_file'])]
+
+    if not options['include_docs']:
+        args += ["--exclude=docs", "--exclude=Documentation"]
+
+    if options['include_locals']:
+        kinds = options['language_handler'].GetKindList()
+        def FindLocalVariableKinds(language_kinds):
+            """Finds the key associated with a value in a dictionary.
+
+            Assumes presence has already been checked."""
+            return "".join(key[-1] for key,val in language_kinds.items() if val == 'CTagsLocalVariable')
+
+        for language in ctags_languages:
+            if language in kinds and 'CTagsLocalVariable' in kinds[language].values():
+                args += ['--{language}-kinds=+{kind}'.format(language=language,
+                    kind=FindLocalVariableKinds(kinds[language]))]
+
+    # Must be last as it includes the file list:
+    if options['recurse']:
+        args += ['--recurse']
+        args += ['.']
+    else:
+        args += glob.glob(os.path.join(options['source_root'],'*'))
+
+    return args
+
+key_regexp = re.compile('^(?P<keyword>.*?)\t(?P<remainder>.*\t(?P<kind>[a-zA-Z])(?:\t|$).*)')
+
+def ctags_key(ctags_line):
+    match = key_regexp.match(ctags_line)
+    if match is None:
+        return ctags_line
+    return match.group('keyword') + match.group('kind') + match.group('remainder')

plugin/TagHighlight/module/generation.py

                                 matchDone = True
                                 break
 
-                    if not matchDone:
+                    if not matchDone and options['debug_level'] == 'Information':
                         print("Skipping keyword '" + keyword + "'")
 
                     continue

plugin/TagHighlight/module/worker.py

 #!/usr/bin/env python
 # Tag Highlighter:
 #   Author:  A. S. Budden <abudden _at_ gmail _dot_ com>
-#   Date:    25/07/2011
+#   Date:    27/07/2011
 # Copyright: Copyright (C) 2009-2011 A. S. Budden
 #            Permission is hereby granted to use and distribute this code,
 #            with or without modifications, provided that this copyright
 
     SetInitialOptions(options)
 
+    if config['debug_level'] == 'Information':
+        print("Running types highlighter generator")
+
     if config['use_existing_tagfile'] and not os.path.exists(config['ctags_file']):
         config['use_existing_tagfile'] = False
 
         print(sys.version)
         return
 
-    from .ctags import GenerateTags, ParseTags
+    from .ctags_interface import GenerateTags, ParseTags
     from .generation import CreateTypesFile
 
     if not config['use_existing_tagfile']:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.