aboutsummaryrefslogtreecommitdiffstats
path: root/projects/aodocs.vim
blob: da1f035f6385de0cbcd49e730fe85d6a5c4c8817 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
augroup AODocs
	autocmd!

	autocmd BufRead $VIM_PROJECT_PATH_AODOCS_GO/ufo-client/client/*.go
		\ silent GoGuruScope github.com/AODocs-Dev/ufo-client/client

	autocmd BufRead,BufEnter $VIM_PROJECT_PATH_AODOCS_GO/*
		\ call s:UFOCacheSyncClientAddMappings()

	autocmd BufRead $VIM_PROJECT_PATH_AODOCS_GO/ufo-client/*.sh
		\ setlocal expandtab tabstop=4 softtabstop=4 shiftwidth=4

	autocmd BufRead,BufEnter $VIM_PROJECT_PATH_AODOCS/*.{js,ts}
		\ setlocal expandtab tabstop=2 softtabstop=2 shiftwidth=2
			\ formatoptions+=cro

	autocmd BufRead,BufEnter $VIM_PROJECT_PATH_AODOCS/*.js
		\ call s:ESLintAddMappings()

	autocmd BufRead,BufEnter $VIM_PROJECT_PATH_AODOCS/*.js
		\ iabbrev htodo /**<CR>TODO<CR>/

	autocmd BufRead,BufEnter $VIM_PROJECT_PATH_AODOCS/*.json
		\ setlocal expandtab tabstop=4 softtabstop=4 shiftwidth=4

	autocmd BufRead,BufEnter $VIM_PROJECT_PATH_AODOCS/*.{html,css,scss}
		\ setlocal expandtab tabstop=4 softtabstop=4 shiftwidth=4

	autocmd BufNewFile,BufRead
		\ $VIM_PROJECT_PATH_AODOCS_GO/*/.git/{COMMIT_EDIT,MERGE_,TAG_EDIT}MSG
		\,$VIM_PROJECT_PATH_AODOCS/*/.git/{COMMIT_EDIT,MERGE_,TAG_EDIT}MSG
		\ call s:CommitWackoTextWidthMappings()
		\ | call s:CommitWackoTextWidth()

	" Open Jira ticket ID in the browser
	autocmd BufRead,BufEnter
		\ $VIM_PROJECT_PATH_AODOCS_GO/*
		\,$VIM_PROJECT_PATH_AODOCS/*
		\ command! JiraOpen :call system('jira-open ' . expand('<cWORD>'))

	autocmd BufRead,BufEnter $VIM_PROJECT_PATH_AODOCS_GO/*
		\ let g:go_play_browser_command = 'open -a Nightly %URL% &'
		\| let g:go_addtags_transform = 'camelcase'

	autocmd BufRead,BufEnter $VIM_PROJECT_PATH_AODOCS_UFO_EXTENSION/*.js
		\ setlocal path+=$VIM_PROJECT_PATH_AODOCS_UFO_EXTENSION_MODULE

	autocmd BufRead,BufEnter $VIM_PROJECT_PATH_AODOCS_SMARTBAR/*.js
		\ setlocal path+=extension/module

	" Turn on context.vim
	autocmd BufRead,BufEnter
		\ $VIM_PROJECT_PATH_AODOCS_GO/*
		\,$VIM_PROJECT_PATH_AODOCS/*
		\ ContextEnable

	autocmd BufRead,BufEnter *.todo
		\ nnoremap <buffer> <Leader>yy :call <SID>TodoCopyLast()<CR>

	" Read an email signature
	autocmd FileType mail
		\ nnoremap <buffer> <leader>s :r $XDG_CONFIG_HOME/mutt/signatures/<C-d>
augroup END

" Insert a path to UFO ticket folders
cnoremap <C-x>u <C-r>=$VIM_PROJECT_PATH_AODOCS_UFO_TICKET_FOLDER<CR>


" Write to a temporary file labelled with the current time.
command! -nargs=0 -bang WChat
	\ execute ":write\<bang> " . $VIM_PROJECT_PATH_AODOCS_CHAT_DRAFTS
		\. '/chat-draft-' . strftime('%FT%H.%M.%S') . '.txt'


" Enables a longer-than-72 character first line and 72 character wrapping on
" subsequent lines.
function! s:CommitWackoTextWidth()
	if line('.') == 1
		" Match "CO-123: "
		let matches = matchlist(getline('.'), '^\u\+-\d\+: ')

		if !empty(matches)
			let id_prefix_length = len(matches[0])
			execute 'setlocal textwidth=' . (72 + id_prefix_length)
		endif
	else
		setlocal textwidth=72
	endif
endfunction

function! s:CommitWackoTextWidthMappings()
	inoremap <silent> <buffer> <CR> <C-o>:call <SID>CommitWackoTextWidth()<CR><CR>
	nnoremap <silent> <buffer> o :call <SID>CommitWackoTextWidth()<CR>o
	nnoremap <silent> <buffer> O :call <SID>CommitWackoTextWidth()<CR>O
endfunction


function! s:UFOCacheSyncClientAddMappings()
	nnoremap <buffer> <leader>uc :silent !ufo-cache-syncclient<CR><C-l>
	nnoremap <buffer> <leader>ud :silent !ufo-cache-syncclient rm<CR><C-l>
	nnoremap <buffer> <leader>ur :silent !ufo-cache-syncclient rebuild<CR><C-l>
endfunction


function! s:ESLintAddMappings()
	nnoremap <buffer> <leader>eda :silent !eslint-yes-debugger.sh -a<CR> <Bar> :redraw!<CR>
	nnoremap <buffer> <leader>edd :silent !eslint-yes-debugger.sh -d<CR> <Bar> :redraw!<CR>
endfunction


function! s:TodoCopyLast()
	try
		" Copy the last entry to the bottom
		?\n\n\d?,$t$

	" We only have a single entry (pattern not found error).
	catch /^Vim\%((\a\+)\)\?:E486: .*\\n\\n\\d/
		" Add two lines to the end of the file.
		call append('$', ['', ''])

		" Copy the only entry to the bottom.
		0,$-2t$

	finally
		" Move to date line
		?\n\n\zs\d?

		" Increment day, then put the current entry at the top of the window
		call setline('.', strftime('%Y.%m.%d:'))
		execute "normal! zt2\<C-e>"
	endtry
endfunction