Sha256: ad8f96169c1c4fe139c8e20e6235aa0bf2a24ed4a71fd12d5ec86c372bb1b059
Contents?: true
Size: 1.02 KB
Versions: 1
Compression:
Stored size: 1.02 KB
Contents
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 = /\/\*\s*vim:\s*set\s*(?:ft|filetype)=(\w+):\s*\*\//i # Public: Detects language based on Vim and Emacs modelines # # blob - An object that quacks like a blob. # # Examples # # Modeline.call(FileBlob.new("path/to/file")) # # Returns an Array with one Language if the blob has a Vim or Emacs modeline # that matches a Language name or alias. Returns an empty array if no match. def self.call(blob, _ = nil) Array(Language.find_by_alias(modeline(blob.data))) end # Public: Get the modeline from the first n-lines of the file # # Returns a String or nil def self.modeline(data) match = data.match(EmacsModeline) || data.match(VimModeline) match[1] if match end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
github-linguist-4.5.4 | lib/linguist/strategy/modeline.rb |