refactoring
This commit is contained in:
		
							parent
							
								
									2da8339c12
								
							
						
					
					
						commit
						0b5b97042a
					
				| 
						 | 
					@ -5,5 +5,5 @@ set expandtab
 | 
				
			||||||
set shiftround
 | 
					set shiftround
 | 
				
			||||||
set autoindent
 | 
					set autoindent
 | 
				
			||||||
 | 
					
 | 
				
			||||||
nnoremap <silent> <buffer> <F5> :call SaveAndExecutePython()<CR> 
 | 
					nnoremap <silent> <buffer> <F5> :call SaveAndExecute('python')<CR> 
 | 
				
			||||||
" vnoremap <silent> <buffer> <F5> :<C-u>call SaveAndExecutePython()<CR> 
 | 
					" vnoremap <silent> <buffer> <F5> :<C-u>call SaveAndExecutePython()<CR> 
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,30 +1,34 @@
 | 
				
			||||||
" TODO better name
 | 
					" TODO better name
 | 
				
			||||||
function! GetStatusFrag(condition, colorname, conditionprefix, text) abort "{{{
 | 
					function! GetStatusFrag(condition, colorname, conditionprefix, text) abort 
 | 
				
			||||||
  let l:frag='%#' . a:colorname . '#'
 | 
					  let l:frag='%#' . a:colorname . '#'"{{{
 | 
				
			||||||
  let l:frag.=a:conditionprefix
 | 
					  let l:frag.=a:conditionprefix
 | 
				
			||||||
  let l:frag.='%{(' . a:condition . ")?'" . a:text . "':''}"
 | 
					  let l:frag.='%{(' . a:condition . ")?'" . a:text . "':''}"
 | 
				
			||||||
  return l:frag
 | 
					  return l:frag
 | 
				
			||||||
endfunction"}}}
 | 
					endfunction
 | 
				
			||||||
 | 
					"}}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function! CheckLineEnding() abort "{{{
 | 
					function! CheckLineEnding() abort 
 | 
				
			||||||
  :normal $
 | 
					  :normal $"{{{
 | 
				
			||||||
  if getline('.')[col('.')-1] == ';' || getline('.')[col('.')-1] == ','
 | 
					  if getline('.')[col('.')-1] == ';' || getline('.')[col('.')-1] == ','
 | 
				
			||||||
    :startinsert
 | 
					    :startinsert
 | 
				
			||||||
  else
 | 
					  else
 | 
				
			||||||
    :startinsert!
 | 
					    :startinsert!
 | 
				
			||||||
  endif
 | 
					  endif
 | 
				
			||||||
endfunction"}}}
 | 
					endfunction
 | 
				
			||||||
 | 
					"}}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
" get name of syntax item
 | 
					" get name of syntax item
 | 
				
			||||||
function! SyntaxItem() abort "{{{
 | 
					function! SyntaxItem() abort 
 | 
				
			||||||
 | 
					"{{{
 | 
				
			||||||
  return synIDattr(synID(line('.'),col('.'),1),'name') . ' -> ' . synIDattr(synIDtrans(synID(line('.'),col('.'),1)), 'name' )
 | 
					  return synIDattr(synID(line('.'),col('.'),1),'name') . ' -> ' . synIDattr(synIDtrans(synID(line('.'),col('.'),1)), 'name' )
 | 
				
			||||||
endfunction
 | 
					endfunction
 | 
				
			||||||
nnoremap <space>p :echom SyntaxItem()<CR>"}}}
 | 
					nnoremap <space>p :echom SyntaxItem()<CR>
 | 
				
			||||||
 | 
					"}}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
" devdocs DD
 | 
					" devdocs DD
 | 
				
			||||||
" https://gist.github.com/romainl/8d3b73428b4366f75a19be2dad2f0987#file-devdocs-vim
 | 
					" https://gist.github.com/romainl/8d3b73428b4366f75a19be2dad2f0987#file-devdocs-vim
 | 
				
			||||||
function! s:Get_env() abort "{{{
 | 
					function! s:Get_env() abort 
 | 
				
			||||||
    if has('win64') || has('win32') || has('win16')
 | 
					    if has('win64') || has('win32') || has('win16')"{{{
 | 
				
			||||||
        return 'WINDOWS'
 | 
					        return 'WINDOWS'
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        return toupper(substitute(system('uname'), '\n', '', ''))
 | 
					        return toupper(substitute(system('uname'), '\n', '', ''))
 | 
				
			||||||
| 
						 | 
					@ -42,8 +46,8 @@ command! -nargs=* DD silent! call system(len(split(<q-args>, ' ')) == 0 ?
 | 
				
			||||||
"}}}
 | 
					"}}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
" use ranger as file manager
 | 
					" use ranger as file manager
 | 
				
			||||||
if !exists('*RangerExplorer') "{{{
 | 
					if !exists('*RangerExplorer') 
 | 
				
			||||||
	function RangerExplorer() abort
 | 
						function RangerExplorer() abort"{{{
 | 
				
			||||||
			exec 'silent !ranger --choosefile=/tmp/vim_ranger_current_file ' . expand('%:p:h')
 | 
								exec 'silent !ranger --choosefile=/tmp/vim_ranger_current_file ' . expand('%:p:h')
 | 
				
			||||||
			if filereadable('/tmp/vim_ranger_current_file')
 | 
								if filereadable('/tmp/vim_ranger_current_file')
 | 
				
			||||||
					exec 'edit ' . system('cat /tmp/vim_ranger_current_file')
 | 
										exec 'edit ' . system('cat /tmp/vim_ranger_current_file')
 | 
				
			||||||
| 
						 | 
					@ -52,26 +56,26 @@ if !exists('*RangerExplorer') "{{{
 | 
				
			||||||
			redraw!
 | 
								redraw!
 | 
				
			||||||
	endfun
 | 
						endfun
 | 
				
			||||||
	map <space>ra :call RangerExplorer()<CR>
 | 
						map <space>ra :call RangerExplorer()<CR>
 | 
				
			||||||
endif"}}}
 | 
					endif
 | 
				
			||||||
 | 
					"}}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function! SetColorColumn()"{{{
 | 
					function! SetColorColumn() abort
 | 
				
			||||||
  if &buftype == ''
 | 
					  if &buftype == ''"{{{
 | 
				
			||||||
    setlocal colorcolumn=80
 | 
					    setlocal colorcolumn=80
 | 
				
			||||||
  endif
 | 
					  endif
 | 
				
			||||||
endfunction
 | 
					endfunction
 | 
				
			||||||
"}}}
 | 
					"}}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function! GetLinterStatus(key) abort "{{{
 | 
					function! GetLinterStatus(key) abort 
 | 
				
			||||||
  let l:linter = ale#statusline#Count(bufnr(''))
 | 
					  let l:linter = ale#statusline#Count(bufnr(''))"{{{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return l:linter[a:key]
 | 
					  return l:linter[a:key]
 | 
				
			||||||
endfunction
 | 
					endfunction
 | 
				
			||||||
 | 
					 | 
				
			||||||
"}}}
 | 
					"}}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
" old linter status function
 | 
					" old linter status function
 | 
				
			||||||
function! LinterStatus() abort "{{{
 | 
					function! LinterStatus() abort 
 | 
				
			||||||
  let l:counts = ale#statusline#Count(bufnr(''))
 | 
					  let l:counts = ale#statusline#Count(bufnr(''))"{{{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let l:all_errors = l:counts.error + l:counts.style_error
 | 
					  let l:all_errors = l:counts.error + l:counts.style_error
 | 
				
			||||||
  let l:all_non_errors = l:counts.total - l:all_errors
 | 
					  let l:all_non_errors = l:counts.total - l:all_errors
 | 
				
			||||||
| 
						 | 
					@ -81,11 +85,7 @@ endfunction
 | 
				
			||||||
"}}}
 | 
					"}}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
" Shell command
 | 
					" Shell command
 | 
				
			||||||
" based on
 | 
					 | 
				
			||||||
" http://vim.wikia.com/wiki/VimTip1599
 | 
					" http://vim.wikia.com/wiki/VimTip1599
 | 
				
			||||||
command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand(<q-args>)
 | 
					 | 
				
			||||||
let g:shell_scratch_buffer_nr = -1
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function! s:RunShellCommand(cmdline) abort
 | 
					function! s:RunShellCommand(cmdline) abort
 | 
				
			||||||
"{{{
 | 
					"{{{
 | 
				
			||||||
  let l:expanded_cmdline = a:cmdline 
 | 
					  let l:expanded_cmdline = a:cmdline 
 | 
				
			||||||
| 
						 | 
					@ -136,11 +136,16 @@ function! s:RunShellCommand(cmdline) abort
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  wincmd p
 | 
					  wincmd p
 | 
				
			||||||
endfunction
 | 
					endfunction
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand(<q-args>)
 | 
				
			||||||
 | 
					let g:shell_scratch_buffer_nr = -1
 | 
				
			||||||
"}}}
 | 
					"}}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
" https://stackoverflow.com/a/40195855
 | 
					" https://stackoverflow.com/a/40195855
 | 
				
			||||||
function! SaveAndExecutePython()
 | 
					" ex_command: command to run to execute file
 | 
				
			||||||
    " SOURCE [reusable window]: https://github.com/fatih/vim-go/blob/master/autoload/go/ui.vim
 | 
					function! SaveAndExecute(ex_command) abort
 | 
				
			||||||
 | 
					    " SOURCE [reusable window]: https://github.com/fatih/vim-go/blob/master/autoload/go/ui.vim{{{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    " save and reload current file
 | 
					    " save and reload current file
 | 
				
			||||||
    silent execute "update | edit"
 | 
					    silent execute "update | edit"
 | 
				
			||||||
| 
						 | 
					@ -181,7 +186,7 @@ function! SaveAndExecutePython()
 | 
				
			||||||
    %delete _
 | 
					    %delete _
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    " add the console output
 | 
					    " add the console output
 | 
				
			||||||
    silent execute ".!python " . shellescape(s:current_buffer_file_path, 1)
 | 
					    silent execute '.!'. a:ex_command . ' ' . shellescape(s:current_buffer_file_path, 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    " resize window to content length
 | 
					    " resize window to content length
 | 
				
			||||||
    " Note: This is annoying because if you print a lot of lines then your code buffer is forced to a height of one line every time you run this function.
 | 
					    " Note: This is annoying because if you print a lot of lines then your code buffer is forced to a height of one line every time you run this function.
 | 
				
			||||||
| 
						 | 
					@ -193,5 +198,6 @@ function! SaveAndExecutePython()
 | 
				
			||||||
    setlocal readonly
 | 
					    setlocal readonly
 | 
				
			||||||
    " setlocal nomodifiable
 | 
					    " setlocal nomodifiable
 | 
				
			||||||
endfunction
 | 
					endfunction
 | 
				
			||||||
 | 
					"}}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
" vim: foldmethod=marker
 | 
					" vim: foldmethod=marker
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue