mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
dont save useless matches, thanks to pchaigno
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
module Linguist
|
module Linguist
|
||||||
module Strategy
|
module Strategy
|
||||||
class Modeline
|
class Modeline
|
||||||
EmacsModeline = /-\*-\s*((?!mode)[\w-]+\s*:\s*([\w+-]+)\s*;?\s*)*(mode\s*:)?\s*([\w+-]+)\s*(;\s*(?!mode)[\w-]+\s*:\s*([\w+-]+)\s*)*;?\s*-\*-/i
|
EmacsModeline = /-\*-\s*(?:(?!mode)[\w-]+\s*:\s*(?:[\w+-]+)\s*;?\s*)*(?:mode\s*:)?\s*([\w+-]+)\s*(?:;\s*(?!mode)[\w-]+\s*:\s*[\w+-]+\s*)*;?\s*-\*-/i
|
||||||
VimModeline = /\/\*\s*vim:\s*set\s*(?:ft|filetype)=(\w+):\s*\*\//i
|
VimModeline = /\/\*\s*vim:\s*set\s*(?:ft|filetype)=(\w+):\s*\*\//i
|
||||||
|
|
||||||
# Public: Detects language based on Vim and Emacs modelines
|
# Public: Detects language based on Vim and Emacs modelines
|
||||||
@@ -22,14 +22,9 @@ module Linguist
|
|||||||
#
|
#
|
||||||
# Returns a String or nil
|
# Returns a String or nil
|
||||||
def self.modeline(data)
|
def self.modeline(data)
|
||||||
match = data.match(EmacsModeline)
|
match = data.match(EmacsModeline) | data.match(VimModeline)
|
||||||
if match
|
|
||||||
match[4]
|
|
||||||
else
|
|
||||||
match = data.match(VimModeline)
|
|
||||||
match[1] if match
|
match[1] if match
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|||||||
Reference in New Issue
Block a user