跨 Windows 和 Unix 的代码格式化

发布于 2024-07-07 07:29:32 字数 178 浏览 6 评论 0原文

哪些 Visual Studio 设置和 .emacs 宏可以提高在 Windows(在 Visual Studio 中)上编写的代码在 Emacs 中仍然看起来不错的可能性(反之亦然)? 我最近开始关闭 emacs 中的选项卡(因此选项卡是通过空格呈现的),这至少使代码看起来相同(喜欢某些选项卡大小的人运气不好)。 有没有更好的办法?

What Visual Studio settings and .emacs macros improve the likelihood that code written on Windows (in visual studio) will still look good in Emacs (and vice versa)? I've recently taken to turning off tabs in emacs (so tabs are rendered via spaces) and this at least makes the code look the same (tho people who like certain tab sizes are out of luck). Is there a better way?

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

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

发布评论

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

评论(4

金兰素衣 2024-07-14 07:29:33

始终使用制表符仅缩进,而不使用其他任何东西,这没有问题。

任何涉及跨行对齐字符(而不是缩进)的内容都应该使用空格。

只要这样做,人们就可以将选项卡大小设置为他们喜欢的任何大小,一切都会好起来的。

Always use tabs for indenting only and nothing else, and there's no problem.

Anything involving aligning characters across lines (not indenting) should use spaces.

Just do that, then people can set their tab size to whatever they like, and everything will all be fine.

云胡 2024-07-14 07:29:33

制表符大小纯粹是个人喜好,但每段代码或项目都应该指定它想要使用哪个制表符大小作为标准。 这样,即使有人不喜欢您的选项卡尺寸,他们也会知道您的意思是这样,并在任何修复中执行相同的操作,希望他们不会对此有问题。

Tab sizes is a purely personal preference, but each piece of code or project should specify which tab size it wants to use as a standard. That way, even if someone doesn't like your tabs sizes, they'll know you meant it to be that way and do the same in any fixes, and hopefully they shouldn't have a problem with that.

白龙吟 2024-07-14 07:29:33

Emacs 的制表符理念是它们是一种压缩方案,它们的大小始终为 8,并且通常与缩进大小不同。 这会导致在第一个缩进处缩进 4 个空格,然后在下一个缩进处缩进 1 个制表符,然后在第三个缩进级别处缩进 1 个制表符和 4 个空格。

要使其与可变大小的选项卡编辑器兼容,您可以选择将 emacs 设置为空格(就像您所做的那样),或者将其缩进大小设置为 8(这是他们在 Linux 内核源代码中所做的),或者寻找emacs 宏文件,使其具有可变大小的选项卡(我在网上看到过它,但我没有制作书签)。

Emacs's idea of tabs is that they're a compression scheme, that they're always size 8, and they're normally a different size from the indent size. This leads to things like it indenting 4 spaces at the first indent, then 1 tab at the next, then 1 tab and 4 spaces at the third indent level.

Your options for making it compatible with a variable-sized tab editor are to set emacs to spaces (like you did), or set its indent size to 8 (this is what they do in the linux kernel source), or to hunt down the emacs macro file which makes it have variable sized tabs ( I have seen it on the web, but I didn't make a bookmark).

醉梦枕江山 2024-07-14 07:29:33

除了使用空格代替制表符并确保两个编辑环境中制表符宽度相同之外,我通常将 emacs(因为我更熟悉它)的 c/c++ 模式更改为“bsd”样式。 这似乎更符合 Visual Studio 的默认风格。

从我的 .emacs 自定义设置变量列表中:

'(c-default-style (quote ((c-mode . "bsd") (c++-mode . "bsd") (java-mode . "jav
a") (other . "gnu"))))

In addition to using spaces instead of tabs and making sure that the tab width is the same in both editing environments, I usually change emacs's (because I'm more familure with it) c/c++ modes to "bsd" style. This seems to more closely match visual studio's default style.

From my .emacs custom-set-variables list:

'(c-default-style (quote ((c-mode . "bsd") (c++-mode . "bsd") (java-mode . "jav
a") (other . "gnu"))))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文