unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Why should interactive search results raise errors?
@ 2006-05-03 16:26 Lennart Borgman
  2006-05-03 16:34 ` Chong Yidong
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Lennart Borgman @ 2006-05-03 16:26 UTC (permalink / raw)


Some interactive search functions raise errors when no hit is found. It 
is quite annoyning if you have set debug-on-error to t. Is there any 
reason why this functions raises errors in this cases? Can that be used 
for anything?

An example is the function in the menu bar: Edit - Search - String 
Forward. As far as I can see this in only meant to be run interactively. 
The same goes for viper-search-next.

It would in my opinion be more convenient if these functions just return 
nil and showed a message when a search fails. Would it not be a good 
convention for interactive search functions in Emacs?

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

* Re: Why should interactive search results raise errors?
  2006-05-03 16:26 Lennart Borgman
@ 2006-05-03 16:34 ` Chong Yidong
  2006-05-03 16:50   ` Lennart Borgman
  2006-05-03 17:29 ` Stefan Monnier
  2006-05-04  8:34 ` Kim F. Storm
  2 siblings, 1 reply; 12+ messages in thread
From: Chong Yidong @ 2006-05-03 16:34 UTC (permalink / raw)
  Cc: Emacs Devel

Lennart Borgman <lennart.borgman.073@student.lu.se> writes:

> Some interactive search functions raise errors when no hit is
> found. It is quite annoyning if you have set debug-on-error to t. Is
> there any reason why this functions raises errors in this cases? Can
> that be used for anything?
>
> An example is the function in the menu bar: Edit - Search - String
> Forward. As far as I can see this in only meant to be run
> interactively. The same goes for viper-search-next.
>
> It would in my opinion be more convenient if these functions just
> return nil and showed a message when a search fails. Would it not be a
> good convention for interactive search functions in Emacs?

Probably the better thing to do is to add the error to
debug-ignored-errors.

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

* Re: Why should interactive search results raise errors?
  2006-05-03 16:34 ` Chong Yidong
@ 2006-05-03 16:50   ` Lennart Borgman
  2006-05-04 14:17     ` Richard Stallman
  0 siblings, 1 reply; 12+ messages in thread
From: Lennart Borgman @ 2006-05-03 16:50 UTC (permalink / raw)
  Cc: Emacs Devel

Chong Yidong wrote:
> Lennart Borgman <lennart.borgman.073@student.lu.se> writes:
>
>   
>> Some interactive search functions raise errors when no hit is
>> found. It is quite annoyning if you have set debug-on-error to t. Is
>> there any reason why this functions raises errors in this cases? Can
>> that be used for anything?
>>
>> An example is the function in the menu bar: Edit - Search - String
>> Forward. As far as I can see this in only meant to be run
>> interactively. The same goes for viper-search-next.
>>
>> It would in my opinion be more convenient if these functions just
>> return nil and showed a message when a search fails. Would it not be a
>> good convention for interactive search functions in Emacs?
>>     
>
> Probably the better thing to do is to add the error to
> debug-ignored-errors.
>   
Oh! Thanks. I was just going to invent that one. How nice it is there 
already ;-)

I still believe that interactive search commands should not raise 
errors. However I think adding these commands now to 
debug-ingnored-errors is the better solution now. Could we please do 
that now?

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

* Re: Why should interactive search results raise errors?
  2006-05-03 16:26 Lennart Borgman
  2006-05-03 16:34 ` Chong Yidong
@ 2006-05-03 17:29 ` Stefan Monnier
  2006-05-03 19:58   ` Lennart Borgman
  2006-05-04  8:34 ` Kim F. Storm
  2 siblings, 1 reply; 12+ messages in thread
From: Stefan Monnier @ 2006-05-03 17:29 UTC (permalink / raw)
  Cc: Emacs Devel

> It would in my opinion be more convenient if these functions just return nil
> and showed a message when a search fails. Would it not be a good convention
> for interactive search functions in Emacs?

I think the better answer is to create a new error class called `user-error'
which would be then added to debug-ignored-errors.  Then we can replace most
elements of debug-ignored-errors by changing the signalling code so as to
signal a `user-error' rather than an `error'.

But that's for post-22.


        Stefan

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

* Re: Why should interactive search results raise errors?
  2006-05-03 17:29 ` Stefan Monnier
@ 2006-05-03 19:58   ` Lennart Borgman
  0 siblings, 0 replies; 12+ messages in thread
From: Lennart Borgman @ 2006-05-03 19:58 UTC (permalink / raw)
  Cc: Emacs Devel

Stefan Monnier wrote:
>> It would in my opinion be more convenient if these functions just return nil
>> and showed a message when a search fails. Would it not be a good convention
>> for interactive search functions in Emacs?
>>     
>
> I think the better answer is to create a new error class called `user-error'
> which would be then added to debug-ignored-errors.  Then we can replace most
> elements of debug-ignored-errors by changing the signalling code so as to
> signal a `user-error' rather than an `error'.
>
> But that's for post-22.
>
>
>         Stefan
>   
Yes, that is good.

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

* Re: Why should interactive search results raise errors?
  2006-05-03 16:26 Lennart Borgman
  2006-05-03 16:34 ` Chong Yidong
  2006-05-03 17:29 ` Stefan Monnier
@ 2006-05-04  8:34 ` Kim F. Storm
  2 siblings, 0 replies; 12+ messages in thread
From: Kim F. Storm @ 2006-05-04  8:34 UTC (permalink / raw)
  Cc: Emacs Devel

Lennart Borgman <lennart.borgman.073@student.lu.se> writes:

> Some interactive search functions raise errors when no hit is
> found. It is quite annoyning if you have set debug-on-error to t. Is
> there any reason why this functions raises errors in this cases? Can
> that be used for anything?

If you include the search in a keyboard macro, it will terminate the
macro if you repeat it "forever".

Perhaps it should only signal an error if executed from a kbd macro?

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

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

* Re: Why should interactive search results raise errors?
@ 2006-05-04  9:21 LENNART BORGMAN
  2006-05-04  9:58 ` Miles Bader
  0 siblings, 1 reply; 12+ messages in thread
From: LENNART BORGMAN @ 2006-05-04  9:21 UTC (permalink / raw)
  Cc: Emacs Devel

From: storm@cua.dk (Kim F. Storm)

> Lennart Borgman <lennart.borgman.073@student.lu.se> writes:
> 
> > Some interactive search functions raise errors when no hit is
> > found. It is quite annoyning if you have set debug-on-error to 
> t. Is
> > there any reason why this functions raises errors in this cases? Can
> > that be used for anything?
> 
> If you include the search in a keyboard macro, it will terminate the
> macro if you repeat it "forever".
> 
> Perhaps it should only signal an error if executed from a kbd macro?

A good idea in my opinion.

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

* Re: Why should interactive search results raise errors?
  2006-05-04  9:21 Why should interactive search results raise errors? LENNART BORGMAN
@ 2006-05-04  9:58 ` Miles Bader
  0 siblings, 0 replies; 12+ messages in thread
From: Miles Bader @ 2006-05-04  9:58 UTC (permalink / raw)
  Cc: Emacs Devel, Kim F. Storm

LENNART BORGMAN <lennart.borgman.073@student.lu.se> writes:
>> If you include the search in a keyboard macro, it will terminate the
>> macro if you repeat it "forever".
>> 
>> Perhaps it should only signal an error if executed from a kbd macro?
>
> A good idea in my opinion.

This behavior has been part of Emacs for so long that it seems very
risky to just change it now (and the reasons for the suggested change
pretty obscure).

Also, making non-display behavior dependent on being in a keyboard macro
is pretty ugly; Stefan's solution is a far cleaner way to handle the
"debugger problem."

-Miles
-- 
"Nah, there's no bigger atheist than me.  Well, I take that back.
I'm a cancer screening away from going agnostic and a biopsy away
from full-fledged Christian."  [Adam Carolla]

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

* Re: Why should interactive search results raise errors?
  2006-05-03 16:50   ` Lennart Borgman
@ 2006-05-04 14:17     ` Richard Stallman
  2006-05-04 14:20       ` Lennart Borgman
  2006-05-04 16:15       ` Stefan Monnier
  0 siblings, 2 replies; 12+ messages in thread
From: Richard Stallman @ 2006-05-04 14:17 UTC (permalink / raw)
  Cc: emacs-devel, cyd

    I still believe that interactive search commands should not raise 
    errors. However I think adding these commands now to 
    debug-ingnored-errors is the better solution now. Could we please do 
    that now?

I see no reason to change this.  Lots of commands signal errors when
they can't do what they are asked to do; why shouldn't these?

    I think the better answer is to create a new error class called `user-error'
    which would be then added to debug-ignored-errors.  Then we can replace most
    elements of debug-ignored-errors by changing the signalling code so as to
    signal a `user-error' rather than an `error'.

That is not necessarily a bad idea, but I am not sure whether it is
really possible to distinguish "user errors" from other errors at the
level of calls to `signal'.

`debug-ignored-errors' does make an attempt to distinguish which
errors are _probably_ user errors, but it cannot really know,
and sometimes this criterion gets the wrong answer.

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

* Re: Why should interactive search results raise errors?
  2006-05-04 14:17     ` Richard Stallman
@ 2006-05-04 14:20       ` Lennart Borgman
  2006-05-04 15:34         ` Stuart D. Herring
  2006-05-04 16:15       ` Stefan Monnier
  1 sibling, 1 reply; 12+ messages in thread
From: Lennart Borgman @ 2006-05-04 14:20 UTC (permalink / raw)
  Cc: emacs-devel, cyd

Richard Stallman wrote:
>     I still believe that interactive search commands should not raise 
>     errors. However I think adding these commands now to 
>     debug-ingnored-errors is the better solution now. Could we please do 
>     that now?
>
> I see no reason to change this.  Lots of commands signal errors when
> they can't do what they are asked to do; why shouldn't these?
If I want to see if there is any hits at all then a failed search is not 
an error. It gives me the information I wanted - whether there are hits 
or not. Why should then this be an error?

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

* Re: Why should interactive search results raise errors?
  2006-05-04 14:20       ` Lennart Borgman
@ 2006-05-04 15:34         ` Stuart D. Herring
  0 siblings, 0 replies; 12+ messages in thread
From: Stuart D. Herring @ 2006-05-04 15:34 UTC (permalink / raw)
  Cc: emacs-devel

> If I want to see if there is any hits at all then a failed search is not
> an error. It gives me the information I wanted - whether there are hits
> or not. Why should then this be an error?

The menu eventually calls `search-forward'.  Its doc string begins thus:

  Search forward from point for STRING.
  Set point to the end of the occurrence found, and return point.

If there is no occurrence of STRING, then this function cannot do what it
says it will do, so it must signal an error.  Even if we ignore that it
says it will return point and return nil from it, it has not set point to
anything meaningful, so it should not return normally.

Certainly one could define a function with different semantics -- or a
flag for an existing function.  And we have:

  Optional third argument, if t, means if fail just return nil (no error).
    If not nil and not t, move to limit of search and return nil.

So perhaps you just want `nonincremental-search-forward' to do
(search-forward string nil t)?  That's not unreasonable, but then the menu
and the underlying command would behave differently.  So you could make
the default value for the NOERROR argument depend on whether the function
was called interactively.  But then you have to print some sort of message
when the search fails, and (ding) for backwards compatibility -- but only
when interactive...

It just seems simpler to me to keep the current behavior and use (the
proposed) `user-error' or `debug-ignored-errors' as suggested.

Davis

-- 
This product is sold by volume, not by mass.  If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.

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

* Re: Why should interactive search results raise errors?
  2006-05-04 14:17     ` Richard Stallman
  2006-05-04 14:20       ` Lennart Borgman
@ 2006-05-04 16:15       ` Stefan Monnier
  1 sibling, 0 replies; 12+ messages in thread
From: Stefan Monnier @ 2006-05-04 16:15 UTC (permalink / raw)
  Cc: Lennart Borgman, cyd, emacs-devel

>     I think the better answer is to create a new error class called
>     `user-error' which would be then added to debug-ignored-errors.
>     Then we can replace most elements of debug-ignored-errors by changing
>     the signalling code so as to signal a `user-error' rather than an
>     `error'.

> That is not necessarily a bad idea, but I am not sure whether it is
> really possible to distinguish "user errors" from other errors at the
> level of calls to `signal'.

Clearly, the distinction between the two is only based on an expectation of
the context in which the function will be used.  So it's a heuristic and can
fail, but it on the flip side it also documents some of the intention behind
the code.
I think of it mostly as a way to clean up the debug-ignored-errors list.


        Stefan

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

end of thread, other threads:[~2006-05-04 16:15 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-04  9:21 Why should interactive search results raise errors? LENNART BORGMAN
2006-05-04  9:58 ` Miles Bader
  -- strict thread matches above, loose matches on Subject: below --
2006-05-03 16:26 Lennart Borgman
2006-05-03 16:34 ` Chong Yidong
2006-05-03 16:50   ` Lennart Borgman
2006-05-04 14:17     ` Richard Stallman
2006-05-04 14:20       ` Lennart Borgman
2006-05-04 15:34         ` Stuart D. Herring
2006-05-04 16:15       ` Stefan Monnier
2006-05-03 17:29 ` Stefan Monnier
2006-05-03 19:58   ` Lennart Borgman
2006-05-04  8:34 ` Kim F. Storm

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