karthink / gptel

A simple LLM client for Emacs
GNU General Public License v3.0
1.63k stars 151 forks source link

Support adding files in directories to context #438

Open benthamite opened 3 weeks ago

benthamite commented 3 weeks ago

Currently, attempting to add directories to the context in Dired will throw an error. This PR provides support for adding files in directories to the context: if there is a directory at point, or the marked files include one or more directories, their files will recursively be added to the context.

karthink commented 3 weeks ago

Looks good! I'll test it when I can and merge.

benthamite commented 2 weeks ago

I just noticed this in the docstring of this function (emphasis added):

If a region is selected, add the selected region to the context. If there is already a gptel context at point, remove it instead.

I may not be understanding what this means, but as far as I can tell the function does not behave in the manner described: if I select a region, add it to the context, then re-select it and call gptel-add again, the region is not removed from the context. (The docstring talks about the "context at point" rather than the region, but I am not sure what that means in this, er, context. 😛)

karthink commented 2 weeks ago

I may not be understanding what this means, but as far as I can tell the function does not behave in the manner described: if I select a region, add it to the context, then re-select it and call gptel-add again, the region is not removed from the context.

It could probably be worded better. Here is an updated description, let me know if it makes more sense:

gptel-add is an alias for ‘gptel-context-add’ in ‘gptel-context.el’.

(gptel-add &optional ARG)

Add context to gptel in a DWIM fashion.

- If a region is selected, add the selected region to the
  context.  If point is in a context region already, it
  is removed first -- overlapping context regions are not
  supported.

- If there is already a gptel context at point, remove it
  instead.

- If in Dired, add marked files or file at point to the context.
  With negative prefix ARG, remove them from the context instead.

- Otherwise add the current buffer to the context.  With positive
  prefix ARG, prompt for a buffer name and add it to the context.

- With negative prefix ARG, remove all gptel contexts from the
  current buffer.
karthink commented 2 weeks ago

We should also add the ability to add directories to the context when running gptel-add-file, shouldn't we?

benthamite commented 1 week ago

We should also add the ability to add directories to the context when running gptel-add-file, shouldn't we?

I wasn’t familiar with this command, but yeah, it seems it should mirror the behavior of gptel-add when the latter is used with a file or directory. Would you like me to make the changes?

benthamite commented 1 week ago

Perhaps we should change gptel-context-add-file so that this is the function called by gptel-add in Dired mode. Currently, the former doesn’t take a prefix argument.