all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Lars Ingebrigtsen <larsi@gnus.org>,
	Nicolas Graner <nicolas.graner@universite-paris-saclay.fr>
Cc: 43218@debbugs.gnu.org, Stefan Monnier <monnier@iro.umontreal.ca>
Subject: bug#43218: EWW handles default answer incorrectly when changing a select
Date: Sat, 5 Sep 2020 21:41:00 -0700 (PDT)	[thread overview]
Message-ID: <3f6f1310-09f9-4ae9-99e3-451724ae7185@default> (raw)
In-Reply-To: <878sdn22sf.fsf@gnus.org>

> > Activate the select and change its value to 'two'.
> > Activate it again and answer <RET> to the prompt for value: the
> > displayed value returns to 'one'.
> >
> > This is not critical as this situation is rare and the value sent to the
> > server will be correct anyway, but it is confusing to the user who does
> > not usually know the value of each option.
> 
> That's true...  there's also a general problem with how the values are
> selected: We're doing a completing-read over the display names, and then
> mapping that back to the values.  But this is perfectly valid:
> 
> <select name="a">
> <option value="1">one</option>
> <option value="2">one</option>
> </select>
> 
> But there's no way to select the second value in eww.
> 
> Unfortunately, the Emacs primitives for prompting are very
> text-oriented, and don't allow putting properties on the values we're
> completing over, not even with:
> 
> ---
> minibuffer-allow-text-properties is a variable defined in ‘src/minibuf.c’.
> Its value is nil
> 
>   Probably introduced at or before Emacs version 20.
> 
> Documentation:
> Non-nil means ‘read-from-minibuffer’ should not discard text properties.
> This also affects ‘read-string’, but it does not affect ‘read-minibuffer’,
> ‘read-no-blanks-input’, or any of the functions that do minibuffer input
> with completion; they always discard text properties.
> ---
> 
> I wonder what the logic behind this is?  And I also have a vague feeling
> I've asked this before...
> 
> Perhaps Stefan knows and or remembers.  :-)
> 
> So the test case is:
> 
> (let ((minibuffer-allow-text-properties t))
>   (completing-read "Foo: " (list (propertize "foo" 'data 'bar))
>                    nil 'require-match))
> => "foo"
> 
> instead of #("foo" 0 3 (data bar))

Huge apologies for jumping in here, possibly
missing the point completely, and probably
not providing much that helps operationally.

But I think I know what you're talking about.

If so, first, note this:

(let ((minibuffer-allow-text-properties t))
  (read-from-minibuffer
    "Foo: " nil nil nil nil
    (propertize "foo" 'data 'bar)))

Use `M-n RET'.  The doc tells you that it only
returns a propertized string that was in the
_minibuffer_ when you hit RET.

That's not the case for a chosen
`completing-read' candidate.  As you quoted
from the doc string:

> the functions that do minibuffer input with
> completion ... always discard text properties.

Second, I can speak a bit to how Icicles deals
with this sort of thing.

I tried (more than once) to get vanilla Emacs
to let you use propertized strings as completion
candidates, both (1) for display in *Completions*
and (2) as returned value for `completing-read'.

I see that in the Icicles doc I mention that
in 2007 RMS agreed to fix Emacs to provide #1,
but AFAIK that never happened.

Icicles redefines `display-completion-alist'
so that it does display propertized candidates.

And Icicles redefines `completing-read' so  it
returns a propertized display-candidate string
that you choose.

You can do more.  But already those two simple
additions go a long way.

Wrt the problem I think you raise above, which
is dealing with multiple candidates that have
the same display string but are associated with
different "values" in some sense (the simplest
being the cdr of an alist cons whose car is the
display candidate):

1. When you cycle among candidates or use mouse-2
to choose one, there's the notion of "current
candidate", so Icicles knows which alist element
you choose (not just which display string).

2. If you bind `icicle-whole-cand-as-text-prop-p'
to non-nil then an entire alist element is put
on its car (the display string) as a property, so
when `completing-read' returns that string the
full candidate (the alist element) can be recovered.
This takes care of distinguishing element
("foo" . 42) from element ("foo" 5 4 3).

#2 is just this:

(let ((text-cand  (copy-sequence (car cand))))
  (put-text-property 0 (length text-cand)
                     'icicle-whole-candidate
                     (cdr cand) text-cand)
  (setcar cand text-cand)
  text-cand)

Then:

(and icicle-whole-candidate-as-text-prop-p
     (get-text-property
       0 'icicle-whole-candidate string))

(I use the same "trick" in Bookmark+ to handle
different bookmarks that have the same name.)

Here are two doc pages that discuss this a bit:

https://www.emacswiki.org/emacs/Icicles_-_Programming_with_Fancy_Candidates#fancy_candidates

https://www.emacswiki.org/emacs/Icicles_-_Candidates_with_Text_Properties





      parent reply	other threads:[~2020-09-06  4:41 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-05 10:44 bug#43218: EWW handles default answer incorrectly when changing a select Nicolas Graner
2020-09-05 13:51 ` Lars Ingebrigtsen
2020-09-05 17:18   ` Nicolas Graner
2020-09-05 23:59     ` Lars Ingebrigtsen
2020-09-06  1:55       ` Stefan Monnier
2020-09-06 11:48         ` Lars Ingebrigtsen
2020-09-06 12:29           ` Nicolas Graner
2020-09-06 12:35             ` Lars Ingebrigtsen
2020-09-06 14:40               ` Eli Zaretskii
2020-09-06 14:41                 ` Lars Ingebrigtsen
2020-09-06 14:57                   ` Eli Zaretskii
2020-09-06 17:05                     ` Lars Ingebrigtsen
2020-09-06 17:56                       ` Nicolas Graner
2020-09-06 19:32                         ` Lars Ingebrigtsen
2020-09-06 17:06           ` Drew Adams
2020-09-06 17:12             ` Lars Ingebrigtsen
2020-09-06 17:18               ` Drew Adams
2020-09-06 17:26                 ` Lars Ingebrigtsen
2020-09-06 18:57                   ` Stefan Monnier
2020-09-06 22:49                     ` Lars Ingebrigtsen
2020-09-06 22:56                       ` Lars Ingebrigtsen
2020-09-06  4:41       ` Drew Adams [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3f6f1310-09f9-4ae9-99e3-451724ae7185@default \
    --to=drew.adams@oracle.com \
    --cc=43218@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=nicolas.graner@universite-paris-saclay.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.