For some time I had been trying to come up with an elegant solution for starting all the multiple shells I need when working on my Ruby on Rails projects. I find that if I have the following shells, it really helps with command history:
command-shell
svn-shell
ruby-shell
console-shell
migrate-shell
test-shell
In the command-shell, I run normal commands, like "script/generate model InputAffinity". In the svn-shell, I interact with subversion. In the ruby-shell, I run commands like "mongrel_rails cluster::start". In the console-shell, interact with the Rails console ("script/console"). In the migrate-shell, I do my migrations, and in the test-shell, I run my Rails tests.
I was getting tired of starting all those shells, and tried various complicated elisp expressions to start shells and change the starting directory in each of those shells. It turns out that there is a very elegant and super simple way to do this.
1) Add the following to your .emacs startup file
(shell "command-shell")
(shell "svn-shell")
(shell "ruby-shell")
(shell "console-shell")
(shell "migrate-shell")
(shell "test-shell")
2) "cd" into the Ruby on Rails directory
3) Start emacs normally.
So simple, and so good.
3 comments:
Why stop at these named shells?
I have a shell named for each directory that i start it in. I usually never cd in a shell now and I also retain a history for each directory so histories between project directories don't get mixed up. I can also go back to a directory after a number of months and look at what the commands are that i need to run, be it compiling, testing, installing.
See UsingMultipleShells (i should update this page as I have changed a bit of my own code, but it should give you enough of an idea).
I'll see your shells and raise you two inferior processes.
I find it much more convenient to use inferior-ruby to interact with the Rails Console:
(defun rails-console ()
(interactive)
(run-ruby (concat (rails-root) "script/console")))
That way you can send method definitions directly from your ruby buffers to the console; no copy/paste required!
And if you use Emacs' built-in VC capability, you don't have to switch to another buffer to use svn. You can commit, diff, and merge from the buffers you're editing.
For migrations and other rake tasks, why not use M-x rake?
(defun rake (task)
(interactive (list (completing-read "Rake (default: default): "
(pcmpl-rake-tasks))))
(shell-command-to-string (concat "rake " (if (= 0 (length task)) "default" task))))
(defun pcmpl-rake-tasks ()
(with-temp-buffer
(insert (shell-command-to-string "rake -T"))
(goto-char (point-min))
(pcmpl-build-rake-task-list)))
(defun pcmpl-build-rake-task-list ()
(when (not (eobp))
(cons (pcmpl-task-at-point)
(progn (forward-line)
(pcmpl-build-rake-task-list)))))
(defun pcmpl-task-at-point ()
(forward-word 2)
(word-at-point))
If you also use ri-emacs (http://rubyforge.org/projects/ri-emacs/) you'll basically only have to leave Emacs to use the browser. (That can be minimized by use of MozRepl, but that's a whole other blog post.)
Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my blog, it is about the Celular, I hope you enjoy. The address is http://telefone-celular-brasil.blogspot.com. A hug.
Post a Comment