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

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

[Elisp] beginner question


From: Fabrice Bauzac
Subject: [Elisp] beginner question
Date: Thu, 21 Jun 2001 19:18:05 +0200
User-agent: Mutt/1.3.18i

Hello,

I'm a beginner in Emacs-Lisp (and in Lisp, and in Scheme).  I want to
put this in my ~/.emacs.el:

(global-set-key "\C-cv1" (lambda () (interactive) (my-aumix 1)))
(global-set-key "\C-cv2" (lambda () (interactive) (my-aumix 2)))
(global-set-key "\C-cv3" (lambda () (interactive) (my-aumix 3)))
(global-set-key "\C-cv4" (lambda () (interactive) (my-aumix 4)))
(global-set-key "\C-cv5" (lambda () (interactive) (my-aumix 5)))
(global-set-key "\C-cv6" (lambda () (interactive) (my-aumix 6)))
(global-set-key "\C-cv7" (lambda () (interactive) (my-aumix 7)))
(global-set-key "\C-cv8" (lambda () (interactive) (my-aumix 8)))
(global-set-key "\C-cv9" (lambda () (interactive) (my-aumix 9)))

Yes, I know that I should make a C-c v keymap, but I'm already
confused by some other simple things.

I want to do it in a more clever way: I tried this:

(let ((n 1))
  (while (<= n 9)
    (global-set-key
     (concat "\C-cv" (number-to-string n))
     (lambda () (interactive) (my-aumix n)))
    (setq n (1+ n))))

It doesn't work.  The code is accepted by Emacs, but then when I do
C-c v 6 it says "Symbol's value as variable is void: n".  I guess the
lambda expression is turned into a procedure but with a binding to the
memory in n, instead of with an individual copy of it, and so my C-c v
6 doesn't work because n was local and doesn't exist anymore (correct
me please).

So, could anyone explain me how to do what I want?

Running Emacs 20.7.2 from debian-unstable.

TIA!
-- 
Fabrice Bauzac
Software should be free.

Attachment: pgpCj5usPEExD.pgp
Description: PGP signature


reply via email to

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