branch: elpa/aidermacs
commit 69580501ddfc8c80171fd955249549da5eabee49
Author: Mingde (Matthew) Zeng <[email protected]>
Commit: Mingde (Matthew) Zeng <[email protected]>
Fix melpazoid warnings
---
README.md | 39 +++++++++++++++++++++++++++++++--------
aidermacs-backend-comint.el | 25 +++++++++++++++----------
aidermacs-backend-vterm.el | 16 ++++++++--------
aidermacs.el | 36 +++++++++++++++++++++++-------------
4 files changed, 77 insertions(+), 39 deletions(-)
diff --git a/README.md b/README.md
index 5198a9757f..68421b7016 100644
--- a/README.md
+++ b/README.md
@@ -47,11 +47,13 @@ Your contributions are essential to making Aidermacs the
best AI pair programmin
:config
(setq aidermacs-default-model "sonnet")
(global-set-key (kbd "C-c a") 'aidermacs-transient-menu)
- ; Ensure emacs can access *_API_KEY through .bashrc or setenv
- (setenv "ANTHROPIC_API_KEY" anthropic-api-key)
+ ; Enable minor mode for Aider files
+ (aidermacs-setup-minor-mode)
; See the Configuration section below
(setq aidermacs-auto-commits t)
- (setq aidermacs-use-architect-mode t))
+ (setq aidermacs-use-architect-mode t)
+ ; Ensure emacs can access *_API_KEY through .bashrc or setenv
+ (setenv "ANTHROPIC_API_KEY" anthropic-api-key))
```
### Sample Config With Doom Emacs
@@ -299,22 +301,43 @@ When using Aidermacs with Doom Emacs, you can enable
Doom-specific keybindings b
The keybindings are only activated in buffers that are part of a Git
repository, keeping your global keybinding space clean.
-### Working with Prompt Blocks in `.aider*` files
+### Prompt Files Minor Mode
+
+Aidermacs provides a minor mode that makes it easy to work with prompt files
and other Aider-related files. The minor mode can be enabled automatically for
specific files by calling `(aidermacs-setup-minor-mode)` in your config:
+
+```emacs-lisp
+(aidermacs-setup-minor-mode)
+```
-When editing `.aider.prompt.org` or other `.aider*` files, these keybindings
are available:
+When enabled, the minor mode provides these convenient keybindings:
- `C-c C-n` or `C-<return>`: Send line/region line-by-line
- `C-c C-c`: Send block/region as whole
- `C-c C-z`: Switch to Aidermacs buffer
-### Prompt Files
+The minor mode is automatically enabled for:
+- `.aider.prompt.org` files (create with `M-x aidermacs-open-prompt-file`)
+- `.aider.chat.md` files
+- `.aider.chat.history.md` files
+- `.aider.input.history` files
+
+#### Working with Prompt Files
-The `.aider.prompt.org` file (created with `M-x aidermacs-open-prompt-file`)
is useful for:
+The `.aider.prompt.org` file is particularly useful for:
- Storing frequently used prompts
- Documenting common workflows
- Quick access to complex instructions
-The file is automatically recognized and enables Aidermacs minor mode with the
above keybindings.
+You can customize which files automatically enable the minor mode by
configuring `aidermacs-auto-mode-files`:
+
+```emacs-lisp
+(setq aidermacs-auto-mode-files
+ '(".aider.prompt.org"
+ ".aider.chat.md"
+ ".aider.chat.history.md"
+ ".aider.input.history"
+ "my-custom-aider-file.org")) ; Add your own files
+```
## Aidermacs vs aider.el
diff --git a/aidermacs-backend-comint.el b/aidermacs-backend-comint.el
index 462e12649c..f6eb21384b 100644
--- a/aidermacs-backend-comint.el
+++ b/aidermacs-backend-comint.el
@@ -77,6 +77,11 @@ This allows for multi-line input without sending the
command."
(defvar-local aidermacs--syntax-work-buffer nil
"Temporary buffer used for syntax highlighting operations.")
+(defvar-local aidermacs--syntax-block-marker nil
+ "Store the current block marker (SEARCH/REPLACE/fence) being processed.
+This variable holds the actual marker text (e.g., <<<<<<< SEARCH, =======,
etc.)
+that was matched at the start of the current syntax block.")
+
(defun aidermacs-reset-font-lock-state ()
"Reset font lock state to default for processing a new source block."
(setq aidermacs--syntax-block-delimiter nil
@@ -109,7 +114,7 @@ OUTPUT is the text to be processed."
(line-text (buffer-substring
next-line
(min (point-max) (+ next-line (length
aidermacs-search-marker)))))
- marker)
+ aidermacs--syntax-block-marker)
(cond ((equal line-text aidermacs-search-marker)
;; Next line is a SEARCH marker. use that instead of the
fence marker
(re-search-forward (format "^\\(%s\\)"
aidermacs-search-marker) nil t))
@@ -120,21 +125,21 @@ OUTPUT is the text to be processed."
(unless aidermacs--syntax-last-output-pos
;; Set up new block state
- (let ((block-marker (match-string 1)))
- (setq aidermacs--syntax-block-start-pos (line-end-position)
- aidermacs--syntax-block-end-pos (line-end-position)
- aidermacs--syntax-block-delimiter
- (pcase block-marker
- ((pred (equal aidermacs-search-marker))
aidermacs-diff-marker)
- ((pred (equal aidermacs-diff-marker))
aidermacs-replace-marker)
- ((pred (equal aidermacs-fence-marker))
aidermacs-fence-marker))))
+ (setq aidermacs--syntax-block-marker (match-string 1)
+ aidermacs--syntax-block-start-pos (line-end-position)
+ aidermacs--syntax-block-end-pos (line-end-position)
+ aidermacs--syntax-block-delimiter
+ (pcase aidermacs--syntax-block-marker
+ ((pred (equal aidermacs-search-marker)) aidermacs-diff-marker)
+ ((pred (equal aidermacs-diff-marker)) aidermacs-replace-marker)
+ ((pred (equal aidermacs-fence-marker))
aidermacs-fence-marker)))
(with-current-buffer aidermacs--syntax-work-buffer
(erase-buffer))
;; Set the major-mode of the font lock buffer unless this is the
second half of
;; SEARCH/REPLACE block. In that case reuse the previous mode
- (unless (equal marker aidermacs-diff-marker)
+ (unless (equal aidermacs--syntax-block-marker aidermacs-diff-marker)
(let ((mode (aidermacs--guess-major-mode)))
(with-current-buffer aidermacs--syntax-work-buffer
(unless (eq mode major-mode)
diff --git a/aidermacs-backend-vterm.el b/aidermacs-backend-vterm.el
index 43fe2a4814..ec7e376adc 100644
--- a/aidermacs-backend-vterm.el
+++ b/aidermacs-backend-vterm.el
@@ -29,6 +29,14 @@
(declare-function vterm-insert "vterm")
+(defvar-local aidermacs--vterm-active-timer nil
+ "Store the active timer for vterm output processing.")
+
+(defcustom aidermacs-vterm-multiline-newline-key "S-<return>"
+ "Key binding to enter a newline without sending in vterm."
+ :type 'string
+ :group 'aidermacs)
+
(defun aidermacs--is-aidermacs-vterm-buffer-p (&optional buffer)
"Check if BUFFER is an aidermacs vterm buffer.
If BUFFER is nil, check the current buffer.
@@ -146,14 +154,6 @@ BUFFER-NAME is the name for the vterm buffer."
(add-hook 'kill-buffer-hook #'aidermacs--vterm-cleanup nil t))))
buffer-name)
-(defvar-local aidermacs--vterm-active-timer nil
- "Store the active timer for vterm output processing.")
-
-(defcustom aidermacs-vterm-multiline-newline-key "S-<return>"
- "Key binding to enter a newline without sending in vterm."
- :type 'string
- :group 'aidermacs)
-
(defun aidermacs--send-command-vterm (buffer command)
"Send command to the aidermacs vterm buffer.
BUFFER is the target buffer to send to. COMMAND is the text to send."
diff --git a/aidermacs.el b/aidermacs.el
index 7630797442..f3805ac928 100644
--- a/aidermacs.el
+++ b/aidermacs.el
@@ -886,19 +886,29 @@ These are exact filename matches (including the dot
prefix)."
:type '(repeat string)
:group 'aidermacs)
-(defun aidermacs--should-enable-minor-mode-p (filename)
- "Determine if `aidermacs-minor-mode' should be enabled for FILENAME.
-Returns t if the file matches any of the patterns in
-`aidermacs-auto-mode-files'."
- (when filename
- (let ((base-name (file-name-nondirectory filename)))
- (member base-name aidermacs-auto-mode-files))))
-
-(add-hook #'find-file-hook
- (lambda ()
- (when (and buffer-file-name
- (aidermacs--should-enable-minor-mode-p
buffer-file-name))
- (aidermacs-minor-mode 1))))
+(defun aidermacs--maybe-enable-minor-mode ()
+ "Enable `aidermacs-minor-mode' if current buffer's file matches any
+of the patterns in `aidermacs-auto-mode-files'."
+ (when (and buffer-file-name
+ (when buffer-file-name
+ (let ((base-name (file-name-nondirectory buffer-file-name)))
+ (member base-name aidermacs-auto-mode-files))))
+ (aidermacs-minor-mode 1)))
+
+;;;###autoload
+(defun aidermacs-setup-minor-mode ()
+ "Set up automatic enabling of `aidermacs-minor-mode' for specific files.
+This adds a hook to automatically enable the minor mode for files
+matching patterns in `aidermacs-auto-mode-files'.
+
+The minor mode provides convenient keybindings for working with
+prompt files and other Aider-related files:
+\\<aidermacs-minor-mode-map>
+\\[aidermacs-send-line-or-region] - Send current line/region line-by-line
+\\[aidermacs-send-block-or-region] - Send block/region as whole
+\\[aidermacs-switch-to-buffer] - Switch to Aidermacs buffer"
+ (interactive)
+ (add-hook 'find-file-hook #'aidermacs--maybe-enable-minor-mode))
(provide 'aidermacs)
;;; aidermacs.el ends here