Skip to content

Conversation

@Bad-ptr
Copy link
Contributor

@Bad-ptr Bad-ptr commented Aug 31, 2025

Standard Emacs' functions like read-from-minibuffer supports propertized prompts.
But ivy overrides text properties of prompt here:

swiper/ivy.el

Line 3266 in 2257a9d

(set-text-properties 0 (length n-str)

This pull request is the fix.

Copy link
Collaborator

@basil-conto basil-conto left a comment

Choose a reason for hiding this comment

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

Thank you for the pull request! And sorry for the long delay.

Comment on lines -3266 to 3275
(set-text-properties 0 (length n-str)
`(face minibuffer-prompt ,@std-props)
n-str)
(let ((old-props (when (fboundp 'object-intervals)
(object-intervals n-str))))
(set-text-properties 0 (length n-str)
`(face minibuffer-prompt ,@std-props)
n-str)
(dolist (propdata old-props)
(cl-destructuring-bind (beg end props) propdata
(add-text-properties beg end props n-str))))
(setq n-str (funcall ivy-set-prompt-text-properties-function
n-str std-props))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Right after the set-text-properties call, there is a call to the variable ivy-set-prompt-text-properties-function, which is allowed to modify the prompt in-place.

Can you please describe in more detail what use-case you are considering, that can't already be addressed via ivy-set-prompt-text-properties-function?

In general, I would prefer to avoid relying on object-intervals, or needing to copy each interval over manually. At least, not by default, and not if we can think of another solution.

For example, set-text-properties could be replaced with add-text-properties. Or, std-props could be turned into a variable that can be bound around relevant calls to Ivy. But I would like to better understand the motivation before making such changes.

@basil-conto basil-conto self-assigned this Nov 22, 2025
@basil-conto basil-conto added the enhancement Suggestion to improve or extend existing behavior label Nov 22, 2025
basil-conto added a commit that referenced this pull request Nov 22, 2025
ivy--insert-prompt seems to emulate some of read-from-minibuffer's
text property logic, but hasn't been doing so correctly w.r.t
minibuffer-prompt-properties and in particular the face property.

This change allows users to affect the entire prompt via m-p-p, or
just the prompt text itself by passing, e.g., a propertized string
to ivy-read.  It should support multiple faces too.

* ivy.el (ivy--insert-prompt): Break text property logic out...
(ivy--propertize-prompt): ...to this new function.  Use
add-text-properties and add-face-text-property in place of
set-text-properties (#3077).  Heed minibuffer-prompt-properties.
@basil-conto
Copy link
Collaborator

In commit 4b1df7c I generalised the current code to use minibuffer-prompt-properties, add-text-properties, and add-face-text-property like read-from-minibuffer does.

This doesn't preserve all text properties, but it does preserve the same text properties as read-from-minibuffer.

Does that address your use-case, or is a new mechanism still needed? Thanks.

@basil-conto basil-conto added the moreinfo Waiting for author to provide more information label Nov 22, 2025
@basil-conto

This comment was marked as resolved.

basil-conto added a commit that referenced this pull request Nov 23, 2025
This continues from the previous commit of 2025-11-22
"Don't completely replace prompt text properties".

* ivy.el (ivy-set-prompt-text-properties-default): Retain existing
faces by using add-face-text-property (#3077).
@Bad-ptr
Copy link
Contributor Author

Bad-ptr commented Nov 23, 2025

I tested new version and it works. So this PR could be closed.
My use case was just to read from minibuffer with propertized prompt, like:

(read-buffer (format-prompt "select buffer (\\`C-t' to toggle filtering)" nil))

To suggest a non standard key binding to user.

@basil-conto
Copy link
Collaborator

I tested new version and it works. So this PR could be closed. My use case was just to read from minibuffer with propertized prompt, like:

Great, thank you for confirming, and once again for your patience.

@basil-conto basil-conto removed the moreinfo Waiting for author to provide more information label Nov 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Suggestion to improve or extend existing behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants