我真的很想看到一个比例字体 IDE,即使我必须自己构建它(也许作为 Visual Studio 的扩展)。 我基本上的意思是 MS Word 风格的代码编辑,有点像 《C++ 编程语言》书。
我想为缩进设置制表位,并排列函数签名和赋值语句行,这些可以用点而不是固定字符位置来指定。 我还想要粗体和斜体。 各种字体大小甚至样式表都会很酷。
有没有人见过这样的东西或者知道开始构建这样的东西的最佳方法?
I would really like to see a proportional font IDE, even if I have to build it myself (perhaps as an extension to Visual Studio). What I basically mean is MS Word style editing of code that sort of looks like the typographical style in The C++ Programming Language book.
I want to set tab stops for my indents and lining up function signatures and rows of assignment statements, which could be specified in points instead of fixed character positions. I would also like bold and italics. Various font sizes and even style sheets would be cool.
Has anyone seen anything like this out there or know the best way to start building one?
发布评论
评论(13)
让我回忆一下有关在 C# 中使用“var”关键字的争论。 人们讨厌它,认为它会让代码变得不太清晰。 例如,您无法知道类似以下内容的类型:
他们的论点是,您无法查看 x 是否是数组、列表或任何其他 IEnumerable。 或者 y 的类型是什么。 在我看来,不清楚并不是因为使用了 var,而是因为选择了不明确的变量名。 为什么不直接输入:
“但是你仍然看不到选举结果的类型!” - 真的有关系吗? 如果您想更改 GetRegionalElectionResults 的返回类型,您可以这样做。 任何 IEnumerable 都可以。
快进到现在。 人们希望将注释与类似的代码对齐:
因此,如果没有注释,一切都不清楚。 如果不对齐值,则无法将它们与变量分开。 但你呢? 这个怎么样(请忽略项目符号)
如果您需要对每一行进行注释,那么您就做错了。 “但你仍然需要调整价值观”——是吗? 38和2有什么关系?
在 C# 中,大多数代码块可以仅使用制表符(或者实际上是四个空格的倍数)轻松对齐:
永远不应该使用逐行注释,并且很少需要垂直对齐内容。 很少,不是从来没有。 所以我理解你们中的一些人是否喜欢等宽字体。 我更喜欢 Noto Sans 或 Source Sans Pro 字体的可读性。 这些字体可从 Google 免费获得,类似于 Calibri,但专为编程而设计,因此具有所有必要的特征:
Let me recall arguments about using the 'var' keyword in C#. People hated it, and thought it would make code less clear. For example, you couldn't know the type in something like:
Their argument was, that you couln't see if x was an array, an List or any other IEnumerable. Or what the type of y was. In my opinion the unclearity did not arise from using var, but from picking unclear variable names. Why not just type:
"But you still cannot see the type of electionResults!" - does it really matter? If you want to change the return type of GetRegionalElectionResults, you can do so. Any IEnumerable will do.
Fast forward to now. People want to align comments en similar code:
So without the comment everything is unclear. And if you don't align the values, you cannot seperate them from the variales. But do you? What about this (ignore the bullets please)
If you need a comment on EVERY LINE, you're doing something wrong. "But you still need to align the VALUES" - do you? what does 38 have to do with 2?
In C# Most code blocks can easily be aligned using only tabs (or acually, multiples of four spaces):
You should never use line-to-line comments and you should rarely need to vertically align things. Rarely, not never. So I understand if some of you guys prefer a monospaced font. I prefer the readibility of font Noto Sans or Source Sans Pro. These fonts are available freely from Google, and resemble Calibri, but are designed for programming and thus have all the neccesary characteristics:
比例字体的主要问题是它们破坏了代码的垂直对齐,这在编写代码时是一个相当大的损失。
垂直对齐使得可以轻松执行剪切、复制、粘贴、删除和缩进、取消缩进等块操作,从而操作跨越多行的矩形代码块。
作为示例,请考虑以下代码片段:
在等宽字体中,= 和 ; 所有行向上。
现在,如果将此文本加载到 Word 中并使用比例字体显示,则文本实际上会变成这样:
注意: 添加额外的空白以显示= 和 ; 如何不再对齐:
随着垂直对齐的消失,那些漂亮的代码块实际上消失了。
另外,由于不再保证光标垂直移动(即,从一行到下一行的列号并不总是恒定),因此编写旨在操纵外观相似的行的废弃宏脚本变得更加困难。
The major problem with proportional fonts is they destroy the vertical alignment of the code and this is a fairly major loss when it comes to writing code.
The vertical alignment makes it possible to manipulate rectangular blocks of code that span multiple lines by allowing block operations like cut, copy, paste, delete and indent, unindent etc to be easily performed.
As an example consider this snippet of code:
In a mono-spaced font the = and the ; all line up.
Now if this text is loded into Word and display using a proportional font the text effectively turns into this:
NOTE: Extra white space added to show how the = and ; no longer line up:
With the vertical alignment gone those nice blocks of code effectively disappear.
Also because the cursor is no longer guaranteed to move vertically (i.e. the column number is not always constant from one line to the next) it makes it more difficult to write throw away macro scripts designed to manipulated similar looking lines.
人们都在抱怨评论不排队。
在我看来,有一个非常简单的解决方案:将单位空间定义为字体中最宽的字符。 现在,按比例间隔除空格之外的所有字符。 该空格占据尽可能多的空间,以便将下一个字符排列在该行上所有前面的字符都是字体中最宽的字符的位置。
即:
iiii_space_Foo
xxxx_space_Foo
将排列“Foo”,“i”之后的空间比“x”之后的空间宽得多。
所以称之为弹性空间。 而不是制表位。
如果你是一个聪明的编辑,请特别对待评论,但这只是肉汁
Folks are all complaining about comments not lining up.
Seems to me that there's a very simple solution: Define the unit space as the widest character in the font. Now, proportionally space all characters except the space. the space takes up as much room so as to line up the next character where it would be if all preceeding characters on the line were the widest in the font.
ie:
iiii_space_Foo
xxxx_space_Foo
would line up the "Foo", with the space after the "i" being much wider than after the "x".
So call it elastic spaces. rather than tab-stops.
If you're a smart editor, treat comments specially, but that's just gravy
您问题的缩进部分今天正在实际产品中完成,尽管自动化程度可能比您想象的更高,我提到的产品是 XSLT IDE,但相同的格式化原则适用于大多数(但不是全部)传统代码语法。
这确实必须在视频中看到才能了解这一切(抱歉音乐回溯) 。 还有一个轻型 XML 编辑器衍生产品 XMLQuire,用作技术演示器。
下面的屏幕截图显示了在此 XSLT IDE 中使用相当复杂的格式规则进行格式化的 XML,其中所有缩进均以文字处理程序样式执行,使用左边距,而不是空格或制表符。
为了强调此格式概念,所有字符均已突出显示,以显示左边距延伸的位置以保持缩进。 我使用术语虚拟格式来描述这一点 - 它不像弹性制表位,因为根本没有制表符,只有作为“段落”格式一部分的边距信息(此处使用 RTF 代码) 。 解析器在与语法着色相同的过程中不断重新格式化。
这里没有使用比例字体,但它本来可以很容易 - 因为缩进是以 TWIPS 为单位设置的。 编辑体验非常引人注目,因为当您重构代码(在本例中为 XML)时,可能通过拖放或扩展属性值的长度,缩进会自行重新调整以适应 - 没有制表符 -键或“重新格式化”按钮按下。
所以,缩进是存在的,但字体工作是一个更复杂的问题。 我已经对此进行了实验,但发现如果在键入时重新选择字体,代码的水平移动会让人分心 - 可能需要用户启动“格式字体”命令。 该产品还内置了用于注释代码的墨水/手写技术,但我尚未在实时版本中利用它。
The indentation part of your question is being done today in a real product, though possibly to even a greater level of automation than you imagined, the product I mention is an XSLT IDE, but the same formatting principles would work with most (but not all) conventional code syntaxes.
This really has to be seen in video to get the sense of it all (sorry about the music back-track). There's also a light XML editor spin-off product, XMLQuire, that serves as a technology demonstrator.
The screenshot below shows XML formatted with quite complex formatting rules in this XSLT IDE, where all indentation is performed word-processor style, using the left margin - not space or tab characters.
To emphasise this formatting concept, all characters have been highlighted to show where the left-margin extends to keep indentation. I use the term Virtual Formatting to describe this - it's not like elastic tab stops, because there simply are no tabs, just margin information which is part of the 'paragraph' formatting (RTF codes are used here). The parser reformats continuously, in the same pass as syntax coloring.
A proportional font hasn't been used here, but it could have been quite easily - because the indentation is set in TWIPS. The editing experience is quite compelling because, as you refactor the code (XML in this case), perhaps through drag and drop, or by extending the length of an attribute value, the indentation just re-flows itself to fit - there's no tab-key or 'reformat' button to press.
So, the indentation is there, but the font work is a more complex problem. I've experimented with this, but found that if fonts are re-selected as you type, the horizontal shifting of the code is too distracting - there would need to be a user-initiated 'format fonts' command probably. The product also has Ink/Handwriting technology built-in for annotating code, but I've yet to exploit this in the live release.
Soeren:在我看来,这很简洁。 但人们真的会像这样排列评论吗? 对于行尾注释,我总是使用一个空格,然后使用 // 或 /* 或同等内容,具体取决于我使用的语言。 我从来没有尝试将声明或评论或任何东西排列起来,我见过的唯一地方就是在教科书中。
Soeren: That's kind of neat, IMO. But do people really line comments up like that? For my end of line comments, I always use a single space then // or /* or equivalent, depending on language I'm using. I never try to line up declarations or comments or anything, and the only place I've ever seen that is in textbooks.
@Brian Ensink:我没有发现这样的代码格式更容易阅读。
就我个人而言,
我发现第一行比第二行更容易阅读。
@Brian Ensink: I don't find code formatted like that easier to read.
versus
I find the first lines easier to read than the second lines, personally.
当我上次查看 Eclipse 时(不久前!),它允许您选择任何已安装的字体来工作。不太确定它是否支持使用制表位缩进的概念。
它看起来很酷,但代码肯定更难阅读......
When I last looked at Eclipse (some time ago now!) it allowed you to choose any installed font to work in. Not so sure whether it supported the notion of indenting using tab stops.
It looked cool, but the code was definitely harder to read...
我想知道为什么没有人真正回答你的问题,以及为什么接受的答案与你的问题没有任何关系。 但无论如何...
比例字体 IDE
在 Eclipse 中,您可以选择系统上的任何字体。
为缩进设置制表位
在 Eclipse 中,您可以配置自动缩进,包括将其设置为“仅制表符”。
排列函数签名和赋值语句行
在 Eclipse 中,自动缩进可以做到这一点。
可以用点而不是固定的字符位置来指定。
抱歉,我认为 Eclipse 无法帮助您。 但它是开源的。 ;-)
粗体和斜体
Eclipse 就有这样的功能。
各种字体大小甚至样式表都会很酷
我认为 Eclipse 只为每种文件类型(例如 Java 源文件)使用一种字体和字体大小,但是您可以为不同的文件类型使用不同的“样式表”不同的文件类型。
I wonder why nobody actually answers your question, and why the accepted answer doesn't really have anything to do with your question. But anyway...
a proportional font IDE
In Eclipse you can cchoose any font on your system.
set tab stops for my indents
In Eclipse you can configure the automatic indentation, including setting it to "tabs only".
lining up function signatures and rows of assignment statements
In Eclipse, automatic indentation does that.
which could be specified in points instead of fixed character positions.
Sorry, I don't think Eclipse can help you there. But it is open source. ;-)
bold and italics
Eclipse has that.
Various font sizes and even style sheets would be cool
I think Eclipse only uses one font and font-size for each file type (for example Java source file), but you can have different "style sheets" for different file types.
@托马斯·欧文斯
没关系,这只是个人喜好,我们可以不同意。 按照您认为最好的方式格式化它,我会尊重它。 我经常问自己“我应该如何格式化这个或那个东西?” 我的答案始终是对其进行格式化以提高可读性,我承认这可能是主观的。
关于您的示例,我只是喜欢在右侧有一个很好对齐的列,它是左侧代码的快速“索引”。 话虽如此,我可能会避免像这样注释每一行,因为代码本身不需要那么多解释。 如果是这样,我倾向于在代码上方写一段话。
但请考虑原始海报中的这个示例。 在我看来,更容易发现第二个中的评论。
@Thomas Owens
That's fine, it is just a personal preference and we can disagree. Format it the way you think is best and I'll respect it. I frequently ask myself 'how should I format this or that thing?' My answer is always to format it to improve readability, which I admit can be subjective.
Regarding your sample, I just like having that nicely aligned column on the right hand side, its sort of a quick "index" into the code on the left. Having said that, I would probably avoid commenting every line like that anyway because the code itself shouldn't need that much explanation. And if it does I tend to write a paragraph above the code.
But consider this example from the original poster. Its easier to spot the comments in the second one in my opinion.
@托马斯·欧文斯
是的,人们确实会发表评论和声明以及各种各样的事情。 格式一致的代码更容易阅读,而更容易阅读的代码也更容易维护。
@Thomas Owens
Yes people do line up comments and declarations and all sorts of things. Consistently well formatted code is easier to read and code that is easier to read is easier to maintain.
我预计你会接受这个建议,但这个想法确实有道理。
代码编辑器中传统“非比例”字体要求的主要优点是减轻执行代码格式化的负担。
但是,随着现代 IDE 中出现的所有交互式自动格式化,比例字体确实有可能提高代码的可读性(而不是阻碍它,正如我确信许多纯粹主义者所期望的那样)。
一个名为 Roedy Green 的角色(因其“如何编写不可维护的代码'文章)写了一种基于 Java 的理论编辑器/语言,称为 巴厘岛。 它并不完全包括非比例字体,但它确实包括使用非统一字体大小的想法。
另外,这篇简短的 Joel Spolsky 帖子 发布到解决方案、弹性选项卡停止(正如另一位评论者所提到的)这将有助于支持非比例(和可变大小)字体。
i expected you'll get down-modded and picked on for that suggestion, but there's some real sense to the idea.
The main advantage of the traditional 'non-proportional' font requirement in code editors is to ease the burden of performing code formatting.
But with all of the interactive automatic formatting that occurs in modern IDE's, it's really possible that a proportional font could improve the readability of the code (rather than hampering it, as i'm sure many purists would expect).
A character called Roedy Green (famous for his 'how to write unmaintainable code' articles) wrote about a theoretical editor/language, based on Java and called Bali. It didn't include non-proportional fonts exactly, but it did include the idea of having non-uniform font-sizes.
Also, this short Joel Spolsky post posts to a solution, elastic tab stops (as mentioned by another commentor) that would help with the support of non-proportional (and variable sized) fonts.
我仍然希望看到流行的编辑器或 IDE 实现弹性制表位。
I'd still like to see a popular editor or IDE implement elastic tabstops.
用风格思考建议使用您最喜欢的文字-Word或Writer等操作软件。 使用丰富的 XML 创建程序代码,并使用 XSLT 提取与编译器相关的部分。 “Office”软件将提供所有高级文本操作和格式化功能。
Thinking with Style suggests to use your favorite text-manipulation software like Word or Writer. Create your programme code in rich XML and extract the compiler-relevant sections with XSLT. The "Office" software will provide all advanced text-manipulation and formatting features.