Re: [patch] Add Error autocmd event

2016-03-19 Fir de Conversatie mattn
BTW, if incldue this patch, vim will allow to create any commands.

function! s:OverrideCmd(msg)
  if a:msg =~ "^E492: Not an editor command: "
" something
  endif
endfunction
au! Error E492 call s:OverrideCmd(v:errmsg)

For example, create command name leading lower letter, multibyte string, or etc.
I'm not strong opinion about this patch, but we need to consider for effect to 
others.

- mattn

-- 
-- 
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 vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [patch] Add Error autocmd event

2016-02-27 Fir de Conversatie Anton Lindqvist
On Thu, Feb 25, 2016 at 10:17:34PM +0100, Bram Moolenaar wrote:
> 
> Anton Lindqvist wrote:
> 
> > Bram,
> > I noticed your comment in todo.txt about the fact that the current
> > solution only remembers the code of last error that occurred. Here's a
> > first attempt address this issue by using an growarray. Caution: I don't
> > know if it's wise to clear the array in the main loop.
> 
> Thanks.  However, I still have doubts about how useful this is.
> Autocommands are tricky as they are, and this one is more tricky then
> others.
> 
> It's not that I don't like your work, I just don't want to make a
> promise to users, which means once this is in we'll have to keep it
> around forever.  Even when we find a better solution eventually.

Sounds reasonable and I respect your judgment.

-- 
: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 vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [patch] Add Error autocmd event

2016-02-25 Fir de Conversatie Bram Moolenaar

Anton Lindqvist wrote:

> Bram,
> I noticed your comment in todo.txt about the fact that the current
> solution only remembers the code of last error that occurred. Here's a
> first attempt address this issue by using an growarray. Caution: I don't
> know if it's wise to clear the array in the main loop.

Thanks.  However, I still have doubts about how useful this is.
Autocommands are tricky as they are, and this one is more tricky then
others.

It's not that I don't like your work, I just don't want to make a
promise to users, which means once this is in we'll have to keep it
around forever.  Even when we find a better solution eventually.


-- 
ARTHUR:  No, hang on!  Just answer the five questions ...
GALAHAD: Three questions ...
ARTHUR:  Three questions ...  And we shall watch ... and pray.
 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
-- 
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 vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [patch] Add Error autocmd event

2016-02-25 Fir de Conversatie Anton Lindqvist
Bram,
I noticed your comment in todo.txt about the fact that the current
solution only remembers the code of last error that occurred. Here's a
first attempt address this issue by using an growarray. Caution: I don't
know if it's wise to clear the array in the main loop.

-- 
: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 vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/fileio.c b/src/fileio.c
index ecec757..aaed5cb 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -7666,6 +7666,7 @@ static struct event_name
 {"CursorMoved",	EVENT_CURSORMOVED},
 {"CursorMovedI",	EVENT_CURSORMOVEDI},
 {"EncodingChanged",	EVENT_ENCODINGCHANGED},
+{"Error",		EVENT_ERROR},
 {"FileEncoding",	EVENT_ENCODINGCHANGED},
 {"FileAppendPost",	EVENT_FILEAPPENDPOST},
 {"FileAppendPre",	EVENT_FILEAPPENDPRE},
@@ -7725,6 +7726,21 @@ static struct event_name
 {NULL,		(event_T)0}
 };
 
+
+/*
+ * Mapping of error code to pattern used for  when triggering the Error
+ * event.
+ */
+static struct error_pat
+{
+const char	*code;
+const char	*pat;
+} error_pats[] =
+{
+{"E426",	"tagnotfound"},
+{NULL,	NULL}
+};
+
 static AutoPat *first_autopat[NUM_EVENTS] =
 {
 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
@@ -9351,7 +9367,7 @@ apply_autocmds_group(
 {
 	sfname = vim_strsave(fname);
 	/* Don't try expanding FileType, Syntax, FuncUndefined, WindowID,
-	 * ColorScheme or QuickFixCmd* */
+	 * ColorScheme, Error or QuickFixCmd* */
 	if (event == EVENT_FILETYPE
 		|| event == EVENT_SYNTAX
 		|| event == EVENT_FUNCUNDEFINED
@@ -9359,6 +9375,7 @@ apply_autocmds_group(
 		|| event == EVENT_SPELLFILEMISSING
 		|| event == EVENT_QUICKFIXCMDPRE
 		|| event == EVENT_COLORSCHEME
+		|| event == EVENT_ERROR
 		|| event == EVENT_OPTIONSET
 		|| event == EVENT_QUICKFIXCMDPOST)
 	fname = vim_strsave(fname);
@@ -9750,20 +9767,26 @@ has_autocmd(event_T event, char_u *sfname, buf_T *buf)
 char_u	*tail = gettail(sfname);
 int		retval = FALSE;
 
-fname = FullName_save(sfname, FALSE);
-if (fname == NULL)
-	return FALSE;
-
+/* don't try expanding Error */
+if (event == EVENT_ERROR) {
+	fname = vim_strsave(sfname);
+	if (fname == NULL)
+	return FALSE;
+} else {
+	fname = FullName_save(sfname, FALSE);
+	if (fname == NULL)
+	return FALSE;
 #ifdef BACKSLASH_IN_FILENAME
-/*
- * Replace all backslashes with forward slashes.  This makes the
- * autocommand patterns portable between Unix and MS-DOS.
- */
-sfname = vim_strsave(sfname);
-if (sfname != NULL)
-	forward_slash(sfname);
-forward_slash(fname);
+	/*
+	 * Replace all backslashes with forward slashes.  This makes the
+	 * autocommand patterns portable between Unix and MS-DOS.
+	 */
+	sfname = vim_strsave(sfname);
+	if (sfname != NULL)
+	forward_slash(sfname);
+	forward_slash(fname);
 #endif
+}
 
 for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next)
 	if (ap->pat != NULL && ap->cmds != NULL
@@ -10358,3 +10381,23 @@ write_eintr(int fd, void *buf, size_t bufsize)
 return ret;
 }
 #endif
+
+#ifdef FEAT_AUTOCMD
+/*
+ * Get the corresponding pattern for the given error message code. The returned
+ * value is used for  when triggering the Error autocmd event.
+ */
+char_u *
+get_error_pat(char_u *code)
+{
+size_t	len;
+int		i;
+
+len = STRLEN(code);
+for (i = 0; error_pats[i].code; i++)
+	if (STRNCMP(error_pats[i].code, code, len) == 0)
+	return (char_u *)error_pats[i].pat;
+
+return NULL;
+}
+#endif
diff --git a/src/globals.h b/src/globals.h
index 4c1b41f..cb46510 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -184,6 +184,11 @@ EXTERN int	did_emsg;		/* set by emsg() when the message
 EXTERN int	did_emsg_syntax;	/* did_emsg set because of a
 	   syntax error */
 EXTERN int	called_emsg;		/* always set by emsg() */
+#ifdef FEAT_AUTOCMD
+EXTERN garray_T	emsg_codes;		/* grow array containing the latest
+	   error message codes set by
+	   emsg(). */
+#endif
 EXTERN int	ex_exitval INIT(= 0);	/* exit value for ex mode */
 EXTERN int	emsg_on_display INIT(= FALSE);	/* there is an error message */
 EXTERN int	rc_did_emsg INIT(= FALSE);  /* vim_regcomp() called emsg() */
diff --git a/src/main.c b/src/main.c
index e412641..6edc369 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1278,6 +1278,22 @@ main_loop(
 		fileinfo(FALSE, TRUE, FALSE);
 		need_fileinfo = FALSE;
 	}
+#ifdef FEAT_AUTOCMD
+	if (emsg_codes.ga_len) {
+		for (int i = 0; i < emsg_codes.ga_len; ++i)
+		{
+		char_u *code = ((char_u **)emsg_codes.g

Re: [patch] Add Error autocmd event

2016-02-22 Fir de Conversatie Anton Lindqvist
Realized I was using my personal preference for cinoptions. Here's a
revised patch with correct indentation.

-- 
: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 vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/fileio.c b/src/fileio.c
index ecec757..aaed5cb 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -7666,6 +7666,7 @@ static struct event_name
 {"CursorMoved",	EVENT_CURSORMOVED},
 {"CursorMovedI",	EVENT_CURSORMOVEDI},
 {"EncodingChanged",	EVENT_ENCODINGCHANGED},
+{"Error",		EVENT_ERROR},
 {"FileEncoding",	EVENT_ENCODINGCHANGED},
 {"FileAppendPost",	EVENT_FILEAPPENDPOST},
 {"FileAppendPre",	EVENT_FILEAPPENDPRE},
@@ -7725,6 +7726,21 @@ static struct event_name
 {NULL,		(event_T)0}
 };
 
+
+/*
+ * Mapping of error code to pattern used for  when triggering the Error
+ * event.
+ */
+static struct error_pat
+{
+const char	*code;
+const char	*pat;
+} error_pats[] =
+{
+{"E426",	"tagnotfound"},
+{NULL,	NULL}
+};
+
 static AutoPat *first_autopat[NUM_EVENTS] =
 {
 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
@@ -9351,7 +9367,7 @@ apply_autocmds_group(
 {
 	sfname = vim_strsave(fname);
 	/* Don't try expanding FileType, Syntax, FuncUndefined, WindowID,
-	 * ColorScheme or QuickFixCmd* */
+	 * ColorScheme, Error or QuickFixCmd* */
 	if (event == EVENT_FILETYPE
 		|| event == EVENT_SYNTAX
 		|| event == EVENT_FUNCUNDEFINED
@@ -9359,6 +9375,7 @@ apply_autocmds_group(
 		|| event == EVENT_SPELLFILEMISSING
 		|| event == EVENT_QUICKFIXCMDPRE
 		|| event == EVENT_COLORSCHEME
+		|| event == EVENT_ERROR
 		|| event == EVENT_OPTIONSET
 		|| event == EVENT_QUICKFIXCMDPOST)
 	fname = vim_strsave(fname);
@@ -9750,20 +9767,26 @@ has_autocmd(event_T event, char_u *sfname, buf_T *buf)
 char_u	*tail = gettail(sfname);
 int		retval = FALSE;
 
-fname = FullName_save(sfname, FALSE);
-if (fname == NULL)
-	return FALSE;
-
+/* don't try expanding Error */
+if (event == EVENT_ERROR) {
+	fname = vim_strsave(sfname);
+	if (fname == NULL)
+	return FALSE;
+} else {
+	fname = FullName_save(sfname, FALSE);
+	if (fname == NULL)
+	return FALSE;
 #ifdef BACKSLASH_IN_FILENAME
-/*
- * Replace all backslashes with forward slashes.  This makes the
- * autocommand patterns portable between Unix and MS-DOS.
- */
-sfname = vim_strsave(sfname);
-if (sfname != NULL)
-	forward_slash(sfname);
-forward_slash(fname);
+	/*
+	 * Replace all backslashes with forward slashes.  This makes the
+	 * autocommand patterns portable between Unix and MS-DOS.
+	 */
+	sfname = vim_strsave(sfname);
+	if (sfname != NULL)
+	forward_slash(sfname);
+	forward_slash(fname);
 #endif
+}
 
 for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next)
 	if (ap->pat != NULL && ap->cmds != NULL
@@ -10358,3 +10381,23 @@ write_eintr(int fd, void *buf, size_t bufsize)
 return ret;
 }
 #endif
+
+#ifdef FEAT_AUTOCMD
+/*
+ * Get the corresponding pattern for the given error message code. The returned
+ * value is used for  when triggering the Error autocmd event.
+ */
+char_u *
+get_error_pat(char_u *code)
+{
+size_t	len;
+int		i;
+
+len = STRLEN(code);
+for (i = 0; error_pats[i].code; i++)
+	if (STRNCMP(error_pats[i].code, code, len) == 0)
+	return (char_u *)error_pats[i].pat;
+
+return NULL;
+}
+#endif
diff --git a/src/globals.h b/src/globals.h
index 4c1b41f..4342b71 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -184,6 +184,10 @@ EXTERN int	did_emsg;		/* set by emsg() when the message
 EXTERN int	did_emsg_syntax;	/* did_emsg set because of a
 	   syntax error */
 EXTERN int	called_emsg;		/* always set by emsg() */
+#ifdef FEAT_AUTOCMD
+EXTERN char_u	*emsg_code INIT(= NULL);/* last error message code set by
+	   emsg() */
+#endif
 EXTERN int	ex_exitval INIT(= 0);	/* exit value for ex mode */
 EXTERN int	emsg_on_display INIT(= FALSE);	/* there is an error message */
 EXTERN int	rc_did_emsg INIT(= FALSE);  /* vim_regcomp() called emsg() */
diff --git a/src/main.c b/src/main.c
index e412641..43671e9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1278,6 +1278,20 @@ main_loop(
 		fileinfo(FALSE, TRUE, FALSE);
 		need_fileinfo = FALSE;
 	}
+#ifdef FEAT_AUTOCMD
+	if (did_emsg && emsg_code) {
+		char_u *pat = get_error_pat(emsg_code);
+		if (pat && has_autocmd(EVENT_ERROR, pat, curbuf))
+		apply_autocmds(EVENT_ERROR, pat, curbuf->b_fname, FALSE,
+			curbuf);
+		else if (has_autocmd(EVENT_ERROR, emsg_code, curbuf))
+		apply_autocmds(EVENT_ERROR, emsg_code, curbuf->b_f

Re: [patch] Add Error autocmd event

2016-02-17 Fir de Conversatie Anton Lindqvist
Updated patch attached which adds a missing autocmd feature check.

-- 
: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 vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/fileio.c b/src/fileio.c
index ecec757..aaed5cb 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -7666,6 +7666,7 @@ static struct event_name
 {"CursorMoved",	EVENT_CURSORMOVED},
 {"CursorMovedI",	EVENT_CURSORMOVEDI},
 {"EncodingChanged",	EVENT_ENCODINGCHANGED},
+{"Error",		EVENT_ERROR},
 {"FileEncoding",	EVENT_ENCODINGCHANGED},
 {"FileAppendPost",	EVENT_FILEAPPENDPOST},
 {"FileAppendPre",	EVENT_FILEAPPENDPRE},
@@ -7725,6 +7726,21 @@ static struct event_name
 {NULL,		(event_T)0}
 };
 
+
+/*
+ * Mapping of error code to pattern used for  when triggering the Error
+ * event.
+ */
+static struct error_pat
+{
+const char	*code;
+const char	*pat;
+} error_pats[] =
+{
+{"E426",	"tagnotfound"},
+{NULL,	NULL}
+};
+
 static AutoPat *first_autopat[NUM_EVENTS] =
 {
 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
@@ -9351,7 +9367,7 @@ apply_autocmds_group(
 {
 	sfname = vim_strsave(fname);
 	/* Don't try expanding FileType, Syntax, FuncUndefined, WindowID,
-	 * ColorScheme or QuickFixCmd* */
+	 * ColorScheme, Error or QuickFixCmd* */
 	if (event == EVENT_FILETYPE
 		|| event == EVENT_SYNTAX
 		|| event == EVENT_FUNCUNDEFINED
@@ -9359,6 +9375,7 @@ apply_autocmds_group(
 		|| event == EVENT_SPELLFILEMISSING
 		|| event == EVENT_QUICKFIXCMDPRE
 		|| event == EVENT_COLORSCHEME
+		|| event == EVENT_ERROR
 		|| event == EVENT_OPTIONSET
 		|| event == EVENT_QUICKFIXCMDPOST)
 	fname = vim_strsave(fname);
@@ -9750,20 +9767,26 @@ has_autocmd(event_T event, char_u *sfname, buf_T *buf)
 char_u	*tail = gettail(sfname);
 int		retval = FALSE;
 
-fname = FullName_save(sfname, FALSE);
-if (fname == NULL)
-	return FALSE;
-
+/* don't try expanding Error */
+if (event == EVENT_ERROR) {
+	fname = vim_strsave(sfname);
+	if (fname == NULL)
+	return FALSE;
+} else {
+	fname = FullName_save(sfname, FALSE);
+	if (fname == NULL)
+	return FALSE;
 #ifdef BACKSLASH_IN_FILENAME
-/*
- * Replace all backslashes with forward slashes.  This makes the
- * autocommand patterns portable between Unix and MS-DOS.
- */
-sfname = vim_strsave(sfname);
-if (sfname != NULL)
-	forward_slash(sfname);
-forward_slash(fname);
+	/*
+	 * Replace all backslashes with forward slashes.  This makes the
+	 * autocommand patterns portable between Unix and MS-DOS.
+	 */
+	sfname = vim_strsave(sfname);
+	if (sfname != NULL)
+	forward_slash(sfname);
+	forward_slash(fname);
 #endif
+}
 
 for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next)
 	if (ap->pat != NULL && ap->cmds != NULL
@@ -10358,3 +10381,23 @@ write_eintr(int fd, void *buf, size_t bufsize)
 return ret;
 }
 #endif
+
+#ifdef FEAT_AUTOCMD
+/*
+ * Get the corresponding pattern for the given error message code. The returned
+ * value is used for  when triggering the Error autocmd event.
+ */
+char_u *
+get_error_pat(char_u *code)
+{
+size_t	len;
+int		i;
+
+len = STRLEN(code);
+for (i = 0; error_pats[i].code; i++)
+	if (STRNCMP(error_pats[i].code, code, len) == 0)
+	return (char_u *)error_pats[i].pat;
+
+return NULL;
+}
+#endif
diff --git a/src/globals.h b/src/globals.h
index 4c1b41f..4342b71 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -184,6 +184,10 @@ EXTERN int	did_emsg;		/* set by emsg() when the message
 EXTERN int	did_emsg_syntax;	/* did_emsg set because of a
 	   syntax error */
 EXTERN int	called_emsg;		/* always set by emsg() */
+#ifdef FEAT_AUTOCMD
+EXTERN char_u	*emsg_code INIT(= NULL);/* last error message code set by
+	   emsg() */
+#endif
 EXTERN int	ex_exitval INIT(= 0);	/* exit value for ex mode */
 EXTERN int	emsg_on_display INIT(= FALSE);	/* there is an error message */
 EXTERN int	rc_did_emsg INIT(= FALSE);  /* vim_regcomp() called emsg() */
diff --git a/src/main.c b/src/main.c
index e412641..aad656a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1278,6 +1278,20 @@ main_loop(
 		fileinfo(FALSE, TRUE, FALSE);
 		need_fileinfo = FALSE;
 	}
+#ifdef FEAT_AUTOCMD
+	if (did_emsg && emsg_code) {
+		char_u *pat = get_error_pat(emsg_code);
+		if (pat && has_autocmd(EVENT_ERROR, pat, curbuf))
+		apply_autocmds(EVENT_ERROR, pat, curbuf->b_fname, FALSE,
+   curbuf);
+		else if (has_autocmd(EVENT_ERROR, emsg_code, curbuf))
+		apply_autocmds(EVENT_ERROR, emsg_code, curbuf->b_fname,
+   FALSE, curbuf);
+
+		vim_fre

Re: [patch] Add Error autocmd event

2016-02-14 Fir de Conversatie Anton Lindqvist
Here's a revised patch including a more rigorous way of parsing the error code
from a error message.

Another use-case I've been trying recently: if wrapscan is initially disabled,
enable it when the search hits top/bottom. This way one is notified that the
search reached the end but pressing n/N again will temporary enable wrapscan in
order to redo the search from the opposite end.

  set nowrapscan
  let s:wrapscan = 0

  func! s:ToggleWrapScan(rhs) abort
if s:wrapscan
  set wrapscan
  let s:wrapscan = 0
else
  set nowrapscan
endif
return a:rhs
  endfunc
  nnoremap  n ToggleWrapScan('n')
  nnoremap  N ToggleWrapScan('N')

  augroup error
au! Error E38[45] let s:wrapscan = 1
  augroup END

-- 
: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 vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/fileio.c b/src/fileio.c
index ecec757..9a1e294 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -7666,6 +7666,7 @@ static struct event_name
 {"CursorMoved",	EVENT_CURSORMOVED},
 {"CursorMovedI",	EVENT_CURSORMOVEDI},
 {"EncodingChanged",	EVENT_ENCODINGCHANGED},
+{"Error",		EVENT_ERROR},
 {"FileEncoding",	EVENT_ENCODINGCHANGED},
 {"FileAppendPost",	EVENT_FILEAPPENDPOST},
 {"FileAppendPre",	EVENT_FILEAPPENDPRE},
@@ -7725,6 +7726,21 @@ static struct event_name
 {NULL,		(event_T)0}
 };
 
+
+/*
+ * Mapping of error code to pattern used for  when triggering the Error
+ * event.
+ */
+static struct error_pat
+{
+const char	*code;
+const char	*pat;
+} error_pats[] =
+{
+{"E426",	"tagnotfound"},
+{NULL,	NULL}
+};
+
 static AutoPat *first_autopat[NUM_EVENTS] =
 {
 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
@@ -9351,7 +9367,7 @@ apply_autocmds_group(
 {
 	sfname = vim_strsave(fname);
 	/* Don't try expanding FileType, Syntax, FuncUndefined, WindowID,
-	 * ColorScheme or QuickFixCmd* */
+	 * ColorScheme, Error or QuickFixCmd* */
 	if (event == EVENT_FILETYPE
 		|| event == EVENT_SYNTAX
 		|| event == EVENT_FUNCUNDEFINED
@@ -9359,6 +9375,7 @@ apply_autocmds_group(
 		|| event == EVENT_SPELLFILEMISSING
 		|| event == EVENT_QUICKFIXCMDPRE
 		|| event == EVENT_COLORSCHEME
+		|| event == EVENT_ERROR
 		|| event == EVENT_OPTIONSET
 		|| event == EVENT_QUICKFIXCMDPOST)
 	fname = vim_strsave(fname);
@@ -9750,20 +9767,26 @@ has_autocmd(event_T event, char_u *sfname, buf_T *buf)
 char_u	*tail = gettail(sfname);
 int		retval = FALSE;
 
-fname = FullName_save(sfname, FALSE);
-if (fname == NULL)
-	return FALSE;
-
+/* don't try expanding Error */
+if (event == EVENT_ERROR) {
+	fname = vim_strsave(sfname);
+	if (fname == NULL)
+	return FALSE;
+} else {
+	fname = FullName_save(sfname, FALSE);
+	if (fname == NULL)
+	return FALSE;
 #ifdef BACKSLASH_IN_FILENAME
-/*
- * Replace all backslashes with forward slashes.  This makes the
- * autocommand patterns portable between Unix and MS-DOS.
- */
-sfname = vim_strsave(sfname);
-if (sfname != NULL)
-	forward_slash(sfname);
-forward_slash(fname);
+	/*
+	 * Replace all backslashes with forward slashes.  This makes the
+	 * autocommand patterns portable between Unix and MS-DOS.
+	 */
+	sfname = vim_strsave(sfname);
+	if (sfname != NULL)
+	forward_slash(sfname);
+	forward_slash(fname);
 #endif
+}
 
 for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next)
 	if (ap->pat != NULL && ap->cmds != NULL
@@ -10358,3 +10381,22 @@ write_eintr(int fd, void *buf, size_t bufsize)
 return ret;
 }
 #endif
+
+
+/*
+ * Get the corresponding pattern for the given error message code. The returned
+ * value is used for  when triggering the Error autocmd event.
+ */
+char_u *
+get_error_pat(char_u *code)
+{
+size_t	len;
+int		i;
+
+len = STRLEN(code);
+for (i = 0; error_pats[i].code; i++)
+	if (STRNCMP(error_pats[i].code, code, len) == 0)
+	return (char_u *)error_pats[i].pat;
+
+return NULL;
+}
diff --git a/src/globals.h b/src/globals.h
index 4c1b41f..4342b71 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -184,6 +184,10 @@ EXTERN int	did_emsg;		/* set by emsg() when the message
 EXTERN int	did_emsg_syntax;	/* did_emsg set because of a
 	   syntax error */
 EXTERN int	called_emsg;		/* always set by emsg() */
+#ifdef FEAT_AUTOCMD
+EXTERN char_u	*emsg_code INIT(= NULL);/* last error message code set by
+	   emsg() */
+#endif
 EXTERN int	ex_exitval INIT(= 0);	/* exit value for ex mode */
 EXTERN int	emsg_on_display INIT(= FALSE);	/* there is an error message */
 EXTERN int	rc_did_emsg INIT

Re: [patch] Add Error autocmd event

2016-02-09 Fir de Conversatie 'Andy Wokula' via vim_dev

Am 09.02.2016 um 20:48 schrieb Anton Lindqvist:

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.


You can already do something like (quoted from somewhere ...):

:au BufWrite * if v:cmdbang && !isdirectory(expand('%:h')) | cal 
mkdir(expand('%:h'), 'p')| endif

--
Andy

--
--
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 vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [patch] Add Error autocmd event

2016-02-09 Fir de Conversatie Anton Lindqvist
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 vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [patch] Add Error autocmd event

2016-02-09 Fir de Conversatie Ben Fritz
On Tuesday, February 9, 2016 at 2:01:43 AM UTC-6, Christian Brabandt wrote:
> > Can you think of a command or situation where this patch provides a
> > nice, useful solution?
> 
> I think, it has come up in the past before:
> - Catching E482/E484/E485 because /tmp got cleaned out would be 
>   possible.
>   https://groups.google.com/d/msg/vim_use/qgRob9SWDv8/FAOFVVcDTv0J
> - https://groups.google.com/d/msg/vim_dev/EbTWqBl2rdw/vT4fTaGFnMoJ
> - and possibly others, which I don't remember currently.
> 

A couple more interesting ideas:

Set 'nowrapscan' in the .vimrc, but catch an E385 (search hit bottom without 
match) and offer to wrap to the beginning (temporarily set wrapscan).

Or, similar to the initial use of rebuilding tags if a tag is not found, modify 
'path' if a file is not found for gf and friends.

Does the autocmd work to catch things thrown by :throw? If so there could be 
all kinds of uses for that.

Writes failing for files being readonly could prompt to retry with the sudo + 
tee trick.

I'm sure clever plugin authors will find plenty more.

-- 
-- 
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 vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [patch] Add Error autocmd event

2016-02-09 Fir de Conversatie Christian Brabandt
Hi Bram!

On Mo, 08 Feb 2016, 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.

But only, if the user did setup the Error autocommand. So he should 
expect that, right?

> Can you think of a command or situation where this patch provides a
> nice, useful solution?

I think, it has come up in the past before:
- Catching E482/E484/E485 because /tmp got cleaned out would be 
  possible.
  https://groups.google.com/d/msg/vim_use/qgRob9SWDv8/FAOFVVcDTv0J
- https://groups.google.com/d/msg/vim_dev/EbTWqBl2rdw/vT4fTaGFnMoJ
- and possibly others, which I don't remember currently.

Best,
Christian
-- 
Treffen sich Kinkel und Hinze im Magen von Kohl.
Sagt Kinkel: "Ich glaube, der Kohl hat mich gefressen."
Darauf Hinze: "Kann ich nichts zu sagen, ich kam von der anderen
  Seite rein."

-- 
-- 
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 vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [patch] Add Error autocmd event

2016-02-08 Fir de Conversatie Bram Moolenaar

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.

Can you think of a command or situation where this patch provides a
nice, useful solution?


-- 
I'm in shape.  Round IS a shape.

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
-- 
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 vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[patch] Add Error autocmd event

2016-02-08 Fir de Conversatie Anton Lindqvist
Hi,
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

-- 
-- 
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 vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/fileio.c b/src/fileio.c
index ecec757..9a1e294 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -7666,6 +7666,7 @@ static struct event_name
 {"CursorMoved",	EVENT_CURSORMOVED},
 {"CursorMovedI",	EVENT_CURSORMOVEDI},
 {"EncodingChanged",	EVENT_ENCODINGCHANGED},
+{"Error",		EVENT_ERROR},
 {"FileEncoding",	EVENT_ENCODINGCHANGED},
 {"FileAppendPost",	EVENT_FILEAPPENDPOST},
 {"FileAppendPre",	EVENT_FILEAPPENDPRE},
@@ -7725,6 +7726,21 @@ static struct event_name
 {NULL,		(event_T)0}
 };
 
+
+/*
+ * Mapping of error code to pattern used for  when triggering the Error
+ * event.
+ */
+static struct error_pat
+{
+const char	*code;
+const char	*pat;
+} error_pats[] =
+{
+{"E426",	"tagnotfound"},
+{NULL,	NULL}
+};
+
 static AutoPat *first_autopat[NUM_EVENTS] =
 {
 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
@@ -9351,7 +9367,7 @@ apply_autocmds_group(
 {
 	sfname = vim_strsave(fname);
 	/* Don't try expanding FileType, Syntax, FuncUndefined, WindowID,
-	 * ColorScheme or QuickFixCmd* */
+	 * ColorScheme, Error or QuickFixCmd* */
 	if (event == EVENT_FILETYPE
 		|| event == EVENT_SYNTAX
 		|| event == EVENT_FUNCUNDEFINED
@@ -9359,6 +9375,7 @@ apply_autocmds_group(
 		|| event == EVENT_SPELLFILEMISSING
 		|| event == EVENT_QUICKFIXCMDPRE
 		|| event == EVENT_COLORSCHEME
+		|| event == EVENT_ERROR
 		|| event == EVENT_OPTIONSET
 		|| event == EVENT_QUICKFIXCMDPOST)
 	fname = vim_strsave(fname);
@@ -9750,20 +9767,26 @@ has_autocmd(event_T event, char_u *sfname, buf_T *buf)
 char_u	*tail = gettail(sfname);
 int		retval = FALSE;
 
-fname = FullName_save(sfname, FALSE);
-if (fname == NULL)
-	return FALSE;
-
+/* don't try expanding Error */
+if (event == EVENT_ERROR) {
+	fname = vim_strsave(sfname);
+	if (fname == NULL)
+	return FALSE;
+} else {
+	fname = FullName_save(sfname, FALSE);
+	if (fname == NULL)
+	return FALSE;
 #ifdef BACKSLASH_IN_FILENAME
-/*
- * Replace all backslashes with forward slashes.  This makes the
- * autocommand patterns portable between Unix and MS-DOS.
- */
-sfname = vim_strsave(sfname);
-if (sfname != NULL)
-	forward_slash(sfname);
-forward_slash(fname);
+	/*
+	 * Replace all backslashes with forward slashes.  This makes the
+	 * autocommand patterns portable between Unix and MS-DOS.
+	 */
+	sfname = vim_strsave(sfname);
+	if (sfname != NULL)
+	forward_slash(sfname);
+	forward_slash(fname);
 #endif
+}
 
 for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next)
 	if (ap->pat != NULL && ap->cmds != NULL
@@ -10358,3 +10381,22 @@ write_eintr(int fd, void *buf, size_t bufsize)
 return ret;
 }
 #endif
+
+
+/*
+ * Get the corresponding pattern for the given error message code. The returned
+ * value is used for  when triggering the Error autocmd event.
+ */
+char_u *
+get_error_pat(char_u *code)
+{
+size_t	len;
+int		i;
+
+len = STRLEN(code);
+for (i = 0; error_pats[i].code; i++)
+	if (STRNCMP(error_pats[i].code, code, len) == 0)
+	return (char_u *)e