修改GNU emacs中TCL的语法突出显示
多年来,我一直在使用Emacs(目前在Ubuntu下的GNU Emacs 26.3),但是当我需要修改或配置Emacs时,我仍然必须折叠。
有人可以帮助我解决以下问题:我正在使用GNU emacs编辑TCL脚本。突出显示很好,除了一个例外:当我将卷曲括号中的列表传递给tcl命令时,卷曲括号中的文本被突出显示,好像它包含tcl 命令。因此,我在正常文本中获得了彩色,如果
, for ,错误等。
我的第一个问题是,是否有一种简单的方法可以停用或修改此特定功能,同时保持其余的语法突出显示完整性?我知道这可能很难或,。
我的第二个问题是:我的TCL文件很特别,因为它们基本上包含了TCL中实现的另一种语言。每当我打开emacs中使用后缀.mylang.tcl
的文件时,我可以自动激活修改的语法突出显示吗?我需要在哪里放置经过修改的突出显示样式文件(实际上,原始文件在哪里?),如何告诉Emacs使用给定后缀的文件使用此突出显示样式文件?我如何保证,即使后缀.mylang.tcl
也以.tcl
的突出显示也会激活,但也以.tcl
结束新的?
非常感谢您的帮助!
I've been using emacs (currently Gnu Emacs 26.3 under Ubuntu) for many years, but I still have to fold when I need to modify or configure emacs.
Can someone please help me with the following problem: I'm using Gnu Emacs to edit Tcl scripts. The highlighting works nicely, with one exception: When I pass a list in curly brackets to a Tcl command, the text in the curly brackets gets highlighted as if it contains Tcl commands. So I get colored if
, for
, error
etc. in normal text.
My first question is, if there's an easy way to deactivate or modify this particular feature while keeping the rest of the syntax highlighting intact? I'm aware that this may be tricky since there's no easy way in Tcl to distinguish between code in curly brackets and other stuff in curly brackets, since code is passed in exactly this way also to commands like while
or if
.
My second question is: My Tcl files are special since they basically contain another language implemented in Tcl. Can I automatically activate a modified syntax highlighting whenever I open a file e.g. with suffix .mylang.tcl
in Emacs? Where do I need to put the modified highlighting style file (actually, where is the original?), how do I tell Emacs to use this highlighting style file for files with the given suffix? How can I guarantee that not the highlighting for .tcl
is activated, even if the suffix .mylang.tcl
also ends in .tcl
, but the new one?
Thanks a lot for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
让我从自下而上回答。
如果点击
ch f tcl-mode ret
,帮助缓冲区说它驻留在tcl.el
中,在此上按ret> ret
揭示了实际文件(在我的系统上,它是/usr/share/emacs/28.1/lisp/progmodes/tcl.el.gz
)。如果您尚未安装来源,也许您只有其编译版本。有一个变量
自动模式alist
,其中包含文件名和模式之间的关联。您可以将类似的内容放在.emacs
文件中:由于这将新模式放在列表的 benter 上,因此它将比原始
tcl具有优先级-mode
。至于您的主要问题,将真实文本和括号引用的命令区分不可行。但是,如果要停用
If
等的字体锁定,这很容易,只需修改tcl-set-font-lock-keywords
函数。仅在内部括号可能很棘手时将其停用,这取决于您想要的。如果您希望牙套的行为像双引号一样,这有点困难,请参阅tcl-syntax-propertize-unction-unction
...在另一项注释上,您可能应该使用双引号的字符串。自然语言,然后整个问题消失了:)这是更自然的(对于那些阅读您的代码的人),除非有字符的 lot 可以逃脱,否则我看不到使用牙套背后的任何动机。 (好吧,可能存在一些效率问题,但是过早的优化是所有邪恶的根源。)
Let me answer from the bottom up.
If you tap
C-h f tcl-mode RET
, the help buffer says that it resides intcl.el
, pressingRET
on that reveals the actual file (on my system it is/usr/share/emacs/28.1/lisp/progmodes/tcl.el.gz
). If you have not installed the sources, maybe you only have its compiled version.There is a variable
auto-mode-alist
that contains associations between file names and modes. You can put something like this in your.emacs
file:Since this puts the new mode at the beginning of the list, it will have precedence over the original
tcl-mode
.As for your main question, differentiating between real text and brace-quoted commands is just not feasible. But if you want to deactivate font-locking of
if
etc., that is easy enough, just modify thetcl-set-font-lock-keywords
function. Deactivating it only when inside braces may be tricky, it depends on what you want. If you want the braces to behave like the double quote, that's a bit more difficult, see thetcl-syntax-propertize-function
...On another note, you should probably use double-quoted strings for natural language, and then the whole problem disappears :) It is more natural (for those reading your code), and unless there are a lot of characters to escape, I cannot see any motivation behind using braces. (Okay, there may be some efficiency issues, but premature optimization is the root of all evil.)