<commit_before>""""""""""""""""""""""""""""""""""""""""
" @author: <NAME> <<EMAIL>>
" @date:   2013-09-26 00:31:53 EDT
"
" Utility methods to manipulate CMake.
""""""""""""""""""""""""""""""""""""""""

func! cmake#util#binary_dir()
  " If we found it already, don't waste effort.
  if exists("g:cmake_binary_dir")
    return g:cmake_binary_dir
  endif

  " Check in the currenty directory as well.
  let l:directories = g:cmake_build_directories + [ getcwd() ]

  for directory in l:directories
    " TODO: Make paths absolute.
    let l:proposed_cmake_file = findfile(directory . "/CMakeCache.txt", ".;")

    if filereadable(l:proposed_cmake_file)
      " If we found it, drop off that CMakeCache.txt reference and cache the
      " value.
      let l:proposed_dir = substitute(l:proposed_cmake_file, "/CMakeCache.txt", "", "")
      return l:proposed_dir
    endif
  endfor

  return 0
endfunc!

" TODO; Resolve path to absolute-ness.
func! cmake#util#source_dir()
  if cmake#util#binary_dir() == 0
    return ""
  endif

  return cmake#util#read_from_cache("Project_SOURCE_DIR")
endfunc!

func! cmake#util#cmake_cache_file_path()
  let l:dir = cmake#util#binary_dir()
  if isdirectory(l:dir)
    return l:dir . "/CMakeCache.txt"
  endif

  return ""
endfunc!

func! cmake#util#read_from_cache(property)
  let l:cmake_cache_file = cmake#util#cmake_cache_file_path()
  let l:property_width = strlen(a:property) + 2

  " If we can't find the cache file, then there's no point in trying to read
  " it.
  if !filereadable(cmake#util#cmake_cache_file_path())
    return ""
  endif

  " First, grep out this property.
  let l:property_line = system("grep -E \"^" . a:property . ":\" " . l:cmake_cache_file)
  if empty(l:property_line)
    return 0
  else
    if 

  " Chop down the response to size.
  let l:property_meta_value = system("echo '" . l:property_line . "' | cut -b " . l:property_width . "-")

  " Split it in half to get the resulting value and its type.
  let l:property_fields = split(l:property_meta_value, "=", 1)
  let l:property_fields[1] = substitute(l:property_fields[1], "\n", "", "")
  let l:property_fields[1] = substitute(l:property_fields[1], "\n", "", "")

  return l:property_fields
endfunc!

func! cmake#util#write_to_cache(property,value)<commit_msg>Fixed a typo.<commit_after>""""""""""""""""""""""""""""""""""""""""
" @author: <NAME> <<EMAIL>>
" @date:   2013-09-26 00:31:53 EDT
"
" Utility methods to manipulate CMake.
""""""""""""""""""""""""""""""""""""""""

func! cmake#util#binary_dir()
  " If we found it already, don't waste effort.
  if exists("g:cmake_binary_dir")
    return g:cmake_binary_dir
  endif

  " Check in the currenty directory as well.
  let l:directories = g:cmake_build_directories + [ getcwd() ]

  for directory in l:directories
    " TODO: Make paths absolute.
    let l:proposed_cmake_file = findfile(directory . "/CMakeCache.txt", ".;")

    if filereadable(l:proposed_cmake_file)
      " If we found it, drop off that CMakeCache.txt reference and cache the
      " value.
      let l:proposed_dir = substitute(l:proposed_cmake_file, "/CMakeCache.txt", "", "")
      return l:proposed_dir
    endif
  endfor

  return 0
endfunc!

" TODO; Resolve path to absolute-ness.
func! cmake#util#source_dir()
  if cmake#util#binary_dir() == 0
    return ""
  endif

  return cmake#util#read_from_cache("Project_SOURCE_DIR")
endfunc!

func! cmake#util#cmake_cache_file_path()
  let l:dir = cmake#util#binary_dir()
  if isdirectory(l:dir)
    return l:dir . "/CMakeCache.txt"
  endif

  return ""
endfunc!

func! cmake#util#read_from_cache(property)
  let l:cmake_cache_file = cmake#util#cmake_cache_file_path()
  let l:property_width = strlen(a:property) + 2

  " If we can't find the cache file, then there's no point in trying to read
  " it.
  if !filereadable(cmake#util#cmake_cache_file_path())
    return ""
  endif

  " First, grep out this property.
  let l:property_line = system("grep -E \"^" . a:property . ":\" " . l:cmake_cache_file)
  if empty(l:property_line)
    return 0
  endif

  " Chop down the response to size.
  let l:property_meta_value = system("echo '" . l:property_line . "' | cut -b " . l:property_width . "-")

  " Split it in half to get the resulting value and its type.
  let l:property_fields = split(l:property_meta_value, "=", 1)
  let l:property_fields[1] = substitute(l:property_fields[1], "\n", "", "")
  let l:property_fields[1] = substitute(l:property_fields[1], "\n", "", "")

  return l:property_fields
endfunc!

func! cmake#util#write_to_cache(property,value)
{'fraction_non_alphanumeric': 0.15710832784003514, 'fraction_numerical': 0.01010766864425401, 'mean_word_length': 4.232183908045977, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 9, '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': '625142', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1635, 'n_words': 386}