From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: How to set outline-level in the first line? Date: Fri, 11 May 2007 01:08:47 -0400 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1178861663 27526 80.91.229.12 (11 May 2007 05:34:23 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 11 May 2007 05:34:23 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri May 11 07:34: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 1HmNll-0008Ak-TH for geh-help-gnu-emacs@m.gmane.org; Fri, 11 May 2007 07:34:22 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HmNt9-0006u8-JQ for geh-help-gnu-emacs@m.gmane.org; Fri, 11 May 2007 01:41:59 -0400 Original-Path: shelby.stanford.edu!headwall.stanford.edu!newsfeed.news2me.com!nx01.iad01.newshosting.com!newshosting.com!216.196.98.140.MISMATCH!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.umontreal.ca!news.umontreal.ca.POSTED!not-for-mail Original-NNTP-Posting-Date: Fri, 11 May 2007 00:08:47 -0500 Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux) Cancel-Lock: sha1:cat3EFuoFEjQOEcCSpuv63LJeyQ= Original-Lines: 73 Original-NNTP-Posting-Host: 132.204.27.213 Original-X-Trace: sv3-upw6AwvUUmBRmOAIsho/f1fpQIMjevSOCyaXl4T45e5oyCKY+i5HR0UkUal9luiAxIBsKe5Xbl7hJf6!v3psWR+JAN33wJ4vj0eAXbIAQ8ProIGUPqFTu56pp90U9u25bsk0kvLrmhYnZzg+VyIVZw9FkOh2!d8ae0M6dq6PhrGsshA== Original-X-Complaints-To: abuse@umontreal.ca X-DMCA-Complaints-To: abuse@umontreal.ca X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.34 Original-Xref: shelby.stanford.edu gnu.emacs.help:148286 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:43871 Archived-At: > 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