* How to set outline-level in the first line?
@ 2007-05-06 11:40 Heinz Tuechler
2007-05-11 0:38 ` Heinz Tuechler
0 siblings, 1 reply; 6+ messages in thread
From: Heinz Tuechler @ 2007-05-06 11:40 UTC (permalink / raw)
To: help-gnu-emacs
Dear All,
To adapt outline-minor-mode to the comment form I use in R, I tried to
adjust the outline-regexp and the outline-level.
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))))
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.
Only if I use eval: (setq outline-level ... it does what I want.
So finally my first line looks as follows:
-*- 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)))) -*-
What I would like to know is, how to set the outline-level without "eval:"?
version information:
GNU Emacs 21.3.1 (i386-mingw-nt5.1.2600) of 2004-03-10 on NYAUMO
Thanks,
Heinz
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to set outline-level in the first line?
2007-05-06 11:40 How to set outline-level in the first line? Heinz Tuechler
@ 2007-05-11 0:38 ` Heinz Tuechler
0 siblings, 0 replies; 6+ messages in thread
From: Heinz Tuechler @ 2007-05-11 0:38 UTC (permalink / raw)
To: help-gnu-emacs
Dear All,
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.
Thanks,
Heinz
At 12:40 06.05.2007 +0100, Heinz Tuechler wrote:
>Dear All,
>
>To adapt outline-minor-mode to the comment form I use in R, I tried to
>adjust the outline-regexp and the outline-level.
>
>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))))
>
>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.
>
>Only if I use eval: (setq outline-level ... it does what I want.
>
>So finally my first line looks as follows:
>-*- 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)))) -*-
>
>What I would like to know is, how to set the outline-level without "eval:"?
>
>version information:
>GNU Emacs 21.3.1 (i386-mingw-nt5.1.2600) of 2004-03-10 on NYAUMO
>
>Thanks,
>Heinz
>
>
>
>
>_______________________________________________
>help-gnu-emacs mailing list
>help-gnu-emacs@gnu.org
>http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to set outline-level in the first line?
[not found] <mailman.505.1178840842.32220.help-gnu-emacs@gnu.org>
@ 2007-05-11 5:08 ` Stefan Monnier
2007-05-11 9:18 ` Heinz Tuechler
2007-05-20 13:07 ` Johan Bockgård
0 siblings, 2 replies; 6+ messages in thread
From: Stefan Monnier @ 2007-05-11 5:08 UTC (permalink / raw)
To: help-gnu-emacs
> 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to set outline-level in the first line?
2007-05-11 5:08 ` Stefan Monnier
@ 2007-05-11 9:18 ` Heinz Tuechler
2007-05-20 13:07 ` Johan Bockgård
1 sibling, 0 replies; 6+ messages in thread
From: Heinz Tuechler @ 2007-05-11 9:18 UTC (permalink / raw)
To: Stefan Monnier, help-gnu-emacs
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
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to set outline-level in the first line?
2007-05-11 5:08 ` Stefan Monnier
2007-05-11 9:18 ` Heinz Tuechler
@ 2007-05-20 13:07 ` Johan Bockgård
2007-06-09 23:58 ` Stefan Monnier
1 sibling, 1 reply; 6+ messages in thread
From: Johan Bockgård @ 2007-05-20 13:07 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> This can't be right. `defun' is a command which is used for its
> side-effect, not its return value.
Emacs Lisp is not Scheme.
(defun foo ()) => foo
--
Johan Bockgård
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to set outline-level in the first line?
2007-05-20 13:07 ` Johan Bockgård
@ 2007-06-09 23:58 ` Stefan Monnier
0 siblings, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2007-06-09 23:58 UTC (permalink / raw)
To: help-gnu-emacs
>> This can't be right. `defun' is a command which is used for its
>> side-effect, not its return value.
> Emacs Lisp is not Scheme.
> (defun foo ()) => foo
Believe me I know. But that doesn't mean that the code I had quoted was
right or that `defun' is a command used for its return value.
Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-06-09 23:58 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-06 11:40 How to set outline-level in the first line? Heinz Tuechler
2007-05-11 0:38 ` Heinz Tuechler
[not found] <mailman.505.1178840842.32220.help-gnu-emacs@gnu.org>
2007-05-11 5:08 ` Stefan Monnier
2007-05-11 9:18 ` Heinz Tuechler
2007-05-20 13:07 ` Johan Bockgård
2007-06-09 23:58 ` Stefan Monnier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).