all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* About an example in Emacs Lisp manual
@ 2013-02-10 14:19 Xue Fuqiao
  0 siblings, 0 replies; 3+ messages in thread
From: Xue Fuqiao @ 2013-02-10 14:19 UTC (permalink / raw)
  To: help-gnu-emacs

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))))))
     (defun add-event-modifier (string e)
       (let ((symbol (if (symbolp e) e (car e))))
         (setq symbol (intern (concat string
                                      (symbol-name symbol))))
         (if (symbolp e)
             symbol
           (cons symbol (cdr e)))))
     (define-key local-function-key-map "\C-ch" 'hyperify)

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.  Can anybody explain it for me (and maybe for other people)?  Thanks.

-- 
Best regards, Xue Fuqiao.
http://www.emacswiki.org/emacs/XueFuqiao



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

* Re: About an example in Emacs Lisp manual
       [not found] <mailman.19496.1360505980.855.help-gnu-emacs@gnu.org>
@ 2013-02-10 15:07 ` Tom Capey
  2013-02-10 15:31   ` Xue Fuqiao
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Capey @ 2013-02-10 15:07 UTC (permalink / raw)
  To: Xue Fuqiao; +Cc: help-gnu-emacs

* 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
--



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

* Re: About an example in Emacs Lisp manual
  2013-02-10 15:07 ` About an example in Emacs Lisp manual Tom Capey
@ 2013-02-10 15:31   ` Xue Fuqiao
  0 siblings, 0 replies; 3+ messages in thread
From: Xue Fuqiao @ 2013-02-10 15:31 UTC (permalink / raw)
  To: Tom Capey; +Cc: help-gnu-emacs

On Sun, 10 Feb 2013 15:07:29 +0000
Tom Capey <tom.capey@gmail.com> wrote:

> * 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))))))
[...]
>   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.

Ah, I see.  Thanks for your explanation.

> /Tom
-- 
Best regards, Xue Fuqiao.
http://www.emacswiki.org/emacs/XueFuqiao



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

end of thread, other threads:[~2013-02-10 15:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.19496.1360505980.855.help-gnu-emacs@gnu.org>
2013-02-10 15:07 ` About an example in Emacs Lisp manual Tom Capey
2013-02-10 15:31   ` Xue Fuqiao
2013-02-10 14:19 Xue Fuqiao

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.