Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to insert space in minibuffer while in completing-read ?

100 views
Skip to first unread message

Brian Adkins

unread,
Mar 7, 2008, 3:41:26 PM3/7/08
to
I've been using the Emacs timeclock to track my time on various
activities. When I invoke timeclock-in, I'm unable to enter a project
name containing embedded space characters (unless it's already in the
auto complete list by virtue of me manually editing the timelog file
beforehand).

I think I tracked the problem down to the completing-read function
that eventually gets invoked from timeclock-in. I put the following
snippet (from timeclock.el) in the *scratch* buffer and invoked it via
C-M-x

(completing-read "Enter string (default foo): " '("bar" "fuz") nil nil
nil nil "foo")

If I type b <space> the minibuffer will complete to bar, but I can't
then type a space. My temporary work around was to do the following:

(global-set-key (kbd "C-#") (lambda () (interactive) (insert-char ?\s
1)))

and then press C-# instead of <space> while in the minibuffer, and
that works fine :)

I suppose my question is how to unbind the <space> key from the
minibuffer-complete-word command when invoking the timeclock-in
command?

Pascal Bourguignon

unread,
Mar 7, 2008, 4:26:28 PM3/7/08
to
Brian Adkins <lojic...@gmail.com> writes:
> I suppose my question is how to unbind the <space> key from the
> minibuffer-complete-word command when invoking the timeclock-in
> command?

C-q SPC

--
__Pascal Bourguignon__ http://www.informatimago.com/
Litter box not here.
You must have moved it again.
I'll poop in the sink.

Brian Adkins

unread,
Mar 7, 2008, 4:53:25 PM3/7/08
to
On Mar 7, 4:26 pm, Pascal Bourguignon <p...@informatimago.com> wrote:

> Brian Adkins <lojicdot...@gmail.com> writes:
> > I suppose my question is how to unbind the <space> key from the
> > minibuffer-complete-word command when invoking the timeclock-in
> > command?
>
> C-q SPC

Thanks, that's a much simpler work around than mine :)

That would work for most of my timeclock projects (0 to 2 spaces), but
occasionally I just want to enter a longer description on that line,
such as:

Met with John & Joe to discuss the authentication scheme

so, it would also be nice to get my space bar back from the over
zealous auto completer. I can M-x timeclock-visit-timelog and edit the
line manually, but it would be nicer to just enter it in the
minibuffer.

Another way to put this would be to say I'd like it to work like C-x C-
f where TAB will autocomplete, but SPC is just a SPC. Of course maybe
that's changed with v23 - I do recall some folks complaining about
losing their SPC autocomplete in find file - basically the opposite of
my problem.

Drew Adams

unread,
Mar 7, 2008, 5:09:37 PM3/7/08
to Pascal Bourguignon, help-gn...@gnu.org
> > I suppose my question is how to unbind the <space> key from the
> > minibuffer-complete-word command when invoking the timeclock-in
> > command?
>
> C-q SPC

Sure, you can quote each space character with `C-q'. Or you can fix Emacs to
do what you want all the time.

Emacs users should be able to type space chars in minibuffer input. Period.
Emacs 22 finally allows that for file-name input, but it should be available
for all minibuffer input. Input completion is not limited to command names.

Solutions:

1. Use Icicles: http://www.emacswiki.org/cgi-bin/wiki/Icicles.

2. If you don't want to use Icicles, but you do want to allow space chars in
minibuffer input, do this:

(define-key minibuffer-local-completion-map
" " 'self-insert-command))
(define-key minibuffer-local-must-match-map
" " 'self-insert-command))

Emacs 22 adds the keymaps `minibuffer-local-filename-completion-map' and
`minibuffer-local-must-match-filename-map', but space should already DTRT
there.


You might also want to do the same thing for the `?' character, in the same
maps: (define-key MAP "?" 'self-insert-command), where MAP is as above (plus
the two filename completion maps if you use Emacs 22 or later).

In Icicles, BTW, it is `C-?', not `?', that displays help. Printable
characters like `?' should not need to be quoted to input them.

You might also want to do the same thing for "\n", the newline character.
Icicles does that so you can have multi-line input without resorting to `C-q
C-j' for each newline char.

HTH.

Brian Adkins

unread,
Mar 7, 2008, 6:34:24 PM3/7/08
to

Definitely helps - exactly what I was looking for. Thx.

Stefan Monnier

unread,
Mar 8, 2008, 4:24:18 PM3/8/08
to
> 2. If you don't want to use Icicles, but you do want to allow space chars in
> minibuffer input, do this:

> (define-key minibuffer-local-completion-map
> " " 'self-insert-command))
> (define-key minibuffer-local-must-match-map
> " " 'self-insert-command))

I think you mean to set those keys to nil rather than to
`self-insert-command'. It may have the same result in 99% of the cases
in the end, of course.


Stefan

Drew Adams

unread,
Mar 8, 2008, 5:06:48 PM3/8/08
to Stefan Monnier, help-gn...@gnu.org

Right. It's enough to remove the local binding, to restore the global
binding. Either is OK here, but what you suggest is preferable.

0 new messages