Make regex for vim modeline more lenient

This change allows the filetype/language to be retrieved from more complex vim modelines. The current regex strictly allows a set line which contains only the filetype/ft parameter and nothing else
This commit is contained in:
Ammar Askar
2015-08-10 00:38:24 -05:00
parent ffcc970140
commit 4650368bc2
4 changed files with 11 additions and 1 deletions

View File

@@ -2,7 +2,7 @@ module Linguist
module Strategy
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
VimModeline = /vim:\s*set\s*(?:ft|filetype)=(\w+):/i
VimModeline = /vim:\s*set.*\s(?:ft|filetype)=(\w+)\s?.*:/i
# Public: Detects language based on Vim and Emacs modelines
#