3

I need to read a char at a time to interactively build a filter string while I show the results in a regular buffer. And what I've written works, except when a cursor key is pressed - then bang, I get a "non-character input event message" and my code exits.

Here's an example. If I run the following command, and hit one of the arrow keys, I get an error.

(defun foobar ()
  (interactive)
  (setq r (read-char)))

I've tried read-char, read-event and read-char-exclusive with and without ignore-errors. I've tried read-char-choice and logic that looks for the vector result a cursor key would give. Nothing works (although I can handle return and backspace perfectly.)

What do I need to do? I don't need the cursor keys to do anything; I just need to make it safe to press them.

closed as unclear what you're asking by Drew, wasamasa, Kaushal Modi, Andrew Swann, Jordon Biondo May 18 '15 at 14:20

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Can you add a little code snippet that shows this problem? – Kaushal Modi May 17 '15 at 13:04
  • You get the event with something as simple as this if you call it from the mininbuffer and then use a cursor key (sorry, I've backticked code but it still doesn't seem to format properly): (defun foobar() (interactive) (setq r (read-char))) – ump May 17 '15 at 13:26
  • Oh - and this also happens if it I use --load to start emacs with an init file consisting of nothing but that function. So we can eliminate interaction with any extensions. ... Excpet that read-char-exclusive now does work, which it didn't in my full init. Hmm. – ump May 17 '15 at 13:40
  • 2
    1. Show your code (more of it). 2. Say why you are trying to use read-char from the minibuffer. Normally, you do not need the minibuffer if you are using read-char, so please help us understand why you use that combination (e.g. what you are really trying to do). The minibuffer is a buffer. In the general case it allows multiple-char input and editing. read-char pays no attention to what buffer is current, and it reads only one event. – Drew May 17 '15 at 14:06
  • 1
    The question and proposed answer are unclear and misleading, and should be closed. Salvaging them would mean posing a different question altogether, and it sounds like that is anyway unneeded. The OP apparently learned something, but this Q & A doesn't help anyone learn; it just offers confusion. – Drew May 17 '15 at 16:14
3

Ok: the answer really is just to use read-char-exclusive instead of read-char. It works perfectly.
I wasn't working for me because of some problem in my configurations.

  • No, that does not answer the question that you asked, which was about using the minibuffer. And the answer itself is unclear. And this is not the place to add helpful hints about Emacs (e.g., -q) that are irrelevant to the question. The question is unclear and should be closed. – Drew May 17 '15 at 16:12
  • 3
    @Drew No Drew. His question was how to read a character without causing a specific error message. The minibuffer is irrelevant. He talks about the minibuffer for lack of understanding. – Malabarba May 17 '15 at 17:07
  • 1
    @Drew and yes, the question was hard to understand (use the close button if you think it should be closed), but the answer is not wrong. – Malabarba May 17 '15 at 17:09
  • @Malabarba: The question as posed was not answered by this answer. And the Q&A were unclear. They needed to be edited, to be helpful to others. You've done that now - OK. But as I said in another comment, that is tantamount to posing a different question, which I encouraged (and which would have been better, IMO). Otherwise this question, as posed, should have been closed as unclear. As for editing this question radically, as you've done, it would have been more helpful to all if the OP had edited it (or posed a separate question). The OP threw out a lousy question and never looked back. – Drew May 18 '15 at 14:08
  • @Drew Let's continue this in chat. – Malabarba May 18 '15 at 14:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.