-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support adding files in directories to context #438
base: master
Are you sure you want to change the base?
Support adding files in directories to context #438
Conversation
Looks good! I'll test it when I can and merge. |
I just noticed this in the docstring of this function (emphasis added):
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 |
It could probably be worded better. Here is an updated description, let me know if it makes more sense:
|
We should also add the ability to add directories to the context when running |
I wasn’t familiar with this command, but yeah, it seems it should mirror the behavior of |
Perhaps we should change |
Please go ahead.
|
8e0419c
to
dcedf1c
Compare
@karthink, I undid the previous attempt and pushed a new version, which (1) works with both |
dcedf1c
to
147fe6e
Compare
gptel-context.el
Outdated
(unless (file-directory-p file) | ||
(pcase action | ||
('add (gptel--file-binary-p file) | ||
(gptel-context--handle-binary file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I missing something here? Seems like this should be (if (gptel--file-binary-p file) (gptel-context--handle-binary file) ...
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, not sure what happened. Will make these and the other changes shortly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed: 2a40dae
gptel-context.el
Outdated
(let ((files (directory-files-recursively path "." t))) | ||
(mapc (lambda (file) | ||
(unless (file-directory-p file) | ||
(pcase action |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use pcase-exhaustive
to future-proof uses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed: 6c66982
gptel-context.el
Outdated
(cl-pushnew (list path) gptel-context--alist :test #'equal) | ||
(message "File \"%s\" added to context." path) | ||
path)) | ||
(if (file-directory-p path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convert to a cond
clause, it's easier to read here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed: bc9138a
gptel-context.el
Outdated
@@ -91,8 +91,10 @@ context chunk. This is accessible as, for example: | |||
context. 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. | |||
- If in Dired, add marked files or file at point to the context. If |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we should ask for confirmation (y-or-n-p
) when adding a directory with gptel-add
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I weakly lean towards asking for confirmation. The prompt could include the number of files to be added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here’s an attempt: 8e5e3c8
Perhaps we should add a user option to allow the user to decide if they want to be asked for confirmation.
Also, note that the user will be asked once for each directory. This seems like the correct behavior, though it can become tedious if the user is adding several dirs. (Perhaps this provides an additional reason for adding the user option.)
gptel-context.el
Outdated
- If in Dired, add marked files or file at point to the context. | ||
With negative prefix ARG, remove them from the context instead. | ||
- If in Dired, add marked files or file at point to the context. If | ||
the file at point is a directory, or directories are marked, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is difficult to read. How about
- If in Dired, add marked files or file at point to the context. Directories
will have all their files added recursively. With negative prefix ARG, remove
them from the context instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed: 8bee48a
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.