TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Emacs Tree-sitter custom highlighting

123 点作者 ibobev3 个月前

5 条评论

kleiba3 个月前
Classic Emacs syntax highlighting is based on regular expressions (&quot;font-lock-mode&quot;). Of course, the grammars of programming languages are usually not regular languages but higher up in the language class hierarchy (hi, C++!). But you can get a surprising amount of things right just through the context in which a token appears.<p>For instance, the example of this article (`type` as a keyword vs. `type` as a function) would probably have worked with font-lock-mode as well because you could distinguish the two cases from whether or not a left parenthesis follows the token. But, of course, without proper parsing, there&#x27;s always the possibility of edge cases that you cannot resolve correctly.<p>The interesting cases arise anyway when whatever you have in your buffer does <i>not</i> adhere to the grammar, i.e. you have a syntax error: how does then your syntax highlighter cope with that?
评论 #43227208 未加载
评论 #43227104 未加载
评论 #43226704 未加载
tptacek3 个月前
I&#x27;m genuinely psyched about this. One of the few bits of Elisp I&#x27;ve ever written and used consistently was some goop to drive `hi-lock-mode`, which allows you to highlight arbitrary regexps --- I used it exclusively to highlight tokens. It was unreasonably effective for source code audits, being able to click a variable and then sweep through the code spotting everything that used it. But hi-lock is an afterthought of a package, and Tree-sitter isn&#x27;t. Neat!
vzaliva3 个月前
When I first read about the integration of tree-sitter into Emacs, I was very excited. I work with a DSL, for which I maintain a tree-sitter grammar and highlighting rules. I can view source files with highlighting from the command line, and I was hoping I could now easily re-use this grammar in Emacs to edit files in my DSL with proper highlighting.<p>Unfortunately, it wasn&#x27;t as straightforward as I hoped. You need to create a custom major mode for your language and manually integrate the tree-sitter highlighting.<p>What I&#x27;d really like to see one day is an Emacs mode that allows you to automatically plug in any tree-sitter grammar with just a couple of lines of configuration in your .emacs, and instantly get syntax highlighting. Is that too much to ask?
评论 #43226343 未加载
评论 #43248438 未加载
评论 #43232074 未加载
tsuru3 个月前
Wow authored by person who created Solar Realms Elite... A blast from my past crossing into my present.<p>(A bit reductionist of his many accomplishments in between, I know, it&#x27;s just a thing that&#x27;s hit me in the moment)
评论 #43227713 未加载
wglb3 个月前
This reminds me of an editor that Datalogics produced back in the 1990s that edited SGML-based documents. The formatting could be directed by the context the element was in--the enclosing tags at various levels.