class Linguist::Strategy::Modeline

def self.call(blob, _ = nil)

that matches a Language name or alias. Returns an empty array if no match.
Returns an Array with one Language if the blob has a Vim or Emacs modeline

Modeline.call(FileBlob.new("path/to/file"))

Examples

blob - An object that quacks like a blob.

Public: Detects language based on Vim and Emacs modelines
def self.call(blob, _ = nil)
  return [] if blob.symlink?
  header = blob.first_lines(SEARCH_SCOPE).join("\n")
  # Return early for Vimball files as their modeline will not reflect their filetype.
  return [] if header.include?("UseVimball")
  footer = blob.last_lines(SEARCH_SCOPE).join("\n")
  Array(Language.find_by_alias(modeline(header + footer)))
end

def self.modeline(data)

Returns a String or nil

Public: Get the modeline from the first n-lines of the file
def self.modeline(data)
  match = MODELINES.map { |regex| data.match(regex) }.reject(&:nil?).first
  match[1] if match
end