branch: elpa/aidermacs
commit e1cb57f81840201cc1dd7a64ef80891dc06c5f9b
Author: Kang Tu <kang...@apple.com>
Commit: Kang Tu <kang...@apple.com>

    add helm-aider.el
---
 README.org    |  2 +-
 helm-aider.el | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/README.org b/README.org
index 7dc5ef3f4d..044129a7ac 100644
--- a/README.org
+++ b/README.org
@@ -29,7 +29,7 @@
 
 #+BEGIN_SRC emacs-lisp
   (use-package aider
-    :straight (:host github :repo "tninja/aider.el")
+    :straight (:host github :repo "tninja/aider.el" :files ("aider.el"))
     :config
     (setq aider-args '("--model" "gpt-4o-mini"))
     (setenv "OPENAI_API_KEY" <your-openai-api-key>)
diff --git a/helm-aider.el b/helm-aider.el
new file mode 100644
index 0000000000..88eaee942f
--- /dev/null
+++ b/helm-aider.el
@@ -0,0 +1,55 @@
+
+;; optional helm based completion, need to be manually loaded when needed
+
+;; helm based aider input
+
+(require 'helm)
+(require 'cl-lib)  ; For `cl-subseq`
+
+(defvar aider-helm-read-string-history nil
+  "History list for `aider-helm-read-string` inputs.")
+
+(defvar aider-helm-read-string-history-file
+  "~/.emacs.d/aider-helm-read-string-history.el"
+  "File to save `aider-helm-read-string-history`.")
+
+(defvar aider-helm-read-string-history-max 1000
+  "Maximum number of entries to keep in `aider-helm-read-string-history`.")
+
+(defun save-aider-helm-read-string-history ()
+  "Save `aider-helm-read-string-history` to a file."
+  ;; Trim history to maximum size
+  (setq aider-helm-read-string-history
+        (cl-subseq aider-helm-read-string-history
+                   0 (min (length aider-helm-read-string-history)
+                          aider-helm-read-string-history-max)))
+  ;; Save to file
+  (with-temp-file aider-helm-read-string-history-file
+    (insert (prin1-to-string aider-helm-read-string-history))))
+
+(defun load-aider-helm-read-string-history ()
+  "Load `aider-helm-read-string-history` from a file."
+  (when (file-exists-p aider-helm-read-string-history-file)
+    (with-temp-buffer
+      (insert-file-contents aider-helm-read-string-history-file)
+      (setq aider-helm-read-string-history (read (buffer-string))))))
+
+(add-hook 'kill-emacs-hook 'save-aider-helm-read-string-history)
+(load-aider-helm-read-string-history)
+
+(defun aider-helm-read-string (prompt &optional initial-input default-value)
+  "Read a string with Helm completion, showing historical inputs."
+  (let* ((input (helm-comp-read
+                 prompt
+                 aider-helm-read-string-history
+                 :must-match nil
+                 :name "Helm Read String"
+                 :history 'aider-helm-read-string-history
+                 :initial-input initial-input
+                 :default default-value)))
+    ;; Add input to history if it's not empty
+    (unless (string-empty-p input)
+      (add-to-history 'aider-helm-read-string-history input))
+    input))
+
+(defalias 'aider-read-string 'aider-helm-read-string)

Reply via email to