格式化代码的问题

emacs能否实现像visual studio一样实时自动格式化代码? 或者有没有比较好的格式化代码方案?

能 zsbd

要怎么实现?

这里抄过配置,效果还可以。输入括号、分号的时候自动调用clang-format进行格式化

radian-software/apheleia: :tulip: Run code formatter on buffer contents without moving point, using RCS patches and dynamic programming. (github.com)

这个包可以试试

vs是咋自动格式化的?没感觉有这个功能呀?(常年写c++) emacs我用的自动indent GitHub - xendk/indentinator: Automatic indentation mode for Emacs ,还可以format on save调用lsp的format,不过我用了auto save每1秒就保存就不用format on save不然会打乱代码。

刚刚给 lsp-bridge 加了一个 lsp-bridge-enable-auto-format-code 选项, 这个选项默认关闭, 通过 (setq lsp-bridge-enable-auto-format-code t) 打开后, 你停止写代码1秒以后会自动格式化当前 Buffer 的代码。

2 个赞

大佬,在设置(setq lsp-bridge-enable-auto-format-code t)后,lsp-bridge 无法正常提供 c++ 补全了

*Messages*报错如下:

File mode specification error: (void-variable lsp-bridge-auto-format-timer)

估计重构的时候有拼写错误,我一会改改。

或者你帮忙发一个补丁,现在我电脑不在身边,谢谢。

逻辑我测试没问题,应该就是提交之前重构了一下单词拼写错了。

应该是拼写错误,我手机提交了一个补丁,你再更新看看。

1 个赞

感谢大佬,可以了

另外这种代码格式化好像会打断 yasnippet 的展开,等大佬有空时麻烦再看一下

我晚上回去看看,在写yas的时候不格式化代码。

1 个赞

更新吧, 已经好了 Don't format code if yasnippet is active. · manateelazycat/lsp-bridge@1438f06 · GitHub

2 个赞