Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added support to allow /* and /** to the end of include paths

  • Loading branch information...
commit 1e60b4e7c227499fa1566bbd8c227dedf8026a19 1 parent d4d71ef
@jvranish jvranish authored
Showing with 76 additions and 4 deletions.
  1. +46 −0 SublimeClang.sublime-settings
  2. +30 −4 common.py
View
46 SublimeClang.sublime-settings
@@ -162,6 +162,52 @@
// "-I<path of the project folder containing main.cpp>/includepath",
// "-I<path of the project folder containing main.cpp>/anotherincludepath"
//
+ //
+ //
+ // You can also add an '*' or '**' to the end of a path.
+ // '*' will include all the subdirectories (non-recursive) of that path (not including the given path)
+ // '**' will expand to include all subdirectories recursively (not including the given path)
+ //
+ // Both with ignore any directories that begin with '.', but you can still specify those manually
+ //
+ //
+ // For example, imagine we had a directory structure like so:
+ //
+ // myproject/myproject.sublime-project
+ // myproject/src
+ // myproject/src/.hidden-dir
+ // myproject/src/ModuleA
+ // myproject/src/ModuleB
+ // myproject/src/ModuleC/SubmoduleC-A
+ // myproject/src/ModuleC/SubmoduleC-B
+ // myproject/includes
+ // myproject/includes/something
+ // myproject/includes/somethingelse
+ // myproject/includes/morethings
+ // myproject/includes/evenmorethings/asdf
+ //
+ //
+ // an option like this:
+ // "-I${folder:${project_path:myproject.sublime-project}}/src/**",
+ //
+ // will expand to:
+ // "-I/path/to/myproject/src/ModuleA",
+ // "-I/path/to/myproject/src/ModuleB",
+ // "-I/path/to/myproject/src/ModuleC/SubmoduleC-A",
+ // "-I/path/to/myproject/src/ModuleC/SubmoduleC-B",
+ //
+ // Note that src and .hidden-dir were skipped
+ //
+ //
+ // an option like this:
+ // "-I${folder:${project_path:myproject.sublime-project}}/includes/*",
+ // will expand to:
+ // "-I/path/to/myproject/includes/something",
+ // "-I/path/to/myproject/includes/somethingelse",
+ // "-I/path/to/myproject/includes/morethings",
+ // "-I/path/to/myproject/includes/evenmorethings",
+ //
+ // Notice that the both the myproject/includes directory and any directories more than one level deep are skipped
"options":
[
"-Wall",
View
34 common.py
@@ -52,7 +52,7 @@ def get_setting(key, default=None):
return get_settings().get(key, default)
-def complete_path(value):
+def expand_path(value):
value = value % ({'home': os.getenv('HOME')})
get_existing_files = \
@@ -66,14 +66,40 @@ def complete_path(value):
return value
+def complete_path(value):
+ path_init, path_last = os.path.split(value)
+ if path_init[:2] == "-I" and (path_last == "**" or path_last == "*") :
+ starting_path = expand_path(path_init[2:])
+ include_paths = []
+ if os.path.exists(starting_path):
+ if path_last == "*":
+ for dirname in os.listdir(starting_path):
+ if not dirname.startswith("."): # skip directories that begin with .
+ include_paths.append("-I" + os.path.join(starting_path, dirname))
+ elif path_last == "**":
+ for dirpath, dirs, files in os.walk(starting_path):
+ for dirname in list(dirs):
+ if dirname.startswith("."): # skip directories that begin with .
+ dirs.remove(dirname)
+ if dirpath != starting_path:
+ include_paths.append("-I" + dirpath)
+ else:
+ include_paths.append("-I" + starting_path)
+ else:
+ pass # perhaps put some error here?
+ return include_paths
+ else:
+ return [expand_path(value)]
def get_path_setting(key, default=None):
value = get_setting(key, default)
-
+ opts = []
if isinstance(value, str) or isinstance(value, unicode):
- return complete_path(value)
+ opts.extend(complete_path(value))
else:
- return [ complete_path(v) for v in value ]
+ for v in value:
+ opts.extend(complete_path(v))
+ return opts
def get_cpu_count():
Please sign in to comment.
Something went wrong with that request. Please try again.