/// Gets the buffer line count /// /// @param buffer The buffer handle /// @param[out] err Details of an error that may have occurred /// @return The line count Integer buffer_line_count(Buffer buffer, Error *err) { buf_T *buf = find_buffer_by_handle(buffer, err); if (!buf) { return 0; } return buf->b_ml.ml_line_count; }
/// Sets the current buffer /// /// @param id The buffer handle /// @param[out] err Details of an error that may have occurred void vim_set_current_buffer(Buffer buffer, Error *err) { buf_T *buf = find_buffer_by_handle(buffer, err); if (!buf) { return; } try_start(); if (do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, buf->b_fnum, 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); }
/// (usually by opening the buffer again in a new window). API methods such as /// |nvim_buf_get_lines()| and |nvim_buf_line_count()| will be affected. /// /// You can use |nvim_buf_is_loaded()| or |nvim_buf_line_count()| to check /// whether a buffer is loaded. /// Gets the buffer line count /// /// @param buffer Buffer handle, or 0 for current buffer /// @param[out] err Error details, if any /// @return Line count, or 0 for unloaded buffer. |api-buffer| Integer nvim_buf_line_count(Buffer buffer, Error *err) FUNC_API_SINCE(1) { buf_T *buf = find_buffer_by_handle(buffer, err); if (!buf) { return 0; } // return sentinel value if the buffer isn't loaded if (buf->b_ml.ml_mfp == NULL) { return 0; } return buf->b_ml.ml_line_count; } /// Gets a buffer line ///