all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to distinguish character from noncharacter input events?
@ 2004-08-10 14:03 Joe Fineman
  2004-08-10 15:32 ` Stefan Monnier
  2004-08-11  3:25 ` Joakim Hove
  0 siblings, 2 replies; 7+ messages in thread
From: Joe Fineman @ 2004-08-10 14:03 UTC (permalink / raw)


Is there a function that distinguishes character from noncharacter
input events?  It would be nice to be able to write

(let ((next (read-event)))
  (if (char-p next)
      (progn ...)
    (...)))

but I can't find anything of the sort.
-- 
---  Joe Fineman    jcf@TheWorld.com

||:  Money is especially valuable in that it is overvalued.  :||

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

* Re: How to distinguish character from noncharacter input events?
  2004-08-10 14:03 How to distinguish character from noncharacter input events? Joe Fineman
@ 2004-08-10 15:32 ` Stefan Monnier
  2004-08-11 22:09   ` Joe Fineman
  2004-08-11  3:25 ` Joakim Hove
  1 sibling, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2004-08-10 15:32 UTC (permalink / raw)


> Is there a function that distinguishes character from noncharacter
> input events?  It would be nice to be able to write

> (let ((next (read-event)))
>   (if (char-p next)
>       (progn ...)
>     (...)))

> but I can't find anything of the sort.

What for?
What's your definition of a "character event"?

You could try

   (integerp event)

but it will also return non-nil for M-p and C-x.  So you might want to use

   (and (integerp event) (null (event-modifiers event))

but it all depends on what you consider to be a character event, of course.


        Stefan

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

* Re: How to distinguish character from noncharacter input events?
  2004-08-10 14:03 How to distinguish character from noncharacter input events? Joe Fineman
  2004-08-10 15:32 ` Stefan Monnier
@ 2004-08-11  3:25 ` Joakim Hove
  2004-08-11 18:24   ` Ehud Karni
  1 sibling, 1 reply; 7+ messages in thread
From: Joakim Hove @ 2004-08-11  3:25 UTC (permalink / raw)



Joe Fineman <jcf@TheWorld.com> writes:

> Is there a function that distinguishes character from noncharacter
> input events?  It would be nice to be able to write
>
> (let ((next (read-event)))
>   (if (char-p next)
>       (progn ...)
>     (...)))
>

Assuming that by 'character input event' you mean keypresses which
just lead to immediate insertion of the corresponding character, you
might be able to make use of the function (self-insert-command N),
which is run everytime you insert characters in the buffer.

Joakim


-- 
Joakim Hove
hove AT ift uib no
+47 (55 5)8 27 90
http://www.ift.uib.no/~hove/

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

* Re: How to distinguish character from noncharacter input events?
  2004-08-11  3:25 ` Joakim Hove
@ 2004-08-11 18:24   ` Ehud Karni
  0 siblings, 0 replies; 7+ messages in thread
From: Ehud Karni @ 2004-08-11 18:24 UTC (permalink / raw)
  Cc: help-gnu-emacs

On Wed, 11 Aug 2004 05:25:15 +0200, Joakim Hove <hove@ift.uib.no> wrote:
>
> Joe Fineman <jcf@TheWorld.com> writes:
>
> > Is there a function that distinguishes character from noncharacter
> > input events?  It would be nice to be able to write
> >
> > (let ((next (read-event)))
> >   (if (char-p next)
> >       (progn ...)
> >     (...)))

You can use other predicates to distinguish, something like this:

(defun test-event ()
  (interactive)
  (let ((next (read-event "Enter event")))
  ;;   (describe-variable 'next)           ;; for debug
       (if (listp next)
           (message "Real event (mouse)")
           (if (numberp next)
               (message "Real char read")
               (message "Key press (non char) read")))))

Ehud.


--
 Ehud Karni           Tel: +972-3-7966-561  /"\
 Mivtach - Simon      Fax: +972-3-7966-667  \ /  ASCII Ribbon Campaign
 Insurance agencies   (USA) voice mail and   X   Against   HTML   Mail
 http://www.mvs.co.il  FAX:  1-815-5509341  / \
 GnuPG: 98EA398D <http://www.keyserver.net/>    Better Safe Than Sorry

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

* Re: How to distinguish character from noncharacter input events?
  2004-08-10 15:32 ` Stefan Monnier
@ 2004-08-11 22:09   ` Joe Fineman
  2004-08-11 23:53     ` Kevin Rodgers
  2004-08-12 12:05     ` Kai Grossjohann
  0 siblings, 2 replies; 7+ messages in thread
From: Joe Fineman @ 2004-08-11 22:09 UTC (permalink / raw)


Stefan Monnier <monnier@iro.umontreal.ca> writes:

> What's your definition of a "character event"?

As a practical matter, it means an event that will not give the error
message "non-character input event" when read-char encounters it.

> You could try

Thank you for the hints.
-- 
---  Joe Fineman    jcf@TheWorld.com

||:  Bless you, you will be blameless yet,  :||
||:  For God forgives, and men forget.      :||

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

* Re: How to distinguish character from noncharacter input events?
  2004-08-11 22:09   ` Joe Fineman
@ 2004-08-11 23:53     ` Kevin Rodgers
  2004-08-12 12:05     ` Kai Grossjohann
  1 sibling, 0 replies; 7+ messages in thread
From: Kevin Rodgers @ 2004-08-11 23:53 UTC (permalink / raw)


Joe Fineman wrote:
 > Stefan Monnier <monnier@iro.umontreal.ca> writes:
 >>What's your definition of a "character event"?
 >
 > As a practical matter, it means an event that will not give the error
 > message "non-character input event" when read-char encounters it.

You could implement the same check as read-char:

(defun character-event-p (event)
   "Return non-nil if EVENT is a character event."
   ;; see Fread_char:
   (if (symbolp event)
       (let* ((mask (get event 'event-symbol-element-mask))
              (char (if mask
                        (get (car mask) 'ascii-character))))
         (if char
             (setq event (logior char (car (cdr mask)))))))
   (integerp event))

-- 
Kevin Rodgers

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

* Re: How to distinguish character from noncharacter input events?
  2004-08-11 22:09   ` Joe Fineman
  2004-08-11 23:53     ` Kevin Rodgers
@ 2004-08-12 12:05     ` Kai Grossjohann
  1 sibling, 0 replies; 7+ messages in thread
From: Kai Grossjohann @ 2004-08-12 12:05 UTC (permalink / raw)


Joe Fineman <jcf@TheWorld.com> writes:

> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
>> What's your definition of a "character event"?
>
> As a practical matter, it means an event that will not give the error
> message "non-character input event" when read-char encounters it.

Use condition-case, call read-char and catch the error.  That will
tell you whether read-char gives the error message.

Kai

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

end of thread, other threads:[~2004-08-12 12:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-08-10 14:03 How to distinguish character from noncharacter input events? Joe Fineman
2004-08-10 15:32 ` Stefan Monnier
2004-08-11 22:09   ` Joe Fineman
2004-08-11 23:53     ` Kevin Rodgers
2004-08-12 12:05     ` Kai Grossjohann
2004-08-11  3:25 ` Joakim Hove
2004-08-11 18:24   ` Ehud Karni

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.