From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: tolugboji Newsgroups: gmane.emacs.help Subject: Code folding in Emacs. Date: Sun, 10 Oct 2021 12:42:43 +0000 Message-ID: <74ZiFVBMtcJQPpNimEwakA_TcGNYwo1-d06PlsqK9PwzAgiqkTEV1uNjcnofSFWhUgQLC1Gxj0YpXqO7ndyY_sjDHQGz6tCIpiNncGCaGTU=@protonmail.com> References: Reply-To: tolugboji Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10509"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs To: Hongyi Zhao Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Oct 10 14:43:41 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mZYB3-0002Y1-Fl for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 10 Oct 2021 14:43:41 +0200 Original-Received: from localhost ([::1]:39466 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZYB2-0006zA-Ed for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 10 Oct 2021 08:43:40 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42974) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZYAJ-0006yv-J1 for help-gnu-emacs@gnu.org; Sun, 10 Oct 2021 08:42:55 -0400 Original-Received: from mail-4318.protonmail.ch ([185.70.43.18]:42363) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZYAF-0002xy-Rl for help-gnu-emacs@gnu.org; Sun, 10 Oct 2021 08:42:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1633869764; bh=rdt3xaqI3/TCG1V086Wo7K1qNtK4MOGkQdBqLp6sdQA=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=Dt57h1D5LIKV6MVeAzRSV8J+iUoNFf45ilhucFfM8UnN+VW0jo/E731FJT1b3OsTT Wzz5HE7RcIpSB73nDBf9GoUogVQT4TvCxWzauWYRf7gKCg6746sWOvf+CP+R21YtJP /NO1PJLX6LjpuNTwBa6bwMIDcoLzZxcrrWeX/KgA= In-Reply-To: Received-SPF: pass client-ip=185.70.43.18; envelope-from=tolugboji@protonmail.com; helo=mail-4318.protonmail.ch X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, FREEMAIL_REPLYTO=1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:133668 Archived-At: =E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90 Original Me= ssage =E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90 On Sunday, October 10th, 2021 at 11:54 AM, Hongyi Zhao wrote: > On Sun, Oct 10, 2021 at 7:37 PM tolugboji tolugboji@protonmail.com wrote: > > > Emacs should develop code folding (opening and closing) to also work wi= th the mouse. > > The code snippet I posted above is based on an idea here [1], as shown be= low: > > -------------------------------------------------------------------------= ------- > > Outlines and Overviews > > SelectiveDisplay =E2=80=93 a poor-man=E2=80=99s OutlineMode. It hides lin= es with more > > than the provided number of spaces in front. It can help in getting a > > quick overview of files as long as paragraph lines are further > > indented than headlines. This is great for viewing man pages: =E2=80= =98C-u 1 > > M-x set-selective-display=E2=80=99 to show only headings, `M-x RET= =E2=80=99 to > > disable it again. > > More SelectiveDisplay: =E2=80=98set-selective-display=E2=80=99 is `C-x$= =E2=80=99 by default. > > You can make it a lot friendlier with a wrapper: =E2=80=93 DaleWiles > > (global-set-key "\C-x$" 'set-selective-display-dlw) > > (defun set-selective-display-dlw (&optional level) > > "Fold text indented more than the cursor. > > If level is set, set the indent level to level. > > 0 displays the entire buffer." > > (interactive "P") > > (set-selective-display (or level (current-column)))) > -------------------------------------------------------------------------= ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= --- > > It seems the idea was initiated by DaleWiles, but his/her homepage > > given on emacswiki [2] is empty. > > Another note, though there are already several code-folding relevant > > packages available on melpa [3-5]. In my opinion, this concise and > > clear code snippet is suitable for any programming language that uses > > indented semantic blocks, and it beats all relevant packages found on > > melpa. Because it is such a basic operation many would like to use, emacs should p= rovide it from itself. Currently outline-minor-mode in too complicated and inconsist= ent to be used regularly. Using a long string of *** is difficult to understand, whe= reas a hierarchy based on numeric values is better. An additional problem is that= Headings Folding and Code Folding are dealt as they are the same. Very bad idea. > [1] https://www.emacswiki.org/emacs/EmacsNiftyTricks#h5o-6 > > [2] https://www.emacswiki.org/emacs/DaleWiles > > [3] https://github.com/gregsexton/origami.el > > [4] https://github.com/matsievskiysv/vimish-fold > > [5] https://github.com/emacsorphanage/yafolding > > HZ > > > =E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90 Origina= l Message =E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80= =90 > > > > On Sunday, October 10th, 2021 at 8:16 AM, Hongyi Zhao hongyi.zhao@gmail= .com wrote: > > > > > I just found the following code snippet from here [1] for code foldin= g in Emacs: > > > > > > (global-set-key (kbd "") 'set-selective-display-dlw) > > > > > > (defun set-selective-display-dlw (&optional level) > > > > > > "Fold text indented same of more than the cursor. > > > > > > If level is set, set the indent level to LEVEL. > > > > > > If 'selective-display' is already set to LEVEL, clicking > > > > > > F5 again will unset 'selective-display' by setting it to 0." > > > > > > (interactive "P") > > > > > > (if (eq selective-display (1+ (current-column))) > > > > > > (set-selective-display 0) > > > > > > (set-selective-display (or level (1+ (current-column)))))) > > > > > > The above code trick seems very simple, but it works for many > > > > > > languages. So I recommend it here. > > > > > > [1] https://discourse.julialang.org/t/code-folding-for-emacs/41421/3 > > > > > > Regards > > > ------- > > > > > > Assoc. Prof. Hongyi Zhao hongyi.zhao@gmail.com > > > > > > Theory and Simulation of Materials > > > > > > Hebei Vocational University of Technology and Engineering > > > > > > No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province