help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: About an example in Emacs Lisp manual


From: Tom Capey
Subject: Re: About an example in Emacs Lisp manual
Date: Sun, 10 Feb 2013 15:07:29 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.90 (gnu/linux)

* Xue Fuqiao writes:

> In (info "(elisp) Translation Keymaps"):
>     For example, here's how to define `C-c h' to turn the character that
>   follows into a Hyper character:
>      (defun hyperify (prompt)
>        (let ((e (read-event)))
>          (vector (if (numberp e)
>                      (logior (lsh 1 24) e)
>                    (if (memq 'hyper (event-modifiers e))
>                        e
>                      (add-event-modifier "H-" e))))))

[...]

> In the first `defun' form, if `e' is a number,
> (vector (logior (lsh 1 24) e)) will be returned.  I don't
> understand what the meaning of the bitwise-or and bit-shifting
> functions are here.

  The Hyper modifier bit is the 2^24 bit--(info "(elisp) Other Char Bits").
  If that bit is a 1 then it's on, 0 and it's off.

  (lsh 1 n) returns a value with just the nth bit turned on, and
  all the other bits are turned off, that is, are zero.  Thus
  (lsh 1 24) has the 2^24 bit turned on [(= (expt 2 24) (lsh 1 24)) => t],
  the Hyper modifier bit.

  `logior' does a bit-by-bit OR comparision between the number
  with its 24th bit on and `e', looking at both numbers as though
  they were binary representations.  In this case we're OR-ing
  `e' against the Hyper bit, and this has the effect of returning
  `e' with the Hyper bit turned on.


/Tom
--



reply via email to

[Prev in Thread] Current Thread [Next in Thread]