From e5b60017596aeb4246b8c558d1ecb288a79d92c7 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Sun, 12 Oct 2014 17:43:03 +0200 Subject: [PATCH 1/4] Add support for TextMate scopes --- lib/linguist/language.rb | 15 +++++++++++++++ lib/linguist/languages.yml | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/linguist/language.rb b/lib/linguist/language.rb index 9c53eb9d..3d803f88 100644 --- a/lib/linguist/language.rb +++ b/lib/linguist/language.rb @@ -290,6 +290,16 @@ module Linguist @lexer = Pygments::Lexer.find_by_name(attributes[:lexer] || name) || raise(ArgumentError, "#{@name} is missing lexer") + @tm_scope = attributes[:tm_scope] || begin + context = case @type + when :data, :markup, :prose + 'text' + when :programming, nil + 'source' + end + "#{context}.#{@name.downcase}" + end + @ace_mode = attributes[:ace_mode] @wrap = attributes[:wrap] || false @@ -363,6 +373,11 @@ module Linguist # Returns the Lexer attr_reader :lexer + # Public: Get the name of a TextMate-compatible scope + # + # Returns the scope + attr_reader :tm_scope + # Public: Get Ace mode # # Examples diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index c85fe463..d2e80f64 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -83,6 +83,7 @@ ATS: ActionScript: type: programming lexer: ActionScript 3 + tm_scope: source.actionscript.3 color: "#e3491a" search_term: as3 aliases: @@ -282,6 +283,7 @@ C: C#: type: programming ace_mode: csharp + tm_scope: source.cs search_term: csharp color: "#178600" aliases: @@ -411,6 +413,7 @@ Clojure: CoffeeScript: type: programming + tm_scope: source.coffee ace_mode: coffee color: "#244776" aliases: @@ -453,6 +456,7 @@ ColdFusion CFC: Common Lisp: type: programming + tm_scope: source.lisp color: "#3fb68b" aliases: - lisp @@ -648,6 +652,7 @@ Elm: Emacs Lisp: type: programming lexer: Common Lisp + tm_scope: source.lisp color: "#c065db" aliases: - elisp @@ -932,6 +937,7 @@ Groovy Server Pages: HTML: type: markup + tm_scope: text.html.basic ace_mode: html aliases: - xhtml @@ -1158,6 +1164,7 @@ Java Server Pages: JavaScript: type: programming + tm_scope: source.js ace_mode: javascript color: "#f1e05a" aliases: @@ -1569,6 +1576,7 @@ ObjDump: Objective-C: type: programming + tm_scope: source.objc color: "#438eff" aliases: - obj-c @@ -1669,6 +1677,7 @@ PAWN: PHP: type: programming + tm_scope: text.html.php ace_mode: php color: "#4F5D95" extensions: @@ -2089,6 +2098,7 @@ SQF: SQL: type: data + tm_scope: source.sql ace_mode: sql extensions: - .sql From 6e872c11b698d79439cd28dc320b7332558a40f3 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Mon, 13 Oct 2014 16:08:58 +0200 Subject: [PATCH 2/4] Pass `tm_scope` overrides --- lib/linguist/language.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/linguist/language.rb b/lib/linguist/language.rb index 3d803f88..666c75df 100644 --- a/lib/linguist/language.rb +++ b/lib/linguist/language.rb @@ -579,6 +579,7 @@ module Linguist :type => options['type'], :aliases => options['aliases'], :lexer => options['lexer'], + :tm_scope => options['tm_scope'], :ace_mode => options['ace_mode'], :wrap => options['wrap'], :group_name => options['group'], From 7dcc3b3edf2ce09be2b53335ca78c87a58168753 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Mon, 13 Oct 2014 16:14:33 +0200 Subject: [PATCH 3/4] Add `tm_scope` to the BlobHelper --- lib/linguist/blob_helper.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/linguist/blob_helper.rb b/lib/linguist/blob_helper.rb index 84aa2281..840ca75c 100644 --- a/lib/linguist/blob_helper.rb +++ b/lib/linguist/blob_helper.rb @@ -321,6 +321,11 @@ module Linguist language ? language.lexer : Pygments::Lexer.find_by_name('Text only') end + # Internal: Get the TextMate compatible scope for the blob + def tm_scope + language && language.tm_scope + end + # Public: Highlight syntax of blob # # options - A Hash of options (defaults to {}) From 9275e5240f33a024c445cc34de4da706ebda3d15 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Mon, 13 Oct 2014 17:45:08 +0200 Subject: [PATCH 4/4] Bump version --- lib/linguist/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/version.rb b/lib/linguist/version.rb index 9c3344f1..cdf9d960 100644 --- a/lib/linguist/version.rb +++ b/lib/linguist/version.rb @@ -1,3 +1,3 @@ module Linguist - VERSION = "3.2.1" + VERSION = "3.3.0.b1" end