class Linguist::Strategy::Modeline
Constants
- EMACS_MODELINE
- MODELINES
- SEARCH_SCOPE
Scope of the search for modelines Number of lines to check at the beginning and at the end of the file
- VIM_MODELINE
Public Class Methods
call(blob, _ = nil)
click to toggle source
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.
# File lib/linguist/strategy/modeline.rb, line 111 def self.call(blob, _ = nil) header = blob.first_lines(SEARCH_SCOPE).join("\n") footer = blob.last_lines(SEARCH_SCOPE).join("\n") Array(Language.find_by_alias(modeline(header + footer))) end
modeline(data)
click to toggle source
Public: Get the modeline from the first n-lines of the file
Returns a String or nil
# File lib/linguist/strategy/modeline.rb, line 120 def self.modeline(data) match = MODELINES.map { |regex| data.match(regex) }.reject(&:nil?).first match[1] if match end