diff --git a/ellama-context.el b/ellama-context.el index 76dc55f3..fb431543 100644 --- a/ellama-context.el +++ b/ellama-context.el @@ -723,13 +723,28 @@ the context." (ellama-context-element-add element))) ;;;###autoload -(defun ellama-context-add-directory (dir) - "Add all files in DIR to the context." +(defun ellama-context-add-directory (dir &optional recursive) + "Add all files in DIR to the context. +Exclude dot-files. Include subdirs if RECURSIVE is t." (interactive "DSelect directory: ") - (dolist (file-name (directory-files dir t "^[^\.].*")) - (unless (file-directory-p file-name) - (let ((element (ellama-context-element-file :name file-name))) - (ellama-context-element-add element))))) + (let ((rec + (or recursive + (transient-arg-value "recursive" + (transient-args transient-current-command))))) + (dolist (file-name (directory-files dir t "^[^\.].*")) + (cond + ((file-regular-p file-name) + (let ((element (ellama-context-element-file :name file-name))) + (ellama-context-element-add element))) + ((and (file-directory-p file-name) rec) + (ellama-context-add-directory file-name 't)))))) + +;;;###autoload +(defun ellama-context-add-directory-recursive (dir) + "Add all files in DIR to the context. +Exclude dot-files. Include all subdirs." + (interactive "DSelect directory: ") + (ellama-context-add-directory dir 't)) ;;;###autoload (defun ellama-context-add-selection () diff --git a/ellama-transient.el b/ellama-transient.el index 5f28cc51..1366b1c2 100644 --- a/ellama-transient.el +++ b/ellama-transient.el @@ -277,6 +277,7 @@ Otherwise, prompt the user to enter a system message." (buffer-substring (point-min) (point-max))))) ["Add" ("b" "Add Buffer" ellama-context-add-buffer) + ("-r" "Recursive mode for `Add Directory'" "recursive") ("d" "Add Directory" ellama-context-add-directory) ("f" "Add File" ellama-context-add-file) ("s" "Add Selection" ellama-context-add-selection)