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

    Add aidermacs-drop-current-file, refactoring
    
    Signed-off-by: Mingde (Matthew) Zeng <matthew...@posteo.net>
---
 README.org        | 15 ++++++-------
 aidermacs-doom.el |  2 +-
 aidermacs.el      | 63 ++++++++++++++-----------------------------------------
 3 files changed, 25 insertions(+), 55 deletions(-)

diff --git a/README.org b/README.org
index 64928d714e..283d15e364 100644
--- a/README.org
+++ b/README.org
@@ -23,10 +23,11 @@ Aidermacs thrives on community involvement. We believe that 
the best software is
 
 Your contributions are essential to making Aidermacs the best AI pair 
programming tool for Emacs!
 
-* Why Aidermacs over aider.el?
-Aidermacs begins as a fork of 
[[https://github.com/tninja/aider.el][aider.el]], intended to offer more 
Emacs-native experience integrating with 
[[https://github.com/paul-gauthier/aider][Aider]].
+** Why Aidermacs over aider.el?
 
-=Aidermacs= and =aider.el= are different development philosophies, =Aidermacs= 
prioritizes Emacs workflow integration, but =aider.el= emphasizes on 
replicating Aider's CLI behavior.
+Aidermacs is designed to provide a more Emacs-native experience while still 
integrating with [[https://github.com/paul-gauthier/aider][Aider]]. It began as 
a fork of [[https://github.com/tninja/aider.el][aider.el]], but has since 
diverged significantly to prioritize Emacs workflow integration.
+
+While =aider.el= strictly mirrors Aider's CLI behavior, =Aidermacs= is built 
around Emacs-specific features and paradigms. This design philosophy allows you 
to harness Aider's powerful capabilities through a natural, Emacs-native coding 
experience.
 
 With =Aidermacs=, you get:
 
@@ -138,7 +139,7 @@ This section provides a step-by-step guide on how to use 
Aidermacs for AI-assist
 To provide context to the AI, you need to add relevant files to the Aidermacs 
session:
 
 - Add current file: =M-x aidermacs-add-current-file= (=f= in transient menu)
-- Add current file in read-only mode: =M-x aidermacs-current-file-read-only= 
(=R= in transient menu)
+- Add current file in read-only mode: =M-x 
aidermacs-add-current-file-read-only= (=R= in transient menu)
 - Add all files in current window: =M-x aidermacs-add-files-in-current-window= 
(=w= in transient menu)
 - Add all files with same suffix in current directory: =M-x 
aidermacs-add-same-type-files-under-dir= (=d= in transient menu)
 - In dired-mode, add marked files: =M-x 
aidermacs-batch-add-dired-marked-files= (=b= in transient menu)
@@ -165,12 +166,13 @@ After adding files to the session, switch to the 
=*aidermacs*= buffer to interac
 
 *** File Management
 - Add Current File: =M-x aidermacs-add-current-file= (=f= in transient menu)
-- Add File Read-Only: =M-x aidermacs-current-file-read-only= (=R= in transient 
menu)
+- Add File Read-Only: =M-x aidermacs-add-current-file-read-only= (=R= in 
transient menu)
 - Add Files in Window: =M-x aidermacs-add-files-in-current-window= (=w= in 
transient menu)
 - Add Files by Type: =M-x aidermacs-add-same-type-files-under-dir= (=d= in 
transient menu)
 - Add Marked Files: =M-x aidermacs-batch-add-dired-marked-files= (=b= in 
transient menu)
 - List Added Files: =M-x aidermacs-list-added-files= (=L= in transient menu)
 - Drop File from Chat: =M-x aidermacs-drop-file= (=D= in transient menu)
+- Drop Current File: =M-x aidermacs-drop-current-file= (=O= in transient menu)
 
 *** Code Actions
 - Code Change: =M-x aidermacs-code-change= (=c= in transient menu)
@@ -233,11 +235,10 @@ Session management commands:
 - The transient menu is a popup menu that provides a convenient way to access 
all aidermacs commands.
 - The menu groups commands into categories:
   - "Session Control": Basic session management (=a=, =.=, =z=, =o=, =l=, =s=, 
=x=)
-  - "File Management": File management (=f=, =R=, =w=, =d=, =b=, =L=, =D=)
+  - "File Management": File management (=f=, =w=, =d=, =b=, =L=, =D=, =O=)
   - "Code Actions": Code modifications (=c=, =r=, =i=, =t=, =u=)
   - "Testing": Unit tests and debugging (=U=, =T=, =X=)
   - "Help & Documentation": Questions and explanations (=q=, =e=, =p=, =h=, 
=Q=)
   - "History & Output": History and output management (=H=, =C=, =m=, =y=, 
=g=, =P=)
-- Toggle options are available at the top of relevant sections
 
 Note: The default keybindings in the minor mode map (=C-c C-n=, =C-<return>=, 
=C-c C-c=, and =C-c C-z=) are always available when the minor mode is active. 
All other commands can be accessed either through =M-x= or through the 
transient menu after invoking =M-x aidermacs-transient-menu=.
diff --git a/aidermacs-doom.el b/aidermacs-doom.el
index 4232e676ad..722793c51c 100644
--- a/aidermacs-doom.el
+++ b/aidermacs-doom.el
@@ -16,7 +16,7 @@
           (:prefix ("A" . "aidermacs")
                    (:prefix ("a" . "Add")
                             :desc "Current file" "c" 
#'aidermacs-add-current-file
-                            :desc "File read-only" "f" 
#'aidermacs-current-file-read-only
+                            :desc "File read-only" "f" 
#'aidermacs-add-current-file-read-only
                             :desc "Files in window" "w" 
#'aidermacs-add-files-in-current-window
                             :desc "Add Same Type Files under dir" "d" 
#'aidermacs-add-same-type-files-under-dir
                             :desc "Batch direct marked files" "b" 
#'aidermacs-batch-add-dired-marked-files
diff --git a/aidermacs.el b/aidermacs.el
index e9b6d6f0a7..dabb26a28e 100644
--- a/aidermacs.el
+++ b/aidermacs.el
@@ -107,34 +107,12 @@ This function can be customized or redefined by the user."
   ;; Ensure the alias is always available in both compiled and interpreted 
modes.
   (defalias 'aidermacs-read-string 'aidermacs-plain-read-string))
 
-(defvar aidermacs--add-file-read-only nil
-  "Set model parameters from `aidermacs-menu' buffer-locally.
-Affects the system message too.")
-
-(defun aidermacs--get-add-command-prefix ()
-  "Return the appropriate command prefix based on 
aidermacs--add-file-read-only."
-  (if aidermacs--add-file-read-only "/read-only" "/add"))
-
-(defclass aidermacs--add-file-type (transient-lisp-variable)
-  ((variable :initform 'aidermacs--add-file-read-only)
-   (format :initform "%k %d %v")
-   (reader :initform #'transient-lisp-variable--read-value))
-  "Class for toggling aidermacs--add-file-read-only.")
-
 (defclass aidermacs--switch-to-buffer-type (transient-lisp-variable)
   ((variable :initform 'aidermacs--switch-to-buffer-other-frame)
    (format :initform "%k %d %v")
    (reader :initform #'transient-lisp-variable--read-value))
   "Class for toggling aidermacs--switch-to-buffer-other-frame.")
 
-(transient-define-infix aidermacs--infix-add-file-read-only ()
-  "Toggle aidermacs--add-file-read-only between nil and t."
-  :class 'aidermacs--add-file-type
-  :key "@"
-  :description "Read-only mode"
-  :reader (lambda (_prompt _initial-input _history)
-            (not aidermacs--add-file-read-only)))
-
 (transient-define-infix aidermacs--infix-switch-to-buffer-other-frame ()
   "Toggle aidermacs--switch-to-buffer-other-frame between nil and t."
   :class 'aidermacs--switch-to-buffer-type
@@ -161,14 +139,14 @@ Affects the system message too.")
     ("x" "Exit Session"               aidermacs-exit)]
 
    ["File Management"
-    (aidermacs--infix-add-file-read-only)
     ("f" "Add Current File"           aidermacs-add-current-file)
-    ("R" "Add File Read-Only"         aidermacs-current-file-read-only)
+    ("R" "Add File Read-Only"         aidermacs-add-current-file-read-only)
     ("w" "Add Files in Window"        aidermacs-add-files-in-current-window)
     ("d" "Add Files by Type"          aidermacs-add-same-type-files-under-dir)
     ("b" "Add Marked Files"           aidermacs-batch-add-dired-marked-files)
     ("L" "List Added Files"           aidermacs-list-added-files)
-    ("D" "Drop File from Chat"        aidermacs-drop-file)]
+    ("D" "Drop File from Chat"        aidermacs-drop-file)
+    ("O" "Drop Current File"          aidermacs-drop-current-file)]
 
    ["Code Actions"
     ("c" "Code Change"                aidermacs-code-change)
@@ -309,7 +287,7 @@ wrap it in {aidermacs\nstr\naidermacs}. Otherwise return 
STR unchanged."
     str))
 
 ;;;###autoload
-(defun aidermacs-add-or-read-current-file (command-prefix)
+(defun aidermacs-act-on-current-file (command-prefix)
   "Send the command \"COMMAND-PREFIX <current buffer file full path>\" to the 
corresponding aidermacs comint buffer."
   ;; Ensure the current buffer is associated with a file
   (if (not buffer-file-name)
@@ -323,20 +301,26 @@ wrap it in {aidermacs\nstr\naidermacs}. Otherwise return 
STR unchanged."
       ;; Use the shared helper function to send the command
       (aidermacs--send-command command))))
 
-;; Function to send "/add <current buffer file full path>" to corresponding 
aidermacs buffer
 ;;;###autoload
 (defun aidermacs-add-current-file ()
   "Send the command \"/add <current buffer file full path>\" to the 
corresponding aidermacs comint buffer."
   (interactive)
-  (aidermacs-add-or-read-current-file (aidermacs--get-add-command-prefix)))
+  (aidermacs-act-on-current-file "/add"))
 
 ;;;###autoload
-(defun aidermacs-current-file-read-only ()
+(defun aidermacs-add-current-file-read-only ()
   "Send the command \"/read-only <current buffer file full path>\" to the 
corresponding aidermacs comint buffer."
   (interactive)
-  (aidermacs-add-or-read-current-file "/read-only"))
+  (aidermacs-act-on-current-file "/read-only"))
+
+
+;;;###autoload
+(defun aidermacs-drop-current-file ()
+  "Send the command \"/drop <current buffer file full path>\" to the 
corresponding aider comint buffer."
+  (interactive)
+  (aidermacs-act-on-current-file "/drop"))
+
 
-;; New function to add files in all buffers in current emacs window
 ;;;###autoload
 (defun aidermacs-add-files-in-current-window ()
   "Add files in all buffers in the current Emacs window to the aidermacs 
buffer."
@@ -348,7 +332,7 @@ wrap it in {aidermacs\nstr\naidermacs}. Otherwise return 
STR unchanged."
                        (mapcar 'window-buffer (window-list)))))
     (setq files (delq nil files))
     (if files
-        (let ((command (concat (aidermacs--get-add-command-prefix) " " 
(mapconcat 'identity files " "))))
+        (let ((command (concat "/add " (mapconcat 'identity files " "))))
           (aidermacs--send-command command nil))
       (message "No files found in the current window."))))
 
@@ -461,7 +445,6 @@ Sends the \"/ls\" command and returns the list of files via 
callback."
   aidermacs--current-output)
 
 
-;; New function to get command from user and send it prefixed with "/ask "
 ;;;###autoload
 (defun aidermacs-ask-question ()
   "Prompt the user for a command and send it to the corresponding aidermacs 
comint buffer prefixed with \"/ask \".
@@ -493,7 +476,6 @@ If cursor is inside a function, include the function name 
as context."
     (let ((command (format "/ask %s" question)))
       (aidermacs--send-command command t))))
 
-;; New function to get command from user and send it prefixed with "/help "
 ;;;###autoload
 (defun aidermacs-help ()
   "Prompt the user for a command and send it to the corresponding aidermacs 
comint buffer prefixed with \"/help \"."
@@ -501,7 +483,6 @@ If cursor is inside a function, include the function name 
as context."
   (let ((command (aidermacs-read-string "Enter help question: ")))
     (aidermacs-send-command-with-prefix "/help " command)))
 
-;; New function to get command from user and send it prefixed with "/architect 
"
 ;;;###autoload
 (defun aidermacs-architect-discussion ()
   "Prompt the user for a command and send it to the corresponding aidermacs 
comint buffer prefixed with \"/architect \"."
@@ -509,7 +490,6 @@ If cursor is inside a function, include the function name 
as context."
   (let ((command (aidermacs-read-string "Enter architect discussion question: 
")))
     (aidermacs-send-command-with-prefix "/architect " command)))
 
-;; New function to get command from user and send it prefixed with "/ask ", 
might be tough for AI at this moment
 ;;;###autoload
 (defun aidermacs-debug-exception ()
   "Prompt the user for a command and send it to the corresponding aidermacs 
comint buffer prefixed with \"/debug \",
@@ -524,7 +504,6 @@ replacing all newline characters except for the one at the 
end."
   (interactive)
   (aidermacs--send-command "go ahead" t))
 
-;; New function to show the last commit using magit
 ;;;###autoload
 (defun aidermacs-magit-show-last-commit ()
   "Show the last commit message using Magit.
@@ -534,7 +513,6 @@ If Magit is not installed, report that it is required."
       (magit-show-commit "HEAD")
     (message "Magit is required to show the last commit.")))
 
-;; Modified function to get command from user and send it based on selected 
region
 ;;;###autoload
 (defun aidermacs-undo-last-change ()
   "Undo the last change made by aidermacs."
@@ -566,7 +544,6 @@ If point is in a function, refactor that function."
           (aidermacs--send-command command t))
       (message "No region selected and no function found at point."))))
 
-;; New function to explain the code in the selected region
 ;;;###autoload
 (defun aidermacs-region-explain ()
   "Get a command from the user and send it to the corresponding aidermacs 
comint buffer based on the selected region.
@@ -586,7 +563,6 @@ The command will be formatted as \"/ask \" followed by the 
text from the selecte
         (aidermacs--send-command command t))
     (message "No region selected.")))
 
-;; New function to ask aidermacs to explain the function under the cursor
 ;;;###autoload
 (defun aidermacs-function-explain ()
   "Ask aidermacs to explain the function under the cursor.
@@ -608,7 +584,6 @@ Prompts user for specific questions about the function."
       (aidermacs-region-explain)
     (aidermacs-function-explain)))
 
-;; New function to explain the symbol at line
 ;;;###autoload
 (defun aidermacs-explain-symbol-under-point ()
   "Ask aidermacs to explain symbol under point, given the code line as 
background info."
@@ -627,9 +602,6 @@ Prompts user for specific questions about the function."
   (aidermacs-add-current-file)
   (aidermacs--send-command (concat prefix command) t))
 
-;;; functions for dired related
-
-;; New function to add multiple Dired marked files to aidermacs buffer
 ;;;###autoload
 (defun aidermacs-batch-add-dired-marked-files ()
   "Add multiple Dired marked files to the aidermacs buffer with the \"/add\" 
command."
@@ -640,7 +612,6 @@ Prompts user for specific questions about the function."
           (aidermacs--send-command command t))
       (message "No files marked in Dired."))))
 
-;; New function to add all files with same suffix as current file under 
current directory
 ;;;###autoload
 (defun aidermacs-add-same-type-files-under-dir ()
   "Add all files with same suffix as current file under current directory to 
aidermacs.
@@ -662,8 +633,6 @@ If there are more than 40 files, refuse to add and show 
warning message."
         (message "Added %d files with suffix .%s"
                  (length files) current-suffix)))))
 
-;;; functions for test fixing
-
 ;;;###autoload
 (defun aidermacs-write-unit-test ()
   "Generate unit test code for current buffer.

Reply via email to