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 07:17:44 +0200 Message-ID: <87mwznhu6f.fsf@web.de> References: <87626blih9.fsf@web.de> <87626bjkhu.fsf@web.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1350364663 30992 80.91.229.3 (16 Oct 2012 05:17:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 16 Oct 2012 05:17:43 +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 07:17:51 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 1TNzXH-0006ob-L7 for geh-help-gnu-emacs@m.gmane.org; Tue, 16 Oct 2012 07:17:47 +0200 Original-Received: from localhost ([::1]:48726 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TNzXA-0003nk-GS for geh-help-gnu-emacs@m.gmane.org; Tue, 16 Oct 2012 01:17:40 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:56906) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TNzX5-0003n6-7B for help-gnu-emacs@gnu.org; Tue, 16 Oct 2012 01:17:36 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TNzX4-0003Z0-2C for help-gnu-emacs@gnu.org; Tue, 16 Oct 2012 01:17:35 -0400 Original-Received: from mout.web.de ([212.227.15.3]:56811) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TNzX3-0003Ys-Oy for help-gnu-emacs@gnu.org; Tue, 16 Oct 2012 01:17:33 -0400 Original-Received: from drachen.dragon ([89.204.139.251]) by smtp.web.de (mrweb103) with ESMTPSA (Nemesis) id 0LbrZ2-1Tn74C0efM-00jn7u; Tue, 16 Oct 2012 07:17:32 +0200 Mail-Followup-To: help-gnu-emacs@gnu.org In-Reply-To: (Shiyuan's message of "Mon, 15 Oct 2012 23:20:56 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux) X-Provags-ID: V02:K0:5YGjT0DtUnN/st+yQBSSdCsw9e3mbLk3qopzhUe1ttP VPSZfE7jh5VXzzagcNspESrmXh6iXaAWpzpMxkXvWS7Km+Of3L S94g6QB8yICCT8JsECSxMzIlu5V68T+3B4FfjyqwCHHkOVjMZq DMaFVdjgwtZZ2gi908i4k9FlbLRT1w+Xms2+ZCGZq24eAwvKZR p/vQVxgai2F4m4wjYudyWYKlZWR0wqaHFD0Z2xiRfQ= 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:87280 Archived-At: 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.