Emacs Ruby

  • robe
    • 程式補全:company-robe
    • 跳到函式定義:jump to def
  • rubocop
    • 語法檢查:flycheck + rubocop
  • rufo
    • 程式美化
  • projectile-rails
    • Ruby on Rails 專案

Youtube 影片

預先安裝

  • robe 需要先安裝
    $gem install pry pry-doc
    
  • rufo
    $gem install rufo
    
  • rubocop
    $gem install rubocop
    

    即設定檔 .rubocop.yml

    AllCops:   
      Exclude:     
        - 'db/**/*'     
        - 'config/**/*'     
        - 'script/**/*'
    

安裝 ruby-mode 跟 rvm

(use-package ruby-mode
:ensure t
:mode ("\\.rb\\’" "Rakefile\\’" "Gemfile\\’" "Berksfile\\’" "Vagrantfile\\’")
:interpreter "ruby"
:bind (:map ruby-mode-map
("}" . my-ruby-close-brace)
("\C-c r a" . rvm-activate-corresponding-ruby)
("\C-c r r" . inf-ruby))
:config
(use-package rvm
:ensure t
:config
(rvm-use-default))
(add-hook ‘ruby-mode-hook (lambda ()
(add-to-list (make-local-variable ‘company-backends)
‘(company-robe))))
)

安裝 inf-ruby 跟 ruby-electric

(use-package inf-ruby
:ensure t
:hook (ruby-mode . inf-ruby-minor-mode)
:config
)

(use-package ruby-electric
:ensure t
:hook (ruby-mode . ruby-electric-mode)
)

安裝 robe

(use-package robe
:ensure t
:hook (ruby-mode . robe-mode)
:bind ("C-M-." . robe-jump)
:config
(defadvice inf-ruby-console-auto (before activate-rvm-for-robe activate)
(rvm-activate-corresponding-ruby))
)

安裝 rubocop

(use-package rubocop
:ensure t
:hook (ruby-mode . rubocop-mode)
:diminish rubocop-mode
)

安裝 projectile-rails

(use-package projectile-rails
:ensure t
:hook (projectile-mode . projectile-rails-on)
)

安裝 rufo

(use-package rufo
:ensure t
:hook (ruby-mode . rufo-minor-mode)
)

使用 robe

  • 先啟動 Meta-x inf-ruby-console-auto 或者 Ctrl-c Ctrl-s
  • 手動啟動 Meta-x robe-start
  • 使用 Ctrl-c Ctrl-l 來載入程式
  • 如果使用 rails 可以使用 Ctrl-c Ctrl-k
  • 使用 rvm 須先設定

(defadvice inf-ruby-console-auto (before activate-rvm-for-robe activate)
(rvm-activate-corresponding-ruby))

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *