TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Does Anyone Use Code Folding?

2 pointsby eugenhotajalmost 6 years ago
Does anyone use code folding? If so, what do you feel are the biggest benefits it gives you?<p>Also curious to see if anyone has any strong reasons against it?<p>The main benefit I can see is that you can use the folded code as an outline of the classes&#x2F;functions in the file.

5 comments

ksajalmost 6 years ago
Code folding is awesome for Lisp. Once a function is working, you rarely have to look at it again. Seeing just the first part, eg: +(defun squared (x) tells just about everything you need to know for reference. If not, the documentation string can easily start on that line, too.<p>Of course a fold that pops up the documentation string on mouse-over would be the cream on top.
davidkneelyalmost 6 years ago
I use code folding in Xcode to quickly check if a method is being used in the code base. Code folding allows me to shrink down the amount of scrolling I need to do. Code folding allows me to access the methods I&#x27;m checking on that might be &quot;below the fold.&quot;
galacticdessertalmost 6 years ago
Yep, and I here when people do not align line comments properly
评论 #20004346 未加载
kazinatoralmost 6 years ago
I use code folding when editing the TXR man page, because it&#x27;s close to 69000 lines long. I developed some custom Vim folding rules for that. Here is what it looks like fully folded:<p><pre><code> +--353 lines: .\&quot; t &#x27;\&quot; vim:set syntax=groff:----------------------------------------------------------------- +-- 3 lines: .SH* NAME--------------------------------------------------------------------------------------- +-- 5 lines: .SH* SYNOPSIS----------------------------------------------------------------------------------- +-- 54 lines: .SH* DESCRIPTION-------------------------------------------------------------------------------- +--563 lines: .SH* ARGUMENTS AND OPTIONS---------------------------------------------------------------------- +-- 47 lines: .SH* STATUS AND ERROR REPORTING----------------------------------------------------------------- +--2290 lines: .SH* BASIC TXR SYNTAX-------------------------------------------------------------------------- +--7519 lines: .SH* DIRECTIVES-------------------------------------------------------------------------------- +--2238 lines: .SH* TXR LISP---------------------------------------------------------------------------------- +--47280 lines: .SH* LISP OPERATOR, FUNCTION AND MACRO REFERENCE---------------------------------------------- +--4613 lines: .SH* FOREIGN FUNCTION INTERFACE---------------------------------------------------------------- +--1306 lines: .SH* LISP COMPILATION-------------------------------------------------------------------------- +--1114 lines: .SH* INTERACTIVE LISTENER---------------------------------------------------------------------- +-- 98 lines: .SH* SETUID&#x2F;SETGID OPERATION-------------------------------------------------------------------- +--149 lines: .SH* STAND-ALONE APPLICATION SUPPORT------------------------------------------------------------ +-- 4 lines: .SH* DEBUGGER----------------------------------------------------------------------------------- +--852 lines: .SH* COMPATIBILITY------------------------------------------------------------------------------ +--315 lines: .SH* APPENDIX----------------------------------------------------------------------------------- </code></pre> Then if we open, say, the FOREIGN FUNCTION INTERFACE section, that looks like this:<p><pre><code> .SH* FOREIGN FUNCTION INTERFACE +--- 35 lines: On platforms where it is supported, \*(TX provides a feature called the------------------------ +--- 21 lines: .SS* Cautionary Notes-------------------------------------------------------------------------- +--- 79 lines: .SS* Key Concepts------------------------------------------------------------------------------ +--- 53 lines: .SS* The FFI Type System----------------------------------------------------------------------- +---428 lines: .SS* Simple FFI Types-------------------------------------------------------------------------- +---1091 lines: .SS* Parametrized FFI Type Operators---------------------------------------------------------- +--- 12 lines: .SS* Additional Types-------------------------------------------------------------------------- +--- 69 lines: .SS* Endian Types------------------------------------------------------------------------------ +--- 95 lines: .SS* Bitfield Allocation Rules----------------------------------------------------------------- +--- 44 lines: .SS* FFI Call Descriptors---------------------------------------------------------------------- +---491 lines: .SS* Foreign Function Type API----------------------------------------------------------------- +---544 lines: .SS* Foreign Function Macro Language----------------------------------------------------------- +---157 lines: .SS* Zero-filled Object Support---------------------------------------------------------------- +---177 lines: .SS* Foreign Unions---------------------------------------------------------------------------- +--- 91 lines: .SS* FFI-type-driven I&#x2F;O Functions------------------------------------------------------------- +---227 lines: .SS* Buffer Functions-------------------------------------------------------------------------- +---997 lines: .SS* Foreign Arrays---------------------------------------------------------------------------- </code></pre> The Vim setup is this:<p><pre><code> :au BufRead,BufNewFile txr.1 set foldmethod=expr | set foldexpr=TxrManFoldLevel(v:lnum) :function TxrManFoldLevel(lno) : let s:line = getline(a:lno) : if a:lno == 1 : return &quot;&gt;1&quot; : elseif s:line =~# &#x27;^\.SH&#x27; : return &quot;&gt;1&quot; : elseif s:line =~# &#x27;^\.SS&#x27; : return &quot;&gt;2&quot; : elseif s:line =~# &#x27;^\.NP&#x27; || s:line =~# &#x27;^\.co\(NP\|SS\)&#x27; : return &quot;&gt;3&quot; : elseif s:line =~# &#x27;^\.desc&#x27; || s:line =~# &#x27;^\.TP&#x27; : return &quot;&gt;4&quot; : elseif s:line =~# &#x27;^\...IP&#x27; || s:line =~# &#x27;^\.IP&#x27; : return &quot;&gt;5&quot; : elseif s:line =~# &#x27;^\.TH&#x27; : return &quot;&lt;1&quot; : elseif a:lno == 1 : return &quot;&gt;1&quot; : elseif getline(a:lno-1) == &quot;&quot; &amp;&amp; s:line != &quot;&quot; : return &quot;&gt;6&quot; : else : return &quot;=&quot; : endif :endf </code></pre> It has quirks, but does the job more or less.
mantawolfalmost 6 years ago
I use it constantly. It helps visualize code flow in larger files by collapsing branches of loops or conditionals.