Bram,
On Mon, Feb 08, 2016 at 10:57:37PM +0100, Bram Moolenaar wrote:
>
> Anton Lindqvist wrote:
>
> > This is a result of a previous discussion[1] which concluded that a
> > more general Error autocmd event would be a better addition than the
> > proposed TagNotFound event.
> >
> > Questions and comments regarding the patch in no particular order:
> >
> > - Is the addition to the main_loop function at a suitable location?
> >
> > - The error code (emsg_code) is the actual code including the 'E' prefix.
> > Another solution is to use the numerical representation of the error code.
> >
> > - The get_error_pat function is used to translate error codes into something
> > more descriptive. As of writing this only one such mapping is
> > present. We could either ensure that all possible error codes has a
> > mapping or add them on demand. The function is doing a linear search
> > of error_pats. If the error code is represented as an int this could
> > be replaced with a constant lookup if the array index is equal to
> > the error code:
> >
> > static const char *error_pat[] = {
> > [426] = "tagnotfound",
> > }
> >
> > If mappings of all possible error codes is present the array won't end up
> > being that sparse.
> >
> > The existing solution (representing error codes as string) could also be
> > improved by replacing the linear search with a binary search.
> >
> > - If no mapping of the error code to pattern is found the actual error
> > code is used as the amatch argument when triggering the Error event.
> >
> > [1] https://groups.google.com/d/msg/vim_dev/XzhNNjbtfow/u6BWsne4CwAJ
>
> I am wondering if this is really a useful solution.
>
> At least in scripts one can already use try/catch to deal with errors.
> Thus this patch is mainly for when typing commands.
>
> The original reason was to handle an error for a tag lookup. With the
> solution the tag lookup will still fail. It can trigger rebuilding the
> tags file, but for most users it will be quite unexpected that trying to
> jump to the same tag suddenly works a bit later.
The creation of the tags file when missing was just an example of a use-case of
my own and is of course a opt-in usage of the new event.
> Can you think of a command or situation where this patch provides a
> nice, useful solution?
Other than the examples already provided, here's a couple of ideas:
- Opening a new file in a non existing directory and then write triggers a E212
which could be caught and then before writing again try to create the
directory (%:h) of the file.
- The SpellFileMissing autocmd event could probably be implemented using the
Error event instead. However this might not a suitable idea since it would
require keeping the old event for backwards compability.
--
:wq
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.