Skip to content

C-c a @: copy file + line range only for regions longer than 5 lines - #514

Merged
tninja merged 2 commits into
mainfrom
copilot/fix-c-c-a-at-region-lines
Sep 18, 2026
Merged

tninja merged 2 commits into
mainfrom
copilot/fix-c-c-a-at-region-lines

Conversation

Copilot AI commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

The C-c a @ copy actions always prepended the full selected region text to the context reference, producing unwieldy clipboard content for large selections. Long selections now copy only the file path with line range; the region text is kept for selections of 5 lines or fewer.

Changes

  • ai-code-file.el
    • ai-code-copy-buffer-file-name-to-clipboard: include region text only when the region spans at most ai-code-region-text-max-lines; otherwise copy just the file#Lstart-Lend reference. Applies to both "Copy context" and "Copy context with full path".
    • New defcustom ai-code-region-text-max-lines (default 5) controlling the threshold.
    • "Add context" needed no change — it already stores line-range references only via ai-code--current-file-context-reference.

Behavior

;; Region of 5 lines (unchanged):
;; => "l1\nl2\nl3\nl4\nl5 in /tmp/sample.el#L1-L5"

;; Region of 6 lines (new):
;; => "/tmp/sample.el#L1-L6"
  • test/test_ai-code-file.el: new ERT tests covering the ≤5-line path (text preserved), the >5-line path (line range only), and both copy sub-menu entries via ai-code-context-action.

Co-authored-by: tninja <714625+tninja@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix: Use file and line range for long selected regions C-c a @: copy file + line range only for regions longer than 5 lines Sep 17, 2026
Copilot AI requested a review from tninja September 17, 2026 22:11
@tninja
tninja requested a balanced review from Copilot September 17, 2026 23:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The implementation is focused and tested; only a minor documentation correction remains.

Pull request overview

Adds configurable suppression of large selected-region text in copied context references.

Changes:

  • Introduces a configurable five-line default threshold.
  • Adds ERT coverage for short/long regions and both copy actions.
  • One minor docstring issue was noted.
File summaries
File Description
ai-code-file.el Applies the region-length threshold when copying context.
test/test_ai-code-file.el Tests threshold behavior and context-menu actions.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread ai-code-file.el
Comment on lines +112 to +113
before that context reference, unless the region spans more than 5
lines; then only the file path with line range is copied.
@tninja
tninja marked this pull request as ready for review September 18, 2026 03:44
@tninja
tninja merged commit 2d9b308 into main Sep 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix: For C-c a @, when the selected region is more than 5 lines, just use the file + line range

3 participants