mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Break modelines into two regular expressions
This makes them easier to read and maintains Ruby 1.9 compatibility
This commit is contained in:
@@ -1,19 +1,8 @@
|
||||
module Linguist
|
||||
module Strategy
|
||||
class Modeline
|
||||
Regex = /
|
||||
(?:
|
||||
(-\*- \s* (?:mode:)? \s*) | # $1: Emacs
|
||||
(\/\* \s* vim: \s* set \s* (?:ft|filetype)=) # $2: Vim
|
||||
)
|
||||
(\w+) # $3: language
|
||||
(?:
|
||||
(?(1) # If $1 matched...
|
||||
;?\s* -\*- | # then close Emacs syntax
|
||||
: \s* \*\/ # otherwise close Vim syntax
|
||||
)
|
||||
)
|
||||
/x
|
||||
EmacsModeline = /-\*-\s*(?:mode:)?\s*(\w+);?\s*-\*-/
|
||||
VimModeline = /\/\*\s*vim:\s*set\s*(?:ft|filetype)=(\w+):\s*\*\//
|
||||
|
||||
# Public: Detects language based on Vim and Emacs modelines
|
||||
#
|
||||
@@ -37,8 +26,8 @@ module Linguist
|
||||
#
|
||||
# Returns a String or nil
|
||||
def self.modeline(data)
|
||||
data.match(Regex)
|
||||
lang = $3
|
||||
match = data.match(EmacsModeline) || data.match(VimModeline)
|
||||
match[1] if match
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user