From: Shiyuan <gshy2014@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: hideshow minor-mode
Date: Mon, 15 Oct 2012 23:20:56 -0500 [thread overview]
Message-ID: <CAOm4EMtPPdS4co856V2UJYTLqsw6jWazdp3yT3SvR-YOEh2=pQ@mail.gmail.com> (raw)
In-Reply-To: <87626bjkhu.fsf@web.de>
[-- Attachment #1: Type: text/plain, Size: 2187 bytes --]
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 <michael_heerdegen@web.de
> 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]" "\\[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.
>
>
>
[-- Attachment #2: Type: text/html, Size: 3100 bytes --]
next prev parent reply other threads:[~2012-10-16 4:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.11001.1350265231.855.help-gnu-emacs@gnu.org>
2012-10-15 18:04 ` hideshow minor-mode Michael Heerdegen
2012-10-15 23:30 ` Shiyuan
[not found] ` <mailman.11078.1350343816.855.help-gnu-emacs@gnu.org>
2012-10-16 1:03 ` Michael Heerdegen
2012-10-16 4:20 ` Shiyuan [this message]
[not found] ` <mailman.11086.1350361261.855.help-gnu-emacs@gnu.org>
2012-10-16 5:17 ` Michael Heerdegen
2012-10-16 14:40 ` Shiyuan
[not found] ` <mailman.11111.1350398455.855.help-gnu-emacs@gnu.org>
2012-10-16 18:09 ` Michael Heerdegen
2012-10-15 1:40 Shiyuan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAOm4EMtPPdS4co856V2UJYTLqsw6jWazdp3yT3SvR-YOEh2=pQ@mail.gmail.com' \
--to=gshy2014@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.