unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* lisp-outline-level.
@ 2005-02-13 15:59 Lute Kamstra
  2005-02-13 16:37 ` lisp-outline-level David Kastrup
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Lute Kamstra @ 2005-02-13 15:59 UTC (permalink / raw)


In (Emacs) Lisp mode, outline-regexp is ";;;;* [^ \t\n]\\|(" and
outline-level is lisp-outline-level:

(defun lisp-outline-level ()
  "Lisp mode `outline-level' function."
  (if (looking-at "(\\|;;;###autoload")
      1000
    (looking-at outline-regexp)
    (- (match-end 0) (match-beginning 0))))

This is a bit strange as outline-regexp doesn't match
";;;###autoload".  Shall I commit the patch below?

Lute.


*** lisp/emacs-lisp/lisp-mode.el	1 Feb 2005 15:48:50 -0000	1.171
--- lisp/emacs-lisp/lisp-mode.el	13 Feb 2005 11:03:02 -0000
***************
*** 212,223 ****
  
  (defun lisp-outline-level ()
    "Lisp mode `outline-level' function."
!   (if (looking-at "(\\|;;;###autoload")
        1000
-     (looking-at outline-regexp)
      (- (match-end 0) (match-beginning 0))))
  
- 
  (defvar lisp-mode-shared-map
    (let ((map (make-sparse-keymap)))
      (define-key map "\t" 'lisp-indent-line)
--- 212,221 ----
  
  (defun lisp-outline-level ()
    "Lisp mode `outline-level' function."
!   (if (eq (following-char) ?\()
        1000
      (- (match-end 0) (match-beginning 0))))
  
  (defvar lisp-mode-shared-map
    (let ((map (make-sparse-keymap)))
      (define-key map "\t" 'lisp-indent-line)

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: lisp-outline-level.
  2005-02-13 15:59 lisp-outline-level Lute Kamstra
@ 2005-02-13 16:37 ` David Kastrup
  2005-02-13 17:06   ` lisp-outline-level Lute Kamstra
  2005-02-13 16:56 ` lisp-outline-level Stefan Monnier
  2005-02-15  6:19 ` lisp-outline-level Richard Stallman
  2 siblings, 1 reply; 15+ messages in thread
From: David Kastrup @ 2005-02-13 16:37 UTC (permalink / raw)
  Cc: emacs-devel

Lute Kamstra <Lute.Kamstra.lists@xs4all.nl> writes:

> In (Emacs) Lisp mode, outline-regexp is ";;;;* [^ \t\n]\\|(" and
> outline-level is lisp-outline-level:
>
> (defun lisp-outline-level ()
>   "Lisp mode `outline-level' function."
>   (if (looking-at "(\\|;;;###autoload")
>       1000
>     (looking-at outline-regexp)
>     (- (match-end 0) (match-beginning 0))))
>
> This is a bit strange as outline-regexp doesn't match
> ";;;###autoload".

Why is that strange?  outline-regexp is not even consulted when
;###autoload is found, so I don't see how it would come into play
here.

> Shall I commit the patch below?

> *** lisp/emacs-lisp/lisp-mode.el	1 Feb 2005 15:48:50 -0000	1.171
> --- lisp/emacs-lisp/lisp-mode.el	13 Feb 2005 11:03:02 -0000
> ***************
> *** 212,223 ****
>   
>   (defun lisp-outline-level ()
>     "Lisp mode `outline-level' function."
> !   (if (looking-at "(\\|;;;###autoload")
>         1000
> -     (looking-at outline-regexp)
>       (- (match-end 0) (match-beginning 0))))
>   
> - 
> --- 212,221 ----
>   
>   (defun lisp-outline-level ()
>     "Lisp mode `outline-level' function."
> !   (if (eq (following-char) ?\()
>         1000
>       (- (match-end 0) (match-beginning 0))))

The patch is completely nonsensical.  It returns rubbish in almost all
cases since it is the "looking-at" that established match-end and
match-beginning in the first place.

However, the original code also is buggy since it returns nonsense in
case outline-regexp does not match at point.  So one should probably
rather write

        (and (looking-at outline-regexp)
             (- (match-end 0) (match-beginning 0)))

as the last lines.  This will return "nil" instead of a nonsensical
value in case there is no match at point.  I don't know how and where
lisp-outline-level is used, so maybe some other value (1000?) would be
more appropriate than nil.  But returning some random value (which
includes a segmentation violation, by the way) in case that none of
the two looking-at expressions succeeded does not seem like a good
idea in any case.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: lisp-outline-level.
  2005-02-13 15:59 lisp-outline-level Lute Kamstra
  2005-02-13 16:37 ` lisp-outline-level David Kastrup
@ 2005-02-13 16:56 ` Stefan Monnier
  2005-02-13 17:35   ` lisp-outline-level Lute Kamstra
  2005-02-13 17:48   ` lisp-outline-level David Kastrup
  2005-02-15  6:19 ` lisp-outline-level Richard Stallman
  2 siblings, 2 replies; 15+ messages in thread
From: Stefan Monnier @ 2005-02-13 16:56 UTC (permalink / raw)
  Cc: emacs-devel

> (defun lisp-outline-level ()
>   "Lisp mode `outline-level' function."
>   (if (looking-at "(\\|;;;###autoload")
>       1000
>     (looking-at outline-regexp)
>     (- (match-end 0) (match-beginning 0))))

> This is a bit strange as outline-regexp doesn't match
> ";;;###autoload".  Shall I commit the patch below?

Why did you assume that the ;;;###autoload thingy got there by mistake?
Wouldn't it be better to fix outline-regexp?


        Stefan

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: lisp-outline-level.
  2005-02-13 16:37 ` lisp-outline-level David Kastrup
@ 2005-02-13 17:06   ` Lute Kamstra
  2005-02-13 17:37     ` lisp-outline-level David Kastrup
  0 siblings, 1 reply; 15+ messages in thread
From: Lute Kamstra @ 2005-02-13 17:06 UTC (permalink / raw)
  Cc: emacs-devel

David Kastrup <dak@gnu.org> writes:

> Lute Kamstra <Lute.Kamstra.lists@xs4all.nl> writes:
>
>> In (Emacs) Lisp mode, outline-regexp is ";;;;* [^ \t\n]\\|(" and
>> outline-level is lisp-outline-level:
>>
>> (defun lisp-outline-level ()
>>   "Lisp mode `outline-level' function."
>>   (if (looking-at "(\\|;;;###autoload")
>>       1000
>>     (looking-at outline-regexp)
>>     (- (match-end 0) (match-beginning 0))))
>>
>> This is a bit strange as outline-regexp doesn't match
>> ";;;###autoload".
>
> Why is that strange?  outline-regexp is not even consulted when
> ;###autoload is found, so I don't see how it would come into play
> here.
>
>> Shall I commit the patch below?
>
>> *** lisp/emacs-lisp/lisp-mode.el	1 Feb 2005 15:48:50 -0000	1.171
>> --- lisp/emacs-lisp/lisp-mode.el	13 Feb 2005 11:03:02 -0000
>> ***************
>> *** 212,223 ****
>>   
>>   (defun lisp-outline-level ()
>>     "Lisp mode `outline-level' function."
>> !   (if (looking-at "(\\|;;;###autoload")
>>         1000
>> -     (looking-at outline-regexp)
>>       (- (match-end 0) (match-beginning 0))))
>>   
>> - 
>> --- 212,221 ----
>>   
>>   (defun lisp-outline-level ()
>>     "Lisp mode `outline-level' function."
>> !   (if (eq (following-char) ?\()
>>         1000
>>       (- (match-end 0) (match-beginning 0))))
>
> The patch is completely nonsensical.  It returns rubbish in almost all
> cases since it is the "looking-at" that established match-end and
> match-beginning in the first place.

The variables outline-regexp and outline-level are used by Outline
minor mode.  Did you take a look at their docstrings?  Outline minor
mode searches for matches of outline-regexp and at each match the
function in outline-level is called to determine the nesting level:

,----[ C-h v outline-level RET ]
| outline-level's value is outline-level
| 
| *Function of no args to compute a header's nesting level in an outline.
| It can assume point is at the beginning of a header line and that the match
| data reflects the `outline-regexp'.
| 
| Defined in `outline'.
`----

Does my patch make more sense now?

Lute.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: lisp-outline-level.
  2005-02-13 16:56 ` lisp-outline-level Stefan Monnier
@ 2005-02-13 17:35   ` Lute Kamstra
  2005-02-13 17:48   ` lisp-outline-level David Kastrup
  1 sibling, 0 replies; 15+ messages in thread
From: Lute Kamstra @ 2005-02-13 17:35 UTC (permalink / raw)
  Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> (defun lisp-outline-level ()
>>   "Lisp mode `outline-level' function."
>>   (if (looking-at "(\\|;;;###autoload")
>>       1000
>>     (looking-at outline-regexp)
>>     (- (match-end 0) (match-beginning 0))))
>
>> This is a bit strange as outline-regexp doesn't match
>> ";;;###autoload".  Shall I commit the patch below?
>
> Why did you assume that the ;;;###autoload thingy got there by
> mistake?

Ah, I see you put it in.

> Wouldn't it be better to fix outline-regexp?

I figured that an ;;;###autoload line is not a heading.  If you do
make it a heading, then a thus autoloaded function would become a
two-headed monster.  But maybe I was too rigid in my thinking.  I
suppose you want it added as a heading so that hiding the body of the
previous function doesn't hide the fact that the current function is
autoloaded?  Should I change outline-regexp into 
";;;;*\\( [^ \t\n]\\|###autoload\\)\\|("?


Lute.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: lisp-outline-level.
  2005-02-13 17:06   ` lisp-outline-level Lute Kamstra
@ 2005-02-13 17:37     ` David Kastrup
  2005-02-13 18:13       ` lisp-outline-level Lute Kamstra
  0 siblings, 1 reply; 15+ messages in thread
From: David Kastrup @ 2005-02-13 17:37 UTC (permalink / raw)
  Cc: emacs-devel

Lute Kamstra <Lute.Kamstra.lists@xs4all.nl> writes:

> David Kastrup <dak@gnu.org> writes:
>
>> Lute Kamstra <Lute.Kamstra.lists@xs4all.nl> writes:
>>
>>> In (Emacs) Lisp mode, outline-regexp is ";;;;* [^ \t\n]\\|(" and
>>> outline-level is lisp-outline-level:
>>>
>>> (defun lisp-outline-level ()
>>>   "Lisp mode `outline-level' function."
>>>   (if (looking-at "(\\|;;;###autoload")
>>>       1000
>>>     (looking-at outline-regexp)
>>>     (- (match-end 0) (match-beginning 0))))
>>>
>>> This is a bit strange as outline-regexp doesn't match
>>> ";;;###autoload".
>>
>> Why is that strange?  outline-regexp is not even consulted when
>> ;###autoload is found, so I don't see how it would come into play
>> here.
>>
>>> Shall I commit the patch below?
>>
>>> *** lisp/emacs-lisp/lisp-mode.el	1 Feb 2005 15:48:50 -0000	1.171
>>> --- lisp/emacs-lisp/lisp-mode.el	13 Feb 2005 11:03:02 -0000
>>> ***************
>>> *** 212,223 ****
>>>   
>>>   (defun lisp-outline-level ()
>>>     "Lisp mode `outline-level' function."
>>> !   (if (looking-at "(\\|;;;###autoload")
>>>         1000
>>> -     (looking-at outline-regexp)
>>>       (- (match-end 0) (match-beginning 0))))
>>>   
>>> - 
>>> --- 212,221 ----
>>>   
>>>   (defun lisp-outline-level ()
>>>     "Lisp mode `outline-level' function."
>>> !   (if (eq (following-char) ?\()
>>>         1000
>>>       (- (match-end 0) (match-beginning 0))))
>>
>> The patch is completely nonsensical.  It returns rubbish in almost all
>> cases since it is the "looking-at" that established match-end and
>> match-beginning in the first place.
>
> The variables outline-regexp and outline-level are used by Outline
> minor mode.  Did you take a look at their docstrings?  Outline minor
> mode searches for matches of outline-regexp and at each match the
> function in outline-level is called to determine the nesting level:
>
> ,----[ C-h v outline-level RET ]
> | outline-level's value is outline-level
> | 
> | *Function of no args to compute a header's nesting level in an outline.
> | It can assume point is at the beginning of a header line and that the match
> | data reflects the `outline-regexp'.
> | 
> | Defined in `outline'.
> `----
>
> Does my patch make more sense now?

Ok, I did not realize that those functions were essentially hook
functions, sorry.  However, I find that within a Lisp buffer I have

outline-regexp's value is ";;;;* [^ 	\n]\\|("
Local in buffer loaddefs.el; global value is "[*\f]+"

*Regular expression to match the beginning of a heading.
Any line whose beginning matches this regexp is considered to start a heading.
Note that Outline mode only checks this regexp at the start of a line,
so the regexp need not (and usually does not) start with `^'.
The recommended way to set this is with a Local Variables: list
in the file it applies to.  See also `outline-heading-end-regexp'.

You can customize this variable.

Defined in `outline'.

[back]

and this just barely manages to avoid matching ;;;###autoload.  I am
not sure whether this really is intentional.  Especially in light of
the lisp-outline-level definition.

So while I have no clue about the matter at hand, I would just want to
suggest that it might be possible from the look of the previous code
that outline-regexp was intended to also match ;;;###autoload, or at
least that it was considered a valid possibility for a user
customization of outline-regexp in Lisp mode.  In either case it would
not be wrong to keep the check.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: lisp-outline-level.
  2005-02-13 16:56 ` lisp-outline-level Stefan Monnier
  2005-02-13 17:35   ` lisp-outline-level Lute Kamstra
@ 2005-02-13 17:48   ` David Kastrup
  2005-02-13 18:23     ` lisp-outline-level Lute Kamstra
  2005-02-13 19:01     ` lisp-outline-level Stefan Monnier
  1 sibling, 2 replies; 15+ messages in thread
From: David Kastrup @ 2005-02-13 17:48 UTC (permalink / raw)
  Cc: Lute Kamstra, emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> (defun lisp-outline-level ()
>>   "Lisp mode `outline-level' function."
>>   (if (looking-at "(\\|;;;###autoload")
>>       1000
>>     (looking-at outline-regexp)
>>     (- (match-end 0) (match-beginning 0))))
>
>> This is a bit strange as outline-regexp doesn't match
>> ";;;###autoload".  Shall I commit the patch below?
>
> Why did you assume that the ;;;###autoload thingy got there by mistake?
> Wouldn't it be better to fix outline-regexp?

Anyway, I find the original butt-ugly and inefficient.  Wouldn't it be
better to write

(defun lisp-outline-level ()
  "Lisp mode `outline-level' function."
  (if (save-match-data (looking-at "(\\|;;;###autoload")))
      1000
    (- (match-end 0) (match-beginning 0))))

or even (if preservation of match data is definitely not required)

(defun lisp-outline-level
  (let ((len (- (match-end 0) (match-beginning 0))))
    (if  (looking-at ...)
       1000
     len)))


-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: lisp-outline-level.
  2005-02-13 17:37     ` lisp-outline-level David Kastrup
@ 2005-02-13 18:13       ` Lute Kamstra
  0 siblings, 0 replies; 15+ messages in thread
From: Lute Kamstra @ 2005-02-13 18:13 UTC (permalink / raw)
  Cc: emacs-devel

David Kastrup <dak@gnu.org> writes:

>>> Lute Kamstra <Lute.Kamstra.lists@xs4all.nl> writes:
>>>
>>>> In (Emacs) Lisp mode, outline-regexp is ";;;;* [^ \t\n]\\|(" and
>>>> outline-level is lisp-outline-level:

[...]

> Ok, I did not realize that those functions were essentially hook
> functions, sorry.  However, I find that within a Lisp buffer I have
>
> outline-regexp's value is ";;;;* [^ 	\n]\\|("
> Local in buffer loaddefs.el; global value is "[*\f]+"

[...]

> and this just barely manages to avoid matching ;;;###autoload.  I am
> not sure whether this really is intentional.  Especially in light of
> the lisp-outline-level definition.
>
> So while I have no clue about the matter at hand, I would just want to
> suggest that it might be possible from the look of the previous code
> that outline-regexp was intended to also match ;;;###autoload, 

Yup, that's what Stefan hinted at.  My bad.

> or at least that it was considered a valid possibility for a user
> customization of outline-regexp in Lisp mode.  In either case it
> would not be wrong to keep the check.

Well, if you change outline-regexp, you should also check
outline-level as those variables work in concert.

Lute.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: lisp-outline-level.
  2005-02-13 17:48   ` lisp-outline-level David Kastrup
@ 2005-02-13 18:23     ` Lute Kamstra
  2005-02-13 19:01     ` lisp-outline-level Stefan Monnier
  1 sibling, 0 replies; 15+ messages in thread
From: Lute Kamstra @ 2005-02-13 18:23 UTC (permalink / raw)
  Cc: Stefan Monnier, emacs-devel

David Kastrup <dak@gnu.org> writes:

[...]

> or even (if preservation of match data is definitely not required)
>
> (defun lisp-outline-level
>   (let ((len (- (match-end 0) (match-beginning 0))))
>     (if  (looking-at ...)
>        1000
>      len)))

A quick look at lisp/outline.el gave me the impression that calls to
outline-level functions are embedded in (save-match-data ...) if the
match data should be preserved.

Lute.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: lisp-outline-level.
  2005-02-13 17:48   ` lisp-outline-level David Kastrup
  2005-02-13 18:23     ` lisp-outline-level Lute Kamstra
@ 2005-02-13 19:01     ` Stefan Monnier
  1 sibling, 0 replies; 15+ messages in thread
From: Stefan Monnier @ 2005-02-13 19:01 UTC (permalink / raw)
  Cc: Lute Kamstra, emacs-devel

> (defun lisp-outline-level
>   (let ((len (- (match-end 0) (match-beginning 0))))
>     (if  (looking-at ...)
>        1000
>      len)))

Yes, that's probably preferable.


        Stefan

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: lisp-outline-level.
  2005-02-13 15:59 lisp-outline-level Lute Kamstra
  2005-02-13 16:37 ` lisp-outline-level David Kastrup
  2005-02-13 16:56 ` lisp-outline-level Stefan Monnier
@ 2005-02-15  6:19 ` Richard Stallman
  2005-02-15  9:30   ` lisp-outline-level Lute Kamstra
  2 siblings, 1 reply; 15+ messages in thread
From: Richard Stallman @ 2005-02-15  6:19 UTC (permalink / raw)
  Cc: emacs-devel

    This is a bit strange as outline-regexp doesn't match
    ";;;###autoload".  Shall I commit the patch below?

Does this change give improved behavior in any particular case?
If so, which case?

What happens if you add ;;;###autoload to outline-regexp?

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: lisp-outline-level.
  2005-02-15  6:19 ` lisp-outline-level Richard Stallman
@ 2005-02-15  9:30   ` Lute Kamstra
  2005-02-16  9:32     ` lisp-outline-level Richard Stallman
  0 siblings, 1 reply; 15+ messages in thread
From: Lute Kamstra @ 2005-02-15  9:30 UTC (permalink / raw)
  Cc: Stefan Monnier, emacs-devel

Richard Stallman <rms@gnu.org> writes:

>     This is a bit strange as outline-regexp doesn't match
>     ";;;###autoload".  Shall I commit the patch below?
>
> Does this change give improved behavior in any particular case?
> If so, which case?
>
> What happens if you add ;;;###autoload to outline-regexp?

As Stefan Monnier suggested, I added ;;;###autoload to outline-regexp.
I also improved the efficiency of lisp-outline-level as suggested by
David Kastrup.

Lute.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: lisp-outline-level.
  2005-02-15  9:30   ` lisp-outline-level Lute Kamstra
@ 2005-02-16  9:32     ` Richard Stallman
  2005-02-16 10:47       ` lisp-outline-level Lute Kamstra
  0 siblings, 1 reply; 15+ messages in thread
From: Richard Stallman @ 2005-02-16  9:32 UTC (permalink / raw)
  Cc: monnier, emacs-devel

    As Stefan Monnier suggested, I added ;;;###autoload to outline-regexp.

Does this in fact give good results?  I can't anticipate whether
they would be good or bad.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: lisp-outline-level.
  2005-02-16  9:32     ` lisp-outline-level Richard Stallman
@ 2005-02-16 10:47       ` Lute Kamstra
  2005-02-17 23:07         ` lisp-outline-level Richard Stallman
  0 siblings, 1 reply; 15+ messages in thread
From: Lute Kamstra @ 2005-02-16 10:47 UTC (permalink / raw)
  Cc: monnier, emacs-devel

Richard Stallman <rms@gnu.org> writes:

>     As Stefan Monnier suggested, I added ;;;###autoload to outline-regexp.
>
> Does this in fact give good results? 

Yes, this has the advantage that Outline minor mode doesn't consider
an autoload cookie as part of the previous top-level sexp anymore.
(Hiding the body of such a preceding top-level sexp would also hide
the autoload cookie.)

Lute.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: lisp-outline-level.
  2005-02-16 10:47       ` lisp-outline-level Lute Kamstra
@ 2005-02-17 23:07         ` Richard Stallman
  0 siblings, 0 replies; 15+ messages in thread
From: Richard Stallman @ 2005-02-17 23:07 UTC (permalink / raw)
  Cc: monnier, emacs-devel

    Yes, this has the advantage that Outline minor mode doesn't consider
    an autoload cookie as part of the previous top-level sexp anymore.
    (Hiding the body of such a preceding top-level sexp would also hide
    the autoload cookie.)

If you like the results, then this is a good change.  Thanks.

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2005-02-17 23:07 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-13 15:59 lisp-outline-level Lute Kamstra
2005-02-13 16:37 ` lisp-outline-level David Kastrup
2005-02-13 17:06   ` lisp-outline-level Lute Kamstra
2005-02-13 17:37     ` lisp-outline-level David Kastrup
2005-02-13 18:13       ` lisp-outline-level Lute Kamstra
2005-02-13 16:56 ` lisp-outline-level Stefan Monnier
2005-02-13 17:35   ` lisp-outline-level Lute Kamstra
2005-02-13 17:48   ` lisp-outline-level David Kastrup
2005-02-13 18:23     ` lisp-outline-level Lute Kamstra
2005-02-13 19:01     ` lisp-outline-level Stefan Monnier
2005-02-15  6:19 ` lisp-outline-level Richard Stallman
2005-02-15  9:30   ` lisp-outline-level Lute Kamstra
2005-02-16  9:32     ` lisp-outline-level Richard Stallman
2005-02-16 10:47       ` lisp-outline-level Lute Kamstra
2005-02-17 23:07         ` lisp-outline-level Richard Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).