branch: elpa/gptel commit 802566e55c876803300a2ccd481ca08fae649141 Author: Karthik Chikmagalur <karthikchikmaga...@gmail.com> Commit: Karthik Chikmagalur <karthikchikmaga...@gmail.com>
gptel-context: Skip non-project files only when adding directories * gptel-context.el (gptel-context--add-directory, gptel-context-add-file): Always add files when they are specified explicitly, ignoring the value of `gptel-context-restrict-to-project-files'. Perform this check only when adding directories. (#1102) * NEWS: Mention change. --- NEWS | 6 ++++-- gptel-context.el | 23 ++++++++++++----------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/NEWS b/NEWS index 691ae260ca4..3a631d99d50 100644 --- a/NEWS +++ b/NEWS @@ -101,9 +101,11 @@ available before performing other actions. One common use is starting MCP servers when applying a gptel preset. -- "gitignored" files are omitted by default when adding files to gptel's +- "gitignored" files are omitted by default when adding directories to gptel's context. This setting can be controlled via the user option - ~gptel-context-restrict-to-project-files~. + ~gptel-context-restrict-to-project-files~. (This only applies to directories, + individual files specified via ~gptel-add-file~ will always be added to the + context.) - ~gptel-make-bedrock~ now checks for the ~AWS_BEARER_TOKEN_BEDROCK~ environment variable parameter and uses it for Bedrock API key based authentication if diff --git a/gptel-context.el b/gptel-context.el index 141de87d75f..ef0dfcd993d 100644 --- a/gptel-context.el +++ b/gptel-context.el @@ -232,7 +232,18 @@ Return PATH if added, nil if ignored." ACTION should be either `add' or `remove'." (dolist (file (directory-files-recursively path ".")) (pcase-exhaustive action - ('add (gptel-context-add-file file)) + ('add + (unless gptel-context--reset-cache + (setq gptel-context--reset-cache t) + (run-at-time + 0 nil + (lambda () (setq gptel-context--reset-cache nil + gptel-context--project-files nil)))) + (if (gptel-context--skip-p file) + ;; Don't message about .git, as this creates thousands of messages + (unless (string-match-p "\\.git/" file) + (gptel-context--message-skipped file)) + (gptel-context-add-file file))) ('remove (setf (alist-get file gptel-context nil 'remove #'equal) nil))))) @@ -242,18 +253,8 @@ ACTION should be either `add' or `remove'." If PATH is a directory, recursively add all files in it. PATH should be readable as text." (interactive "fChoose file to add to context: ") - (unless gptel-context--reset-cache - (setq gptel-context--reset-cache t) - (run-at-time - 0 nil - (lambda () (setq gptel-context--reset-cache nil - gptel-context--project-files nil)))) (cond ((file-directory-p path) (gptel-context--add-directory path 'add)) - ((gptel-context--skip-p path) - ;; Don't message about .git, as this creates thousands of messages - (unless (string-match-p "\\.git/" path) - (gptel-context--message-skipped path))) ((gptel--file-binary-p path) (gptel-context--add-binary-file path)) (t (gptel-context--add-text-file path))))