Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tips and tricks for using emacs to develop a ruby on rails app

What are the best modes, configuration settings, or anything that makes developing a ruby on rails app in emacs better.

like image 787
Justin Tanner Avatar asked Mar 11 '10 23:03

Justin Tanner


5 Answers

You should try all the RoR and settle on the one you like best.

First you should check out Marshall Vandegrift's excellent screencast using ECB, ruby-mode, emacs-rails, and some other stuff. It gives you a good feel for how cool writing RoR on Emacs can be.

In short here are some of the modes you should try:

  • Rinari - A simple framework for getting around your code, running tests, and managing consoles, web-servers, etc. It's minimalistic and revolves around a series of key-bindings.
  • Emacs-rails - the grandfather of Emacs RoR modes. It hasn't been updated in a while, and in fact the primary homepage no longer exists. But it's quite powerful and lets you do almost everything.
  • Emacs-rails-reloaded - This is a re-design of the original emacs-rails, I believe by the same guy. It uses the the great anything mode to help you find things and get around. I am using this AND rinari currently.

Here are some other modes that are useful:

  • ECB - the Emacs Code Browser. Use it for project management, and getting around your code.
  • Yasnippet - provides all kinds of useful snippets, automatically inserted with the TAB key.
  • Nxhtml - For editing rhtml, erb, etc.

More modes you might try:

  • Ri - for viewing ri documentation inline.
  • Flymake-ruby - on the fly syntax checking.
  • Ri - for viewing ri documentation

Oh and of course you need ruby-mode, which comes with the ruby source, and is maintained by Matz himself.

Hope this helps

like image 121
thermans Avatar answered Oct 06 '22 05:10

thermans


rspec-mode (run single or multiple specs easily)

js2-mode (JavaScript syntax highlighting)

ido (find files/buffers in your project super quickly)

like image 41
sahglie Avatar answered Oct 06 '22 04:10

sahglie


Since I am new to rails (and emacs), I don't want to use rinari right away. I find that if a tool does too much magic for me I don't learn the details as quickly as I would like. I think I will use it eventually. For now, however, I set up a bunch of shells that I spawn in emacs for RAILS 3 and just switch between them to do my work. I prefix them with tmr so that I can easily find them.

   (defun tmr-spork-shell ()
      "Invoke spork shell" ; Spork - love that name
      (interactive)
      (pop-to-buffer (get-buffer-create (generate-new-buffer-name "spork")))
      (shell (current-buffer))
      (process-send-string nil "cd .\n"); makes sure rvm variables set with .rvmrc
      (process-send-string nil "spork\n"))

    (defun tmr-devlog-shell ()
      "Tail the development log, shell"
      (interactive)
      (pop-to-buffer (get-buffer-create (generate-new-buffer-name "devlog")))
      (shell (current-buffer))
      (process-send-string nil "cd .\n"); makes sure rvm variables set with .rvmrc
      (process-send-string nil "tail -f log/development.log\n"))

    (defun tmr-testlog-shell ()
      "Tail the test log, shell"
      (interactive)
      (pop-to-buffer (get-buffer-create (generate-new-buffer-name "testlog")))
      (shell (current-buffer))
      (process-send-string nil "cd .\n"); makes sure rvm variables set with .rvmrc
      (process-send-string nil "tail -f log/test.log\n"))

    (defun tmr-server-shell ()
      "Invoke rails ui server shell"
      (interactive)
      (pop-to-buffer (get-buffer-create (generate-new-buffer-name "server")))
      (shell (current-buffer))
      (process-send-string nil "cd .\n"); makes sure rvm variables set with .rvmrc
      (process-send-string nil "rails s\n"))

    (defun tmr-db-shell ()
      "Invoke rails dbconsole shell"
      (interactive)
      (pop-to-buffer (get-buffer-create (generate-new-buffer-name "dbconsole")))
      (shell (current-buffer))
      (process-send-string nil "cd .\n"); makes sure rvm variables set with .rvmrc
      (process-send-string nil "rails dbconsole\n"))

    (defun tmr-console-shell ()
      "Invoke rails console shell"
      (interactive)
      (pop-to-buffer (get-buffer-create (generate-new-buffer-name "console")))
      (shell (current-buffer))
      (process-send-string nil "cd .\n"); makes sure rvm variables set with .rvmrc
      (process-send-string nil "rails console\n"))

    ; I like to run all my tests in the same shell
    (defun tmr-rspec-shell ()
      "Invoke rspec shell"
      (interactive)
      (pop-to-buffer (get-buffer-create (generate-new-buffer-name "rspec")))
      (shell (current-buffer))
      (process-send-string nil "cd .\n"); makes sure rvm variables set with .rvmrc
      (process-send-string nil "rspec spec\n")) ; This is debatable, since spork wont be up yet

    ; The shell where I do most of my work
    (defun tmr-shell ()
      "Invoke plain old shell"
      (interactive)
      (pop-to-buffer (get-buffer-create (generate-new-buffer-name "sh")))
      (shell (current-buffer))
      (process-send-string nil "cd .\n")); makes sure rvm variables set with .rvmrc

    ; My everyday ide
    (defun tmr-ide-lite ()
      "Spawn several shells for a mini Rails IDE"
      (interactive)
      (progn (tmr-spork-shell)
             (tmr-shell)
             (tmr-server-shell)
             (tmr-rspec-shell)))

    ; When I am doing a big debug session
    (defun tmr-ide-full ()
      "Spawn several shells for a full Rails IDE"
      (interactive)
      (progn (tmr-spork-shell)
             (tmr-shell)
             (tmr-server-shell)
             (tmr-console-shell)
             (tmr-db-shell)
             (tmr-devlog-shell)
             (tmr-testlog-shell)
             (tmr-rspec-shell)))
like image 45
traday Avatar answered Oct 06 '22 03:10

traday


Another mode that I find useful that has not been mentioned is web-mode. It is useful for writing views, and handles .html.erb files very well. It features syntax highlighting and tag completion, among other things. You can find it at here.

like image 30
Scott Weldon Avatar answered Oct 06 '22 03:10

Scott Weldon


Since all of the entries here are 8+ years old, I thought I would mention projectile-rails (found here). It is currently maintained (last commit as of this writing is Aug 10, 2021) and, along with other functionality provided by projectile-mode, full-featured enough for most Rails projects. I find it easy enough to use with a couple of aliases:

(defalias 'gt 'projectile-rails-goto-file-at-point)
(defalias 'gtv 'projectile-rails-find-current-view)

like image 38
amp108 Avatar answered Oct 06 '22 05:10

amp108