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 20:09:15 +0200 Message-ID: <87fw5e2ss4.fsf@web.de> References: <87626blih9.fsf@web.de> <87626bjkhu.fsf@web.de> <87mwznhu6f.fsf@web.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1350410960 22435 80.91.229.3 (16 Oct 2012 18:09:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 16 Oct 2012 18:09:20 +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 20:09:28 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 1TOBZz-0007ay-Sl for geh-help-gnu-emacs@m.gmane.org; Tue, 16 Oct 2012 20:09:24 +0200 Original-Received: from localhost ([::1]:33715 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOBZs-0002nB-HJ for geh-help-gnu-emacs@m.gmane.org; Tue, 16 Oct 2012 14:09:16 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:55524) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOBZm-0002n0-Uh for help-gnu-emacs@gnu.org; Tue, 16 Oct 2012 14:09:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TOBZg-0007lO-QF for help-gnu-emacs@gnu.org; Tue, 16 Oct 2012 14:09:10 -0400 Original-Received: from mout.web.de ([212.227.15.4]:53054) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOBZg-0007lE-GT for help-gnu-emacs@gnu.org; Tue, 16 Oct 2012 14:09:04 -0400 Original-Received: from drachen.dragon ([89.204.137.155]) by smtp.web.de (mrweb102) with ESMTPSA (Nemesis) id 0LuuS5-1TWbjr0lbl-010bvH; Tue, 16 Oct 2012 20:09:02 +0200 Mail-Followup-To: help-gnu-emacs@gnu.org In-Reply-To: (Shiyuan's message of "Tue, 16 Oct 2012 09:40:40 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux) X-Provags-ID: V02:K0:FCvilsYTlg5sKgWatLoHCQQIzSh7N4KiSmpjicR01tt zwdsOWV6aUR4lXS8gndyUbYx9gvWwDgip5VwRHaLd4B2loGqlJ GDpJnGWH7BN99sH4IKRs/BQm9d0DZAFNs9mcyjYOKm8w3JQzAM S8nT0bh/0kJiDBmqFKnJ5lzUeie44VGvTpdt8qmDuDn5bV4uR3 Pu0rV+h7Vgbs21fsZun/8fXLYcS1wfzxizVoQlgfLk= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 212.227.15.4 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:87287 Archived-At: Shiyuan writes: > That works. Fine. Maybe also have a look at folding.el, if you don't yet know it: http://www.emacswiki.org/emacs/FoldingMode It uses explicit markers, but therefore works out of the box in any mode. Regards, Michael. > Shiyuan > > On Tue, Oct 16, 2012 at 12:17 AM, Michael Heerdegen wrote: > > Hi again, > > > > 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 > > > Yes, there are two little errors. > > First, you register your mode in `hs-special-modes-alist' after you > enable hs-minor-mode. That's too late, because hideshow then has > already initialized its stuff. Also, adding to `hs-special-modes-alist' > has to be done only once, and not every time mymode is enabled. > > Second, you quoted mymode-forward-sexp-func in your quoted list: > > | '(mymode "\\[begin]" "\\[end]" "#" 'mymode-forward-sexp-func nil)) > ^ > > That's not needed, remember, the quote before a list already prevents > evaluation of its members (you want to specify a symbol). > > So, this should do the trick: > > --8<---------------cut here---------------start------------->8--- > (require 'hideshow) > > (defun mymode-forward-sexp-func (arg) > "move over ARG balanced blocks; This is needed by hs-minor-mode" > (dotimes (number 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))))))) > > > (add-to-list 'hs-special-modes-alist '(mymode "\\[begin]" "\\[end]" "#" mymode-forward-sexp-func)) > > (define-derived-mode mymode fundamental-mode > "mymode is a major mode for fun." > (setq mode-name "mymode") > (setq comment-start "#") > (setq comment-end "") > (hs-minor-mode 1)) > --8<---------------cut here---------------end--------------->8--- > > Of course, that's all just for playing. If mymode was a major-mode > really to be used, you would leave it up to the user to call > `hs-minor-mode' e.g. in `mymode-hook', and not call it in the mode > definition. > > > Michael. >