From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Heinz Tuechler Newsgroups: gmane.emacs.help Subject: Re: How to set outline-level in the first line? Date: Fri, 11 May 2007 10:18:03 +0100 Message-ID: <3.0.6.32.20070511101803.00a7f358@pop.gmx.net> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: sea.gmane.org 1178871564 1393 80.91.229.12 (11 May 2007 08:19:24 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 11 May 2007 08:19:24 +0000 (UTC) To: Stefan Monnier ,help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri May 11 10:19:22 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HmQLR-000205-KY for geh-help-gnu-emacs@m.gmane.org; Fri, 11 May 2007 10:19:21 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HmQSq-0003MC-1v for geh-help-gnu-emacs@m.gmane.org; Fri, 11 May 2007 04:27:00 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HmQSQ-0003LF-5y for help-gnu-emacs@gnu.org; Fri, 11 May 2007 04:26:34 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HmQSM-0003Jj-Pf for help-gnu-emacs@gnu.org; Fri, 11 May 2007 04:26:32 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HmQSM-0003JV-0K for help-gnu-emacs@gnu.org; Fri, 11 May 2007 04:26:30 -0400 Original-Received: from mail.gmx.net ([213.165.64.20]) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1HmQKw-00005B-Fh for help-gnu-emacs@gnu.org; Fri, 11 May 2007 04:18:50 -0400 Original-Received: (qmail invoked by alias); 11 May 2007 08:18:49 -0000 Original-Received: from d86-33-228-203.cust.tele2.at (HELO fsa) [86.33.228.203] by mail.gmx.net (mp017) with SMTP; 11 May 2007 10:18:49 +0200 X-Authenticated: #933343 X-Provags-ID: V01U2FsdGVkX1+LqVoBnMaL4d/TAgIFyVdArQ/CM9v11vjvUpGjzt hwGqm2IVFR0muH X-Sender: 933343@pop.gmx.net X-Mailer: QUALCOMM Windows Eudora Light Version 3.0.6 (32) In-Reply-To: Original-References: X-Y-GMX-Trusted: 0 X-detected-kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:43873 Archived-At: Dear Stefan! Thank you for your answer and the explanation. Now it works well. The first line, I tested is: -*- mode: text; mode:outline-minor; outline-regexp:"#\\{2,5\\} "; outline-level: (lambda () (interactive) (cond ((looking-at "##### ") 1)((looking-at "#### ") 2)((looking-at "### ") 3)((looking-at "## ") 4) (t 1000))) -*- For me it has the same effect as: -*- mode: text; mode:outline-minor; outline-regexp:"#\\{2,5\\} "; eval: (setq outline-level (defun outline-level () (interactive) (cond ((looking-at "##### ") 1)((looking-at "#### ") 2)((looking-at "### ") 3)((looking-at "## ") 4) (t 1000)))) -*- I wanted to solve this problem by local variables, because in this way others may use it on a per file basis. For my own use I did as you suggested and added a hook in my .emacs file. Thanks again, Heinz At 01:08 11.05.2007 -0400, Stefan Monnier wrote: >> some days ago I sent the message below to the list. Until now, I did not >> receive any answer. >> I assume, this means, it is not possible to set outline-level as local >> variable in the first line (except by eval:). >> Could one of you experts confirm this opinion? I would be happy about some >> yes/no answer. > >It's definitely possible. But since it's dangerous (in case the file comes >>from someone you don't trust), Emacs should try to make it a bit harder. > >>> The outline-level should be: >>> (setq outline-level (defun outline-level () >>> "adjust outline-level to R-comments" >>> (interactive) >>> (cond ((looking-at "#\\{5\\} ") 1) >>> ((looking-at "#### ") 2) >>> ((looking-at "### ") 3) >>> ((looking-at "## ") 4) >>> (t 1000)))) > >This can't be right. `defun' is a command which is used for its >side-effect, not its return value. Use: > >(setq outline-level (lambda () > "Adjust outline-level to R-comments." > (interactive) > (cond ((looking-at "#\\{5\\} ") 1) > ((looking-at "#### ") 2) > ((looking-at "### ") 3) > ((looking-at "## ") 4) > (t 1000)))) > >instead, or > >(defun my-R-outline-level () > "Adjust outline-level to R-comments." > (interactive) > (cond ((looking-at "#\\{5\\} ") 1) > ((looking-at "#### ") 2) > ((looking-at "### ") 3) > ((looking-at "## ") 4) > (t 1000)))) > >(setq outline-level 'my-R-outline-level) > > >>> I tried to do this in the first line by something like >>> outline-level: (defun outline-level () (interactive) (cond ((looking-at >>> "##### ") 1)((looking-at "#### ") 2)((looking-at "### ") 3)((looking-at "## >>> ") 4) (t 1000))) >>> but I did not find the right way. > >The expression after the : should be a *value*, not an expression: it will >not be evaluated but just directly assigned to the variable. >I.e. > > foo-bar: (+ 3 4) > >will not set `foo-bar' to 7 but to the 3-element list containing the >symbol + and the integers 3 and 4. Luckily (lambda () ...) *is* a value, so > > outline-level: (lambda () (interactive) (cond ((looking-at > "##### ") 1)((looking-at "#### ") 2)((looking-at "### ") 3)((looking-at "## > ") 4) (t 1000))) > >might work (provided you add the necessary -*- around, of course. > >Another option might be to change your R mode with > > (add-hook 'R-mode-hook 'my-R-outline-level) > > >-- Stefan >_______________________________________________ >help-gnu-emacs mailing list >help-gnu-emacs@gnu.org >http://lists.gnu.org/mailman/listinfo/help-gnu-emacs >