From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Shiyuan Newsgroups: gmane.emacs.help Subject: Re: hideshow minor-mode Date: Tue, 16 Oct 2012 09:40:40 -0500 Message-ID: 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: multipart/alternative; boundary=e89a8ff1c0d059ff8904cc2e2300 X-Trace: ger.gmane.org 1350398461 30317 80.91.229.3 (16 Oct 2012 14:41:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 16 Oct 2012 14:41:01 +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 16:41:05 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 1TO8KO-0002aX-NV for geh-help-gnu-emacs@m.gmane.org; Tue, 16 Oct 2012 16:41:04 +0200 Original-Received: from localhost ([::1]:40404 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TO8KH-0003Gr-S0 for geh-help-gnu-emacs@m.gmane.org; Tue, 16 Oct 2012 10:40:57 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:57552) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TO8K7-0003Gg-PA for help-gnu-emacs@gnu.org; Tue, 16 Oct 2012 10:40:53 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TO8K1-0000M4-GH for help-gnu-emacs@gnu.org; Tue, 16 Oct 2012 10:40:47 -0400 Original-Received: from mail-ob0-f169.google.com ([209.85.214.169]:40248) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TO8K1-0000Ls-9T for help-gnu-emacs@gnu.org; Tue, 16 Oct 2012 10:40:41 -0400 Original-Received: by mail-ob0-f169.google.com with SMTP id va7so7327381obc.0 for ; Tue, 16 Oct 2012 07:40:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=PcGyvOt3B9HSqxS1cSwu9dOp82ql18CuWQ/omgz/1L4=; b=BGslDc4gBlWln3cVeXjWJUk3VDZSdicY/DiVJo4U1X3/JERkM6NEDvZOYQt3HUy5yi UKFD+TEXSfWTQ3yT6ABSBhGk080El56rvK4WNkOVejAJt0ciwQ+OpOulKer0dd9cpn9s xQCpuLNqz66w7eXyse94+Ip27wQ354GhLLGUo1ZAZqNiEAOnlMRgZ1ESzr5bk9EMRRIu ffvB0HtiEox0vywm1ReI5PTT9VtLoiMDz7RI8MjDEI+Xf+L+hJNbXj7v9WGwNObAeGY2 lPmEdCq5KRUfPhaK8GuJ2EF9db14M0w9ytE/GoxtmVnfXnmleMZ264sZvUZTeMfCQyPR 9q8w== Original-Received: by 10.60.13.9 with SMTP id d9mr12490748oec.92.1350398440504; Tue, 16 Oct 2012 07:40:40 -0700 (PDT) Original-Received: by 10.182.26.110 with HTTP; Tue, 16 Oct 2012 07:40:40 -0700 (PDT) In-Reply-To: <87mwznhu6f.fsf@web.de> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.214.169 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:87285 Archived-At: --e89a8ff1c0d059ff8904cc2e2300 Content-Type: text/plain; charset=ISO-8859-1 Michael, That works. Thank you very much for guiding me into the world of Lisp. Shiyuan On Tue, Oct 16, 2012 at 12:17 AM, Michael Heerdegen < michael_heerdegen@web.de> 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. > > --e89a8ff1c0d059ff8904cc2e2300 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Michael,=A0
That works. Thank you very much for guiding me into the worl= d of Lisp.

Shiyuan =A0

On Tue, Oct 16, 2012 at 12:17 AM, Michael Heerdegen <= ;michael_heer= degen@web.de> wrote:
Hi again,

> Michael,
> Thanks for the detailed reply. However, it doesn't work for me. I<= br> > guess I make a mistake somewhere. Here is mymode.el:
>
> htt= p://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. =A0That's too late, because hideshow then has
already initialized its stuff. =A0Also, adding to `hs-special-modes-alist&#= 39;
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]" "#" =A0&= #39;mymode-forward-sexp-func nil))
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= ^

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)
=A0 "move over ARG balanced blocks; This is needed by hs-minor-mode&qu= ot;
=A0 (dotimes (number arg)
=A0 =A0 (let ((counter 0))
=A0 =A0 =A0 (catch 'done
=A0 =A0 =A0 =A0 (while t
=A0 =A0 =A0 =A0 =A0 (search-forward-regexp "\\[begin]\\|\\[end]")=
=A0 =A0 =A0 =A0 =A0 (setq counter (+ counter (if (looking-back "\\[beg= in]") 1 -1)))
=A0 =A0 =A0 =A0 =A0 (when (=3D counter 0) (throw 'done t)))))))

(add-to-list 'hs-special-modes-alist '(mymode "\\[begin]= " "\\[end]" "#" =A0mymode-forward-sexp-func))

(define-derived-mode mymode fundamental-mode
=A0 "mymode is a major mode for fun."
=A0 (setq mode-name "mymode")
=A0 (setq comment-start "#")
=A0 (setq comment-end "")
=A0 (hs-minor-mode 1))
--8<---------------cut here---------------end--------------->8---

Of course, that's all just for playing. =A0If 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<= br> definition.


Michael.


--e89a8ff1c0d059ff8904cc2e2300--