unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* completing-read a list of keywords
@ 2020-04-15 17:30 Daniele Nicolodi
  2020-04-15 17:33 ` Noam Postavsky
  0 siblings, 1 reply; 15+ messages in thread
From: Daniele Nicolodi @ 2020-04-15 17:30 UTC (permalink / raw)
  To: emacs-devel

Hello,

I am trying to come up with a solution to be able to use completing-read
to prompt the user for a comma (or space) separated list of words.
Unfortunately the completion framework is still rather impenetrable to
me. Does anyone have pointers to relevant examples and documentation?

org-mode has something similar for the completion of tags. But I haven't
been able to understand what the code does.

Thank you!

Best,
Dan



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: completing-read a list of keywords
  2020-04-15 17:30 Daniele Nicolodi
@ 2020-04-15 17:33 ` Noam Postavsky
  2020-04-15 18:21   ` Daniele Nicolodi
  0 siblings, 1 reply; 15+ messages in thread
From: Noam Postavsky @ 2020-04-15 17:33 UTC (permalink / raw)
  To: Daniele Nicolodi; +Cc: Emacs developers

On Wed, 15 Apr 2020 at 13:30, Daniele Nicolodi <daniele@grinta.net> wrote:

> I am trying to come up with a solution to be able to use completing-read
> to prompt the user for a comma (or space) separated list of words.
> Unfortunately the completion framework is still rather impenetrable to
> me. Does anyone have pointers to relevant examples and documentation?

I don't think completing-read supports this use-case. You might want
to look at completing-read-multiple.



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: completing-read a list of keywords
  2020-04-15 17:33 ` Noam Postavsky
@ 2020-04-15 18:21   ` Daniele Nicolodi
  2020-04-15 18:26     ` Noam Postavsky
  2020-04-15 18:55     ` Stefan Monnier
  0 siblings, 2 replies; 15+ messages in thread
From: Daniele Nicolodi @ 2020-04-15 18:21 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: Emacs developers

On 15-04-2020 11:33, Noam Postavsky wrote:
> On Wed, 15 Apr 2020 at 13:30, Daniele Nicolodi <daniele@grinta.net> wrote:
> 
>> I am trying to come up with a solution to be able to use completing-read
>> to prompt the user for a comma (or space) separated list of words.
>> Unfortunately the completion framework is still rather impenetrable to
>> me. Does anyone have pointers to relevant examples and documentation?
> 
> I don't think completing-read supports this use-case. You might want
> to look at completing-read-multiple.

Thanks Noam! I didn't know about completing-read-multiple. It comes very
close to do what I want. However, I am unable to make it work for
elements separated by ", " as SPC is mapped to the complete action. Is
there a way to customize this behavior?

Thank you.

Cheers,
Dan



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: completing-read a list of keywords
  2020-04-15 18:21   ` Daniele Nicolodi
@ 2020-04-15 18:26     ` Noam Postavsky
  2020-04-15 18:41       ` Joost Kremers
  2020-04-15 19:13       ` Daniele Nicolodi
  2020-04-15 18:55     ` Stefan Monnier
  1 sibling, 2 replies; 15+ messages in thread
From: Noam Postavsky @ 2020-04-15 18:26 UTC (permalink / raw)
  To: Daniele Nicolodi; +Cc: Emacs developers

On Wed, 15 Apr 2020 at 14:21, Daniele Nicolodi <daniele@grinta.net> wrote:

> Thanks Noam! I didn't know about completing-read-multiple. It comes very
> close to do what I want. However, I am unable to make it work for
> elements separated by ", " as SPC is mapped to the complete action. Is
> there a way to customize this behavior?

(define-key crm-local-completion-map (kbd "SPC") #'self-insert-command)

Seems to do the trick.



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: completing-read a list of keywords
  2020-04-15 18:26     ` Noam Postavsky
@ 2020-04-15 18:41       ` Joost Kremers
  2020-04-15 19:32         ` Daniele Nicolodi
  2020-04-15 19:13       ` Daniele Nicolodi
  1 sibling, 1 reply; 15+ messages in thread
From: Joost Kremers @ 2020-04-15 18:41 UTC (permalink / raw)
  To: emacs-devel


On Wed, Apr 15 2020, Noam Postavsky wrote:
> On Wed, 15 Apr 2020 at 14:21, Daniele Nicolodi 
> <daniele@grinta.net> wrote:
>
>> Thanks Noam! I didn't know about completing-read-multiple. It 
>> comes very
>> close to do what I want. However, I am unable to make it work 
>> for
>> elements separated by ", " as SPC is mapped to the complete 
>> action. Is
>> there a way to customize this behavior?
>
> (define-key crm-local-completion-map (kbd "SPC") 
> #'self-insert-command)

Or if you don't want to stomp on anyone's keybindings:

```
(let ((crm-local-must-match-map (make-composed-keymap '(keymap 
(32)) crm-local-must-match-map)))
  (completing-read-multiple ...)
  ...
  )
```


-- 
Joost Kremers
Life has its moments



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: completing-read a list of keywords
  2020-04-15 18:21   ` Daniele Nicolodi
  2020-04-15 18:26     ` Noam Postavsky
@ 2020-04-15 18:55     ` Stefan Monnier
  2020-04-15 20:15       ` Daniele Nicolodi
  1 sibling, 1 reply; 15+ messages in thread
From: Stefan Monnier @ 2020-04-15 18:55 UTC (permalink / raw)
  To: Daniele Nicolodi; +Cc: Noam Postavsky, Emacs developers

> Thanks Noam! I didn't know about completing-read-multiple. It comes very
> close to do what I want. However, I am unable to make it work for
> elements separated by ", " as SPC is mapped to the complete action.
> Is there a way to customize this behavior?

Not really, no, it's a known limitation.


        Stefan




^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: completing-read a list of keywords
  2020-04-15 18:26     ` Noam Postavsky
  2020-04-15 18:41       ` Joost Kremers
@ 2020-04-15 19:13       ` Daniele Nicolodi
  1 sibling, 0 replies; 15+ messages in thread
From: Daniele Nicolodi @ 2020-04-15 19:13 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: Emacs developers

On 15-04-2020 12:26, Noam Postavsky wrote:
> On Wed, 15 Apr 2020 at 14:21, Daniele Nicolodi <daniele@grinta.net> wrote:
> 
>> Thanks Noam! I didn't know about completing-read-multiple. It comes very
>> close to do what I want. However, I am unable to make it work for
>> elements separated by ", " as SPC is mapped to the complete action. Is
>> there a way to customize this behavior?
> 
> (define-key crm-local-completion-map (kbd "SPC") #'self-insert-command)
> 
> Seems to do the trick.

I will continue to display crass ignorance: wouldn't that change the
keymap for all commands that uses completing-read-multiple and not only
for the one I am implementing?  Is there a convenient way to modify the
keymap only around my invocation of completing-read-multiple?

/me goes to read some documentation

Thank you!

Cheers,
Dan



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: completing-read a list of keywords
  2020-04-15 18:41       ` Joost Kremers
@ 2020-04-15 19:32         ` Daniele Nicolodi
  2020-04-15 22:13           ` Daniele Nicolodi
  0 siblings, 1 reply; 15+ messages in thread
From: Daniele Nicolodi @ 2020-04-15 19:32 UTC (permalink / raw)
  To: emacs-devel

On 15-04-2020 12:41, Joost Kremers wrote:
> 
> On Wed, Apr 15 2020, Noam Postavsky wrote:
>> On Wed, 15 Apr 2020 at 14:21, Daniele Nicolodi <daniele@grinta.net>
>> wrote:
>>
>>> Thanks Noam! I didn't know about completing-read-multiple. It comes very
>>> close to do what I want. However, I am unable to make it work for
>>> elements separated by ", " as SPC is mapped to the complete action. Is
>>> there a way to customize this behavior?
>>
>> (define-key crm-local-completion-map (kbd "SPC") #'self-insert-command)
> 
> Or if you don't want to stomp on anyone's keybindings:
> 
> ```
> (let ((crm-local-must-match-map (make-composed-keymap '(keymap (32))
> crm-local-must-match-map)))
>  (completing-read-multiple ...)
>  ...
>  )
> ```

Thanks!  Wouldn't it make sense to have a with-define-key macro to
effectively do the same?

Cheers,
Dan



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: completing-read a list of keywords
  2020-04-15 18:55     ` Stefan Monnier
@ 2020-04-15 20:15       ` Daniele Nicolodi
  2020-04-15 22:42         ` Stefan Monnier
  0 siblings, 1 reply; 15+ messages in thread
From: Daniele Nicolodi @ 2020-04-15 20:15 UTC (permalink / raw)
  To: emacs-devel

On 15-04-2020 12:55, Stefan Monnier wrote:
>> Thanks Noam! I didn't know about completing-read-multiple. It comes very
>> close to do what I want. However, I am unable to make it work for
>> elements separated by ", " as SPC is mapped to the complete action.
>> Is there a way to customize this behavior?
> 
> Not really, no, it's a known limitation.

What do you think of the proposed temporary keymap modification
solution? It seems that it solved the problem nicely, doesn't it?

Thank you.

Best,
Dan



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: completing-read a list of keywords
@ 2020-04-15 22:06 Roland Winkler
  2020-04-15 22:44 ` Stefan Monnier
  0 siblings, 1 reply; 15+ messages in thread
From: Roland Winkler @ 2020-04-15 22:06 UTC (permalink / raw)
  To: monnier; +Cc: daniele, emacs-devel

> > However, I am unable to make it work for elements separated by
> > ", " as SPC is mapped to the complete action.  Is there a way
> > to customize this behavior?
> 
> Not really, no, it's a known limitation.

SPC is mapped to crm-complete-word, which is not always needed with
crm (depending on your needs).

BBDB defines a bbdb-crm-local-completion-map that makes SPC
self-inserting.  Then it binds crm-local-completion-map to
bbdb-crm-local-completion-map.

Stefan, I believe you suggested this to me when you helped me a few
years ago to extend crm to handle regexps as crm-separator.



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: completing-read a list of keywords
  2020-04-15 19:32         ` Daniele Nicolodi
@ 2020-04-15 22:13           ` Daniele Nicolodi
  0 siblings, 0 replies; 15+ messages in thread
From: Daniele Nicolodi @ 2020-04-15 22:13 UTC (permalink / raw)
  To: emacs-devel

On 15-04-2020 13:32, Daniele Nicolodi wrote:
> On 15-04-2020 12:41, Joost Kremers wrote:
>>
>> On Wed, Apr 15 2020, Noam Postavsky wrote:
>>> On Wed, 15 Apr 2020 at 14:21, Daniele Nicolodi <daniele@grinta.net>
>>> wrote:
>>>
>>>> Thanks Noam! I didn't know about completing-read-multiple. It comes very
>>>> close to do what I want. However, I am unable to make it work for
>>>> elements separated by ", " as SPC is mapped to the complete action. Is
>>>> there a way to customize this behavior?
>>>
>>> (define-key crm-local-completion-map (kbd "SPC") #'self-insert-command)
>>
>> Or if you don't want to stomp on anyone's keybindings:
>>
>> ```
>> (let ((crm-local-must-match-map (make-composed-keymap '(keymap (32))
>> crm-local-must-match-map)))
>>  (completing-read-multiple ...)
>>  ...
>>  )
>> ```
> 
> Thanks!  Wouldn't it make sense to have a with-define-key macro to
> effectively do the same?

For whom may be interested, this macro may look like:

(defmacro with-define-key (keymap key def &rest body)
  (declare (indent 3) (debug t))
  `(let ((map (make-sparse-keymap)))
     (define-key map ,key ,def)
     (let ((,keymap (make-composed-keymap map ,keymap)))
       (progn ,@body))))

It requires a bit of contortions to get it accept a syntax equivalent to
define-key.

Cheers,
Dan



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: completing-read a list of keywords
  2020-04-15 20:15       ` Daniele Nicolodi
@ 2020-04-15 22:42         ` Stefan Monnier
  0 siblings, 0 replies; 15+ messages in thread
From: Stefan Monnier @ 2020-04-15 22:42 UTC (permalink / raw)
  To: Daniele Nicolodi; +Cc: emacs-devel

>>> Thanks Noam! I didn't know about completing-read-multiple. It comes very
>>> close to do what I want. However, I am unable to make it work for
>>> elements separated by ", " as SPC is mapped to the complete action.
>>> Is there a way to customize this behavior?
>> Not really, no, it's a known limitation.
> What do you think of the proposed temporary keymap modification
> solution? It seems that it solved the problem nicely, doesn't it?

I'm surprised to hear that it works.  IIRC the code will try to
complete " b" rather than "b" if you type `a , SPC b TAB`, so unless
your completion table is happy with spurious leading spaces I think you
won't like the result.

But maybe it's been improved.  This is based on a vague recollection
from many years ago.


        Stefan




^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: completing-read a list of keywords
  2020-04-15 22:06 completing-read a list of keywords Roland Winkler
@ 2020-04-15 22:44 ` Stefan Monnier
  2020-04-18 22:07   ` Roland Winkler
  0 siblings, 1 reply; 15+ messages in thread
From: Stefan Monnier @ 2020-04-15 22:44 UTC (permalink / raw)
  To: Roland Winkler; +Cc: daniele, emacs-devel

> Stefan, I believe you suggested this to me when you helped me a few
> years ago to extend crm to handle regexps as crm-separator.

Ah, so your patch fixed the problem I was thinking of?
If so, we should likely change the SPC binding there: I think it's more
often harmful than useful in this context.


        Stefan




^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: completing-read a list of keywords
  2020-04-15 22:44 ` Stefan Monnier
@ 2020-04-18 22:07   ` Roland Winkler
  2020-04-19  2:30     ` Stefan Monnier
  0 siblings, 1 reply; 15+ messages in thread
From: Roland Winkler @ 2020-04-18 22:07 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: daniele, emacs-devel

On Wed Apr 15 2020 Stefan Monnier wrote:
> > Stefan, I believe you suggested this to me when you helped me a few
> > years ago to extend crm to handle regexps as crm-separator.
> 
> Ah, so your patch fixed the problem I was thinking of?  If so, we
> should likely change the SPC binding there: I think it's more
> often harmful than useful in this context.

Hi Stefan,

Yes and no!  ...I had to referesh my memories about this:

Originally, completing-read-multiple only supported a
single-character string for crm-separator which defaulted to ",".
I guess back then SPC was rarely used as self-inserting character
with completing-read-multiple and it was OK that
crm-local-completion-map bound SPC to crm-complete-word.

For BBDB, I didn't like that crm-separator was restricted to a
single character, and you helped me so that now crm-separator can be
any regexp with new default  "[ \t]*,[ \t]*".

But like the OP, I was rather annoyed that crm-local-completion-map
binds SPC to crm-complete-word.  You suggested to me that BBDB could
define its own keymap for completing-read-multiple that makes SPC
self-inserting.  To the best of my knowledge, this has worked well
for BBDB.  I am not aware of complaints from BBDB users that missed
a keybinding for crm-complete-word.

But today I do not understand anymore: how was the new default for
crm-separator ever supposed to work elsewhere?  I tried to define
some simple test cases and quickly I got very annoyed by
crm-complete-word that interferes with an intuitive usage of
completing-read-multiple.

So I suggest: we change crm-local-completion-map such that it makes
SPC self-inserting.  This may represent a minor inconsistency
compared with other completion commands.  But in my opinion, this
inconsistency is justified by the very purpose of
completing-read-multiple.  (Personally, I wouldn't mind if there was
simply no default keybinding for crm-complete-word, as it is now the
case inside BBDB.  Otherwise, maybe we can come up with a "more
exotic" keybinding for it.)

Or am I missing something else?



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: completing-read a list of keywords
  2020-04-18 22:07   ` Roland Winkler
@ 2020-04-19  2:30     ` Stefan Monnier
  0 siblings, 0 replies; 15+ messages in thread
From: Stefan Monnier @ 2020-04-19  2:30 UTC (permalink / raw)
  To: Roland Winkler; +Cc: daniele, emacs-devel

>> should likely change the SPC binding there: I think it's more
>> often harmful than useful in this context.
[...]
> So I suggest: we change crm-local-completion-map such that it makes
> SPC self-inserting.

Exactly!

If we want to be more conservative, we could make it self-inserting only
when `crm-separator` can match a string with a space, but I don't see
any strong reason to justify the complexity.


        Stefan




^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2020-04-19  2:30 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-15 22:06 completing-read a list of keywords Roland Winkler
2020-04-15 22:44 ` Stefan Monnier
2020-04-18 22:07   ` Roland Winkler
2020-04-19  2:30     ` Stefan Monnier
  -- strict thread matches above, loose matches on Subject: below --
2020-04-15 17:30 Daniele Nicolodi
2020-04-15 17:33 ` Noam Postavsky
2020-04-15 18:21   ` Daniele Nicolodi
2020-04-15 18:26     ` Noam Postavsky
2020-04-15 18:41       ` Joost Kremers
2020-04-15 19:32         ` Daniele Nicolodi
2020-04-15 22:13           ` Daniele Nicolodi
2020-04-15 19:13       ` Daniele Nicolodi
2020-04-15 18:55     ` Stefan Monnier
2020-04-15 20:15       ` Daniele Nicolodi
2020-04-15 22:42         ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).