Skip to content

Strip source-buffer properties from grabbed region context#696

Merged
xenodium merged 2 commits into
xenodium:mainfrom
liaowang11:strip-source-buffer-props
Jul 4, 2026
Merged

Strip source-buffer properties from grabbed region context#696
xenodium merged 2 commits into
xenodium:mainfrom
liaowang11:strip-source-buffer-props

Conversation

@liaowang11

Copy link
Copy Markdown
Contributor

agent-shell--get-region-context built its single-line file-link preview with buffer-substring, and agent-shell--get-numbered-region built its numbered preview the same way. buffer-substring copies all text properties, so when the source buffer was a markdown-mode or poly-markdown buffer, markdown-mode's font-lock leaked into the grabbed context: the emphasis markup characters carried 'invisible markdown-markup' + 'markdown-markup-face' and the enclosed text carried italic faces. _hello_world_ then showed up in the compose buffer as helloworld (underscores hidden, inner text italic) — the same intraword-underscore symptom the response renderer was already fixed to avoid.

Use buffer-substring-no-properties for both preview paths so the context carries plain text and no foreign-mode styling.

Checklist

  • I agree to communicate (PR description and comments) with the author myself (not AI-generated).
  • I've reviewed all code in PR myself and will vouch for its quality.
  • I've read and followed the Contributing guidelines.
  • I've filed a feature request/discussion for a new feature.
  • I'm making visual changes, so I'm including screenshots so you can view and discuss.
  • I've added tests where applicable.
  • I've updated documentation where necessary.
  • I've run M-x checkdoc and M-x byte-compile-file.

agent-shell--get-region-context built its single-line file-link
preview with buffer-substring, and agent-shell--get-numbered-region
built its numbered preview the same way.  buffer-substring copies
all text properties, so when the source buffer was a markdown-mode
or poly-markdown buffer, markdown-mode's font-lock leaked into the
grabbed context: the emphasis markup characters carried
'invisible markdown-markup' + 'markdown-markup-face' and the
enclosed text carried italic faces.  _hello_world_ then showed up
in the compose buffer as helloworld (underscores hidden, inner
text italic) - the same intraword-underscore symptom the response
renderer was already fixed to avoid.

Use buffer-substring-no-properties for both preview paths so the
context carries plain text and no foreign-mode styling.
@xenodium

xenodium commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Thanks for the PR!

Wouldn't we want to at least keep face and 'font-lock-face? Often gives us syntax highlighting for free.

@liaowang11

Copy link
Copy Markdown
Contributor Author

Thanks for the PR!

Wouldn't we want to at least keep face and 'font-lock-face? Often gives us syntax highlighting for free.

Yes, it's a good idea to keep some faces, I added a custom buffer-substring function to keep both.

@xenodium xenodium left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for the PR and follow-up changes.

@xenodium xenodium merged commit 68e7be4 into xenodium:main Jul 4, 2026
2 checks 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.

2 participants