ChatGPT解决这个技术问题 Extra ChatGPT

Emacs Ruby autocomplete almost working

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?

The autocomplete function is used in ruby, C++, lisp and everything
i meant, where is the macro here used?
I mainly use the rails macro to jump between different files in the MVC and start the DB/server/console/etc.
Can you extract your solution to answer, and give it "works" ticket?
przemo_li, I would if I had an answer to this but the autocomplete still doesn't work when you have the rails.el plugin installed and you are trying to autocomplete within a rails minor mode source code file.

G
Gene

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.