docs: def custom_pygments_guess_lexer_for_filename(_fn, _text, **options):
      """Overwrite pygments.lexers.guess_lexer_for_filename to customize the
      priority of different lexers based on popularity of languages."""
  
      fn = basename(_fn)
      primary = {}
      matching_lexers = set()
      for lexer in _iter_lexerclasses():
          for filename in lexer.filenames:
              if _fn_matches(fn, filename):
                  matching_lexers.add(lexer)
                  primary[lexer] = True
          for filename in lexer.alias_filenames:
              if _fn_matches(fn, filename):
                  matching_lexers.add(lexer)
                  primary[lexer] = False
      if not matching_lexers:
          raise ClassNotFound('no lexer for filename %r found' % fn)
      if len(matching_lexers) == 1:
          return matching_lexers.pop()(**options)
      result = []
      for lexer in matching_lexers:
          rv = lexer.analyse_text(_text)
          if rv == 1.0:
              return lexer(**options)
          result.append(customize_lexer_priority(_fn, rv, lexer))
  
      matlab = list(filter(lambda x: x[2].name.lower() == 'matlab', result))
      if len(matlab) > 0:
          objc = list(filter(lambda x: x[2].name.lower() == 'objective-c', result))
          if objc and objc[0][0] == matlab[0][0]:
              raise SkipHeartbeat('Skipping because not enough language accuracy.')
  
      def type_sort(t):
          # sort by:
          # - analyse score
          # - is primary filename pattern?
          # - priority
          # - last resort: class name
          return (t[0], primary[t[2]], t[1], t[2].__name__)
      result.sort(key=type_sort)
  
      return result[-1][2](**options)