Skip to content

Commit

Permalink
Merge pull request #424 from liquidz/dev
Browse files Browse the repository at this point in the history
3.10.1
  • Loading branch information
liquidz authored Jul 28, 2022
2 parents bdd1768 + 2b21dd9 commit d0c2d50
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 26 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ All notable changes to this project will be documented in this file. This change

== Unreleased (dev)

== 3.10.1 (2022-07-29)
// {{{
=== Changed
* Applied idiomatic namespace aliases in style guide to default values for `g:iced#ns#favorites`.
** https://github.com/bbatsov/clojure-style-guide#use-idiomatic-namespace-aliases
* Bumped iced-nrepl to 1.2.13.

=== Fixed
* Fixed nbb connection to detect CLJS session correctly.
* https://github.com/liquidz/vim-iced/issues/423[#423]: Fixed a bug about evaluating reader conditionals.
// }}}

== 3.10.0 (2022-07-16)
// {{{
=== Added
Expand Down
28 changes: 24 additions & 4 deletions autoload/iced/nrepl.vim
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,11 @@ function! s:is_cljs_session(timeout_msec) abort
return (type(value) == v:t_string && value ==# 'true')
endfunction

function! s:is_nbb_nrepl(describe_resp) abort
let vers = get(a:describe_resp, 'versions', {})
return has_key(vers, 'nbb-nrepl')
endfunction

function! s:connected(resp, opts) abort
if has_key(a:resp, 'new-session')
try
Expand All @@ -447,15 +452,30 @@ function! s:connected(resp, opts) abort
call iced#nrepl#set_session(initial_session, session)
call iced#nrepl#change_current_session(initial_session)

let describe_resp = {}
try
if s:is_cljs_session(500)
call iced#nrepl#set_session('cljs', session)
call iced#nrepl#change_current_session('cljs')
endif
let describe_resp = iced#promise#sync('iced#nrepl#describe', [], 500)
catch
" ignore
endtry

if iced#nrepl#current_session_key() ==# 'clj'
if s:is_nbb_nrepl(describe_resp)
call iced#nrepl#set_session('cljs', session)
call iced#nrepl#change_current_session('cljs')
let a:opts['with_iced_nrepl'] = v:false
else
try
if s:is_cljs_session(500)
call iced#nrepl#set_session('cljs', session)
call iced#nrepl#change_current_session('cljs')
endif
catch
" ignore
endtry
endif
endif

let s:nrepl['init_ns'] = iced#nrepl#ns#name_by_var()

if get(a:opts, 'with_iced_nrepl', v:true)
Expand Down
18 changes: 16 additions & 2 deletions autoload/iced/nrepl/refactor.vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,36 @@ let s:L = s:V.import('Data.List')
" g:iced#ns#favorites {{{
let s:default_ns_favorites = {
\ 'clj': {
\ 'cheshire.core': 'json',
\ 'clj-http.client': 'http',
\ 'clj-yaml.core': 'yaml',
\ 'clojure.core.async': 'as',
\ 'clojure.core.matrix': 'mat',
\ 'clojure.data.csv': 'csv',
\ 'clojure.data.xml': 'xml',
\ 'clojure.edn': 'edn',
\ 'clojure.java.io': 'io',
\ 'clojure.java.shell': 'sh',
\ 'clojure.pprint': 'pp',
\ 'clojure.set': 'set',
\ 'clojure.spec.alpha': 's',
\ 'clojure.spec.alpha': 'spec',
\ 'clojure.spec.gen.alpha': 'sgen',
\ 'clojure.spec.test.alpha': 'stest',
\ 'clojure.string': 'str',
\ 'clojure.tools.logging': 'log',
\ 'clojure.walk': 'walk',
\ 'clojure.zip': 'zip',
\ 'hugsql.core': 'sql',
\ 'java-time': 'time',
\ },
\ 'cljs': {
\ 'cljs.core.async': 'as',
\ 'cljs.pprint': 'pp',
\ 'cljs.reader': 'reader',
\ 'cljs.spec.alpha': 's',
\ 'cljs.spec.alpha': 'spec',
\ 'cljs.spec.gen.alpha': 'sgen',
\ 'cljs.spec.test.alpha': 'stest',
\ 'clojure.edn': 'edn',
\ 'clojure.set': 'set',
\ 'clojure.string': 'str',
\ 'clojure.walk': 'walk',
Expand Down
37 changes: 24 additions & 13 deletions autoload/iced/paredit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,6 @@ function! s:set_visual_marks(marks) abort
endfunction

" Return visually selected text without changing selection state and registers
function! s:get_visual_selection() abort
let reg_save = @@
silent normal! y
let result = @@
let @@ = reg_save
silent normal! gv
return result
endfunction

function! s:get_visual_selection_and_pos() abort
let reg_save = @@
silent normal! y
Expand All @@ -262,7 +253,7 @@ function! s:select_top_list(top_code) abort
let current_marks = s:get_visual_marks()

call sexp#docount(2, 'sexp#select_current_list', 'v', 0, 1)
let next_code = s:get_visual_selection()
let next_code = get(s:get_visual_selection_and_pos(), 'code', '')

if (next_code ==# a:top_code) | break | endif
endwhile
Expand All @@ -273,13 +264,33 @@ function! s:select_top_list(top_code) abort
endtry
endfunction

function! s:select_current_top_list() abort
let current_line = line('.')
let start_line = search('^\S', 'bW')

call search('(', 'cW')
silent normal! %
let end_pos = getcurpos()

if start_line > current_line || current_line > end_pos[1]
return ''
endif

call cursor(start_line, 1)
silent normal! v
call cursor(end_pos[1], end_pos[2])
endfunction

function! iced#paredit#get_top_list_in_comment() abort
let view = winsaveview()
let curpos = getpos('.')

" First use vim-sexp optimized top form selector
call sexp#select_current_top_list('v', 0)
let top_code = s:get_visual_selection()
" NOTE: `sexp#select_current_top_list` cannot correctly select codes
" including reader conditionals like below
" > #?(:clj :foo
" > :cljs :bar)
call s:select_current_top_list()
let top_code = get(s:get_visual_selection_and_pos(), 'code', '')

if (stridx(top_code, '(comment') == 0)
" Select up one by one if the top list is a (comment ...) form
Expand Down
2 changes: 1 addition & 1 deletion bin/iced
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SCRIPT_DIR=$(cd $(dirname $0); pwd)
PROJECT_DIR=$(cd $SCRIPT_DIR; cd ..; pwd)
VERSION=$(grep 'Version: ' ${SCRIPT_DIR}/../doc/vim-iced.txt | cut -d' ' -f2)

BASE_DEPENDENCIES='nrepl/nrepl:0.9.0 refactor-nrepl/refactor-nrepl:3.5.3 cider/cider-nrepl:0.28.5 com.github.liquidz/iced-nrepl:1.2.12'
BASE_DEPENDENCIES='nrepl/nrepl:0.9.0 refactor-nrepl/refactor-nrepl:3.5.3 cider/cider-nrepl:0.28.5 com.github.liquidz/iced-nrepl:1.2.13'
BASE_MIDDLEWARES='cider.nrepl/wrap-classpath cider.nrepl/wrap-clojuredocs cider.nrepl/wrap-complete cider.nrepl/wrap-debug cider.nrepl/wrap-format cider.nrepl/wrap-info cider.nrepl/wrap-macroexpand cider.nrepl/wrap-ns cider.nrepl/wrap-out cider.nrepl/wrap-refresh cider.nrepl/wrap-stacktrace cider.nrepl/wrap-spec cider.nrepl/wrap-test cider.nrepl/wrap-trace cider.nrepl/wrap-undef cider.nrepl/wrap-xref refactor-nrepl.middleware/wrap-refactor iced.nrepl/wrap-iced'

CLJS_DEPENDENCIES='cider/piggieback:0.5.3'
Expand Down
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
:deps {nrepl/nrepl {:mvn/version "0.9.0"}
refactor-nrepl/refactor-nrepl {:mvn/version "3.5.3"}
cider/cider-nrepl {:mvn/version "0.28.5"}
com.github.liquidz/iced-nrepl {:mvn/version "1.2.12"}}
com.github.liquidz/iced-nrepl {:mvn/version "1.2.13"}}
:__middlewares__
["cider.nrepl/wrap-classpath"
"cider.nrepl/wrap-clojuredocs"
Expand Down
8 changes: 4 additions & 4 deletions doc/vim-iced.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*vim-iced.txt* Clojure interactive development environment for Vim8/Neovim

Version: 3.10.0
Version: 3.10.1
Author : Masashi Iizuka <liquidz.uo+vim@gmail.com>
License: MIT LICENSE

Expand Down Expand Up @@ -139,7 +139,7 @@ LEININGEN~
>
{:user
{:dependencies [[nrepl "0.9.0"]
[com.github.liquidz/iced-nrepl "1.2.12"]
[com.github.liquidz/iced-nrepl "1.2.13"]
[cider/cider-nrepl "0.28.5"]]
:repl-options {:nrepl-middleware [cider.nrepl/wrap-classpath
cider.nrepl/wrap-clojuredocs
Expand Down Expand Up @@ -171,7 +171,7 @@ BOOT~
(swap! boot.repl/*default-dependencies* concat
'[[refactor-nrepl "3.5.3"]
[cider/cider-nrepl "0.28.5"]
[com.github.liquidz/iced-nrepl "1.2.12"]])
[com.github.liquidz/iced-nrepl "1.2.13"]])
(swap! boot.repl/*default-middleware* concat
'[cider.nrepl/wrap-classpath
Expand Down Expand Up @@ -201,7 +201,7 @@ SHADOW-CLJS~
{
:dependencies [[refactor-nrepl "3.5.3"]
[cider/cider-nrepl "0.28.5"]
[com.github.liquidz/iced-nrepl "1.2.12"]]
[com.github.liquidz/iced-nrepl "1.2.13"]]
}
<
.nrepl.edn (local config) or $HOME/.nrepl/nrepl.edn (global config)
Expand Down
2 changes: 1 addition & 1 deletion ftplugin/clojure.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ if exists('g:loaded_vim_iced')
finish
endif
let g:loaded_vim_iced = 1
let g:vim_iced_version = 31000
let g:vim_iced_version = 31001
let g:vim_iced_home = expand('<sfile>:p:h:h')
" NOTE: https://github.com/vim/vim/commit/162b71479bd4dcdb3a2ef9198a1444f6f99e6843
" Add functions for defining and placing signs.
Expand Down
58 changes: 58 additions & 0 deletions test/paredit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,61 @@ function! s:suite.get_current_top_something_test() abort
call s:assert.equals(res['code'], "{:foo\n {:bar 123}}")
call s:buf.stop_dummy()
endfunction

function! s:suite.get_top_list_in_comment_test() abort
call s:buf.start_dummy([
\ '(foo',
\ ' (bar|))',
\ ])
let res = iced#paredit#get_top_list_in_comment()
call s:assert.equals(res['code'], "(foo\n (bar))")
call s:buf.stop_dummy()

" reader conditionals
call s:buf.start_dummy([
\ '#?(:clj :foo',
\ ' :cljs :bar|)',
\ ])
let res = iced#paredit#get_top_list_in_comment()
call s:assert.equals(res['code'], "#?(:clj :foo\n :cljs :bar)")
call s:buf.stop_dummy()

" whole in comments
call s:buf.start_dummy([
\ '(comment',
\ ' |(foo)',
\ ' (bar))',
\ ])
let res = iced#paredit#get_top_list_in_comment()
call s:assert.equals(res['code'], "(comment\n (foo)\n (bar))")
call s:buf.stop_dummy()

" a part of comments
call s:buf.start_dummy([
\ '(comment',
\ ' (|foo)',
\ ' (bar))',
\ ])
let res = iced#paredit#get_top_list_in_comment()
call s:assert.equals(res['code'], '(foo)')
call s:buf.stop_dummy()

" not a top list
call s:buf.start_dummy([
\ '(foo)',
\ ' (bar|)',
\ ])
let res = iced#paredit#get_top_list_in_comment()
call s:assert.equals(res['code'], '')
call s:buf.stop_dummy()

call s:buf.start_dummy([
\ '(foo)',
\ '|',
\ ])
let res = iced#paredit#get_top_list_in_comment()
call s:assert.equals(res['code'], '')
call s:buf.stop_dummy()

endfunction

0 comments on commit d0c2d50

Please sign in to comment.