<commit_before>if exists("g:loaded_switch") || &cp
  finish
endif

let g:loaded_switch = '0.0.1' " version number
let s:keepcpo = &cpo
set cpo&vim

let g:switch_definitions =
      \ [
      \   ['&&', '||'],
      \   ['true', 'false'],
      \ ]

autocmd FileType eruby let b:switch_definitions =
      \ [
      \   {
      \     '<% if true or (\(.*\)) %>':          '<% if false and (\1) %>',
      \     '<% if false and (\(.*\)) %>':        '<% if \1 %>',
      \     '<% if \%(true\|false\)\@!\(.*\) %>': '<% if true or (\1) %>',
      \   },
      \   {
      \     '<%= \(.*\) %>':    '<% \1 %>',
      \     '<% \(.*\) -\?%>':  '<%# \1 %>',
      \     '<%# \(.*\) %>':    '<%=raw \1 %>',
      \     '<%=raw \(.*\) %>': '<%= \1 %>',
      \   },
      \   {
      \     ':\(\k\+\)\s\+=>': '\1:',
      \     '\<\(\k\+\):':     ':\1 =>',
      \   },
      \ ]

autocmd FileType php let b:switch_definitions =
      \ [
      \   { '<?php echo \(.*\) ?>': '<?php \1 ?>' },
      \   { '<?php \(.*\) ?>':      '<?php echo \1 ?>' },
      \ ]

autocmd FileType ruby let b:switch_definitions =
      \ [
      \   {
      \     ':\(\k\+\)\s\+=>': '\1:',
      \     '\<\(\k\+\):':     ':\1 =>',
      \   },
      \   {
      \     'if true or (\(.*\))':         'if false and (\1)',
      \     'if false and (\(.*\))':       'if \1',
      \     'if \%(true\|false\)\@!\(.*\)': 'if true or (\1)',
      \   },
      \   ['should ', 'should_not '],
      \   {
      \     '\.\%(tap\)\@!\(\k\+\)':        '.tap { |o| puts o.inspect }.\1',
      \     '\.tap { |o| puts o.inspect }': '',
      \   }
      \ ]

autocmd FileType cpp let b:switch_definitions =
      \ [
      \   {
      \     '\(\k\+\)\.': '\1->',
      \     '\(\k\+\)->': '\1.',
      \   }
      \ ]

autocmd FileType coffee let b:switch_definitions =
      \ [
      \   {
      \     '^\(.*\)->': '\1=>',
      \     '^\(.*\)=>': '\1->',
      \   }
      \ ]

command! Switch call s:Switch()
function! s:Switch()
  let definitions = []
  let definitions = extend(definitions, g:switch_definitions)

  if exists('g:switch_custom_definitions')
    call extend(definitions, g:switch_custom_definitions)
  endif

  if exists('b:switch_definitions')
    call extend(definitions, b:switch_definitions)
  endif

  if exists('b:switch_custom_definitions')
    call extend(definitions, b:switch_custom_definitions)
  endif

  call switch#Switch(definitions)
endfunction

let &cpo = s:keepcpo
unlet s:keepcpo<commit_msg>Extract builtin switch definitions<commit_after>if exists("g:loaded_switch") || &cp
  finish
endif

let g:loaded_switch = '0.0.1' " version number
let s:keepcpo = &cpo
set cpo&vim

let g:switch_builtins =
      \ {
      \   'ruby_hash_style': {
      \     ':\(\k\+\)\s\+=>': '\1:',
      \     '\<\(\k\+\):':     ':\1 =>',
      \   },
      \   'ruby_if_clause': {
      \     'if true or (\(.*\))':          'if false and (\1)',
      \     'if false and (\(.*\))':        'if \1',
      \     'if \%(true\|false\)\@!\(.*\)': 'if true or (\1)',
      \   },
      \   'ruby_tap': {
      \     '\.\%(tap\)\@!\(\k\+\)':        '.tap { |o| puts o.inspect }.\1',
      \     '\.tap { |o| puts o.inspect }': '',
      \   },
      \   'rspec_should': ['should ', 'should_not '],
      \   'eruby_if_clause': {
      \     '<% if true or (\(.*\)) %>':          '<% if false and (\1) %>',
      \     '<% if false and (\(.*\)) %>':        '<% if \1 %>',
      \     '<% if \%(true\|false\)\@!\(.*\) %>': '<% if true or (\1) %>',
      \   },
      \   'eruby_tag_type': {
      \     '<%= \(.*\) %>':    '<% \1 %>',
      \     '<% \(.*\) -\?%>':  '<%# \1 %>',
      \     '<%# \(.*\) %>':    '<%=raw \1 %>',
      \     '<%=raw \(.*\) %>': '<%= \1 %>',
      \   },
      \   'php_echo': {
      \     '<?php echo \(.\{-}\) ?>':        '<?php \1 ?>',
      \     '<?php \%(echo\)\@!\(.\{-}\) ?>': '<?php echo \1 ?>',
      \   },
      \   'cpp_pointer': {
      \     '\(\k\+\)\.': '\1->',
      \     '\(\k\+\)->': '\1.',
      \   },
      \   'coffee_arrow': {
      \     '^\(.*\)->': '\1=>',
      \     '^\(.*\)=>': '\1->',
      \   },
      \ }

let g:switch_definitions =
      \ [
      \   ['&&', '||'],
      \   ['true', 'false'],
      \ ]

autocmd FileType eruby let b:switch_definitions =
      \ [
      \   g:switch_builtins.eruby_if_clause,
      \   g:switch_builtins.eruby_tag_type,
      \   g:switch_builtins.ruby_hash_style,
      \ ]

autocmd FileType php let b:switch_definitions =
      \ [
      \   g:switch_builtins.php_echo,
      \ ]

autocmd FileType ruby let b:switch_definitions =
      \ [
      \   g:switch_builtins.ruby_hash_style,
      \   g:switch_builtins.ruby_if_clause,
      \   g:switch_builtins.rspec_should,
      \   g:switch_builtins.ruby_tap,
      \ ]

autocmd FileType cpp let b:switch_definitions =
      \ [
      \   g:switch_builtins.cpp_pointer,
      \ ]

autocmd FileType coffee let b:switch_definitions =
      \ [
      \   g:switch_builtins.coffee_arrow,
      \ ]

command! Switch call s:Switch()
function! s:Switch()
  let definitions = []
  let definitions = extend(definitions, g:switch_definitions)

  if exists('g:switch_custom_definitions')
    call extend(definitions, g:switch_custom_definitions)
  endif

  if exists('b:switch_definitions')
    call extend(definitions, b:switch_definitions)
  endif

  if exists('b:switch_custom_definitions')
    call extend(definitions, b:switch_custom_definitions)
  endif

  call switch#Switch(definitions)
endfunction

let &cpo = s:keepcpo
unlet s:keepcpo
{'fraction_non_alphanumeric': 0.2495053067098399, 'fraction_numerical': 0.008274869580859866, 'mean_word_length': 1.5504587155963303, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 57, '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': '2594205', 'n_tokens_mistral': 2194, 'n_tokens_neox': 2125, 'n_words': 336}