ba6a5cb2dc59

Go folding and more
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Wed, 13 Mar 2019 13:33:42 -0400
parents 80f5ec3932ae
children 188c44d7247c 9dcc4278dc41
branches/tags (none)
files bin/cal vim/vimrc

Changes

--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/cal	Wed Mar 13 13:33:42 2019 -0400
@@ -0,0 +1,5 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+ncal -Mb "$@"
--- a/vim/vimrc	Tue Mar 12 12:24:28 2019 -0400
+++ b/vim/vimrc	Wed Mar 13 13:33:42 2019 -0400
@@ -1404,11 +1404,33 @@
 " }}}
 " Go {{{
 
+function! GetGoFold(lnum)
+    let line = getline(a:lnum)
+    let prev = getline(a:lnum-1)
+
+    if line =~# '\v^//'
+        if prev =~# '\v^//'
+            return '1'
+        else
+            return '>1'
+        endif
+    elseif line =~# '\v^\S.*[{(]$'
+        return '>1'
+    elseif line =~#'\v^[})]$'
+        return '1'
+    elseif line == "" && prev =~#'\v^[})]$'
+        return '<1'
+    else
+        return '='
+    endif
+endfunction
+
 augroup ft_go
     au!
 
     au FileType go setlocal shiftwidth=8
-    au FileType go setlocal foldmethod=syntax
+    au FileType go setlocal foldmethod=expr
+    au FileType go setlocal foldexpr=GetGoFold(v:lnum)
     au FileType go nnoremap <buffer> <silent> M :GoDoc<cr>
     au FileType go nnoremap <buffer> <localleader>t :GoInfo<cr>
     au FileType go nnoremap <buffer> <localleader>h :GoDocBrowser<cr>
@@ -1416,6 +1438,7 @@
 
     " this language is incredible
     au FileType go iabbrev <buffer> ernil if err != nil {<cr>return nil, err<esc>jA
+    au FileType go iabbrev <buffer> erpan if err != nil {<cr>panic(err)<esc>jA
 augroup END
 
 " }}}