使用 emacs 处理命令行代码

发布于 2025-01-18 19:26:19 字数 633 浏览 4 评论 0原文

是否可以使用命令行使用emacs从源文件过滤内容。例如,如果要使用emacs过滤来自代码的注释,那么可以从命令行完成吗?

我的理解是emacs具有出色的语言支持< /a>且能力 hide/hide/show comment 在'ui'中。

例如:emacs -strip_comments -trim_trail_whitespace ./myfile.rs将读取文件./ myfile.rs,使用内部语言引擎来解析它所有尾随的空格并剥离所有代码注释。

请不要提供任何“您可以使用GREP或SED”的答案提供任何内容。我想要可以以可靠且一致的方式处理大多数流行语言的东西。

Is it possible to filter content from source files using emacs from command line. For instance, if you want to use emacs to filter out comments from code, can this be done just from command line?

My understanding is that emacs has excellent language support and ability to hide / show comments in the 'ui'.

For example: emacs --strip_comments --trim_trail_whitespace ./myfile.rs would would read the file ./myfile.rs, parse it using the internal language engine, strip out all trailing whitespaces and strip out all code comments.

Please don't provide any 'you can do this with grep or sed' answers. I want something that can handle most popular languages in a dependable and consistent way.

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

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

发布评论

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

评论(1

太阳哥哥 2025-01-25 19:26:19

我决定学习LISP和Emacs来实现此功能。进行了许多不同的尝试,但是我能够获得我想要的功能。

我使用 hideorignorignorecomments 库和一些来自orgmode> orgmode sources的代码想法。

请参阅GitHub中的LISP代码的源回购,请 javascriptdude/javascriptdude/
emacscomstrip

用法:
emacs -file =&lt; path_to_source_code&gt; -Quick - batch -eval'(load“ ./comstrip.lisp”)'

此工具将在&lt; source_code&gt;中使用emacs删除注释,然后写入/tmp /&lt; file_name&gt; _comstrip

只要Emacs具有给定输入语言的语言语义文件,它应该能够以非常可靠的方式剥离评论。

I decided to learn lisp and emacs to get this working. Took many different attempts, but I was able to get the functionality I was looking for.

I used HideOrIgnoreComments library and some code ideas from orgmode sources.

See my source repo for the lisp code in Github at JavaScriptDude /
EmacsComStrip
.

Usage:
emacs --file=<path_to_source_code> --quick --batch --eval '(load "./comstrip.lisp")'

This tool will read in <source_code>, use emacs to strip comments out and the write to /tmp/<file_name>_comstrip

As long as Emacs has the language semantics files for the given input language, it should be able to strip out comments in a very dependable fashion.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文