A minor annoyance of running "rails console" inside Emacs

If you run "rails console" from within Emacs, you might have been annoyed by the output that contains control characters whenever you run a query. Like the one given below:

1.9.3-p125 :001 > BlogPost.all
^[[1m^[[36mBlogPost Load (0.2ms)^[[0m  ^[[1mSELECT "blog_posts".* FROM "blog_posts" ^[[0m
I could not find a satisfactory solution for this anywhere. So I came up with the following solution that works fine for me.


What this code does is to make use of "term" instead of "shell" to run the rails console. In term-mode you have better support for rendering these control chars. To make navigation and kill/yank easier, it switches to line-mode. The default mode is char-mode. You can switch between line-mode and char-mode using C-c C-j and C-c C-k respectively. Hope that helps.

Comments

Unknown said…
Hello, Thanks for your post. This is useful. I have one more question. When I have line numbers enabled in Emacs, the line output from rails console wraps funny, because you get one of 2 characters for a line wrapping to the next and then a new line. Is there a way to amend this script so it disables line numbers only for the terminal? I already have

(global-linum-mode)

Set in my config for all other files.

Thank you,

Isaac

Popular posts from this blog

The mysterious ORA-03111 error

Note on allocationSize parameter of @SequenceGenerator while using JPA

xVM's vboxmanage.exe command