Tatsuhiro Ujihisa github.com/ujihisa
@ujm
>(._. )<
- Develop CRuby with Vim
- Hard to structure things you should know for 5min talk
-> FAQ style 11 questions and answers
Play some games
"CRuby indentations look weird!" - A Rubyist Vimmer
static VALUE
rb_str_casecmp(VALUE str1, VALUE str2)
{
VALUE s = rb_check_string_type(str2);
if (NIL_P(s)) {
>-return Qnil;
}
return str_casecmp(str1, s);
}
Indent 4 spaces for C with tabs for eight-space indentation (emacs default)
according to ruby/doc/contributing.rdoc
For CRuby buffers, do this:
in your ~/.vimrc
" Same as default
set cindent
set tabstop=8
set noexpandtab
" Different to the default
set shiftwidth=4 " it was 8
set softtabstop=4 " it was 0
^ works for first file
set shiftwidth=4 softtabstop=4
is equivalent
"works for first file" ??
Common mistake 1:
:set
is a buffer-local option.
Don't :set
directly at the top level.
in your ~/.vimrc
autocmd FileType c set shiftwidth=4
autocmd FileType c set softtabstop=4
^ works, but not reloadable
"works, but not reloadable" ??
Common mistake 2
autocmd FileType c set shiftwidth=4
autocmd FileType c set softtabstop=4
:autocmd
adds an event every- When you reload this file it registers an additional event again
augroup ujihisa-cruby
autocmd!
autocmd FileType c set shiftwidth=4
autocmd FileType c set softtabstop=4
augroup END
Or
- Just install github.com/mrkn/vim-cruby
- new filetype: cruby (instead of c)
- This also has ruby idiom (e.g. VALUE) for highlight and completion
e.g.
'a'.upcase
'a'.method(:upcase).
source_location #=> nil
- ri? rdoc?
- ri has filename info (not visible)
- no linenum
- ruby-doc.org can show the implementation
CRuby defines C function with
rb_define_method
// string.c
rb_define_method(
rb_cSymbol, "upcase", sym_upcase, -1);
install this vim plugin
https://github.com/ujihisa/cruby-defs.vim
(to be released during RubyKaigi)
* nontrivial but possible.
* manual index
* rdoc or ri (mystery)
- Q. ruby completion
- (not a cruby dev question)
- use language server and fix rcodetools