forked from joshuavial/aider.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
diff.txt
614 lines (577 loc) · 26.1 KB
/
diff.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d8b5d5d..36c6991 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
# Changelog
All notable changes to this project will be documented in this file.
+## [0.3.0] - 2023-10-15
## [0.2.1] - 2023-07-18
diff --git a/README.md b/README.md
index f1188db..5a2895f 100644
--- a/README.md
+++ b/README.md
@@ -26,44 +26,66 @@ call dein#add('joshuavial/aider.nvim')
## Usage
-The Aider Plugin for Neovim provides the `OpenAider` function, which you can call to open a terminal window with the Aider command. The `OpenAider` function accepts the following arguments:
+The Aider Plugin for Neovim provides the `AiderOpen` and `AiderBackground` lua functions.
-- `command`: The full aider command to use - defaults to `aider`
-- `window`: The window style to use 'vsplit' (default), 'hsplit' or 'float'
+The `AiderOpen` function opens a terminal window with the Aider command. It accepts the following arguments:
+- `args`: The command line arguments to pass to `aider` - defaults to ""
+- `window_type`: The window style to use 'vsplit' (default), 'hsplit' or 'editor'
-Note: When Aider opens, it will automatically add all open buffers to the command.
+The `AiderBackground` function runs the Aider command in the background. It accepts the following arguments:
+- `args`: The command line arguments to pass to `aider` - defaults to ""
+- `message`: The message to pass to the Aider command - defaults to "Complete as many todo items as you can and remove the comment for any item you complete."
+Note: When Aider opens, it will automatically add all open buffers to both commands. If you are going to use this plugin you will want to actively manage open buffers with commands like `:ls` and `:bd`.
-
-Before using the `OpenAider` function, you need to require the `aider` module in your configuration file. Add the following line to your `.vimrc` or `init.vim`:
-
-```vim
-lua require('aider')
-```
-
-Here are some examples of how to use the `OpenAider` function:
+Here are some examples of how to use the `AiderOpen` and `AiderBackground` functions:
```vim
-:lua require('aider').OpenAider()
-:lua require('aider').OpenAider("aider", "float")
-:lua require('aider').OpenAider("AIDER_NO_AUTO_COMMITS=1 aider -3" )
+:lua AiderOpen()
+:lua AiderOpen("-3", "hsplit")
+:lua AiderOpen("AIDER_NO_AUTO_COMMITS=1 aider -3", "editor")
+:lua AiderBackground()
+:lua AiderBackground("-3")
+:lua AiderBackground("AIDER_NO_AUTO_COMMITS=1 aider -3")
```
-You can also set keybindings for the `OpenAider` function in Lua. Here's an example:
+You can also set keybindings for the `AiderOpen` and `AiderBackground` functions in Lua. Here's an example:
```lua
--- set a keybinding for the OpenAider function
-vim.api.nvim_set_keymap('n', '<leader>oa', '<cmd>lua require("aider").OpenAider()<cr>', {noremap = true, silent = true})
+-- set a keybinding for the AiderOpen function
+vim.api.nvim_set_keymap('n', '<leader>oa', '<cmd>lua AiderOpen()<cr>', {noremap = true, silent = true})
+-- set a keybinding for the AiderBackground function
+vim.api.nvim_set_keymap('n', '<leader>ob', '<cmd>lua AiderBackground()<cr>', {noremap = true, silent = true})
```
-In this example, pressing `<leader>oa` in normal mode will call the `OpenAider` function.
+In this example, pressing `<leader>oa` in normal mode will call the `AiderOpen` function, and `<leader>ob` will call the `AiderBackground` function.
Run `aider --help` to see all the options you can pass to the cli.
-The plugin provides the following keybindings:
+The plugin provides the following default keybindings:
- `<leader><Space><Space>` to open a terminal window with the Aider defaults (gpt-4).
- `<leader><Space>3` to open a terminal window with the Aider command using the gpt-3.5-turbo-16k model for chat.
+- `<leader><space>b` to run the Aider command in the background with the defaults.
+- `<leader><space>b3` to run the Aider command in the background using the gpt-3.5-turbo-16k model for chat.
+
+## Setup
+
+The Aider Plugin for Neovim provides a `setup` function that you can use to configure the plugin. This function accepts a table with the following keys:
+
+- `auto_manage_context`: A boolean value that determines whether the plugin should automatically manage the context. If set to `true`, the plugin will automatically add and remove buffers from the context as they are opened and closed. Defaults to `true`.
+- `default_bindings`: A boolean value that determines whether the plugin should use the default keybindings. If set to `true`, the plugin will require the keybindings file and set the default keybindings. Defaults to `true`.
+
+Here is an example of how to use the `setup` function:
+
+```lua
+require('aider').setup({
+ auto_manage_context = false,
+ default_bindings = false
+})
+```
+
+In this example, the `setup` function is called with a table that sets `auto_manage_context` to `false` and `default_bindings` to `false`. This means that the plugin will not automatically manage the context and will not use the default keybindings.
## Tips for Working with Buffers in Vim
@@ -75,6 +97,24 @@ If you're not familiar with buffers in Vim, here are some tips:
- Use `:bd <number>` or `:bdelete <number>` to close a specific buffer. Replace `<number>` with the buffer number.
- Use `:bufdo bd` to close all buffers.
+This helper function may be useful for closing all buffers that are hidden
+
+```lua
+_G.close_hidden_buffers = function()
+ local curr_buf_num = vim.api.nvim_get_current_buf()
+ local all_buf_nums = vim.api.nvim_list_bufs()
+
+ for _, buf_num in ipairs(all_buf_nums) do
+ if buf_num ~= curr_buf_num and vim.api.nvim_buf_is_valid(buf_num) and vim.api.nvim_buf_is_loaded(buf_num) and vim.fn.bufwinnr(buf_num) == -1 then
+ if vim.fn.getbufvar(buf_num, '&buftype') ~= 'terminal' then
+ vim.api.nvim_buf_delete(buf_num, { force = true })
+ end
+ end
+ end
+end
+```
+
## NOTE
if you resize a split the nvim buffer can truncate the text output, chatGPT tells me there isn't an easy work around for this. Feel free to make a PR if you think it's easy to solve without rearchitecting and using tmux or something similar.
+
diff --git a/ai-docs/aider.txt b/ai-docs/aider.txt
new file mode 100644
index 0000000..a49771e
--- /dev/null
+++ b/ai-docs/aider.txt
@@ -0,0 +1,147 @@
+usage: aider [-h] [--openai-api-key OPENAI_API_KEY] [--model MODEL]
+ [--skip-model-availability-check SKIP_MODEL_AVAILABILITY_CHECK]
+ [-3] [--voice-language VOICE_LANGUAGE]
+ [--openai-api-base OPENAI_API_BASE]
+ [--openai-api-type OPENAI_API_TYPE]
+ [--openai-api-version OPENAI_API_VERSION]
+ [--openai-api-deployment-id OPENAI_API_DEPLOYMENT_ID]
+ [--openai-api-engine OPENAI_API_ENGINE]
+ [--edit-format EDIT_FORMAT] [--map-tokens MAP_TOKENS]
+ [--input-history-file INPUT_HISTORY_FILE]
+ [--chat-history-file CHAT_HISTORY_FILE] [--dark-mode]
+ [--light-mode] [--pretty | --no-pretty] [--stream | --no-stream]
+ [--user-input-color USER_INPUT_COLOR]
+ [--tool-output-color TOOL_OUTPUT_COLOR]
+ [--tool-error-color TOOL_ERROR_COLOR]
+ [--assistant-output-color ASSISTANT_OUTPUT_COLOR]
+ [--code-theme CODE_THEME] [--show-diffs] [--git | --no-git]
+ [--gitignore | --no-gitignore]
+ [--auto-commits | --no-auto-commits]
+ [--dirty-commits | --no-dirty-commits] [--dry-run | --no-dry-run]
+ [--version] [--apply FILE] [--yes] [-v] [--show-repo-map]
+ [--message COMMAND] [-c CONFIG_FILE]
+ [FILE ...]
+
+aider is GPT powered coding in your terminal
+
+options:
+ -h, --help show this help message and exit
+
+Main:
+ FILE the directory of a git repo, or a list of files to
+ edit with GPT (optional)
+ --openai-api-key OPENAI_API_KEY
+ Specify the OpenAI API key [env var: OPENAI_API_KEY]
+ --model MODEL Specify the model to use for the main chat (default:
+ gpt-4) [env var: AIDER_MODEL]
+ --skip-model-availability-check SKIP_MODEL_AVAILABILITY_CHECK
+ Override to skip model availability check (default:
+ False) [env var: AIDER_SKIP_MODEL_AVAILABILITY_CHECK]
+ -3 Use gpt-3.5-turbo-16k model for the main chat (gpt-4
+ is better)
+ --voice-language VOICE_LANGUAGE
+ Specify the language for voice using ISO 639-1 code
+ (default: auto) [env var: AIDER_VOICE_LANGUAGE]
+
+Advanced Model Settings:
+ --openai-api-base OPENAI_API_BASE
+ Specify the openai.api_base (default:
+ https://api.openai.com/v1) [env var:
+ AIDER_OPENAI_API_BASE]
+ --openai-api-type OPENAI_API_TYPE
+ Specify the openai.api_type [env var:
+ AIDER_OPENAI_API_TYPE]
+ --openai-api-version OPENAI_API_VERSION
+ Specify the openai.api_version [env var:
+ AIDER_OPENAI_API_VERSION]
+ --openai-api-deployment-id OPENAI_API_DEPLOYMENT_ID
+ Specify the deployment_id arg to be passed to
+ openai.ChatCompletion.create() [env var:
+ AIDER_OPENAI_API_DEPLOYMENT_ID]
+ --openai-api-engine OPENAI_API_ENGINE
+ Specify the engine arg to be passed to
+ openai.ChatCompletion.create() [env var:
+ AIDER_OPENAI_API_ENGINE]
+ --edit-format EDIT_FORMAT
+ Specify what edit format GPT should use (default
+ depends on model) [env var: AIDER_EDIT_FORMAT]
+ --map-tokens MAP_TOKENS
+ Max number of tokens to use for repo map, use 0 to
+ disable (default: 1024) [env var: AIDER_MAP_TOKENS]
+
+History Files:
+ --input-history-file INPUT_HISTORY_FILE
+ Specify the chat input history file (default:
+ /home/jv/projects/aider.nvim/.aider.input.history)
+ [env var: AIDER_INPUT_HISTORY_FILE]
+ --chat-history-file CHAT_HISTORY_FILE
+ Specify the chat history file (default:
+ /home/jv/projects/aider.nvim/.aider.chat.history.md)
+ [env var: AIDER_CHAT_HISTORY_FILE]
+
+Output Settings:
+ --dark-mode Use colors suitable for a dark terminal background
+ (default: False) [env var: AIDER_DARK_MODE]
+ --light-mode Use colors suitable for a light terminal background
+ (default: False) [env var: AIDER_LIGHT_MODE]
+ --pretty, --no-pretty
+ Enable/disable pretty, colorized output (default:
+ True) (default: True) [env var: AIDER_PRETTY]
+ --stream, --no-stream
+ Enable/disable streaming responses (default: True)
+ (default: True) [env var: AIDER_STREAM]
+ --user-input-color USER_INPUT_COLOR
+ Set the color for user input (default: #00cc00) [env
+ var: AIDER_USER_INPUT_COLOR]
+ --tool-output-color TOOL_OUTPUT_COLOR
+ Set the color for tool output (default: None) [env
+ var: AIDER_TOOL_OUTPUT_COLOR]
+ --tool-error-color TOOL_ERROR_COLOR
+ Set the color for tool error messages (default: red)
+ [env var: AIDER_TOOL_ERROR_COLOR]
+ --assistant-output-color ASSISTANT_OUTPUT_COLOR
+ Set the color for assistant output (default: #0088ff)
+ [env var: AIDER_ASSISTANT_OUTPUT_COLOR]
+ --code-theme CODE_THEME
+ Set the markdown code theme (default: default, other
+ options include monokai, solarized-dark, solarized-
+ light) [env var: AIDER_CODE_THEME]
+ --show-diffs Show diffs when committing changes (default: False)
+ [env var: AIDER_SHOW_DIFFS]
+
+Git Settings:
+ --git, --no-git Enable/disable looking for a git repo (default: True)
+ (default: True) [env var: AIDER_GIT]
+ --gitignore, --no-gitignore
+ Enable/disable adding .aider* to .gitignore (default:
+ True) (default: True) [env var: AIDER_GITIGNORE]
+ --auto-commits, --no-auto-commits
+ Enable/disable auto commit of GPT changes (default:
+ True) (default: True) [env var: AIDER_AUTO_COMMITS]
+ --dirty-commits, --no-dirty-commits
+ Enable/disable commits when repo is found dirty
+ (default: True) (default: True) [env var:
+ AIDER_DIRTY_COMMITS]
+ --dry-run, --no-dry-run
+ Enable/disable performing a dry run without modifying
+ files (default: False) (default: False) [env var:
+ AIDER_DRY_RUN]
+
+Other Settings:
+ --version Show the version number and exit
+ --apply FILE Apply the changes from the given file instead of
+ running the chat (debug) [env var: AIDER_APPLY]
+ --yes Always say yes to every confirmation [env var:
+ AIDER_YES]
+ -v, --verbose Enable verbose output [env var: AIDER_VERBOSE]
+ --show-repo-map Print the repo map and exit (debug) [env var:
+ AIDER_SHOW_REPO_MAP]
+ --message COMMAND, --msg COMMAND, -m COMMAND
+ Specify a single message to send GPT, process reply
+ then exit (disables chat mode) [env var:
+ AIDER_MESSAGE]
+ -c CONFIG_FILE, --config CONFIG_FILE
+ Specify the config file (default: search for
+ .aider.conf.yml in git root, cwd or home directory)
+
+Args that start with '--' can also be set in a config file
diff --git a/doc/aider.txt b/doc/aider.txt
index 93112f8..c127ebf 100644
--- a/doc/aider.txt
+++ b/doc/aider.txt
@@ -1,37 +1,75 @@
-* aider.txt* For aider.nvim plugin *aider.nvim*
+* aider.txt* For aider.nvim plugin *Aider* version 0.3.0
-1. Introduction
-2. Functions
-3. Keybindings
+1. |introduction|
+2. |setup|
+4. |keybindings|
+3. |functions|
==============================================================================
-1. Introduction
+*introduction*
+
+Aider is a simple plugin for Neovim that allows you to open a terminal window inside Neovim and run the Aider command.
-Aider is a simple plugin for Neovim that allows you to open a terminal window inside Neovim and run the Aider.
You will need the aider cli installed for it to work - https://github.com/paul-gauthier/aider
==============================================================================
-2. Functions
+*setup*
-The Aider Plugin for Neovim provides the `OpenAider` function, which you can call to open a terminal window with the Aider command. The `OpenAider` function accepts the following arguments:
+The plugin provides a `setup` function that you can use to configure the plugin. This function accepts a table with the following keys:
-- `command`: The full aider command to use - defaults to `aider`
-- `window`: The window style to use 'vsplit' (default), 'hsplit' or 'float'
+- `auto_manage_context`: A boolean value that determines whether the plugin should automatically manage the context. If set to `true`, the plugin will automatically add and remove buffers from the context as they are opened and closed. Defaults to `true`.
+- `default_bindings`: A boolean value that determines whether the plugin should use the default keybindings. If set to `true`, the plugin will require the keybindings file and set the default keybindings. Defaults to `true`.
-Here are some examples of how to use the `OpenAider` function:
+Here is an example of how to use the `setup` function:
-```vim
-:lua require('aider').OpenAider()
-:lua require('aider').OpenAider("aider", "float")
-:lua require('aider').OpenAider("AIDER_NO_AUTO_COMMITS=1 aider -3" )
+```lua
+require('aider').setup({
+ auto_manage_context = false,
+ default_bindings = false
+})
```
+In this example, the `setup` function is called with a table that sets `auto_manage_context` to `false` and `default_bindings` to `false`. This means that the plugin will not automatically manage the context and will not use the default keybindings.
+
==============================================================================
-3. Keybindings
+*keybindings*
-The plugin provides the following keybindings:
+The plugin provides the following default keybindings:
- `<leader><Space><Space>` to open a terminal window with the Aider defaults (gpt-4).
- `<leader><Space>3` to open a terminal window with the Aider command using the gpt-3.5-turbo-16k model for chat.
+- `<leader><space>b` to run the Aider command in the background with the defaults.
+- `<leader><space>b3` to run the Aider command in the background using the gpt-3.5-turbo-16k model for chat.
+
+They can be disabled by setting the `default_bindings` option to `false` in the setup config.
+
+==============================================================================
+*functions*
+
+The plugin provides the `OpenAider` and `AiderBackground` functions.
+
+The `OpenAider` function can be called to open a terminal window with the Aider command. The `OpenAider` function accepts the following arguments:
+
+- `command`: The full aider command to use - defaults to `aider`
+- `window`: The window style to use 'vsplit' (default), 'hsplit' or 'float'
+
+Here are some examples of how to use the `AiderOpen` function:
+
+```vim
+:lua require('aider').AiderOpen()
+:lua require('aider').AiderOpen("", "float")
+:lua require('aider').AiderOpen("-3 --no-git" )
+```
+
+The `AiderBackground` function runs the Aider command in the background. It accepts the following arguments:
+- `args`: The command line arguments to pass to `aider` - defaults to ""
+- `message`: The message to pass to the Aider command - defaults to "Complete as many todo items as you can and remove the comment for any item you complete."
+
+Here are some examples of how to use the `AiderBackground` function:
+
+```vim
+:lua require('aider').AiderBackground()
+:lua require('aider').AiderBackground("-3")
+:lua require('aider').AiderBackground("AIDER_NO_AUTO_COMMITS=1 aider -3")
+```
-vim:tw=78:ts=8:ft=help:norl:
diff --git a/lua/aider.lua b/lua/aider.lua
index e619d42..08a9b5a 100644
--- a/lua/aider.lua
+++ b/lua/aider.lua
@@ -1,46 +1,84 @@
-local api = vim.api
-
-local function open_window(window_type)
- local buf = api.nvim_create_buf(false, true)
- if window_type == 'vsplit' then
- vim.cmd('vnew')
- elseif window_type == 'hsplit' then
- vim.cmd('new')
- else
- local width = api.nvim_win_get_width(0) - 10
- local height = api.nvim_win_get_height(0) - 10
- local row = 2
- local col = 2
- local win = api.nvim_open_win(buf, true, {relative = 'editor', width = width, height = height, row = row, col = col})
- api.nvim_set_current_win(win)
- end
- vim.bo[buf].buftype = 'nofile'
+local helpers = require('helpers')
+local M = {}
+
+M.aider_buf = nil
+
+function M.AiderBackground(args, message)
+ helpers.showProcessingCue()
+ local command = helpers.build_background_command(args, message)
+ local handle = vim.loop.spawn('bash', {
+ args = {'-c', command}
+ }, NotifyOnExit)
+
+ vim.notify("Aider started " .. (args or ''))
end
-function OnExit(job_id, data, event)
- api.nvim_win_close(0, true)
+
+function OnExit(code, signal)
+ if M.aider_buf then
+ vim.api.nvim_command('bd! ' .. M.aider_buf)
+ M.aider_buf = nil
+ end
end
-local M = {}
+function M.AiderOpen(args, window_type)
+ window_type = window_type or 'vsplit'
+ if M.aider_buf and vim.api.nvim_buf_is_valid(M.aider_buf) then
+ helpers.open_buffer_in_new_window(window_type, M.aider_buf)
+ else
+ command = 'aider ' .. (args or '')
+ helpers.open_window(window_type)
+ command = helpers.add_buffers_to_command(command)
+ M.aider_job_id = vim.fn.termopen(command, {on_exit = OnExit})
+ M.aider_buf = vim.api.nvim_get_current_buf()
+ end
+end
-function M.OpenAider(command, window_type)
- command = command or 'aider'
- window_type = window_type or 'vsplit'
- open_window(window_type)
- local buffers = vim.api.nvim_list_bufs()
- for _, buf in ipairs(buffers) do
- if vim.api.nvim_buf_is_loaded(buf) then
- local bufname = vim.api.nvim_buf_get_name(buf)
- if not bufname:match('^term:') and not bufname:match('NeogitConsole') then
- command = command .. " " .. bufname
- end
- end
- end
- vim.fn.termopen(command, {on_exit = 'OnExit'})
+function M.AiderOnBufferOpen(bufnr)
+ bufnr = tonumber(bufnr)
+ local bufname = vim.api.nvim_buf_get_name(bufnr)
+ if not bufname or bufname:match('^term://') then
+ return
+ end
+ local relative_filename = vim.fn.fnamemodify(bufname, ':~:.')
+ if M.aider_buf and vim.api.nvim_buf_is_valid(M.aider_buf) then
+ local line_to_add = '/add ' .. relative_filename
+ vim.fn.chansend(M.aider_job_id, line_to_add .. '\n')
+ end
end
-vim.g.mapleader = vim.g.mapleader or ' '
-api.nvim_set_keymap('n', '<leader> ', ':lua require("aider").OpenAider()<CR>', {noremap = true, silent = true})
-api.nvim_set_keymap('n', '<leader> 3', ':lua require("aider").OpenAider("aider -3")<CR>', {noremap = true, silent = true})
+function M.AiderOnBufferClose(bufnr)
+ bufnr = tonumber(bufnr)
+ local bufname = vim.api.nvim_buf_get_name(bufnr)
+ if not bufname or bufname:match('^term://') then
+ return
+ end
+ local relative_filename = vim.fn.fnamemodify(bufname, ':~:.')
+ if M.aider_buf and vim.api.nvim_buf_is_valid(M.aider_buf) then
+ local line_to_drop = '/drop ' .. relative_filename
+ vim.fn.chansend(M.aider_job_id, line_to_drop .. '\n')
+ end
+end
+
+function M.setup(config)
+ M.config = config or {}
+ M.config.auto_manage_context = M.config.auto_manage_context or true
+ M.config.default_bindings = M.config.default_bindings or true
+
+ if M.config.auto_manage_context then
+ vim.api.nvim_command('autocmd BufAdd * lua AiderOnBufferOpen(vim.fn.expand("<abuf>"))')
+ vim.api.nvim_command('autocmd BufDelete * lua AiderOnBufferClose(vim.fn.expand("<abuf>"))')
+ _G.AiderOnBufferOpen = M.AiderOnBufferOpen
+ _G.AiderOnBufferClose = M.AiderOnBufferClose
+ end
+
+ _G.AiderOpen = M.AiderOpen
+ _G.AiderBackground = M.AiderBackground
+ _G.aider_background_status = 'idle'
+
+ if M.config.default_bindings then
+ require('keybindings')
+ end
+end
return M
diff --git a/lua/helpers.lua b/lua/helpers.lua
new file mode 100644
index 0000000..152182b
--- /dev/null
+++ b/lua/helpers.lua
@@ -0,0 +1,89 @@
+local function set_idle_status(isIdle)
+ if isIdle then
+ _G.aider_background_status = 'idle'
+ else
+ _G.aider_background_status = 'working'
+ end
+ vim.cmd('redrawstatus')
+end
+
+local function open_vsplit_window()
+ vim.api.nvim_command('vnew')
+end
+
+local function open_hsplit_window()
+ vim.api.nvim_command('new')
+end
+
+local function open_editor_relative_window()
+ local buf = vim.api.nvim_create_buf(false, true)
+ local width = vim.api.nvim_get_option("columns")
+ local height = vim.api.nvim_get_option("lines")
+ local win = vim.api.nvim_open_win(buf, true, {relative = 'editor', width = width - 10, height = height - 10, row = 2, col = 2})
+ vim.api.nvim_set_current_win(win)
+ vim.bo[buf].buftype = 'nofile'
+end
+
+local function open_window(window_type)
+ if window_type == 'vsplit' then
+ open_vsplit_window()
+ elseif window_type == 'hsplit' then
+ open_hsplit_window()
+ else
+ open_editor_relative_window()
+ end
+end
+
+function NotifyOnExit(code, signal)
+ vim.schedule(function()
+ set_idle_status(true)
+ vim.api.nvim_command('echo ""')
+ vim.cmd('edit')
+ vim.notify("Aider finished with exit code " .. code)
+ end)
+end
+
+local function showProcessingCue()
+ vim.api.nvim_command('echo "Aider processing ..."')
+ set_idle_status(false)
+end
+
+local function add_buffers_to_command(command)
+ local buffers = vim.api.nvim_list_bufs()
+ for _, buf in ipairs(buffers) do
+ if vim.api.nvim_buf_is_loaded(buf) then
+ local bufname = vim.api.nvim_buf_get_name(buf)
+ if not bufname:match('^term:') and not bufname:match('NeogitConsole') then
+ command = command .. " " .. bufname
+ end
+ end
+ end
+ return command
+end
+
+local function build_background_command(args, prompt)
+ prompt = prompt or "Complete as many todo items as you can and remove the comment for any item you complete."
+ local command = 'aider --msg "' .. prompt .. '" ' .. (args or '')
+ command = add_buffers_to_command(command)
+ return command
+end
+
+function open_buffer_in_new_window(window_type, aider_buf)
+ if window_type == 'vsplit' then
+ vim.api.nvim_command('vsplit | buffer ' .. aider_buf)
+ elseif window_type == 'hsplit' then
+ vim.api.nvim_command('split | buffer ' .. aider_buf)
+ else
+ vim.api.nvim_command('buffer ' .. aider_buf)
+ end
+end
+
+
+return {
+ open_window = open_window,
+ NotifyOnExit = NotifyOnExit,
+ showProcessingCue = showProcessingCue,
+ add_buffers_to_command = add_buffers_to_command,
+ build_background_command = build_background_command,
+ open_buffer_in_new_window = open_buffer_in_new_window
+}
diff --git a/lua/keybindings.lua b/lua/keybindings.lua
new file mode 100644
index 0000000..32916ff
--- /dev/null
+++ b/lua/keybindings.lua
@@ -0,0 +1,5 @@
+vim.g.mapleader = vim.g.mapleader or ' '
+vim.api.nvim_set_keymap('n', '<leader> b', ':lua AiderBackground()<CR>', {noremap = true, silent = true})
+vim.api.nvim_set_keymap('n', '<leader> b3', ':lua AiderBackground("-3")<CR>', {noremap = true, silent = true})
+vim.api.nvim_set_keymap('n', '<leader> ', ':lua AiderOpen()<CR>', {noremap = true, silent = true})
+vim.api.nvim_set_keymap('n', '<leader> 3', ':lua AiderOpen("-3")<CR>', {noremap = true, silent = true})
diff --git a/term:/~/aider.nvim/2913:aider b/term:/~/aider.nvim/2913:aider
deleted file mode 100644
index e69de29..0000000