-
-
Notifications
You must be signed in to change notification settings - Fork 35
Referring to evaluation ranges in :IcedEval #407
Comments
@sheluchin Currently there is no way to do that. vim-iced/autoload/iced/operation.vim Lines 59 to 61 in 0382d4c
|
@liquidz Thank you for your consideration. A generalized Reveal has a similar feature which it implements by using Maybe vim-iced could implement it similarly by using something like My knowledge of vimscript is unfortunately not very strong, but I hacked around the |
So I tried this: function! iced#operation#eval_and_tap_wrapped(type, wrapper) abort
return s:eval({code -> iced#repl#execute(
\ 'eval_code',
\ printf('(clojure.core/tap> %s)', substitute(a:wrapper, '*v', code, 'g')))})
endfunction And then with the cursor positioned at (iden|tity (do (Thread/sleep 5000) (str 123))) I used "Elapsed time: 5001.441812 msecs"
; I think this line is a Reveal artifact you can probably ignore
(clojure.core/tap> (time (identity (do (Thread/sleep 5000) (str 123)))))
=> true
tap> "123" I think that looks pretty good, but I'm sure it could be improved. What do you think, @liquidz? I like this idea because it allows for a tighter integration between the editor and the interactive environment. For example, it would make it easy to create an editor mapping that would pass a datalog query directly to your query function without having to manually wrap the query in your code. |
@sheluchin Nice work! Thanks! |
@sheluchin How about to define a function like below? function! s:eval_wrapped(wrapper, type) abort
return s:eval({code -> iced#repl#execute('eval_code',
\ substitute(a:wrapper, '*v', code, 'g')
\ )})
endfunction
function! iced#operation#setup_wrapper(wrapper) abort
let &operatorfunc = funcref('s:eval_wrapped', [a:wrapper])
let s:register = v:register
endfunction Then, we can define the following mappings. nnoremap <silent> <Plug>(iced_eval_and_time) <Cmd>call iced#operation#setup_wrapper('(clojure.core/time *v)')<CR>g@
aug Fixme
au!
au FileType clojure nmap <buffer> <Leader>eat <Plug>(iced_eval_and_time)<Plug>(sexp_outer_list)``
aug END It may be a little difficult to define, but this feature will allow us to freely define operations wchich wraps some code. |
So by separating the evaluation and wrapper setup into two functions it makes it possible to use the setup generically to define bindings. Looks like a good idea. It looks like there is a bug in your snippet because when I try to use it:
I don't know vim script, but it looks like an I'll note that this direction is slightly different from the initial idea of issue - using the evaluation range in |
@sheluchin Oh, it seems a problem in neovim. (works in vim) |
Ah, neovim has not been applied patch 8.2.3619 yet. I'll reconsider. |
@liquidz thanks for giving this some thought. I think it's reasonable to wait for the patch to merged to Neovim if there's no easy workaround now. I can try just using my above snippet with |
@sheluchin Thanks! |
Nice catch! |
One more idea about this... if it can also be possible to include the cursor position as an argument to the receiving Clojure function, it would make a powerful way to extend vim-iced functionality using Clojure code. For example, given a form like: (let [k :foo]
(x k)
(y |k)
(z k)) if the sending the outer top list can look like Just an idea 🤷♂️ |
Not an issue, but a question.
Is it possible to refer to some evaluation range within the code passed to
:IcedEval
? For example, if I want to do something like:IcedEval '(time <outer list>)'
, is there some way to write that without literally copying the outer list?Thank you for the amazing plugin!
The text was updated successfully, but these errors were encountered: