如何在 Emacs 中实现自动补全以在按下按钮时自动开始补全

发布于 2024-08-21 23:08:46 字数 618 浏览 4 评论 0原文

我正在使用 emacs 的自动完成 elisp。 我目前通过按 M-TAB 使用它,但我希望它也能在 4 个字符后自动完成。

我使用 yasnippet 作为自动完成的源,因此如果我将其设置为在 4 个字符后自动完成,它将不会显示像 if、for、inc、main 这样的完成。

如果我将其设置为立即开始自动完成,那么它会妨碍我的打字。

如果我设置一个键绑定并告诉它在 4 个字符后开始自动完成,它会忽略键绑定,并且不会开始完成

(setq ac-auto-start 4)
(define-key ac-mode-map (kbd "M-TAB") 'auto-complete)

我希望它在我按 M-TAB 或在 4 个字符后完成。

编辑: 试过了

(setq ac-auto-start 4)
(global-set-key (kbd "M-TAB") 'ac-start)

我也

(global-auto-complete-mode t)

还是不行。 当我点击 M-TAB 时,它在迷你缓冲区中显示“Nothing to Complete”。

I am using the auto-completion elisp for emacs.
I am currently using it by pressing M-TAB but I would like it to also auto-complete after 4 characters.

I use yasnippet as a source for auto-complete so if I set it to auto-complete after 4 characters it won't show completions like if, for, inc, main.

If I set it to start auto-completion immediately then it gets in the way of my typing.

If I set a key binding and tell it start auto-completion after 4 characters, it ignores the key-bindings, and doesn't start completion

(setq ac-auto-start 4)
(define-key ac-mode-map (kbd "M-TAB") 'auto-complete)

I would like for it to complete when I press M-TAB or after 4 characters.

EDIT:
I tried

(setq ac-auto-start 4)
(global-set-key (kbd "M-TAB") 'ac-start)

I also have

(global-auto-complete-mode t)

It still didn't work.
when I hit M-TAB it displays "Nothing to complete" in the minibuffer.

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

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

发布评论

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

评论(1

各空 2024-08-28 23:08:46

“ac-mode-map”仅在自动完成弹出窗口可见时才定义,因此上面的“define-key”将不起作用。也许可以使用“global-set-key”来代替。

另外,我相信您需要将其绑定到“ac-start”,而不是“auto-complete”。

总之,请尝试以下操作:

(setq ac-auto-start 4)
(global-set-key (kbd "M-TAB") 'ac-start)

"ac-mode-map" is only defined when the auto-complete popup is visible, so your "define-key" above won't work. Maybe use "global-set-key" instead.

Also, I believe you need to bind it to "ac-start", not "auto-complete".

In summary, try the following:

(setq ac-auto-start 4)
(global-set-key (kbd "M-TAB") 'ac-start)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文