<commit_before>if exists("b:did_indent")
  finish
endif
let b:did_indent = 1
let s:cpo_save = &cpo
set cpo&vim

" {{{1 Options and common patterns
setlocal autoindent
setlocal indentexpr=LatexIndent()
setlocal indentkeys&
setlocal indentkeys+=[,(,{,),},],\&,=\\item

" Define some common patterns
let s:envs_lists = 'itemize\|description\|enumerate\|thebibliography'
let s:envs_noindent = 'document\|verbatim\|lstlisting'
let s:delimiters_open = '\(' . join([
        \ '{',
        \ '(',
        \ '\[',
        \ '\\{',
        \ '\\(',
        \ '\\\[',
        \ '\\\Cbegin\s*{.\{-}}',
        \ '\\\Cleft\s*\%([^\\]\|\\.\|\\\a*\)',
        \ '\\\cbigg\?\((\|\[\|\\{\)',
      \ ], '\|') . '\)'
let s:delimiters_close = '\(' . join([
        \ '}',
        \ ')',
        \ '\]',
        \ '\\}',
        \ '\\)',
        \ '\\\]',
        \ '\\\Cend\s*{.\{-}}',
        \ '\\\Cright\s*\%([^\\]\|\\.\|\\\a*\)',
        \ '\\\cbigg\?\()\|\]\|\\}\)',
      \ ], '\|') . '\)'
" }}}1

" {{{1 LatexIndent
function! LatexIndent()
  " Find a non-blank non-comment line above the current line
  let lnum = prevnonblank(v:lnum - 1)
  while lnum != 0 && getline(lnum) =~ '^\s*%'
    let lnum = prevnonblank(lnum - 1)
  endwhile

  " Zero indent for top of file
  if lnum == 0
    return 0
  endif

  " Get current and previous line, remove comments
  let cline = substitute(getline(v:lnum), '\\\@<!%.*', '', '')
  let pline = substitute(getline(lnum),   '\\\@<!%.*', '', '')

  " Check for verbatim modes
  if synIDattr(synID(v:lnum, indent(v:lnum), 1), "name") == "texZone"
    if empty(cline)
      return indent(lnum)
    else
      return indent(v:lnum)
    end
  endif

  " Align on ampersands
  if cline =~ '^\s*&' && pline =~ '\\\@<!&.*'
    return indent(v:lnum) + match(pline, '\\\@<!&') - stridx(cline, "&")
  endif

  " Find previous non-empty non-comment non-ampersand line
  while lnum != 0 && (match(pline, '\\\@<!&') != -1 || pline =~ '^\s*%')
    let lnum = prevnonblank(lnum - 1)
    let pline = getline(lnum)
  endwhile

  " Zero indent for top of file
  if lnum == 0
    return 0
  endif

  " Use previous indentation for comments
  if cline =~ '^\s*%'
    return indent(v:lnum)
  endif

  let ind = indent(lnum)

  " Add indent on begin environment
  if pline =~ '\\begin{.*}' && pline !~ s:envs_noindent
    let ind = ind + &sw

    " Add extra indent for list environments
    if pline =~ s:envs_lists
      let ind = ind + &sw
    endif
  endif

  " Subtract indent on end environment
  if cline =~ '\\end{.*}' && cline !~ s:envs_noindent
    let ind = ind - &sw

    " Subtract extra indent for list environments
    if cline =~ s:envs_lists
      let ind = ind - &sw
    endif
  endif

  " Indent opening and closing delimiters
  let ind += s:indent_braces(cline, pline) * &sw

  " Indent list items
  if pline =~ '^\s*\\\(bib\)\?item'
    let ind += &sw
  endif
  if cline =~ '^\s*\\\(bib\)\?item'
    let ind -= &sw
  endif

  return ind
endfunction
"}}}
<commit_msg>Added initial indent support for tikz commands<commit_after>if exists("b:did_indent")
  finish
endif
let b:did_indent = 1
let s:cpo_save = &cpo
let s:tikz_indented = 0
set cpo&vim

" {{{1 Options and common patterns
setlocal autoindent
setlocal indentexpr=LatexIndent()
setlocal indentkeys&
setlocal indentkeys+=[,(,{,),},],\&,=\\item

" Define some common patterns
let s:envs_lists = 'itemize\|description\|enumerate\|thebibliography'
let s:envs_noindent = 'document\|verbatim\|lstlisting'
let s:delimiters_open = '\(' . join([
        \ '{',
        \ '(',
        \ '\[',
        \ '\\{',
        \ '\\(',
        \ '\\\[',
        \ '\\\Cbegin\s*{.\{-}}',
        \ '\\\Cleft\s*\%([^\\]\|\\.\|\\\a*\)',
        \ '\\\cbigg\?\((\|\[\|\\{\)',
      \ ], '\|') . '\)'
let s:delimiters_close = '\(' . join([
        \ '}',
        \ ')',
        \ '\]',
        \ '\\}',
        \ '\\)',
        \ '\\\]',
        \ '\\\Cend\s*{.\{-}}',
        \ '\\\Cright\s*\%([^\\]\|\\.\|\\\a*\)',
        \ '\\\cbigg\?\()\|\]\|\\}\)',
      \ ], '\|') . '\)'
let s:tikz_commands = '\(' . join([
        \ 'draw',
        \ 'path',
        \ 'node',
        \ 'add\(legendentry\|plot\)',
      \ ], '\|') . '\)'
" }}}1

" {{{1 LatexIndent
function! LatexIndent()
  " Find a non-blank non-comment line above the current line
  let lnum = prevnonblank(v:lnum - 1)
  while lnum != 0 && getline(lnum) =~ '^\s*%'
    let lnum = prevnonblank(lnum - 1)
  endwhile

  " Zero indent for top of file
  if lnum == 0
    return 0
  endif

  " Get current and previous line, remove comments
  let cline = substitute(getline(v:lnum), '\\\@<!%.*', '', '')
  let pline = substitute(getline(lnum),   '\\\@<!%.*', '', '')

  " Check for verbatim modes
  if synIDattr(synID(v:lnum, indent(v:lnum), 1), "name") == "texZone"
    if empty(cline)
      return indent(lnum)
    else
      return indent(v:lnum)
    end
  endif

  " Align on ampersands
  if cline =~ '^\s*&' && pline =~ '\\\@<!&.*'
    return indent(v:lnum) + match(pline, '\\\@<!&') - stridx(cline, "&")
  endif

  " Find previous non-empty non-comment non-ampersand line
  while lnum != 0 && (match(pline, '\\\@<!&') != -1 || pline =~ '^\s*%')
    let lnum = prevnonblank(lnum - 1)
    let pline = getline(lnum)
  endwhile

  " Zero indent for top of file
  if lnum == 0
    return 0
  endif

  " Use previous indentation for comments
  if cline =~ '^\s*%'
    return indent(v:lnum)
  endif

  let ind = indent(lnum)

  " Add indent on begin environment
  if pline =~ '\\begin{.*}' && pline !~ s:envs_noindent
    let ind = ind + &sw

    " Add extra indent for list environments
    if pline =~ s:envs_lists
      let ind = ind + &sw
    endif
  endif

  " Subtract indent on end environment
  if cline =~ '\\end{.*}' && cline !~ s:envs_noindent
    let ind = ind - &sw

    " Subtract extra indent for list environments
    if cline =~ s:envs_lists
      let ind = ind - &sw
    endif
  endif

  " Indent opening and closing delimiters
  let ind += s:indent_braces(cline, pline) * &sw

  " Indent list items
  if pline =~ '^\s*\\\(bib\)\?item'
    let ind += &sw
  endif
  if cline =~ '^\s*\\\(bib\)\?item'
    let ind -= &sw
  endif

  " Indent tikz elements
  if pline =~ s:tikz_commands
    let ind += &sw
    let s:tikz_indented += 1
  endif
  if s:tikz_indented > 0 && pline =~ ';\s*$'
    let ind -= &sw
    let s:tikz_indented -= 1
  endif

  return ind
endfunction
"}}}

{'fraction_non_alphanumeric': 0.2121875, 'fraction_numerical': 0.0053125, 'mean_word_length': 2.1893373193821626, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 4, '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': '4842462', 'n_tokens_mistral': 2534, 'n_tokens_neox': 2392, 'n_words': 573}