* Auto-Generation of Sub-Menu Items (Keys) from a list of lists
@ 2008-09-17 10:41 Nordlöw
2008-09-17 11:21 ` Notes: " Nordlöw
0 siblings, 1 reply; 2+ messages in thread
From: Nordlöw @ 2008-09-17 10:41 UTC (permalink / raw)
To: help-gnu-emacs
I am trying to automatically create a Sub-menu to "C++"-menu from the
list c++-iostream-objects in the following way:
(defvar c++-iostream-objects
'(
("cin" [cin] "Standard input stream." 'object)
("cout" [cout] "Standard output stream." 'object)
("cerr" [cerr] "Standard output stream for errors." 'object)
("clog" [clog] "Standard output stream for logging." 'object)
)
"List of C++ IOstream Objects.")
(defun generate-keymap-menu (keymap-menu-name insert-prefix alist)
(let ((m (make-sparse-keymap keymap-menu-name)))
(dolist (elm (reverse alist))
(let* ((str (concat insert-prefix (elt elm 0)))
(key (elt elm 1))
(doc (elt elm 2))
)
(define-key m key `(menu-item ,str '(lambda () (interactive)
(insert ,str)) :help ,doc))))
m))
(defvar c++-iostream-objects-menu)
(setq c++-iostream-objects-menu
(generate-keymap-menu "IOstream Objects" "std::" c++-iostream-
objects))
(add-hook 'c++-mode-hook
'(lambda () (define-key-after c-c++-menu [iostream-objects]
(cons "IOstream Objects" c++-iostream-objects-
menu) t))
t)
The value of c++-iostream-objects-menu after evaluating the above is:
(keymap
(cin menu-item "std::cin"
'(lambda nil
(interactive)
(insert "std::cin"))
:help "Standard input stream.")
(cout menu-item "std::cout"
'(lambda nil
(interactive)
(insert "std::cout"))
:help "Standard output stream.")
(cerr menu-item "std::cerr"
'(lambda nil
(interactive)
(insert "std::cerr"))
:help "Standard output stream for errors.")
(clog menu-item "std::clog"
'(lambda nil
(interactive)
(insert "std::clog"))
:help "Standard output stream for logging.")
"IOstream Objects")
and the sub-menu elements gets created but when I press on one of them
I get the error:
Debugger entered--Lisp error: (wrong-type-argument commandp (quote
(lambda nil (interactive) (insert "std::cin"))))
call-interactively((quote (lambda nil (interactive) (insert
"std::cin"))) nil nil)
This is really strange since the evaluation of
(call-interactively (quote (lambda nil (interactive) (insert
"std::cin"))))
works correctly and
(commandp (quote (lambda nil (interactive) (insert "std::cin"))))
evaluates to t.
What on earth have I missed? This nut is really hard to crack!
Many thanks in advance,
Nordlöw
^ permalink raw reply [flat|nested] 2+ messages in thread
* Notes: Auto-Generation of Sub-Menu Items (Keys) from a list of lists
2008-09-17 10:41 Auto-Generation of Sub-Menu Items (Keys) from a list of lists Nordlöw
@ 2008-09-17 11:21 ` Nordlöw
0 siblings, 0 replies; 2+ messages in thread
From: Nordlöw @ 2008-09-17 11:21 UTC (permalink / raw)
To: help-gnu-emacs
On 17 Sep, 12:41, Nordlöw <per.nord...@gmail.com> wrote:
> I am trying to automatically create a Sub-menu to "C++"-menu from the
> list c++-iostream-objects in the following way:
>
> (defvar c++-iostream-objects
> '(
> ("cin" [cin] "Standard input stream." 'object)
> ("cout" [cout] "Standard output stream." 'object)
> ("cerr" [cerr] "Standard output stream for errors." 'object)
> ("clog" [clog] "Standard output stream for logging." 'object)
> )
> "List of C++ IOstream Objects.")
>
> (defun generate-keymap-menu (keymap-menu-name insert-prefix alist)
> (let ((m (make-sparse-keymap keymap-menu-name)))
> (dolist (elm (reverse alist))
> (let* ((str (concat insert-prefix (elt elm 0)))
> (key (elt elm 1))
> (doc (elt elm 2))
> )
> (define-key m key `(menu-item ,str '(lambda () (interactive)
> (insert ,str)) :help ,doc))))
> m))
>
> (defvar c++-iostream-objects-menu)
> (setq c++-iostream-objects-menu
> (generate-keymap-menu "IOstream Objects" "std::" c++-iostream-
> objects))
>
> (add-hook 'c++-mode-hook
> '(lambda () (define-key-after c-c++-menu [iostream-objects]
> (cons "IOstream Objects" c++-iostream-objects-
> menu) t))
> t)
>
> The value of c++-iostream-objects-menu after evaluating the above is:
>
> (keymap
> (cin menu-item "std::cin"
> '(lambda nil
> (interactive)
> (insert "std::cin"))
> :help "Standard input stream.")
> (cout menu-item "std::cout"
> '(lambda nil
> (interactive)
> (insert "std::cout"))
> :help "Standard output stream.")
> (cerr menu-item "std::cerr"
> '(lambda nil
> (interactive)
> (insert "std::cerr"))
> :help "Standard output stream for errors.")
> (clog menu-item "std::clog"
> '(lambda nil
> (interactive)
> (insert "std::clog"))
> :help "Standard output stream for logging.")
> "IOstream Objects")
>
> and the sub-menu elements gets created but when I press on one of them
> I get the error:
>
> Debugger entered--Lisp error: (wrong-type-argument commandp (quote
> (lambda nil (interactive) (insert "std::cin"))))
> call-interactively((quote (lambda nil (interactive) (insert
> "std::cin"))) nil nil)
>
> This is really strange since the evaluation of
>
> (call-interactively (quote (lambda nil (interactive) (insert
> "std::cin"))))
>
> works correctly and
>
> (commandp (quote (lambda nil (interactive) (insert "std::cin"))))
>
> evaluates to t.
>
> What on earth have I missed? This nut is really hard to crack!
>
> Many thanks in advance,
> Nordlöw
First Note: All of the above code snippets can be evaluated in Vanilla
Emacs if you want to test or integrate these concepts into other Emacs
add-ons.
Second Note: The fourth element 'object is currently not used for
anything.
/Nordlöw
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-09-17 11:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-17 10:41 Auto-Generation of Sub-Menu Items (Keys) from a list of lists Nordlöw
2008-09-17 11:21 ` Notes: " Nordlöw
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).