branch: externals/ellama commit 53a9e08186ad395cdcf688e103d08c535154fda9 Author: Sergey Kostyaev <sskosty...@gmail.com> Commit: Sergey Kostyaev <sskosty...@gmail.com>
Improve file name handling Added a new function `ellama--fix-file-name` to replace forbidden characters in file names with underscores. Updated `ellama-generate-name` to use this new function for generating session names. Added a corresponding test case in `test-ellama.el`. --- ellama.el | 20 +++++++++++++++++++- tests/test-ellama.el | 5 +++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/ellama.el b/ellama.el index 775895d626..614b431c58 100644 --- a/ellama.el +++ b/ellama.el @@ -643,6 +643,24 @@ EXTRA contains additional information." "Return ellama session buffer by provided ID." (gethash id ellama--active-sessions)) +(defun ellama--fix-file-name (name) + "Change forbidden characters in the NAME to acceptable." + (replace-regexp-in-string (rx (or (literal "/") + (literal "\\") + (literal "?") + (literal "%") + (literal "*") + (literal ":") + (literal "|") + (literal "\"") + (literal "<") + (literal ">") + (literal ".") + (literal ";") + (literal "="))) + "_" + name)) + (defun ellama-generate-name-by-words (provider action prompt) "Generate name for ACTION by PROVIDER by getting first N words from PROMPT." (let* ((cleaned-prompt (replace-regexp-in-string "/" "_" prompt)) @@ -687,7 +705,7 @@ EXTRA contains additional information." (defun ellama-generate-name (provider action prompt) "Generate name for ellama ACTION by PROVIDER according to PROMPT." - (replace-regexp-in-string "/" "_" (funcall ellama-naming-scheme provider action prompt))) + (ellama--fix-file-name (funcall ellama-naming-scheme provider action prompt))) (defvar ellama--new-session-context nil) diff --git a/tests/test-ellama.el b/tests/test-ellama.el index 8c93f6ee03..d4d4c878f5 100644 --- a/tests/test-ellama.el +++ b/tests/test-ellama.el @@ -388,6 +388,11 @@ average_score = calculate_average_score(student_math_score, student_science_scor print(f\"The average score of {student_name} in {class_name} is: {average_score:.2f}\") #+END_SRC\n\nIn this example:\n- Variable names like ~student/name~, ~class/name~, and ~grade/level~ use snake/case.\n- The function name ~calculate/average/score~ also follows the snake_case convention.\n\nSnake case helps improve readability, especially in languages that are sensitive to capitalization\nlike Python.")))) +(ert-deftest test-ellama--fix-file-name () + (should (string= + (ellama--fix-file-name "a/\\?%*:|\"<>.;=") + "a_____________"))) + (provide 'test-ellama) ;;; test-ellama.el ends here