From: Stefan Monnier <monnier@iro.umontreal.ca>
To: help-gnu-emacs@gnu.org
Subject: Re: Quoted function in `define-key'
Date: Sat, 04 Feb 2017 13:10:34 -0500 [thread overview]
Message-ID: <jwvlgtlx28b.fsf-monnier+gmane.emacs.help@gnu.org> (raw)
In-Reply-To: 874m0a6ywa.fsf@vicarie.i-did-not-set--mail-host-address--so-tickle-me
>>>>> "Narendra" == Narendra Joshi <narendraj9@gmail.com> writes:
> The following piece of code is confusing me. It is from `rinari-minor-mode'.
> (dolist (el (append (mapcar
> (lambda (el)
> (cons (concat "f" (second el))
> (read (format "'rinari-find-%S"
> (first el)))))
> rinari-jump-schema)
> rinari-minor-mode-keybindings))
> (eval `(define-key rinari-prefix-map ,(car el) ,(cdr el))))
> If I replace the last expression with:
> (define-key rinari-prefix-map (car el) (cdr el))
> why does it fail?
> (cdr el) is (quote function-name) which is exactly the same as
> 'function-name.
"Exactly the same"? Well, clearly not, since it behaves differently:
(eval (cdr el)) => (quote function-name)
(eval 'function-name) => function-name
A good first rule is that if you're using `eval` it means you're not really
doing it right:
(dolist (el (append (mapcar
(lambda (el)
(cons (vconcat [?\f] (nth 1 el))
(intern "rinari-find-%s" (nth 0 el))))
rinari-jump-schema)
rinari-minor-mode-keybindings))
(define-key rinari-prefix-map (car el) (cdr el)))
-- Stefan
prev parent reply other threads:[~2017-02-04 18:10 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-04 10:20 Quoted function in `define-key' Narendra Joshi
2017-02-04 11:11 ` Narendra Joshi
2017-02-04 12:05 ` Michael Heerdegen
2017-02-04 15:03 ` Narendra Joshi
2017-02-04 17:25 ` Michael Heerdegen
2017-02-05 10:10 ` Narendra Joshi
2017-02-05 13:50 ` Michael Heerdegen
2017-02-05 19:09 ` Narendra Joshi
2017-02-05 19:45 ` Michael Heerdegen
2017-02-04 18:10 ` Stefan Monnier [this message]
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvlgtlx28b.fsf-monnier+gmane.emacs.help@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=help-gnu-emacs@gnu.org \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).