API: Implement buffer switching functions

This commit is contained in:
Thiago de Arruda 2014-05-09 14:45:18 -03:00
parent c001cfdba0
commit 9dd1d2cd00
2 changed files with 18 additions and 16 deletions

View File

@ -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)

View File

@ -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
///