Code folding in Emacs [duplicate]

两盒软妹~` 提交于 2019-12-03 08:17:16

问题


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?


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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.




回答5:


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.




回答6:


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.)



来源:https://stackoverflow.com/questions/1208622/code-folding-in-emacs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!