I have a list with the pattern (list (cons key-binding1 file-name1) (cons key-binding2 file-name2)...)
(setq hot-list
(list
(cons "H-g" "~/Documents/goals")
(cons "H-h" "~/Documents/things")
(cons "H-1" "~/Files/C/abc.c")
(cons "H-2" "~/Files/C/abc2.c")
(cons "H-3" "~/Files/C/abc3.c")
(cons "H-e" "~/.emacs") ))
Now I want to bind each key-binding to the respective file. But I don't want to do write a (global-set-key)
form for each file. Instead I use (dolist)
:
(dolist (i hot-list)
(global-set-key (kbd (car i))
(list `lambda (list i)
`(interactive)
`(find-file (cdr ,i)))))
When I try "H-1", it gives an error: " Invalid function: (lambda (("H-1" . "~/Files/C/abc.c")) (interactive) (find-file (cdr ("H-1" . "~/Files/C/abc.c"))))
"
Although I don't find anything wrong with my code. (global-set-key)
accept a command. And the test: (commandp (lambda (("H-1" . "~/Files/C/abc.c")) (interactive) (find-file (cdr ("H-1" . "~/Files/C/abc.c")))))
returns t
How should I do this?