branch: elpa/aidermacs
commit 09cb8a5546804e5c8dbc29dca5008396e6c49726
Author: Mingde (Matthew) Zeng (aider) <matthew...@posteo.net>
Commit: Mingde (Matthew) Zeng <matthew...@posteo.net>

    feat: Improve documentation, error handling, and code clarity
---
 README.org                  | 15 +++++++++------
 aidermacs-backend-comint.el |  2 +-
 aidermacs-backend-vterm.el  |  2 +-
 aidermacs-backends.el       |  4 +++-
 aidermacs-doom.el           | 10 +++++-----
 aidermacs.el                | 26 +++++++++++++-------------
 6 files changed, 32 insertions(+), 27 deletions(-)

diff --git a/README.org b/README.org
index 0639b14f84..3801269024 100644
--- a/README.org
+++ b/README.org
@@ -78,6 +78,8 @@ With =aidermacs=, you get:
 ** Terminal Backend Selection
 Choose your preferred terminal backend by setting =aidermacs-backend=:
 
+=vterm= provides better terminal compatibility and bracketed paste support, 
while =comint= is a simpler, built-in option.
+
 #+BEGIN_SRC emacs-lisp
 ;; Use vterm backend (default is comint)
 (setq aidermacs-backend 'vterm)
@@ -120,7 +122,7 @@ To provide context to the AI, you need to add relevant 
files to the Aidermacs se
 
 ** 3. Interact with the AI
 
-Once you have added the relevant files, you can interact with the AI using 
these commands:
+After adding files to the session, switch to the =*aidermacs*= buffer to 
interact with the AI using these commands:
 
 *** Code Changes
 - Request code changes: =M-x aidermacs-code-change= (=c= in transient menu)
@@ -130,11 +132,11 @@ Once you have added the relevant files, you can interact 
with the AI using these
 - Undo last AI change: =M-x aidermacs-undo-last-change= (=u= in transient menu)
 
 *** Questions and Explanations
-- Ask questions about code context: =M-x aidermacs-ask-question= (=q= in 
transient menu)
-- Ask general questions: =M-x aidermacs-general-question= (=Q= in transient 
menu)
-- Explain function/region: =M-x aidermacs-function-or-region-explain= (=e= in 
transient menu)
-- Explain symbol at point: =M-x aidermacs-explain-symbol-under-point= (=p= in 
transient menu)
-- Get help: =M-x aidermacs-help= (=h= in transient menu)
+- Ask the AI questions about the current code context: =M-x 
aidermacs-ask-question= (=q= in transient menu)
+- Ask the AI a general question: =M-x aidermacs-general-question= (=Q= in 
transient menu)
+- Explain a function or region of code: =M-x 
aidermacs-function-or-region-explain= (=e= in transient menu)
+- Explain the symbol at point: =M-x aidermacs-explain-symbol-under-point= (=p= 
in transient menu)
+- Get help on aidermacs commands: =M-x aidermacs-help= (=h= in transient menu)
 
 *** Testing and Debugging
 - Generate unit tests: =M-x aidermacs-write-unit-test= (=U= in transient menu)
@@ -177,6 +179,7 @@ Session management commands:
 ** 7. Transient Menu
 
 - Access all commands through the transient menu: =M-x 
aidermacs-transient-menu=
+- The transient menu is a popup menu that provides a convenient way to access 
all aidermacs commands.
 - The menu groups commands into categories:
   - "aidermacs Process": Basic session management (=a=, =z=, =o=, =l=, =s=, 
=x=)
   - "Add File to aidermacs": File management (=f=, =R=, =w=, =d=, =b=)
diff --git a/aidermacs-backend-comint.el b/aidermacs-backend-comint.el
index 7633b157c7..55c21eaa72 100644
--- a/aidermacs-backend-comint.el
+++ b/aidermacs-backend-comint.el
@@ -1,4 +1,4 @@
-;;; aidermacsmacs-backend-comint.el --- Comint backend for aidermacs.el -*- 
lexical-binding: t; -*-
+;;; aidermacs-backend-comint.el --- Comint backend for aidermacs.el -*- 
lexical-binding: t; -*-
 
 ;;; Commentary:
 ;; Comint backend implementation for aidermacs.el
diff --git a/aidermacs-backend-vterm.el b/aidermacs-backend-vterm.el
index cf482cafdd..abc769fd0b 100644
--- a/aidermacs-backend-vterm.el
+++ b/aidermacs-backend-vterm.el
@@ -12,7 +12,7 @@
   (unless (require 'vterm nil t)
     (error "vterm package is not available"))
   (unless (get-buffer buffer-name)
-    (let ((mode (if (eq (frame-parameter nil 'background-mode) 'dark)
+    (let* ((mode (if (eq (frame-parameter nil 'background-mode) 'dark)
                      "--dark-mode"
                    "--light-mode"))
            (cmd (mapconcat 'identity (append (list program mode) args) " ")))
diff --git a/aidermacs-backends.el b/aidermacs-backends.el
index ee4d73cfda..4209c80158 100644
--- a/aidermacs-backends.el
+++ b/aidermacs-backends.el
@@ -31,7 +31,9 @@ PROGRAM is the aidermacs executable path, ARGS are command 
line arguments,
 and BUFFER-NAME is the name for the aidermacs buffer."
   (cond
    ((eq aidermacs-backend 'vterm)
-    (aidermacs-run-aidermacs-vterm program args buffer-name))
+    (if (featurep 'vterm)
+        (aidermacs-run-aidermacs-vterm program args buffer-name)
+      (error "vterm package is not available. Please install it to use the 
vterm backend.")))
    (t
     (aidermacs-run-aidermacs-comint program args buffer-name))))
 
diff --git a/aidermacs-doom.el b/aidermacs-doom.el
index 7fe88603ea..4232e676ad 100644
--- a/aidermacs-doom.el
+++ b/aidermacs-doom.el
@@ -23,8 +23,8 @@
                             )
 
                    (:prefix ("b" . "Buffer")
-                            :desc "Switch to aidermacsmacs" "b" 
#'aidermacs-switch-to-buffer
-                            :desc "Clear aidermacsmacs" "c" #'aidermacs-clear
+                            :desc "Switch to aidermacs" "b" 
#'aidermacs-switch-to-buffer
+                            :desc "Clear aidermacs" "c" #'aidermacs-clear
                             )
 
                    (:prefix ("s" . "Send")
@@ -58,9 +58,9 @@
                             :desc "Help" "h" #'aidermacs-help
                             )
 
-                   :desc "Open aidermacsmacs" "o" #'aidermacs-run-aidermacs
-                   :desc "Reset aidermacsmacs" "r" #'aidermacs-reset
-                   :desc "Exit aidermacsmacs" "x" #'aidermacs-exit
+                   :desc "Open aidermacs" "o" #'aidermacs-run-aidermacs
+                   :desc "Reset aidermacs" "r" #'aidermacs-reset
+                   :desc "Exit aidermacs" "x" #'aidermacs-exit
                    ))))
 
 ;; Add the setup function to appropriate hooks
diff --git a/aidermacs.el b/aidermacs.el
index 66859cf197..35f8826b6e 100644
--- a/aidermacs.el
+++ b/aidermacs.el
@@ -1,4 +1,4 @@
-;;; aidermacs.el --- aidermacsmacs package for interactive conversation with 
aidermacs -*- lexical-binding: t; -*-
+;;; aidermacs.el --- aidermacs package for interactive conversation with 
aidermacs -*- lexical-binding: t; -*-a
 
 ;; Author: Mingde (Matthew) Zeng <matthew...@posteo.net>
 ;; Original Author: Kang Tu <tni...@gmail.com>
@@ -149,7 +149,7 @@ Affects the system message too.")
 ;; Transient menu for aidermacs commands
 ;; The instruction in the autoload comment is needed, see
 ;; https://github.com/magit/transient/issues/280.
-;;;###autoload (autoload 'aidermacs-transient-menu "aidermacs" "Transient menu 
for aidermacsmacs commands." t)
+;;;###autoload (autoload 'aidermacs-transient-menu "aidermacs" "Transient menu 
for aidermacs commands." t)
 (transient-define-prefix aidermacs-transient-menu ()
   "Transient menu for aidermacs commands."
   ["aidermacs: AI Pair Programming"
@@ -210,7 +210,7 @@ If not in a git repository and no buffer file exists, an 
error is raised."
               (file-truename (file-name-directory current-file))))
      ;; Case 3: No git repo and no buffer file
      (t
-      (error "Not in a git repository and current buffer is not associated 
with a file")))))
+      (error "Not in a git repository and current buffer is not associated 
with a file.  Please open a file or start aidermacs from within a git 
repository.")))))
 
 ;;;###autoload
 (defun aidermacs-run-aidermacs (&optional edit-args)
@@ -235,7 +235,7 @@ Dispatches to the appropriate backend."
         (when switch-to-buffer
           (aidermacs-switch-to-buffer))
         (sleep-for 0.2))
-    (message "Buffer %s does not exist. Please start 'aidermacs' first." 
(funcall #'aidermacs-buffer-name))))
+    (message "Buffer %s does not exist. Please start aidermacs with 'M-x 
aidermacs-run-aidermacs'." (funcall #'aidermacs-buffer-name))))
 
 (defun aidermacs-kill-buffer ()
   "Clean-up fontify buffer."
@@ -335,7 +335,7 @@ Dispatches to the appropriate backend."
               (condition-case e
                   (let ((inhibit-message t))
                     (funcall mode))
-                (error (message "aidermacs: failed to init major-mode `%s' for 
font-locking: %s" mode e))))))
+                (error "aidermacs: failed to init major-mode `%s' for 
font-locking: %s" mode e)))))
 
         ;; Process initial content
         (aidermacs--fontify-block)))))
@@ -430,7 +430,7 @@ If the current buffer is already the aidermacs buffer, do 
nothing."
         (if aidermacs--switch-to-buffer-other-frame
             (switch-to-buffer-other-frame buffer)
           (pop-to-buffer buffer))
-      (message "aidermacsmacs buffer '%s' does not exist." 
(aidermacs-buffer-name)))))
+      (message "aidermacs buffer '%s' does not exist." 
(aidermacs-buffer-name)))))
 
 ;; Function to reset the aidermacs buffer
 ;;;###autoload
@@ -472,7 +472,7 @@ from the source buffer and maintaining proper process 
markers."
   "Entering multi-line chat messages
 
https://aidermacs.chat/docs/usage/commands.html#entering-multi-line-chat-messages
 If STR contains newlines and isn't already wrapped in {aidermacs...aidermacs},
-wrap it in {aidermacs\\nstr\\naidermacs}. Otherwise return STR unchanged."
+wrap it in {aidermacs\nstr\naidermacs}. Otherwise return STR unchanged."
   (if (and (string-match-p "\n" str)
            (not (string-match-p "^{aidermacs\n.*\naidermacs}$" str)))
       (format "{aidermacs\n%s\naidermacs}" str)
@@ -484,11 +484,11 @@ wrap it in {aidermacs\\nstr\\naidermacs}. Otherwise 
return STR unchanged."
   ;; Ensure the current buffer is associated with a file
   (if (not buffer-file-name)
       (message "Current buffer is not associated with a file.")
-    (let* ((local-name (file-local-name
-                        (expand-file-name buffer-file-name)))
-           (formatted-path (if (string-match-p " " local-name)
-                               (format "\"%s\"" local-name)
-                             local-name))
+    (let* ((file-path (buffer-file-name))
+           ;; Use buffer-file-name directly
+           (formatted-path (if (string-match-p " " file-path)
+                               (format "\"%s\"" file-path)
+                             file-path))
            (command (format "%s %s" command-prefix formatted-path)))
       ;; Use the shared helper function to send the command
       (aidermacs--send-command command))))
@@ -527,7 +527,7 @@ wrap it in {aidermacs\\nstr\\naidermacs}. Otherwise return 
STR unchanged."
 (defun aidermacs-general-command ()
   "Prompt the user to input COMMAND and send it to the corresponding aidermacs 
comint buffer."
   (interactive)
-  (let ((command (aidermacs-read-string "Enter command to send to 
aidermacsmacs: ")))
+  (let ((command (aidermacs-read-string "Enter command to send to aidermacs: 
")))
     ;; Use the shared helper function to send the command
     (aidermacs--send-command command t)))
 

Reply via email to