Corfu 补全的使用姿势

(setup (:pkg corfu)
  (:option
   ;; Optional customizations
   corfu-cycle t                ;; Enable cycling for `corfu-next/previous'
   corfu-auto t                 ;; Enable auto completion
   ;; (corfu-quit-at-boundary t)     ;; Automatically quit at word boundary
   corfu-quit-no-match t        ;; Automatically quit if there is no match
   corfu-preview-current nil    ;; Disable current candidate preview
   corfu-echo-documentation nil ;; Disable documentation in the echo area
   corfu-auto-prefix 2
   )
  (:with-map corfu-map
    (:bind [tab] corfu-next
           [backtab] corfu-previous
           "<escape>" corfu-quit))
      (corfu-global-mode)
  )

我开了自动补全和空格匹配,对于你提到的补全混乱问题,这个的确有些鱼与熊掌不可兼得。我的方案是对esc绑定了corfu-quit,因为我是一个前vim现meow用户,esc太习惯了,如果发现匹配太长了就随手esc一下,已经输入的内容会保持输入,如果c-g的话我记得会直接删除这些字符,因此c-g不太行的。

另外,我感觉如果上一个单词已经输入完成了,然后输入下一个单词,结果两个单词一起补全这种情况有一些奇怪,一般输入完一个变量或者函数会敲一下回车选择,如果是很短的变量一下子就输完了,后面继续输入新的内容,那用quit可以解决我的问题。

默认情况下corfu在这里的esc默认逻辑是多层退出,也就是不断地后退选择内容和输入内容,这个逻辑我觉得有些反直觉

目前我用起来挺好的,没遇到什么不适应的情况,也可能是我用的包不多?基本就eglot啥的,空格匹配,配合esc取消补全,这点似乎和其他编译器差别不大,我感觉用起来挺好

多谢,看来只能要么适应一下 C-g / ESC 退出(我是原生按键,C-g 是正常退出,不会删除输入;ESC 对原生按键用户来说不好适应 :grinning_face_with_smiling_eyes:),要么就放弃 orderless,空格直接退出补全。

用了几天corfu,和你一样的问题,不过我是修改了一下evil-escape让补全触发时退出corfu,留在insert-mode内,但是感觉还是怪怪的,,,所以干脆把corfu删了用consult-completion-in-region手动补全了

如果喜欢通过 minibufer 补全的话 consult-completion-in-region 确实是最佳选择。 Corfu 作者也推荐这个方式

Corfu 现在可以通过 M-Space 来启动在自动补全开启的情况更好的使用 orderless,这样鱼和熊掌可以兼得了😄。

可以直接用官方推荐的自动补全配置

更新:
要在 eglot 下使用 orderless,因为 eglot 会更改completion-category-defaults 这个变量。 需要通过修改 completion-category-overrides 改为 orderless

(use-package orderless
  :demand t
  :config
  (setq completion-styles '(orderless flex)
        completion-category-overrides '((eglot (styles . (orderless flex))))))

详细内容可以参考这个issue: How to make corfu + orderless work well with eglot + clangd · Issue #136 · minad/corfu · GitHub

5 个赞

最近给 Corfu 加了 kind-icon,通过 svg-lib 启用了新的图标。可是这些图标不是一次性全部下载下来,而是第一次使用到才会到 GitHub 去下载,速度很慢,非常影响使用体验。

我这里手动去上游仓库把所有的图标下载后,整理到一起,需要的朋友从我的个人Github仓库直接下载然后拷贝到 .emacs.d/.cache/svg-lib/ 文件夹下即可。

同时,通过 kind-icon ,用户可以替换所有的图标为自己喜欢的图标,更多的图标可以在Templarian/MaterialDesign-SVG 下载

5 个赞

OT 一下,这是啥字体。

Bookerly, 亚马逊专门为 Kindle 开发的字体,比较适合电子设备。

我主要在 org-mode ,Info-mode 看文档,gnus 看邮件列表,以及 mode-line 用这个变宽字体,很舒服 :grinning_face_with_smiling_eyes:

Corfu 的用户主要一下,如果把 延迟改为 0 以及前缀改为 1,在这种情况下会和 flyspell-mode 冲突,造成补全列表的候选不全。如果喜欢这种即时显示补全窗口的话,建议手动运行 flyspell 进行拼写检查。

比如这种设置:

(use-package corfu
  :demand t
  :custom
  (corfu-auto t)
  (corfu-max-width 110)
  (corfu-auto-delay 0.0)
  (corfu-auto-prefix 1)
  (corfu-preview-current nil)
  (corfu-echo-documentation t)
  :bind (:map corfu-map
              ("C-d" . corfu-info-documentation)
              ("M-." . corfu-info-location))
  :init
  (global-corfu-mode))

我在 macOS 上开了 flyspell 也不影响,在 Windows 下就有影响,估计是因为 Windows 下性能较差。

参考这个 issue:

1 个赞

Corfu 可以通过 corfu-popup 这个包在终端里面使用了。但只支持基于文本的 kind-icon 图标

这是在 iterm2 中的效果:

8 个赞

corfu 看着很强大呀。

Corfu 在除了在后端方面没 Company 那么丰富,其他方面都挺不错的,值得一试。

Company 相当于大而全,Corfu 是小而美,自由组合 :smile:

  1. 因为用的是 childframe 来显示,弹窗可以越过其他窗口。Company 的弹窗是overlay 实现,只能在窗口内显示。
  2. 通过 kind-icon 支持漂亮的 UI 图标。
  3. 通过 cape 支持更多的后端,甚至可以直接用 company 的后端。
  4. 配合 orderless 补全体验和 minibuffer 中的 vertico 保持一致。
5 个赞

哈哈哈, 感觉不错,等我把 lsp-bridge 弄完了尝试一下。

1 个赞

好耶!tty党无比开心 :smiling_face_with_three_hearts:

1 个赞

看起来很不错。说到这个,我发现 kind-icon 即使提前在 .cache/svg-lib 下载了图标,他也会从 github 下载。最难受的是,他会卡住 emacs。。就算 C-g 也没用

不会啊,本地有图标是不会再去下载的。那说明你本地的图标还没下载全。 你可以试试将我这个仓库的图标放到 ~/.emacs.d/.cache/svg-lib 目录下,这里都是全了的。

我就是从你这下载的 :joy:

那不应该啊,一共是32个图标,只要名字对就行,对应这里设置的名字:

你是在什么mode下输入哪个关键字就会提示下载图标?

emacs-lisp-mode,

README.org
material_application-braces-outline.svg
material_application-brackets-outline.svg
material_application-parentheses-outline.svg
material_circle-half-full.svg
material_code-braces.svg
material_code-brackets.svg
material_cog.svg
material_crosshairs-question.svg
material_file-code-outline.svg
material_file-document-outline.svg
material_folder.svg
material_format-list-bulleted-square.svg
material_format-list-bulleted-type.svg
material_format-list-checks.svg
material_function-variant.svg
material_function.svg
material_key-variant.svg
material_lambda.svg
material_lightning-bolt-outline.svg
material_lock-remove-outline.svg
material_note-text-outline.svg
material_numeric.svg
material_palette.svg
material_plus-circle-outline.svg
material_plus-minus.svg
material_ruler-square.svg
material_script-text-outline.svg
material_sticker-text-outline.svg
material_table-column-plus-after.svg
material_variable-box.svg
material_variable.svg
material_view-grid-plus-outline.svg