<commit_before># Converts Xcode's code snippets into Emacs yasnippets

import plistlib
import re
import os
import sys

from collections import namedtuple


def load_raw_xcode_snippets_plist():
  return plistlib.readPlist(
      "/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/SystemCodeSnippets.codesnippets")


def parse_raw_xcode_yasnippet(xcode_snippet):
  XcodeSnippet = namedtuple('XcodeSnippet',
                            'prefix title summary language content')
  return XcodeSnippet(xcode_snippet["IDECodeSnippetCompletionPrefix"],
                      xcode_snippet["IDECodeSnippetTitle"],
                      xcode_snippet["IDECodeSnippetSummary"],
                      xcode_snippet["IDECodeSnippetLanguage"],
                      xcode_snippet["IDECodeSnippetContents"])


def convert_xcode_content_to_yasnippet(content):
  pattern = re.compile(r'<#(.*?)#>', re.IGNORECASE)
  argument_number = [0]

  def replace_function(match):
    argument_number[0] += 1
    return "${%d:%s}" % (argument_number[0], match.groups()[0])

  return pattern.sub(replace_function, content)


def convert_xcode_to_yasnippet(xcode_snippet):
  yasnippet = ""
  yasnippet += "#name : %s\n" % xcode_snippet.title
  yasnippet += "#key : %s\n" % xcode_snippet.prefix
  yasnippet += "# --\n"
  yasnippet += convert_xcode_content_to_yasnippet(xcode_snippet.content)
  return yasnippet


def convert_to_yasnippets():
  raw_xcode_snippets = load_raw_xcode_snippets_plist()
  for raw_xcode_snippet in raw_xcode_snippets:
    xcode_snippet = parse_raw_xcode_yasnippet(raw_xcode_snippet)
    if not xcode_snippet.language or not xcode_snippet.prefix:
      continue
    language_to_emacs_mode = {
        "Xcode.SourceCodeLanguage.Swift": "swift-mode",
        "Xcode.SourceCodeLanguage.C": "c-mode",
        "Xcode.SourceCodeLanguage.C-Plus-Plus": "c++-mode",
        "Xcode.SourceCodeLanguage.Objective-C": "objc-mode"
    }
    if xcode_snippet.language not in language_to_emacs_mode.keys():<commit_msg>Renaming parse_raw_xcode_yasnippet to parse_raw_xcode_snippet<commit_after># Converts Xcode's code snippets into Emacs yasnippets

import plistlib
import re
import os
import sys

from collections import namedtuple


def load_raw_xcode_snippets_plist():
  return plistlib.readPlist(
      "/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/SystemCodeSnippets.codesnippets")


def parse_raw_xcode_snippet(xcode_snippet):
  XcodeSnippet = namedtuple('XcodeSnippet',
                            'prefix title summary language content')
  return XcodeSnippet(xcode_snippet["IDECodeSnippetCompletionPrefix"],
                      xcode_snippet["IDECodeSnippetTitle"],
                      xcode_snippet["IDECodeSnippetSummary"],
                      xcode_snippet["IDECodeSnippetLanguage"],
                      xcode_snippet["IDECodeSnippetContents"])


def convert_xcode_content_to_yasnippet(content):
  pattern = re.compile(r'<#(.*?)#>', re.IGNORECASE)
  argument_number = [0]

  def replace_function(match):
    argument_number[0] += 1
    return "${%d:%s}" % (argument_number[0], match.groups()[0])

  return pattern.sub(replace_function, content)


def convert_xcode_to_yasnippet(xcode_snippet):
  yasnippet = ""
  yasnippet += "#name : %s\n" % xcode_snippet.title
  yasnippet += "#key : %s\n" % xcode_snippet.prefix
  yasnippet += "# --\n"
  yasnippet += convert_xcode_content_to_yasnippet(xcode_snippet.content)
  return yasnippet


def convert_to_yasnippets():
  raw_xcode_snippets = load_raw_xcode_snippets_plist()
  for raw_xcode_snippet in raw_xcode_snippets:
    xcode_snippet = parse_raw_xcode_snippet(raw_xcode_snippet)
    if not xcode_snippet.language or not xcode_snippet.prefix:
      continue
    language_to_emacs_mode = {
        "Xcode.SourceCodeLanguage.Swift": "swift-mode",
        "Xcode.SourceCodeLanguage.C": "c-mode",
        "Xcode.SourceCodeLanguage.C-Plus-Plus": "c++-mode",
        "Xcode.SourceCodeLanguage.Objective-C": "objc-mode"
    }
    if xcode_snippet.language not in language_to_emacs_mode.keys():
{'fraction_non_alphanumeric': 0.10492923377257199, 'fraction_numerical': 0.002440214738897023, 'mean_word_length': 4.060493827160494, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4814365', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1392, 'n_words': 214}