Emacs Ruby autocomplete almost working

Ruby on-Rails-3EmacsIdeElisp

Ruby on-Rails-3 Problem Overview


I've been updating my emacs config with the use of Rsense to allow for an autocomplete drop down box to appear whilst typing code. This works well in most files except I've found it doesn't allow me to select an answer from the table when I'm editing some code in my ruby on rails project.

Here is my setup: https://github.com/map7/simple_emacs

I'm using this under Ubuntu 10.04.

For simple ruby script files it works great. I can open up a new file and type.

"test".up...

Just as I type the 'p' character in up a list of options appear and I can go up and down the list with arrow keys and select one (eg: upcase) with the enter key.

What doesn't work is when I do the exact same test but within a rails project's base directory.

Update:

Found that the problem is with (require 'rails), so it's something in the emacs-rails plugin that the autocomplete doesn't like.

Update:

It's within emacs-rails -> rails-project.el. If I comment this macro out then autocomplete works, otherwise it doesn't:

(defmacro* rails-project:with-root ((root) &body body)
  "If you use `rails-project:root' or functions related on it
several times in a block of code, you can optimize your code by
using this macro. Also, blocks of code will be executed only if
rails-root exist.
 (rails-project:with-root (root)
    (foo root)
    (bar (rails-core:file \"some/path\")))
 "
 `(let ((,root (rails-project:root)))
    (when ,root
      (flet ((rails-project:root () ,root))
        ,@body))))

Can someone explain why this breaks autocomplete?

Ruby on-Rails-3 Solutions


Solution 1 - Ruby on-Rails-3

Here's a thought: The macro binds a flet function (rails-project:root) one time to the value that (rails-project:root) has just before the body executes. (That's how it claims a performance increase: Apparently the outer (rails-project:root) is expensive, so calling once and caching the value seems like a good idea.)

Unfortunately, if there is code inside the body that has a side effect meant intentionally to change the value that (rails-project:root) returns, it's going to have no effect. That change will be invisible even to other code called within the body because Emacs lisp has dynamic binding of flet names.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionmap7View Question on Stackoverflow
Solution 1 - Ruby on-Rails-3GeneView Answer on Stackoverflow