diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2016-04-17 20:24:23 -0400 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2016-04-17 20:24:23 -0400 |
commit | 007d573147bb9086c63e779b1db3938690037db8 (patch) | |
tree | 8a0833743202d0e6be899fe65b50a47197c0e40a /src/nvim/api/buffer.c | |
parent | 83c683f5e15867c2e2889442860e91fd1074b4e1 (diff) | |
parent | a64114eba017c0db3d1849186c9c54fb09308761 (diff) | |
download | rneovim-007d573147bb9086c63e779b1db3938690037db8.tar.gz rneovim-007d573147bb9086c63e779b1db3938690037db8.tar.bz2 rneovim-007d573147bb9086c63e779b1db3938690037db8.zip |
Merge pull request #4131 from ZyX-I/json-functions
Add JSON support
Diffstat (limited to 'src/nvim/api/buffer.c')
-rw-r--r-- | src/nvim/api/buffer.c | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index c25a9789c5..55b535c78c 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -423,13 +423,16 @@ Object buffer_get_var(Buffer buffer, String name, Error *err) return dict_get_value(buf->b_vars, name, err); } -/// Sets a buffer-scoped (b:) variable. 'nil' value deletes the variable. +/// Sets a buffer-scoped (b:) variable /// /// @param buffer The buffer handle /// @param name The variable name /// @param value The variable value /// @param[out] err Details of an error that may have occurred -/// @return The old value +/// @return The old value or nil if there was no previous value. +/// +/// @warning It may return nil if there was no previous value +/// or if previous value was `v:null`. Object buffer_set_var(Buffer buffer, String name, Object value, Error *err) { buf_T *buf = find_buffer_by_handle(buffer, err); @@ -438,7 +441,27 @@ Object buffer_set_var(Buffer buffer, String name, Object value, Error *err) return (Object) OBJECT_INIT; } - return dict_set_value(buf->b_vars, name, value, err); + return dict_set_value(buf->b_vars, name, value, false, err); +} + +/// Removes a buffer-scoped (b:) variable +/// +/// @param buffer The buffer handle +/// @param name The variable name +/// @param[out] err Details of an error that may have occurred +/// @return The old value or nil if there was no previous value. +/// +/// @warning It may return nil if there was no previous value +/// or if previous value was `v:null`. +Object buffer_del_var(Buffer buffer, String name, Error *err) +{ + buf_T *buf = find_buffer_by_handle(buffer, err); + + if (!buf) { + return (Object) OBJECT_INIT; + } + + return dict_set_value(buf->b_vars, name, NIL, true, err); } /// Gets a buffer option value |