Emacs 中的代码折叠

发布于 2024-07-29 03:42:39 字数 551 浏览 3 评论 0 原文

可能的重复:
如何在emacs中实现代码折叠效果

的一个优秀功能Dreamweaver 是任意文本行的代码折叠——递归!

太棒了,我可以折叠任何文本或代码,无论语言如何。 我使用现有系统; 我不会编辑编写良好的代码或用一种语言等编写的代码。主要是 HTML 与天知道什么混合在一起。 折叠线使理解很多变得更加容易和快捷。 遗憾的是,这是 Dreamweaver 中我喜欢的唯一功能。

Emacs 是否有类似目标的代码折叠?

Possible Duplicate:
How to achieve code folding effects in emacs

An excellent feature of Dreamweaver is code folding of any lines of text -- recursively!

It's fantastic, I can fold any text or code, regardless of language. I work with existing systems; I don't edit well-written code or code in one language etc. mostly HTML mixed with god-knows-what. Folding lines makes understanding a lot easier and quicker. Sadly, this is the only feature I like in Dreamweaver.

Is there any code folding for Emacs in a similar aim?

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

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

发布评论

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

评论(6

好菇凉咱不稀罕他 2024-08-05 03:42:40

我使用fold-dwim.el。 来自 emacs wiki:

fold-dwim.el 是 Emacs 折叠/大纲模式的统一用户界面。 它支持folding.el、hideshow.el、outline.el、TeX-fold.el 和nxml-outln.el

您可以在此处获取它:

http://www.emacswiki.org/emacs/FoldDwim

我的 .emacs 中有这个:

(require 'fold-dwim)
(global-set-key [(C kp-4)] 'fold-dwim-hide-all)
(global-set-key [(C kp-5)] 'fold-dwim-toggle)
(global-set-key [(C kp-6)] 'fold-dwim-show-all)

请记住,您仍然需要激活 hs-minor-mode,folding-模式等,但我发现这样使用它们更容易。

I use fold-dwim.el. From the emacs wiki:

fold-dwim.el is a unified user interface for Emacs folding/outlining modes. It supports folding.el, hideshow.el, outline.el, TeX-fold.el, and nxml-outln.el

You can get it here:

http://www.emacswiki.org/emacs/FoldDwim

I have this in my .emacs:

(require 'fold-dwim)
(global-set-key [(C kp-4)] 'fold-dwim-hide-all)
(global-set-key [(C kp-5)] 'fold-dwim-toggle)
(global-set-key [(C kp-6)] 'fold-dwim-show-all)

Keep in mind that you still need to activate hs-minor-mode, folding-mode, etc. but I find it easier to use them this way.

以往的大感动 2024-08-05 03:42:40

您可能会研究的其他内容是 nxhtml-mode; 它不会折叠代码,但它会根据其类型以不同的方式突出显示混合代码(即 HTML 和 PHP)。 这使您在可理解性方面获得了类似的增益,而没有折叠模式的尴尬。 我认为无论如何,这种方法更适合 Emacs,首先是因为代码折叠似乎是一种面向鼠标的想法,不能很好地适应基本上以键盘为中心的 Emacs 界面,其次是因为 Emacs 在一定程度上简化了大文件的导航该代码可以保持可见而不会妨碍您。

Something else you might look into is nxhtml-mode; it doesn't fold code, but it does highlight mixed code (i.e. HTML and PHP) differently depending on its type. That gives you a similar gain in comprehensibility without the awkwardness of folding-mode. I think that approach is more suited to Emacs anyway, first because code-folding seems like a mouse-oriented idea that doesn't adapt well to the basically keyboard-centric Emacs interface, and second because Emacs eases navigating a large file to an extent that code can stay visible without getting in your way.

叹沉浮 2024-08-05 03:42:40

如果您实际上需要“隐藏给定区域的东西,而不是试图理解语法”(与 hideshow 和其他基于解析的解决方案不同)并且您“不想编辑[您的]代码”(与折叠不同) ,那么,我认为,您的意思是您不希望这些区域在不同的编辑会话之间保持不变。 然后你可以使用 http://www.emacswiki.org/emacs/HideRegion 来隐藏用户- 选定的区域...

(但这很奇怪。带有持久标记的折叠次要模式似乎是一个更方便的解决方案。)

If you actually need "something to hide a given region rather than it trying to understand the syntax" (unlike hideshow and other solutions based on parsing) and you "don't want to have to edit [your] code" (unlike folding), then, I assume, you mean you don't want the regions to be persistent between different editing sessions. Then you might use http://www.emacswiki.org/emacs/HideRegion to hide user-selected regions...

(But that's strange. The folding minor mode with persistent marks seems to be a far more convenient solution.)

银河中√捞星星 2024-08-05 03:42:39

折叠模式,一种次要模式。 不幸的是,它具有侵入性:您必须使用专门的注释手动注释折叠,当您不使用该模式时(或与不使用该模式的其他人共享代码时),这会使代码变得混乱。 更好的模式不会改变您的代码以使其正常工作。

让我补充一下:有一个重复的内容值得一看:如何在Emacs中实现代码折叠效果

There's folding mode, a minor mode. Unfortunately it's intrusive: you have to manually annotate the folds with specialized comments, which clutter the code when you aren't using the mode (or when sharing code with others who don't use it). A better mode would not change your code to work.

Let me add: there's a duplicate of this that's worth a look: How to achieve code folding effects in Emacs.

猫弦 2024-08-05 03:42:39

hide-show (hs-minor-mode) 是一种次要模式,它将执行类似以下操作...

触发折叠的默认键绑定是 Cc @ Cc我觉得这很麻烦。 但我也不怎么用它。

hide-show (hs-minor-mode) is a minor mode that will do something like this...

The default key-binding to trigger the folding is C-c @ C-c which I find pretty cumbersome. But then I don't use it much, either.

小霸王臭丫头 2024-08-05 03:42:39

您可能需要查找函数 set-selective-display 和变量 selective-display。 不完全是您想要的,但它可以让您根据缩进级别隐藏行。

You might want to look up the function set-selective-display and the variable selective-display. Not exactly what you want but it lets you hide lines based on indentation level.

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