Shiyuan <gshy2014@gmail.com> writes:Yes, that's not wrong.
> 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))
I'm afraid you'll need to specify a FORWARD-SEXP-FUNC element in your
> However, it doesn't work. Anything else I need to do?
`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
"#" my-mode-forward-sexp-func))
(add-to-list 'hs-special-modes-alist '(mymode "\\[begin]" "\\[end]"
folding worked for me in a test buffer using your syntax.
Fundamentally, hideshow is fine for that. It's just the setup that
> or is there other packages allow me to fold the source where the
> blocks are defined in this way?
isn't trivial. No doubt, there is room for improvement.
Regards,
Michael.