Skip to content

Commit

Permalink
Merge pull request #31 from steffex/master
Browse files Browse the repository at this point in the history
Max amount of Gists
  • Loading branch information
condemil committed Aug 11, 2012
2 parents 8924542 + 872dcce commit 335c713
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Default (Linux).sublime-keymap
Expand Up @@ -2,5 +2,6 @@
{ "keys": ["ctrl+k", "ctrl+i"], "command": "gist" }, { "keys": ["ctrl+k", "ctrl+i"], "command": "gist" },
{ "keys": ["ctrl+k", "ctrl+l"], "command": "gist_private" }, { "keys": ["ctrl+k", "ctrl+l"], "command": "gist_private" },
{ "keys": ["ctrl+k", "ctrl+s"], "command": "gist_update_file" }, { "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" }
] ]
3 changes: 2 additions & 1 deletion Default (OSX).sublime-keymap
Expand Up @@ -2,5 +2,6 @@
{ "keys": ["super+k", "super+i"], "command": "gist" }, { "keys": ["super+k", "super+i"], "command": "gist" },
{ "keys": ["super+k", "super+l"], "command": "gist_private" }, { "keys": ["super+k", "super+l"], "command": "gist_private" },
{ "keys": ["super+k", "super+s"], "command": "gist_update_file" }, { "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" }
] ]
3 changes: 2 additions & 1 deletion Default (Windows).sublime-keymap
Expand Up @@ -2,5 +2,6 @@
{ "keys": ["ctrl+k", "ctrl+i"], "command": "gist" }, { "keys": ["ctrl+k", "ctrl+i"], "command": "gist" },
{ "keys": ["ctrl+k", "ctrl+l"], "command": "gist_private" }, { "keys": ["ctrl+k", "ctrl+l"], "command": "gist_private" },
{ "keys": ["ctrl+k", "ctrl+s"], "command": "gist_update_file" }, { "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" }
] ]
4 changes: 4 additions & 0 deletions Gist.sublime-commands
Expand Up @@ -11,6 +11,10 @@
"caption": "Gist: Open Gist", "caption": "Gist: Open Gist",
"command": "gist_list" "command": "gist_list"
}, },
{
"caption": "Gist: Insert Gist",
"command": "insert_gist_list"
},
{ {
"caption": "Gist: Add File to Gist", "caption": "Gist: Add File to Gist",
"command": "gist_add_file" "command": "gist_add_file"
Expand Down
5 changes: 4 additions & 1 deletion Gist.sublime-settings
Expand Up @@ -14,5 +14,8 @@
// Github URL // Github URL
// Default: Leave empty if you want to use GitHub.com // Default: Leave empty if you want to use GitHub.com
// Example: https://github.domain.com // Example: https://github.domain.com
"url": "" "url": "",

// Max Gists to show (max 100 allowed by GitHub API)
"max_gists": 100
} }
1 change: 1 addition & 0 deletions Main.sublime-menu
Expand Up @@ -12,6 +12,7 @@
{ "command": "gist", "caption": "Create Public Gist…" }, { "command": "gist", "caption": "Create Public Gist…" },
{ "command": "gist_private", "caption": "Create Private Gist…" }, { "command": "gist_private", "caption": "Create Private Gist…" },
{ "command": "gist_list", "caption": "Open Gist…" }, { "command": "gist_list", "caption": "Open Gist…" },
{ "command": "insert_gist_list", "caption": "Insert Gist…" },
{ "command": "gist_add_file", "caption": "Add File to Gist…" }, { "command": "gist_add_file", "caption": "Add File to Gist…" },
{ "caption": "-" }, { "caption": "-" },
{ "command": "gist_copy_url", "caption": "Copy Gist URL" }, { "command": "gist_copy_url", "caption": "Copy Gist URL" },
Expand Down
17 changes: 17 additions & 0 deletions README.md
Expand Up @@ -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 You can enter https proxy here
Format: "http://user:pass@proxy:port" 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 # Usage


All functionality of the plugin is available in the `Tools` / `Gist` menu and in the command pallette. All functionality of the plugin is available in the `Tools` / `Gist` menu and in the command pallette.
Expand Down Expand Up @@ -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` * Windows and Linux: `Ctrl+Shift+G`
* OS X: `Ctrl+Cmd+G` * OS X: `Ctrl+Cmd+G`


## Insert Gist

* Windows and Linux: "ctrl+shift+alt+g"
* OS X: "ctrl+shift+super+g"

# Information # Information


Source: https://github.com/condemil/Gist Source: https://github.com/condemil/Gist
Expand Down
27 changes: 27 additions & 0 deletions gist.py
Expand Up @@ -25,6 +25,13 @@
raise MissingCredentialsException() raise MissingCredentialsException()
GISTS_URL += '/api/v3/gists' 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): class MissingCredentialsException(Exception):
pass pass


Expand Down Expand Up @@ -216,6 +223,18 @@ def open_gist(gist_url):
if os.path.exists(new_syntax_path): if os.path.exists(new_syntax_path):
view.set_syntax_file( 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(): def get_gists():
return api_request(GISTS_URL) return api_request(GISTS_URL)


Expand Down Expand Up @@ -464,6 +483,14 @@ def handle_gist(self, gist):
def get_window(self): def get_window(self):
return self.window 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): class GistAddFileCommand(GistListCommandBase, sublime_plugin.TextCommand):
def is_enabled(self): def is_enabled(self):
return self.view.settings().get('gist_url') is None return self.view.settings().get('gist_url') is None
Expand Down

0 comments on commit 335c713

Please sign in to comment.