diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2014-05-08 17:24:14 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-05-13 09:33:40 -0300 |
commit | d488b7de1df729aa6fbc3b1107d9f5ad3be5235a (patch) | |
tree | cebf6db2713a02f2b04ad3ca8aec879356d0ca0d /src/api/buffer.c | |
parent | 9f25a4153ca17fb5bbba47688817fef984c64b14 (diff) | |
download | rneovim-d488b7de1df729aa6fbc3b1107d9f5ad3be5235a.tar.gz rneovim-d488b7de1df729aa6fbc3b1107d9f5ad3be5235a.tar.bz2 rneovim-d488b7de1df729aa6fbc3b1107d9f5ad3be5235a.zip |
API: Extract error boilerplate into a macro
Diffstat (limited to 'src/api/buffer.c')
-rw-r--r-- | src/api/buffer.c | 24 |
1 files changed, 6 insertions, 18 deletions
diff --git a/src/api/buffer.c b/src/api/buffer.c index 554272955e..39c69f1ce7 100644 --- a/src/api/buffer.c +++ b/src/api/buffer.c @@ -68,9 +68,7 @@ void buffer_set_line(Buffer buffer, int64_t index, Object line, Error *err) } if (line.type != kObjectTypeNil && line.type != kObjectTypeString) { - char msg[] = "Invalid line"; - strncpy(err->msg, msg, sizeof(err->msg)); - err->set = true; + set_api_error("Invalid line", err); return; } @@ -86,14 +84,10 @@ void buffer_set_line(Buffer buffer, int64_t index, Object line, Error *err) if (u_savedel(index, 1L) == FAIL) { // Failed to save undo - char msg[] = "Cannot save undo information"; - strncpy(err->msg, msg, sizeof(err->msg)); - err->set = true; + set_api_error("Cannot save undo information", err); } else if (ml_delete(index, FALSE) == FAIL) { // Failed to delete - char msg[] = "Cannot delete the line"; - strncpy(err->msg, msg, sizeof(err->msg)); - err->set = true; + set_api_error("Cannot delete the line", err); } else { restore_win_for_buf(save_curwin, save_curtab, save_curbuf); // Success @@ -117,14 +111,10 @@ void buffer_set_line(Buffer buffer, int64_t index, Object line, Error *err) if (u_savesub(index) == FAIL) { // Failed to save undo - char msg[] = "Cannot save undo information"; - strncpy(err->msg, msg, sizeof(err->msg)); - err->set = true; + set_api_error("Cannot save undo information", err); } else if (ml_replace(index, (char_u *)string, FALSE) == FAIL) { // Failed to replace - char msg[] = "Cannot replace line"; - strncpy(err->msg, msg, sizeof(err->msg)); - err->set = true; + set_api_error("Cannot replace line", err); free(string); } else { // Success @@ -213,9 +203,7 @@ static buf_T *find_buffer(Buffer buffer, Error *err) buf_T *buf = buflist_findnr(buffer); if (buf == NULL) { - char msg[] = "Invalid buffer id"; - strncpy(err->msg, msg, sizeof(err->msg)); - err->set = true; + set_api_error("Invalid buffer id", err); } return buf; |