Skip to content

Commit

Permalink
feat: Add info buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidz committed Jan 31, 2024
1 parent 614bbd1 commit 9d39cb7
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 2 deletions.
69 changes: 69 additions & 0 deletions autoload/elin/compat/buffer.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
function! elin#compat#buffer#focus_by_win_nr(win_nr) abort
execute printf('%dwincmd w', a:win_nr)
endfunction

function! elin#compat#buffer#focus_by_name(buf_name) abort
let win_nr = bufwinnr(a:buf_name)
if win_nr == -1
return
endif
return elin#compat#buffer#focus_by_win_nr(win_nr)
endfunction

function! elin#compat#buffer#is_visible(buf_name) abort
return bufwinnr(a:buf_name) != -1
endfunction

function! elin#compat#buffer#open(buf_name, option) abort
let opt = type(a:option) == v:t_dict ? a:option : {}
let mods = get(opt, 'mods', '')
let opener = get(opt, 'opener', 'split')
execute printf('%s %s %s', mods, opener, a:buf_name)
endfunction

function! elin#compat#buffer#append_line(buf_name, one_line) abort
if has('nvim')
return nvim_buf_set_lines(bufnr(a:buf_name), -1, -1, 0, [a:one_line])
else
call appendbufline(a:buf_name, '$', a:one_line)
endif
endfunction

function! s:delete_color_code(s) abort
return substitute(a:s, '\[[0-9;]*m', '', 'g')
endfunction

function! s:scroll_to_bottom(nr) abort
let current_window = winnr()
let last_window = winnr('#')
try
let &eventignore = 'WinEnter,WinLeave,BufEnter,BufLeave'
call elin#compat#buffer#focus_by_win_nr(bufwinnr(a:nr))
silent normal! G
finally
" Preserve the user's last visited window by focusing to it first (PR #187)
call elin#compat#buffer#focus_by_win_nr(last_window)
call elin#compat#buffer#focus_by_win_nr(current_window)
let &eventignore = ''
endtry
endfunction

function! elin#compat#buffer#append(buf_name, s, ...) abort
let nr = bufnr(a:buf_name)
if nr < 0 | return | endif
let opt = get(a:, 1, {})

for line in split(s:delete_color_code(a:s), '\r\?\n')
silent call elin#compat#buffer#append_line(a:buf_name, line)
endfor

if get(opt, 'scroll_to_bottom', v:false)
\ && elin#compat#buffer#is_visible(a:buf_name)
\ && bufnr('%') != nr
call elin#util#start_lazily('scroll_to_bottom', 500, funcref('s:scroll_to_bottom', [nr]))
endif
endfunction

function! elin#compat#buffer#clear(buf_name) abort
return deletebufline(a:buf_name, 1, "$")
endfunction
99 changes: 99 additions & 0 deletions autoload/elin/internal/buffer/info.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
let s:buf_name = 'elin_info_buffer'
let s:delimiter = ';; ----------'

function! elin#internal#buffer#info#open() abort
if elin#compat#buffer#is_visible(s:buf_name)
return
endif

call elin#compat#buffer#open(s:buf_name, {})
"call elin#compat#buffer#focus_by_name(s:buf_name)
endfunction

function! elin#internal#buffer#info#ready() abort
if bufnr(s:buf_name) != -1
return
endif
silent execute printf(':split %s', s:buf_name)
silent execute ':q'

call setbufvar(s:buf_name, 'lsp_diagnostics_enabled', 0)
call setbufvar(s:buf_name, '&bufhidden', 'hide')
call setbufvar(s:buf_name, '&buflisted', 0)
call setbufvar(s:buf_name, '&buftype', 'nofile')
call setbufvar(s:buf_name, '&filetype', 'clojure')
call setbufvar(s:buf_name, '&swapfile', 0)
call setbufvar(s:buf_name, '&wrap', 0)
endfunction

function! elin#internal#buffer#info#append(s) abort
" let s = iced#util#delete_color_code(a:s)
" let timer = iced#system#get('timer')

call elin#compat#buffer#append(s:buf_name, a:s, {'scroll_to_bottom': v:true})

" call timer.start_lazily(
" \ 'delete_old_lines',
" \ g:iced#buffer#stdout#deleting_line_delay,
" \ funcref('s:delete_old_lines'),
" \ )

if a:s !=# s:delimiter
call elin#util#start_lazily('append_delimiter', 500, {-> elin#internal#buffer#info#append(s:delimiter)})
endif
" if g:iced#buffer#stdout#enable_delimiter
" \ && a:s !=# g:iced#buffer#stdout#delimiter_line
" call timer.start_lazily(
" \ 'append_delimiter',
" \ g:iced#buffer#stdout#delimiter_delay,
" \ {-> (g:iced#buffer#stdout#enable_delimiter)
" \ ? iced#buffer#stdout#append(g:iced#buffer#stdout#delimiter_line)
" \ : ''},
" \ )
" endif

" if ! iced#buffer#stdout#is_visible()
" \ && g:iced#buffer#stdout#enable_notify
" silent call iced#system#get('notify').notify(s, {'title': 'Stdout'})
" endif
endfunction



" import { Diced } from "../../types.ts";
" import * as vimBuf from "../../std/vim/buffer.ts";
"
" export const bufName = "diced_info";
"
" export async function open(diced: Diced): Promise<boolean> {
" const denops = diced.denops;
" const currentWin = await dpsFns.winnr(denops);
" if (await vimBuf.isVisible(diced, bufName)) return false;
" if (!await vimBuf.open(diced, bufName)) return false;
" await vimBuf.focusByWinNr(diced, currentWin);
" return true;
" }
"
" export async function ready(diced: Diced): Promise<void> {
" const denops = diced.denops;
" if (await dpsFns.bufnr(denops, bufName) !== -1) return;
"
" dpsHelper.execute(
" denops,
" `
" silent execute ':split ${bufName}'
" silent execute ':q'
"
" call setbufvar('${bufName}', 'lsp_diagnostics_enabled', 0)
" call setbufvar('${bufName}', '&bufhidden', 'hide')
" call setbufvar('${bufName}', '&buflisted', 0)
" call setbufvar('${bufName}', '&buftype', 'nofile')
" call setbufvar('${bufName}', '&filetype', 'clojure')
" call setbufvar('${bufName}', '&swapfile', 0)
" call setbufvar('${bufName}', '&wrap', 0)
" `,
" );
"
" return;
" }
"
4 changes: 4 additions & 0 deletions src/elin/function/vim.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
[elin.util.function :as e.u.function]
[malli.core :as m]))

(m/=> call!! [:=> [:cat e.s.server/?Writer string? [:sequential any?]] any?])
(defn call!! [writer function-name params]
(async/<!! (e.u.function/call-function writer function-name params)))

(m/=> get-current-working-directory!! [:=> [:cat e.s.server/?Writer [:* any?]] (e.schema/error-or string?)])
(defn get-current-working-directory!!
[writer & extra-params]
Expand Down
5 changes: 3 additions & 2 deletions src/elin/handler/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
[elin.protocol.interceptor :as e.p.interceptor]))

(defmethod e.handler/handler* :initialize
[_]
[{:component/keys [writer]}]
;; TODO Load plugins
"FIXME")
(e.f.vim/call!! writer "elin#internal#buffer#info#ready" [])
true)

(defmethod e.handler/handler* :intercept
[{:as elin :component/keys [interceptor] :keys [message]}]
Expand Down

0 comments on commit 9d39cb7

Please sign in to comment.