mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 10:20:05 +08:00
Add vim#window api (#3133)
This commit is contained in:
parent
9b354e05b4
commit
8a6baac866
@ -9,6 +9,11 @@
|
|||||||
""
|
""
|
||||||
" @section vim#buffer, api-vim-buffer
|
" @section vim#buffer, api-vim-buffer
|
||||||
" @parentsection api
|
" @parentsection api
|
||||||
|
" @subsection Intro
|
||||||
|
"
|
||||||
|
" vim#buffer API provides some basic functions for setting and getting config
|
||||||
|
" of vim buffer.
|
||||||
|
"
|
||||||
" @subsection Functions
|
" @subsection Functions
|
||||||
"
|
"
|
||||||
" is_cmdwin()
|
" is_cmdwin()
|
||||||
|
54
autoload/SpaceVim/api/vim/window.vim
Normal file
54
autoload/SpaceVim/api/vim/window.vim
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
"=============================================================================
|
||||||
|
" window.vim --- window api for vim and neovim
|
||||||
|
" Copyright (c) 2016-2019 Wang Shidong & Contributors
|
||||||
|
" Author: Wang Shidong < wsdjeg@outlook.com >
|
||||||
|
" URL: https://spacevim.org
|
||||||
|
" License: GPLv3
|
||||||
|
"=============================================================================
|
||||||
|
|
||||||
|
""
|
||||||
|
" @section vim#buffer, api-vim-window
|
||||||
|
" @parentsection api
|
||||||
|
" @subsection Intro
|
||||||
|
"
|
||||||
|
" vim#window API provides some basic functions for setting and getting config
|
||||||
|
" of vim window.
|
||||||
|
"
|
||||||
|
" @subsection Functions
|
||||||
|
"
|
||||||
|
" get_cursor({winid})
|
||||||
|
"
|
||||||
|
" Gets the cursor position in the window {winid}, to get the ID of a window,
|
||||||
|
" checkout |window-ID|.
|
||||||
|
|
||||||
|
let s:self = {}
|
||||||
|
|
||||||
|
if exists('*nvim_win_get_cursor')
|
||||||
|
function! s:self.get_cursor(winid) abort
|
||||||
|
return nvim_win_get_cursor(a:winid)
|
||||||
|
endfunction
|
||||||
|
elseif g:_spacevim_if_lua
|
||||||
|
function! s:self.get_cursor(winid) abort
|
||||||
|
lua require("spacevim.api.vim.window").get_cursor(vim.eval("a:winid"))
|
||||||
|
endfunction
|
||||||
|
else
|
||||||
|
function! s:self.get_cursor(winid) abort
|
||||||
|
|
||||||
|
endfunction
|
||||||
|
endif
|
||||||
|
|
||||||
|
if exists('*nvim_win_set_cursor')
|
||||||
|
function! s:self.set_cursor(winid, pos) abort
|
||||||
|
return nvim_win_set_cursor(a:winid, a:pos)
|
||||||
|
endfunction
|
||||||
|
elseif g:_spacevim_if_lua
|
||||||
|
function! s:self.set_cursor(winid, pos) abort
|
||||||
|
lua require("spacevim.api.vim.window").set_cursor(vim.eval("a:winid"), vim.eval("a:pos"))
|
||||||
|
endfunction
|
||||||
|
else
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
function! SpaceVim#api#vim#window#get() abort
|
||||||
|
return deepcopy(s:self)
|
||||||
|
endfunction
|
@ -73,7 +73,7 @@ function! SpaceVim#layers#lang#lua#config() abort
|
|||||||
elseif executable('luap')
|
elseif executable('luap')
|
||||||
let lua_repl = 'luap'
|
let lua_repl = 'luap'
|
||||||
elseif !empty(luaexe)
|
elseif !empty(luaexe)
|
||||||
let lua_repl = luaexe[0] + ['-i']
|
let lua_repl = luaexe + ['-i']
|
||||||
else
|
else
|
||||||
let lua_repl = ['lua', '-i']
|
let lua_repl = ['lua', '-i']
|
||||||
endif
|
endif
|
||||||
|
@ -133,9 +133,10 @@ CONTENTS *SpaceVim-contents*
|
|||||||
9. sid............................................|SpaceVim-api-vim-sid|
|
9. sid............................................|SpaceVim-api-vim-sid|
|
||||||
10. system.........................................|SpaceVim-api-system|
|
10. system.........................................|SpaceVim-api-system|
|
||||||
11. vim#buffer.................................|SpaceVim-api-vim-buffer|
|
11. vim#buffer.................................|SpaceVim-api-vim-buffer|
|
||||||
12. vim#command...............................|SpaceVim-api-vim-command|
|
12. vim#buffer.................................|SpaceVim-api-vim-window|
|
||||||
13. vim#compatible.........................|SpaceVim-api-vim-compatible|
|
13. vim#command...............................|SpaceVim-api-vim-command|
|
||||||
14. vim#message...............................|SpaceVim-api-vim-message|
|
14. vim#compatible.........................|SpaceVim-api-vim-compatible|
|
||||||
|
15. vim#message...............................|SpaceVim-api-vim-message|
|
||||||
8. FAQ........................................................|SpaceVim-faq|
|
8. FAQ........................................................|SpaceVim-faq|
|
||||||
9. Changelog............................................|SpaceVim-changelog|
|
9. Changelog............................................|SpaceVim-changelog|
|
||||||
|
|
||||||
@ -2467,6 +2468,11 @@ mac.
|
|||||||
==============================================================================
|
==============================================================================
|
||||||
VIM#BUFFER *SpaceVim-api-vim-buffer*
|
VIM#BUFFER *SpaceVim-api-vim-buffer*
|
||||||
|
|
||||||
|
INTRO
|
||||||
|
|
||||||
|
vim#buffer API provides some basic functions for setting and getting config of
|
||||||
|
vim buffer.
|
||||||
|
|
||||||
FUNCTIONS
|
FUNCTIONS
|
||||||
|
|
||||||
is_cmdwin()
|
is_cmdwin()
|
||||||
@ -2486,6 +2492,21 @@ is a dict with following keys:
|
|||||||
|
|
||||||
cmd: the ex command which will be run after the new buffer is created
|
cmd: the ex command which will be run after the new buffer is created
|
||||||
|
|
||||||
|
==============================================================================
|
||||||
|
VIM#BUFFER *SpaceVim-api-vim-window*
|
||||||
|
|
||||||
|
INTRO
|
||||||
|
|
||||||
|
vim#window API provides some basic functions for setting and getting config of
|
||||||
|
vim window.
|
||||||
|
|
||||||
|
FUNCTIONS
|
||||||
|
|
||||||
|
get_cursor({winid})
|
||||||
|
|
||||||
|
Gets the cursor position in the window {winid}, to get the ID of a window,
|
||||||
|
checkout |window-ID|.
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
VIM#COMMAND *SpaceVim-api-vim-command*
|
VIM#COMMAND *SpaceVim-api-vim-command*
|
||||||
|
|
||||||
|
30
docs/api/vim/buffer.md
Normal file
30
docs/api/vim/buffer.md
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
---
|
||||||
|
title: "vim#buffer api"
|
||||||
|
description: "vim#buffer API provides some basic functions for setting and getting config of vim buffer."
|
||||||
|
---
|
||||||
|
|
||||||
|
# [Available APIs](../../) >> vim#buffer
|
||||||
|
|
||||||
|
<!-- vim-markdown-toc GFM -->
|
||||||
|
|
||||||
|
- [Intro](#intro)
|
||||||
|
- [Functions](#functions)
|
||||||
|
|
||||||
|
<!-- vim-markdown-toc -->
|
||||||
|
|
||||||
|
## Intro
|
||||||
|
|
||||||
|
vim#buffer API provides some basic functions for setting and getting config of vim buffer.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
let s:BUFFER = SpaceVim#api#import('vim#buffer')
|
||||||
|
```
|
||||||
|
|
||||||
|
## Functions
|
||||||
|
|
||||||
|
here is a list of functions implement in this api. When Vim has python or lua support,
|
||||||
|
some of these functions are better experienced
|
||||||
|
|
||||||
|
| function name | description |
|
||||||
|
| ---------------- | -------------------------- |
|
||||||
|
| `filter_do(cmd)` | filter buffers and run cmd |
|
35
docs/api/vim/window.md
Normal file
35
docs/api/vim/window.md
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
---
|
||||||
|
title: "vim#window api"
|
||||||
|
description: "vim#window API provides some basic functions for setting and getting config of vim window."
|
||||||
|
---
|
||||||
|
|
||||||
|
# [Available APIs](../../) >> vim#window
|
||||||
|
|
||||||
|
<!-- vim-markdown-toc GFM -->
|
||||||
|
|
||||||
|
- [Intro](#intro)
|
||||||
|
- [Functions](#functions)
|
||||||
|
|
||||||
|
<!-- vim-markdown-toc -->
|
||||||
|
|
||||||
|
## Intro
|
||||||
|
|
||||||
|
vim#window API provides some basic functions for setting and getting config of vim window.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
let s:WINDOW = SpaceVim#api#import('vim#window')
|
||||||
|
" if you want to change the cursor to [10, 3] in window winid
|
||||||
|
call s:WINDOW.set_cursor(s:winid, [10, 3])
|
||||||
|
" of cause, you can get the cursor for a window
|
||||||
|
let cursorpos = s:WINDOW.get_cursor(s:winid)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Functions
|
||||||
|
|
||||||
|
here is a list of functions implement in this api. When Vim has python or lua support,
|
||||||
|
some of these functions are better experienced
|
||||||
|
|
||||||
|
| function name | description |
|
||||||
|
| ------------------------ | --------------------------------------- |
|
||||||
|
| `get_cursor(winid)` | Gets the cursor position in the window. |
|
||||||
|
| `set_cursor(winid, pos)` | Sets the cursor position in the window. |
|
2
init.vim
2
init.vim
@ -7,5 +7,3 @@
|
|||||||
"=============================================================================
|
"=============================================================================
|
||||||
|
|
||||||
execute 'source' fnamemodify(expand('<sfile>'), ':h').'/config/main.vim'
|
execute 'source' fnamemodify(expand('<sfile>'), ':h').'/config/main.vim'
|
||||||
|
|
||||||
" lua require('spacevim').bootstrap()
|
|
||||||
|
0
lua/spacevim/api/vim/buffer.lua
Normal file
0
lua/spacevim/api/vim/buffer.lua
Normal file
27
lua/spacevim/api/vim/window.lua
Normal file
27
lua/spacevim/api/vim/window.lua
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
local window = {}
|
||||||
|
|
||||||
|
function window.get_cursor(window_id)
|
||||||
|
local winindex = vim.eval("win_id2win(" .. window_id .. ")")
|
||||||
|
local w = vim.window(winindex)
|
||||||
|
if w == nil then
|
||||||
|
vim.command("return [" .. table.concat({0, 0}, ", ") .. "]")
|
||||||
|
else
|
||||||
|
vim.command("return [" .. table.concat({w.line, w.col}, ", ") .. "]")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function window.set_cursor(window_id, pos)
|
||||||
|
local winindex = vim.eval("win_id2win(" .. window_id .. ")")
|
||||||
|
local w = vim.window(winindex)
|
||||||
|
w.line = pos[1]
|
||||||
|
w.col = pos[2]
|
||||||
|
end
|
||||||
|
|
||||||
|
function window.close(window_id)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
return window
|
||||||
|
|
||||||
|
|
11
vimrc
11
vimrc
@ -8,6 +8,17 @@
|
|||||||
|
|
||||||
" Note: Skip initialization for vim-tiny or vim-small.
|
" Note: Skip initialization for vim-tiny or vim-small.
|
||||||
if 1
|
if 1
|
||||||
|
let g:_spacevim_if_lua = 0
|
||||||
|
if has('lua')
|
||||||
|
try
|
||||||
|
let s:plugin_dir = fnamemodify(expand('<sfile>'), ':h').'\lua'
|
||||||
|
let s:str = s:plugin_dir . '\?.lua;' . s:plugin_dir . '\?\init.lua;'
|
||||||
|
lua package.path=vim.eval("s:str") .. package.path
|
||||||
|
let g:_spacevim_if_lua = 1
|
||||||
|
catch
|
||||||
|
let g:_spacevim_if_lua = 0
|
||||||
|
endtry
|
||||||
|
endif
|
||||||
execute 'source' fnamemodify(expand('<sfile>'), ':h').'/config/main.vim'
|
execute 'source' fnamemodify(expand('<sfile>'), ':h').'/config/main.vim'
|
||||||
endif
|
endif
|
||||||
" vim:set et sw=2
|
" vim:set et sw=2
|
||||||
|
Loading…
Reference in New Issue
Block a user