Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Fujiwara Takuya tyru

🏠
Working from home
View GitHub Profile
View flatten.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef enum _type_t {
INT_T,
STRING_T,
LIST_T,
} type_t;
View vimrc
set laststatus=2
let &statusline = '%!StatusLine()'
function! StatusLine() abort
if &hlsearch
" XXX: 'l', 'h' do not move current cursor!
let searchcount = matchstr(execute('keepjumps keepmarks %s//&/gne', 'silent'), '\d\+')
let searchcount = printf(' (%s/%s)', searchcount !=# '' ? searchcount : '0', @/)
else
let searchcount = ''
View execute-convert-snr.patch
diff --git a/src/eval.c b/src/eval.c
index 4a3cf9912..cdb1d2f4e 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -8109,6 +8109,7 @@ ex_echohl(exarg_T *eap)
ex_execute(exarg_T *eap)
{
char_u *arg = eap->arg;
+ char_u *trans_arg;
typval_T rettv;
@tyru
tyru / sid_snr.vim
Last active Nov 11, 2018
Bizarre <SID> and <SNR> conversion (https://github.com/vim-jp/issues/issues/1201)
View sid_snr.vim
function! s:get_next_tab(n) abort
let last = tabpagenr('$')
let i = (tabpagenr() - 1 + a:n) % last
let i = i < 0 ? last + i : i
return i ==# 0 || i + 2 ==# tabpagenr() ? i : i + 1
endfunction
" =============== Error ===============
@tyru
tyru / vimrc.vim
Created Oct 10, 2018
Toggle current tab's terminal window modes
View vimrc.vim
nnoremap <Plug>(vimrc:prefix:excmd)oT :<C-u>call <SID>toggle_terminal_modes()<CR>
function! s:toggle_terminal_modes()
let prevwinnr = winnr()
" -1: undefined, 0: terminal normal mode, 1: terminal job mode
" Change all terminal window's modes to this mode.
" It is determined by the first terminal window's mode.
let dest_mode = -1
try
for bufnr in tabpagebuflist()
@tyru
tyru / output
Last active Sep 23, 2018
Parsing / Evaluating Vim script number literals in Prolog DCG
View output
number(tInt(['1']))
number(tFloat(int_flac(['1'],['0'])))
number(tInt(['1','2','3','4','5','6','7','8','9']))
number(tFloat(int_flac(['1','2'],['3','4'])))
number(tInt(bin('0b',['1','0','1','0'])))
number(tInt(bin('0B',['0','1','0','1'])))
number(tInt(hex('0x',['D',e,'A',d,'B',e,'E',f])))
number(tInt(hex('0X',[d,'E',a,'D',b,'E',e,'F'])))
number(tInt(hex('0x',['1','2','3','4','5','6','7','8','9',a,b,c,d,e,f,'A','B','C','D','E','F'])))
number(tInt(hex('0X',['1','2','3','4','5','6','7','8','9',a,b,c,d,e,f,'A','B','C','D','E
View duptermbuf.vim
scriptencoding utf-8
let s:save_cpo = &cpo
set cpo&vim
" index = xterm number
" cf.
" * :help cterm-colors
" * https://jonasjacek.github.io/colors/
let s:color_table = [
@tyru
tyru / check-le-date.sh
Last active Sep 8, 2018
Check end dates of all installed certificates (Let's Encrypt)
View check-le-date.sh
#!/bin/bash
set -u
# /etc/letsencrypt/live/ にインストールされている証明書の有効期限が1つでも報告日を迎えていたら
# 終了コード=0以外で終了し、標準出力に出力する (cron 用)
# 例: 有効期限の終了日=20180929, REPORT_DAYS_AGO=7 の場合 報告日=20180922 となる。
REPORT_DAYS_AGO=${REPORT_DAYS_AGO:-14}
# 2つの日付のシリアル秒の差を求める
compare_date() {
@tyru
tyru / output
Last active Sep 7, 2018
go-vimlparser walk
View output
node = (*ast.File) &{Start:sample.vim:1:1 Body:[0xc420001200 0xc420001380]}
node = (*ast.Function) &{Func:sample.vim:1:1 ExArg:{Forceit:true AddrCount:0 Line1:0 Line2:0 Flags:0 DoEcmdCmd: DoEcmdLnum:0 Append:0 Usefilter:false Amount:0 Regname:0 ForceBin:0 ReadEdit:0 ForceFf: ForceEnc: BadChar: Linepos:sample.vim:1:1 Cmdpos:sample.vim:1:1 Argpos:sample.vim:1:11 Cmd:0xc42005e500 Modifiers:[] Range:[] Argopt:map[] Argcmd:map[]} Body:[0xc4200e3540] Name:0xc42005e640 Params:[] Attr:{Range:false Abort:false Dict:false Closure:false} EndFunction:0xc4200e3680}
node = (*ast.Ident) &{NamePos:sample.vim:1:11 Name:s:f}
node = (<nil>) <nil>
node = (*ast.ExCall) &{ExCall:sample.vim:2:3 ExArg:{Forceit:false AddrCount:0 Line1:0 Line2:0 Flags:0 DoEcmdCmd: DoEcmdLnum:0 Append:0 Usefilter:false Amount:0 Regname:0 ForceBin:0 ReadEdit:0 ForceFf: ForceEnc: BadChar: Linepos:sample.vim:2:3 Cmdpos:sample.vim:2:3 Argpos:sample.vim:2:8 Cmd:0xc42005e540 Modifiers:[] Range:[] Argopt:map[] Argcmd:map[]} FuncCall:0xc42008d6
@tyru
tyru / output
Last active Sep 7, 2018
go/ast walk
View output
node = (*ast.File) &{Doc:<nil> Package:1 Name:main Decls:[0xc42006e2d0 0xc42006e3c0] Scope:scope 0xc420054220 {
func f
func g
}
Imports:[] Unresolved:[int] Comments:[]}
node = (*ast.Ident) main
node = (<nil>) <nil>
node = (*ast.FuncDecl) &{Doc:<nil> Recv:<nil> Name:f Type:0xc42000a180 Body:0xc42006e2a0}
node = (*ast.Ident) f
node = (<nil>) <nil>