last-input-event and X/non-X
  Home FAQ Contact Sign in
gnu.emacs.help only
 
Advanced search
POPULAR GROUPS

more...

gnu.emacs.help Profile…
 Up
last-input-event and X/non-X         


Author: Tim X
Date: Aug 26, 2006 01:31

I have some code which uses last-input-event to test what was last
entered by the user. However, I've noticed that this value can vary
depending on whether you are running under X or within a console. I'm
wondering what the standard emacs lisp idiom is for handling this.

As an example, I have some code in a conditional which is like

((= last-input-event 127)
(do-somehting))

Under the console, this block will execute if the user hits backspace
to indicate a character has been deleted. However, if I execute this
code under X, I will get a wrong-type-argument number-or-marker-p
backspace error. This is because under X, rather than a number,
last-input-event will hold the symbol 'backspace.

Now, I could fix this by doing something like
((or (eq last-input-event 127)
(eq last-input-event 'backspace))
(do-something))

but that seems a bit clunky to me. Also, I'm not sure how well this
will work with other character sets or encodings or on other
platforms, like Windows.
Show full article (1.08Kb)
2 Comments
Re: last-input-event and X/non-X         


Author: Miles Bader
Date: Aug 26, 2006 04:41

Tim X writes:
> ((or (eq last-input-event 127)
> (eq last-input-event 'backspace))
> (do-something))
>
> but that seems a bit clunky to me. Also, I'm not sure how well this
> will work with other character sets or encodings or on other
> platforms, like Windows.

You might try looking up the event in `function-key-map', which is how
platform-specific things like normally get translated.

e.g.

(when (equal (lookup-key function-key-map (vector last-input-event))
[127])
(do something))

-Miles
--
"Suppose He doesn't give a shit? Suppose there is a God but He
just doesn't give a shit?" [George Carlin]
1 Comment
Re: last-input-event and X/non-X         


Author: Tim X
Date: Aug 26, 2006 05:59

Miles Bader gnu.org> writes:
> Tim X writes:
>> ((or (eq last-input-event 127)
>> (eq last-input-event 'backspace))
>> (do-something))
>>
>> but that seems a bit clunky to me. Also, I'm not sure how well this
>> will work with other character sets or encodings or on other
>> platforms, like Windows.
>
> You might try looking up the event in `function-key-map', which is how
> platform-specific things like normally get translated.
>
> e.g.
>
> (when (equal (lookup-key function-key-map (vector last-input-event))
> [127])
> (do something))
>
Show full article (0.90Kb)
no comments

RELATED THREADS
SubjectArticles qty Group
Re: iTunes non è una monnezza perchè non si può dire ma ad essere onesti...it.comp.macintosh ·