Emacs Ruby 自动完成几乎可以工作

发布于 2024-12-13 18:52:21 字数 1267 浏览 8 评论 0原文

我一直在使用 Rsense 更新我的 emacs 配置,以允许在键入代码时出现自动完成下拉框。这在大多数文件中都适用,但我发现当我在 ruby​​ on Rails 项目中编辑一些代码时,它不允许我从表中选择答案。

这是我的设置: https://github.com/map7/simple_emacs

我在 Ubuntu 10.04 下使用它。

对于简单的 ruby​​ 脚本文件来说它效果很好。我可以打开一个新文件并输入。

"test".up...

正如我在向上键入“p”字符时,会出现一个选项列表,我可以使用箭头键在列表中上下移动,然后使用 Enter 键选择一个(例如:大写)。

当我在 Rails 项目的基本目录中进行完全相同的测试时,不起作用。

更新:

发现问题出在 (require 'rails),所以这是 emacs-rails 插件中自动完成功能不喜欢的东西。

更新:

它位于 emacs-rails 内 -> Rails-project.el。如果我注释掉这个宏,那么自动完成功能就会起作用,否则就不会:

(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))))

有人可以解释为什么这会破坏自动完成功能吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

同展鸳鸯锦 2024-12-20 18:52:21

这里有一个想法:宏将 flet 函数 (rails-project:root) 绑定一次到 (rails-project:root) 的值> 就在 body 执行之前。 (这就是它声称性能提高的方式:显然外部 (rails-project:root) 很昂贵,因此调用一次并缓存该值似乎是一个好主意。)

不幸的是,如果内部有代码具有副作用的 body 意味着故意更改 (rails-project:root) 返回的值,它将不会产生任何效果。即使对于 body 中调用的其他代码来说,这种更改也是不可见的,因为 Emacs lisp 具有 flet 名称的动态绑定。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文