<commit_before>" File:             autoload/cmake/targets.vim
" Description:      Handles the logic of interacting with targets.
" Author:           <NAME> <<EMAIL>>
" License:          MIT
" Website:          https://jalcine.github.io/cmake.vim
" Version:          0.2.0
" Last Modified:    2013-09-28 15:21:40 EDT

func! cmake#targets#build(target)
  echomsg "[cmake] Building target '" . a:target . "'..."
  return cmake#util#run_cmake("--build " . cmake#util#binary_dir() . 
        \ " --target " . a:target . " -- ", "", "")
endfunc!

func! cmake#targets#clean()
  " TODO: This requires a bit of magic.
endfunc!

func! cmake#targets#binary_dir(target)
  let l:dir = glob(cmake#util#binary_dir() . '**/' . a:target . '.dir', 1)
  if isdirectory(l:dir)
    return l:dir
  endif

  return 0
endfunc!

func! cmake#targets#source_dir(target)
  let l:build_dir  = cmake#targets#binary_dir(a:target)
  let l:source_dir = substitute(l:build_dir,  
        \ cmake#util#binary_dir(), cmake#util#source_dir(), "g")
  let l:source_dir = substitute(l:source_dir,
        \ "/CMakeFiles/" . a:target . ".dir/", "", "g")
  let l:source_dir = fnamemodify(l:source_dir, ':p')
  return l:source_dir
endfunc!

func! cmake#targets#list()
  let dirs = glob(cmake#util#binary_dir() . '**/*.dir', 0, 1)
  for dir in dirs
    let oldir = dir
    let dir = substitute(dir, '^' . cmake#util#binary_dir(), '', 'g')
    let dir = substitute(dir, '.dir$', '', 'g')
    let dir = split(dir, '/')[-1]
    let dirs[index(dirs,oldir)] = dir
  endfor
  return dirs
endfunc!

func! cmake#targets#exists(target)
  return index(cmake#targets#list(), a:target) != -1
endfunc

func! cmake#targets#corresponding_file(filepath)
  " A bit intensive of a method, searches each target if the provided file is
  " within. This value is cached.
  if exists("b:cmake_corresponding_target")
    return b:cmake_corresponding_target
  endif

  for target in cmake#targets#list()
    if exists("l:files")
      unlet l:files
    endif
    let files = cmake#targets#files(target)

    if !empty(files) && index(files, fnamemodify(bufname('%'), ':p')) != -1 
      let b:cmake_corresponding_target = l:target
      break
    else
      continue
    endif<commit_msg>For the provided path, not the current buffer.<commit_after>" File:             autoload/cmake/targets.vim
" Description:      Handles the logic of interacting with targets.
" Author:           <NAME> <<EMAIL>>
" License:          MIT
" Website:          https://jalcine.github.io/cmake.vim
" Version:          0.2.0
" Last Modified:    2013-09-28 15:21:40 EDT

func! cmake#targets#build(target)
  echomsg "[cmake] Building target '" . a:target . "'..."
  return cmake#util#run_cmake("--build " . cmake#util#binary_dir() . 
        \ " --target " . a:target . " -- ", "", "")
endfunc!

func! cmake#targets#clean()
  " TODO: This requires a bit of magic.
endfunc!

func! cmake#targets#binary_dir(target)
  let l:dir = glob(cmake#util#binary_dir() . '**/' . a:target . '.dir', 1)
  if isdirectory(l:dir)
    return l:dir
  endif

  return 0
endfunc!

func! cmake#targets#source_dir(target)
  let l:build_dir  = cmake#targets#binary_dir(a:target)
  let l:source_dir = substitute(l:build_dir,  
        \ cmake#util#binary_dir(), cmake#util#source_dir(), "g")
  let l:source_dir = substitute(l:source_dir,
        \ "/CMakeFiles/" . a:target . ".dir/", "", "g")
  let l:source_dir = fnamemodify(l:source_dir, ':p')
  return l:source_dir
endfunc!

func! cmake#targets#list()
  let dirs = glob(cmake#util#binary_dir() . '**/*.dir', 0, 1)
  for dir in dirs
    let oldir = dir
    let dir = substitute(dir, '^' . cmake#util#binary_dir(), '', 'g')
    let dir = substitute(dir, '.dir$', '', 'g')
    let dir = split(dir, '/')[-1]
    let dirs[index(dirs,oldir)] = dir
  endfor
  return dirs
endfunc!

func! cmake#targets#exists(target)
  return index(cmake#targets#list(), a:target) != -1
endfunc

func! cmake#targets#corresponding_file(filepath)
  " A bit intensive of a method, searches each target if the provided file is
  " within. This value is cached.
  if exists("b:cmake_corresponding_target")
    return b:cmake_corresponding_target
  endif

  for target in cmake#targets#list()
    if exists("l:files")
      unlet l:files
    endif
    let files = cmake#targets#files(target)

    if !empty(files) && index(files, fnamemodify(filepath, ':p')) != -1 
      let b:cmake_corresponding_target = l:target
      break
    else
      continue
    endif
{'fraction_non_alphanumeric': 0.15238308346386217, 'fraction_numerical': 0.01074065786529425, 'mean_word_length': 3.352482960077897, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '632806', 'n_tokens_mistral': 1675, 'n_tokens_neox': 1572, 'n_words': 372}