Permalink
Browse files

Add support for setting Gist hilight mode using file extension and TM…

…_SCOPE.
  • Loading branch information...
1 parent c70da04 commit 64e8231833b40904c5ce5a3392582fd8bb50bf08 @4rc0s 4rc0s committed Nov 19, 2008
Showing with 45 additions and 3 deletions.
  1. +43 −1 Support/bin/create_gist_from_selection.rb
  2. +2 −2 Support/lib/gist.rb
@@ -3,13 +3,55 @@
$:.unshift(File.dirname(__FILE__) + "/../lib")
require "gist"
+# Add extension for supported modes based on TM_SCOPE
+# Cribbed from http://github.com/defunkt/gist.el/tree/master/gist.el
+def get_extension
+ scope = ENV["TM_SCOPE"].split[0]
+ case scope
+ when "source.actionscript" : "as"
+ when "source.c", "source.objc" : "c"
+ when "source.c++", "source.objc++" : "cpp"
+ # common-lisp-mode : "el"
+ when "source.css" : "css"
+ when "source.diff", "meta.diff.range" : "diff"
+ # emacs-lisp-mode : "el"
+ when "source.erlang" : "erl"
+ when "source.haskell", "text.tex.latex.haskel" : "hs"
+ when "text.html" : "html"
+ when "source.io" : "io"
+ when "source.java" : "java"
+ when "source.js" : "js"
+ # jde-mode : "java"
+ # js2-mode : "js"
+ when "source.lua" : "lua"
+ when "source.ocaml" : "ml"
+ when "source.objc", "source.objc++" : "m"
+ when "source.perl" : "pl"
+ when "source.php" : "php"
+ when "source.python" : "sc"
+ when "source.ruby" : "rb" # Emacs bundle uses rbx
+ when "text.plain" : "txt"
+ when "source.sql" : "sql"
+ when "source.scheme" : "scm"
+ when "source.smalltalk" : "st"
+ when "source.shell" : "sh"
+ when "source.tcl", "text.html.tcl" : "tcl"
+ when "source.lex" : "tex"
+ when "text.xml", "text.xml.xsl" : "xml"
+ else "txt"
+ end
+end
+
selection = nil
+gistname = nil
if ENV['TM_SELECTED_TEXT']
selection = ENV['TM_SELECTED_TEXT']
+ gistname = "snippet" << "." << get_extension
else
selection = STDIN.read
+ gistname = "file" << "." << get_extension
end
-if url = Gist.write(selection, ARGV[0] == "private" ? true : false)
+if url = Gist.write(gistname, selection, ARGV[0] == "private" ? true : false)
puts "Created gist at #{url}. URL copied to clipboard."
end
View
@@ -14,9 +14,9 @@ def read(gist_id)
open(@@gist_url % gist_id).read
end
- def write(content, private_gist)
+ def write(gistname, content, private_gist)
url = URI.parse('http://gist.github.com/gists')
- req = Net::HTTP.post_form(url, data(nil, nil, content, private_gist))
+ req = Net::HTTP.post_form(url, data(gistname, nil, content, private_gist))
copy req['Location']
end

0 comments on commit 64e8231

Please sign in to comment.