Skip to content

Commit 16b436c

Browse files
committed
Allow linking log buffers to client state #777
1 parent 3441ccc commit 16b436c

8 files changed

Lines changed: 243 additions & 87 deletions

File tree

.nvim.fnl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
; (set vim.g.conjure#debug true)
2828
; (set vim.g.conjure#client#clojure#nrepl#eval#auto_require false)
2929

30+
; (set vim.g.conjure#log#linked_to_client_state true)
31+
3032
(set vim.g.conjure#client#scheme#stdio#command "chicken-csi -:c")
3133
(set vim.g.conjure#client#scheme#stdio#prompt_pattern "\n-#;%d-> ")
3234
(set vim.g.conjure#client#scheme#stdio#value_prefix_pattern false)

doc/conjure.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,17 @@ configure the ones you care about one at a time you can set:
782782
*g:conjure#log#wrap*
783783
`g:conjure#log#wrap`
784784
Enable line wrapping in the HUD and log.
785+
Default: `false`
786+
787+
*g:conjure#log#linked_to_client_state*
788+
`g:conjure#log#linked_to_client_state`
789+
When enabled, the log buffer name is derived from the current
790+
client state key (set via |:ConjureClientState|) rather than the
791+
Neovim process ID. This gives each named state its own log buffer,
792+
e.g. `conjure-log-my-feature.cljc`, making it easy to switch
793+
between work streams within a long-running session.
794+
Falls back to the PID name when no state key has been explicitly
795+
set.
785796
Default: `false`
786797

787798
*g:conjure#log#fold#enabled*

fnl/conjure-spec/log_spec.fnl

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
(local {: describe : it : before_each} (require :plenary.busted))
2+
(local assert (require :luassert.assert))
3+
(local log (require :conjure.log))
4+
(local client (require :conjure.client))
5+
(local config (require :conjure.config))
6+
(local vim _G.vim)
7+
8+
(describe "log-buf?"
9+
(fn []
10+
(before_each
11+
(fn []
12+
(config.assoc-in [:log :linked_to_client_state] false)
13+
(tset client.state :state-key-set? false)))
14+
15+
(describe "linked_to_client_state disabled"
16+
(fn []
17+
(it "matches a buffer named with the PID"
18+
(fn []
19+
(client.with-filetype :fennel
20+
#(assert.is_true
21+
(log.log-buf? (.. "conjure-log-" (vim.fn.getpid) ".fnl"))))))
22+
23+
(it "does not match a buffer named with a state key"
24+
(fn []
25+
(client.set-state-key! :my-feature)
26+
(client.with-filetype :fennel
27+
#(assert.is_false (log.log-buf? "conjure-log-my-feature.fnl")))))))
28+
29+
(describe "linked_to_client_state enabled with state key set"
30+
(fn []
31+
(before_each
32+
(fn []
33+
(config.assoc-in [:log :linked_to_client_state] true)
34+
(client.set-state-key! :my-feature)))
35+
36+
(it "matches a buffer named with the state key"
37+
(fn []
38+
(client.with-filetype :fennel
39+
#(assert.is_true (log.log-buf? "conjure-log-my-feature.fnl")))))
40+
41+
(it "does not match a buffer named with the PID"
42+
(fn []
43+
(client.with-filetype :fennel
44+
#(assert.is_false
45+
(log.log-buf? (.. "conjure-log-" (vim.fn.getpid) ".fnl"))))))))
46+
47+
(describe "linked_to_client_state enabled but no state key set"
48+
(fn []
49+
(before_each
50+
(fn []
51+
(config.assoc-in [:log :linked_to_client_state] true)))
52+
53+
(it "falls back to matching a buffer named with the PID"
54+
(fn []
55+
(client.with-filetype :fennel
56+
#(assert.is_true
57+
(log.log-buf? (.. "conjure-log-" (vim.fn.getpid) ".fnl"))))))))))

fnl/conjure/config.fnl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@
144144
:fold {:enabled false
145145
:lines 10
146146
:marker {:start "~~~%{"
147-
:end "}%~~~"}}}
147+
:end "}%~~~"}}
148+
:linked_to_client_state false}
148149

149150
:extract
150151
{:context_header_lines -1

fnl/conjure/log.fnl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@
3535
(str.join [(client.get :comment-prefix) "State: " (client.state-key)]))
3636

3737
(fn log-buf-name []
38-
(str.join ["conjure-log-" (vim.fn.getpid) (client.get :buf-suffix)]))
38+
(str.join
39+
["conjure-log-"
40+
(if (and (config.get-in [:log :linked_to_client_state])
41+
(client.multiple-states?))
42+
(client.state-key)
43+
(vim.fn.getpid))
44+
(client.get :buf-suffix)]))
3945

4046
(fn M.log-buf? [name]
4147
(vim.endswith name (log-buf-name)))

lua/conjure-spec/log_spec.lua

Lines changed: 73 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lua/conjure/config.lua

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)