help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: hideshow minor-mode


From: Shiyuan
Subject: Re: hideshow minor-mode
Date: Mon, 15 Oct 2012 23:20:56 -0500

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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]