@@ -114,18 +114,22 @@ Returns a list of relative paths from the git repository root."
114114;;;### autoload
115115(defun ai-code-investigate-exception (arg )
116116 " Generate prompt to investigate exceptions or errors in code.
117- With a prefix argument (C-u), or if not in a programming mode buffer,
118- prompt for investigation without adding any context.
117+ With a prefix argument (C-u), use context from clipboard as the error to investigate.
119118If a *compilation* buffer is visible in the current window, use its full content as context.
120119If a region is selected, investigate that specific error or exception.
121120If cursor is in a function, investigate exceptions in that function.
122121Otherwise, investigate general exception handling in the file.
123122Inserts the prompt into the AI prompt file and optionally sends to AI.
124123Argument ARG is the prefix argument."
125124 (interactive " P" )
126- (let* ((compilation-buffer (get-buffer " *compilation*" ))
125+ (let* ((clipboard-content (when arg
126+ (condition-case nil
127+ (current-kill 0 )
128+ (error nil ))))
129+ (compilation-buffer (get-buffer " *compilation*" ))
127130 (compilation-content (when (and compilation-buffer
128- (get-buffer-window compilation-buffer))
131+ (get-buffer-window compilation-buffer)
132+ (not arg))
129133 (with-current-buffer compilation-buffer
130134 (buffer-substring-no-properties (point-min ) (point-max )))))
131135 (region-text (when (region-active-p )
@@ -139,13 +143,17 @@ Argument ARG is the prefix argument."
139143 (if full-buffer-context
140144 (concat " \n\n Context:\n " full-buffer-context)
141145 (concat
146+ (when clipboard-content
147+ (concat " \n\n Clipboard context (error/exception):\n " clipboard-content))
142148 (when compilation-content
143149 (concat " \n\n Compilation output:\n " compilation-content))
144- (when (and region-text (not compilation-content))
150+ (when (and region-text (not compilation-content) ( not clipboard-content) )
145151 (concat " \n\n Selected code:\n " region-text)))))
146152 (default-question " How to fix the error in this code? Please analyze the error, explain the root cause, and provide the corrected code to resolve the issue: " )
147153 (prompt-label
148154 (cond
155+ (clipboard-content
156+ " Investigate error from clipboard: " )
149157 (compilation-content
150158 " Investigate compilation error: " )
151159 (full-buffer-context
0 commit comments