Skip to content
This repository was archived by the owner on Feb 23, 2025. It is now read-only.

Commit

Permalink
Merge pull request #439 from liquidz/dev
Browse files Browse the repository at this point in the history
Next release
  • Loading branch information
liquidz authored Aug 29, 2022
2 parents 2964493 + 894cf67 commit c420b84
Show file tree
Hide file tree
Showing 19 changed files with 172 additions and 22 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
All notable changes to this project will be documented in this file. This change log follows the conventions of http://keepachangelog.com/[keepachangelog.com].

== Unreleased (dev)
// {{{
=== Added
* https://github.com/liquidz/vim-iced/issues/434[#434]: Added a feature to evaluate codes in a user specified context.
** See https://liquidz.github.io/vim-iced/#evaluate_in_context for details.
* https://github.com/liquidz/vim-iced/issues/437[#437] Added `g:iced_clj_kondo_analysis_dirs` option.

=== Changed
* Bumped nrepl to 1.0.0.
* Bumped refactor-nrepl to 3.5.5.
* Bumped iced-nrepl to 1.2.462.
// }}}

== 3.10.3061 (2022-08-19)
// {{{
=== Fixed
* https://github.com/liquidz/vim-iced/issues/432[#432]: Fixed to ignore case on detecting namespaces.
// }}}

== 3.10.3057 (2022-08-12)
// {{{
Expand Down
13 changes: 11 additions & 2 deletions autoload/iced/component/clj_kondo.vim
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let s:kondo = {
\ 'job_out': '',
\ 'option': '',
\ 'user_dir': '',
\ 'lint_opts': '',
\ 'cache_dir': '',
\ '__is_analyzing': v:false,
\ }
Expand Down Expand Up @@ -59,12 +60,15 @@ function! s:kondo.analyze(callback) abort
let config = g:iced_enable_clj_kondo_local_analysis
\ ? '{:output {:analysis {:protocol-impls true :locals true :keywords true} :format :json}}'
\ : '{:output {:analysis {:protocol-impls true} :format :json}}'

" NOTE: Using `writefile` will freeze vim/nvim just a little
let command = ['sh', '-c', printf('clj-kondo --parallel --lint %s --config ''%s'' > %s',
\ self.user_dir,
let command = ['sh', '-c', printf('clj-kondo --parallel %s --config ''%s'' > %s',
\ self.lint_opts,
\ config,
\ s:temp_name(self.cache_name()),
\ )]

call iced#util#debug('clj-kondo', printf('analyze %s', command))
call self.job_out.redir(command, funcref('s:analyze__analyzed', [a:callback], self))
endfunction

Expand Down Expand Up @@ -431,6 +435,11 @@ function! iced#component#clj_kondo#start(this) abort
let user_dir = iced#nrepl#system#user_dir()
let s:kondo.user_dir = empty(user_dir) ? expand('%:p:h') : user_dir

let analysis_dirs = (len(g:iced_clj_kondo_analysis_dirs) > 0)
\ ? g:iced_clj_kondo_analysis_dirs
\ : [user_dir]
let s:kondo.lint_opts = join(map(copy(analysis_dirs), {_, dir -> printf('--lint %s', dir)}), ' ')

return s:kondo
endfunction

Expand Down
11 changes: 11 additions & 0 deletions autoload/iced/operation.vim
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ function! s:__eval_and_comment(resp) abort
endif
endfunction

let s:last_context = ''
function! iced#operation#eval_in_context(type) abort
call inputsave()
let context = iced#system#get('io').input(iced#message#get('evaluation_context'), s:last_context)
call inputrestore()
if empty(context) | return | endif

let s:last_context = context
return s:eval({code -> iced#repl#execute('eval_code', printf('(clojure.core/let [%s] %s)', s:last_context, code))})
endfunction

function! iced#operation#macroexpand(type) abort
let view = winsaveview()
let reg_save = @@
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.4 cider/cider-nrepl:0.28.5 com.github.liquidz/iced-nrepl:1.2.458'
BASE_DEPENDENCIES='nrepl/nrepl:1.0.0 refactor-nrepl/refactor-nrepl:3.5.5 cider/cider-nrepl:0.28.5 com.github.liquidz/iced-nrepl:1.2.462'
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 build.edn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{:lib com.github.liquidz/vim-iced
:version "3.10.{{git/commit-count}}"
:version "3.11.{{git/commit-count}}"
:documents [{:file "doc/vim-iced.txt"
:match "^Version: "
:action :replace
Expand Down
6 changes: 3 additions & 3 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{:paths ["clj/repl"]
:deps {nrepl/nrepl {:mvn/version "0.9.0"}
refactor-nrepl/refactor-nrepl {:mvn/version "3.5.4"}
:deps {nrepl/nrepl {:mvn/version "1.0.0"}
refactor-nrepl/refactor-nrepl {:mvn/version "3.5.5"}
cider/cider-nrepl {:mvn/version "0.28.5"}
com.github.liquidz/iced-nrepl {:mvn/version "1.2.458"}}
com.github.liquidz/iced-nrepl {:mvn/version "1.2.462"}}
:__middlewares__
["cider.nrepl/wrap-classpath"
"cider.nrepl/wrap-clojuredocs"
Expand Down
48 changes: 48 additions & 0 deletions doc/pages/evaluation.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,51 @@ If you'd like to define a custom mapping, try below.
nmap <silent> ee <Plug>(iced_eval)<Plug>(sexp_outer_list)``
----

=== Context [[evaluate_in_context]]

There are times when you want to evaluate the contents of a function for confirmation.

[source,clojure]
----
(defn greet [s]
;; We'd like to evaluate the following code!
(str "hello " s))
----

It is tired to bind arguments separately,
or to write function calls in the comment form every time.

[source,clojure]
----
(comment (def s "iced"))
;; or
(comment (greet "iced"))
----

This is where evaluating codes in context help you.
There is a default key bindings to evaluate code in a context.

.Default key mappings
[cols="30a,70"]
|===

| [reftext="evaluating outer list"]
[[evaluate_outer_list]]
outer list
| `{plug_iced_eval_in_context}`

|===

With this mapping, the context input will be required.

The context is `clojure.core/let` style.
For example, the context `s "iced"` will be expanded to the following code.

[source,clojure]
----
(clojure.core/let [s "iced"]
(str "hello " s))
----

See {help_html}#%3CPlug%3E%28iced_eval_in_context%29[<Plug>(iced_eval_in_context)] for more information.

1 change: 1 addition & 0 deletions doc/pages/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
:plug_iced_eval_outer_top_list: <Leader>et
:plug_iced_eval_at_mark: <Leader>ea
:plug_iced_eval_last_outer_top_list: <Leader>el
:plug_iced_eval_in_context: <Leader>ece
:plug_iced_extract_function: <Leader>ref
:plug_iced_format: ==
:plug_iced_format_all: =G
Expand Down
77 changes: 62 additions & 15 deletions doc/vim-iced.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ CONTENTS *vim-iced-contents*
Evaluating |vim-iced-evaluating|
Stdout Buffer |vim-iced-stdout-buffer|
Yank the result |vim-iced-yank-the-result|
Evaluating in context |vim-iced-eval-in-context|
Testing |vim-iced-testing|
Plain nREPL |vim-iced-testing-plain-nrepl|
Debugging |vim-iced-debugging|
Expand Down Expand Up @@ -138,8 +139,8 @@ LEININGEN~
$HOME/.lein/profile.clj
>
{:user
{:dependencies [[nrepl "0.9.0"]
[com.github.liquidz/iced-nrepl "1.2.458"]
{:dependencies [[nrepl "1.0.0"]
[com.github.liquidz/iced-nrepl "1.2.462"]
[cider/cider-nrepl "0.28.5"]]
:repl-options {:nrepl-middleware [cider.nrepl/wrap-classpath
cider.nrepl/wrap-clojuredocs
Expand All @@ -158,7 +159,7 @@ LEININGEN~
cider.nrepl/wrap-undef
cider.nrepl/wrap-xref
iced.nrepl/wrap-iced]}
:plugins [[refactor-nrepl "3.5.4"]]}}
:plugins [[refactor-nrepl "3.5.5"]]}}
<

*vim-iced-manual-boot*
Expand All @@ -169,9 +170,9 @@ BOOT~
(require (quote boot.repl))
(swap! boot.repl/*default-dependencies* concat
'[[refactor-nrepl "3.5.4"]
'[[refactor-nrepl "3.5.5"]
[cider/cider-nrepl "0.28.5"]
[com.github.liquidz/iced-nrepl "1.2.458"]])
[com.github.liquidz/iced-nrepl "1.2.462"]])
(swap! boot.repl/*default-middleware* concat
'[cider.nrepl/wrap-classpath
Expand Down Expand Up @@ -199,9 +200,9 @@ SHADOW-CLJS~
shadow-cljs.edn
>
{
:dependencies [[refactor-nrepl "3.5.4"]
:dependencies [[refactor-nrepl "3.5.5"]
[cider/cider-nrepl "0.28.5"]
[com.github.liquidz/iced-nrepl "1.2.458"]]
[com.github.liquidz/iced-nrepl "1.2.462"]]
}
<
.nrepl.edn (local config) or $HOME/.nrepl/nrepl.edn (global config)
Expand Down Expand Up @@ -402,7 +403,7 @@ EVALUATING *vim-iced-evaluating*
- `<Leader>ei` : Evaluate inner element
- `<Leader>ee` : Evaluate outer list
- `<Leader>et` : Evaluate outer top list
c.f. |vim-iced-customizing-default-keys|
cf. |vim-iced-customizing-default-keys|

Specific evaluation range(`|` means cursor position): >
;; <------------et----------->
Expand Down Expand Up @@ -445,7 +446,7 @@ YANK THE RESULT *vim-iced-yank-the-result*

Like vim's behavior, iced shifts the previous result of register 1 into
register 2, 2 into 3, and so forth.

If you have values you don't want to store,
See |g:iced#eval#values_to_skip_storing_register|.

Expand All @@ -461,6 +462,27 @@ YANK THE RESULT *vim-iced-yank-the-result*
" mapping for "xee
nmap <silent> ee <Plug>(iced_eval)<Plug>(sexp_outer_list)``
<
------------------------------------------------------------------------------
EVALUATING IN CONTEXT *vim-iced-eval-in-context*

There are times when you want to evaluate the contents of a function
for confirmation.
>
(defn greet [s]
(str "hello " s))
<
It is tired to bind arguments separately, (e.g. `(def s "iced")`)
or to write function calls in the comment form every time.
(e.g. `(comment (greet "iced"))`)

This is where evaluating codes in context help you.

There is a default key bindings to evaluate code in a context.
- `<Leader>ece` : Evaluate outer list in a context
cf. |vim-iced-customizing-default-keys|

See |<Plug>(iced_eval_in_context)| for more information.

==============================================================================
TESTING *vim-iced-testing*

Expand Down Expand Up @@ -579,7 +601,8 @@ JUMP TO DEFINITION *vim-iced-tag-jump* *vim-iced-jump-to-def
|:IcedDefJump| to jump to definition.
It is also supported to jump to qualified keywords and local vars.

If the jump destination for keyword is inaccurate or the jump is slow, enabling clj-kondo feature may improve the result.
If the jump destination for keyword is inaccurate or the jump is slow,
enabling clj-kondo feature may improve the result.
- |vim-iced-static-analysis-clj-kondo|

To jump back, you can use default key mapping(<C-t>).
Expand Down Expand Up @@ -714,6 +737,11 @@ CLJ-KONDO *vim-iced-static-analysis-clj-kondo*
This can be used to support jumping to local vars.
To enable, see |g:iced_enable_clj_kondo_local_analysis|.

ANALYSIS DIRECTORIES
vim-iced uses the project root directory for analysis by default.
If you want to analyze files only in specific directories,
see |g:iced_clj_kondo_analysis_dirs|.

TIPS
- Cached files will be separated to var definition/usage and
ns definition/usage automatically if you have `jq` or `jet`.
Expand Down Expand Up @@ -1086,7 +1114,7 @@ COMMANDS *vim-iced-commands*
*:IcedJavaDocument*
:IcedJavaDocument [{class_name}]
Opens a browser window displaying the javadoc for {class_name}.
c.f. https://clojuredocs.org/clojure.java.javadoc/javadoc
cf. https://clojuredocs.org/clojure.java.javadoc/javadoc

If {class_name} is not passed,
the result of `clojure.core/class` for the form under cursor is used.
Expand Down Expand Up @@ -1177,7 +1205,7 @@ COMMANDS *vim-iced-commands*
:IcedFormatSync
Same as |:IcedFormat|, but it's done synchronously.
Key is mapped to |<Plug>(iced_format_sync)|.

*:IcedFormatSyncAll*
:IcedFormatSyncAll
Same as |:IcedFormatAll|, but it's done synchronously.
Expand Down Expand Up @@ -1492,6 +1520,17 @@ KEY MAPPINGS *vim-iced-key-mappings*
<Plug>(iced_eval_and_comment)<Plug>(sexp_outer_list)``
<Plug>(iced_eval_and_comment)<Plug>(sexp_outer_top_list)``
<
*<Plug>(iced_eval_in_context)*
<Plug>(iced_eval_in_context)
Evaluate code in the user specified context.
The context is `clojure.core/let` style.
For example, the context `foo "bar" num 10` will be expanded to
`(clojure.core/let [foo "bar" num 10] ...)`.

The input context is saved and will be expanded at the next evaluation.

See also |vim-iced-eval-in-context|.

*<Plug>(iced_eval_ns)*
<Plug>(iced_eval_ns)
Same as |:IcedEvalNs|.
Expand Down Expand Up @@ -1907,7 +1946,7 @@ g:iced#eval#mark_at_last
g:iced#eval#values_to_skip_storing_register
Evaluated values not to store to numbered registers.
Default value is `['nil', 'true', 'false']`.

*g:iced#eval#popup_highlight*
g:iced#eval#popup_highlight
The highlight setting for popup to display evaluated result.
Expand Down Expand Up @@ -1961,7 +2000,7 @@ g:iced#grep#format
*g:iced#refactor#prefix_rewriting*
g:iced#refactor#prefix_rewriting
Should `clean-ns` favor prefix forms in the ns macro?
c.f. https://github.com/clojure-emacs/refactor-nrepl#available-features
cf. https://github.com/clojure-emacs/refactor-nrepl#available-features
Default value is `v:false`.

*g:iced#refactor#insert_newline_after_require*
Expand Down Expand Up @@ -2056,6 +2095,13 @@ g:iced_enable_clj_kondo_local_analysis
Default value is `v:false`.
See also |vim-iced-static-analysis-clj-kondo|.

*g:iced_clj_kondo_analysis_dirs*
g:iced_clj_kondo_analysis_dirs
If some values are set, vim-iced uses these directories for analysis
by clj-kondo.
If this option is empty, vim-iced uses the project root directory.
Default value is `[]`.

*g:iced#navigate#prefer_local_jump*
g:iced#navigate#prefer_local_jump
If {v:true}, change the behavior of |:IcedDefJump| to prefer local jumping.
Expand Down Expand Up @@ -2438,7 +2484,7 @@ CONNECT PREPARED *hook_event_connect_prepared*

Hooked before the start of connection.
This hook only allows `function` hook type.
c.f. |hook_report_function|
cf. |hook_report_function|

Following list is passed to reporter.
e.g. `[{'label': 'nREPL', 'type': 'nrepl', 'port': 12345}]`
Expand Down Expand Up @@ -2601,6 +2647,7 @@ g:iced_enable_default_key_mappings
n <Leader>" <Plug>(iced_jack_in)
n <Leader>ei <Plug>(iced_eval)<Plug>(sexp_inner_element)``
n <Leader>ee <Plug>(iced_eval)<Plug>(sexp_outer_list)``
n <Leader>ece <Plug>(iced_eval_in_context)<Plug>(sexp_outer_list)``
n <Leader>et <Plug>(iced_eval_outer_top_list)
n <Leader>ea <Plug>(iced_eval_at_mark)
n <Leader>el <Plug>(iced_eval_last_outer_top_list)
Expand Down
Loading

0 comments on commit c420b84

Please sign in to comment.