Skip to content

Commit

Permalink
Add settings files for sublime
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul committed Jul 21, 2013
1 parent 4322a23 commit ace2519
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 8 deletions.
7 changes: 7 additions & 0 deletions ClangComplete.sublime-settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"additional_options": ["-Wno-c++11-narrowing", "-D__STRICT_ANSI__", "-DQT_NO_DEBUG", "-isystem", "/usr/local/lib/clang/3.3/include"],
"build_dir": "build",
"default_options": ["-std=c++11"],
"timeout": 200,
"inhibit_sublime_completions": true
}
20 changes: 20 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"caption": "Preferences: ClangComplete Settings – Default",
"command": "open_file", "args":
{
"file": "${packages}/ClangComplete/ClangComplete.sublime-settings"
}
},
{
"caption": "Preferences: ClangComplete Settings – User",
"command": "open_file", "args":
{
"file": "${packages}/User/ClangComplete.sublime-settings"
}
},
{
"caption": "ClangComplete: Clear cache",
"command": "clang_clear_cache"
}
]
3 changes: 3 additions & 0 deletions Default.sublime-keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{

}
62 changes: 62 additions & 0 deletions Main.sublime-menu
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[
{
"caption": "Preferences",
"mnemonic": "n",
"id": "preferences",
"children":
[
{
"caption": "ClangComplete",
"children":
[
{
"command": "open_file", "args":
{
"file": "${packages}/ClangComplete/ClangComplete.sublime-settings"
},
"caption": "Settings – Default"
},
{
"command": "open_file", "args":
{
"file": "${packages}/User/ClangComplete.sublime-settings"
},
"caption": "Settings – User"
},
{ "caption": "-" },
{
"command": "open_file", "args":
{
"file": "${packages}/ClangComplete/Default.sublime-keymap"
},
"caption": "Key Bindings – Default"
},
{
"command": "open_file", "args":
{
"file": "${packages}/User/Default (OSX).sublime-keymap",
"platform": "OSX"
},
"caption": "Key Bindings – User"
},
{
"command": "open_file", "args":
{
"file": "${packages}/User/Default (Linux).sublime-keymap",
"platform": "Linux"
},
"caption": "Key Bindings – User"
},
{
"command": "open_file",
"args": {
"file": "${packages}/User/Default (Windows).sublime-keymap",
"platform": "Windows"
},
"caption": "Key Bindings – User"
}
]
}
]
}
]
33 changes: 25 additions & 8 deletions clangcomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,14 @@ def accumulate_options(path):

project_options = {}

def get_options(project_path):
def get_options(project_path, additional_options, build_dir, default_options):
if project_path in project_options: return project_options[project_path]

additional_options = ['-Wno-c++11-narrowing', '-D__STRICT_ANSI__', '-DQT_NO_DEBUG', '-isystem', '/usr/local/lib/clang/3.3/include']
build_dir = os.path.join(project_path, "build")
build_dir = os.path.join(project_path, build_dir)
if os.path.exists(build_dir):
project_options[project_path] = ['-x', 'c++'] + accumulate_options(build_dir) + additional_options
else:
project_options[project_path] = ['-x', 'c++'] + ["-std=c++11"] + additional_options
project_options[project_path] = ['-x', 'c++'] + default_options + additional_options

# print(project_path, project_options[project_path])
return project_options[project_path]
Expand Down Expand Up @@ -239,9 +238,25 @@ def is_member_completion(view, caret):
return False

class ClangCompleteCompletion(sublime_plugin.EventListener):
def get_settings(self):
return sublime.load_settings("ClangComplete.sublime-settings")


def get_setting(self, view, key, default=None):
try:
s = view.settings()
if s.has("clangcomplete_%s" % key):
return s.get("clangcomplete_%s" % key)
except:
pass
return self.get_settings().get(key, default)

def get_args(self, view):
project_path = view.window().folders()[0]
return get_options(project_path)
additional_options = self.get_setting(view, "additional_options", [])
build_dir = self.get_setting(view, "build_dir", "build")
default_options = self.get_setting(view, "default_options", ["-std=c++11"])
return get_options(project_path, additional_options, build_dir, default_options)

def complete_at(self, view, prefix, location, timeout):
print("complete_at", prefix)
Expand Down Expand Up @@ -288,10 +303,12 @@ def on_query_completions(self, view, prefix, locations):
if not is_supported_language(view):
return []

completions = self.complete_at(view, prefix, locations[0], 200)
completions = self.complete_at(view, prefix, locations[0], self.get_setting(view, "timeout", 200))
print("on_query_completions:", prefix, len(completions))
# return ([(c, c) for c in completions])
return ([(c, c) for c in completions], sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
if (self.get_setting(view, "inhibit_sublime_completions", True)):
return ([(c, c) for c in completions], sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
else:
return ([(c, c) for c in completions])

def on_activated_async(self, view):
self.complete_at(view, "", view.sel()[0].begin(), 0)
Expand Down

0 comments on commit ace2519

Please sign in to comment.