all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* last-input-event and X/non-X
@ 2006-08-26  8:31 Tim X
  2006-08-26 11:41 ` Miles Bader
       [not found] ` <mailman.5673.1156592483.9609.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 3+ messages in thread
From: Tim X @ 2006-08-26  8:31 UTC (permalink / raw)



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. 

Any advice appreciated.

thanks,

Tim

-- 
tcross (at) rapttech dot com dot au

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

* Re: last-input-event and X/non-X
  2006-08-26  8:31 last-input-event and X/non-X Tim X
@ 2006-08-26 11:41 ` Miles Bader
       [not found] ` <mailman.5673.1156592483.9609.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 3+ messages in thread
From: Miles Bader @ 2006-08-26 11:41 UTC (permalink / raw)


Tim X <timx@nospam.dev.null> 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 <backspace> 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]

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

* Re: last-input-event and X/non-X
       [not found] ` <mailman.5673.1156592483.9609.help-gnu-emacs@gnu.org>
@ 2006-08-26 12:59   ` Tim X
  0 siblings, 0 replies; 3+ messages in thread
From: Tim X @ 2006-08-26 12:59 UTC (permalink / raw)


Miles Bader <miles@gnu.org> writes:

> Tim X <timx@nospam.dev.null> 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 <backspace> normally get translated.
>
> e.g. 
>
>     (when (equal (lookup-key function-key-map (vector last-input-event))
>                  [127])
>        (do something))
>        

thanks Miles - that is a good idea. I was actually just delving into
the key maps as I figured there had to be something like that. You
have saved me a bit of time by narrowing the search space a bit.
Thanks.

Tim


-- 
tcross (at) rapttech dot com dot au

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

end of thread, other threads:[~2006-08-26 12:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-26  8:31 last-input-event and X/non-X Tim X
2006-08-26 11:41 ` Miles Bader
     [not found] ` <mailman.5673.1156592483.9609.help-gnu-emacs@gnu.org>
2006-08-26 12:59   ` Tim X

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.