GNU bug report logs -
#8897
`completion--insert-strings' clobbers user-added text properties
Previous Next
Reported by: Štěpán Němec <stepnem <at> gmail.com>
Date: Sun, 19 Jun 2011 18:28:02 UTC
Severity: normal
Tags: fixed
Fixed in version 28.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 8897 in the body.
You can then email your comments to 8897 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
:
bug#8897
; Package
emacs
.
(Sun, 19 Jun 2011 18:28:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Štěpán Němec <stepnem <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Sun, 19 Jun 2011 18:28:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Tags: patch
It is possible to bind `completion-annotate-function' to add custom
annotations, which is great. Unfortunately, the `face' and `mouse-face'
text properties added by such a function are then unconditionally
overwritten by `completion--insert-strings'.
In my particular case I define annotations as buttons (which display
even more detail about a completion value upon activation), so a visual
indication of clickability is very important for me.
I wonder if something like the patch below, which fixes the problem for
me, could be applied?
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 284cbdc..11534e6 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -1003,9 +1003,12 @@ (defun completion--insert-strings (strings)
'mouse-face 'highlight)
(put-text-property (point) (progn (insert (car str)) (point))
'mouse-face 'highlight)
- (add-text-properties (point) (progn (insert (cadr str)) (point))
- '(mouse-face nil
- face completions-annotations)))
+ (let ((annotation (cadr str)))
+ (if (text-properties-at 1 annotation)
+ (insert annotation)
+ (add-text-properties (point) (progn (insert annotation) (point))
+ '(mouse-face nil
+ face completions-annotations)))))
(cond
((eq completions-format 'vertical)
;; Vertical format
Information forwarded
to
owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
:
bug#8897
; Package
emacs
.
(Sun, 19 Jun 2011 18:35:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 8897 <at> debbugs.gnu.org (full text, mbox):
> I wonder if something like the patch below, which fixes the problem for
> me, could be applied?
We cannot apply any (more) patches from you because you don't want to
complete a copyright assignment. That's your prerogative of course, but
given that, it is best if you do not send patches when you report issues.
Information forwarded
to
owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
:
bug#8897
; Package
emacs
.
(Mon, 20 Jun 2011 03:10:03 GMT)
Full text and
rfc822 format available.
Message #11 received at 8897 <at> debbugs.gnu.org (full text, mbox):
> In my particular case I define annotations as buttons (which display
> even more detail about a completion value upon activation), so a visual
> indication of clickability is very important for me.
Currently, the completion-list-mode uses the `mouse-face' text-property
to determine what is a completion item and what i something else (blank
space, annotation, you name it). So as it stands, any mouse-face you'd
add to an annotation would confuse completion-list-mode into thinking it
is a completion item.
Maybe you could try to use the `category' text-property instead.
Stefan
Information forwarded
to
owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
:
bug#8897
; Package
emacs
.
(Mon, 20 Jun 2011 08:12:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 8897 <at> debbugs.gnu.org (full text, mbox):
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
>> In my particular case I define annotations as buttons (which display
>> even more detail about a completion value upon activation), so a visual
>> indication of clickability is very important for me.
>
> Currently, the completion-list-mode uses the `mouse-face' text-property
> to determine what is a completion item and what i something else (blank
> space, annotation, you name it). So as it stands, any mouse-face you'd
> add to an annotation would confuse completion-list-mode into thinking it
> is a completion item.
>
> Maybe you could try to use the `category' text-property instead.
Well I do use the `category' property, but the button functions seem to
set up the button face automatically, which is then clobbered by
`completion--insert-strings' (which is the problem). Here's how I set up
an annotation, `n' being the number of a pull request as a string (i.e.,
the completion value itself):
#+begin_src elisp
(let ((req (assoc-default n minibuffer-completion-table)))
(concat " "
(propertize (plist-get req :title)
'fontified t
'button '(t)
'category 'default-button
'help-echo "RET or mouse-2 for details"
'pr-data req
'action (lambda (b) (magithub-pull-request-details
(button-get b 'pr-data))))))
#+end_src
With my patch I haven't noticed any problems you mention -- clicking
or RET on the completion itself selects it, clicking or RET on the
annotation displays further details, the button face is preserved.
Štěpán
Information forwarded
to
owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
:
bug#8897
; Package
emacs
.
(Mon, 20 Jun 2011 14:02:01 GMT)
Full text and
rfc822 format available.
Message #17 received at 8897 <at> debbugs.gnu.org (full text, mbox):
>>> In my particular case I define annotations as buttons (which display
>>> even more detail about a completion value upon activation), so a visual
>>> indication of clickability is very important for me.
>> Currently, the completion-list-mode uses the `mouse-face' text-property
>> to determine what is a completion item and what i something else (blank
>> space, annotation, you name it). So as it stands, any mouse-face you'd
>> add to an annotation would confuse completion-list-mode into thinking it
>> is a completion item.
>> Maybe you could try to use the `category' text-property instead.
> Well I do use the `category' property, but the button functions seem to
> set up the button face automatically, which is then clobbered by
> `completion--insert-strings' (which is the problem). Here's how I set up
> an annotation, `n' being the number of a pull request as a string (i.e.,
> the completion value itself):
> #+begin_src elisp
> (let ((req (assoc-default n minibuffer-completion-table)))
> (concat " "
> (propertize (plist-get req :title)
> 'fontified t
> 'button '(t)
> 'category 'default-button
> 'help-echo "RET or mouse-2 for details"
> 'pr-data req
> 'action (lambda (b) (magithub-pull-request-details
> (button-get b 'pr-data))))))
> #+end_src
I must be missing something: where is a `face' or `mouse-face' property
added? The above code should not be affected by your patch, AFAICT.
And I don't understand your comment about "but the button functions seem
to set up the button face automatically" since I don't see where you
call a button function before insertion.
> With my patch I haven't noticed any problems you mention -- clicking
> or RET on the completion itself selects it, clicking or RET on the
> annotation displays further details, the button face is preserved.
I guess click&RET work OK because they're locally overridden, but if you
run M-x choose-completion while on the button or if you hit `left' or
`right' to skip from one completion to the next, you might see some
problem (although not with the code quoted above which should not
suffer from any of the problems discussed in this thread, AFAICT).
Stefan
Information forwarded
to
owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
:
bug#8897
; Package
emacs
.
(Mon, 20 Jun 2011 14:27:01 GMT)
Full text and
rfc822 format available.
Message #20 received at 8897 <at> debbugs.gnu.org (full text, mbox):
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
>> #+begin_src elisp
>> (let ((req (assoc-default n minibuffer-completion-table)))
>> (concat " "
>> (propertize (plist-get req :title)
>> 'fontified t
>> 'button '(t)
>> 'category 'default-button
>> 'help-echo "RET or mouse-2 for details"
>> 'pr-data req
>> 'action (lambda (b) (magithub-pull-request-details
>> (button-get b 'pr-data))))))
>> #+end_src
>
> I must be missing something: where is a `face' or `mouse-face' property
> added? The above code should not be affected by your patch, AFAICT.
> And I don't understand your comment about "but the button functions seem
> to set up the button face automatically" since I don't see where you
> call a button function before insertion.
Sorry for my confusing description. What I meant is that there is
apparently some magic involved that makes a string manufactured with a
`propertize' form like the one above appear as if it had the button face
(underlined), even though it's not explicitely among its text properties
(maybe the `category' does it? I don't know).
In any case, without my patch the face is overridden to become the usual
annotation italic, so it _does_ suffer from the problem I describe.
>> With my patch I haven't noticed any problems you mention -- clicking
>> or RET on the completion itself selects it, clicking or RET on the
>> annotation displays further details, the button face is preserved.
>
> I guess click&RET work OK because they're locally overridden, but if you
> run M-x choose-completion while on the button or if you hit `left' or
> `right' to skip from one completion to the next, you might see some
> problem (although not with the code quoted above which should not
> suffer from any of the problems discussed in this thread, AFAICT).
Indeed. I don't use the cursor keys, but you're right in that they seem
to include the button-like annotations among their jump targets; as for
`choose-completion', that seems to be bound to RET in the *Completions*
buffer, but as I said and in line with your guess, pressing RET on an
annotation actually invokes the button action as desired, so this
problem doesn't seem to occur.
Štěpán
Information forwarded
to
owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
:
bug#8897
; Package
emacs
.
(Mon, 20 Jun 2011 16:37:01 GMT)
Full text and
rfc822 format available.
Message #23 received at 8897 <at> debbugs.gnu.org (full text, mbox):
>>> #+begin_src elisp
>>> (let ((req (assoc-default n minibuffer-completion-table)))
>>> (concat " "
>>> (propertize (plist-get req :title)
>>> 'fontified t
>>> 'button '(t)
>>> 'category 'default-button
>>> 'help-echo "RET or mouse-2 for details"
>>> 'pr-data req
>>> 'action (lambda (b) (magithub-pull-request-details
>>> (button-get b 'pr-data))))))
>>> #+end_src
>>
>> I must be missing something: where is a `face' or `mouse-face' property
>> added? The above code should not be affected by your patch, AFAICT.
>> And I don't understand your comment about "but the button functions seem
>> to set up the button face automatically" since I don't see where you
>> call a button function before insertion.
> Sorry for my confusing description. What I meant is that there is
> apparently some magic involved that makes a string manufactured with a
> `propertize' form like the one above appear as if it had the button face
> (underlined), even though it's not explicitely among its text properties
> (maybe the `category' does it? I don't know).
Yes, the `category' property is special and is "equivalent" to adding
all the properties on the symbol used for the category (i.e. all the
properties on the `default-button' symbol in your above example), which
most likely includes `face' and/or `mouse-face' properties.
> In any case, without my patch the face is overridden to become the usual
> annotation italic, so it _does_ suffer from the problem I describe.
Right, the `face' text-property takes precedence over the `face'
property provided by the `category' text property. Hmm...
> Indeed. I don't use the cursor keys, but you're right in that they seem
> to include the button-like annotations among their jump targets; as for
> `choose-completion', that seems to be bound to RET in the *Completions*
> buffer, but as I said and in line with your guess, pressing RET on an
> annotation actually invokes the button action as desired, so this
> problem doesn't seem to occur.
Yes, when point is on the button, RET (and mouse clicks) does not call
choose-completion but the button command instead. But if you have bound
choose-completion to some other keys that are not overridden by the
button, you'll see the problem (or if you do M-x choose-completion).
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#8897
; Package
emacs
.
(Mon, 14 Sep 2020 12:26:01 GMT)
Full text and
rfc822 format available.
Message #26 received at 8897 <at> debbugs.gnu.org (full text, mbox):
Štěpán Němec <stepnem <at> gmail.com> writes:
> It is possible to bind `completion-annotate-function' to add custom
> annotations, which is great. Unfortunately, the `face' and `mouse-face'
> text properties added by such a function are then unconditionally
> overwritten by `completion--insert-strings'.
>
> In my particular case I define annotations as buttons (which display
> even more detail about a completion value upon activation), so a visual
> indication of clickability is very important for me.
>
> I wonder if something like the patch below, which fixes the problem for
> me, could be applied?
In conjunction with bug#43218, completion no longer clobbers all text
properties (but it does clobber the face text property). So it still
requires some wrangling by the caller if the text property was the one
they wanted to have preserved, but the caller can stash that in a
different text property.
This requires that `minibuffer-allow-text-properties' is non-nil.
So I think that basically takes care of the problem described here, and
I'm closing this bug report.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Added tag(s) fixed.
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Mon, 14 Sep 2020 12:26:02 GMT)
Full text and
rfc822 format available.
bug marked as fixed in version 28.1, send any further explanations to
8897 <at> debbugs.gnu.org and Štěpán Němec <stepnem <at> gmail.com>
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Mon, 14 Sep 2020 12:26:02 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Tue, 13 Oct 2020 11:24:09 GMT)
Full text and
rfc822 format available.
This bug report was last modified 4 years and 270 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.