code: def smart_guess_lexer(file_name, local_file):
      
      lexer = None
  
      text = get_file_head(file_name)
  
      lexer1, accuracy1 = guess_lexer_using_filename(local_file or file_name, text)
      lexer2, accuracy2 = guess_lexer_using_modeline(text)
  
      if lexer1:
          lexer = lexer1
      if (lexer2 and accuracy2 and
              (not accuracy1 or accuracy2 > accuracy1)):
          lexer = lexer2
  
      return lexer
docs: Guess Pygments lexer for a file.
  
      Looks for a vim modeline in file contents, then compares the accuracy
      of that lexer with a second guess. The second guess looks up all lexers
      matching the file name, then runs a text analysis for the best choice.