From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.help Subject: Re: hideshow minor-mode Date: Tue, 16 Oct 2012 03:03:57 +0200 Message-ID: <87626bjkhu.fsf@web.de> References: <87626blih9.fsf@web.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1350349433 25006 80.91.229.3 (16 Oct 2012 01:03:53 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 16 Oct 2012 01:03:53 +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 03:04:01 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 1TNvZg-00041i-Rv for geh-help-gnu-emacs@m.gmane.org; Tue, 16 Oct 2012 03:04:00 +0200 Original-Received: from localhost ([::1]:39409 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TNvZZ-0006PN-U3 for geh-help-gnu-emacs@m.gmane.org; Mon, 15 Oct 2012 21:03:53 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:60224) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TNvZU-0006PI-AA for help-gnu-emacs@gnu.org; Mon, 15 Oct 2012 21:03:49 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TNvZS-0001pg-RT for help-gnu-emacs@gnu.org; Mon, 15 Oct 2012 21:03:48 -0400 Original-Received: from mout.web.de ([212.227.15.3]:52723) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TNvZS-0001pZ-I9 for help-gnu-emacs@gnu.org; Mon, 15 Oct 2012 21:03:46 -0400 Original-Received: from drachen.dragon ([89.204.139.251]) by smtp.web.de (mrweb002) with ESMTPSA (Nemesis) id 0MOB3E-1TIPn22qou-0061Xe; Tue, 16 Oct 2012 03:03:45 +0200 Mail-Followup-To: help-gnu-emacs@gnu.org In-Reply-To: (Shiyuan's message of "Mon, 15 Oct 2012 18:30:09 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux) X-Provags-ID: V02:K0:xg7mrJ70dGwcJd5QnqQNaOt5cQy0rBG1KFfmssllJjt xyYd/huMsN0fo3fLw8c4DGahGwOo6GG47+VYV01foUANDXbcLe v+UmxjlYdfFMPkWqIYbCOxwk24gGHkVjdf5wKIvVQLW4MULIhZ ZgJRQLccO2DhkB4ykJRp6b70LN+Wl1T1/R6NiZonslODfqnLfn 9GpK5vi4AKegyJ4DPMmXFphKDzvZPt/5uJHtZgKDqk= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 212.227.15.3 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:87277 Archived-At: 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.