From 9dd1d2cd003d2567fcd47c8cb54603cc348dec01 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Fri, 9 May 2014 14:45:18 -0300 Subject: [PATCH] API: Implement buffer switching functions --- src/api/vim.c | 24 ++++++++++++++++-------- src/api/vim.h | 10 ++-------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/api/vim.c b/src/api/vim.c index c23ac8affd..6b04c4b7a5 100644 --- a/src/api/vim.c +++ b/src/api/vim.c @@ -8,6 +8,7 @@ #include "api/defs.h" #include "api/buffer.h" #include "../vim.h" +#include "../buffer.h" #include "types.h" #include "ascii.h" #include "ex_docmd.h" @@ -184,19 +185,26 @@ int64_t vim_get_buffer_count(void) return n; } -Buffer vim_get_buffer(int64_t num, Error *err) -{ - abort(); -} - Buffer vim_get_current_buffer(void) { - abort(); + return curbuf->b_fnum; } -void vim_set_current_buffer(Buffer buffer) +void vim_set_current_buffer(Buffer buffer, Error *err) { - abort(); + try_start(); + if (do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, buffer, 0) == FAIL) { + if (try_end(err)) { + return; + } + + char msg[256]; + snprintf(msg, sizeof(msg), "failed to switch to buffer %d", (int)buffer); + set_api_error(msg, err); + return; + } + + try_end(err); } int64_t vim_get_window_count(void) diff --git a/src/api/vim.h b/src/api/vim.h index 81aadb2014..e310842e5b 100644 --- a/src/api/vim.h +++ b/src/api/vim.h @@ -101,13 +101,6 @@ void vim_err_write(String str); /// @return The number of buffers int64_t vim_get_buffer_count(void); -/// Gets a buffer by index -/// -/// @param num The buffer number -/// @param[out] err Details of an error that may have occurred -/// @return The buffer handle -Buffer vim_get_buffer(int64_t num, Error *err); - /// Return the current buffer /// /// @reqturn The buffer handle @@ -116,7 +109,8 @@ Buffer vim_get_current_buffer(void); /// Sets the current buffer /// /// @param id The buffer handle -void vim_set_current_buffer(Buffer buffer); +/// @param[out] err Details of an error that may have occurred +void vim_set_current_buffer(Buffer buffer, Error *err); /// Gets the number of windows ///