Skip to content

Instantly share code, notes, and snippets.

View eagletmt's full-sized avatar

Kohei Suzuki eagletmt

View GitHub Profile
nnoremap <silent> <Plug>select_cstyle_if :<C-u>call <SID>select_cstyle_if()<CR>
function! s:select_cstyle_if() " {{{
let orig_view = winsaveview()
let if_start_pos = []
while searchpair('{', '', '}', 'bW', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|character"') != 0
let brace_start_pos = getpos('.')
normal! ge
let save = @"
normal! yl
let t = @"
@eagletmt
eagletmt / .vimrc
Created May 16, 2010 17:58 — forked from thinca/.vimrc
" Move window position {{{
nnoremap <silent> <Plug>swap_window_next :<C-u>call <SID>swap_window(v:count1)<CR>
nnoremap <silent> <Plug>swap_window_prev :<C-u>call <SID>swap_window(-v:count1)<CR>
nnoremap <silent> <Plug>swap_window_j :<C-u>call <SID>swap_window_dir(v:count1, 'j')<CR>
nnoremap <silent> <Plug>swap_window_k :<C-u>call <SID>swap_window_dir(v:count1, 'k')<CR>
nnoremap <silent> <Plug>swap_window_h :<C-u>call <SID>swap_window_dir(v:count1, 'h')<CR>
nnoremap <silent> <Plug>swap_window_l :<C-u>call <SID>swap_window_dir(v:count1, 'l')<CR>
nnoremap <silent> <Plug>swap_window_t :<C-u>call <SID>swap_window_dir(v:count1, 't')<CR>
nnoremap <silent> <Plug>swap_window_b :<C-u>call <SID>swap_window_dir(v:count1, 'b')<CR>
command! -nargs=0 CompileThis call s:compile_this()
let s:compile_cmd = {
\ 'c': 'gcc -c -Wall',
\ 'cpp': 'g++ -c -Wall -std=c++0x',
\ 'haskell': 'ghc -c -Wall'
\ }
function! s:compile_this()
if !has_key(s:compile_cmd, &l:filetype)
echoerr "I don't know how to compile"
return
# require ghc-paths <http://hackage.haskell.org/package/ghc-paths>
% echo 'length x' | ./hint
[a]
% echo 'x + 1' | ./hint
(GHC.Num.Num a) => a
% echo 'foldl x 0 [2,3]' | ./hint
(GHC.Num.Num a, GHC.Num.Num b) => a -> b -> a
% echo 'nub x' | ./hint Data.List
(GHC.Classes.Eq a) => [a]
mappings.addUserMap(
[modes.COMMAND_LINE],
['<C-x>'],
'toggle bang',
function() {
let [,cmd,bang,args] = commands.parseCommand(commandline.command);
bang = bang ? '' : '!';
commandline.command = cmd + bang + ' ' + args;
});
import Data.Array
import Data.Array.ST
import Control.Monad (forM_, liftM2)
main = print $ exchanges coins 10000 ! 10000
where
coins = [1, 5, 10, 50, 100, 500, 1000, 2000, 5000, 10000]
exchanges :: (Ix a, Enum a, Num a, Num e) => [a] -> a -> Array a e
exchanges cs n = runSTArray $ do
@eagletmt
eagletmt / .vimrc
Created April 27, 2010 10:55 — forked from Shougo/.vimrc
" Capture {{{
command!
\ -nargs=+
\ -complete=command
\ Capture
\ call s:cmd_capture([<f-args>])
function! s:capture(cmd)
redir => result
silent execute a:cmd
" A .vimrc snippet that allows you to move around windows beyond tabs
nnoremap <silent> <Tab> :<C-u>call <SID>NextWindowOrTab()<CR>
nnoremap <silent> <S-Tab> :<C-u>call <SID>PreviousWindowOrTab()<CR>
function! s:NextWindowOrTab()
if winnr() < winnr("$")
wincmd w
else
tabnext
commands.addUserCommand(['hseval'], 'evaluate haskell expression',
function(args) {
util.httpGet('http://tryhaskell.org/haskell.json?method=eval&expr=' + encodeURIComponent(args.literalArg), function(res) {
let json = JSON.parse(res.responseText);
if (json.error) {
liberator.echoerr('error: ' + json.error);
} else if (json.exception) {
liberator.echoerr('exception: ' + json.exception);
} else {
liberator.echo(json.result + ' :: ' + json.type);
function! s:encodeURIComponent(str)
let s = ''
for i in range(strlen(a:str))
let c = a:str[i]
if c =~# "[A-Za-z0-9-_.!~*'()]"
let s .= c
else
let s .= printf('%%%02X', char2nr(a:str[i]))
endif
endfor