Syntax tweak

This commit is contained in:
Arfon Smith
2015-01-28 16:52:26 -06:00
parent 96154627d3
commit bf6bd246fd

View File

@@ -23,19 +23,21 @@ module Linguist
# #
# Returns a String or nil # Returns a String or nil
def self.modeline(data) def self.modeline(data)
pattern = %q{(?: regex = <<-EOF
(-\*- \s* (?:mode:)? \s*) | # $1: Emacs /(?:
(\/\* \s* vim: \s* set \s* (?:ft|filetype)=) # $2: Vim (-\*- \s* (?:mode:)? \s*) | # $1: Emacs
) (\/\* \s* vim: \s* set \s* (?:ft|filetype)=) # $2: Vim
(\w+) # $3: language )
(?: (\w+) # $3: language
(?(1) # If $1 matched... (?:
;?\s* -\*- | # then close Emacs syntax (?(1) # If $1 matched...
: \s* \*\/ # otherwise close Vim syntax ;?\s* -\*- | # then close Emacs syntax
) : \s* \*\/ # otherwise close Vim syntax
)} )
)/x
EOF
data.lines.first(5).any? { |l| l.match(/#{pattern}/x) } data.lines.first(5).any? { |l| l.match(regex) }
lang = $3 lang = $3
end end
end end