Permalink
Browse files

Merge pull request #31 from steffex/master

Max amount of Gists
  • Loading branch information...
2 parents 8924542 + 872dcce commit 335c713998fe7db121a973b36acad619cd677479 @condemil committed Aug 11, 2012
@@ -2,5 +2,6 @@
{ "keys": ["ctrl+k", "ctrl+i"], "command": "gist" },
{ "keys": ["ctrl+k", "ctrl+l"], "command": "gist_private" },
{ "keys": ["ctrl+k", "ctrl+s"], "command": "gist_update_file" },
- { "keys": ["ctrl+shift+g"], "command": "gist_list" }
+ { "keys": ["ctrl+shift+g"], "command": "gist_list" },
+ { "keys": ["ctrl+shift+alt+g"], "command": "insert_gist_list" }
]
@@ -2,5 +2,6 @@
{ "keys": ["super+k", "super+i"], "command": "gist" },
{ "keys": ["super+k", "super+l"], "command": "gist_private" },
{ "keys": ["super+k", "super+s"], "command": "gist_update_file" },
- { "keys": ["ctrl+super+g"], "command": "gist_list" }
+ { "keys": ["ctrl+super+g"], "command": "gist_list" },
+ { "keys": ["ctrl+shift+super+g"], "command": "insert_gist_list" }
]
@@ -2,5 +2,6 @@
{ "keys": ["ctrl+k", "ctrl+i"], "command": "gist" },
{ "keys": ["ctrl+k", "ctrl+l"], "command": "gist_private" },
{ "keys": ["ctrl+k", "ctrl+s"], "command": "gist_update_file" },
- { "keys": ["ctrl+shift+g"], "command": "gist_list" }
+ { "keys": ["ctrl+shift+g"], "command": "gist_list" },
+ { "keys": ["ctrl+shift+alt+g"], "command": "insert_gist_list" }
]
View
@@ -12,6 +12,10 @@
"command": "gist_list"
},
{
+ "caption": "Gist: Insert Gist",
+ "command": "insert_gist_list"
+ },
+ {
"caption": "Gist: Add File to Gist",
"command": "gist_add_file"
},
View
@@ -14,5 +14,8 @@
// Github URL
// Default: Leave empty if you want to use GitHub.com
// Example: https://github.domain.com
- "url": ""
+ "url": "",
+
+ // Max Gists to show (max 100 allowed by GitHub API)
+ "max_gists": 100
}
View
@@ -12,6 +12,7 @@
{ "command": "gist", "caption": "Create Public Gist…" },
{ "command": "gist_private", "caption": "Create Private Gist…" },
{ "command": "gist_list", "caption": "Open Gist…" },
+ { "command": "insert_gist_list", "caption": "Insert Gist…" },
{ "command": "gist_add_file", "caption": "Add File to Gist…" },
{ "caption": "-" },
{ "command": "gist_copy_url", "caption": "Copy Gist URL" },
View
@@ -31,6 +31,18 @@ If you're using OS X and have a keychain entry for github.com, no configuration
You can enter https proxy here
Format: "http://user:pass@proxy:port"
+* `"enterprise": false`
+
+ Set this to true if you want to use a enterprise version of github instead of github.com
+
+* `"url": ""`
+
+ Set the url of the enterprise version of github you want to use. Leave this blank if the enterprise option is set to false.
+
+* `"max_gists": 100`
+
+ Set the maximum number of Gists that can will fetched by the plugin. It can't be higher than 100, because of GitHub API limitations.
+
# Usage
All functionality of the plugin is available in the `Tools` / `Gist` menu and in the command pallette.
@@ -69,6 +81,11 @@ Use the `Gist` / `Add File To Gist` command to see a list of your Gists. Selecti
* Windows and Linux: `Ctrl+Shift+G`
* OS X: `Ctrl+Cmd+G`
+## Insert Gist
+
+* Windows and Linux: "ctrl+shift+alt+g"
+* OS X: "ctrl+shift+super+g"
+
# Information
Source: https://github.com/condemil/Gist
View
27 gist.py
@@ -25,6 +25,13 @@
raise MissingCredentialsException()
GISTS_URL += '/api/v3/gists'
+#Per page support (max 100)
+if settings.get('max_gists'):
+ if settings.get('max_gists') <= 100:
+ GISTS_URL += '?per_page=%d' % settings.get('max_gists');
+ else:
+ sublime.error_message("Gist: GitHub API does not support a value of higher than 100")
+
class MissingCredentialsException(Exception):
pass
@@ -216,6 +223,18 @@ def open_gist(gist_url):
if os.path.exists(new_syntax_path):
view.set_syntax_file( new_syntax_path )
+def insert_gist(gist_url):
+ gist = api_request(gist_url)
+ files = sorted(gist['files'].keys())
+ for gist_filename in files:
+ view = sublime.active_window().active_view()
+ edit = view.begin_edit()
+ for region in view.sel():
+
+ view.replace(edit, region, gist['files'][gist_filename]['content'])
+
+ view.end_edit(edit)
+
def get_gists():
return api_request(GISTS_URL)
@@ -464,6 +483,14 @@ def handle_gist(self, gist):
def get_window(self):
return self.window
+class InsertGistListCommand(GistListCommandBase, sublime_plugin.WindowCommand):
+ @catch_errors
+ def handle_gist(self, gist):
+ insert_gist(gist['url'])
+
+ def get_window(self):
+ return self.window
+
class GistAddFileCommand(GistListCommandBase, sublime_plugin.TextCommand):
def is_enabled(self):
return self.view.settings().get('gist_url') is None

0 comments on commit 335c713

Please sign in to comment.