* ignore-error?
@ 2019-07-15 10:29 Lars Ingebrigtsen
2019-07-15 13:08 ` ignore-error? Stefan Monnier
0 siblings, 1 reply; 6+ messages in thread
From: Lars Ingebrigtsen @ 2019-07-15 10:29 UTC (permalink / raw)
To: emacs-devel
It seems like people like writing `ignore-errors' a lot more than
`condition-case', and I think `ignore-errors' is the wrong thing to say
90% of the time.
So would it be a good idea to add a new convenience macro `ignore-error'
to entice people to not use `ignore-errors' so much? It would take an
error condition as its parameter, so:
(ignore-error 'file-error
(directory-files dir))
which would simply expand to
(condition-case _
(directory-files dir)
(file-error nil))
It indents nicely, too. :-)
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: ignore-error?
2019-07-15 10:29 ignore-error? Lars Ingebrigtsen
@ 2019-07-15 13:08 ` Stefan Monnier
2019-07-15 13:36 ` ignore-error? Lars Ingebrigtsen
0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2019-07-15 13:08 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: emacs-devel
> It seems like people like writing `ignore-errors' a lot more than
> `condition-case', and I think `ignore-errors' is the wrong thing to say
> 90% of the time.
I agree, but I think in 99% of those cases, the author has no idea which
error might need to be caught.
> So would it be a good idea to add a new convenience macro `ignore-error'
> to entice people to not use `ignore-errors' so much? It would take an
> error condition as its parameter, so:
>
> (ignore-error 'file-error
> (directory-files dir))
[ I think the argument shouldn't be quoted. ]
More importantly, if you want me to use this, you'll have to improve
elisp-mode's completion so it DTRT for the error symbol, like it does in
condition-case.
Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: ignore-error?
2019-07-15 13:08 ` ignore-error? Stefan Monnier
@ 2019-07-15 13:36 ` Lars Ingebrigtsen
2019-07-15 14:45 ` ignore-error? Stefan Monnier
0 siblings, 1 reply; 6+ messages in thread
From: Lars Ingebrigtsen @ 2019-07-15 13:36 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> It seems like people like writing `ignore-errors' a lot more than
>> `condition-case', and I think `ignore-errors' is the wrong thing to say
>> 90% of the time.
>
> I agree, but I think in 99% of those cases, the author has no idea which
> error might need to be caught.
That's true. If only Emacs Lisp had... checked exceptions. *runs
away*
*then returns*
But it sure would be nice if we had some way of telling at least some of
the errors that a function can raise...
>> So would it be a good idea to add a new convenience macro `ignore-error'
>> to entice people to not use `ignore-errors' so much? It would take an
>> error condition as its parameter, so:
>>
>> (ignore-error 'file-error
>> (directory-files dir))
>
> [ I think the argument shouldn't be quoted. ]
True.
> More importantly, if you want me to use this, you'll have to improve
> elisp-mode's completion so it DTRT for the error symbol, like it does in
> condition-case.
Let's see... It this stuff?
((and (or 'condition-case 'condition-case-unless-debug)
(guard (save-excursion
(ignore-errors
(forward-sexp 2)
(< (point) beg)))))
(list t obarray
:predicate (lambda (sym) (get sym 'error-conditions))))
Sure, that should be simple enough to cargo cult for the new macro, I
think.
The parameter should perhaps also be allowed to be a list of symbols:
(ignore-error (file-error some-other-error)
(foo))
?
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: ignore-error?
2019-07-15 13:36 ` ignore-error? Lars Ingebrigtsen
@ 2019-07-15 14:45 ` Stefan Monnier
2019-07-26 8:08 ` ignore-error? Lars Ingebrigtsen
0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2019-07-15 14:45 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: emacs-devel
> But it sure would be nice if we had some way of telling at least some of
> the errors that a function can raise...
We could decide that docstrings should mention which errors
are signal'd, indeed. Ideally in a standardized format.
> Let's see... It's this stuff?
Yup.
> The parameter should perhaps also be allowed to be a list of symbols:
>
> (ignore-error (file-error some-other-error)
> (foo))
Even better,
Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: ignore-error?
2019-07-15 14:45 ` ignore-error? Stefan Monnier
@ 2019-07-26 8:08 ` Lars Ingebrigtsen
2019-07-26 13:42 ` ignore-error? Stefan Monnier
0 siblings, 1 reply; 6+ messages in thread
From: Lars Ingebrigtsen @ 2019-07-26 8:08 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> Let's see... It's this stuff?
>
> Yup.
>
>> The parameter should perhaps also be allowed to be a list of symbols:
>>
>> (ignore-error (file-error some-other-error)
>> (foo))
>
> Even better,
I have now added `ignore-error', and provided for completion... but
with some caveats, as `elisp-completion-at-point' isn't... er... quite
right? :-)
Right: If you say
(ignore-erC-M-i
then funpos will indicate that we're in a function position and complete
over functions (which is correct).
(ignore-error C-M-i
still has funpos indicating that we're in a function definition, which
doesn't seem correct? But even if we fix that, then `end' will indicate
that we can't complete anything anyway.
(ignore-error argC-M-i
will have everything correct and complete to
(ignore-error args-out-of-range
Unfortunately, so will
(ignore-error foo
argC-M-i
because we don't have a count at all where we are in the sexp we're
completing. But on the other hand, the sexps are usually not closed
when we're completing anyway, so I guess that's a hard problem.
And, by the way
(condition-case nil
(foo)
(argC-M-i
completes well, but not
(condition-case nil
(foo)
((argC-M-i
that is, where the condition is a list...
It seems like that completing function could, like, use more... stuff.
:-) But I guess it's a DWIM best effort kinda thing.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: ignore-error?
2019-07-26 8:08 ` ignore-error? Lars Ingebrigtsen
@ 2019-07-26 13:42 ` Stefan Monnier
0 siblings, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2019-07-26 13:42 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: emacs-devel
> It seems like that completing function could, like, use more... stuff.
Yes, if you have love to give it, it will be eternally thankful, and
I will also appreciate it,
Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-07-26 13:42 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-15 10:29 ignore-error? Lars Ingebrigtsen
2019-07-15 13:08 ` ignore-error? Stefan Monnier
2019-07-15 13:36 ` ignore-error? Lars Ingebrigtsen
2019-07-15 14:45 ` ignore-error? Stefan Monnier
2019-07-26 8:08 ` ignore-error? Lars Ingebrigtsen
2019-07-26 13:42 ` ignore-error? Stefan Monnier
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.