set encoding=utf-8
scriptencoding utf-8

" " 単体動作テスト用 {{{1
" if &compatible
"   set nocompatible               " Be iMproved
" endif
" 
" if empty(glob('c:/tools/vim/vim90/autoload/plug.vim'))
"   silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
"        \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
"   autocmd VimEnter * PlugInstall | source $MYVIMRC
" endif
" 
" call plug#begin('c:/tools/vim/vim90/plugged')
" Plug 'vim-denops/denops.vim'
" Plug 'Shougo/ddu.vim'
" Plug 'Shougo/ddu-ui-ff'
" Plug 'Shougo/ddu-kind-file'
" Plug 'Shougo/ddu-filter-matcher_substring'
" Plug 'Shougo/ddu-source-file'
" 
" Plug 'Shougo/ddu-source-line'
" 
" call plug#end()
" 
" call ddu#custom#patch_global(#{
"      \   ui: 'ff',
"      \ })
" 
" call ddu#custom#patch_global(#{
"      \   uiParams: #{
"      \     ff: #{
"      \         startFilter: v:true,
"      \         split: 'floating',
"      \         prompt: '> ' ,
"      \         filterSplitDirection: 'floating',
"      \         filterFloatingPosition: 'top',
"      \         highlights: #{filterText: 'Statement', floating: "Normal", floatingBorder: "Special"},
"      \         floatingBorder: 'single',
"      \         autoAction: #{name: "preview"},
"      \         startAutoAction: v:true,
"      \         previewFloating: v:true,
"      \         floatingTitle: '',
"      \         previewSplit: 'vertical',
"      \     }
"      \   },
"      \ })
" 
" call ddu#custom#patch_global(#{
"    \   kindOptions: #{
"    \     file: #{
"    \       defaultAction: 'open',
"    \     },
"    \   }
"    \ })
" 
" call ddu#custom#patch_global(#{
"    \   sourceOptions: #{
"    \     _: #{
"    \       matchers: ['matcher_substring'],
"    \     },
"    \   }
"    \ })
" 
" autocmd FileType ddu-ff-filter call s:ddu_filter_my_settings()
" function! s:ddu_filter_my_settings() abort
"   nnoremap <buffer><silent> q
"  \ <Cmd>close<CR>
"   nnorema <buffer><silent> <CR>
"        \ <Cmd>call ddu#ui#ff#do_action('itemAction')<CR>
"   nnoremap <buffer><silent> <Space>
"        \ <Cmd>call ddu#ui#ff#do_action('toggleSelectItem')<CR>
"   nnoremap <buffer><silent> i
"        \ <Cmd>call ddu#ui#ff#do_action('openFilterWindow')<CR>
"   nnoremap <buffer><silent> q
"        \<Cmd>call ddu#ui#ff#do_action('quit')<CR>
" endfunction
" 
" " }}}1

" -------------------------------------------------------- ローカル設定
if has('vim_starting')
	set nocompatible
endif

let g:python3_host_prog = 'C:\Python311\python.exe'

" ----- settings.
if has('mac')
else
  source C:\tools\vim\vim90\rc\env.vim
  source C:\tools\vim\vim90\rc\plugin.vim
  " changelog
  autocmd FileType changelog set tabstop=2 noexpandtab formatoptions=q
endif

set renderoptions=type:directx

" denops
let g:denops#debug = 0
let g:denops_disable_version_check = v:true
let g:denops_server_addr = '127.0.0.1:32123'

" outline
function! s:textobject_outline(...) abort
  let from_parent = index(a:000, 'from_parent') >= 0
  let with_blank = index(a:000, 'with_blank') >= 0

  " get current line and indent
  let from = line('.')
  let indent = indent(from)
  if indent < 0
    return
  endif
  let to = from

  " search first parent
  if from_parent && from > 1 && indent > 0
    let lnum = from - 1
    while indent <= indent(lnum) || (with_blank && getline(lnum) =~ '^\s*$')
      let lnum -= 1
    endwhile

    " update current line and indent
    let from = lnum
    call cursor(from, 0)
    let indent = indent(from)
  endif

  " search last child
  let lnum = to + 1
  while indent < indent(lnum) || (with_blank && getline(lnum) =~ '^\s*$')
    let to = lnum
    let lnum += 1
  endwhile

  " exit visual mode
  let m = mode()
  if m ==# 'v' || m ==# 'V' || m == "\<C-v>"
    execute 'normal! ' .. m
  endif

  " select with line-visual mode
  normal! V
  call cursor(to, 0)


  normal! o
endfunction
command! -nargs=* TextobjectOutline call s:textobject_outline(<f-args>)

xnoremap io <Cmd>TextobjectOutline<CR>
xnoremap ao <Cmd>TextobjectOutline from_parent<CR>
xnoremap iO <Cmd>TextobjectOutline with_blank<CR>
xnoremap aO <Cmd>TextobjectOutline from_parent with_blank<CR>
onoremap io <Cmd>TextobjectOutline<CR>
onoremap ao <Cmd>TextobjectOutline from_parent<CR>
onoremap iO <Cmd>TextobjectOutline with_blank<CR>
onoremap aO <Cmd>TextobjectOutline from_parent with_blank<CR>
onoremap i<space> iW'

function! s:ReplaceJapaneseComma()
	call setline(line('.'), substitute(getline('.'), "@", '、', 'g'))
	call setline(line('.'), substitute(getline('.'), " てん ", '、', 'g'))
	call setline(line('.'), substitute(getline('.'), " 楽天 ", '。', 'g'))
	call setline(line('.'), substitute(getline('.'), "楽天 ", '。', 'g'))
	call setline(line('.'), substitute(getline('.'), "&", '。', 'g'))
	call setline(line('.'), substitute(getline('.'), "句点", '。', 'g'))
	call setline(line('.'), substitute(getline('.'), "点", '。', 'g'))
	call setline(line('.'), substitute(getline('.'), "ケーピーアイ", 'KPI', 'g'))
	call setline(line('.'), substitute(getline('.'), "スペース", ' ', 'g'))
	call setline(line('.'),substitute(getline('.')," ",'','g'))
	call setline(line('.'), substitute(getline('.'), "+", '+ ', 'g'))
	call setline(line('.'), substitute(getline('.'), "バッハ", 'バッファ', 'g'))
	return ''
endfunction
command! -range ReplaceJapaneseComma call s:ReplaceJapaneseComma() 
nnoremap <silent> <F4> :ReplaceJapaneseComma<CR>
inoremap <silent> <F4> <Cmd>ReplaceJapaneseComma<CR>

" previm
let g:previm_open_cmd = 'C:\\Users\\taket\\AppData\\Local\\Mozilla\ Firefox\\firefox.exe'

call ai_review#config({ 'chat_gpt': { 'model': 'gpt-4-1106-preview' } })

" chatgpt
let g:chat_gpt_max_tokens=2000
let g:chat_gpt_model='gpt-4-1106-preview'
let g:chat_gpt_session_mode=1
let g:chat_gpt_temperature = 0.7
let g:chat_gpt_lang = 'Japanese'

" perplexity
let g:perplexity_token = 'ok'
let g:perplexity_model = 'aaa'

"  END