From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Shiyuan Newsgroups: gmane.emacs.help Subject: Re: hideshow minor-mode Date: Mon, 15 Oct 2012 23:20:56 -0500 Message-ID: References: <87626blih9.fsf@web.de> <87626bjkhu.fsf@web.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=e89a8fb1f8d20210c504cc257b91 X-Trace: ger.gmane.org 1350361269 8362 80.91.229.3 (16 Oct 2012 04:21:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 16 Oct 2012 04:21:09 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Oct 16 06:21:12 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TNyeV-0003vu-Jp for geh-help-gnu-emacs@m.gmane.org; Tue, 16 Oct 2012 06:21:11 +0200 Original-Received: from localhost ([::1]:45279 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TNyeO-0006FI-Iw for geh-help-gnu-emacs@m.gmane.org; Tue, 16 Oct 2012 00:21:04 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:51032) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TNyeI-0006FD-RB for help-gnu-emacs@gnu.org; Tue, 16 Oct 2012 00:21:00 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TNyeH-0007K2-HN for help-gnu-emacs@gnu.org; Tue, 16 Oct 2012 00:20:58 -0400 Original-Received: from mail-ob0-f169.google.com ([209.85.214.169]:63536) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TNyeH-0007Js-AQ for help-gnu-emacs@gnu.org; Tue, 16 Oct 2012 00:20:57 -0400 Original-Received: by mail-ob0-f169.google.com with SMTP id va7so6722144obc.0 for ; Mon, 15 Oct 2012 21:20:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=XzIq/6t1woBxA3RZJC/UCiueQP2uIu7lXaDhHly0NrQ=; b=Nk81UZk1n5HosDKnROpZPxf2T6hpCV1TWKHu3so+nA+HQMyuYcFY3BA2tsDYjIkSKI J83zgrKwfoEOW1o88usTl9glMREQShc8GQ6uB2A7R86zYGduyAZFOVLiM9yUxcpIO2hV fLEcue83hM4esx7JrMZ7ciSZJEsJljE+hSEPafFK9HMbaN23lncGvDymW3FMfl2/lv2M 4egooByisAGEMn08HCXRKHy54VE3GccX2L75kIekjxlf6a3lifK27+YFbWu4uZlxLL2M BrUc2WABxxCEf588dSLhflQvxlC4OnV5fk6od3UL+R7w8JrbbQW3pcq+bPbNeQlK0CRW WSBw== Original-Received: by 10.60.26.72 with SMTP id j8mr5607521oeg.68.1350361256431; Mon, 15 Oct 2012 21:20:56 -0700 (PDT) Original-Received: by 10.182.26.110 with HTTP; Mon, 15 Oct 2012 21:20:56 -0700 (PDT) In-Reply-To: <87626bjkhu.fsf@web.de> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.214.169 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 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.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:87279 Archived-At: --e89a8fb1f8d20210c504cc257b91 Content-Type: text/plain; charset=ISO-8859-1 Michael, Thanks for the detailed reply. However, it doesn't work for me. I guess I make a mistake somewhere. Here is mymode.el: http://paste.lisp.org/display/132611 Thanks. On Mon, Oct 15, 2012 at 8:03 PM, Michael Heerdegen wrote: > Shiyuan writes: > > > Yes, that solves the problem. Now, I can turn on hs-minor-mode. > > > > But actually the block in my major mode is defined by tags, not by > > braces/parentheses, like, > > [begin] > > This is the block. > > This is the block. > > [end] > > > > accord to the commentary in the hideshow.el file, we can define the > > BEGIN and the END of the block by regex, this is what I did, > > > > (add-to-list 'hs-special-modes-alist '(mymode "\\[begin]" "\\[end]" > > "#" nil nil)) > > Yes, that's not wrong. > > > However, it doesn't work. Anything else I need to do? > > I'm afraid you'll need to specify a FORWARD-SEXP-FUNC element in your > `hs-special-modes-alist' entry, since the default `forward-sexp' > function won't work for your mode. > > This function must accept one argument ARG and implement moving over ARG > balanced blocks. > > If you don't have something like that yet - I tried the following: > > --8<---------------cut here---------------start------------->8--- > (defun mymode-forward-sexp-func (arg) > (dotimes (_ arg) > (let ((counter 0)) > (catch 'done > (while t > (search-forward-regexp "\\[begin]\\|\\[end]") > (setq counter (+ counter (if (looking-back "\\[begin]") 1 -1))) > (when (= counter 0) (throw 'done t))))))) > --8<---------------cut here---------------end--------------->8--- > > It doesn't check for comments, dunno what else I forgot. But, > if I then use > > (add-to-list 'hs-special-modes-alist '(mymode "\\[begin]" "\\[end]" > "#" my-mode-forward-sexp-func)) > > folding worked for me in a test buffer using your syntax. > > > or is there other packages allow me to fold the source where the > > blocks are defined in this way? > > Fundamentally, hideshow is fine for that. It's just the setup that > isn't trivial. No doubt, there is room for improvement. > > > Regards, > > Michael. > > > --e89a8fb1f8d20210c504cc257b91 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Michael,=A0
Thanks for the detailed reply. However, it doesn'= t work for me. I guess I make a mistake somewhere. Here is mymode.el:=A0

Thanks.=A0

On Mon, Oc= t 15, 2012 at 8:03 PM, Michael Heerdegen <michael_heerdegen@web.de<= /a>> wrote:
Shiyuan <gshy2014@gmail.com> writes:

> Yes, that solves the problem. Now, I can turn on hs-minor-mode.
>
> But actually the block in my major mode is defined by tags, not by
> braces/parentheses, like,
> [begin]
> This is the block.
> This is the block.
> [end]
>
> accord to the commentary in the hideshow.el file, we can define the > BEGIN and the END of the block by regex, this is what I did,
>
> (add-to-list 'hs-special-modes-alist '(mymode "\\[begin]&= quot; "\\[end]"
> "#" nil nil))

Yes, that's not wrong.

> However, it doesn't work. Anything else I need to do?

I'm afraid you'll need to specify a FORWARD-SEXP-FUNC element= in your
`hs-special-modes-alist' entry, since the default `forward-sexp' function won't work for your mode.

This function must accept one argument ARG and implement moving over ARG balanced blocks.

If you don't have something like that yet - I tried the following:

--8<---------------cut here---------------start------------->8---
(defun mymode-forward-sexp-func (arg)
=A0 (dotimes (_ arg)
=A0 =A0 (let ((counter 0))
=A0 =A0 =A0 (catch 'done
=A0 =A0 =A0 =A0 (while t
=A0 =A0 =A0 =A0 =A0 (search-forward-regexp "\\[begin]\\|\\[end]")=
=A0 =A0 =A0 =A0 =A0 (setq counter (+ counter (if (looking-back "\\[beg= in]") 1 -1)))
=A0 =A0 =A0 =A0 =A0 (when (=3D counter 0) (throw 'done t)))))))
--8<---------------cut here---------------end--------------->8---

It doesn't check for comments, dunno what else I forgot. =A0But,
if I then use

(add-to-list 'hs-special-modes-alist '(mymode "\\[begin]"= "\\[end]"
"#" my-mode-forward-sexp-func))

folding worked for me in a test buffer using your syntax.

> or is there other packages allow me to fold the source where the
> blocks are defined in this way?

Fundamentally, hideshow is fine for that. =A0It's just the setup = that
isn't trivial. =A0No doubt, there is room for improvement.


Regards,

Michael.



--e89a8fb1f8d20210c504cc257b91--