mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-12-08 20:38:47 +00:00
Syntax tweak
This commit is contained in:
@@ -23,7 +23,8 @@ 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* (?:mode:)? \s*) | # $1: Emacs
|
||||||
(\/\* \s* vim: \s* set \s* (?:ft|filetype)=) # $2: Vim
|
(\/\* \s* vim: \s* set \s* (?:ft|filetype)=) # $2: Vim
|
||||||
)
|
)
|
||||||
@@ -33,9 +34,10 @@ module Linguist
|
|||||||
;?\s* -\*- | # then close Emacs syntax
|
;?\s* -\*- | # then close Emacs syntax
|
||||||
: \s* \*\/ # otherwise close Vim 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
|
||||||
|
|||||||
Reference in New Issue
Block a user