all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tom Capey <tom.capey@gmail.com>
To: Xue Fuqiao <xfq.free@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: About an example in Emacs Lisp manual
Date: Sun, 10 Feb 2013 15:07:29 +0000	[thread overview]
Message-ID: <87zjzcmclq.fsf@madasafish.co.uk> (raw)
In-Reply-To: <mailman.19496.1360505980.855.help-gnu-emacs@gnu.org> (Xue Fuqiao's message of "Sun, 10 Feb 2013 22:19:25 +0800")

* 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	other threads:[~2013-02-10 15:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.19496.1360505980.855.help-gnu-emacs@gnu.org>
2013-02-10 15:07 ` Tom Capey [this message]
2013-02-10 15:31   ` About an example in Emacs Lisp manual Xue Fuqiao
2013-02-10 14:19 Xue Fuqiao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zjzcmclq.fsf@madasafish.co.uk \
    --to=tom.capey@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=xfq.free@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.