diff --git a/ai-code-git.el b/ai-code-git.el index 35951638..b19f7e31 100644 --- a/ai-code-git.el +++ b/ai-code-git.el @@ -62,6 +62,15 @@ or nil (prompt the user)." (defvar ai-code-pr-title-history nil "Minibuffer history for optional PR titles.") +;; DONE: when press C-c a v, if there is a selected region, and if there is a url inside, it should be used as a default value when asking user for PR or issue URL. + +(defun ai-code--extract-url-from-region () + "Return the first URL found in the active region, or nil." + (when (use-region-p) + (let ((text (buffer-substring-no-properties (region-beginning) (region-end)))) + (when (string-match "https?://[^ \t\n]+" text) + (match-string 0 text))))) + (defun ai-code--git-ignored-repo-file-p (file root) "Return non-nil when FILE should be ignored for repo candidates under ROOT." (when (and file root) @@ -242,7 +251,8 @@ Otherwise, ask for the relevant pull request or issue URL." (ai-code--build-send-current-branch-pr-init-prompt review-source current-branch target-branch pr-title))) (let* ((url-prompt (ai-code--pull-or-review-url-prompt review-mode)) - (target-url (ai-code-read-string url-prompt))) + (region-url (ai-code--extract-url-from-region)) + (target-url (ai-code-read-string url-prompt region-url))) (ai-code--build-pr-init-prompt review-source target-url review-mode)))) (prompt-label (if (eq review-mode 'send-current-branch-pr) "Enter PR creation prompt: " diff --git a/ai-code-prompt-mode.el b/ai-code-prompt-mode.el index bc4c44fe..440b1bb1 100644 --- a/ai-code-prompt-mode.el +++ b/ai-code-prompt-mode.el @@ -422,7 +422,7 @@ If PROMPT-TEXT is a command (starts with /), execute it directly instead." (not (string-match-p " " processed-prompt))) (ai-code--execute-command processed-prompt) (let* ((append-summary-p (and (derived-mode-p 'ai-code-prompt-mode) - (org-at-heading-p) + (ignore-errors (save-excursion (org-back-to-heading t) t)) (y-or-n-p "Append result summary to current section? "))) (final-prompt (if append-summary-p (concat processed-prompt